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: 13629898 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 3BF6AC05024 for ; Mon, 15 Apr 2024 12:16:48 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.706123.1103167 (Exim 4.92) (envelope-from ) id 1rwLGB-0006W9-MP; Mon, 15 Apr 2024 12:16:31 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 706123.1103167; Mon, 15 Apr 2024 12:16:31 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rwLGB-0006V3-It; Mon, 15 Apr 2024 12:16:31 +0000 Received: by outflank-mailman (input) for mailman id 706123; Mon, 15 Apr 2024 12:16:30 +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 1rwLGA-0006Sb-JU for xen-devel@lists.xenproject.org; Mon, 15 Apr 2024 12:16:30 +0000 Received: from mail145-16.atl61.mandrillapp.com (mail145-16.atl61.mandrillapp.com [198.2.145.16]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id fc1438ec-fb21-11ee-b908-491648fe20b8; Mon, 15 Apr 2024 14:16:28 +0200 (CEST) Received: from pmta06.mandrill.prod.atl01.rsglab.com (localhost [127.0.0.1]) by mail145-16.atl61.mandrillapp.com (Mailchimp) with ESMTP id 4VJ5kM28glz8XRtNL for ; Mon, 15 Apr 2024 12:16:27 +0000 (GMT) Received: from [37.26.189.201] by mandrillapp.com id 8426781ae7c74282b1e6f20712725546; 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: fc1438ec-fb21-11ee-b908-491648fe20b8 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mandrillapp.com; s=mte1; t=1713183387; x=1713443887; bh=pVW5u35fq+zXx1B2L8XZPx9h9eXL6mZato+52jJIsMA=; 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=yL1Mr6ZTczaYfHsPFN4XTWjm4qiJyRYGH+LI2gzrNgtb21EgaVN1Y2rRD60uqvrP6 zz8C8U7lJLww00F+/SovfYm1qU8w40douXQicu3OTLFpRX9GxxzmjQ1s/KSGNCKeoo EAzhTE9IPIAKv9AUSgJI4itExMJZQ7OwxqHhW+4zuJB6yb8r6sNiaR4NU9KVMZ6roz FiHyKL+Nyve6hHOvGR8d3eDqd6LeQ0dl6I+/ZZUFT0H6Bb3kK+wLEfyfBm7CW3jLC4 F5oK+RJtV1TGYNUYQ9sshf2B/RCjG2h6sjkofrnyNMKWngIpsWcaevRILa0Fou5bVG /XhOvT+rB37+A== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=vates.tech; s=mte1; t=1713183387; x=1713443887; i=teddy.astie@vates.tech; bh=pVW5u35fq+zXx1B2L8XZPx9h9eXL6mZato+52jJIsMA=; 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=UmfWPwzlkKnvKJo1IhUYm6sd2WMBdqKSDOIpv6g0yAro8eN3OeX6++w3tGaPwCfIi B4ow3VSfkEwdhfmC/wDgeckisISoA0sH8QDNNBkroK59GI1VxSOnY5IllsMxftXa+Z aSAQb9G0yoRTM2zY35HNaF6RukpqjZvp2uQYBvsQkuknSCwnI+Ge1eOqqV5XVZGdb6 rLIubdMh0XTUBLIkzH64P3mAqRHZCLsCYfkHMip0E9WwFE0kW32VFCn0HU/oBe6tf/ dC1qmenMTMs+95YSzCRSbNGwr95ANQjiEf8Yp7TYTwsa+8LAL93m3dfP2/wYyYDTD7 bmVrxXhlJxCFQ== From: Teddy Astie Subject: =?utf-8?q?=5BXEN_PATCH_v4_2/5=5D_AMD-Vi=3A_Disable_IOMMU_if_cx16_is?= =?utf-8?q?n=27t_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: 1713183386410 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=2E8426781ae7c74282b1e6f20712725546?= 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 AMD-Vi has CMPXCHG16 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/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/passthrough/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_dte *dte, { bool valid = flags & SET_ROOT_VALID; - 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 = { .dte = *dte }; - __uint128_t old = ldte.raw128[0]; + __uint128_t res, old = ldte.raw128[0]; int ret = 0; ldte.dte.domain_id = domain_id; @@ -185,33 +184,20 @@ int amd_iommu_set_root_page_table(struct amd_iommu_dte *dte, ldte.dte.paging_mode = paging_mode; ldte.dte.v = valid; - if ( cpu_has_cx16 ) - { - __uint128_t res = cmpxchg16b(dte, &old, &ldte.raw128[0]); + res = cmpxchg16b(dte, &old, &ldte.raw128[0]); - /* - * Hardware does not update the DTE behind our backs, so the - * return value should match "old". - */ - if ( res != old ) - { - 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 = -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 != old ) { - uint64_t *ptr = (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 = 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 = -EILSEQ; } return ret; diff --git a/xen/drivers/passthrough/amd/pci_amd_iommu.c b/xen/drivers/passthrough/amd/pci_amd_iommu.c index f6efd88e36..3a6a23f706 100644 --- a/xen/drivers/passthrough/amd/pci_amd_iommu.c +++ b/xen/drivers/passthrough/amd/pci_amd_iommu.c @@ -305,6 +305,12 @@ static int __init cf_check iov_detect(void) if ( !iommu_enable && !iommu_intremap ) return 0; + if ( unlikely(!cpu_has_cx16) ) + { + printk("AMD-Vi: CPU doesn't support CMPXCHG16B, disabling\n"); + return -ENODEV; + } + if ( (init_done ? amd_iommu_init_late() : amd_iommu_init(false)) != 0 ) {