From nobody Sat May 18 08:35:53 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 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=quarantine dis=none) header.from=vates.tech ARC-Seal: i=1; a=rsa-sha256; t=1712581352; cv=none; d=zohomail.com; s=zohoarc; b=Ttdg/Ihk+Un0BscOyVw3RNisFMnJCF0VsXjq0hJHoa3s+BK4B7g5KVhMExe8sHHNtzstN+3iLgN34O2sSiChO489VHRFUg3A4s88r2slM1APTVm0MS56O0asgEJZmbe/YMPWSkiUMpRfsGFK0me3m4w6oSoGRPJ20ozIYFuZhIg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1712581352; 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=oEfPK4kpMZ9sydCf3jqQctQoxsRawCygWixvd6Mv/Mo=; b=acf6QBUEgQb3U2tdXqOgD2Q5ErTqxa30bEhjFM6j6Lf6K6rijJLl8q+UgYeq3+V3JZWtNs6ldvsit3cROxhiS2RIMpyxY6zffPUmS1lyBPXQS+iW/J3x1TBiLAzW7N+hz8inEiWopFbheGm1rtBhspzukzGHX1D6sCARqsZV4Jg= 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=quarantine dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1712581352716948.3009248267207; Mon, 8 Apr 2024 06:02:32 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.701951.1096607 (Exim 4.92) (envelope-from ) id 1rtodf-0001RJ-HN; Mon, 08 Apr 2024 13:02:19 +0000 Received: by outflank-mailman (output) from mailman id 701951.1096607; Mon, 08 Apr 2024 13:02:19 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rtodf-0001RC-EB; Mon, 08 Apr 2024 13:02:19 +0000 Received: by outflank-mailman (input) for mailman id 701951; Mon, 08 Apr 2024 13:02:18 +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 1rtode-0001Ba-1H for xen-devel@lists.xenproject.org; Mon, 08 Apr 2024 13:02:18 +0000 Received: from mail177-6.suw61.mandrillapp.com (mail177-6.suw61.mandrillapp.com [198.2.177.6]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 3983f4ae-f5a8-11ee-afe6-a90da7624cb6; Mon, 08 Apr 2024 15:02:17 +0200 (CEST) Received: from pmta14.mandrill.prod.suw01.rsglab.com (localhost [127.0.0.1]) by mail177-6.suw61.mandrillapp.com (Mailchimp) with ESMTP id 4VCq4S10D5z2K1s5f for ; Mon, 8 Apr 2024 13:02:16 +0000 (GMT) Received: from [37.26.189.201] by mandrillapp.com id ca814b5c59f143059367cc7ae6c933c5; Mon, 08 Apr 2024 13:02:16 +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: 3983f4ae-f5a8-11ee-afe6-a90da7624cb6 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mandrillapp.com; s=mte1; t=1712581336; x=1712841836; bh=oEfPK4kpMZ9sydCf3jqQctQoxsRawCygWixvd6Mv/Mo=; 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=LPDH6VMIuv61YjnLQzDSLvAiz+XaHS6+0l3DnyMwz0+BcG1GhZnLjbjB85U6avRCs yQTSBJ1IwefFBkCSknX7UtTACKX6KdsoNC58HYIUCODSz5h3qYxhv3x8/audkWiNh3 n4nhTLxDR/2FfXETWZagGyWjQpCmBXA88CQi0jYPs2C4Jr6TWv/hJMzrFmCiPEqGUr wC3rOHJ+pOfWPumhmxsjdT3FgPbQ2l6FL/cbTKDzTQFlr3vSD5i8u+q5nDyA9uVE5r nmH9DOUnSsZ78M4QKlTioyzA8AlKmZ5FqMgUB91TYowvk12LLgAYHqrmcjzouaAwby G9pFMkVLEhRWA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=vates.tech; s=mte1; t=1712581336; x=1712841836; i=teddy.astie@vates.tech; bh=oEfPK4kpMZ9sydCf3jqQctQoxsRawCygWixvd6Mv/Mo=; 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=eLqWN7C960FRIlM4/+mFpXESWkLIXfWdfgepiXoRSJk4lMTqCmAquT61oD242PePt Z/c0MS6tYge7z9iwRDuz4CZbBUKVC6T8BlnGak5DJA6zRTwjcuSpdM/0puePcHl16u wZTD8ihP4RLPjMe0WSroV4oety3tggMHqyK9J3UILIu5o7HXKNrgkw3nSEQkGT39iU sLecohEyw2PNYEYVy3/7FJOBVgATFf4ayY7CAd4U030oBg0d9eGykjzLGtCcroZUXN fwVyXHDO3hRBWnQhSeoVDy27iTCO4aL8XDqTpCiGgcQpI2SLdUVNy190yF6sOuhxc/ iBhG03UJxmIeA== From: Teddy Astie Subject: =?utf-8?Q?[XEN=20PATCH=20v2=201/3]=20VT-d:=20Disable=20IOMMU=20if=20cx16=20isn't=20supported?= X-Mailer: git-send-email 2.44.0 X-Bm-Disclaimer: Yes X-Bm-Milter-Handled: 4ffbd6c1-ee69-4e1b-aabd-f977039bd3e2 X-Bm-Transport-Timestamp: 1712581333441 To: xen-devel@lists.xenproject.org Cc: Teddy Astie , Jan Beulich , Andrew Cooper , =?utf-8?Q?Roger=20Pau=20Monn=C3=A9?= Message-Id: <7132468b43cdf62587cbdccf21b25d961e435601.1712580356.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.ca814b5c59f143059367cc7ae6c933c5?= X-Mandrill-User: md_30504962 Feedback-ID: 30504962:30504962.20240408:md Date: Mon, 08 Apr 2024 13:02:16 +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: 1712581353430100001 Content-Type: text/plain; charset="utf-8" No hardware has VT-d support while not having cx16 support, disable IOMMU in this case to avoid potentially buggy code. Now that IOMMU is only enabled if cx16 is supported, drop dead code that handles cases where cx16 isn't supported. Suggested-by: Andrew Cooper Signed-off-by: Teddy Astie --- xen/arch/x86/apic.c | 6 ++ xen/drivers/passthrough/vtd/intremap.c | 65 +++++---------------- xen/drivers/passthrough/vtd/iommu.c | 80 +++++++++----------------- 3 files changed, 46 insertions(+), 105 deletions(-) diff --git a/xen/arch/x86/apic.c b/xen/arch/x86/apic.c index 592b78e11e..91d7f2b248 100644 --- a/xen/arch/x86/apic.c +++ b/xen/arch/x86/apic.c @@ -836,6 +836,12 @@ void __init x2apic_bsp_setup(void) if ( !cpu_has_x2apic ) return; =20 + if ( unlikely(!cpu_has_cx16) ) + { + printk("x2APIC: CPU doesn't support CMPXCHG16B, disabling\n"); + return; + } + if ( !opt_x2apic ) { if ( !x2apic_enabled ) diff --git a/xen/drivers/passthrough/vtd/intremap.c b/xen/drivers/passthrou= gh/vtd/intremap.c index c504852eb8..b0a0dbdbc2 100644 --- a/xen/drivers/passthrough/vtd/intremap.c +++ b/xen/drivers/passthrough/vtd/intremap.c @@ -173,47 +173,26 @@ bool __init cf_check intel_iommu_supports_eim(void) * Assume iremap_lock has been acquired. It is to make sure software will = not * change the same IRTE behind us. With this assumption, if only high qwor= d or * low qword in IRTE is to be updated, this function's atomic variant can - * present an atomic update to VT-d hardware even when cmpxchg16b - * instruction is not supported. + * present an atomic update to VT-d hardware. */ static void update_irte(struct vtd_iommu *iommu, struct iremap_entry *entr= y, const struct iremap_entry *new_ire, bool atomic) { - ASSERT(spin_is_locked(&iommu->intremap.lock)); - - if ( cpu_has_cx16 ) - { - __uint128_t ret; - struct iremap_entry old_ire; + __uint128_t ret; + struct iremap_entry old_ire; =20 - old_ire =3D *entry; - ret =3D cmpxchg16b(entry, &old_ire, new_ire); + ASSERT(spin_is_locked(&iommu->intremap.lock)); + =20 + old_ire =3D *entry; + ret =3D cmpxchg16b(entry, &old_ire, new_ire); =20 - /* - * In the above, we use cmpxchg16 to atomically update the 128-bit - * IRTE, and the hardware cannot update the IRTE behind us, so - * the return value of cmpxchg16 should be the same as old_ire. - * This ASSERT validate it. - */ - ASSERT(ret =3D=3D old_ire.val); - } - else - { - /* - * VT-d hardware doesn't update IRTEs behind us, nor the software - * since we hold iremap_lock. If the caller wants VT-d hardware to - * always see a consistent entry, but we can't meet it, a bug will - * be raised. - */ - if ( entry->lo =3D=3D new_ire->lo ) - write_atomic(&entry->hi, new_ire->hi); - else if ( entry->hi =3D=3D new_ire->hi ) - write_atomic(&entry->lo, new_ire->lo); - else if ( !atomic ) - *entry =3D *new_ire; - else - BUG(); - } + /* + * In the above, we use cmpxchg16 to atomically update the 128-bit + * IRTE, and the hardware cannot update the IRTE behind us, so + * the return value of cmpxchg16 should be the same as old_ire. + * This ASSERT validate it. + */ + ASSERT(ret =3D=3D old_ire.val); } =20 /* Mark specified intr remap entry as free */ @@ -395,7 +374,6 @@ static int ioapic_rte_to_remap_entry(struct vtd_iommu *= iommu, /* Indicate remap format. */ remap_rte->format =3D 1; =20 - /* If cmpxchg16b is not available the caller must mask the IO-APIC pin= . */ update_irte(iommu, iremap_entry, &new_ire, !init && !masked); iommu_sync_cache(iremap_entry, sizeof(*iremap_entry)); iommu_flush_iec_index(iommu, 0, index); @@ -437,21 +415,6 @@ void cf_check io_apic_write_remap_rte( bool masked =3D true; int rc; =20 - if ( !cpu_has_cx16 ) - { - /* - * Cannot atomically update the IRTE entry: mask the IO-APIC pin to - * avoid interrupts seeing an inconsistent IRTE entry. - */ - old_rte =3D __ioapic_read_entry(apic, pin, true); - if ( !old_rte.mask ) - { - masked =3D false; - old_rte.mask =3D 1; - __ioapic_write_entry(apic, pin, true, old_rte); - } - } - /* Not the initializer, for old gcc to cope. */ new_rte.raw =3D rte; =20 diff --git a/xen/drivers/passthrough/vtd/iommu.c b/xen/drivers/passthrough/= vtd/iommu.c index c7110af7c9..47b56f37a9 100644 --- a/xen/drivers/passthrough/vtd/iommu.c +++ b/xen/drivers/passthrough/vtd/iommu.c @@ -1482,7 +1482,7 @@ int domain_context_mapping_one( { struct domain_iommu *hd =3D dom_iommu(domain); struct context_entry *context, *context_entries, lctxt; - __uint128_t old; + __uint128_t res, old; uint64_t maddr; uint16_t seg =3D iommu->drhd->segment, prev_did =3D 0; struct domain *prev_dom =3D NULL; @@ -1580,55 +1580,23 @@ int domain_context_mapping_one( ASSERT(!context_fault_disable(lctxt)); } =20 - if ( cpu_has_cx16 ) - { - __uint128_t res =3D cmpxchg16b(context, &old, &lctxt.full); + res =3D cmpxchg16b(context, &old, &lctxt.full); =20 - /* - * Hardware does not update the context entry behind our backs, - * so the return value should match "old". - */ - if ( res !=3D old ) - { - if ( pdev ) - check_cleanup_domid_map(domain, pdev, iommu); - printk(XENLOG_ERR - "%pp: unexpected context entry %016lx_%016lx (expected = %016lx_%016lx)\n", - &PCI_SBDF(seg, bus, devfn), - (uint64_t)(res >> 64), (uint64_t)res, - (uint64_t)(old >> 64), (uint64_t)old); - rc =3D -EILSEQ; - goto unlock; - } - } - else if ( !prev_dom || !(mode & MAP_WITH_RMRR) ) - { - context_clear_present(*context); - iommu_sync_cache(context, sizeof(*context)); - - write_atomic(&context->hi, lctxt.hi); - /* No barrier should be needed between these two. */ - write_atomic(&context->lo, lctxt.lo); - } - else /* Best effort, updating DID last. */ + /* + * Hardware does not update the context entry behind our backs, + * so the return value should match "old". + */ + if ( res !=3D old ) { - /* - * By non-atomically updating the context entry's DID field last, - * during a short window in time TLB entries with the old domain = ID - * but the new page tables may be inserted. This could affect I/O - * of other devices using this same (old) domain ID. Such updati= ng - * therefore is not a problem if this was the only device associa= ted - * with the old domain ID. Diverting I/O of any of a dying domai= n's - * devices to the quarantine page tables is intended anyway. - */ - if ( !(mode & (MAP_OWNER_DYING | MAP_SINGLE_DEVICE)) ) - printk(XENLOG_WARNING VTDPREFIX - " %pp: reassignment may cause %pd data corruption\n", - &PCI_SBDF(seg, bus, devfn), prev_dom); - - write_atomic(&context->lo, lctxt.lo); - /* No barrier should be needed between these two. */ - write_atomic(&context->hi, lctxt.hi); + if ( pdev ) + check_cleanup_domid_map(domain, pdev, iommu); + printk(XENLOG_ERR + "%pp: unexpected context entry %016lx_%016lx (expected %01= 6lx_%016lx)\n", + &PCI_SBDF(seg, bus, devfn), + (uint64_t)(res >> 64), (uint64_t)res, + (uint64_t)(old >> 64), (uint64_t)old); + rc =3D -EILSEQ; + goto unlock; } =20 iommu_sync_cache(context, sizeof(struct context_entry)); @@ -2630,6 +2598,15 @@ static int __init cf_check vtd_setup(void) int ret; bool reg_inval_supported =3D true; =20 + if ( unlikely(!cpu_has_cx16) ) + { + printk(XENLOG_ERR VTDPREFIX + "IOMMU: CPU doesn't support CMPXCHG16B, disabling\n"); + + ret =3D -ENOSYS; + goto error; + } + if ( list_empty(&acpi_drhd_units) ) { ret =3D -ENODEV; @@ -2692,12 +2669,7 @@ static int __init cf_check vtd_setup(void) iommu_intremap =3D iommu_intremap_off; =20 #ifndef iommu_intpost - /* - * We cannot use posted interrupt if X86_FEATURE_CX16 is - * not supported, since we count on this feature to - * atomically update 16-byte IRTE in posted format. - */ - if ( !cap_intr_post(iommu->cap) || !iommu_intremap || !cpu_has_cx1= 6 ) + if ( !cap_intr_post(iommu->cap) || !iommu_intremap ) iommu_intpost =3D false; #endif =20 --=20 2.44.0 Teddy Astie | Vates XCP-ng Intern XCP-ng & Xen Orchestra - Vates solutions web: https://vates.tech From nobody Sat May 18 08:35:53 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 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=quarantine dis=none) header.from=vates.tech ARC-Seal: i=1; a=rsa-sha256; t=1712581359; cv=none; d=zohomail.com; s=zohoarc; b=BSzMcTur0ecTNSRgzbl8cI2/equaxjNGoL6woof7LyJnCu4HKcv3evb4TqKK/fbpCio1jsMj6+dAAR0eK2U1jnZx7T4Nap128mRYlxg5+wD3qLhHSJnecPDm0fF/5ixeozHWs3hRWBzm7U4NNMC1jVIEjjO4WcdhTOlfbKRTKRQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1712581359; 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=lmg1wvOs/uJDwssyenqKN9R0+t8h06cxEawQnlJOsho=; b=QrfRKElFV9PkazllxZdhD90u/D8rX2HLfvv/FBjlE8Qz6fV2jHjxY7P5INGljRRWxZqv9JdVqrFzYvHbdyZ8vwVEny3xhKxW4JdKlNL8JJWFB0XuFzFH3zwBt7tjoTyx/j9p6NaWPe3sfNk7ijrdx8sZHvFJyu+bIKVPQjDBSxQ= 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=quarantine dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1712581359144132.19498645046463; Mon, 8 Apr 2024 06:02:39 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.701952.1096617 (Exim 4.92) (envelope-from ) id 1rtodg-0001h3-SJ; Mon, 08 Apr 2024 13:02:20 +0000 Received: by outflank-mailman (output) from mailman id 701952.1096617; Mon, 08 Apr 2024 13:02:20 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rtodg-0001gu-PD; Mon, 08 Apr 2024 13:02:20 +0000 Received: by outflank-mailman (input) for mailman id 701952; Mon, 08 Apr 2024 13:02:20 +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 1rtodg-0001Ba-3S for xen-devel@lists.xenproject.org; Mon, 08 Apr 2024 13:02:20 +0000 Received: from mail177-6.suw61.mandrillapp.com (mail177-6.suw61.mandrillapp.com [198.2.177.6]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 3ad6ff3b-f5a8-11ee-afe6-a90da7624cb6; Mon, 08 Apr 2024 15:02:19 +0200 (CEST) Received: from pmta14.mandrill.prod.suw01.rsglab.com (localhost [127.0.0.1]) by mail177-6.suw61.mandrillapp.com (Mailchimp) with ESMTP id 4VCq4V2ZQPz2K1s5n for ; Mon, 8 Apr 2024 13:02:18 +0000 (GMT) Received: from [37.26.189.201] by mandrillapp.com id e3ed585cd2d543d1b303d19dc598241b; Mon, 08 Apr 2024 13:02:18 +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: 3ad6ff3b-f5a8-11ee-afe6-a90da7624cb6 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mandrillapp.com; s=mte1; t=1712581338; x=1712841838; bh=lmg1wvOs/uJDwssyenqKN9R0+t8h06cxEawQnlJOsho=; 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=IVb48SzPIFuwyzGHykv5/PkMcXkPLRe2ovW0Ttf7dHs3ERv9oTpUxfys0k6Tj3R25 J1A4xf3jl7GP5L15YKQDv2hfydwnkUGlNQXSHfbIFK9p3s77uU5mg8NRFxWKBSCswn f3YSlKjUrHnI8BXu6eIxANRmnd+P5ErMgDeHcQQjRnVrJFqKnBBJmxaGZpz1q8HgCx M+Nu9DR1hKnrdv6Ifen6sMEradDLCW0x2WH5y2RyQf6wM0Em2Hmwqe7IzoFKXdhZq8 0z9Mp79nYjFGKa70C7zLKkCLAMmuaKO/uj1vngRapfHbiWr5jirgUpOwHDMGRYeZuP AXbkcp08jVVLA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=vates.tech; s=mte1; t=1712581338; x=1712841838; i=teddy.astie@vates.tech; bh=lmg1wvOs/uJDwssyenqKN9R0+t8h06cxEawQnlJOsho=; 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=MC6Xlx3/AJ9bGIKjcLXCrESsQx73xqIin/09TWI6gTDikG4Q54MxXLncT6g96vP/N HHrAmkbRpIxs+6ce1y4H/OxSnNAEFBH0QhXqV10nKBLKnyYDrEjg0FrSgXpS+M6nyx sfLsbHUKSlW7ppOpgZjQgHqB+3N9dSzTGnhdwhuYT3fDZXZXy+W5iLL4l528QHXe88 aH0sGVMAtGpopjDZEF4Wqj44U4y1zeLYoET68C2jwzl+oFSOR0CevP2hzTCcQdaOQt 0Wqhqxhf9uYhRs3E/mQf5iMPTswHfuBF7c5WznkfSU5raEqQwHu33L7jmRCU7RY0Ui HAfq6V2p+QWxA== From: Teddy Astie Subject: =?utf-8?Q?[XEN=20PATCH=20v2=202/3]=20AMD-Vi:=20Disable=20IOMMU=20if=20cx16=20isn't=20supported?= X-Mailer: git-send-email 2.44.0 X-Bm-Disclaimer: Yes X-Bm-Milter-Handled: 4ffbd6c1-ee69-4e1b-aabd-f977039bd3e2 X-Bm-Transport-Timestamp: 1712581335662 To: xen-devel@lists.xenproject.org Cc: Teddy Astie , Jan Beulich , Andrew Cooper , =?utf-8?Q?Roger=20Pau=20Monn=C3=A9?= Message-Id: <80112e79fe7f5c27e685c98f95462b4912770682.1712580356.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.e3ed585cd2d543d1b303d19dc598241b?= X-Mandrill-User: md_30504962 Feedback-ID: 30504962:30504962.20240408:md Date: Mon, 08 Apr 2024 13:02:18 +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: 1712581359365100003 Content-Type: text/plain; charset="utf-8" No hardware has AMD-Vi support while not having cx16 support, disable IOMMU in this case to avoid potentially buggy code. Now that IOMMU is only enabled if cx16 is supported, drop dead code that handles cases where cx16 isn't supported. Suggested-by: Andrew Cooper Signed-off-by: Teddy Astie --- xen/drivers/passthrough/amd/iommu_map.c | 42 +++++++-------------- xen/drivers/passthrough/amd/pci_amd_iommu.c | 6 +++ 2 files changed, 20 insertions(+), 28 deletions(-) diff --git a/xen/drivers/passthrough/amd/iommu_map.c b/xen/drivers/passthro= ugh/amd/iommu_map.c index e0f4fe736a..f67975e700 100644 --- a/xen/drivers/passthrough/amd/iommu_map.c +++ b/xen/drivers/passthrough/amd/iommu_map.c @@ -167,15 +167,14 @@ int amd_iommu_set_root_page_table(struct amd_iommu_dt= e *dte, { bool valid =3D flags & SET_ROOT_VALID; =20 - if ( dte->v && dte->tv && - (cpu_has_cx16 || (flags & SET_ROOT_WITH_UNITY_MAP)) ) + if ( dte->v && dte->tv ) { union { struct amd_iommu_dte dte; uint64_t raw64[4]; __uint128_t raw128[2]; } ldte =3D { .dte =3D *dte }; - __uint128_t old =3D ldte.raw128[0]; + __uint128_t res, old =3D ldte.raw128[0]; int ret =3D 0; =20 ldte.dte.domain_id =3D domain_id; @@ -185,33 +184,20 @@ int amd_iommu_set_root_page_table(struct amd_iommu_dt= e *dte, ldte.dte.paging_mode =3D paging_mode; ldte.dte.v =3D valid; =20 - if ( cpu_has_cx16 ) - { - __uint128_t res =3D cmpxchg16b(dte, &old, &ldte.raw128[0]); + res =3D cmpxchg16b(dte, &old, &ldte.raw128[0]); =20 - /* - * Hardware does not update the DTE behind our backs, so the - * return value should match "old". - */ - if ( res !=3D old ) - { - printk(XENLOG_ERR - "Dom%d: unexpected DTE %016lx_%016lx (expected %016= lx_%016lx)\n", - domain_id, - (uint64_t)(res >> 64), (uint64_t)res, - (uint64_t)(old >> 64), (uint64_t)old); - ret =3D -EILSEQ; - } - } - else /* Best effort, updating domain_id last. */ + /* + * Hardware does not update the DTE behind our backs, so the + * return value should match "old". + */ + if ( res !=3D old ) { - uint64_t *ptr =3D (void *)dte; - - write_atomic(ptr + 0, ldte.raw64[0]); - /* No barrier should be needed between these two. */ - write_atomic(ptr + 1, ldte.raw64[1]); - - ret =3D 1; + printk(XENLOG_ERR + "Dom%d: unexpected DTE %016lx_%016lx (expected %016lx_%= 016lx)\n", + domain_id, + (uint64_t)(res >> 64), (uint64_t)res, + (uint64_t)(old >> 64), (uint64_t)old); + ret =3D -EILSEQ; } =20 return ret; diff --git a/xen/drivers/passthrough/amd/pci_amd_iommu.c b/xen/drivers/pass= through/amd/pci_amd_iommu.c index f6efd88e36..656c5eda5d 100644 --- a/xen/drivers/passthrough/amd/pci_amd_iommu.c +++ b/xen/drivers/passthrough/amd/pci_amd_iommu.c @@ -312,6 +312,12 @@ static int __init cf_check iov_detect(void) return -ENODEV; } =20 + if ( unlikely(!cpu_has_cx16) ) + { + printk("AMD-Vi: CPU doesn't support CMPXCHG16B, disabling\n"); + return -ENOSYS; + } + init_done =3D 1; =20 if ( !amd_iommu_perdev_intremap ) --=20 2.44.0 Teddy Astie | Vates XCP-ng Intern XCP-ng & Xen Orchestra - Vates solutions web: https://vates.tech From nobody Sat May 18 08:35:53 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 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=quarantine dis=none) header.from=vates.tech ARC-Seal: i=1; a=rsa-sha256; t=1712581359; cv=none; d=zohomail.com; s=zohoarc; b=bOVBpN6Zd13+ITxdwJ038xVw9r9ItOzlh4h3/wsaWjzZls49gdVkwAfEecbjOI1wpLT4o270VjaxwHBoj989VUp40clTcGlyZgEAHETm/xHH+t60T2vZdUKYIkUbEEsvPuIadowFCJo/dmkDJiN1BhpDxhVSNumqdwSEwaOxwJc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1712581359; 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=nCr/dQ7MOvz4AtUAz90cOrY6iTnWRg80lBBHOoVQiPc=; b=Lc8GDdN7iudOpEvwYl7x/cVK1khZSbpj/tVdN5+HOiyEtA6haOVUcj0osfaqPT2EDGKcVeMoA0oGEggJp7D6RBYzXytS67918AEPTKNz1c2TgD9B8IyHbM36ji2ohTce3ULGvcEOCkxoIZUTQ+/XTDASgmdeeuUZrKJynHmMq9Y= 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=quarantine dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1712581358982235.79482428551523; Mon, 8 Apr 2024 06:02:38 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.701953.1096626 (Exim 4.92) (envelope-from ) id 1rtodi-0001wj-3K; Mon, 08 Apr 2024 13:02:22 +0000 Received: by outflank-mailman (output) from mailman id 701953.1096626; Mon, 08 Apr 2024 13:02:22 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rtodi-0001wa-0M; Mon, 08 Apr 2024 13:02:22 +0000 Received: by outflank-mailman (input) for mailman id 701953; Mon, 08 Apr 2024 13:02:21 +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 1rtodh-0001Ba-8n for xen-devel@lists.xenproject.org; Mon, 08 Apr 2024 13:02:21 +0000 Received: from mail177-6.suw61.mandrillapp.com (mail177-6.suw61.mandrillapp.com [198.2.177.6]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 3bf99a28-f5a8-11ee-afe6-a90da7624cb6; Mon, 08 Apr 2024 15:02:20 +0200 (CEST) Received: from pmta14.mandrill.prod.suw01.rsglab.com (localhost [127.0.0.1]) by mail177-6.suw61.mandrillapp.com (Mailchimp) with ESMTP id 4VCq4X2hWGz2K1ttS for ; Mon, 8 Apr 2024 13:02:20 +0000 (GMT) Received: from [37.26.189.201] by mandrillapp.com id a3802b0a34d545169485f79ab33fff0c; Mon, 08 Apr 2024 13:02:20 +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: 3bf99a28-f5a8-11ee-afe6-a90da7624cb6 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mandrillapp.com; s=mte1; t=1712581340; x=1712841840; bh=nCr/dQ7MOvz4AtUAz90cOrY6iTnWRg80lBBHOoVQiPc=; 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=hSZXAVC6IirS3MMUs7cOjAbhOVYpnI7RrQu17ul5SuEcYktNz8yxGCBmKNFNeRNXv 98kC/Cs7fN0Y4NRcG0kOtlsp7yVjVl3UGMaEsuVv+1YMpj0pbKuiCdqrbJnmqIbo0v uFgAjiDoyZBlR3/b68B8TsgCDLBqVG5iAJGlUdzMgAjK9YShDUJgx4gpHk5DmQ6zKe 8KTi+udlN0eihp3vrd448BB3NTT7jol1OTPBs3DTyPKs4+8HuLiO/VSw5M4OmWSb5N D0vrvi5dpHb9bL9OmhSYMEVd05lhG7m//60c3qKXrISrbX8k5xIECuRi/jMfr2NAi2 +3fRgVH/wl4AQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=vates.tech; s=mte1; t=1712581340; x=1712841840; i=teddy.astie@vates.tech; bh=nCr/dQ7MOvz4AtUAz90cOrY6iTnWRg80lBBHOoVQiPc=; 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=m7xAmt2QSFYru2Wp0XMobiPlRPmmJSPCVlm4j6phcKLPmWYgNdslduMxuF+BaDinS mR+/31IQ97caHtcGB6PjFUfpCU1lZNN3qTBCQSc2Q3fI/RhCD4YFPyCHxqmlWHTlyM Uz2epdGoR0csT7l1xjbqL+VQ1LN22PytPVyrV6APVxD+rw6PR5pWA8Ruhp6RDFPpLI SA7JvYU4G9tTEkLYOBsmbE2kh8FFR+NyJG1CtVt99r4vBZHc44su/2sS+y6DIbILLv 6O0xSBp/yYZ8GcWQgaOtREMIVTgxyNWCHf7jUjBHtd2ZOBGz4FWAgQqXstFCOuW3DH 9kFsCrQnAoPGA== From: Teddy Astie Subject: =?utf-8?Q?[XEN=20PATCH=20v2=203/3]=20VT-d:=20Cleanup=20MAP=5FSINGLE=5FDEVICE=20and=20related=20code?= X-Mailer: git-send-email 2.44.0 X-Bm-Disclaimer: Yes X-Bm-Milter-Handled: 4ffbd6c1-ee69-4e1b-aabd-f977039bd3e2 X-Bm-Transport-Timestamp: 1712581337631 To: xen-devel@lists.xenproject.org Cc: Teddy Astie , Jan Beulich , Andrew Cooper , =?utf-8?Q?Roger=20Pau=20Monn=C3=A9?= Message-Id: 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.a3802b0a34d545169485f79ab33fff0c?= X-Mandrill-User: md_30504962 Feedback-ID: 30504962:30504962.20240408:md Date: Mon, 08 Apr 2024 13:02:20 +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: 1712581361390100005 Content-Type: text/plain; charset="utf-8" This flag was only used in case cx16 is not available, as those code paths = no longer exist, this flag now does basically nothing. Suggested-by: Andrew Cooper Signed-off-by: Teddy Astie --- xen/drivers/passthrough/vtd/iommu.c | 12 +++--------- xen/drivers/passthrough/vtd/vtd.h | 5 ++--- 2 files changed, 5 insertions(+), 12 deletions(-) diff --git a/xen/drivers/passthrough/vtd/iommu.c b/xen/drivers/passthrough/= vtd/iommu.c index 47b56f37a9..4b15e6da79 100644 --- a/xen/drivers/passthrough/vtd/iommu.c +++ b/xen/drivers/passthrough/vtd/iommu.c @@ -1692,15 +1692,9 @@ static int domain_context_mapping(struct domain *dom= ain, u8 devfn, break; } =20 - if ( domain !=3D pdev->domain && pdev->domain !=3D dom_io ) - { - if ( pdev->domain->is_dying ) - mode |=3D MAP_OWNER_DYING; - else if ( drhd && - !any_pdev_behind_iommu(pdev->domain, pdev, drhd->iommu) = && - !pdev->phantom_stride ) - mode |=3D MAP_SINGLE_DEVICE; - } + if ( domain !=3D pdev->domain && pdev->domain !=3D dom_io && + pdev->domain->is_dying ) + mode |=3D MAP_OWNER_DYING; =20 switch ( pdev->type ) { diff --git a/xen/drivers/passthrough/vtd/vtd.h b/xen/drivers/passthrough/vt= d/vtd.h index cb2df76eed..43f06a353d 100644 --- a/xen/drivers/passthrough/vtd/vtd.h +++ b/xen/drivers/passthrough/vtd/vtd.h @@ -28,9 +28,8 @@ */ #define MAP_WITH_RMRR (1u << 0) #define MAP_OWNER_DYING (1u << 1) -#define MAP_SINGLE_DEVICE (1u << 2) -#define MAP_ERROR_RECOVERY (1u << 3) -#define UNMAP_ME_PHANTOM_FUNC (1u << 4) +#define MAP_ERROR_RECOVERY (1u << 2) +#define UNMAP_ME_PHANTOM_FUNC (1u << 3) =20 /* Allow for both IOAPIC and IOSAPIC. */ #define IO_xAPIC_route_entry IO_APIC_route_entry --=20 2.44.0 Teddy Astie | Vates XCP-ng Intern XCP-ng & Xen Orchestra - Vates solutions web: https://vates.tech