Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 93E06CFA466 for ; Mon, 24 Nov 2025 15:12:56 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.1171421.1496427 (Exim 4.92) (envelope-from ) id 1vNYFA-0007cK-H1; Mon, 24 Nov 2025 15:12:44 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 1171421.1496427; Mon, 24 Nov 2025 15:12:44 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1vNYFA-0007cD-EI; Mon, 24 Nov 2025 15:12:44 +0000 Received: by outflank-mailman (input) for mailman id 1171421; Mon, 24 Nov 2025 15:12:43 +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 1vNY5l-0001E9-F4 for xen-devel@lists.xenproject.org; Mon, 24 Nov 2025 15:03:01 +0000 Received: from mail136-9.atl41.mandrillapp.com (mail136-9.atl41.mandrillapp.com [198.2.136.9]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id aa8e7194-c946-11f0-9d18-b5c5bf9af7f9; Mon, 24 Nov 2025 16:03:00 +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 4dFTb61F0rzHXYlwy for ; Mon, 24 Nov 2025 15:02:58 +0000 (GMT) Received: from [37.26.189.201] by mandrillapp.com id e298da46acbe4345b5f1dad1e68afb33; Mon, 24 Nov 2025 15:02:57 +0000 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: aa8e7194-c946-11f0-9d18-b5c5bf9af7f9 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mandrillapp.com; s=mte1; t=1763996578; x=1764266578; bh=GDrz6jEcGb5OeNyozvsgDwOYd7aUCGtM/1WkfqyEd30=; h=From:Subject:Message-Id:To:Cc:References:In-Reply-To:Feedback-ID: Date:MIME-Version:Content-Type:Content-Transfer-Encoding:CC:Date: Subject:From; b=pl+aIbWdkSHKB2rLKUFhCWgyGdlvASPheTcBRSuNddEDh3+DwQ0foG2BOADwi8tse A0FksaqrhjVl6O7VDo6ddzJKpe1dUOMflk2UABfYU+NYR4Hrv13mTwVdggYzKo5u0W zSx2eqvPSX8Yp09rvvU5KtkUZvb1sYiK2f69K5ZXZxcgGqSu29B3qJJCtATvJZIJRd HIqHlOuryFCf78EZjYzeWr7JOM+jxwwFVAsCjYBAWTbE06R14zpVyPLnSRK2dYlL+H ABcfG4nLPtdsPz9ZLbeIQYePTXWNoBa8iJ3qcQVHig/gwQuZzJ4iFpE6tmyI5jPvg3 KNPi07L/Jt5IA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=vates.tech; s=mte1; t=1763996578; x=1764257078; i=ngoc-tu.dinh@vates.tech; bh=GDrz6jEcGb5OeNyozvsgDwOYd7aUCGtM/1WkfqyEd30=; h=From:Subject:Message-Id:To:Cc:References:In-Reply-To:Feedback-ID: Date:MIME-Version:Content-Type:Content-Transfer-Encoding:CC:Date: Subject:From; b=BpQe5boGh/kIS67hbAlR38MQQiGWnYmdOLgsxzCmNrNRiPAetidyE4wlc0egeOLlt Qd6ckzkMGUQWxCvXH3UjOZCtQezQIeBymbWy7401Feoqh88EtjcIl4N4KfFdhL/ayr Eo+XGERYM7MnK5xRP6gpoom9JKMeJHtwljLAFvJvL/4a0HHp8zp6963libSMQ18WYs fSnxVOHxa/LLMjlmQ3V1/Mpwuuk6uAEdZfZPcY7laE32zXuWAyYBkJlvuB3euv9yHW U6KfKn3ZfRlBhwa8X8Yabcv3Eb2eYhqi5bUXgkWbtG1baiYiL6xMs/VbsXsgrsr0EG 7RZT9N+Th4fUg== From: "Tu Dinh" Subject: =?utf-8?Q?Re:=20[PATCH]=20x86/vhpet:=20Fix=20sanitization=20of=20legacy=20IRQ=20route?= X-Bm-Disclaimer: Yes X-Bm-Milter-Handled: 4ffbd6c1-ee69-4e1b-aabd-f977039bd3e2 X-Bm-Transport-Timestamp: 1763996576074 Message-Id: <143076ee-6ade-4fe8-924a-a2b8a5af1a5f@vates.tech> To: "Jan Beulich" Cc: "Andrew Cooper" , "=?utf-8?Q?Roger=20Pau=20Monn=C3=A9?=" , xen-devel@lists.xenproject.org References: <20251124134344.456-1-ngoc-tu.dinh@vates.tech> <8581c3ce-e0f7-41e5-aee7-cf607f8f338d@suse.com> In-Reply-To: <8581c3ce-e0f7-41e5-aee7-cf607f8f338d@suse.com> 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.e298da46acbe4345b5f1dad1e68afb33?= X-Mandrill-User: md_30504962 Feedback-ID: 30504962:30504962.20251124:md Date: Mon, 24 Nov 2025 15:02:57 +0000 MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit On 24/11/2025 15:53, Jan Beulich wrote: > On 24.11.2025 14:43, Tu Dinh wrote: >> 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. > > Fixes: ec40d3fe2147 ("x86/vhpet: check that the set interrupt route is valid") > (I think) Yes, thanks. > >> Signed-off-by: Tu Dinh >> --- >> xen/arch/x86/hvm/hpet.c | 11 ++++++++--- >> 1 file changed, 8 insertions(+), 3 deletions(-) >> >> --- 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) <= 1) && ((h)->hpet.config & HPET_CFG_LEGACY)) >> >> #define timer_int_route(h, n) MASK_EXTR(timer_config(h, n), HPET_TN_ROUTE) >> >> @@ -244,7 +246,7 @@ static void hpet_set_timer(HPETState *h, unsigned int tn, >> (timer_level(h, tn) && test_bit(tn, &h->hpet.isr)) ) >> return; >> >> - if ( !timer_int_route_valid(h, tn) ) >> + if ( !timer_is_legacy(h, tn) && !timer_int_route_valid(h, tn) ) > > Seeing this and the other use together with timer_int_route_valid(), > wouldn't timer_int_route_valid() better itself invoke the new macro? I thought about it, but I found that it was overloading the definition of timer_int_route_valid a little too much. Since timer_is_legacy() is being used by itself later anyway, I figured it'd be better to just separate the two. > >> @@ -379,6 +381,9 @@ static int cf_check hpet_write( >> h->hpet.config = hpet_fixup_reg(new_val, old_val, >> HPET_CFG_ENABLE | HPET_CFG_LEGACY); >> >> + for ( i = 0; i < HPET_TIMER_NUM; i++ ) >> + timer_sanitize_int_route(h, i); > > Strictly speaking this is needed only when HPET_CFG_LEGACY went from > 1 to 0. Plus it's needed only on the first 2 channels, as it's only > there where timer_sanitize_int_route() changes behavior. I'm not going > to insist to limit it like this, but if you don't, then I'd like to ask > for a comment here clarifying that excess work is done for simplicity's > sake. Agreed, I can limit it to i <= 1. I'll prepare a v2. > > Jan > -- Ngoc Tu Dinh | Vates XCP-ng Developer XCP-ng & Xen Orchestra - Vates solutions web: https://vates.tech