From nobody Thu Oct 30 16:37:39 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=teddy.astie@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=1761126715; cv=none; d=zohomail.com; s=zohoarc; b=KJSeOGuRTQV4cbyffDwZ0wXdKgKxODs7QDFTTn9vIEAponfnAbLyBZyE6LKKSmyuvj4C8hkPfDz/2nNrSDnFFm2gK2OYrmiJwue6tvUtgB1FmLdBcxtIqVDfuJ5NeqzOHkH01Z/Hg2GEkE/UojiRKVOj4UVCn9EAJew9Si2IpZg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1761126715; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=u65tTbbGHDnLFDs3oLFBy6jWBaKMKOiRqgKclIL4gpA=; b=CFB/AqFJFN5XDHBeCQi00/w4RF7R3yRLha5CgTcWI605HXzzknEIYDNTjorzNvfYoxSczE9Uuuky0XJ22n4phEh048qaWpleqo5lR4ojWFIWqzdH5Dx6S/2ADehpeTlD+8ylAwrCLrVmm9wodU5ZHHJQQIwe/ddV/XjykSIvijc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=teddy.astie@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 1761126715660549.1496078197815; Wed, 22 Oct 2025 02:51:55 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1147747.1479948 (Exim 4.92) (envelope-from ) id 1vBVVI-0007v2-1P; Wed, 22 Oct 2025 09:51:36 +0000 Received: by outflank-mailman (output) from mailman id 1147747.1479948; Wed, 22 Oct 2025 09:51:35 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1vBVVH-0007us-TO; Wed, 22 Oct 2025 09:51:35 +0000 Received: by outflank-mailman (input) for mailman id 1147747; Wed, 22 Oct 2025 09:51:33 +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 1vBVVF-0007BN-Pz for xen-devel@lists.xenproject.org; Wed, 22 Oct 2025 09:51:33 +0000 Received: from mail187-3.suw11.mandrillapp.com (mail187-3.suw11.mandrillapp.com [198.2.187.3]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id af993062-af2c-11f0-980a-7dc792cee155; Wed, 22 Oct 2025 11:51:31 +0200 (CEST) Received: from pmta09.mandrill.prod.suw01.rsglab.com (localhost [127.0.0.1]) by mail187-3.suw11.mandrillapp.com (Mailchimp) with ESMTP id 4cs4Dn66SVzDRJHhh for ; Wed, 22 Oct 2025 09:51:21 +0000 (GMT) Received: from [37.26.189.201] by mandrillapp.com id 9b6d7c45405a405e9f943669d8d0ba31; Wed, 22 Oct 2025 09:51:21 +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: af993062-af2c-11f0-980a-7dc792cee155 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mandrillapp.com; s=mte1; t=1761126681; x=1761396681; bh=u65tTbbGHDnLFDs3oLFBy6jWBaKMKOiRqgKclIL4gpA=; h=From:Subject:To:Cc:Message-Id:In-Reply-To:References:Feedback-ID: Date:MIME-Version:Content-Type:Content-Transfer-Encoding:CC:Date: Subject:From; b=oY8+Hu1kq3Wi/xu+r2DIGUMCNtUAqPbMq8WOG3aKJS1we84QBENoQtwUaC+Oe2CIp 6qOytG8zBzLc/xTi64lZNf8EXYDzAQjuAb75pwTdCo0WeuU5/uwxAIh48q1hX9KdxQ xUU6cdUInQAMF+OGivCx34EbXRYFqjusBguxtkPPUrtNe9XCI/c3n2Dz0zoD4JT23V 2J8dqQE709qE5HHV57igCK4vVRqeHr3CpG9CPnkwWuKTv1vBND/lICtKJqafSdSYxS YbvoqOVzsqmHgnkMLHXc1W11VLXw+JZip8MWc/3KezJK/KqLIPkAiKygrcT3Xe2Tb3 pvixyq1VJ5Y4g== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=vates.tech; s=mte1; t=1761126681; x=1761387181; i=teddy.astie@vates.tech; bh=u65tTbbGHDnLFDs3oLFBy6jWBaKMKOiRqgKclIL4gpA=; h=From:Subject:To:Cc:Message-Id:In-Reply-To:References:Feedback-ID: Date:MIME-Version:Content-Type:Content-Transfer-Encoding:CC:Date: Subject:From; b=MSv240JMXfe4EWAytify7HzLpVtU0etqw/x9KwkOe760JELTkX6w8SPhNAjFcAyCb ZjjVh3eCXG1ZZUlLTG3qqnTqd+hj7Ijv2mA3gZgAP35k6xfQAMuWm/ZZHKUbff8gYS U53J0j4GQjO6Ztd+Fn8Q7vY//fyjQ8YKS4mY7H4hArCf4gA3V/wh4nzx//jxs11o+f lprgTkqCFxfSBipzibQTujdPh4q8oSkbTlMxpAoClKsFtewi/qdx5HaBOP1BeRGjOI 7GARzsrgzDnIWiRzI6/tSu7fkOYqv8GoSxVE3JFzf7kKfwZSDkBCIF/UsU6GuSCtmb Fv2FB5hrSP/GA== From: "Teddy Astie" Subject: =?utf-8?Q?[PATCH=204/4]=20x86/ioapic:=20Don't=20open-code=2032-bits=20rte=20reads?= X-Mailer: git-send-email 2.51.1 X-Bm-Disclaimer: Yes X-Bm-Milter-Handled: 4ffbd6c1-ee69-4e1b-aabd-f977039bd3e2 X-Bm-Transport-Timestamp: 1761126681095 To: xen-devel@lists.xenproject.org Cc: "Teddy Astie" , "Jan Beulich" , "Andrew Cooper" , "=?utf-8?Q?Roger=20Pau=20Monn=C3=A9?=" Message-Id: <819a011a32c608f4aefaf692aeac5ee47381a998.1761124632.git.teddy.astie@vates.tech> In-Reply-To: References: 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.9b6d7c45405a405e9f943669d8d0ba31?= X-Mandrill-User: md_30504962 Feedback-ID: 30504962:30504962.20251022:md Date: Wed, 22 Oct 2025 09:51:21 +0000 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity teddy.astie@vates.tech) (identity @mandrillapp.com) X-ZM-MESSAGEID: 1761126717756154100 Content-Type: text/plain; charset="utf-8" There are many places where we use interesting ways of reading 32-bits components of the RTE. Introduce and use low and high components directly to the rte structure instead. Also take the opportunity to simplify "x & 1 ? 1 : 0". Signed-off-by: Teddy Astie --- xen/arch/x86/include/asm/io_apic.h | 1 + xen/arch/x86/io_apic.c | 29 ++++++++++---------------- xen/drivers/passthrough/vtd/intremap.c | 9 +++----- 3 files changed, 15 insertions(+), 24 deletions(-) diff --git a/xen/arch/x86/include/asm/io_apic.h b/xen/arch/x86/include/asm/= io_apic.h index 4680dce9e1..0e85f2a860 100644 --- a/xen/arch/x86/include/asm/io_apic.h +++ b/xen/arch/x86/include/asm/io_apic.h @@ -122,6 +122,7 @@ struct IO_APIC_route_entry { } dest; }; uint64_t raw; + struct { uint32_t low, high; }; }; }; =20 diff --git a/xen/arch/x86/io_apic.c b/xen/arch/x86/io_apic.c index 24447aef6c..9d2edec179 100644 --- a/xen/arch/x86/io_apic.c +++ b/xen/arch/x86/io_apic.c @@ -257,28 +257,23 @@ nomem: return NULL; } =20 -union entry_union { - struct { u32 w1, w2; }; - struct IO_APIC_route_entry entry; -}; - struct IO_APIC_route_entry __ioapic_read_entry( unsigned int apic, unsigned int pin, bool raw) { - union entry_union eu; + struct IO_APIC_route_entry entry; =20 if ( raw || !iommu_intremap ) { - eu.w1 =3D __io_apic_read(apic, 0x10 + 2 * pin); - eu.w2 =3D __io_apic_read(apic, 0x11 + 2 * pin); + entry.low =3D __io_apic_read(apic, 0x10 + 2 * pin); + entry.high =3D __io_apic_read(apic, 0x11 + 2 * pin); } else { - eu.w1 =3D iommu_read_apic_from_ire(apic, 0x10 + 2 * pin); - eu.w2 =3D iommu_read_apic_from_ire(apic, 0x11 + 2 * pin); + entry.low =3D iommu_read_apic_from_ire(apic, 0x10 + 2 * pin); + entry.high =3D iommu_read_apic_from_ire(apic, 0x11 + 2 * pin); } =20 - return eu.entry; + return entry; } =20 static struct IO_APIC_route_entry ioapic_read_entry( @@ -297,12 +292,10 @@ void __ioapic_write_entry( unsigned int apic, unsigned int pin, bool raw, struct IO_APIC_route_entry e) { - union entry_union eu =3D { .entry =3D e }; - if ( raw || !iommu_intremap ) { - __io_apic_write(apic, 0x11 + 2 * pin, eu.w2); - __io_apic_write(apic, 0x10 + 2 * pin, eu.w1); + __io_apic_write(apic, 0x11 + 2 * pin, e.high); + __io_apic_write(apic, 0x10 + 2 * pin, e.low); /* * Might be called before io_apic_pin_eoi is allocated. Entry wil= l be * initialized to the RTE value once the cache is allocated. @@ -2235,7 +2228,7 @@ int ioapic_guest_read(unsigned long physbase, unsigne= d int reg, u32 *pval) dprintk(XENLOG_INFO, "IO-APIC: apic=3D%d, pin=3D%d, irq=3D%d\n" \ XENLOG_INFO "IO-APIC: new_entry=3D%08x\n" \ XENLOG_INFO "IO-APIC: " f "\n", \ - apic, pin, irq, *(u32 *)&rte, ##a ) + apic, pin, irq, rte.low, ##a ) =20 int ioapic_guest_write(unsigned long physbase, unsigned int reg, u32 val) { @@ -2254,7 +2247,7 @@ int ioapic_guest_write(unsigned long physbase, unsign= ed int reg, u32 val) pin =3D (reg - 0x10) >> 1; =20 /* Write first half from guest; second half is target info. */ - *(u32 *)&rte =3D val; + rte.low =3D val; =20 /* * What about weird destination types? @@ -2305,7 +2298,7 @@ int ioapic_guest_write(unsigned long physbase, unsign= ed int reg, u32 val) ret =3D io_apic_read(apic, 0x10 + 2 * pin); spin_unlock_irqrestore(&ioapic_lock, flags); rte.vector =3D desc->arch.vector; - if ( *(u32*)&rte !=3D ret ) + if ( rte.low !=3D ret ) WARN_BOGUS_WRITE("old_entry=3D%08x pirq=3D%d\n" XENLOG_INFO "IO-APIC: Attempt to modify IO-APIC pin for i= n-use IRQ!", ret, pirq); diff --git a/xen/drivers/passthrough/vtd/intremap.c b/xen/drivers/passthrou= gh/vtd/intremap.c index e0314aa469..3cdb892559 100644 --- a/xen/drivers/passthrough/vtd/intremap.c +++ b/xen/drivers/passthrough/vtd/intremap.c @@ -399,7 +399,7 @@ unsigned int cf_check io_apic_read_remap_rte( unsigned int ioapic_pin =3D (reg - 0x10) / 2; int index; struct IO_APIC_route_entry old_rte =3D { }; - int rte_upper =3D (reg & 1) ? 1 : 0; + unsigned int rte_upper =3D reg & 1; struct vtd_iommu *iommu =3D ioapic_to_iommu(IO_APIC_ID(apic)); =20 if ( !iommu->intremap.num || @@ -410,11 +410,8 @@ unsigned int cf_check io_apic_read_remap_rte( =20 if ( remap_entry_to_ioapic_rte(iommu, index, &old_rte) ) return __io_apic_read(apic, reg); - - if ( rte_upper ) - return (*(((u32 *)&old_rte) + 1)); - else - return (*(((u32 *)&old_rte) + 0)); + =20 + return rte_upper ? old_rte.high : old_rte.low; } =20 void cf_check io_apic_write_remap_rte( --=20 2.51.1 -- Teddy Astie | Vates XCP-ng Developer XCP-ng & Xen Orchestra - Vates solutions web: https://vates.tech