From nobody Wed Nov 19 01:54:31 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=1762961894; cv=none; d=zohomail.com; s=zohoarc; b=G5+GXRf+VX+iHZUMLc40Xt/vEcuQaTWJI3bOIfECz8bhwApa1xVYDlroUZO1BBOetI9O9ZKm0jcD+FBAXM7moHqzmV8qnCyvgjBF16k96BxqiI7WDZWM/qmCh8oz7EFNScbzsDATPlCuQMbx2nsrX4xD9Eo4TGw6TBnh6leIMKo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1762961894; 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=J9x4ke0xLc2x3x8APrrN6CRsBsF1UIlxpCMJLxJb3Gg=; b=SJrCuv+9orkh+gw/kifuzo3iGeIPEobFqevJRNAvlm1w5pS92lD639Se+d4C6xhvCC582iAgwQ96XKrGLYvlFKFegnY3l8HrBAJdNx5CcuBQJWzrLUf3CqIN1ifrQ2SSd4HcFnCPDgxsXsvKqw7OTY4mQ/Jc4NjcH2DZy3JrGUk= 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 1762961894698111.04164083038188; Wed, 12 Nov 2025 07:38:14 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.1160077.1488301 (Exim 4.92) (envelope-from ) id 1vJCv2-0007vV-Jk; Wed, 12 Nov 2025 15:38:00 +0000 Received: by outflank-mailman (output) from mailman id 1160077.1488301; Wed, 12 Nov 2025 15:38:00 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1vJCv2-0007vO-F4; Wed, 12 Nov 2025 15:38:00 +0000 Received: by outflank-mailman (input) for mailman id 1160077; Wed, 12 Nov 2025 15:37:59 +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 1vJCv1-0007vC-3g for xen-devel@lists.xenproject.org; Wed, 12 Nov 2025 15:37:59 +0000 Received: from mail136-17.atl41.mandrillapp.com (mail136-17.atl41.mandrillapp.com [198.2.136.17]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 8fdb73a7-bfdd-11f0-9d18-b5c5bf9af7f9; Wed, 12 Nov 2025 16:37:57 +0100 (CET) Received: from pmta11.mandrill.prod.atl01.rsglab.com (localhost [127.0.0.1]) by mail136-17.atl41.mandrillapp.com (Mailchimp) with ESMTP id 4d66x00Lp0zPm0XnY for ; Wed, 12 Nov 2025 15:37:56 +0000 (GMT) Received: from [37.26.189.201] by mandrillapp.com id ca881e3520284e09af5a0d4a5edb2e05; Wed, 12 Nov 2025 15:37:55 +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: 8fdb73a7-bfdd-11f0-9d18-b5c5bf9af7f9 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mandrillapp.com; s=mte1; t=1762961876; x=1763231876; bh=J9x4ke0xLc2x3x8APrrN6CRsBsF1UIlxpCMJLxJb3Gg=; 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=bobo2YqkI0DN8lMnubvtH1DhxBMTxBW1NrqIN7Lmp0AJPCJPs+6F0c78+p2oxCmbS 2TM+11FnYMk5iLKgSq+yFhTZ6HKKxpG+U8WmarnxO7H+sC4635ODuOiq4hl/BWT2yw mIitzn23mvugWJoW8BTvtSIpQsYdrSZXW4zYAFUXoKmzUE5UgoID5tT8oDzTu2Ud3H 5H4IIJFuaL8F5SV5x5ln1sHfY4DRKLk8HAhAgOmFX8YC/fmfl+QKFeDF/RSVDh6mXT XPosCKqZCOHhi08fAp+q7YXJLBKFFn8RqrDmeK6JIMVYPkQr81XqHKPqoInPsyJNUW mYvTghtoe2sPA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=vates.tech; s=mte1; t=1762961876; x=1763222376; i=teddy.astie@vates.tech; bh=J9x4ke0xLc2x3x8APrrN6CRsBsF1UIlxpCMJLxJb3Gg=; 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=Shcu5diDseLfdZWVYNHW0OzCuKA6bHs4szVgFdQq5vHIdxo8Gtq0enZ3W0g8+43cJ ODwph8ONPm5R+yXvZFya7gG6ne+lV6wrpkcdXx9a2Wtk91jAtBcz/99jgY/oEUzom7 y3PKVYiaAjiszWAse8A8l4TaPEwdbTsxiydjCw7gGfJogb1J0k9yibw1QfuQsA8NdJ axExwtIx7F3X7iC68muDARKne+CZlEm+70O9L5L2fKDlGM4rQ2WAXsP4+P8ukkGWHQ E+3mELp47+ZlSefKHEMu9QPo1EcJ8pwQs2qT8jwfjb0rSCLOP+8XFDnxWWwzjOce/Y Si74+KyEynDrg== From: "Teddy Astie" Subject: =?utf-8?Q?[PATCH=201/2]=20amd/iommu:=20Always=20atomically=20update=20DTE?= X-Mailer: git-send-email 2.51.2 X-Bm-Disclaimer: Yes X-Bm-Milter-Handled: 4ffbd6c1-ee69-4e1b-aabd-f977039bd3e2 X-Bm-Transport-Timestamp: 1762961874465 To: xen-devel@lists.xenproject.org Cc: "Teddy Astie" , "Jan Beulich" , "Andrew Cooper" , "=?utf-8?Q?Roger=20Pau=20Monn=C3=A9?=" , "Jason Andryuk" 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.ca881e3520284e09af5a0d4a5edb2e05?= X-Mandrill-User: md_30504962 Feedback-ID: 30504962:30504962.20251112:md Date: Wed, 12 Nov 2025 15:37:55 +0000 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @mandrillapp.com) (identity teddy.astie@vates.tech) X-ZM-MESSAGEID: 1762961897598153000 Content-Type: text/plain; charset="utf-8" amd_iommu_set_root_page_table chooses between updating atomically and non-atomically depending on whether the DTE is active or not. This choice existed mostly because cx16 wasn't supposed always available until [1]. Thus we don't need to threat the non-atomic path in a special way anymore. By rearranging slightly the atomic path, we can make it cover all the cases which improves the code generation at the expense of systematically perform= ing cmpxchg16b. Also remove unused raw64 fields of ldte, and the deprecated comment as the function actually behaves in a more usual way and can't return >0. [1] 2636fcdc15c7 "x86/iommu: check for CMPXCHG16B when enabling IOMMU" Signed-off-by: Teddy Astie --- xen/drivers/passthrough/amd/iommu_map.c | 78 ++++++++----------------- 1 file changed, 25 insertions(+), 53 deletions(-) diff --git a/xen/drivers/passthrough/amd/iommu_map.c b/xen/drivers/passthro= ugh/amd/iommu_map.c index 320a2dc64c..e3165d93aa 100644 --- a/xen/drivers/passthrough/amd/iommu_map.c +++ b/xen/drivers/passthrough/amd/iommu_map.c @@ -154,69 +154,41 @@ static void set_iommu_ptes_present(unsigned long pt_m= fn, unmap_domain_page(table); } =20 -/* - * This function returns - * - -errno for errors, - * - 0 for a successful update, atomic when necessary - * - 1 for a successful but non-atomic update, which may need to be warned - * about by the caller. - */ int amd_iommu_set_root_page_table(struct amd_iommu_dte *dte, uint64_t root_ptr, uint16_t domain_id, uint8_t paging_mode, unsigned int flags) { bool valid =3D flags & SET_ROOT_VALID; =20 - 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 res, old =3D ldte.raw128[0]; - int ret =3D 0; - - ldte.dte.domain_id =3D domain_id; - ldte.dte.pt_root =3D paddr_to_pfn(root_ptr); - ldte.dte.iw =3D true; - ldte.dte.ir =3D true; - ldte.dte.paging_mode =3D paging_mode; - ldte.dte.v =3D valid; - - res =3D cmpxchg16b(dte, &old, &ldte.raw128[0]); - - /* - * 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 %016lx_%= 016lx)\n", - domain_id, - (uint64_t)(res >> 64), (uint64_t)res, - (uint64_t)(old >> 64), (uint64_t)old); - ret =3D -EILSEQ; - } + union { + struct amd_iommu_dte dte; + __uint128_t raw128[2]; + } ldte =3D { .dte =3D *dte }; + __uint128_t res, old =3D ldte.raw128[0]; =20 - return ret; - } + ldte.dte.domain_id =3D domain_id; + ldte.dte.pt_root =3D paddr_to_pfn(root_ptr); + ldte.dte.iw =3D true; + ldte.dte.ir =3D true; + ldte.dte.paging_mode =3D paging_mode; + ldte.dte.tv =3D true; + ldte.dte.v =3D valid; + + res =3D cmpxchg16b(dte, &old, &ldte.raw128[0]); =20 - if ( valid || dte->v ) + /* + * Hardware does not update the DTE behind our backs, so the + * return value should match "old". + */ + if ( res !=3D old ) { - dte->tv =3D false; - dte->v =3D true; - smp_wmb(); + printk(XENLOG_ERR + "Dom%d: unexpected DTE %016lx_%016lx (expected %016lx_%016= lx)\n", + domain_id, + (uint64_t)(res >> 64), (uint64_t)res, + (uint64_t)(old >> 64), (uint64_t)old); + return -EILSEQ; } - dte->domain_id =3D domain_id; - dte->pt_root =3D paddr_to_pfn(root_ptr); - dte->iw =3D true; - dte->ir =3D true; - dte->paging_mode =3D paging_mode; - smp_wmb(); - dte->tv =3D true; - dte->v =3D valid; =20 return 0; } --=20 2.51.2 -- Teddy Astie | Vates XCP-ng Developer XCP-ng & Xen Orchestra - Vates solutions web: https://vates.tech From nobody Wed Nov 19 01:54:31 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=1762961895; cv=none; d=zohomail.com; s=zohoarc; b=JQQMpg1FVsQ5+zH+SK3PQaER+g5y0uryu/G2I75u1jOrTztKjxwP57HpJXZ+bGge04WjGGLu+22C1Pgy/Yzskmm2NnfmEbL5qvKesYT+uuCRoQyrzf+tWvpGqyXjb19e+U1xdgmSL+OQDdxgWhqxfz2rvJf+UHvYbBlgG+3VdxI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1762961895; 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=kCjQ/w4mi64pHFYbQXYYAj4/n0muw09kfLASyhbwR3Y=; b=i7GD3yaiIBYXRr0kJXmheyW2uOxTrvDTuJWj+VjU8cXaEjcTmaOF0GM7ScoNjKKtDrmkEet+L3bLDIqshZtdqQf8zG0njALyIkEytrEVfDRzKJdfyTZZWI9Ji4fzEOCVhhIpvAU39M0db5q7XYpZO5lm+5iqmK2DpOOeRxs6/1A= 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 1762961895421826.2521023589258; Wed, 12 Nov 2025 07:38:15 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.1160078.1488310 (Exim 4.92) (envelope-from ) id 1vJCv4-00089e-Ov; Wed, 12 Nov 2025 15:38:02 +0000 Received: by outflank-mailman (output) from mailman id 1160078.1488310; Wed, 12 Nov 2025 15:38:02 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1vJCv4-00089X-Lu; Wed, 12 Nov 2025 15:38:02 +0000 Received: by outflank-mailman (input) for mailman id 1160078; Wed, 12 Nov 2025 15:38:00 +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 1vJCv2-0007vC-HH for xen-devel@lists.xenproject.org; Wed, 12 Nov 2025 15:38:00 +0000 Received: from mail136-17.atl41.mandrillapp.com (mail136-17.atl41.mandrillapp.com [198.2.136.17]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 912f6e0e-bfdd-11f0-9d18-b5c5bf9af7f9; Wed, 12 Nov 2025 16:38:00 +0100 (CET) Received: from pmta11.mandrill.prod.atl01.rsglab.com (localhost [127.0.0.1]) by mail136-17.atl41.mandrillapp.com (Mailchimp) with ESMTP id 4d66x00cdYzPm0Zms for ; Wed, 12 Nov 2025 15:37:56 +0000 (GMT) Received: from [37.26.189.201] by mandrillapp.com id 98f689ac8ef6429eba55bb534baecc65; Wed, 12 Nov 2025 15:37:56 +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: 912f6e0e-bfdd-11f0-9d18-b5c5bf9af7f9 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mandrillapp.com; s=mte1; t=1762961876; x=1763231876; bh=kCjQ/w4mi64pHFYbQXYYAj4/n0muw09kfLASyhbwR3Y=; 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=J0hi8lk5FCgyJsaDLkkVsDEOmpJGDK7vPr06fWvfA2+bO7hhLghFQ+lPH163R+25m 3gJw1Ru3vVU5ZoKgyStzHbuf+Js+IJS+3QOBY66ccblc+S9RwTdUtn/OHs0t6r1IwD MnclgqeawIFwfgInb6DBTNFMtwPAYE9Mfm2XUHKOvJCrsxyIaI6DkypTmCAkJdzjXi 5RkQCUFwRX4/IK7BGbI8ovOcDEBp47WGb9xRSOzGDMxb6E1IovPvXxnPP80gE0P+wr Aep/USDeXGxSPKKX9v6/t9ErEzaFBQD94VUWqKbujnKN69IVQfqP4hacQVlSmKgIuT MyalPI2MgJZQw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=vates.tech; s=mte1; t=1762961876; x=1763222376; i=teddy.astie@vates.tech; bh=kCjQ/w4mi64pHFYbQXYYAj4/n0muw09kfLASyhbwR3Y=; 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=vgaj0LtADCuCvad7mQ7zgjGaGFNrB9WaMwLciqRruKy7vqv61JGa2eSZ7jspe8rdj qF5PlAmFpMICfzH8SHu+dY+D7Z6XdhIWPhd++wJH9n5ORxrE0yrAruneXAQBdoGB1b NBTPR+u44I+rk33Hm9mM9Ks+KWBy7nBPAQ+iLs6ask57Mh8vU/rmHpu0n/krm/9duZ Yhz6etH5dsBMNonBO2fxPDwOKs9mFfMdpKvUHeBtemBsRpFyLXomUw1hv+7uAWzk8m zShoZql9b/d13CoMMp4WFb81LfUIno/EiMgNBYap5XHHgd4q9RS3Q3DHUZsiBUyPxf O02sYDc7HPxxg== From: "Teddy Astie" Subject: =?utf-8?Q?[PATCH=202/2]=20amd/iommu:=20Remove=20dead=20non-atomic=20update=20checking?= X-Mailer: git-send-email 2.51.2 X-Bm-Disclaimer: Yes X-Bm-Milter-Handled: 4ffbd6c1-ee69-4e1b-aabd-f977039bd3e2 X-Bm-Transport-Timestamp: 1762961874950 To: xen-devel@lists.xenproject.org Cc: "Teddy Astie" , "Jan Beulich" , "Andrew Cooper" , "=?utf-8?Q?Roger=20Pau=20Monn=C3=A9?=" , "Jason Andryuk" 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.98f689ac8ef6429eba55bb534baecc65?= X-Mandrill-User: md_30504962 Feedback-ID: 30504962:30504962.20251112:md Date: Wed, 12 Nov 2025 15:37:56 +0000 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @mandrillapp.com) (identity teddy.astie@vates.tech) X-ZM-MESSAGEID: 1762961897868158500 Content-Type: text/plain; charset="utf-8" When updating a DTE, amd_iommu_setup_domain_device() would check if the update had been non-atomic (i.e rc > 0) and throw a warning if such non-atomic update could be dangerous. However since commit 3fc44151d83d, rc can no longer be positive, making this branch unreachable code. No functional change intended. Signed-off-by: Teddy Astie Reviewed-by: Jan Beulich Reviewed-by: Jason Andryuk --- xen/drivers/passthrough/amd/pci_amd_iommu.c | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/xen/drivers/passthrough/amd/pci_amd_iommu.c b/xen/drivers/pass= through/amd/pci_amd_iommu.c index 3a14770855..02eee4e658 100644 --- a/xen/drivers/passthrough/amd/pci_amd_iommu.c +++ b/xen/drivers/passthrough/amd/pci_amd_iommu.c @@ -225,24 +225,6 @@ static int __must_check amd_iommu_setup_domain_device( spin_unlock_irqrestore(&iommu->lock, flags); return rc; } - if ( rc && - domain !=3D pdev->domain && - /* - * By non-atomically updating the DTE's domain ID field last, - * during a short window in time TLB entries with the old dom= ain - * ID but the new page tables may have been inserted. This c= ould - * affect I/O of other devices using this same (old) domain I= D. - * Such updating therefore is not a problem if this was the o= nly - * device associated with the old domain ID. Diverting I/O o= f any - * of a dying domain's devices to the quarantine page tables = is - * intended anyway. - */ - !pdev->domain->is_dying && - pdev->domain !=3D dom_io && - (any_pdev_behind_iommu(pdev->domain, pdev, iommu) || - pdev->phantom_stride) ) - AMD_IOMMU_WARN(" %pp: reassignment may cause %pd data corrupti= on\n", - &PCI_SBDF(pdev->seg, bus, devfn), pdev->domain); =20 /* * Check remaining settings are still in place from an earlier call --=20 2.51.2 -- Teddy Astie | Vates XCP-ng Developer XCP-ng & Xen Orchestra - Vates solutions web: https://vates.tech