From nobody Sun Dec 14 05:53:24 2025 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 header.i=ngoc-tu.dinh@vates.tech; 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=vates.tech ARC-Seal: i=1; a=rsa-sha256; t=1763991857; cv=none; d=zohomail.com; s=zohoarc; b=IM+OLsmVmhcSBT7dugRMLwidgRikY0L7uDxnnbC21nmTmdRXYiaturmQF22Nd2EleBO0xocIy6CjBtCUVJ76vDOfGroPVqcgyqVB3ysn1jXFjbEtUvmd3nCB+5hYnTj1uSsFTsSwBv8/9WAQQwXxz5YuianycJBHUp8zhBpV8nc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1763991857; h=Content-Type: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=tgHAZmk0TqxSfJ22MEtgYW7nyHYSd/spYYd3Txp8mGc=; b=j6ut1QPcUOOCClMUxW5AfB5gAHw5MWGAf4WvpLYJODnsvELcEhocSRMxVoGXPqDzUI64VnBmRKiOvKCVPYdMcVEDaVNXr3JFlPJeC42hvN8Z9N18E/PULglY+s1sPJQRnDdAfQ35ZlOEf733EICUMG+R3mcNUirzbi59SVPoN8Y= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=ngoc-tu.dinh@vates.tech; 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 1763991857501137.31207619363988; Mon, 24 Nov 2025 05:44:17 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.1171082.1496091 (Exim 4.92) (envelope-from ) id 1vNWrF-0000le-S7; Mon, 24 Nov 2025 13:43:57 +0000 Received: by outflank-mailman (output) from mailman id 1171082.1496091; Mon, 24 Nov 2025 13:43:57 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1vNWrF-0000ke-OU; Mon, 24 Nov 2025 13:43:57 +0000 Received: by outflank-mailman (input) for mailman id 1171082; Mon, 24 Nov 2025 13:43:56 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1vNWrE-0000kX-IX for xen-devel@lists.xenproject.org; Mon, 24 Nov 2025 13:43:56 +0000 Received: from mail136-9.atl41.mandrillapp.com (mail136-9.atl41.mandrillapp.com [198.2.136.9]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 9b875cb6-c93b-11f0-980a-7dc792cee155; Mon, 24 Nov 2025 14:43:50 +0100 (CET) Received: from pmta11.mandrill.prod.atl01.rsglab.com (localhost [127.0.0.1]) by mail136-9.atl41.mandrillapp.com (Mailchimp) with ESMTP id 4dFRqm6YJxzHXYgd9 for ; Mon, 24 Nov 2025 13:43:48 +0000 (GMT) Received: from [37.26.189.201] by mandrillapp.com id 996e3febf77541058d7a8895e834a16e; Mon, 24 Nov 2025 13:43:48 +0000 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: 9b875cb6-c93b-11f0-980a-7dc792cee155 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mandrillapp.com; s=mte1; t=1763991828; x=1764261828; bh=tgHAZmk0TqxSfJ22MEtgYW7nyHYSd/spYYd3Txp8mGc=; h=From:Subject:To:Cc:Message-Id:Feedback-ID:Date:MIME-Version: Content-Type:Content-Transfer-Encoding:CC:Date:Subject:From; b=V1Yv7mgmp+iLihaK79ev2IqvpaIVvoFMcIMint+Ok2IJraj3taBLtiWWBgKGxkZAd YUz59xu32zb9cuxxGaDeoqXIAmsrpnmz8sso9mCXCutbbynOUOh8O88PQS2eMtmbRE NEFvvPEfT0pTK/4hkmgdEcyF/YdZ4ILGGNxG0J5ZAGHlzQBrBUhij5rEwoVrGfnz1c rHishlfvFMowfMYM+ahxIF0FhJLZls9tXIG0C7GcaLdIeWoo1oFDCDRgM+b3281eHV nA3dGIeBNajFQcj8soq1+aEg9GIFFdZHAKw6qhI014mqnG1zLEfYDdWBWTnlPac21U d7ZgJufDTnZjg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=vates.tech; s=mte1; t=1763991828; x=1764252328; i=ngoc-tu.dinh@vates.tech; bh=tgHAZmk0TqxSfJ22MEtgYW7nyHYSd/spYYd3Txp8mGc=; h=From:Subject:To:Cc:Message-Id:Feedback-ID:Date:MIME-Version: Content-Type:Content-Transfer-Encoding:CC:Date:Subject:From; b=XhZ7/VJkYyfkY1B5pGhPSYHZjPbR837VPetl1QdeplnIpWiG/JPDjn0Tz4DTjEe3/ 0pGbaTndZo9L4Hwhnh/wWVK/ilEhOBgKBQ76tRIthhLH/pR1AHr4Usb4axH/GKcYRa EzcrAEbMTaYB5SHaWSpiX3UNslQcMrzqhq0/E7P7kQ+vYkVXP0nmKT4OmHKTl9b6xL zoDh8DDE2Wgx8K8yoIzgorRm5iGcYCcgEWh1T6LiZ8Y/1qg2qZtZMILE0mxm4t+Uib QUKkCfFs0M4huiw3eT04tuJZyQjT5H0kdPrrHneY91fvYvmclomWrXStRdAcHa61Z5 QgcC451MA6Dcw== From: "Tu Dinh" Subject: =?utf-8?Q?[PATCH]=20x86/vhpet:=20Fix=20sanitization=20of=20legacy=20IRQ=20route?= X-Mailer: git-send-email 2.51.2.windows.1 X-Bm-Disclaimer: Yes X-Bm-Milter-Handled: 4ffbd6c1-ee69-4e1b-aabd-f977039bd3e2 X-Bm-Transport-Timestamp: 1763991827489 To: xen-devel@lists.xenproject.org Cc: "Tu Dinh" , "Jan Beulich" , "Andrew Cooper" , "=?utf-8?Q?Roger=20Pau=20Monn=C3=A9?=" Message-Id: <20251124134344.456-1-ngoc-tu.dinh@vates.tech> X-Native-Encoded: 1 X-Report-Abuse: =?UTF-8?Q?Please=20forward=20a=20copy=20of=20this=20message,=20including=20all=20headers,=20to=20abuse@mandrill.com.=20You=20can=20also=20report=20abuse=20here:=20https://mandrillapp.com/contact/abuse=3Fid=3D30504962.996e3febf77541058d7a8895e834a16e?= X-Mandrill-User: md_30504962 Feedback-ID: 30504962:30504962.20251124:md Date: Mon, 24 Nov 2025 13:43:48 +0000 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @mandrillapp.com) (identity ngoc-tu.dinh@vates.tech) X-ZM-MESSAGEID: 1763991859894019200 Content-Type: text/plain; charset="utf-8" When setting a timer's config register, timer_sanitize_int_route will always reset the IRQ route value to what's valid corresponding to the !HPET_CFG_LEGACY case. This is applied even if the HPET is set to HPET_CFG_LEGACY. When some operating systems (e.g. Windows) try to write to a timer config, they will verify and rewrite the register if the values don't match what they expect. This causes an unnecessary write to HPET_Tn_CFG. Note, the HPET specification states that for the Tn_INT_ROUTE_CNF field: "If the value is not supported by this prarticular timer, then the value read back will not match what is written. [...] If the LegacyReplacement Route bit is set, then Timers 0 and 1 will have a different routing, and this bit field has no effect for those two timers." Therefore, Xen should not reset timer_int_route if legacy mode is enabled, regardless of what's in there. Signed-off-by: Tu Dinh --- xen/arch/x86/hvm/hpet.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/xen/arch/x86/hvm/hpet.c b/xen/arch/x86/hvm/hpet.c index f0e5f877f4..fb2f4f94aa 100644 --- a/xen/arch/x86/hvm/hpet.c +++ b/xen/arch/x86/hvm/hpet.c @@ -48,6 +48,8 @@ #define timer_is_32bit(h, n) (timer_config(h, n) & HPET_TN_32BIT) #define hpet_enabled(h) ((h)->hpet.config & HPET_CFG_ENABLE) #define timer_level(h, n) (timer_config(h, n) & HPET_TN_LEVEL) +#define timer_is_legacy(h, n) \ + (((n) <=3D 1) && ((h)->hpet.config & HPET_CFG_LEGACY)) =20 #define timer_int_route(h, n) MASK_EXTR(timer_config(h, n), HPET_TN_ROU= TE) =20 @@ -244,7 +246,7 @@ static void hpet_set_timer(HPETState *h, unsigned int t= n, (timer_level(h, tn) && test_bit(tn, &h->hpet.isr)) ) return; =20 - if ( !timer_int_route_valid(h, tn) ) + if ( !timer_is_legacy(h, tn) && !timer_int_route_valid(h, tn) ) { ASSERT_UNREACHABLE(); return; @@ -275,7 +277,7 @@ static void hpet_set_timer(HPETState *h, unsigned int t= n, ? (uint32_t)diff : 0; =20 destroy_periodic_time(&h->pt[tn]); - if ( (tn <=3D 1) && (h->hpet.config & HPET_CFG_LEGACY) ) + if ( timer_is_legacy(h, tn) ) { /* if LegacyReplacementRoute bit is set, HPET specification requir= es timer0 be routed to IRQ0 in NON-APIC or IRQ2 in the I/O APIC, @@ -323,7 +325,7 @@ static inline uint64_t hpet_fixup_reg( =20 static void timer_sanitize_int_route(HPETState *h, unsigned int tn) { - if ( timer_int_route_valid(h, tn) ) + if ( timer_is_legacy(h, tn) || timer_int_route_valid(h, tn) ) return; =20 timer_config(h, tn) &=3D ~HPET_TN_ROUTE; @@ -379,6 +381,9 @@ static int cf_check hpet_write( h->hpet.config =3D hpet_fixup_reg(new_val, old_val, HPET_CFG_ENABLE | HPET_CFG_LEGACY); =20 + for ( i =3D 0; i < HPET_TIMER_NUM; i++ ) + timer_sanitize_int_route(h, i); + if ( !(old_val & HPET_CFG_ENABLE) && (new_val & HPET_CFG_ENABLE) ) { /* Enable main counter and interrupt generation. */ --=20 2.43.0 -- Ngoc Tu Dinh | Vates XCP-ng Developer XCP-ng & Xen Orchestra - Vates solutions web: https://vates.tech