From nobody Fri May 17 05:50:23 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=reject dis=none) header.from=citrix.com ARC-Seal: i=1; a=rsa-sha256; t=1712593434; cv=none; d=zohomail.com; s=zohoarc; b=afJCO0vRM/xG4M1XpleZPnhRjtWl49jdKSRQPQw7y63XDuIUnIzf1Bmk+4AiXNPIh0f7i7cVPyt0Xjc+LNlulnO0MVgPeU4ZO6+Fgbc/xnwbSpiOUcb+KtDGi52Gsk5xfGxL4yaNvHaUb84JMNG8qdGfcoW5zhVrdOOxes+MNow= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1712593434; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=H5x+YaR09ZTu1jMXSzWW/50S2FlPaWtNu+wmw+3STVI=; b=aBJ60jTToQ6zYHB4GzN/DbbUQKLnfeFS+76lWnhr5MAh25Cst69usJl2IrqPw9GOCFp/SO3c0ZI7pqmv1RVuvVj4fRL4G4YNeRvA/0VOnps3BxzLieDwpR84E22RFzClx9XR4Ny1XJwjn/9hmyMRAxDroHS0tRg/X8RyDrPE97s= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1712593434259278.465784139765; Mon, 8 Apr 2024 09:23:54 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.702023.1096737 (Exim 4.92) (envelope-from ) id 1rtrmQ-00051x-7u; Mon, 08 Apr 2024 16:23:34 +0000 Received: by outflank-mailman (output) from mailman id 702023.1096737; Mon, 08 Apr 2024 16:23:34 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rtrmQ-00051l-5L; Mon, 08 Apr 2024 16:23:34 +0000 Received: by outflank-mailman (input) for mailman id 702023; Mon, 08 Apr 2024 16:23:32 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rtrmO-0004wR-Fk for xen-devel@lists.xenproject.org; Mon, 08 Apr 2024 16:23:32 +0000 Received: from mail-qv1-xf36.google.com (mail-qv1-xf36.google.com [2607:f8b0:4864:20::f36]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 567a7749-f5c4-11ee-afe6-a90da7624cb6; Mon, 08 Apr 2024 18:23:31 +0200 (CEST) Received: by mail-qv1-xf36.google.com with SMTP id 6a1803df08f44-696719f8dfcso26743096d6.0 for ; Mon, 08 Apr 2024 09:23:31 -0700 (PDT) Received: from rossla-lxenia.eng.citrite.net ([185.25.67.249]) by smtp.gmail.com with ESMTPSA id q8-20020ad44348000000b0069b14ff208bsm1515536qvs.79.2024.04.08.09.23.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Apr 2024 09:23:28 -0700 (PDT) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 567a7749-f5c4-11ee-afe6-a90da7624cb6 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=citrix.com; s=google; t=1712593410; x=1713198210; darn=lists.xenproject.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=H5x+YaR09ZTu1jMXSzWW/50S2FlPaWtNu+wmw+3STVI=; b=o82H6dSv2xomsoYqe7C7+/TNAzWPUzVE74v8vwVYcIM/c1al9gbNuyhd/pHgKx+5JN LHAmCA6keadTniDvGNlRwXaPKAXrZdRZomwfxr2L+Rw7TQ8kWU9VOYMnjNe9mPvB/LLE cr1VvVR4Dj7HXyuuopxx2wiExeI+9upa/QH1w= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712593410; x=1713198210; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=H5x+YaR09ZTu1jMXSzWW/50S2FlPaWtNu+wmw+3STVI=; b=OOt6jazhi+fQUgQhd1ITiF/YgrMUJtjasb+xd1Busua9x6AqI5rLD3TT5g1L/Ayjy+ OMG2zitBWrTGKLaHD1DGiIRwObKi41XeMXL6Oex37MoqTGHCDMHD+fFQOm/v8aN7v+sV 5mvXWdiTXTzy9TM5d3BWOYHBNplLtqrUXhJCVbcNGSFSNLo1dUTgWm9cEl0pgZHIlQTi 8YRI6OJtZhhKpKN/NmoGTNnf3CkgHqxY36aBU9CdhqBUJuhovYCPBfCTQB+Fy3y7ljer ndiiC57tmZgo6zf1oASash29ebeZGdLMYdprMIlVYKPN6G+j6+GQkmLSGh/iI33e4uaA EJUw== X-Gm-Message-State: AOJu0YzttBg3Ppje0Zq78UzFpnDCDtdqFICbbQeg/R8Q+NWzIRuiQE7T FXJjLOkxVArzEMzFA0GKpdbdyVFnLHNMld1ele3W6GlKs7IrRZVtpWMCKEE/aQJ/3HGXlAWanuk = X-Google-Smtp-Source: AGHT+IHNIxXp5tnZapf03sBF+9VMqkABIFTS8/Tmwrw/svZmCKuzi1+h3BKtwmRhGS33jo51GDZSTA== X-Received: by 2002:ad4:5be7:0:b0:696:7ed9:9d8b with SMTP id k7-20020ad45be7000000b006967ed99d8bmr11936531qvc.2.1712593409777; Mon, 08 Apr 2024 09:23:29 -0700 (PDT) From: Ross Lagerwall To: xen-devel@lists.xenproject.org Cc: Jan Beulich , Andrew Cooper , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Ross Lagerwall Subject: [PATCH] x86/rtc: Avoid UIP flag being set for longer than expected Date: Mon, 8 Apr 2024 17:26:20 +0100 Message-ID: <20240408162620.1633551-1-ross.lagerwall@citrix.com> X-Mailer: git-send-email 2.43.0 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @citrix.com) X-ZM-MESSAGEID: 1712593435347100001 Content-Type: text/plain; charset="utf-8" In a test, OVMF reported an error initializing the RTC without indicating the precise nature of the error. The only plausible explanation I can find is as follows: As part of the initialization, OVMF reads register C and then reads register A repatedly until the UIP flag is not set. If this takes longer than 100 ms, OVMF fails and reports an error. This may happen with the following sequence of events: At guest time=3D0s, rtc_init() calls check_update_timer() which schedules update_timer for t=3D(1 - 244us). At t=3D1s, the update_timer function happens to have been called >=3D 244us late. In the timer callback, it sets the UIP flag and schedules update_timer2 for t=3D1s. Before update_timer2 runs, the guest reads register C which calls check_update_timer(). check_update_timer() stops the scheduled update_timer2 and since the guest time is now outside of the update cycle, it schedules update_timer for t=3D(2 - 244us). The UIP flag will therefore be set for a whole second from t=3D1 to t=3D2 while the guest repeatedly reads register A waiting for the UIP flag to clear. Fix it by clearing the UIP flag when scheduling update_timer. I was able to reproduce this issue with a synthetic test and this resolves the issue. Signed-off-by: Ross Lagerwall Reviewed-by: Jan Beulich --- xen/arch/x86/hvm/rtc.c | 1 + 1 file changed, 1 insertion(+) diff --git a/xen/arch/x86/hvm/rtc.c b/xen/arch/x86/hvm/rtc.c index 4b31382619f4..4bb1c7505534 100644 --- a/xen/arch/x86/hvm/rtc.c +++ b/xen/arch/x86/hvm/rtc.c @@ -202,6 +202,7 @@ static void check_update_timer(RTCState *s) } else { + s->hw.cmos_data[RTC_REG_A] &=3D ~RTC_UIP; next_update_time =3D (USEC_PER_SEC - guest_usec - 244) * NS_PE= R_USEC; expire_time =3D NOW() + next_update_time; s->next_update_time =3D expire_time; --=20 2.43.0