From patchwork Mon Apr 15 12:16:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Teddy Astie X-Patchwork-Id: 13629897 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 5E0EDC04FFF for ; Mon, 15 Apr 2024 12:16:47 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.706124.1103183 (Exim 4.92) (envelope-from ) id 1rwLGD-0006vg-TE; Mon, 15 Apr 2024 12:16:33 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 706124.1103183; Mon, 15 Apr 2024 12:16:33 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rwLGD-0006vY-Q1; Mon, 15 Apr 2024 12:16:33 +0000 Received: by outflank-mailman (input) for mailman id 706124; Mon, 15 Apr 2024 12:16:31 +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 1rwLGB-0006Sb-Ji for xen-devel@lists.xenproject.org; Mon, 15 Apr 2024 12:16:31 +0000 Received: from mail5.us4.mandrillapp.com (mail5.us4.mandrillapp.com [205.201.136.5]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id fca20e38-fb21-11ee-b908-491648fe20b8; Mon, 15 Apr 2024 14:16:29 +0200 (CEST) Received: from pmta15.mandrill.prod.suw01.rsglab.com (localhost [127.0.0.1]) by mail5.us4.mandrillapp.com (Mailchimp) with ESMTP id 4VJ5kN0Q8xzDRHx8L for ; Mon, 15 Apr 2024 12:16:28 +0000 (GMT) Received: from [37.26.189.201] by mandrillapp.com id 5940a3e6221749998ac9aca906e84254; Mon, 15 Apr 2024 12:16:27 +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: fca20e38-fb21-11ee-b908-491648fe20b8 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mandrillapp.com; s=mte1; t=1713183388; x=1713443888; bh=N55hC69B7xJL3Kv7A7B9tNKAYd1n2HnGpDoxaSJnBes=; 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=bcY4bLo6Tngd9910qD9P9AuopNav7PQ3rhdRCf277Ef/iWENJfyn0w4cbxgwTlX2V sSUVq5UahlurNBJcLnKcYpIr2mSsoQcA0CJ8MYmlHb/P/25caGhu/ZKA0NCjqVr5JR 8OxI7fiu5UXgNXjnvFO8UpKOZpv8VJerPemUVLFqe2ZAz5Uy+1bA/VgRFKGWYL/xuo 3B8BxJgM/YP+SgPzdzfVejnct3LTHEtWmXV5FJ88YgHlsgRIJPRqMg56j5dhrQLshe PXdO+rHBRdGBSW4h2No0ymisKG/IyVEfU71JqwaidvwxLC9BWWCnl6Qa0eDjwvfqRw KtNDR+0uKZlUw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=vates.tech; s=mte1; t=1713183388; x=1713443888; i=teddy.astie@vates.tech; bh=N55hC69B7xJL3Kv7A7B9tNKAYd1n2HnGpDoxaSJnBes=; 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=v2SfJIbwokjLYSpPyKgyooUHE1MuI9xbjPbqmGhGmHTGthMRTx3+gU1l23OAkuSS2 hA9Wb0YBDOZ3aOH83JXFXzn+oe3ecmfrPiZONqYFHUuiswpIciaHWKkvJ/UfS4ybs9 JlOKYRYhS1eUesqZgMrvHZFAIZCB9ogkUhBe8QQdLixbr2kWATp6wLDMlV161lLBv4 WUfeRzj1MNbzB1zaWLOpUZfo/tDYSEE2SrAPsKD1BB8T+nJ3YYnoWlLxIBzPYJGKq8 HlLaxycuDdVxp8nZwU/my09g84TPf5cScroQKX8DJDZeByiTKlzwaZlG6zxbcXDplz MPxI/0aSnaNFw== From: Teddy Astie Subject: =?utf-8?q?=5BXEN_PATCH_v4_4/5=5D_VT-d=3A_Disable_intrerrupt_remappi?= =?utf-8?q?ng_if_cx16_is_not_supported?= 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: 1713183387080 To: xen-devel@lists.xenproject.org Cc: Teddy Astie , Andrew Cooper Message-Id: In-Reply-To: References: X-Native-Encoded: 1 X-Report-Abuse: =?utf-8?q?Please_forward_a_copy_of_this_message=2C_including?= =?utf-8?q?_all_headers=2C_to_abuse=40mandrill=2Ecom=2E_You_can_also_report_?= =?utf-8?q?abuse_here=3A_https=3A//mandrillapp=2Ecom/contact/abuse=3Fid=3D30?= =?utf-8?q?504962=2E5940a3e6221749998ac9aca906e84254?= X-Mandrill-User: md_30504962 Feedback-ID: 30504962:30504962.20240415:md Date: Mon, 15 Apr 2024 12:16:27 +0000 MIME-Version: 1.0 All hardware with VT-d has CMPXCHG16B support. Check this at initialisation time, and remove the effectively-dead logic for the non-cx16 case. Suggested-by: Andrew Cooper Signed-off-by: Teddy Astie --- xen/drivers/passthrough/vtd/intremap.c | 70 ++++++++------------------ xen/drivers/passthrough/vtd/iommu.c | 7 +-- 2 files changed, 21 insertions(+), 56 deletions(-) diff --git a/xen/drivers/passthrough/vtd/intremap.c b/xen/drivers/passthrough/vtd/intremap.c index c504852eb8..7d4d907b4f 100644 --- a/xen/drivers/passthrough/vtd/intremap.c +++ b/xen/drivers/passthrough/vtd/intremap.c @@ -150,6 +150,13 @@ bool __init cf_check intel_iommu_supports_eim(void) if ( !iommu_qinval || !iommu_intremap || list_empty(&acpi_drhd_units) ) return false; + if ( unlikely(!cpu_has_cx16) ) + { + printk(XENLOG_WARNING VTDPREFIX + "CPU doesn't support CMPXCHG16B, disable interrupt remapping\n"); + return false; + } + /* We MUST have a DRHD unit for each IOAPIC. */ for ( apic = 0; apic < nr_ioapics; apic++ ) if ( !ioapic_to_drhd(IO_APIC_ID(apic)) ) @@ -173,47 +180,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 qword 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 *entry, const struct iremap_entry *new_ire, bool atomic) { - ASSERT(spin_is_locked(&iommu->intremap.lock)); + __uint128_t ret; + struct iremap_entry old_ire; - if ( cpu_has_cx16 ) - { - __uint128_t ret; - struct iremap_entry old_ire; + ASSERT(spin_is_locked(&iommu->intremap.lock)); - old_ire = *entry; - ret = cmpxchg16b(entry, &old_ire, new_ire); + old_ire = *entry; + ret = cmpxchg16b(entry, &old_ire, new_ire); - /* - * 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 == 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 == new_ire->lo ) - write_atomic(&entry->hi, new_ire->hi); - else if ( entry->hi == new_ire->hi ) - write_atomic(&entry->lo, new_ire->lo); - else if ( !atomic ) - *entry = *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 == old_ire.val); } /* Mark specified intr remap entry as free */ @@ -395,7 +381,6 @@ static int ioapic_rte_to_remap_entry(struct vtd_iommu *iommu, /* Indicate remap format. */ remap_rte->format = 1; - /* 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 +422,6 @@ void cf_check io_apic_write_remap_rte( bool masked = true; int rc; - 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 = __ioapic_read_entry(apic, pin, true); - if ( !old_rte.mask ) - { - masked = false; - old_rte.mask = 1; - __ioapic_write_entry(apic, pin, true, old_rte); - } - } - /* Not the initializer, for old gcc to cope. */ new_rte.raw = rte; diff --git a/xen/drivers/passthrough/vtd/iommu.c b/xen/drivers/passthrough/vtd/iommu.c index 7c6bae0256..a1bd3c5ff6 100644 --- a/xen/drivers/passthrough/vtd/iommu.c +++ b/xen/drivers/passthrough/vtd/iommu.c @@ -2663,12 +2663,7 @@ static int __init cf_check vtd_setup(void) iommu_intremap = iommu_intremap_off; #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_cx16 ) + if ( !cap_intr_post(iommu->cap) || !iommu_intremap ) iommu_intpost = false; #endif