From nobody Mon Dec 15 12:39:58 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1765781659; cv=none; d=zohomail.com; s=zohoarc; b=JKasXGczsGKHF6PQjOPPi+Cq7ZFSkFywJGox52jo+lD0/f9sFjlFMbQVrRfpCgOukyA7V+yGlyYA/vZU8HSg7tLRLpE+cszge/mymB4hZPytXKfInUGZ6yqfKj3wD7aP/08NRCZveK5/Rlh5mg+BFZmSC9Haq4BFeVKYt0qv5cM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1765781659; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=AqAzG6eB5rddXzxK5/5SidKq6vRR8MKY6g7nYwj7POs=; b=RXcqYm8dMdcyP0OPfruemQ2kDLzKSnoG6tG+7u7ptrQ2JKf/BB13wqLmQBruIhAG10jl0gaiDnuJgHCHmQGiWz5V4tBQ9H15gTcsPLSrKRuf+u/bNz7nYC6GaIvtHvRv9Bu7loeUKDblNJRZvKtHkO4g+ttIEndGaS2iuFMoQpg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1765781659591264.38844136175453; Sun, 14 Dec 2025 22:54:19 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vV2QX-0007yn-Co; Mon, 15 Dec 2025 01:51:25 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vV2QU-0007yE-Qs for qemu-devel@nongnu.org; Mon, 15 Dec 2025 01:51:22 -0500 Received: from mgamail.intel.com ([198.175.65.15]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vV2QR-0000t7-5f for qemu-devel@nongnu.org; Mon, 15 Dec 2025 01:51:22 -0500 Received: from orviesa009.jf.intel.com ([10.64.159.149]) by orvoesa107.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Dec 2025 22:51:16 -0800 Received: from unknown (HELO gnr-sp-2s-612.sh.intel.com) ([10.112.230.229]) by orviesa009-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Dec 2025 22:51:11 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1765781480; x=1797317480; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=o7EFDuOyt6LdCO+MRYeG3gPf14I89uaBFCeSBtkVm7Y=; b=X1bbqkvGyqwnksHjsGdT5H4ZYYRz0T/iASAWtxtEbm63jQcsWpsFLYJS mnAwzQQvwoygfSMRMuxosGtC+hnA4gGRIIhFQZkNJVZJD76wlSjvZ3gJE 8Vhg9hADFG02Fa4mQrBC979JM3uwZ7PoHrV8CPFcigZF14zGkfXyEcR/F a4PHdoJq8dmuv4PivOeu4wWghataq1b54oHit/dG71Ro+6AjZfm2cfYI0 q1sEB23TvEabhq0ID5uBsQHacz6aV68zuPcuQXzBP0I64Yq9tdII7KljN 46dyRhOgzrO68XHRMmgIqH+ARn4RTN50R8I2RcfHlr7B4B93AuVp8+ydk w==; X-CSE-ConnectionGUID: ixXpa5G5QFSBxjFau75lCQ== X-CSE-MsgGUID: MZqdhoE1Q5y0EIUwmwRR0Q== X-IronPort-AV: E=McAfee;i="6800,10657,11642"; a="71304922" X-IronPort-AV: E=Sophos;i="6.21,150,1763452800"; d="scan'208";a="71304922" X-CSE-ConnectionGUID: z+RFa0J3QS2cC7i2LJEMXw== X-CSE-MsgGUID: WJtWESu6SqWixIIPVO0kRg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.21,150,1763452800"; d="scan'208";a="197408714" From: Zhenzhong Duan To: qemu-devel@nongnu.org Cc: alex@shazbot.org, clg@redhat.com, eric.auger@redhat.com, mst@redhat.com, jasowang@redhat.com, peterx@redhat.com, ddutile@redhat.com, jgg@nvidia.com, nicolinc@nvidia.com, skolothumtho@nvidia.com, joao.m.martins@oracle.com, clement.mathieu--drif@eviden.com, kevin.tian@intel.com, yi.l.liu@intel.com, chao.p.peng@intel.com, Zhenzhong Duan Subject: [PATCH v9 01/19] intel_iommu: Rename vtd_ce_get_rid2pasid_entry to vtd_ce_get_pasid_entry Date: Mon, 15 Dec 2025 01:50:25 -0500 Message-ID: <20251215065046.86991-2-zhenzhong.duan@intel.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20251215065046.86991-1-zhenzhong.duan@intel.com> References: <20251215065046.86991-1-zhenzhong.duan@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=198.175.65.15; envelope-from=zhenzhong.duan@intel.com; helo=mgamail.intel.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1765781665370158500 In early days vtd_ce_get_rid2pasid_entry() was used to get pasid entry of rid2pasid, then it was extended to get any pasid entry. So a new name vtd_ce_get_pasid_entry is better to match what it actually does. No functional change intended. Signed-off-by: Zhenzhong Duan Reviewed-by: Cl=C3=A9ment Mathieu--Drif Reviewed-by: Yi Liu Reviewed-by: Eric Auger Reviewed-by: Nicolin Chen --- hw/i386/intel_iommu.c | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/hw/i386/intel_iommu.c b/hw/i386/intel_iommu.c index 78b142ccea..ab7afdbf3d 100644 --- a/hw/i386/intel_iommu.c +++ b/hw/i386/intel_iommu.c @@ -954,10 +954,8 @@ static int vtd_get_pe_from_pasid_table(IntelIOMMUState= *s, return 0; } =20 -static int vtd_ce_get_rid2pasid_entry(IntelIOMMUState *s, - VTDContextEntry *ce, - VTDPASIDEntry *pe, - uint32_t pasid) +static int vtd_ce_get_pasid_entry(IntelIOMMUState *s, VTDContextEntry *ce, + VTDPASIDEntry *pe, uint32_t pasid) { dma_addr_t pasid_dir_base; int ret =3D 0; @@ -1035,7 +1033,7 @@ static uint32_t vtd_get_iova_level(IntelIOMMUState *s, VTDPASIDEntry pe; =20 if (s->root_scalable) { - vtd_ce_get_rid2pasid_entry(s, ce, &pe, pasid); + vtd_ce_get_pasid_entry(s, ce, &pe, pasid); if (s->flts) { return VTD_PE_GET_FL_LEVEL(&pe); } else { @@ -1058,7 +1056,7 @@ static uint32_t vtd_get_iova_agaw(IntelIOMMUState *s, VTDPASIDEntry pe; =20 if (s->root_scalable) { - vtd_ce_get_rid2pasid_entry(s, ce, &pe, pasid); + vtd_ce_get_pasid_entry(s, ce, &pe, pasid); return 30 + ((pe.val[0] >> 2) & VTD_SM_PASID_ENTRY_AW) * 9; } =20 @@ -1126,7 +1124,7 @@ static dma_addr_t vtd_get_iova_pgtbl_base(IntelIOMMUS= tate *s, VTDPASIDEntry pe; =20 if (s->root_scalable) { - vtd_ce_get_rid2pasid_entry(s, ce, &pe, pasid); + vtd_ce_get_pasid_entry(s, ce, &pe, pasid); if (s->flts) { return pe.val[2] & VTD_SM_PASID_ENTRY_FLPTPTR; } else { @@ -1532,7 +1530,7 @@ static int vtd_ce_rid2pasid_check(IntelIOMMUState *s, * has valid rid2pasid setting, which includes valid * rid2pasid field and corresponding pasid entry setting */ - return vtd_ce_get_rid2pasid_entry(s, ce, &pe, PCI_NO_PASID); + return vtd_ce_get_pasid_entry(s, ce, &pe, PCI_NO_PASID); } =20 /* Map a device to its corresponding domain (context-entry) */ @@ -1621,7 +1619,7 @@ static uint16_t vtd_get_domain_id(IntelIOMMUState *s, VTDPASIDEntry pe; =20 if (s->root_scalable) { - vtd_ce_get_rid2pasid_entry(s, ce, &pe, pasid); + vtd_ce_get_pasid_entry(s, ce, &pe, pasid); return VTD_SM_PASID_ENTRY_DID(pe.val[1]); } =20 @@ -1697,7 +1695,7 @@ static bool vtd_dev_pt_enabled(IntelIOMMUState *s, VT= DContextEntry *ce, int ret; =20 if (s->root_scalable) { - ret =3D vtd_ce_get_rid2pasid_entry(s, ce, &pe, pasid); + ret =3D vtd_ce_get_pasid_entry(s, ce, &pe, pasid); if (ret) { /* * This error is guest triggerable. We should assumt PT @@ -3083,7 +3081,7 @@ static inline int vtd_dev_get_pe_from_pasid(VTDAddres= sSpace *vtd_as, return ret; } =20 - return vtd_ce_get_rid2pasid_entry(s, &ce, pe, vtd_as->pasid); + return vtd_ce_get_pasid_entry(s, &ce, pe, vtd_as->pasid); } =20 static int vtd_pasid_entry_compare(VTDPASIDEntry *p1, VTDPASIDEntry *p2) @@ -5161,7 +5159,7 @@ static int vtd_pri_perform_implicit_invalidation(VTDA= ddressSpace *vtd_as, if (ret) { return -EINVAL; } - ret =3D vtd_ce_get_rid2pasid_entry(s, &ce, &pe, vtd_as->pasid); + ret =3D vtd_ce_get_pasid_entry(s, &ce, &pe, vtd_as->pasid); if (ret) { return -EINVAL; } --=20 2.47.1 From nobody Mon Dec 15 12:39:58 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1765781512; cv=none; d=zohomail.com; s=zohoarc; b=f6AnDS39/Alsqn9WVrgmNtbuQ8/tUf8Ubi2/5FHtOABG3B2hnpqpuUmQxiWjdZ8fs/xczQtCy3GrigSengzz3JDx8GbMKOrcJ/KvaGD4dMQBkOrA96qTnDi7nd6x+Rg0GzIyoHlVBp3eqZ7493gpw8tEXqf2oFw8pXo4GWknBqA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1765781512; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=DXRQi5Jo9JuN54U3SFamJJgXL5ObLSKNfAuuIuqasKQ=; b=K964ae9+wgxyGOEgX1OIUoS8BUktuBazQ+aRlCHbAgtlsMi6NcrK2vtkCNZ8UjmO8Gwrh/2MxpOgyIh00D/ehx3rfWLJASNDLxme2n9cpYZEz9GIVB4gAQQG7D1zRybB+9FOSVWY66hE50JuYQJ8NO/xy2+UfOt43XoxcGV/bb0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1765781512299214.3851542755233; Sun, 14 Dec 2025 22:51:52 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vV2QY-0007z0-55; Mon, 15 Dec 2025 01:51:26 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vV2QV-0007yZ-99 for qemu-devel@nongnu.org; Mon, 15 Dec 2025 01:51:23 -0500 Received: from mgamail.intel.com ([198.175.65.15]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vV2QT-0000u9-23 for qemu-devel@nongnu.org; Mon, 15 Dec 2025 01:51:22 -0500 Received: from orviesa009.jf.intel.com ([10.64.159.149]) by orvoesa107.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Dec 2025 22:51:20 -0800 Received: from unknown (HELO gnr-sp-2s-612.sh.intel.com) ([10.112.230.229]) by orviesa009-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Dec 2025 22:51:16 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1765781482; x=1797317482; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=CrcbGDYu4t1KGlBoxXFtJlX6+xdx6r7Dm7GHUltTqt8=; b=Gm0SXn2ZujoX7fGbs6fup/5ls0ayc3NasBA73jNXZi9pDdEZsRASAHdm 9JqplJpp/CieLWtvhIO1NUg4XdNkDo+NggQZkloUxLhHqwi3QsDxM65C5 6r489/a7wErY0hoJMgpzHCgSJsU/NoTjociE8JwvcUUB73HKlzDfYBd1u 08ilEU06gScOlu/JUNp+gHedsDzbGODytr1q0hRxou4VjytlQ4jzrAMaD 5gbITaMQEGxXiJhiypflw9Zpf9uapN2Mh1aMpHrPKcQCuDDzp408NJQBH RwELpk890x64QOkgj2YF6klRy411RLWA2nZkWhfydPgC9AtWt/DeLs5ca w==; X-CSE-ConnectionGUID: xEJgr/CPQIqpmq688IM1nQ== X-CSE-MsgGUID: AshaaLj9Q1KoRpfwzO6vcA== X-IronPort-AV: E=McAfee;i="6800,10657,11642"; a="71304930" X-IronPort-AV: E=Sophos;i="6.21,150,1763452800"; d="scan'208";a="71304930" X-CSE-ConnectionGUID: YmK5jMJHR0qNOxLbD/m5qg== X-CSE-MsgGUID: oim5s8/XRQGA/dMTuqAwDg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.21,150,1763452800"; d="scan'208";a="197408727" From: Zhenzhong Duan To: qemu-devel@nongnu.org Cc: alex@shazbot.org, clg@redhat.com, eric.auger@redhat.com, mst@redhat.com, jasowang@redhat.com, peterx@redhat.com, ddutile@redhat.com, jgg@nvidia.com, nicolinc@nvidia.com, skolothumtho@nvidia.com, joao.m.martins@oracle.com, clement.mathieu--drif@eviden.com, kevin.tian@intel.com, yi.l.liu@intel.com, chao.p.peng@intel.com, Zhenzhong Duan Subject: [PATCH v9 02/19] intel_iommu: Delete RPS capability related supporting code Date: Mon, 15 Dec 2025 01:50:26 -0500 Message-ID: <20251215065046.86991-3-zhenzhong.duan@intel.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20251215065046.86991-1-zhenzhong.duan@intel.com> References: <20251215065046.86991-1-zhenzhong.duan@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=198.175.65.15; envelope-from=zhenzhong.duan@intel.com; helo=mgamail.intel.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1765781517023158500 Content-Type: text/plain; charset="utf-8" RID-PASID Support(RPS) is not set in vIOMMU ECAP register, the supporting code is there but never takes effect. Meanwhile, according to VTD spec section 3.4.3: "Implementations not supporting RID_PASID capability (ECAP_REG.RPS is 0b), use a PASID value of 0 to perform address translation for requests without PASID." We should delete the supporting code which fetches RID_PASID field from scalable context entry and use 0 as RID_PASID directly, because RID_PASID field is ignored if no RPS support according to spec. This simplifies the code and doesn't bring any penalty. Suggested-by: Yi Liu Signed-off-by: Zhenzhong Duan Reviewed-by: Eric Auger --- hw/i386/intel_iommu_internal.h | 2 +- hw/i386/intel_iommu.c | 89 +++++++++++----------------------- 2 files changed, 28 insertions(+), 63 deletions(-) diff --git a/hw/i386/intel_iommu_internal.h b/hw/i386/intel_iommu_internal.h index 75bafdf0cd..36d04427dd 100644 --- a/hw/i386/intel_iommu_internal.h +++ b/hw/i386/intel_iommu_internal.h @@ -609,7 +609,7 @@ typedef struct VTDRootEntry VTDRootEntry; #define VTD_CTX_ENTRY_LEGACY_SIZE 16 #define VTD_CTX_ENTRY_SCALABLE_SIZE 32 =20 -#define VTD_SM_CONTEXT_ENTRY_RID2PASID_MASK 0xfffff +#define PASID_0 0 #define VTD_SM_CONTEXT_ENTRY_RSVD_VAL0(aw) (0x1e0ULL | ~VTD_HAW_MASK(aw)) #define VTD_SM_CONTEXT_ENTRY_RSVD_VAL1 0xffffffffffe00000ULL #define VTD_SM_CONTEXT_ENTRY_PRE 0x10ULL diff --git a/hw/i386/intel_iommu.c b/hw/i386/intel_iommu.c index ab7afdbf3d..cc55a68ae7 100644 --- a/hw/i386/intel_iommu.c +++ b/hw/i386/intel_iommu.c @@ -41,8 +41,6 @@ #include "trace.h" =20 /* context entry operations */ -#define VTD_CE_GET_RID2PASID(ce) \ - ((ce)->val[1] & VTD_SM_CONTEXT_ENTRY_RID2PASID_MASK) #define VTD_CE_GET_PASID_DIR_TABLE(ce) \ ((ce)->val[0] & VTD_PASID_DIR_BASE_ADDR_MASK) #define VTD_CE_GET_PRE(ce) \ @@ -958,15 +956,12 @@ static int vtd_ce_get_pasid_entry(IntelIOMMUState *s,= VTDContextEntry *ce, VTDPASIDEntry *pe, uint32_t pasid) { dma_addr_t pasid_dir_base; - int ret =3D 0; =20 if (pasid =3D=3D PCI_NO_PASID) { - pasid =3D VTD_CE_GET_RID2PASID(ce); + pasid =3D PASID_0; } pasid_dir_base =3D VTD_CE_GET_PASID_DIR_TABLE(ce); - ret =3D vtd_get_pe_from_pasid_table(s, pasid_dir_base, pasid, pe); - - return ret; + return vtd_get_pe_from_pasid_table(s, pasid_dir_base, pasid, pe); } =20 static int vtd_ce_get_pasid_fpd(IntelIOMMUState *s, @@ -980,7 +975,7 @@ static int vtd_ce_get_pasid_fpd(IntelIOMMUState *s, VTDPASIDEntry pe; =20 if (pasid =3D=3D PCI_NO_PASID) { - pasid =3D VTD_CE_GET_RID2PASID(ce); + pasid =3D PASID_0; } pasid_dir_base =3D VTD_CE_GET_PASID_DIR_TABLE(ce); =20 @@ -1520,17 +1515,15 @@ static inline int vtd_context_entry_rsvd_bits_check= (IntelIOMMUState *s, return 0; } =20 -static int vtd_ce_rid2pasid_check(IntelIOMMUState *s, - VTDContextEntry *ce) +static int vtd_ce_pasid_0_check(IntelIOMMUState *s, VTDContextEntry *ce) { VTDPASIDEntry pe; =20 /* * Make sure in Scalable Mode, a present context entry - * has valid rid2pasid setting, which includes valid - * rid2pasid field and corresponding pasid entry setting + * has valid pasid entry setting at PASID_0. */ - return vtd_ce_get_pasid_entry(s, ce, &pe, PCI_NO_PASID); + return vtd_ce_get_pasid_entry(s, ce, &pe, PASID_0); } =20 /* Map a device to its corresponding domain (context-entry) */ @@ -1591,15 +1584,11 @@ static int vtd_dev_to_context_entry(IntelIOMMUState= *s, uint8_t bus_num, } } else { /* - * Check if the programming of context-entry.rid2pasid - * and corresponding pasid setting is valid, and thus - * avoids to check pasid entry fetching result in future - * helper function calling. + * Check if the programming of pasid setting of PASID_0 + * is valid, and thus avoids to check pasid entry fetching + * result in future helper function calling. */ - ret_fr =3D vtd_ce_rid2pasid_check(s, ce); - if (ret_fr) { - return ret_fr; - } + return vtd_ce_pasid_0_check(s, ce); } =20 return 0; @@ -2108,7 +2097,6 @@ static bool vtd_do_iommu_translate(VTDAddressSpace *v= td_as, PCIBus *bus, bool reads =3D true; bool writes =3D true; uint8_t access_flags, pgtt; - bool rid2pasid =3D (pasid =3D=3D PCI_NO_PASID) && s->root_scalable; VTDIOTLBEntry *iotlb_entry; uint64_t xlat, size; =20 @@ -2120,21 +2108,23 @@ static bool vtd_do_iommu_translate(VTDAddressSpace = *vtd_as, PCIBus *bus, =20 vtd_iommu_lock(s); =20 - cc_entry =3D &vtd_as->context_cache_entry; + if (pasid =3D=3D PCI_NO_PASID && s->root_scalable) { + pasid =3D PASID_0; + } =20 - /* Try to fetch pte from IOTLB, we don't need RID2PASID logic */ - if (!rid2pasid) { - iotlb_entry =3D vtd_lookup_iotlb(s, source_id, pasid, addr); - if (iotlb_entry) { - trace_vtd_iotlb_page_hit(source_id, addr, iotlb_entry->pte, - iotlb_entry->domain_id); - pte =3D iotlb_entry->pte; - access_flags =3D iotlb_entry->access_flags; - page_mask =3D iotlb_entry->mask; - goto out; - } + /* Try to fetch pte from IOTLB */ + iotlb_entry =3D vtd_lookup_iotlb(s, source_id, pasid, addr); + if (iotlb_entry) { + trace_vtd_iotlb_page_hit(source_id, addr, iotlb_entry->pte, + iotlb_entry->domain_id); + pte =3D iotlb_entry->pte; + access_flags =3D iotlb_entry->access_flags; + page_mask =3D iotlb_entry->mask; + goto out; } =20 + cc_entry =3D &vtd_as->context_cache_entry; + /* Try to fetch context-entry from cache first */ if (cc_entry->context_cache_gen =3D=3D s->context_cache_gen) { trace_vtd_iotlb_cc_hit(bus_num, devfn, cc_entry->context_entry.hi, @@ -2171,10 +2161,6 @@ static bool vtd_do_iommu_translate(VTDAddressSpace *= vtd_as, PCIBus *bus, cc_entry->context_cache_gen =3D s->context_cache_gen; } =20 - if (rid2pasid) { - pasid =3D VTD_CE_GET_RID2PASID(&ce); - } - /* * We don't need to translate for pass-through context entries. * Also, let's ignore IOTLB caching as well for PT devices. @@ -2200,19 +2186,6 @@ static bool vtd_do_iommu_translate(VTDAddressSpace *= vtd_as, PCIBus *bus, return true; } =20 - /* Try to fetch pte from IOTLB for RID2PASID slow path */ - if (rid2pasid) { - iotlb_entry =3D vtd_lookup_iotlb(s, source_id, pasid, addr); - if (iotlb_entry) { - trace_vtd_iotlb_page_hit(source_id, addr, iotlb_entry->pte, - iotlb_entry->domain_id); - pte =3D iotlb_entry->pte; - access_flags =3D iotlb_entry->access_flags; - page_mask =3D iotlb_entry->mask; - goto out; - } - } - if (s->flts && s->root_scalable) { ret_fr =3D vtd_iova_to_flpte(s, &ce, addr, is_write, &pte, &level, &reads, &writes, s->aw_bits, pasid); @@ -2475,20 +2448,14 @@ static void vtd_iotlb_page_invalidate_notify(IntelI= OMMUState *s, ret =3D vtd_dev_to_context_entry(s, pci_bus_num(vtd_as->bus), vtd_as->devfn, &ce); if (!ret && domain_id =3D=3D vtd_get_domain_id(s, &ce, vtd_as->pas= id)) { - uint32_t rid2pasid =3D PCI_NO_PASID; - - if (s->root_scalable) { - rid2pasid =3D VTD_CE_GET_RID2PASID(&ce); - } - /* * In legacy mode, vtd_as->pasid =3D=3D pasid is always true. * In scalable mode, for vtd address space backing a PCI * device without pasid, needs to compare pasid with - * rid2pasid of this device. + * PASID_0 of this device. */ if (!(vtd_as->pasid =3D=3D pasid || - (vtd_as->pasid =3D=3D PCI_NO_PASID && pasid =3D=3D rid2p= asid))) { + (vtd_as->pasid =3D=3D PCI_NO_PASID && pasid =3D=3D PASID= _0))) { continue; } =20 @@ -2993,9 +2960,7 @@ static void vtd_piotlb_pasid_invalidate(IntelIOMMUSta= te *s, if (!vtd_dev_to_context_entry(s, pci_bus_num(vtd_as->bus), vtd_as->devfn, &ce) && domain_id =3D=3D vtd_get_domain_id(s, &ce, vtd_as->pasid)) { - uint32_t rid2pasid =3D VTD_CE_GET_RID2PASID(&ce); - - if ((vtd_as->pasid !=3D PCI_NO_PASID || pasid !=3D rid2pasid) = && + if ((vtd_as->pasid !=3D PCI_NO_PASID || pasid !=3D PASID_0) && vtd_as->pasid !=3D pasid) { continue; } --=20 2.47.1 From nobody Mon Dec 15 12:39:58 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1765781611; cv=none; d=zohomail.com; s=zohoarc; b=Hf4zfv3iX4gAry2PIUI4D2e/ypEX1UybSk6hkNUWt+/4lFd3gh8k5EFeUy2cX6wBHv1PZm0UfomFNHCDqxq0skM9F9Y+ZTJWjE3OOMrfAZvyOmv7BLzRcYziG+wy7w5m4+DrJ1Mm8vKEer6AoDSiQE5Qp1boR1KYktmGOn7kOZ0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1765781611; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=sbfb+dBqUQQN+KRol+ZQcZjNhCw/VZ2D423hfG7OvgE=; b=eXwIEi0ZGnHcPWn8i4P3e1+CF9Zu/GFAmJe+qTudGy9vVTIfWNTMMYXG7FW48e8ObPzKzUvl26UFVppX2Ai0TUkSFslVyX/2wOtWjoAl8YlpScrSjtULbZCj7dfYWoVjMhEhpqCvNBaMKi8CYvstnyKpXgcLVCYiMok+yFleeKA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 176578161107776.44264166271239; Sun, 14 Dec 2025 22:53:31 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vV2Qc-0007zq-LA; Mon, 15 Dec 2025 01:51:30 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vV2Qb-0007zY-1c for qemu-devel@nongnu.org; Mon, 15 Dec 2025 01:51:29 -0500 Received: from mgamail.intel.com ([198.175.65.15]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vV2QX-0000u9-7K for qemu-devel@nongnu.org; Mon, 15 Dec 2025 01:51:28 -0500 Received: from orviesa009.jf.intel.com ([10.64.159.149]) by orvoesa107.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Dec 2025 22:51:25 -0800 Received: from unknown (HELO gnr-sp-2s-612.sh.intel.com) ([10.112.230.229]) by orviesa009-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Dec 2025 22:51:20 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1765781486; x=1797317486; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=zk7dzziG5AC7loQXHjEJkuDZ9c+OfGUZ++iqCEA4huQ=; b=fOJfH2ZOgMf2+P4/D3WYk1L4zWNpHtr7vLLPSHWKaf9olp93NkNoYbos /XUcCwn3EtfhCV2zvMNnXuW2agpbA0UDSaYd1u5MHuG1e1HXNdB9nijbD nR/f5aPJUZo0WA0kawoCHKntWcrpovLPc9AfTobXKQ2QGxwsvjRzOi4Z2 IWlX6MkwBeMIKbtAIIeOYf8LAOFZHQFPxkKCdwaeEvqkhmcOg53sECmTw wYpbCuLbuztKXHybYeSjFmjlghbnewTrzs7PP39y/qw6zG78bRzR7pBoc 00gbV75aUX5tnQfzxP6fr/fEIxou8lE3NTFUFQ0aw7hJSVfQoMKdvw3Uo g==; X-CSE-ConnectionGUID: a/0ilYePTraBrBXreKKKvw== X-CSE-MsgGUID: OvHpQEdiTOScQCmSwMteDA== X-IronPort-AV: E=McAfee;i="6800,10657,11642"; a="71304940" X-IronPort-AV: E=Sophos;i="6.21,150,1763452800"; d="scan'208";a="71304940" X-CSE-ConnectionGUID: s0koPXMgQqmEL6CMveqGfw== X-CSE-MsgGUID: XBUhOi5pTMuUC8iAVkIq5g== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.21,150,1763452800"; d="scan'208";a="197408738" From: Zhenzhong Duan To: qemu-devel@nongnu.org Cc: alex@shazbot.org, clg@redhat.com, eric.auger@redhat.com, mst@redhat.com, jasowang@redhat.com, peterx@redhat.com, ddutile@redhat.com, jgg@nvidia.com, nicolinc@nvidia.com, skolothumtho@nvidia.com, joao.m.martins@oracle.com, clement.mathieu--drif@eviden.com, kevin.tian@intel.com, yi.l.liu@intel.com, chao.p.peng@intel.com, Zhenzhong Duan , Paolo Bonzini Subject: [PATCH v9 03/19] intel_iommu: Update terminology to match VTD spec Date: Mon, 15 Dec 2025 01:50:27 -0500 Message-ID: <20251215065046.86991-4-zhenzhong.duan@intel.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20251215065046.86991-1-zhenzhong.duan@intel.com> References: <20251215065046.86991-1-zhenzhong.duan@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=198.175.65.15; envelope-from=zhenzhong.duan@intel.com; helo=mgamail.intel.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1765781613380158500 Content-Type: text/plain; charset="utf-8" VTD spec revision 3.4 released in December 2021 renamed "First-level" to "First-stage" and "Second-level" to "Second-stage". Do the same in intel_iommu code to match spec, change all existing "fl/sl/FL/SL/first level/second level/stage-1/stage-2" terminology to "fs/ss/FS/SS/first stage/second stage". Opportunistically fix a error print of "flts=3Don" with "x-flts=3Don". No functional changes intended. Suggested-by: Yi Liu Suggested-by: Eric Auger Signed-off-by: Zhenzhong Duan Reviewed-by: Eric Auger Reviewed-by: Yi Liu --- hw/i386/intel_iommu_internal.h | 85 ++++++------ include/hw/i386/intel_iommu.h | 2 +- hw/i386/intel_iommu.c | 247 +++++++++++++++++---------------- tests/qtest/intel-iommu-test.c | 4 +- 4 files changed, 170 insertions(+), 168 deletions(-) diff --git a/hw/i386/intel_iommu_internal.h b/hw/i386/intel_iommu_internal.h index 36d04427dd..3330298884 100644 --- a/hw/i386/intel_iommu_internal.h +++ b/hw/i386/intel_iommu_internal.h @@ -196,8 +196,8 @@ #define VTD_ECAP_PSS (7ULL << 35) /* limit: MemTxAttrs::pid= */ #define VTD_ECAP_PASID (1ULL << 40) #define VTD_ECAP_SMTS (1ULL << 43) -#define VTD_ECAP_SLTS (1ULL << 46) -#define VTD_ECAP_FLTS (1ULL << 47) +#define VTD_ECAP_SSTS (1ULL << 46) +#define VTD_ECAP_FSTS (1ULL << 47) =20 /* CAP_REG */ /* (offset >> 4) << 24 */ @@ -211,7 +211,7 @@ #define VTD_MAMV 18ULL #define VTD_CAP_MAMV (VTD_MAMV << 48) #define VTD_CAP_PSI (1ULL << 39) -#define VTD_CAP_SLLPS ((1ULL << 34) | (1ULL << 35)) +#define VTD_CAP_SSLPS ((1ULL << 34) | (1ULL << 35)) #define VTD_CAP_DRAIN_WRITE (1ULL << 54) #define VTD_CAP_DRAIN_READ (1ULL << 55) #define VTD_CAP_FS1GP (1ULL << 56) @@ -284,7 +284,7 @@ typedef enum VTDFaultReason { VTD_FR_ADDR_BEYOND_MGAW, /* Input-address above (2^x-1) */ VTD_FR_WRITE, /* No write permission */ VTD_FR_READ, /* No read permission */ - /* Fail to access a second-level paging entry (not SL_PML4E) */ + /* Fail to access a second-stage paging entry (not SS_PML4E) */ VTD_FR_PAGING_ENTRY_INV, VTD_FR_ROOT_TABLE_INV, /* Fail to access a root-entry */ VTD_FR_CONTEXT_TABLE_INV, /* Fail to access a context-entry */ @@ -292,7 +292,8 @@ typedef enum VTDFaultReason { VTD_FR_ROOT_ENTRY_RSVD, /* Non-zero reserved field in a present context-entry */ VTD_FR_CONTEXT_ENTRY_RSVD, - /* Non-zero reserved field in a second-level paging entry with at leas= e one + /* + * Non-zero reserved field in a second-stage paging entry with at leas= e one * Read(R) and Write(W) or Execute(E) field is Set. */ VTD_FR_PAGING_ENTRY_RSVD, @@ -329,7 +330,7 @@ typedef enum VTDFaultReason { VTD_FR_PASID_ENTRY_P =3D 0x59, VTD_FR_PASID_TABLE_ENTRY_INV =3D 0x5b, /*Invalid PASID table entry */ =20 - /* Fail to access a first-level paging entry (not FS_PML4E) */ + /* Fail to access a first-stage paging entry (not FS_PML4E) */ VTD_FR_FS_PAGING_ENTRY_INV =3D 0x70, VTD_FR_FS_PAGING_ENTRY_P =3D 0x71, /* Non-zero reserved field in present first-stage paging entry */ @@ -473,23 +474,23 @@ typedef union VTDPRDesc VTDPRDesc; =20 #define VTD_SPTE_PAGE_L1_RSVD_MASK(aw, stale_tm) \ stale_tm ? \ - (0x800ULL | ~(VTD_HAW_MASK(aw) | VTD_SL_IGN_COM | VTD_SL_TM)) : \ - (0x800ULL | ~(VTD_HAW_MASK(aw) | VTD_SL_IGN_COM)) + (0x800ULL | ~(VTD_HAW_MASK(aw) | VTD_SS_IGN_COM | VTD_SS_TM)) : \ + (0x800ULL | ~(VTD_HAW_MASK(aw) | VTD_SS_IGN_COM)) #define VTD_SPTE_PAGE_L2_RSVD_MASK(aw) \ - (0x800ULL | ~(VTD_HAW_MASK(aw) | VTD_SL_IGN_COM)) + (0x800ULL | ~(VTD_HAW_MASK(aw) | VTD_SS_IGN_COM)) #define VTD_SPTE_PAGE_L3_RSVD_MASK(aw) \ - (0x800ULL | ~(VTD_HAW_MASK(aw) | VTD_SL_IGN_COM)) + (0x800ULL | ~(VTD_HAW_MASK(aw) | VTD_SS_IGN_COM)) #define VTD_SPTE_PAGE_L4_RSVD_MASK(aw) \ - (0x880ULL | ~(VTD_HAW_MASK(aw) | VTD_SL_IGN_COM)) + (0x880ULL | ~(VTD_HAW_MASK(aw) | VTD_SS_IGN_COM)) =20 #define VTD_SPTE_LPAGE_L2_RSVD_MASK(aw, stale_tm) \ stale_tm ? \ - (0x1ff800ULL | ~(VTD_HAW_MASK(aw) | VTD_SL_IGN_COM | VTD_SL_TM)) := \ - (0x1ff800ULL | ~(VTD_HAW_MASK(aw) | VTD_SL_IGN_COM)) + (0x1ff800ULL | ~(VTD_HAW_MASK(aw) | VTD_SS_IGN_COM | VTD_SS_TM)) := \ + (0x1ff800ULL | ~(VTD_HAW_MASK(aw) | VTD_SS_IGN_COM)) #define VTD_SPTE_LPAGE_L3_RSVD_MASK(aw, stale_tm) \ stale_tm ? \ - (0x3ffff800ULL | ~(VTD_HAW_MASK(aw) | VTD_SL_IGN_COM | VTD_SL_TM))= : \ - (0x3ffff800ULL | ~(VTD_HAW_MASK(aw) | VTD_SL_IGN_COM)) + (0x3ffff800ULL | ~(VTD_HAW_MASK(aw) | VTD_SS_IGN_COM | VTD_SS_TM))= : \ + (0x3ffff800ULL | ~(VTD_HAW_MASK(aw) | VTD_SS_IGN_COM)) =20 /* Rsvd field masks for fpte */ #define VTD_FS_UPPER_IGNORED 0xfff0000000000000ULL @@ -596,8 +597,8 @@ typedef struct VTDRootEntry VTDRootEntry; #define VTD_CONTEXT_TT_MULTI_LEVEL 0 #define VTD_CONTEXT_TT_DEV_IOTLB (1ULL << 2) #define VTD_CONTEXT_TT_PASS_THROUGH (2ULL << 2) -/* Second Level Page Translation Pointer*/ -#define VTD_CONTEXT_ENTRY_SLPTPTR (~0xfffULL) +/* Second Stage Page Translation Pointer*/ +#define VTD_CONTEXT_ENTRY_SSPTPTR (~0xfffULL) #define VTD_CONTEXT_ENTRY_RSVD_LO(aw) (0xff0ULL | ~VTD_HAW_MASK(aw)) /* hi */ #define VTD_CONTEXT_ENTRY_AW 7ULL /* Adjusted guest-address-width */ @@ -635,37 +636,37 @@ typedef struct VTDPASIDCacheInfo { /* PASID Granular Translation Type Mask */ #define VTD_PASID_ENTRY_P 1ULL #define VTD_SM_PASID_ENTRY_PGTT (7ULL << 6) -#define VTD_SM_PASID_ENTRY_FLT (1ULL << 6) -#define VTD_SM_PASID_ENTRY_SLT (2ULL << 6) +#define VTD_SM_PASID_ENTRY_FST (1ULL << 6) +#define VTD_SM_PASID_ENTRY_SST (2ULL << 6) #define VTD_SM_PASID_ENTRY_NESTED (3ULL << 6) #define VTD_SM_PASID_ENTRY_PT (4ULL << 6) =20 #define VTD_SM_PASID_ENTRY_AW 7ULL /* Adjusted guest-address-widt= h */ #define VTD_SM_PASID_ENTRY_DID(val) ((val) & VTD_DOMAIN_ID_MASK) =20 -#define VTD_SM_PASID_ENTRY_FLPM 3ULL -#define VTD_SM_PASID_ENTRY_FLPTPTR (~0xfffULL) - -/* First Level Paging Structure */ -/* Masks for First Level Paging Entry */ -#define VTD_FL_P 1ULL -#define VTD_FL_RW (1ULL << 1) -#define VTD_FL_US (1ULL << 2) -#define VTD_FL_A (1ULL << 5) -#define VTD_FL_D (1ULL << 6) - -/* Second Level Page Translation Pointer*/ -#define VTD_SM_PASID_ENTRY_SLPTPTR (~0xfffULL) - -/* Second Level Paging Structure */ -/* Masks for Second Level Paging Entry */ -#define VTD_SL_RW_MASK 3ULL -#define VTD_SL_R 1ULL -#define VTD_SL_W (1ULL << 1) -#define VTD_SL_IGN_COM 0xbff0000000000000ULL -#define VTD_SL_TM (1ULL << 62) - -/* Common for both First Level and Second Level */ +#define VTD_SM_PASID_ENTRY_FSPM 3ULL +#define VTD_SM_PASID_ENTRY_FSPTPTR (~0xfffULL) + +/* First Stage Paging Structure */ +/* Masks for First Stage Paging Entry */ +#define VTD_FS_P 1ULL +#define VTD_FS_RW (1ULL << 1) +#define VTD_FS_US (1ULL << 2) +#define VTD_FS_A (1ULL << 5) +#define VTD_FS_D (1ULL << 6) + +/* Second Stage Page Translation Pointer*/ +#define VTD_SM_PASID_ENTRY_SSPTPTR (~0xfffULL) + +/* Second Stage Paging Structure */ +/* Masks for Second Stage Paging Entry */ +#define VTD_SS_RW_MASK 3ULL +#define VTD_SS_R 1ULL +#define VTD_SS_W (1ULL << 1) +#define VTD_SS_IGN_COM 0xbff0000000000000ULL +#define VTD_SS_TM (1ULL << 62) + +/* Common for both First Stage and Second Stage */ #define VTD_PML4_LEVEL 4 #define VTD_PDP_LEVEL 3 #define VTD_PD_LEVEL 2 diff --git a/include/hw/i386/intel_iommu.h b/include/hw/i386/intel_iommu.h index ca7f7bb661..0b7832d25d 100644 --- a/include/hw/i386/intel_iommu.h +++ b/include/hw/i386/intel_iommu.h @@ -271,7 +271,7 @@ struct IntelIOMMUState { =20 bool caching_mode; /* RO - is cap CM enabled? */ bool scalable_mode; /* RO - is Scalable Mode supported? */ - bool flts; /* RO - is stage-1 translation support= ed? */ + bool fsts; /* RO - is first stage translation sup= ported? */ bool snoop_control; /* RO - is SNP filed supported? */ =20 dma_addr_t root; /* Current root table pointer */ diff --git a/hw/i386/intel_iommu.c b/hw/i386/intel_iommu.c index cc55a68ae7..64c5c6cbc2 100644 --- a/hw/i386/intel_iommu.c +++ b/hw/i386/intel_iommu.c @@ -48,9 +48,9 @@ =20 /* pe operations */ #define VTD_PE_GET_TYPE(pe) ((pe)->val[0] & VTD_SM_PASID_ENTRY_PGTT) -#define VTD_PE_GET_FL_LEVEL(pe) \ - (4 + (((pe)->val[2] >> 2) & VTD_SM_PASID_ENTRY_FLPM)) -#define VTD_PE_GET_SL_LEVEL(pe) \ +#define VTD_PE_GET_FS_LEVEL(pe) \ + (4 + (((pe)->val[2] >> 2) & VTD_SM_PASID_ENTRY_FSPM)) +#define VTD_PE_GET_SS_LEVEL(pe) \ (2 + (((pe)->val[0] >> 2) & VTD_SM_PASID_ENTRY_AW)) =20 /* @@ -327,7 +327,7 @@ static gboolean vtd_hash_remove_by_page(gpointer key, g= pointer value, * nested (PGTT=3D011b) mapping associated with specified domain-id are * invalidated. Nested isn't supported yet, so only need to check 001b. */ - if (entry->pgtt =3D=3D VTD_SM_PASID_ENTRY_FLT) { + if (entry->pgtt =3D=3D VTD_SM_PASID_ENTRY_FST) { return true; } =20 @@ -348,7 +348,7 @@ static gboolean vtd_hash_remove_by_page_piotlb(gpointer= key, gpointer value, * or pass-through (PGTT=3D100b) mappings. Nested isn't supported yet, * so only need to check first-stage (PGTT=3D001b) mappings. */ - if (entry->pgtt !=3D VTD_SM_PASID_ENTRY_FLT) { + if (entry->pgtt !=3D VTD_SM_PASID_ENTRY_FST) { return false; } =20 @@ -756,9 +756,9 @@ static int vtd_get_context_entry_from_root(IntelIOMMUSt= ate *s, return 0; } =20 -static inline dma_addr_t vtd_ce_get_slpt_base(VTDContextEntry *ce) +static inline dma_addr_t vtd_ce_get_sspt_base(VTDContextEntry *ce) { - return ce->lo & VTD_CONTEXT_ENTRY_SLPTPTR; + return ce->lo & VTD_CONTEXT_ENTRY_SSPTPTR; } =20 static inline uint64_t vtd_get_pte_addr(uint64_t pte, uint8_t aw) @@ -799,13 +799,13 @@ static inline uint32_t vtd_iova_level_offset(uint64_t= iova, uint32_t level) } =20 /* Check Capability Register to see if the @level of page-table is support= ed */ -static inline bool vtd_is_sl_level_supported(IntelIOMMUState *s, uint32_t = level) +static inline bool vtd_is_ss_level_supported(IntelIOMMUState *s, uint32_t = level) { return VTD_CAP_SAGAW_MASK & s->cap & (1ULL << (level - 2 + VTD_CAP_SAGAW_SHIFT)); } =20 -static inline bool vtd_is_fl_level_supported(IntelIOMMUState *s, uint32_t = level) +static inline bool vtd_is_fs_level_supported(IntelIOMMUState *s, uint32_t = level) { return level =3D=3D VTD_PML4_LEVEL; } @@ -814,10 +814,10 @@ static inline bool vtd_is_fl_level_supported(IntelIOM= MUState *s, uint32_t level) static inline bool vtd_pe_type_check(IntelIOMMUState *s, VTDPASIDEntry *pe) { switch (VTD_PE_GET_TYPE(pe)) { - case VTD_SM_PASID_ENTRY_FLT: - return !!(s->ecap & VTD_ECAP_FLTS); - case VTD_SM_PASID_ENTRY_SLT: - return !!(s->ecap & VTD_ECAP_SLTS); + case VTD_SM_PASID_ENTRY_FST: + return !!(s->ecap & VTD_ECAP_FSTS); + case VTD_SM_PASID_ENTRY_SST: + return !!(s->ecap & VTD_ECAP_SSTS); case VTD_SM_PASID_ENTRY_NESTED: /* Not support NESTED page table type yet */ return false; @@ -889,13 +889,13 @@ static int vtd_get_pe_in_pasid_leaf_table(IntelIOMMUS= tate *s, } =20 pgtt =3D VTD_PE_GET_TYPE(pe); - if (pgtt =3D=3D VTD_SM_PASID_ENTRY_SLT && - !vtd_is_sl_level_supported(s, VTD_PE_GET_SL_LEVEL(pe))) { + if (pgtt =3D=3D VTD_SM_PASID_ENTRY_SST && + !vtd_is_ss_level_supported(s, VTD_PE_GET_SS_LEVEL(pe))) { return -VTD_FR_PASID_TABLE_ENTRY_INV; } =20 - if (pgtt =3D=3D VTD_SM_PASID_ENTRY_FLT && - !vtd_is_fl_level_supported(s, VTD_PE_GET_FL_LEVEL(pe))) { + if (pgtt =3D=3D VTD_SM_PASID_ENTRY_FST && + !vtd_is_fs_level_supported(s, VTD_PE_GET_FS_LEVEL(pe))) { return -VTD_FR_PASID_TABLE_ENTRY_INV; } =20 @@ -1013,7 +1013,8 @@ static int vtd_ce_get_pasid_fpd(IntelIOMMUState *s, return 0; } =20 -/* Get the page-table level that hardware should use for the second-level +/* + * Get the page-table level that hardware should use for the second-stage * page-table walk from the Address Width field of context-entry. */ static inline uint32_t vtd_ce_get_level(VTDContextEntry *ce) @@ -1029,10 +1030,10 @@ static uint32_t vtd_get_iova_level(IntelIOMMUState = *s, =20 if (s->root_scalable) { vtd_ce_get_pasid_entry(s, ce, &pe, pasid); - if (s->flts) { - return VTD_PE_GET_FL_LEVEL(&pe); + if (s->fsts) { + return VTD_PE_GET_FS_LEVEL(&pe); } else { - return VTD_PE_GET_SL_LEVEL(&pe); + return VTD_PE_GET_SS_LEVEL(&pe); } } =20 @@ -1101,7 +1102,7 @@ static inline uint64_t vtd_iova_limit(IntelIOMMUState= *s, } =20 /* Return true if IOVA passes range check, otherwise false. */ -static inline bool vtd_iova_sl_range_check(IntelIOMMUState *s, +static inline bool vtd_iova_ss_range_check(IntelIOMMUState *s, uint64_t iova, VTDContextEntry = *ce, uint8_t aw, uint32_t pasid) { @@ -1120,14 +1121,14 @@ static dma_addr_t vtd_get_iova_pgtbl_base(IntelIOMM= UState *s, =20 if (s->root_scalable) { vtd_ce_get_pasid_entry(s, ce, &pe, pasid); - if (s->flts) { - return pe.val[2] & VTD_SM_PASID_ENTRY_FLPTPTR; + if (s->fsts) { + return pe.val[2] & VTD_SM_PASID_ENTRY_FSPTPTR; } else { - return pe.val[0] & VTD_SM_PASID_ENTRY_SLPTPTR; + return pe.val[0] & VTD_SM_PASID_ENTRY_SSPTPTR; } } =20 - return vtd_ce_get_slpt_base(ce); + return vtd_ce_get_sspt_base(ce); } =20 /* @@ -1142,13 +1143,13 @@ static dma_addr_t vtd_get_iova_pgtbl_base(IntelIOMM= UState *s, static uint64_t vtd_spte_rsvd[VTD_SPTE_RSVD_LEN]; static uint64_t vtd_spte_rsvd_large[VTD_SPTE_RSVD_LEN]; =20 -static bool vtd_slpte_nonzero_rsvd(uint64_t slpte, uint32_t level) +static bool vtd_sspte_nonzero_rsvd(uint64_t sspte, uint32_t level) { uint64_t rsvd_mask; =20 /* * We should have caught a guest-mis-programmed level earlier, - * via vtd_is_sl_level_supported. + * via vtd_is_ss_level_supported. */ assert(level < VTD_SPTE_RSVD_LEN); /* @@ -1158,46 +1159,47 @@ static bool vtd_slpte_nonzero_rsvd(uint64_t slpte, = uint32_t level) assert(level); =20 if ((level =3D=3D VTD_PD_LEVEL || level =3D=3D VTD_PDP_LEVEL) && - (slpte & VTD_PT_PAGE_SIZE_MASK)) { + (sspte & VTD_PT_PAGE_SIZE_MASK)) { /* large page */ rsvd_mask =3D vtd_spte_rsvd_large[level]; } else { rsvd_mask =3D vtd_spte_rsvd[level]; } =20 - return slpte & rsvd_mask; + return sspte & rsvd_mask; } =20 -/* Given the @iova, get relevant @slptep. @slpte_level will be the last le= vel +/* + * Given the @iova, get relevant @ssptep. @sspte_level will be the last le= vel * of the translation, can be used for deciding the size of large page. */ -static int vtd_iova_to_slpte(IntelIOMMUState *s, VTDContextEntry *ce, +static int vtd_iova_to_sspte(IntelIOMMUState *s, VTDContextEntry *ce, uint64_t iova, bool is_write, - uint64_t *slptep, uint32_t *slpte_level, + uint64_t *ssptep, uint32_t *sspte_level, bool *reads, bool *writes, uint8_t aw_bits, uint32_t pasid) { dma_addr_t addr =3D vtd_get_iova_pgtbl_base(s, ce, pasid); uint32_t level =3D vtd_get_iova_level(s, ce, pasid); uint32_t offset; - uint64_t slpte; + uint64_t sspte; uint64_t access_right_check; =20 - if (!vtd_iova_sl_range_check(s, iova, ce, aw_bits, pasid)) { + if (!vtd_iova_ss_range_check(s, iova, ce, aw_bits, pasid)) { error_report_once("%s: detected IOVA overflow (iova=3D0x%" PRIx64 = "," "pasid=3D0x%" PRIx32 ")", __func__, iova, pasid); return -VTD_FR_ADDR_BEYOND_MGAW; } =20 /* FIXME: what is the Atomics request here? */ - access_right_check =3D is_write ? VTD_SL_W : VTD_SL_R; + access_right_check =3D is_write ? VTD_SS_W : VTD_SS_R; =20 while (true) { offset =3D vtd_iova_level_offset(iova, level); - slpte =3D vtd_get_pte(addr, offset); + sspte =3D vtd_get_pte(addr, offset); =20 - if (slpte =3D=3D (uint64_t)-1) { - error_report_once("%s: detected read error on DMAR slpte " + if (sspte =3D=3D (uint64_t)-1) { + error_report_once("%s: detected read error on DMAR sspte " "(iova=3D0x%" PRIx64 ", pasid=3D0x%" PRIx32 = ")", __func__, iova, pasid); if (level =3D=3D vtd_get_iova_level(s, ce, pasid)) { @@ -1207,30 +1209,30 @@ static int vtd_iova_to_slpte(IntelIOMMUState *s, VT= DContextEntry *ce, return -VTD_FR_PAGING_ENTRY_INV; } } - *reads =3D (*reads) && (slpte & VTD_SL_R); - *writes =3D (*writes) && (slpte & VTD_SL_W); - if (!(slpte & access_right_check)) { - error_report_once("%s: detected slpte permission error " + *reads =3D (*reads) && (sspte & VTD_SS_R); + *writes =3D (*writes) && (sspte & VTD_SS_W); + if (!(sspte & access_right_check)) { + error_report_once("%s: detected sspte permission error " "(iova=3D0x%" PRIx64 ", level=3D0x%" PRIx32 = ", " - "slpte=3D0x%" PRIx64 ", write=3D%d, pasid=3D= 0x%" + "sspte=3D0x%" PRIx64 ", write=3D%d, pasid=3D= 0x%" PRIx32 ")", __func__, iova, level, - slpte, is_write, pasid); + sspte, is_write, pasid); return is_write ? -VTD_FR_WRITE : -VTD_FR_READ; } - if (vtd_slpte_nonzero_rsvd(slpte, level)) { + if (vtd_sspte_nonzero_rsvd(sspte, level)) { error_report_once("%s: detected splte reserve non-zero " "iova=3D0x%" PRIx64 ", level=3D0x%" PRIx32 - "slpte=3D0x%" PRIx64 ", pasid=3D0x%" PRIX32 = ")", - __func__, iova, level, slpte, pasid); + "sspte=3D0x%" PRIx64 ", pasid=3D0x%" PRIX32 = ")", + __func__, iova, level, sspte, pasid); return -VTD_FR_PAGING_ENTRY_RSVD; } =20 - if (vtd_is_last_pte(slpte, level)) { - *slptep =3D slpte; - *slpte_level =3D level; + if (vtd_is_last_pte(sspte, level)) { + *ssptep =3D sspte; + *sspte_level =3D level; break; } - addr =3D vtd_get_pte_addr(slpte, aw_bits); + addr =3D vtd_get_pte_addr(sspte, aw_bits); level--; } =20 @@ -1356,7 +1358,7 @@ static int vtd_page_walk_level(dma_addr_t addr, uint6= 4_t start, { bool read_cur, write_cur, entry_valid; uint32_t offset; - uint64_t slpte; + uint64_t sspte; uint64_t subpage_size, subpage_mask; IOMMUTLBEvent event; uint64_t iova =3D start; @@ -1372,21 +1374,21 @@ static int vtd_page_walk_level(dma_addr_t addr, uin= t64_t start, iova_next =3D (iova & subpage_mask) + subpage_size; =20 offset =3D vtd_iova_level_offset(iova, level); - slpte =3D vtd_get_pte(addr, offset); + sspte =3D vtd_get_pte(addr, offset); =20 - if (slpte =3D=3D (uint64_t)-1) { + if (sspte =3D=3D (uint64_t)-1) { trace_vtd_page_walk_skip_read(iova, iova_next); goto next; } =20 - if (vtd_slpte_nonzero_rsvd(slpte, level)) { + if (vtd_sspte_nonzero_rsvd(sspte, level)) { trace_vtd_page_walk_skip_reserve(iova, iova_next); goto next; } =20 /* Permissions are stacked with parents' */ - read_cur =3D read && (slpte & VTD_SL_R); - write_cur =3D write && (slpte & VTD_SL_W); + read_cur =3D read && (sspte & VTD_SS_R); + write_cur =3D write && (sspte & VTD_SS_W); =20 /* * As long as we have either read/write permission, this is a @@ -1395,12 +1397,12 @@ static int vtd_page_walk_level(dma_addr_t addr, uin= t64_t start, */ entry_valid =3D read_cur | write_cur; =20 - if (!vtd_is_last_pte(slpte, level) && entry_valid) { + if (!vtd_is_last_pte(sspte, level) && entry_valid) { /* * This is a valid PDE (or even bigger than PDE). We need * to walk one further level. */ - ret =3D vtd_page_walk_level(vtd_get_pte_addr(slpte, info->aw), + ret =3D vtd_page_walk_level(vtd_get_pte_addr(sspte, info->aw), iova, MIN(iova_next, end), level - 1, read_cur, write_cur, info); } else { @@ -1417,7 +1419,7 @@ static int vtd_page_walk_level(dma_addr_t addr, uint6= 4_t start, event.entry.perm =3D IOMMU_ACCESS_FLAG(read_cur, write_cur); event.entry.addr_mask =3D ~subpage_mask; /* NOTE: this is only meaningful if entry_valid =3D=3D true */ - event.entry.translated_addr =3D vtd_get_pte_addr(slpte, info->= aw); + event.entry.translated_addr =3D vtd_get_pte_addr(sspte, info->= aw); event.type =3D event.entry.perm ? IOMMU_NOTIFIER_MAP : IOMMU_NOTIFIER_UNMAP; ret =3D vtd_page_walk_one(&event, info); @@ -1451,11 +1453,11 @@ static int vtd_page_walk(IntelIOMMUState *s, VTDCon= textEntry *ce, dma_addr_t addr =3D vtd_get_iova_pgtbl_base(s, ce, pasid); uint32_t level =3D vtd_get_iova_level(s, ce, pasid); =20 - if (!vtd_iova_sl_range_check(s, start, ce, info->aw, pasid)) { + if (!vtd_iova_ss_range_check(s, start, ce, info->aw, pasid)) { return -VTD_FR_ADDR_BEYOND_MGAW; } =20 - if (!vtd_iova_sl_range_check(s, end, ce, info->aw, pasid)) { + if (!vtd_iova_ss_range_check(s, end, ce, info->aw, pasid)) { /* Fix end so that it reaches the maximum */ end =3D vtd_iova_limit(s, ce, info->aw, pasid); } @@ -1568,7 +1570,7 @@ static int vtd_dev_to_context_entry(IntelIOMMUState *= s, uint8_t bus_num, =20 /* Check if the programming of context-entry is valid */ if (!s->root_scalable && - !vtd_is_sl_level_supported(s, vtd_ce_get_level(ce))) { + !vtd_is_ss_level_supported(s, vtd_ce_get_level(ce))) { error_report_once("%s: invalid context entry: hi=3D%"PRIx64 ", lo=3D%"PRIx64" (level %d not supported)", __func__, ce->hi, ce->lo, @@ -1672,10 +1674,9 @@ static int vtd_address_space_sync(VTDAddressSpace *v= td_as) } =20 /* - * Check if specific device is configured to bypass address - * translation for DMA requests. In Scalable Mode, bypass - * 1st-level translation or 2nd-level translation, it depends - * on PGTT setting. + * Check if specific device is configured to bypass address translation + * for DMA requests. In Scalable Mode, bypass first stage translation + * or second stage translation, it depends on PGTT setting. */ static bool vtd_dev_pt_enabled(IntelIOMMUState *s, VTDContextEntry *ce, uint32_t pasid) @@ -1913,13 +1914,13 @@ out: static uint64_t vtd_fpte_rsvd[VTD_FPTE_RSVD_LEN]; static uint64_t vtd_fpte_rsvd_large[VTD_FPTE_RSVD_LEN]; =20 -static bool vtd_flpte_nonzero_rsvd(uint64_t flpte, uint32_t level) +static bool vtd_fspte_nonzero_rsvd(uint64_t fspte, uint32_t level) { uint64_t rsvd_mask; =20 /* * We should have caught a guest-mis-programmed level earlier, - * via vtd_is_fl_level_supported. + * via vtd_is_fs_level_supported. */ assert(level < VTD_FPTE_RSVD_LEN); /* @@ -1929,23 +1930,23 @@ static bool vtd_flpte_nonzero_rsvd(uint64_t flpte, = uint32_t level) assert(level); =20 if ((level =3D=3D VTD_PD_LEVEL || level =3D=3D VTD_PDP_LEVEL) && - (flpte & VTD_PT_PAGE_SIZE_MASK)) { + (fspte & VTD_PT_PAGE_SIZE_MASK)) { /* large page */ rsvd_mask =3D vtd_fpte_rsvd_large[level]; } else { rsvd_mask =3D vtd_fpte_rsvd[level]; } =20 - return flpte & rsvd_mask; + return fspte & rsvd_mask; } =20 -static inline bool vtd_flpte_present(uint64_t flpte) +static inline bool vtd_fspte_present(uint64_t fspte) { - return !!(flpte & VTD_FL_P); + return !!(fspte & VTD_FS_P); } =20 /* Return true if IOVA is canonical, otherwise false. */ -static bool vtd_iova_fl_check_canonical(IntelIOMMUState *s, uint64_t iova, +static bool vtd_iova_fs_check_canonical(IntelIOMMUState *s, uint64_t iova, VTDContextEntry *ce, uint32_t pasi= d) { uint64_t iova_limit =3D vtd_iova_limit(s, ce, s->aw_bits, pasid); @@ -1975,32 +1976,32 @@ static MemTxResult vtd_set_flag_in_pte(dma_addr_t b= ase_addr, uint32_t index, } =20 /* - * Given the @iova, get relevant @flptep. @flpte_level will be the last le= vel + * Given the @iova, get relevant @fsptep. @fspte_level will be the last le= vel * of the translation, can be used for deciding the size of large page. */ -static int vtd_iova_to_flpte(IntelIOMMUState *s, VTDContextEntry *ce, +static int vtd_iova_to_fspte(IntelIOMMUState *s, VTDContextEntry *ce, uint64_t iova, bool is_write, - uint64_t *flptep, uint32_t *flpte_level, + uint64_t *fsptep, uint32_t *fspte_level, bool *reads, bool *writes, uint8_t aw_bits, uint32_t pasid) { dma_addr_t addr =3D vtd_get_iova_pgtbl_base(s, ce, pasid); uint32_t offset; - uint64_t flpte, flag_ad =3D VTD_FL_A; - *flpte_level =3D vtd_get_iova_level(s, ce, pasid); + uint64_t fspte, flag_ad =3D VTD_FS_A; + *fspte_level =3D vtd_get_iova_level(s, ce, pasid); =20 - if (!vtd_iova_fl_check_canonical(s, iova, ce, pasid)) { + if (!vtd_iova_fs_check_canonical(s, iova, ce, pasid)) { error_report_once("%s: detected non canonical IOVA (iova=3D0x%" PR= Ix64 "," "pasid=3D0x%" PRIx32 ")", __func__, iova, pasid); return -VTD_FR_FS_NON_CANONICAL; } =20 while (true) { - offset =3D vtd_iova_level_offset(iova, *flpte_level); - flpte =3D vtd_get_pte(addr, offset); + offset =3D vtd_iova_level_offset(iova, *fspte_level); + fspte =3D vtd_get_pte(addr, offset); =20 - if (flpte =3D=3D (uint64_t)-1) { - if (*flpte_level =3D=3D vtd_get_iova_level(s, ce, pasid)) { + if (fspte =3D=3D (uint64_t)-1) { + if (*fspte_level =3D=3D vtd_get_iova_level(s, ce, pasid)) { /* Invalid programming of pasid-entry */ return -VTD_FR_PASID_ENTRY_FSPTPTR_INV; } else { @@ -2008,47 +2009,47 @@ static int vtd_iova_to_flpte(IntelIOMMUState *s, VT= DContextEntry *ce, } } =20 - if (!vtd_flpte_present(flpte)) { + if (!vtd_fspte_present(fspte)) { *reads =3D false; *writes =3D false; return -VTD_FR_FS_PAGING_ENTRY_P; } =20 /* No emulated device supports supervisor privilege request yet */ - if (!(flpte & VTD_FL_US)) { + if (!(fspte & VTD_FS_US)) { *reads =3D false; *writes =3D false; return -VTD_FR_FS_PAGING_ENTRY_US; } =20 *reads =3D true; - *writes =3D (*writes) && (flpte & VTD_FL_RW); - if (is_write && !(flpte & VTD_FL_RW)) { + *writes =3D (*writes) && (fspte & VTD_FS_RW); + if (is_write && !(fspte & VTD_FS_RW)) { return -VTD_FR_SM_WRITE; } - if (vtd_flpte_nonzero_rsvd(flpte, *flpte_level)) { - error_report_once("%s: detected flpte reserved non-zero " + if (vtd_fspte_nonzero_rsvd(fspte, *fspte_level)) { + error_report_once("%s: detected fspte reserved non-zero " "iova=3D0x%" PRIx64 ", level=3D0x%" PRIx32 - "flpte=3D0x%" PRIx64 ", pasid=3D0x%" PRIX32 = ")", - __func__, iova, *flpte_level, flpte, pasid); + "fspte=3D0x%" PRIx64 ", pasid=3D0x%" PRIX32 = ")", + __func__, iova, *fspte_level, fspte, pasid); return -VTD_FR_FS_PAGING_ENTRY_RSVD; } =20 - if (vtd_is_last_pte(flpte, *flpte_level) && is_write) { - flag_ad |=3D VTD_FL_D; + if (vtd_is_last_pte(fspte, *fspte_level) && is_write) { + flag_ad |=3D VTD_FS_D; } =20 - if (vtd_set_flag_in_pte(addr, offset, flpte, flag_ad) !=3D MEMTX_O= K) { + if (vtd_set_flag_in_pte(addr, offset, fspte, flag_ad) !=3D MEMTX_O= K) { return -VTD_FR_FS_BIT_UPDATE_FAILED; } =20 - if (vtd_is_last_pte(flpte, *flpte_level)) { - *flptep =3D flpte; + if (vtd_is_last_pte(fspte, *fspte_level)) { + *fsptep =3D fspte; return 0; } =20 - addr =3D vtd_get_pte_addr(flpte, aw_bits); - (*flpte_level)--; + addr =3D vtd_get_pte_addr(fspte, aw_bits); + (*fspte_level)--; } } =20 @@ -2186,14 +2187,14 @@ static bool vtd_do_iommu_translate(VTDAddressSpace = *vtd_as, PCIBus *bus, return true; } =20 - if (s->flts && s->root_scalable) { - ret_fr =3D vtd_iova_to_flpte(s, &ce, addr, is_write, &pte, &level, + if (s->fsts && s->root_scalable) { + ret_fr =3D vtd_iova_to_fspte(s, &ce, addr, is_write, &pte, &level, &reads, &writes, s->aw_bits, pasid); - pgtt =3D VTD_SM_PASID_ENTRY_FLT; + pgtt =3D VTD_SM_PASID_ENTRY_FST; } else { - ret_fr =3D vtd_iova_to_slpte(s, &ce, addr, is_write, &pte, &level, + ret_fr =3D vtd_iova_to_sspte(s, &ce, addr, is_write, &pte, &level, &reads, &writes, s->aw_bits, pasid); - pgtt =3D VTD_SM_PASID_ENTRY_SLT; + pgtt =3D VTD_SM_PASID_ENTRY_SST; } if (!ret_fr) { xlat =3D vtd_get_pte_addr(pte, s->aw_bits); @@ -2461,13 +2462,13 @@ static void vtd_iotlb_page_invalidate_notify(IntelI= OMMUState *s, =20 if (vtd_as_has_map_notifier(vtd_as)) { /* - * When stage-1 translation is off, as long as we have MAP + * When first stage translation is off, as long as we have= MAP * notifications registered in any of our IOMMU notifiers, * we need to sync the shadow page table. Otherwise VFIO * device attaches to nested page table instead of shadow * page table, so no need to sync. */ - if (!s->flts || !s->root_scalable) { + if (!s->fsts || !s->root_scalable) { vtd_sync_shadow_page_table_range(vtd_as, &ce, addr, si= ze); } } else { @@ -2965,7 +2966,7 @@ static void vtd_piotlb_pasid_invalidate(IntelIOMMUSta= te *s, continue; } =20 - if (!s->flts || !vtd_as_has_map_notifier(vtd_as)) { + if (!s->fsts || !vtd_as_has_map_notifier(vtd_as)) { vtd_address_space_sync(vtd_as); } } @@ -4060,7 +4061,7 @@ static const Property vtd_properties[] =3D { VTD_HOST_ADDRESS_WIDTH), DEFINE_PROP_BOOL("caching-mode", IntelIOMMUState, caching_mode, FALSE), DEFINE_PROP_BOOL("x-scalable-mode", IntelIOMMUState, scalable_mode, FA= LSE), - DEFINE_PROP_BOOL("x-flts", IntelIOMMUState, flts, FALSE), + DEFINE_PROP_BOOL("x-flts", IntelIOMMUState, fsts, FALSE), DEFINE_PROP_BOOL("snoop-control", IntelIOMMUState, snoop_control, fals= e), DEFINE_PROP_BOOL("x-pasid-mode", IntelIOMMUState, pasid, false), DEFINE_PROP_BOOL("dma-drain", IntelIOMMUState, dma_drain, true), @@ -4585,12 +4586,13 @@ static bool vtd_check_hiod(IntelIOMMUState *s, Host= IOMMUDevice *hiod, return false; } =20 - if (!s->flts) { - /* All checks requested by VTD stage-2 translation pass */ + if (!s->fsts) { + /* All checks requested by VTD second stage translation pass */ return true; } =20 - error_setg(errp, "host device is uncompatible with stage-1 translation= "); + error_setg(errp, + "host device is uncompatible with first stage translation"); return false; } =20 @@ -4782,7 +4784,7 @@ static void vtd_cap_init(IntelIOMMUState *s) X86IOMMUState *x86_iommu =3D X86_IOMMU_DEVICE(s); =20 s->cap =3D VTD_CAP_FRO | VTD_CAP_NFR | VTD_CAP_ND | - VTD_CAP_MAMV | VTD_CAP_PSI | VTD_CAP_SLLPS | + VTD_CAP_MAMV | VTD_CAP_PSI | VTD_CAP_SSLPS | VTD_CAP_ESRTPS | VTD_CAP_MGAW(s->aw_bits); if (s->dma_drain) { s->cap |=3D VTD_CAP_DRAIN; @@ -4818,13 +4820,13 @@ static void vtd_cap_init(IntelIOMMUState *s) } =20 /* TODO: read cap/ecap from host to decide which cap to be exposed. */ - if (s->flts) { - s->ecap |=3D VTD_ECAP_SMTS | VTD_ECAP_FLTS; + if (s->fsts) { + s->ecap |=3D VTD_ECAP_SMTS | VTD_ECAP_FSTS; if (s->fs1gp) { s->cap |=3D VTD_CAP_FS1GP; } } else if (s->scalable_mode) { - s->ecap |=3D VTD_ECAP_SMTS | VTD_ECAP_SRS | VTD_ECAP_SLTS; + s->ecap |=3D VTD_ECAP_SMTS | VTD_ECAP_SRS | VTD_ECAP_SSTS; } =20 if (s->snoop_control) { @@ -5132,7 +5134,7 @@ static int vtd_pri_perform_implicit_invalidation(VTDA= ddressSpace *vtd_as, domain_id =3D VTD_SM_PASID_ENTRY_DID(pe.val[1]); ret =3D 0; switch (pgtt) { - case VTD_SM_PASID_ENTRY_FLT: + case VTD_SM_PASID_ENTRY_FST: vtd_piotlb_page_invalidate(s, domain_id, vtd_as->pasid, addr, 0); break; /* Room for other pgtt values */ @@ -5334,12 +5336,12 @@ static bool vtd_decide_config(IntelIOMMUState *s, E= rror **errp) } } =20 - if (!s->scalable_mode && s->flts) { + if (!s->scalable_mode && s->fsts) { error_setg(errp, "x-flts is only available in scalable mode"); return false; } =20 - if (!s->flts && s->aw_bits !=3D VTD_HOST_AW_39BIT && + if (!s->fsts && s->aw_bits !=3D VTD_HOST_AW_39BIT && s->aw_bits !=3D VTD_HOST_AW_48BIT) { error_setg(errp, "%s: supported values for aw-bits are: %d, %d", s->scalable_mode ? "Scalable mode(flts=3Doff)" : "Legac= y mode", @@ -5347,10 +5349,9 @@ static bool vtd_decide_config(IntelIOMMUState *s, Er= ror **errp) return false; } =20 - if (s->flts && s->aw_bits !=3D VTD_HOST_AW_48BIT) { - error_setg(errp, - "Scalable mode(flts=3Don): supported value for aw-bits = is: %d", - VTD_HOST_AW_48BIT); + if (s->fsts && s->aw_bits !=3D VTD_HOST_AW_48BIT) { + error_setg(errp, "Scalable mode(x-flts=3Don): supported value for " + "aw-bits is: %d", VTD_HOST_AW_48BIT); return false; } =20 diff --git a/tests/qtest/intel-iommu-test.c b/tests/qtest/intel-iommu-test.c index c521b3796e..e5cc6acaf0 100644 --- a/tests/qtest/intel-iommu-test.c +++ b/tests/qtest/intel-iommu-test.c @@ -13,9 +13,9 @@ #include "hw/i386/intel_iommu_internal.h" =20 #define CAP_STAGE_1_FIXED1 (VTD_CAP_FRO | VTD_CAP_NFR | VTD_CAP_ND | \ - VTD_CAP_MAMV | VTD_CAP_PSI | VTD_CAP_SLLPS) + VTD_CAP_MAMV | VTD_CAP_PSI | VTD_CAP_SSLPS) #define ECAP_STAGE_1_FIXED1 (VTD_ECAP_QI | VTD_ECAP_IR | VTD_ECAP_IRO |= \ - VTD_ECAP_MHMV | VTD_ECAP_SMTS | VTD_ECAP_FLT= S) + VTD_ECAP_MHMV | VTD_ECAP_SMTS | VTD_ECAP_FST= S) =20 static inline uint64_t vtd_reg_readq(QTestState *s, uint64_t offset) { --=20 2.47.1 From nobody Mon Dec 15 12:39:58 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1765781561; cv=none; d=zohomail.com; s=zohoarc; b=hCn+ww1JIZsejml8X8v0Dty1KtbCZQ6k6jj0hI1rv26yKoTJLvD1/N2tOLZhnELMJ9wAhtXvgx7pVqJtdoMlPQMHHtnLrv4/DbErFdTwbr0LQQmoteIjsJFKAmU52DM2n88b7Hf3zJxj3cYlQo8tkbGvaKvUAPsLYpghgPM8QNc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1765781561; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=hWOF0G9OmpVPSkoVR4HP0c1RrEnFkwKI9mWcI4BYA8g=; b=E4XEujQTE12LvJXUtZb9hfGn68lTtUE6hxrRZS4TXzj9/hnw9rIEe4AQ492ZdmmtfgXFA58d3TaF3gDZ8O21gY0m5yd3vy9NEIWy2BTU9R2MUBp8BgLixakqNszifUSWhzQ72JA4AX4WitnvsGuj9YRB28jGeaP0a52sqEDy6Rg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1765781561371439.91365206880516; Sun, 14 Dec 2025 22:52:41 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vV2Qh-00080Y-9G; Mon, 15 Dec 2025 01:51:36 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vV2Qf-00080E-Gn for qemu-devel@nongnu.org; Mon, 15 Dec 2025 01:51:33 -0500 Received: from mgamail.intel.com ([198.175.65.15]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vV2Qd-0000u9-BG for qemu-devel@nongnu.org; Mon, 15 Dec 2025 01:51:32 -0500 Received: from orviesa009.jf.intel.com ([10.64.159.149]) by orvoesa107.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Dec 2025 22:51:29 -0800 Received: from unknown (HELO gnr-sp-2s-612.sh.intel.com) ([10.112.230.229]) by orviesa009-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Dec 2025 22:51:25 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1765781492; x=1797317492; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=XDnUEaBT3mLSFTfR7mqqUXIcK4G2KiahJspPNGq6d0o=; b=nRzPxImxJEUJ3ljs0QiwRljQseg0NMI9X+9PqwvVQPmVbYxDr9GyZBup aJxtzFoTArz/ieA287qQrnTVlv05kEDhEyGjbhFgi0Nc1vOp3wKB4nzuQ XtSC6BNu0LnRwZcsXvk8/fqnI3x6HWx97QA3gR0qa8a7XC3vO6bbDPUPB Jw6u+yXMlAO+eqWI0PL5aceNWZXzOFiTPEMGWuFTV9XkaRpdvDmydN3rJ SnOsqwQV8KchkrX7HvBszZp9v2K88uDvFs542VBBF3gJx+eZaIv2zo83U dj6WumZ9tqpForQlEnvt4UcS2m4kaOgdlOPEk/bd1FlXt85oWdo+Vzi7j g==; X-CSE-ConnectionGUID: +yIT/iotSLaHgOyiHiFGug== X-CSE-MsgGUID: uGDkTiDcQ3WY1LnX4hvJdw== X-IronPort-AV: E=McAfee;i="6800,10657,11642"; a="71304967" X-IronPort-AV: E=Sophos;i="6.21,150,1763452800"; d="scan'208";a="71304967" X-CSE-ConnectionGUID: Za73tJ6cSgaUpsnRi/74vA== X-CSE-MsgGUID: PclLGV6sTeuEPyb53D5j3Q== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.21,150,1763452800"; d="scan'208";a="197408747" From: Zhenzhong Duan To: qemu-devel@nongnu.org Cc: alex@shazbot.org, clg@redhat.com, eric.auger@redhat.com, mst@redhat.com, jasowang@redhat.com, peterx@redhat.com, ddutile@redhat.com, jgg@nvidia.com, nicolinc@nvidia.com, skolothumtho@nvidia.com, joao.m.martins@oracle.com, clement.mathieu--drif@eviden.com, kevin.tian@intel.com, yi.l.liu@intel.com, chao.p.peng@intel.com, Zhenzhong Duan Subject: [PATCH v9 04/19] hw/pci: Export pci_device_get_iommu_bus_devfn() and return bool Date: Mon, 15 Dec 2025 01:50:28 -0500 Message-ID: <20251215065046.86991-5-zhenzhong.duan@intel.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20251215065046.86991-1-zhenzhong.duan@intel.com> References: <20251215065046.86991-1-zhenzhong.duan@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=198.175.65.15; envelope-from=zhenzhong.duan@intel.com; helo=mgamail.intel.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1765781563146158500 Content-Type: text/plain; charset="utf-8" Returns true if PCI device is aliased or false otherwise. This will be used in following patch to determine if a PCI device is under a PCI bridge. Signed-off-by: Zhenzhong Duan Reviewed-by: Eric Auger Reviewed-by: Nicolin Chen Reviewed-by: Yi Liu --- include/hw/pci/pci.h | 2 ++ hw/pci/pci.c | 12 ++++++++---- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/include/hw/pci/pci.h b/include/hw/pci/pci.h index 6bccb25ac2..bde9dca8e2 100644 --- a/include/hw/pci/pci.h +++ b/include/hw/pci/pci.h @@ -637,6 +637,8 @@ typedef struct PCIIOMMUOps { bool is_write); } PCIIOMMUOps; =20 +bool pci_device_get_iommu_bus_devfn(PCIDevice *dev, PCIBus **piommu_bus, + PCIBus **aliased_bus, int *aliased_dev= fn); AddressSpace *pci_device_iommu_address_space(PCIDevice *dev); bool pci_device_set_iommu_device(PCIDevice *dev, HostIOMMUDevice *hiod, Error **errp); diff --git a/hw/pci/pci.c b/hw/pci/pci.c index b1eba348e0..3eb57b96ea 100644 --- a/hw/pci/pci.c +++ b/hw/pci/pci.c @@ -2869,20 +2869,21 @@ static void pci_device_class_base_init(ObjectClass = *klass, const void *data) * For call sites which don't need aliased BDF, passing NULL to * aliased_[bus|devfn] is allowed. * + * Returns true if PCI device RID is aliased or false otherwise. + * * @piommu_bus: return root #PCIBus backed by an IOMMU for the PCI device. * * @aliased_bus: return aliased #PCIBus of the PCI device, optional. * * @aliased_devfn: return aliased devfn of the PCI device, optional. */ -static void pci_device_get_iommu_bus_devfn(PCIDevice *dev, - PCIBus **piommu_bus, - PCIBus **aliased_bus, - int *aliased_devfn) +bool pci_device_get_iommu_bus_devfn(PCIDevice *dev, PCIBus **piommu_bus, + PCIBus **aliased_bus, int *aliased_dev= fn) { PCIBus *bus =3D pci_get_bus(dev); PCIBus *iommu_bus =3D bus; int devfn =3D dev->devfn; + bool aliased =3D false; =20 while (iommu_bus && !iommu_bus->iommu_ops && iommu_bus->parent_dev) { PCIBus *parent_bus =3D pci_get_bus(iommu_bus->parent_dev); @@ -2919,6 +2920,7 @@ static void pci_device_get_iommu_bus_devfn(PCIDevice = *dev, devfn =3D parent->devfn; bus =3D parent_bus; } + aliased =3D true; } =20 /* @@ -2953,6 +2955,8 @@ static void pci_device_get_iommu_bus_devfn(PCIDevice = *dev, if (aliased_devfn) { *aliased_devfn =3D devfn; } + + return aliased; } =20 AddressSpace *pci_device_iommu_address_space(PCIDevice *dev) --=20 2.47.1 From nobody Mon Dec 15 12:39:58 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1765781580; cv=none; d=zohomail.com; s=zohoarc; b=IbJBoYCQErwKJyndFxuO3t+YAdSMgCH+JTwZBPk77I3re1ZhhQJ7PMzYSSjDh/MKluRnZ4caXrLFgXDtT6aGMmfWtUbGRAuPl0nGpSUM1m9itw0YxNEpuga/H2LhH4ubNM2fmCJjRnl+kJc+XRbAAqDn8+sUy1aOhs1BLptbTmg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1765781580; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=G0weip4YfkoUkHuV3u/MlUx1kMy0QgBkWwgj43xgGRg=; b=LUVxuSRMlyDldanw4hUfEegV/Dt+TkoVzGJCMR13hFh6z+1zWtT4hb++SOmct2ijhV1jsrpvdljFuw3z5BoFwJcZm2NN4pd0tvhqse0S3gz77Q/iZo+YjNzJDAiFrPUoJk1aLih+YSy4L7E9MrZmqvdZARooLZ3F4yTHfL5Gxyo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1765781580477395.57387926020874; Sun, 14 Dec 2025 22:53:00 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vV2Qp-00081U-NY; Mon, 15 Dec 2025 01:51:43 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vV2Qi-000810-Mb for qemu-devel@nongnu.org; Mon, 15 Dec 2025 01:51:38 -0500 Received: from mgamail.intel.com ([198.175.65.15]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vV2Qg-0000u9-4h for qemu-devel@nongnu.org; Mon, 15 Dec 2025 01:51:36 -0500 Received: from orviesa009.jf.intel.com ([10.64.159.149]) by orvoesa107.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Dec 2025 22:51:34 -0800 Received: from unknown (HELO gnr-sp-2s-612.sh.intel.com) ([10.112.230.229]) by orviesa009-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Dec 2025 22:51:29 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1765781495; x=1797317495; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=IDqjTPmEfiskGsVfVAVPXLUUK/9gq3KKukts76FWljY=; b=UyDdEWZzDy/UOPECCLbHvbl0feXrqdIa1M3wx5YKAmUKPP+QYadQkE13 KzL7CdjTN2nHvbnedbRlhV2IaUWOLDBG7iHvfIxFyK1NvyiZ0Fayw7CHT T6Lw1MJWazAvJnsB/Hz3KebWuSkxOAWaPs251pMlPw0pRGI1cdk8OrayW 6+gJIMEk3ffrdjq4thRi6wpXlw77BIghCRhGPqMvprvfLWb3Bc+kyvYNh KyJ/XREIILe99VJ0X8mrLjd5hcQ8QqqkpZDWexhm1UBfjGgwO1t+y2NR7 NavQSQsHk7TbSqpiQcvmEGJBazMVwNKWw4JUJFu6yn/+rwqGIlDT4vKiH A==; X-CSE-ConnectionGUID: ftAU2tNhQW+hMA4r5USqPA== X-CSE-MsgGUID: Z5UucovCTy2QcFfm9AEksQ== X-IronPort-AV: E=McAfee;i="6800,10657,11642"; a="71304975" X-IronPort-AV: E=Sophos;i="6.21,150,1763452800"; d="scan'208";a="71304975" X-CSE-ConnectionGUID: F1TfjK+WQdOrv2TsKGoaXQ== X-CSE-MsgGUID: U6yL3LuzSH6H7yDcIa5trQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.21,150,1763452800"; d="scan'208";a="197408753" From: Zhenzhong Duan To: qemu-devel@nongnu.org Cc: alex@shazbot.org, clg@redhat.com, eric.auger@redhat.com, mst@redhat.com, jasowang@redhat.com, peterx@redhat.com, ddutile@redhat.com, jgg@nvidia.com, nicolinc@nvidia.com, skolothumtho@nvidia.com, joao.m.martins@oracle.com, clement.mathieu--drif@eviden.com, kevin.tian@intel.com, yi.l.liu@intel.com, chao.p.peng@intel.com, Zhenzhong Duan Subject: [PATCH v9 05/19] hw/pci: Introduce pci_device_get_viommu_flags() Date: Mon, 15 Dec 2025 01:50:29 -0500 Message-ID: <20251215065046.86991-6-zhenzhong.duan@intel.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20251215065046.86991-1-zhenzhong.duan@intel.com> References: <20251215065046.86991-1-zhenzhong.duan@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=198.175.65.15; envelope-from=zhenzhong.duan@intel.com; helo=mgamail.intel.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1765781581076158500 Introduce a new PCIIOMMUOps optional callback, get_viommu_flags() which allows to retrieve flags exposed by a vIOMMU. The first planned vIOMMU device flag is VIOMMU_FLAG_WANT_NESTING_PARENT that advertises the support of HW nested stage translation scheme and wants other sub-system like VFIO's cooperation to create nesting parent HWPT. pci_device_get_viommu_flags() is a wrapper that can be called on a PCI device potentially protected by a vIOMMU. get_viommu_flags() is designed to return 64bit bitmap of purely vIOMMU flags which are only determined by user's configuration, no host capabilities involved. Reasons are: 1. host may has heterogeneous IOMMUs, each with different capabilities 2. this is migration friendly, return value is consistent between source and target. Note that this op will be invoked at the attach_device() stage, at which point host IOMMU capabilities are not yet forwarded to the vIOMMU through the set_iommu_device() callback that will be after the attach_device(). See below sequence: vfio_device_attach(): iommufd_cdev_attach(): pci_device_get_viommu_flags() for HW nesting cap create a nesting parent HWPT attach device to the HWPT vfio_device_hiod_create_and_realize() creating hiod ... pci_device_set_iommu_device(hiod) Suggested-by: Yi Liu Signed-off-by: Zhenzhong Duan Reviewed-by: Nicolin Chen Reviewed-by: Eric Auger Reviewed-by: Yi Liu Reviewed-by: C=C3=A9dric Le Goater --- MAINTAINERS | 1 + include/hw/iommu.h | 25 +++++++++++++++++++++++++ include/hw/pci/pci.h | 22 ++++++++++++++++++++++ hw/pci/pci.c | 11 +++++++++++ 4 files changed, 59 insertions(+) create mode 100644 include/hw/iommu.h diff --git a/MAINTAINERS b/MAINTAINERS index d007584b47..5529353759 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -2346,6 +2346,7 @@ F: include/system/iommufd.h F: backends/host_iommu_device.c F: include/system/host_iommu_device.h F: include/qemu/chardev_open.h +F: include/hw/iommu.h F: util/chardev_open.c F: docs/devel/vfio-iommufd.rst =20 diff --git a/include/hw/iommu.h b/include/hw/iommu.h new file mode 100644 index 0000000000..9b8bb94fc2 --- /dev/null +++ b/include/hw/iommu.h @@ -0,0 +1,25 @@ +/* + * General vIOMMU flags + * + * Copyright (C) 2025 Intel Corporation. + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#ifndef HW_IOMMU_H +#define HW_IOMMU_H + +#include "qemu/bitops.h" + +/* + * Theoretical vIOMMU flags. Only determined by the vIOMMU device properti= es and + * independent on the actual host IOMMU capabilities they may depend on. E= ach + * flag can be an expectation or request to other sub-system or just a pure + * vIOMMU capability. vIOMMU can choose which flags to expose. + */ +enum viommu_flags { + /* vIOMMU needs nesting parent HWPT to create nested HWPT */ + VIOMMU_FLAG_WANT_NESTING_PARENT =3D BIT_ULL(0), +}; + +#endif /* HW_IOMMU_H */ diff --git a/include/hw/pci/pci.h b/include/hw/pci/pci.h index bde9dca8e2..a3ca54859c 100644 --- a/include/hw/pci/pci.h +++ b/include/hw/pci/pci.h @@ -462,6 +462,18 @@ typedef struct PCIIOMMUOps { * @devfn: device and function number of the PCI device. */ void (*unset_iommu_device)(PCIBus *bus, void *opaque, int devfn); + /** + * @get_viommu_flags: get vIOMMU flags + * + * Optional callback, if not implemented, then vIOMMU doesn't support + * exposing flags to other sub-system, e.g., VFIO. + * + * @opaque: the data passed to pci_setup_iommu(). + * + * Returns: bitmap with each bit representing a vIOMMU flag defined in + * enum viommu_flags. + */ + uint64_t (*get_viommu_flags)(void *opaque); /** * @get_iotlb_info: get properties required to initialize a device IOT= LB. * @@ -644,6 +656,16 @@ bool pci_device_set_iommu_device(PCIDevice *dev, HostI= OMMUDevice *hiod, Error **errp); void pci_device_unset_iommu_device(PCIDevice *dev); =20 +/** + * pci_device_get_viommu_flags: get vIOMMU flags. + * + * Returns: bitmap with each bit representing a vIOMMU flag defined in + * enum viommu_flags. Or 0 if vIOMMU doesn't report any. + * + * @dev: PCI device pointer. + */ +uint64_t pci_device_get_viommu_flags(PCIDevice *dev); + /** * pci_iommu_get_iotlb_info: get properties required to initialize a * device IOTLB. diff --git a/hw/pci/pci.c b/hw/pci/pci.c index 3eb57b96ea..8b62044a8e 100644 --- a/hw/pci/pci.c +++ b/hw/pci/pci.c @@ -3021,6 +3021,17 @@ void pci_device_unset_iommu_device(PCIDevice *dev) } } =20 +uint64_t pci_device_get_viommu_flags(PCIDevice *dev) +{ + PCIBus *iommu_bus; + + pci_device_get_iommu_bus_devfn(dev, &iommu_bus, NULL, NULL); + if (iommu_bus && iommu_bus->iommu_ops->get_viommu_flags) { + return iommu_bus->iommu_ops->get_viommu_flags(iommu_bus->iommu_opa= que); + } + return 0; +} + int pci_pri_request_page(PCIDevice *dev, uint32_t pasid, bool priv_req, bool exec_req, hwaddr addr, bool lpig, uint16_t prgi, bool is_read, bool is_write) --=20 2.47.1 From nobody Mon Dec 15 12:39:58 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1765781629; cv=none; d=zohomail.com; s=zohoarc; b=X4Na4QfnnzF42b0VhFZiv75BpxfxdKPsM0l0MQFeDlgUsCg8XdML05VECPFZ5TuZHVEbnuzbFSyDntoDnn055VodKIaFmLGKDb9351U9XAD9MNbRmRnD8nNmn2+H1Uthcz/jdy4Zzh+VEH9wBETKgi0ZWCORVNy6oSQPeLg039c= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1765781629; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=EILkSlreInAVsSTUGNHb1eArbpYYk1z75keySmPt1b4=; b=VDnPrI+kFsJz5YKRAKNuCK+vhXpw1W3IFjCt0zzm2njwOS59x99GlNmlpbBYv2Oab1zsVckPMKfEtWWCfZSKUoI56Fe8481f4t1bemmJbDYlzR/2mX9HZjNGVTknBk8OsA1rCkxhSwwT+at09t4c3PgkA8WZfXlWEk4N6nEshRg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1765781629043310.13005084336226; Sun, 14 Dec 2025 22:53:49 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vV2Qq-00081x-Qn; Mon, 15 Dec 2025 01:51:44 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vV2Qm-00081J-NU for qemu-devel@nongnu.org; Mon, 15 Dec 2025 01:51:41 -0500 Received: from mgamail.intel.com ([198.175.65.15]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vV2Qk-0000u9-HD for qemu-devel@nongnu.org; Mon, 15 Dec 2025 01:51:39 -0500 Received: from orviesa009.jf.intel.com ([10.64.159.149]) by orvoesa107.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Dec 2025 22:51:38 -0800 Received: from unknown (HELO gnr-sp-2s-612.sh.intel.com) ([10.112.230.229]) by orviesa009-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Dec 2025 22:51:34 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1765781499; x=1797317499; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=+lnzhucuHqjGiQjtymO74OMQe4vZs/s9Ugzcv28XoS4=; b=AVxYkmA+zg6EP3efnheOETNojIaoc3oF1ko/myI3pnloaiKtwp5Q6x56 RBk2Hqr3DQIfmiyAPGU41p4sHzs3u9iRJsZMnDOnUYVEKaBctxLIxRd5Z VgOyogPNObCjM+4gxraiEJBsRGkV12ycfHTpe37M+Z01/sAJLr2rdoRil w57dmrLMoh0irSLaWDkTjTn2me4qeksDGaGuLuwybNQkevp373oNTa8ey lvLfCTZ7zm+tvwh/q3pAkzvaCrkJsOFLYcGVOpIWTtl/pwmsw4TGa2kbP RN/e0KInJvpPj6jz7Z48bFVlveslgYOnOQ04oOrOMUYL/gb4FtariwSBp Q==; X-CSE-ConnectionGUID: jSIatDw1SHebJLxhi/bG4Q== X-CSE-MsgGUID: wSLnkNPOSo6HZZ+Jd1IyLA== X-IronPort-AV: E=McAfee;i="6800,10657,11642"; a="71304982" X-IronPort-AV: E=Sophos;i="6.21,150,1763452800"; d="scan'208";a="71304982" X-CSE-ConnectionGUID: ++0PnQz/RsWSSKXF9FlIlA== X-CSE-MsgGUID: dULeDp0lTba4PgIHqpqTgg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.21,150,1763452800"; d="scan'208";a="197408761" From: Zhenzhong Duan To: qemu-devel@nongnu.org Cc: alex@shazbot.org, clg@redhat.com, eric.auger@redhat.com, mst@redhat.com, jasowang@redhat.com, peterx@redhat.com, ddutile@redhat.com, jgg@nvidia.com, nicolinc@nvidia.com, skolothumtho@nvidia.com, joao.m.martins@oracle.com, clement.mathieu--drif@eviden.com, kevin.tian@intel.com, yi.l.liu@intel.com, chao.p.peng@intel.com, Zhenzhong Duan Subject: [PATCH v9 06/19] intel_iommu: Implement get_viommu_flags() callback Date: Mon, 15 Dec 2025 01:50:30 -0500 Message-ID: <20251215065046.86991-7-zhenzhong.duan@intel.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20251215065046.86991-1-zhenzhong.duan@intel.com> References: <20251215065046.86991-1-zhenzhong.duan@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=198.175.65.15; envelope-from=zhenzhong.duan@intel.com; helo=mgamail.intel.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1765781631619158500 Content-Type: text/plain; charset="utf-8" Implement get_viommu_flags() callback and expose a request for nesting parent HWPT for now. VFIO uses it to create nesting parent HWPT which is further used to create nested HWPT in vIOMMU. All these will be implemented in following patches. Suggested-by: Yi Liu Signed-off-by: Zhenzhong Duan Reviewed-by: Eric Auger Reviewed-by: Nicolin Chen Reviewed-by: Yi Liu --- hw/i386/intel_iommu.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/hw/i386/intel_iommu.c b/hw/i386/intel_iommu.c index 64c5c6cbc2..7fc14509ac 100644 --- a/hw/i386/intel_iommu.c +++ b/hw/i386/intel_iommu.c @@ -24,6 +24,7 @@ #include "qemu/main-loop.h" #include "qapi/error.h" #include "hw/sysbus.h" +#include "hw/iommu.h" #include "intel_iommu_internal.h" #include "hw/pci/pci.h" #include "hw/pci/pci_bus.h" @@ -4659,6 +4660,16 @@ static void vtd_dev_unset_iommu_device(PCIBus *bus, = void *opaque, int devfn) vtd_iommu_unlock(s); } =20 +static uint64_t vtd_get_viommu_flags(void *opaque) +{ + IntelIOMMUState *s =3D opaque; + uint64_t flags; + + flags =3D s->fsts ? VIOMMU_FLAG_WANT_NESTING_PARENT : 0; + + return flags; +} + /* Unmap the whole range in the notifier's scope. */ static void vtd_address_space_unmap(VTDAddressSpace *as, IOMMUNotifier *n) { @@ -5312,6 +5323,7 @@ static PCIIOMMUOps vtd_iommu_ops =3D { .pri_register_notifier =3D vtd_pri_register_notifier, .pri_unregister_notifier =3D vtd_pri_unregister_notifier, .pri_request_page =3D vtd_pri_request_page, + .get_viommu_flags =3D vtd_get_viommu_flags, }; =20 static bool vtd_decide_config(IntelIOMMUState *s, Error **errp) --=20 2.47.1 From nobody Mon Dec 15 12:39:58 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1765781555; cv=none; d=zohomail.com; s=zohoarc; b=lf+q55ZpYImB5DW4FN7PHdCqXZgutPbYRi7G3+ZxBbFjBlCE2HsMQ6JPq1/0Lrp3zHG3O/ymEwupUW2DMLZihPX/MfFEefYPx6aaIS7M9aDT+hiAYji/N2qSskFjqi8WIRn6qgxnHbf8A9DnwJzPxHmwxC8OfieMIkLxnD5CECo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1765781555; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=Ahjp0NM53PJqtjmum2JjE/A9054G1ldQy5ndzeE/wDw=; b=T1rZM0PblTYn/DygB5xUZsUnxRmPpUyYXah6G/vsehkYB33nD06bJQ1uedCl+rw2QIp2nZtmqrr1ExfBROLAHitNj59KJqQpRblT7yKCiHqt06VD6JsQCCgV5pBYChVMpooCxCjco4qRRtA/2SnbZugaoyXntbPsKuS68AmlSQA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1765781555425447.2441898635735; Sun, 14 Dec 2025 22:52:35 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vV2Qs-00082c-Dk; Mon, 15 Dec 2025 01:51:46 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vV2Qr-000824-6n for qemu-devel@nongnu.org; Mon, 15 Dec 2025 01:51:45 -0500 Received: from mgamail.intel.com ([198.175.65.15]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vV2Qp-0000u9-GC for qemu-devel@nongnu.org; Mon, 15 Dec 2025 01:51:44 -0500 Received: from orviesa009.jf.intel.com ([10.64.159.149]) by orvoesa107.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Dec 2025 22:51:43 -0800 Received: from unknown (HELO gnr-sp-2s-612.sh.intel.com) ([10.112.230.229]) by orviesa009-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Dec 2025 22:51:38 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1765781504; x=1797317504; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=w3h2Y8fCD3LTF7Ri2xKlMng6dLpw6QxWjGnGzlxLaJk=; b=oKafmmxD2qYh8N6dXPzvM7xaZ3/WggV4Mv8DQZh69P8JlVEjUT29W641 eGRPsdV09zhro7lecLQrpuE4BBd06nygsBRIsxQ9oe7UeVsoTxjm0oStn NsrUC9UBTyezyxipLh6MWNDb4P0F4V9UmLyHEpKRQkR74OalwbwnAy9/h VwLV6xrT/U1ZUsKLFRiumRJ03OEvFak0AbkCCLIzy93WZ+j7OgCFDS2AZ fA8MeZ3TVV/M2H4+qYNs341F2CXWAPgrOOWir/uct7FgkLGbv5vCbv/Iy q1tzmKXRPm7qTsNUSwpogRnnUuClxmWF9AaKIZhcSRTcPxEupgOMUBNGA w==; X-CSE-ConnectionGUID: h0OZoGJoTn+NOw/J8ImsmQ== X-CSE-MsgGUID: 3oGbim9bSPKIQ7CzHImTcQ== X-IronPort-AV: E=McAfee;i="6800,10657,11642"; a="71304989" X-IronPort-AV: E=Sophos;i="6.21,150,1763452800"; d="scan'208";a="71304989" X-CSE-ConnectionGUID: 2EUykbiUSFSCxtEknM9SCA== X-CSE-MsgGUID: 3HGwLXK9ScW0Jsldpulfog== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.21,150,1763452800"; d="scan'208";a="197408767" From: Zhenzhong Duan To: qemu-devel@nongnu.org Cc: alex@shazbot.org, clg@redhat.com, eric.auger@redhat.com, mst@redhat.com, jasowang@redhat.com, peterx@redhat.com, ddutile@redhat.com, jgg@nvidia.com, nicolinc@nvidia.com, skolothumtho@nvidia.com, joao.m.martins@oracle.com, clement.mathieu--drif@eviden.com, kevin.tian@intel.com, yi.l.liu@intel.com, chao.p.peng@intel.com, Zhenzhong Duan Subject: [PATCH v9 07/19] intel_iommu: Introduce a new structure VTDHostIOMMUDevice Date: Mon, 15 Dec 2025 01:50:31 -0500 Message-ID: <20251215065046.86991-8-zhenzhong.duan@intel.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20251215065046.86991-1-zhenzhong.duan@intel.com> References: <20251215065046.86991-1-zhenzhong.duan@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=198.175.65.15; envelope-from=zhenzhong.duan@intel.com; helo=mgamail.intel.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1765781557083158500 Content-Type: text/plain; charset="utf-8" Introduce a new structure VTDHostIOMMUDevice which replaces HostIOMMUDevice to be stored in hash table. It includes a reference to HostIOMMUDevice and IntelIOMMUState, also includes BDF information which will be used in future patches. Signed-off-by: Zhenzhong Duan Reviewed-by: Eric Auger Reviewed-by: Nicolin Chen Reviewed-by: Yi Liu --- hw/i386/intel_iommu_internal.h | 7 +++++++ include/hw/i386/intel_iommu.h | 2 +- hw/i386/intel_iommu.c | 15 +++++++++++++-- 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/hw/i386/intel_iommu_internal.h b/hw/i386/intel_iommu_internal.h index 3330298884..02522f64e0 100644 --- a/hw/i386/intel_iommu_internal.h +++ b/hw/i386/intel_iommu_internal.h @@ -28,6 +28,7 @@ #ifndef HW_I386_INTEL_IOMMU_INTERNAL_H #define HW_I386_INTEL_IOMMU_INTERNAL_H #include "hw/i386/intel_iommu.h" +#include "system/host_iommu_device.h" =20 /* * Intel IOMMU register specification @@ -678,4 +679,10 @@ typedef struct VTDPASIDCacheInfo { /* Bits to decide the offset for each level */ #define VTD_LEVEL_BITS 9 =20 +typedef struct VTDHostIOMMUDevice { + IntelIOMMUState *iommu_state; + PCIBus *bus; + uint8_t devfn; + HostIOMMUDevice *hiod; +} VTDHostIOMMUDevice; #endif diff --git a/include/hw/i386/intel_iommu.h b/include/hw/i386/intel_iommu.h index 0b7832d25d..401322665a 100644 --- a/include/hw/i386/intel_iommu.h +++ b/include/hw/i386/intel_iommu.h @@ -302,7 +302,7 @@ struct IntelIOMMUState { /* list of registered notifiers */ QLIST_HEAD(, VTDAddressSpace) vtd_as_with_notifiers; =20 - GHashTable *vtd_host_iommu_dev; /* HostIOMMUDevice */ + GHashTable *vtd_host_iommu_dev; /* VTDHostIOMMUDevice */ =20 /* interrupt remapping */ bool intr_enabled; /* Whether guest enabled IR */ diff --git a/hw/i386/intel_iommu.c b/hw/i386/intel_iommu.c index 7fc14509ac..4585af1fe5 100644 --- a/hw/i386/intel_iommu.c +++ b/hw/i386/intel_iommu.c @@ -288,7 +288,10 @@ static gboolean vtd_hiod_equal(gconstpointer v1, gcons= tpointer v2) =20 static void vtd_hiod_destroy(gpointer v) { - object_unref(v); + VTDHostIOMMUDevice *vtd_hiod =3D v; + + object_unref(vtd_hiod->hiod); + g_free(vtd_hiod); } =20 static gboolean vtd_hash_remove_by_domain(gpointer key, gpointer value, @@ -4601,6 +4604,7 @@ static bool vtd_dev_set_iommu_device(PCIBus *bus, voi= d *opaque, int devfn, HostIOMMUDevice *hiod, Error **errp) { IntelIOMMUState *s =3D opaque; + VTDHostIOMMUDevice *vtd_hiod; struct vtd_as_key key =3D { .bus =3D bus, .devfn =3D devfn, @@ -4623,7 +4627,14 @@ static bool vtd_dev_set_iommu_device(PCIBus *bus, vo= id *opaque, int devfn, return false; } =20 + vtd_hiod =3D g_malloc0(sizeof(VTDHostIOMMUDevice)); + vtd_hiod->bus =3D bus; + vtd_hiod->devfn =3D (uint8_t)devfn; + vtd_hiod->iommu_state =3D s; + vtd_hiod->hiod =3D hiod; + if (!vtd_check_hiod(s, hiod, errp)) { + g_free(vtd_hiod); vtd_iommu_unlock(s); return false; } @@ -4633,7 +4644,7 @@ static bool vtd_dev_set_iommu_device(PCIBus *bus, voi= d *opaque, int devfn, new_key->devfn =3D devfn; =20 object_ref(hiod); - g_hash_table_insert(s->vtd_host_iommu_dev, new_key, hiod); + g_hash_table_insert(s->vtd_host_iommu_dev, new_key, vtd_hiod); =20 vtd_iommu_unlock(s); =20 --=20 2.47.1 From nobody Mon Dec 15 12:39:58 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1765781522; cv=none; d=zohomail.com; s=zohoarc; b=kjd1e7qRmi7j59vg0+vC043Xtp5stK5x8iftrh1eHU/c5xnUalAejkXy+If7BnyScjB6uSvZh3F287NOLv3QvWhO20EAJBcsvR+F2wEcu2T/qZLZg7ZhcvnAmw5DF4yihQ8BYugeUWMNAF9OAMWyzT9YV7jszCqBU2qa6TbonlM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1765781522; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=UucGS8QHrnEOPyb8MjHqOIZBMFkWXUEQr7QQDKzqinU=; b=ESFZLPmIzCVpJG4UwxFhL7+zovGgay9ebuMK+u2OIHUftamlkHQYHo5Ix/bTpYrb2vjYowahp3Rg+UwIG9GzHV5gqFFgKdfFMV2GOHeTsoHNj4mhKXg9nYASiEo5DRUQ9dI+V7Z75oKSd/qfmhSiU9yKZ/X8D5za2jjRPse1ZvU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1765781522897632.2728311711099; Sun, 14 Dec 2025 22:52:02 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vV2Qx-00083L-0F; Mon, 15 Dec 2025 01:51:51 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vV2Qv-000835-DI for qemu-devel@nongnu.org; Mon, 15 Dec 2025 01:51:49 -0500 Received: from mgamail.intel.com ([198.175.65.15]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vV2Qt-0000u9-EC for qemu-devel@nongnu.org; Mon, 15 Dec 2025 01:51:49 -0500 Received: from orviesa009.jf.intel.com ([10.64.159.149]) by orvoesa107.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Dec 2025 22:51:47 -0800 Received: from unknown (HELO gnr-sp-2s-612.sh.intel.com) ([10.112.230.229]) by orviesa009-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Dec 2025 22:51:43 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1765781508; x=1797317508; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=/UKc8gFWpDNMwE+c/sx7DfhfQm/FgyBSEYrB8dOna6g=; b=j97E0a3+w4ait8jEiybLo/RJCedkKk3MzvshVZ8toHTT3tqseChv4k/B mcoDr6atelaVflkjBOBDOZVClpiPCr+s1k5mt/3N+FyK8sY+/RxyT940c KxYw2DuRra4x+bvYfpT9etAFDhcmBVnulkE9/m04/x+msuw5FT2xYRzGc lA9DaTqo8Hz9DgboOuKdjFDzlOyKRuLCc7yR5aYaM+bGU3tWl/BZ7NzT5 QhOCcvmcMV0AIE+tg5pInGsHoZcLDiqn/lPj5UnpXD6yx0wOOPKa7AITK 3/9Qgm4I5+cbEkEQ69bQldz4n41mlz9FpdER7FM5IRUroDWhIEXHTjVKk Q==; X-CSE-ConnectionGUID: eiwDFOwyRmeIY2h5TdCkVw== X-CSE-MsgGUID: 2v88DGt7R4OcdtORLGfw9w== X-IronPort-AV: E=McAfee;i="6800,10657,11642"; a="71304996" X-IronPort-AV: E=Sophos;i="6.21,150,1763452800"; d="scan'208";a="71304996" X-CSE-ConnectionGUID: lCgeFzLrRj6keqwA/h/nfg== X-CSE-MsgGUID: JX3GQc4ZSlW2bFGAbwXcvw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.21,150,1763452800"; d="scan'208";a="197408786" From: Zhenzhong Duan To: qemu-devel@nongnu.org Cc: alex@shazbot.org, clg@redhat.com, eric.auger@redhat.com, mst@redhat.com, jasowang@redhat.com, peterx@redhat.com, ddutile@redhat.com, jgg@nvidia.com, nicolinc@nvidia.com, skolothumtho@nvidia.com, joao.m.martins@oracle.com, clement.mathieu--drif@eviden.com, kevin.tian@intel.com, yi.l.liu@intel.com, chao.p.peng@intel.com, Zhenzhong Duan Subject: [PATCH v9 08/19] vfio/iommufd: Force creating nesting parent HWPT Date: Mon, 15 Dec 2025 01:50:32 -0500 Message-ID: <20251215065046.86991-9-zhenzhong.duan@intel.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20251215065046.86991-1-zhenzhong.duan@intel.com> References: <20251215065046.86991-1-zhenzhong.duan@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=198.175.65.15; envelope-from=zhenzhong.duan@intel.com; helo=mgamail.intel.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1765781525212158500 Content-Type: text/plain; charset="utf-8" Call pci_device_get_viommu_flags() to get if vIOMMU supports VIOMMU_FLAG_WANT_NESTING_PARENT. If yes, create a nesting parent HWPT and add it to the container's hwpt_lis= t, letting this parent HWPT cover the entire second stage mappings (GPA=3D>HPA= ). This allows a VFIO passthrough device to directly attach to this default HW= PT and then to use the system address space and its listener. Introduce a vfio_device_get_viommu_flags_want_nesting() helper to facilitate this implementation. It is safe to do so because a vIOMMU will be able to fail in set_iommu_devi= ce() call, if something else related to the VFIO device or vIOMMU isn't compatib= le. Suggested-by: Nicolin Chen Suggested-by: Yi Liu Signed-off-by: Zhenzhong Duan Reviewed-by: Nicolin Chen Reviewed-by: Eric Auger Reviewed-by: Yi Liu --- include/hw/vfio/vfio-device.h | 2 ++ hw/vfio/device.c | 12 ++++++++++++ hw/vfio/iommufd.c | 9 +++++++++ 3 files changed, 23 insertions(+) diff --git a/include/hw/vfio/vfio-device.h b/include/hw/vfio/vfio-device.h index 0fe6c60ba2..0bc877ff62 100644 --- a/include/hw/vfio/vfio-device.h +++ b/include/hw/vfio/vfio-device.h @@ -257,6 +257,8 @@ void vfio_device_prepare(VFIODevice *vbasedev, VFIOCont= ainer *bcontainer, =20 void vfio_device_unprepare(VFIODevice *vbasedev); =20 +bool vfio_device_get_viommu_flags_want_nesting(VFIODevice *vbasedev); + int vfio_device_get_region_info(VFIODevice *vbasedev, int index, struct vfio_region_info **info); int vfio_device_get_region_info_type(VFIODevice *vbasedev, uint32_t type, diff --git a/hw/vfio/device.c b/hw/vfio/device.c index 76869828fc..eff5aab207 100644 --- a/hw/vfio/device.c +++ b/hw/vfio/device.c @@ -23,6 +23,7 @@ =20 #include "hw/vfio/vfio-device.h" #include "hw/vfio/pci.h" +#include "hw/iommu.h" #include "hw/hw.h" #include "trace.h" #include "qapi/error.h" @@ -515,6 +516,17 @@ void vfio_device_unprepare(VFIODevice *vbasedev) vbasedev->bcontainer =3D NULL; } =20 +bool vfio_device_get_viommu_flags_want_nesting(VFIODevice *vbasedev) +{ + VFIOPCIDevice *vdev =3D vfio_pci_from_vfio_device(vbasedev); + + if (vdev) { + return !!(pci_device_get_viommu_flags(PCI_DEVICE(vdev)) & + VIOMMU_FLAG_WANT_NESTING_PARENT); + } + return false; +} + /* * Traditional ioctl() based io */ diff --git a/hw/vfio/iommufd.c b/hw/vfio/iommufd.c index bb5775aa71..ca8a6b7029 100644 --- a/hw/vfio/iommufd.c +++ b/hw/vfio/iommufd.c @@ -361,6 +361,15 @@ static bool iommufd_cdev_autodomains_get(VFIODevice *v= basedev, flags =3D IOMMU_HWPT_ALLOC_DIRTY_TRACKING; } =20 + /* + * If vIOMMU requests VFIO's cooperation to create nesting parent HWPT, + * force to create it so that it could be reused by vIOMMU to create + * nested HWPT. + */ + if (vfio_device_get_viommu_flags_want_nesting(vbasedev)) { + flags |=3D IOMMU_HWPT_ALLOC_NEST_PARENT; + } + if (cpr_is_incoming()) { hwpt_id =3D vbasedev->cpr.hwpt_id; goto skip_alloc; --=20 2.47.1 From nobody Mon Dec 15 12:39:58 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1765781661; cv=none; d=zohomail.com; s=zohoarc; b=aRqgy0Mpris9yOHPUWpT53UFO4Qd1qhD9of8mPWamBdd/Xn+xKuYN8ckH3l0jdMCO8PFr1Vksbbr/YZEj57hXJl9GeEofDvB39CFglbeI0Liug/ZolleLKEZ0bbWESjYkvU5ujYTNwkPET+0F5koa4YTp2hLDglRRdsJGgPFt/I= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1765781661; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=A4seaunfNwukw9PJWfE8rU1xUDQKMWyqSRBs6N+MGrg=; b=M9dvpBGBCx9pLLxtZeLxcBy5JhBOm9C9Tf2x1TbyY61z3NtvRzqnMDor+r2wrECTeOSF/H0viQcJoZKcrRqdqEVaWsmrF4ej5fF1Dw9V3OOoWRLzlZka6++RKGv22QFOkiKhMFNZWh4as8tx+fNPRqiQSOVFogSQ3QQPLn5m6Ko= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1765781661847480.4951201225607; Sun, 14 Dec 2025 22:54:21 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vV2R1-0008AM-CM; Mon, 15 Dec 2025 01:51:55 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vV2Qz-00089o-PE for qemu-devel@nongnu.org; Mon, 15 Dec 2025 01:51:53 -0500 Received: from mgamail.intel.com ([198.175.65.15]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vV2Qx-0000u9-Q8 for qemu-devel@nongnu.org; Mon, 15 Dec 2025 01:51:53 -0500 Received: from orviesa009.jf.intel.com ([10.64.159.149]) by orvoesa107.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Dec 2025 22:51:52 -0800 Received: from unknown (HELO gnr-sp-2s-612.sh.intel.com) ([10.112.230.229]) by orviesa009-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Dec 2025 22:51:47 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1765781512; x=1797317512; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=bwCbonyQfsynN5a1Kx/nYXanY9rqP/DJVmUsSZAFOH4=; b=Kq64NDwU5JVWS7V7BMilg7v9cRXrTyzs3QuDfKzLfPjTNNL+MzVB6G0J 5DBtiAPvW2vEg/OZaKOvTzj2DG1wFKi5mwHP/RsQf14IwpZcWImwAvhm8 9poI9lLpKWQ6TLObPT95fOgljMcQpsQztv0oVPx0Sj7xMT5bDTDd++MCB 7sApK5ZOUB7To58vf/EgUyXrk2DSfrPJNE0yg+z6b8sU5Dp7KCzR8Gqys d3yFT220eaZQXa+3tGAK8wTuuiNCYlueU2ka26w9Hncht42o3843uxCjg LlfoNcyLeK0JRkiSgd/3BEhnuLjEXzrjTmxOQOOcxUCjxYm50XNK6z23h A==; X-CSE-ConnectionGUID: vcTZEAUURg+CmsqunSqfmg== X-CSE-MsgGUID: AC9sIuD9Q9CKAhWFMg+34Q== X-IronPort-AV: E=McAfee;i="6800,10657,11642"; a="71305002" X-IronPort-AV: E=Sophos;i="6.21,150,1763452800"; d="scan'208";a="71305002" X-CSE-ConnectionGUID: P4dNMzBfTJ6OIbjEvwFZ7w== X-CSE-MsgGUID: K2aC4VMGTiy09WyLvXU0bw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.21,150,1763452800"; d="scan'208";a="197408791" From: Zhenzhong Duan To: qemu-devel@nongnu.org Cc: alex@shazbot.org, clg@redhat.com, eric.auger@redhat.com, mst@redhat.com, jasowang@redhat.com, peterx@redhat.com, ddutile@redhat.com, jgg@nvidia.com, nicolinc@nvidia.com, skolothumtho@nvidia.com, joao.m.martins@oracle.com, clement.mathieu--drif@eviden.com, kevin.tian@intel.com, yi.l.liu@intel.com, chao.p.peng@intel.com, Zhenzhong Duan Subject: [PATCH v9 09/19] intel_iommu_accel: Check for compatibility with IOMMUFD backed device when x-flts=on Date: Mon, 15 Dec 2025 01:50:33 -0500 Message-ID: <20251215065046.86991-10-zhenzhong.duan@intel.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20251215065046.86991-1-zhenzhong.duan@intel.com> References: <20251215065046.86991-1-zhenzhong.duan@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=198.175.65.15; envelope-from=zhenzhong.duan@intel.com; helo=mgamail.intel.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1765781663392158501 When vIOMMU is configured x-flts=3Don in scalable mode, first stage page ta= ble is passed to host to construct nested page table for passthrough devices. We need to check compatibility of some critical IOMMU capabilities between vIOMMU and host IOMMU to ensure guest first stage page table could be used = by host. For instance, vIOMMU supports first stage 1GB large page mapping, but host = does not, then this IOMMUFD backed device should fail. Even of the checks pass, for now we willingly reject the association because all the bits are not there yet, it will be relaxed in the end of this serie= s. Note vIOMMU has exposed IOMMU_HWPT_ALLOC_NEST_PARENT flag to force VFIO cor= e to create nesting parent HWPT, if host doesn't support nested translation, the creation will fail. So no need to check nested capability here. Signed-off-by: Zhenzhong Duan Reviewed-by: Eric Auger --- MAINTAINERS | 1 + hw/i386/intel_iommu_accel.h | 28 +++++++++++++++++++++++++ hw/i386/intel_iommu.c | 5 ++--- hw/i386/intel_iommu_accel.c | 42 +++++++++++++++++++++++++++++++++++++ hw/i386/Kconfig | 5 +++++ hw/i386/meson.build | 1 + 6 files changed, 79 insertions(+), 3 deletions(-) create mode 100644 hw/i386/intel_iommu_accel.h create mode 100644 hw/i386/intel_iommu_accel.c diff --git a/MAINTAINERS b/MAINTAINERS index 5529353759..39ff0432fd 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -3931,6 +3931,7 @@ R: Cl=C3=A9ment Mathieu--Drif S: Supported F: hw/i386/intel_iommu.c F: hw/i386/intel_iommu_internal.h +F: hw/i386/intel_iommu_accel.* F: include/hw/i386/intel_iommu.h F: tests/functional/x86_64/test_intel_iommu.py F: tests/qtest/intel-iommu-test.c diff --git a/hw/i386/intel_iommu_accel.h b/hw/i386/intel_iommu_accel.h new file mode 100644 index 0000000000..472ae109e2 --- /dev/null +++ b/hw/i386/intel_iommu_accel.h @@ -0,0 +1,28 @@ +/* + * Intel IOMMU acceleration with nested translation + * + * Copyright (C) 2025 Intel Corporation. + * + * Authors: Zhenzhong Duan + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#ifndef HW_I386_INTEL_IOMMU_ACCEL_H +#define HW_I386_INTEL_IOMMU_ACCEL_H +#include CONFIG_DEVICES + +#ifdef CONFIG_VTD_ACCEL +bool vtd_check_hiod_accel(IntelIOMMUState *s, HostIOMMUDevice *hiod, + Error **errp); +#else +static inline bool vtd_check_hiod_accel(IntelIOMMUState *s, + HostIOMMUDevice *hiod, + Error **errp) +{ + error_setg(errp, "host IOMMU cannot be checked!"); + error_append_hint(errp, "CONFIG_VTD_ACCEL is not enabled"); + return false; +} +#endif +#endif diff --git a/hw/i386/intel_iommu.c b/hw/i386/intel_iommu.c index 4585af1fe5..6b86cd5ada 100644 --- a/hw/i386/intel_iommu.c +++ b/hw/i386/intel_iommu.c @@ -26,6 +26,7 @@ #include "hw/sysbus.h" #include "hw/iommu.h" #include "intel_iommu_internal.h" +#include "intel_iommu_accel.h" #include "hw/pci/pci.h" #include "hw/pci/pci_bus.h" #include "hw/qdev-properties.h" @@ -4595,9 +4596,7 @@ static bool vtd_check_hiod(IntelIOMMUState *s, HostIO= MMUDevice *hiod, return true; } =20 - error_setg(errp, - "host device is uncompatible with first stage translation"); - return false; + return vtd_check_hiod_accel(s, hiod, errp); } =20 static bool vtd_dev_set_iommu_device(PCIBus *bus, void *opaque, int devfn, diff --git a/hw/i386/intel_iommu_accel.c b/hw/i386/intel_iommu_accel.c new file mode 100644 index 0000000000..6846c6ec4d --- /dev/null +++ b/hw/i386/intel_iommu_accel.c @@ -0,0 +1,42 @@ +/* + * Intel IOMMU acceleration with nested translation + * + * Copyright (C) 2025 Intel Corporation. + * + * Authors: Zhenzhong Duan + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#include "qemu/osdep.h" +#include "system/iommufd.h" +#include "intel_iommu_internal.h" +#include "intel_iommu_accel.h" + +bool vtd_check_hiod_accel(IntelIOMMUState *s, HostIOMMUDevice *hiod, + Error **errp) +{ + struct HostIOMMUDeviceCaps *caps =3D &hiod->caps; + struct iommu_hw_info_vtd *vtd =3D &caps->vendor_caps.vtd; + + if (!object_dynamic_cast(OBJECT(hiod), TYPE_HOST_IOMMU_DEVICE_IOMMUFD)= ) { + error_setg(errp, "Need IOMMUFD backend when x-flts=3Don"); + return false; + } + + if (caps->type !=3D IOMMU_HW_INFO_TYPE_INTEL_VTD) { + error_setg(errp, "Incompatible host platform IOMMU type %d", + caps->type); + return false; + } + + if (s->fs1gp && !(vtd->cap_reg & VTD_CAP_FS1GP)) { + error_setg(errp, + "First stage 1GB large page is unsupported by host IOMM= U"); + return false; + } + + error_setg(errp, + "host IOMMU is incompatible with guest first stage translat= ion"); + return false; +} diff --git a/hw/i386/Kconfig b/hw/i386/Kconfig index 6a0ab54bea..12473acaa7 100644 --- a/hw/i386/Kconfig +++ b/hw/i386/Kconfig @@ -150,8 +150,13 @@ config X86_IOMMU =20 config VTD bool + imply VTD_ACCEL select X86_IOMMU =20 +config VTD_ACCEL + bool + depends on VTD && IOMMUFD + config AMD_IOMMU bool select X86_IOMMU diff --git a/hw/i386/meson.build b/hw/i386/meson.build index 436b3ce52d..63ae57baa5 100644 --- a/hw/i386/meson.build +++ b/hw/i386/meson.build @@ -21,6 +21,7 @@ i386_ss.add(when: 'CONFIG_Q35', if_true: files('pc_q35.c'= )) i386_ss.add(when: 'CONFIG_VMMOUSE', if_true: files('vmmouse.c')) i386_ss.add(when: 'CONFIG_VMPORT', if_true: files('vmport.c')) i386_ss.add(when: 'CONFIG_VTD', if_true: files('intel_iommu.c')) +i386_ss.add(when: 'CONFIG_VTD_ACCEL', if_true: files('intel_iommu_accel.c'= )) i386_ss.add(when: 'CONFIG_SGX', if_true: files('sgx-epc.c','sgx.c'), if_false: files('sgx-stub.c')) =20 --=20 2.47.1 From nobody Mon Dec 15 12:39:58 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1765781653; cv=none; d=zohomail.com; s=zohoarc; b=NU4EkQbzSleW/bZoddI9lbBbA6JVtcUj59+5za+o4a577MLjMZU8AP1nAfKHkNPzwHg/6VDug9vkw8f9EAorHmmAWfdkJRpqqrttMk7UkLagVNZ3mVGMd1p5zuXYRgkiHlQGYAypfe69zRdZexX+i3tDkWzTvB7Qdd03zr4c4XU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1765781653; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=2EsUU5KUquJHf3+WrFNYSaX+N8A+Ha8bS6pCd0eiTkY=; b=lCr8B/Hq9nxL5XWlTO+H3R2Pv9HbOGrXQtzcKmn9BrBJiRm8uIAV4DTpMHt2hBprAbE57+A1kb02rTohCuGquqZIT1jP1fYPxkUA8KJQqdwzwXV9hC8SWi3bevSS3GozVV3Ikxr55Psc0CNHRJumtb8RfkNxdk5JLFH/+2bAl0o= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 176578165391352.114881387174705; Sun, 14 Dec 2025 22:54:13 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vV2R5-0008BO-Fo; Mon, 15 Dec 2025 01:51:59 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vV2R3-0008Ax-W0 for qemu-devel@nongnu.org; Mon, 15 Dec 2025 01:51:58 -0500 Received: from mgamail.intel.com ([198.175.65.15]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vV2R2-0000u9-6N for qemu-devel@nongnu.org; Mon, 15 Dec 2025 01:51:57 -0500 Received: from orviesa009.jf.intel.com ([10.64.159.149]) by orvoesa107.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Dec 2025 22:51:56 -0800 Received: from unknown (HELO gnr-sp-2s-612.sh.intel.com) ([10.112.230.229]) by orviesa009-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Dec 2025 22:51:52 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1765781517; x=1797317517; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=cwZPdK9NC99Ad8Z0dhse6aPJ9AlerzfXjqzYgBa+xp4=; b=i6CB8mCfS71mVtAvir1Vhlk/An+1AMCEDfmKIudifqeDs21apREjOdZz LzMvvEERogRT98FWulcLQzValdj/R6A/5dvHISjbl5cqcC+YJufhDdHey nAooWOvzeX4ArJbKQ5JQseclcJt+fdEo44LDAtgcxnlC0bifhavatDGR7 8Fjs5E83cv7V7Al4mAftpAH/7LKmtvcSYBUStwMvSUTtaAU4Oql+tsrbD GBsoXwiX7KdJL/1sfPTP4hPaOiXYmqiwkTu7Nr7y8zOEKP5VgCDa1NTlv wJRGtl/Ht/NfKA3LkgbZetXkLSArqyAv6E/CeVMnHR1TvVtpY35T0T174 w==; X-CSE-ConnectionGUID: 1UHacdp1QZWKHwPmGr6tvw== X-CSE-MsgGUID: MASAeLbQR9WICwLQ1VZQkg== X-IronPort-AV: E=McAfee;i="6800,10657,11642"; a="71305009" X-IronPort-AV: E=Sophos;i="6.21,150,1763452800"; d="scan'208";a="71305009" X-CSE-ConnectionGUID: VflW8yYYSSaQSRvDowmjww== X-CSE-MsgGUID: 2asy4frVRdaiZO0nNUBhbA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.21,150,1763452800"; d="scan'208";a="197408797" From: Zhenzhong Duan To: qemu-devel@nongnu.org Cc: alex@shazbot.org, clg@redhat.com, eric.auger@redhat.com, mst@redhat.com, jasowang@redhat.com, peterx@redhat.com, ddutile@redhat.com, jgg@nvidia.com, nicolinc@nvidia.com, skolothumtho@nvidia.com, joao.m.martins@oracle.com, clement.mathieu--drif@eviden.com, kevin.tian@intel.com, yi.l.liu@intel.com, chao.p.peng@intel.com, Zhenzhong Duan Subject: [PATCH v9 10/19] intel_iommu_accel: Fail passthrough device under PCI bridge if x-flts=on Date: Mon, 15 Dec 2025 01:50:34 -0500 Message-ID: <20251215065046.86991-11-zhenzhong.duan@intel.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20251215065046.86991-1-zhenzhong.duan@intel.com> References: <20251215065046.86991-1-zhenzhong.duan@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=198.175.65.15; envelope-from=zhenzhong.duan@intel.com; helo=mgamail.intel.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1765781655340158500 Content-Type: text/plain; charset="utf-8" Currently we don't support nested translation for passthrough device with emulated device under same PCI bridge, because they require different addre= ss space when x-flts=3Don. In theory, we do support if devices under same PCI bridge are all passthrou= gh devices. But emulated device can be hotplugged under same bridge. To simpli= fy, just forbid passthrough device under PCI bridge no matter if there is, or w= ill be emulated devices under same bridge. This is acceptable because PCIE brid= ge is more popular than PCI bridge now. Suggested-by: Yi Liu Signed-off-by: Zhenzhong Duan Reviewed-by: Eric Auger --- hw/i386/intel_iommu_accel.h | 4 ++-- hw/i386/intel_iommu.c | 7 ++++--- hw/i386/intel_iommu_accel.c | 12 +++++++++++- 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/hw/i386/intel_iommu_accel.h b/hw/i386/intel_iommu_accel.h index 472ae109e2..76e0d26942 100644 --- a/hw/i386/intel_iommu_accel.h +++ b/hw/i386/intel_iommu_accel.h @@ -13,11 +13,11 @@ #include CONFIG_DEVICES =20 #ifdef CONFIG_VTD_ACCEL -bool vtd_check_hiod_accel(IntelIOMMUState *s, HostIOMMUDevice *hiod, +bool vtd_check_hiod_accel(IntelIOMMUState *s, VTDHostIOMMUDevice *vtd_hiod, Error **errp); #else static inline bool vtd_check_hiod_accel(IntelIOMMUState *s, - HostIOMMUDevice *hiod, + VTDHostIOMMUDevice *vtd_hiod, Error **errp) { error_setg(errp, "host IOMMU cannot be checked!"); diff --git a/hw/i386/intel_iommu.c b/hw/i386/intel_iommu.c index 6b86cd5ada..5bf1c0e5a4 100644 --- a/hw/i386/intel_iommu.c +++ b/hw/i386/intel_iommu.c @@ -4570,9 +4570,10 @@ VTDAddressSpace *vtd_find_add_as(IntelIOMMUState *s,= PCIBus *bus, return vtd_dev_as; } =20 -static bool vtd_check_hiod(IntelIOMMUState *s, HostIOMMUDevice *hiod, +static bool vtd_check_hiod(IntelIOMMUState *s, VTDHostIOMMUDevice *vtd_hio= d, Error **errp) { + HostIOMMUDevice *hiod =3D vtd_hiod->hiod; HostIOMMUDeviceClass *hiodc =3D HOST_IOMMU_DEVICE_GET_CLASS(hiod); int ret; =20 @@ -4596,7 +4597,7 @@ static bool vtd_check_hiod(IntelIOMMUState *s, HostIO= MMUDevice *hiod, return true; } =20 - return vtd_check_hiod_accel(s, hiod, errp); + return vtd_check_hiod_accel(s, vtd_hiod, errp); } =20 static bool vtd_dev_set_iommu_device(PCIBus *bus, void *opaque, int devfn, @@ -4632,7 +4633,7 @@ static bool vtd_dev_set_iommu_device(PCIBus *bus, voi= d *opaque, int devfn, vtd_hiod->iommu_state =3D s; vtd_hiod->hiod =3D hiod; =20 - if (!vtd_check_hiod(s, hiod, errp)) { + if (!vtd_check_hiod(s, vtd_hiod, errp)) { g_free(vtd_hiod); vtd_iommu_unlock(s); return false; diff --git a/hw/i386/intel_iommu_accel.c b/hw/i386/intel_iommu_accel.c index 6846c6ec4d..ead6c42879 100644 --- a/hw/i386/intel_iommu_accel.c +++ b/hw/i386/intel_iommu_accel.c @@ -12,12 +12,16 @@ #include "system/iommufd.h" #include "intel_iommu_internal.h" #include "intel_iommu_accel.h" +#include "hw/pci/pci_bus.h" =20 -bool vtd_check_hiod_accel(IntelIOMMUState *s, HostIOMMUDevice *hiod, +bool vtd_check_hiod_accel(IntelIOMMUState *s, VTDHostIOMMUDevice *vtd_hiod, Error **errp) { + HostIOMMUDevice *hiod =3D vtd_hiod->hiod; struct HostIOMMUDeviceCaps *caps =3D &hiod->caps; struct iommu_hw_info_vtd *vtd =3D &caps->vendor_caps.vtd; + PCIBus *bus =3D vtd_hiod->bus; + PCIDevice *pdev =3D bus->devices[vtd_hiod->devfn]; =20 if (!object_dynamic_cast(OBJECT(hiod), TYPE_HOST_IOMMU_DEVICE_IOMMUFD)= ) { error_setg(errp, "Need IOMMUFD backend when x-flts=3Don"); @@ -36,6 +40,12 @@ bool vtd_check_hiod_accel(IntelIOMMUState *s, HostIOMMUD= evice *hiod, return false; } =20 + if (pci_device_get_iommu_bus_devfn(pdev, &bus, NULL, NULL)) { + error_setg(errp, "Host device downstream to a PCI bridge is " + "unsupported when x-flts=3Don"); + return false; + } + error_setg(errp, "host IOMMU is incompatible with guest first stage translat= ion"); return false; --=20 2.47.1 From nobody Mon Dec 15 12:39:58 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1765781553; cv=none; d=zohomail.com; s=zohoarc; b=nG4KlcdPWCEaTLSGuirNmLxFyZwHpS0S5sntg/bhagZGyCbtl7ZR9etEMqzOrzdajDXj2aXV2PpX31ozJagCTJtAuqHuEBcdLU09u88fW7e3FvWm1i1swLNh/AFSpVm1hSS+TlZSOjE1JwBASeO6U6kboR4WcULPWjoW/uVF4Is= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1765781553; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=A168xPjFdwSYMkKiKN+cF3LPgVYLIPz17U/f3K51ie8=; b=RJC3KKC7GlTMQs+2bRNhz/pQ0ReVqe0HAA+RQ7vW2yGeyj8GU0TMPZmwrJT+ypYZ0fK16z48npH/e/C1xahal0vXfwwivJBlSowAFYbmvc86gvEuVbVaVk6V6SiftVGb8DKuYdmxKnm0mbznEa1S1w8Pys2E7V4aZp6ZfAKAh9Q= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1765781553343680.2381790270017; Sun, 14 Dec 2025 22:52:33 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vV2RC-0008F8-HO; Mon, 15 Dec 2025 01:52:06 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vV2R8-0008Dp-NV for qemu-devel@nongnu.org; Mon, 15 Dec 2025 01:52:03 -0500 Received: from mgamail.intel.com ([198.175.65.15]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vV2R6-0000u9-L1 for qemu-devel@nongnu.org; Mon, 15 Dec 2025 01:52:02 -0500 Received: from orviesa009.jf.intel.com ([10.64.159.149]) by orvoesa107.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Dec 2025 22:52:01 -0800 Received: from unknown (HELO gnr-sp-2s-612.sh.intel.com) ([10.112.230.229]) by orviesa009-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Dec 2025 22:51:56 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1765781521; x=1797317521; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=bnVHkEZtWfXFals983bCj0nWaVIaMUkcxGxAggluiiI=; b=crZOtnwd3lbC4JZOk1tGP5RZUsoZNedpHu2zgmT7KVl3MWFNMWkwynNI +X1r4bs6kyQUoA1Fp/v28zT4Yh4cZ8wQBh6Vxl1c4/0QG4sIoqZfEiVMV yTZo7dzF/iNaPUa/+6DNw61tOlXPJ5CZKmDLutqVZSLlSCVwcOEHbMEVE 6ayhOnIRmE1PTW6psi7qRJv4HZbUjhlwbuZIyyhu03Y153EygxEl8fbyB 33UmdhtDm7vfMzUd8N5U8yhgCzpfgcr/NiiLOvqNFfuZNl9BCvX7pmK1g Nt/ZcuPtQERtzq3SVurntPPC5IxdkG6mWcbJLbb0/qCcCQINzTHlHv2Vx g==; X-CSE-ConnectionGUID: HYsL2xh0T6+fgt8VuHPhhw== X-CSE-MsgGUID: rzPNZ4wiR5e2jR0MUWJGmw== X-IronPort-AV: E=McAfee;i="6800,10657,11642"; a="71305015" X-IronPort-AV: E=Sophos;i="6.21,150,1763452800"; d="scan'208";a="71305015" X-CSE-ConnectionGUID: WCLMLaUZTe6YsEqr3caveg== X-CSE-MsgGUID: FIi6vUnAR9KWgxTVhRsfoA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.21,150,1763452800"; d="scan'208";a="197408803" From: Zhenzhong Duan To: qemu-devel@nongnu.org Cc: alex@shazbot.org, clg@redhat.com, eric.auger@redhat.com, mst@redhat.com, jasowang@redhat.com, peterx@redhat.com, ddutile@redhat.com, jgg@nvidia.com, nicolinc@nvidia.com, skolothumtho@nvidia.com, joao.m.martins@oracle.com, clement.mathieu--drif@eviden.com, kevin.tian@intel.com, yi.l.liu@intel.com, chao.p.peng@intel.com, Zhenzhong Duan Subject: [PATCH v9 11/19] intel_iommu_accel: Stick to system MR for IOMMUFD backed host device when x-flts=on Date: Mon, 15 Dec 2025 01:50:35 -0500 Message-ID: <20251215065046.86991-12-zhenzhong.duan@intel.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20251215065046.86991-1-zhenzhong.duan@intel.com> References: <20251215065046.86991-1-zhenzhong.duan@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=198.175.65.15; envelope-from=zhenzhong.duan@intel.com; helo=mgamail.intel.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1765781555283158500 Content-Type: text/plain; charset="utf-8" When guest enables scalable mode and setup first stage page table, we don't want to use IOMMU MR but rather continue using the system MR for IOMMUFD backed host device. Then default HWPT in VFIO contains GPA->HPA mappings which could be reused as nesting parent HWPT to construct nested HWPT in vIOMMU. Move vtd_as_key into intel_iommu_internal.h as it's also used by accel code. Suggested-by: Yi Liu Signed-off-by: Zhenzhong Duan Reviewed-by: Eric Auger --- hw/i386/intel_iommu_accel.h | 6 ++++++ hw/i386/intel_iommu_internal.h | 11 +++++++++++ hw/i386/intel_iommu.c | 28 +++++++++++++++------------- hw/i386/intel_iommu_accel.c | 18 ++++++++++++++++++ 4 files changed, 50 insertions(+), 13 deletions(-) diff --git a/hw/i386/intel_iommu_accel.h b/hw/i386/intel_iommu_accel.h index 76e0d26942..d049cab3e1 100644 --- a/hw/i386/intel_iommu_accel.h +++ b/hw/i386/intel_iommu_accel.h @@ -15,6 +15,7 @@ #ifdef CONFIG_VTD_ACCEL bool vtd_check_hiod_accel(IntelIOMMUState *s, VTDHostIOMMUDevice *vtd_hiod, Error **errp); +VTDHostIOMMUDevice *vtd_find_hiod_iommufd(VTDAddressSpace *as); #else static inline bool vtd_check_hiod_accel(IntelIOMMUState *s, VTDHostIOMMUDevice *vtd_hiod, @@ -24,5 +25,10 @@ static inline bool vtd_check_hiod_accel(IntelIOMMUState = *s, error_append_hint(errp, "CONFIG_VTD_ACCEL is not enabled"); return false; } + +static inline VTDHostIOMMUDevice *vtd_find_hiod_iommufd(VTDAddressSpace *a= s) +{ + return NULL; +} #endif #endif diff --git a/hw/i386/intel_iommu_internal.h b/hw/i386/intel_iommu_internal.h index 02522f64e0..d8dad18304 100644 --- a/hw/i386/intel_iommu_internal.h +++ b/hw/i386/intel_iommu_internal.h @@ -685,4 +685,15 @@ typedef struct VTDHostIOMMUDevice { uint8_t devfn; HostIOMMUDevice *hiod; } VTDHostIOMMUDevice; + +/* + * PCI bus number (or SID) is not reliable since the device is usaully + * initialized before guest can configure the PCI bridge + * (SECONDARY_BUS_NUMBER). + */ +struct vtd_as_key { + PCIBus *bus; + uint8_t devfn; + uint32_t pasid; +}; #endif diff --git a/hw/i386/intel_iommu.c b/hw/i386/intel_iommu.c index 5bf1c0e5a4..e4610a61b2 100644 --- a/hw/i386/intel_iommu.c +++ b/hw/i386/intel_iommu.c @@ -55,17 +55,6 @@ #define VTD_PE_GET_SS_LEVEL(pe) \ (2 + (((pe)->val[0] >> 2) & VTD_SM_PASID_ENTRY_AW)) =20 -/* - * PCI bus number (or SID) is not reliable since the device is usaully - * initialized before guest can configure the PCI bridge - * (SECONDARY_BUS_NUMBER). - */ -struct vtd_as_key { - PCIBus *bus; - uint8_t devfn; - uint32_t pasid; -}; - /* bus/devfn is PCI device's real BDF not the aliased one */ struct vtd_hiod_key { PCIBus *bus; @@ -1730,12 +1719,25 @@ static bool vtd_as_pt_enabled(VTDAddressSpace *as) /* Return whether the device is using IOMMU translation. */ static bool vtd_switch_address_space(VTDAddressSpace *as) { + IntelIOMMUState *s; bool use_iommu, pt; =20 assert(as); =20 - use_iommu =3D as->iommu_state->dmar_enabled && !vtd_as_pt_enabled(as); - pt =3D as->iommu_state->dmar_enabled && vtd_as_pt_enabled(as); + s =3D as->iommu_state; + use_iommu =3D s->dmar_enabled && !vtd_as_pt_enabled(as); + pt =3D s->dmar_enabled && vtd_as_pt_enabled(as); + + /* + * When guest enables scalable mode and sets up first stage page table, + * we stick to system MR for IOMMUFD backed host device. Then its + * default hwpt contains GPA->HPA mappings which is used directly if + * PGTT=3DPT and used as nesting parent if PGTT=3DFST. Otherwise fall = back + * to original processing. + */ + if (s->root_scalable && s->fsts && vtd_find_hiod_iommufd(as)) { + use_iommu =3D false; + } =20 trace_vtd_switch_address_space(pci_bus_num(as->bus), VTD_PCI_SLOT(as->devfn), diff --git a/hw/i386/intel_iommu_accel.c b/hw/i386/intel_iommu_accel.c index ead6c42879..ebfc503d64 100644 --- a/hw/i386/intel_iommu_accel.c +++ b/hw/i386/intel_iommu_accel.c @@ -50,3 +50,21 @@ bool vtd_check_hiod_accel(IntelIOMMUState *s, VTDHostIOM= MUDevice *vtd_hiod, "host IOMMU is incompatible with guest first stage translat= ion"); return false; } + +VTDHostIOMMUDevice *vtd_find_hiod_iommufd(VTDAddressSpace *as) +{ + IntelIOMMUState *s =3D as->iommu_state; + struct vtd_as_key key =3D { + .bus =3D as->bus, + .devfn =3D as->devfn, + }; + VTDHostIOMMUDevice *vtd_hiod =3D g_hash_table_lookup(s->vtd_host_iommu= _dev, + &key); + + if (vtd_hiod && vtd_hiod->hiod && + object_dynamic_cast(OBJECT(vtd_hiod->hiod), + TYPE_HOST_IOMMU_DEVICE_IOMMUFD)) { + return vtd_hiod; + } + return NULL; +} --=20 2.47.1 From nobody Mon Dec 15 12:39:58 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1765781630; cv=none; d=zohomail.com; s=zohoarc; b=c6fGH2RQWlynxmYA85bvEscwYtU/W1Z2gSRBDse8jGQa9QHKyp556DcDvoiGsBhoZrg3ltZLLvYQZMZjwQcEk0pOfMsF02gt+tSzGk8JtA/rgfglNiQ2j+SvhjEC685WzAx82Nb4Nr+pBvFxAN2AuWnBIKAOIX6xdB0BFZE6E6o= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1765781630; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=WzW9klE742/OLf/dLpPOGupKl5z6Ut3BBxr+HqkOlSw=; b=M9HBm6eIvqMP+OO/v/ZaPXJA6Kuzk94BAu6W0d03F8ZBI8I9zAlUmZt6GH1F3K3j8JzjBzSfzRciySgCe+NYAsQEQJXss4rkzbZBHh7f2NFUlaMv/XudmB8w9V5DYAcJIy4XaVp3IM8+KI2vfRHlo9cFUr09QVLuFstpBLysDXk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1765781630644518.0451726269532; Sun, 14 Dec 2025 22:53:50 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vV2RH-0008FV-2U; Mon, 15 Dec 2025 01:52:11 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vV2RE-0008FD-HW for qemu-devel@nongnu.org; Mon, 15 Dec 2025 01:52:08 -0500 Received: from mgamail.intel.com ([198.175.65.15]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vV2RB-0000u9-Cc for qemu-devel@nongnu.org; Mon, 15 Dec 2025 01:52:08 -0500 Received: from orviesa009.jf.intel.com ([10.64.159.149]) by orvoesa107.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Dec 2025 22:52:05 -0800 Received: from unknown (HELO gnr-sp-2s-612.sh.intel.com) ([10.112.230.229]) by orviesa009-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Dec 2025 22:52:00 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1765781526; x=1797317526; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=55PuOwK/GkGureFvqF33/UbmwyBfzJa+bmoAwgDbTC4=; b=jnbr5e+iqu4DgQ6a1+DBBfANg7QMd1lpTg4pyxLJjZ6hQYPSP70zCCme HcgqX2lG4uh4DX39DJAJFhm3BmSxcC9sUy4rGZOCVQADF61TbuRe3w5qA KoyQwPdDb3WeE62Fs0j06xbgLSAg4oIb+k+jJArvWzG3RpS/uM7LV8rxL r0M36H/xJfq9/93poEHDiHEUYpk4LWm+kkbt6tmnPo2BGpwONCwY5kZ/o OBwcV1feyMozxoIPJEzi2goeZZmEZ3+ivAVlQQc1hffTOsDm18rMa3+jb BE6u/OKA7UZ+43r5LRZCaP4/VHG2GP34zRFQISCC6vkgoM0Klz2XP8VhA A==; X-CSE-ConnectionGUID: aXmG4niZSd67ZWuha8OVZg== X-CSE-MsgGUID: yGKTX2RrRBmqP0dquw+gsQ== X-IronPort-AV: E=McAfee;i="6800,10657,11642"; a="71305022" X-IronPort-AV: E=Sophos;i="6.21,150,1763452800"; d="scan'208";a="71305022" X-CSE-ConnectionGUID: hPBwPg2URUSMBkAdLiCklg== X-CSE-MsgGUID: T7HWBgJfR6Wmy8vNHpDywQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.21,150,1763452800"; d="scan'208";a="197408813" From: Zhenzhong Duan To: qemu-devel@nongnu.org Cc: alex@shazbot.org, clg@redhat.com, eric.auger@redhat.com, mst@redhat.com, jasowang@redhat.com, peterx@redhat.com, ddutile@redhat.com, jgg@nvidia.com, nicolinc@nvidia.com, skolothumtho@nvidia.com, joao.m.martins@oracle.com, clement.mathieu--drif@eviden.com, kevin.tian@intel.com, yi.l.liu@intel.com, chao.p.peng@intel.com, Zhenzhong Duan Subject: [PATCH v9 12/19] intel_iommu: Add some macros and inline functions Date: Mon, 15 Dec 2025 01:50:36 -0500 Message-ID: <20251215065046.86991-13-zhenzhong.duan@intel.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20251215065046.86991-1-zhenzhong.duan@intel.com> References: <20251215065046.86991-1-zhenzhong.duan@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=198.175.65.15; envelope-from=zhenzhong.duan@intel.com; helo=mgamail.intel.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1765781631686158500 Content-Type: text/plain; charset="utf-8" Add some macros and inline functions that will be used by following patch. This patch also make a cleanup to change below macros to use extract64() just like what smmu does, because they are either used in following patches or used indirectly by new introduced inline functions. VTD_INV_DESC_PIOTLB_IH VTD_SM_PASID_ENTRY_PGTT VTD_SM_PASID_ENTRY_DID VTD_SM_PASID_ENTRY_FSPM VTD_SM_PASID_ENTRY_FSPTPTR But we doesn't aim to change the huge amount of bit mask style macro definitions in this patch, that should be in a separate patch. Suggested-by: Eric Auger Signed-off-by: Zhenzhong Duan Reviewed-by: Yi Liu --- hw/i386/intel_iommu_internal.h | 50 ++++++++++++++++++++++++++++------ hw/i386/intel_iommu.c | 27 +++++++++--------- 2 files changed, 55 insertions(+), 22 deletions(-) diff --git a/hw/i386/intel_iommu_internal.h b/hw/i386/intel_iommu_internal.h index d8dad18304..e987322e93 100644 --- a/hw/i386/intel_iommu_internal.h +++ b/hw/i386/intel_iommu_internal.h @@ -516,7 +516,7 @@ typedef union VTDPRDesc VTDPRDesc; #define VTD_INV_DESC_PIOTLB_DID(val) (((val) >> 16) & VTD_DOMAIN_ID_M= ASK) #define VTD_INV_DESC_PIOTLB_PASID(val) (((val) >> 32) & 0xfffffULL) #define VTD_INV_DESC_PIOTLB_AM(val) ((val) & 0x3fULL) -#define VTD_INV_DESC_PIOTLB_IH(val) (((val) >> 6) & 0x1) +#define VTD_INV_DESC_PIOTLB_IH(x) extract64((x)->val[1], 6, 1) #define VTD_INV_DESC_PIOTLB_ADDR(val) ((val) & ~0xfffULL) #define VTD_INV_DESC_PIOTLB_RSVD_VAL0 0xfff000000000f1c0ULL #define VTD_INV_DESC_PIOTLB_RSVD_VAL1 0xf80ULL @@ -636,17 +636,20 @@ typedef struct VTDPASIDCacheInfo { =20 /* PASID Granular Translation Type Mask */ #define VTD_PASID_ENTRY_P 1ULL -#define VTD_SM_PASID_ENTRY_PGTT (7ULL << 6) -#define VTD_SM_PASID_ENTRY_FST (1ULL << 6) -#define VTD_SM_PASID_ENTRY_SST (2ULL << 6) -#define VTD_SM_PASID_ENTRY_NESTED (3ULL << 6) -#define VTD_SM_PASID_ENTRY_PT (4ULL << 6) +#define VTD_SM_PASID_ENTRY_PGTT(x) extract64((x)->val[0], 6, 3) +#define VTD_SM_PASID_ENTRY_FST 1 +#define VTD_SM_PASID_ENTRY_SST 2 +#define VTD_SM_PASID_ENTRY_NESTED 3 +#define VTD_SM_PASID_ENTRY_PT 4 =20 #define VTD_SM_PASID_ENTRY_AW 7ULL /* Adjusted guest-address-widt= h */ -#define VTD_SM_PASID_ENTRY_DID(val) ((val) & VTD_DOMAIN_ID_MASK) +#define VTD_SM_PASID_ENTRY_DID(x) extract64((x)->val[1], 0, 16) =20 -#define VTD_SM_PASID_ENTRY_FSPM 3ULL -#define VTD_SM_PASID_ENTRY_FSPTPTR (~0xfffULL) +#define VTD_SM_PASID_ENTRY_SRE(x) extract64((x)->val[2], 0, 1) +#define VTD_SM_PASID_ENTRY_FSPM(x) extract64((x)->val[2], 2, 2) +#define VTD_SM_PASID_ENTRY_WPE(x) extract64((x)->val[2], 4, 1) +#define VTD_SM_PASID_ENTRY_EAFE(x) extract64((x)->val[2], 7, 1) +#define VTD_SM_PASID_ENTRY_FSPTPFN(x) extract64((x)->val[2], 12, 52) =20 /* First Stage Paging Structure */ /* Masks for First Stage Paging Entry */ @@ -696,4 +699,33 @@ struct vtd_as_key { uint8_t devfn; uint32_t pasid; }; + +static inline dma_addr_t vtd_pe_get_fspt_base(VTDPASIDEntry *pe) +{ + return VTD_SM_PASID_ENTRY_FSPTPFN(pe) << VTD_PAGE_SHIFT; +} + +/* + * First stage IOVA address width: 48 bits for 4-level paging(FSPM=3D00) + * 57 bits for 5-level paging(FSPM=3D01) + */ +static inline uint32_t vtd_pe_get_fs_aw(VTDPASIDEntry *pe) +{ + /* + * Paging mode for first-stage translation (VTD spec Figure 9-6) + * 00: 4-level paging, 01: 5-level paging + */ + return VTD_HOST_AW_48BIT + VTD_SM_PASID_ENTRY_FSPM(pe) * 9; +} + +static inline bool vtd_pe_pgtt_is_pt(VTDPASIDEntry *pe) +{ + return (VTD_SM_PASID_ENTRY_PGTT(pe) =3D=3D VTD_SM_PASID_ENTRY_PT); +} + +/* check if PGTT is first stage translation */ +static inline bool vtd_pe_pgtt_is_fst(VTDPASIDEntry *pe) +{ + return (VTD_SM_PASID_ENTRY_PGTT(pe) =3D=3D VTD_SM_PASID_ENTRY_FST); +} #endif diff --git a/hw/i386/intel_iommu.c b/hw/i386/intel_iommu.c index e4610a61b2..ace046836f 100644 --- a/hw/i386/intel_iommu.c +++ b/hw/i386/intel_iommu.c @@ -48,10 +48,11 @@ #define VTD_CE_GET_PRE(ce) \ ((ce)->val[0] & VTD_SM_CONTEXT_ENTRY_PRE) =20 -/* pe operations */ -#define VTD_PE_GET_TYPE(pe) ((pe)->val[0] & VTD_SM_PASID_ENTRY_PGTT) -#define VTD_PE_GET_FS_LEVEL(pe) \ - (4 + (((pe)->val[2] >> 2) & VTD_SM_PASID_ENTRY_FSPM)) +/* + * Paging mode for first-stage translation (VTD spec Figure 9-6) + * 00: 4-level paging, 01: 5-level paging + */ +#define VTD_PE_GET_FS_LEVEL(pe) (VTD_SM_PASID_ENTRY_FSPM(pe) + 4) #define VTD_PE_GET_SS_LEVEL(pe) \ (2 + (((pe)->val[0] >> 2) & VTD_SM_PASID_ENTRY_AW)) =20 @@ -807,7 +808,7 @@ static inline bool vtd_is_fs_level_supported(IntelIOMMU= State *s, uint32_t level) /* Return true if check passed, otherwise false */ static inline bool vtd_pe_type_check(IntelIOMMUState *s, VTDPASIDEntry *pe) { - switch (VTD_PE_GET_TYPE(pe)) { + switch (VTD_SM_PASID_ENTRY_PGTT(pe)) { case VTD_SM_PASID_ENTRY_FST: return !!(s->ecap & VTD_ECAP_FSTS); case VTD_SM_PASID_ENTRY_SST: @@ -882,7 +883,7 @@ static int vtd_get_pe_in_pasid_leaf_table(IntelIOMMUSta= te *s, return -VTD_FR_PASID_TABLE_ENTRY_INV; } =20 - pgtt =3D VTD_PE_GET_TYPE(pe); + pgtt =3D VTD_SM_PASID_ENTRY_PGTT(pe); if (pgtt =3D=3D VTD_SM_PASID_ENTRY_SST && !vtd_is_ss_level_supported(s, VTD_PE_GET_SS_LEVEL(pe))) { return -VTD_FR_PASID_TABLE_ENTRY_INV; @@ -1116,7 +1117,7 @@ static dma_addr_t vtd_get_iova_pgtbl_base(IntelIOMMUS= tate *s, if (s->root_scalable) { vtd_ce_get_pasid_entry(s, ce, &pe, pasid); if (s->fsts) { - return pe.val[2] & VTD_SM_PASID_ENTRY_FSPTPTR; + return vtd_pe_get_fspt_base(&pe); } else { return pe.val[0] & VTD_SM_PASID_ENTRY_SSPTPTR; } @@ -1605,7 +1606,7 @@ static uint16_t vtd_get_domain_id(IntelIOMMUState *s, =20 if (s->root_scalable) { vtd_ce_get_pasid_entry(s, ce, &pe, pasid); - return VTD_SM_PASID_ENTRY_DID(pe.val[1]); + return VTD_SM_PASID_ENTRY_DID(&pe); } =20 return VTD_CONTEXT_ENTRY_DID(ce->hi); @@ -1687,7 +1688,7 @@ static bool vtd_dev_pt_enabled(IntelIOMMUState *s, VT= DContextEntry *ce, */ return false; } - return (VTD_PE_GET_TYPE(&pe) =3D=3D VTD_SM_PASID_ENTRY_PT); + return vtd_pe_pgtt_is_pt(&pe); } =20 return (vtd_ce_get_type(ce) =3D=3D VTD_CONTEXT_TT_PASS_THROUGH); @@ -3108,9 +3109,9 @@ static void vtd_pasid_cache_sync_locked(gpointer key,= gpointer value, /* Fall through */ case VTD_INV_DESC_PASIDC_G_DSI: if (pc_entry->valid) { - did =3D VTD_SM_PASID_ENTRY_DID(pc_entry->pasid_entry.val[1]); + did =3D VTD_SM_PASID_ENTRY_DID(&pc_entry->pasid_entry); } else { - did =3D VTD_SM_PASID_ENTRY_DID(pe.val[1]); + did =3D VTD_SM_PASID_ENTRY_DID(&pe); } if (pc_info->did !=3D did) { return; @@ -5154,8 +5155,8 @@ static int vtd_pri_perform_implicit_invalidation(VTDA= ddressSpace *vtd_as, if (ret) { return -EINVAL; } - pgtt =3D VTD_PE_GET_TYPE(&pe); - domain_id =3D VTD_SM_PASID_ENTRY_DID(pe.val[1]); + pgtt =3D VTD_SM_PASID_ENTRY_PGTT(&pe); + domain_id =3D VTD_SM_PASID_ENTRY_DID(&pe); ret =3D 0; switch (pgtt) { case VTD_SM_PASID_ENTRY_FST: --=20 2.47.1 From nobody Mon Dec 15 12:39:58 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1765781683; cv=none; d=zohomail.com; s=zohoarc; b=E5mddzN9Xo7t3GLj2lpsVvtO8CHTO8TTz15+TWIfRanYbYHqryFGsW/wROBdODHJLcxkgMDxURC4ePJ3yQIf3nPPYvjJp5Q0dWOFjQ1UNn/PvvYeG7roRuV9Q9KiMkCLPo/kAFNl3TnnoGq9OGgUxTE5/siH3aH7SEc+oCVYvfY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1765781683; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=7E3H6tf2qNSFO2KDq/gXDpyIpHEnTqWbBCAtG+bXICM=; b=c6edzQpVPm4KniDNvWSn8FtXVJuIISEf/S8UpHkcQHjviLRzylspt+EW2WOdsePtXB8Ie/ANqQjXS/gOhL6uZLyNUuuXoSx5Dhw/8K/QAvt72xVmkeXbGpK5izur34lAjfl3qKsDBJbYJvjmrBMgU9tqheumevyRivyM6S7qdzM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1765781683110179.82766238943293; Sun, 14 Dec 2025 22:54:43 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vV2RX-0008VX-Eu; Mon, 15 Dec 2025 01:52:30 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vV2RI-0008Fk-Eb for qemu-devel@nongnu.org; Mon, 15 Dec 2025 01:52:13 -0500 Received: from mgamail.intel.com ([198.175.65.15]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vV2RF-0000u9-PB for qemu-devel@nongnu.org; Mon, 15 Dec 2025 01:52:12 -0500 Received: from orviesa009.jf.intel.com ([10.64.159.149]) by orvoesa107.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Dec 2025 22:52:10 -0800 Received: from unknown (HELO gnr-sp-2s-612.sh.intel.com) ([10.112.230.229]) by orviesa009-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Dec 2025 22:52:05 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1765781530; x=1797317530; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=ctOGbbkyAeu6taefT4X2QSoL5UJ6D+CW401dwvnWWQY=; b=Q8tFoilVpeNoF5HqHbMlkdXMJxDdCWmBkIGHwv+Wadt1KPoUjFFi9SFg ltCwpkQdumQRq/jvFQwNWrOAK5Ht68PbgKcjeH0JVgsnCZL1aKMjcpviv uronG0YPzpr6YUfpWteJSPOVu4ITe7ZAFzwOJJht5nAg7nAgjSlDUBgef uiCwqtB/KUJ3iI/cxclUC/c6OHIY58qjRbEq9WqUAAPq3mvbNQQiw8ziQ HN8GBLn2n9ndYKGfMaZdCQq8GwBwApOQmvZuydi7uQjsZtVGW55QtoxM+ LY4reRrO919NAGPEYkqqsEPtOBbmpsS5w3SnX8etze2gAZs95QJ+HgxtT w==; X-CSE-ConnectionGUID: cVf9Q3AnTpyNpY2MtQ5ipg== X-CSE-MsgGUID: h8fgNyY7SLyi7n765tTBpQ== X-IronPort-AV: E=McAfee;i="6800,10657,11642"; a="71305030" X-IronPort-AV: E=Sophos;i="6.21,150,1763452800"; d="scan'208";a="71305030" X-CSE-ConnectionGUID: PPt06TIkSpmwl3mwI/iV1Q== X-CSE-MsgGUID: 0EO9v6LIQbqGY1TDl9nU1w== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.21,150,1763452800"; d="scan'208";a="197408827" From: Zhenzhong Duan To: qemu-devel@nongnu.org Cc: alex@shazbot.org, clg@redhat.com, eric.auger@redhat.com, mst@redhat.com, jasowang@redhat.com, peterx@redhat.com, ddutile@redhat.com, jgg@nvidia.com, nicolinc@nvidia.com, skolothumtho@nvidia.com, joao.m.martins@oracle.com, clement.mathieu--drif@eviden.com, kevin.tian@intel.com, yi.l.liu@intel.com, chao.p.peng@intel.com, Zhenzhong Duan , Yi Sun Subject: [PATCH v9 13/19] intel_iommu_accel: Bind/unbind guest page table to host Date: Mon, 15 Dec 2025 01:50:37 -0500 Message-ID: <20251215065046.86991-14-zhenzhong.duan@intel.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20251215065046.86991-1-zhenzhong.duan@intel.com> References: <20251215065046.86991-1-zhenzhong.duan@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=198.175.65.15; envelope-from=zhenzhong.duan@intel.com; helo=mgamail.intel.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1765781683538158500 Content-Type: text/plain; charset="utf-8" This captures the guest PASID table entry modifications and propagates the changes to host to attach a hwpt with type determined per guest IOMMU PGTT configuration. When PGTT=3DPT, attach PASID_0 to a second stage HWPT(GPA->HPA). When PGTT=3DFST, attach PASID_0 to nested HWPT with nesting parent HWPT coming from VFIO. Co-Authored-by: Yi Liu Signed-off-by: Yi Liu Signed-off-by: Yi Sun Signed-off-by: Zhenzhong Duan --- hw/i386/intel_iommu_accel.h | 7 +++ include/hw/i386/intel_iommu.h | 2 + hw/i386/intel_iommu.c | 22 ++++++- hw/i386/intel_iommu_accel.c | 114 ++++++++++++++++++++++++++++++++++ hw/i386/trace-events | 3 + 5 files changed, 145 insertions(+), 3 deletions(-) diff --git a/hw/i386/intel_iommu_accel.h b/hw/i386/intel_iommu_accel.h index d049cab3e1..82821ec0ef 100644 --- a/hw/i386/intel_iommu_accel.h +++ b/hw/i386/intel_iommu_accel.h @@ -16,6 +16,7 @@ bool vtd_check_hiod_accel(IntelIOMMUState *s, VTDHostIOMMUDevice *vtd_hiod, Error **errp); VTDHostIOMMUDevice *vtd_find_hiod_iommufd(VTDAddressSpace *as); +bool vtd_propagate_guest_pasid(VTDAddressSpace *vtd_as, Error **errp); #else static inline bool vtd_check_hiod_accel(IntelIOMMUState *s, VTDHostIOMMUDevice *vtd_hiod, @@ -30,5 +31,11 @@ static inline VTDHostIOMMUDevice *vtd_find_hiod_iommufd(= VTDAddressSpace *as) { return NULL; } + +static inline bool vtd_propagate_guest_pasid(VTDAddressSpace *vtd_as, + Error **errp) +{ + return true; +} #endif #endif diff --git a/include/hw/i386/intel_iommu.h b/include/hw/i386/intel_iommu.h index 401322665a..6c61fd39c7 100644 --- a/include/hw/i386/intel_iommu.h +++ b/include/hw/i386/intel_iommu.h @@ -154,6 +154,8 @@ struct VTDAddressSpace { * with the guest IOMMU pgtables for a device. */ IOVATree *iova_tree; + + uint32_t fs_hwpt_id; }; =20 struct VTDIOTLBEntry { diff --git a/hw/i386/intel_iommu.c b/hw/i386/intel_iommu.c index ace046836f..fd58fbdac7 100644 --- a/hw/i386/intel_iommu.c +++ b/hw/i386/intel_iommu.c @@ -87,7 +87,11 @@ static void vtd_pasid_cache_reset_locked(IntelIOMMUState= *s) g_hash_table_iter_init(&as_it, s->vtd_address_spaces); while (g_hash_table_iter_next(&as_it, NULL, (void **)&vtd_as)) { VTDPASIDCacheEntry *pc_entry =3D &vtd_as->pasid_cache_entry; - pc_entry->valid =3D false; + if (pc_entry->valid) { + pc_entry->valid =3D false; + /* It's fatal to get failure during reset */ + vtd_propagate_guest_pasid(vtd_as, &error_fatal); + } } } =20 @@ -3073,6 +3077,8 @@ static void vtd_pasid_cache_sync_locked(gpointer key,= gpointer value, VTDPASIDEntry pe; IOMMUNotifier *n; uint16_t did; + const char *err_prefix =3D "Attaching to HWPT failed: "; + Error *local_err =3D NULL; =20 if (vtd_dev_get_pe_from_pasid(vtd_as, &pe)) { if (!pc_entry->valid) { @@ -3093,7 +3099,9 @@ static void vtd_pasid_cache_sync_locked(gpointer key,= gpointer value, vtd_address_space_unmap(vtd_as, n); } vtd_switch_address_space(vtd_as); - return; + + err_prefix =3D "Detaching from HWPT failed: "; + goto do_bind_unbind; } =20 /* @@ -3121,12 +3129,20 @@ static void vtd_pasid_cache_sync_locked(gpointer ke= y, gpointer value, if (!pc_entry->valid) { pc_entry->pasid_entry =3D pe; pc_entry->valid =3D true; - } else if (!vtd_pasid_entry_compare(&pe, &pc_entry->pasid_entry)) { + } else if (vtd_pasid_entry_compare(&pe, &pc_entry->pasid_entry)) { + err_prefix =3D "Replacing HWPT attachment failed: "; + } else { return; } =20 vtd_switch_address_space(vtd_as); vtd_address_space_sync(vtd_as); + +do_bind_unbind: + /* TODO: Fault event injection into guest, report error to QEMU for no= w */ + if (!vtd_propagate_guest_pasid(vtd_as, &local_err)) { + error_reportf_err(local_err, "%s", err_prefix); + } } =20 static void vtd_pasid_cache_sync(IntelIOMMUState *s, VTDPASIDCacheInfo *pc= _info) diff --git a/hw/i386/intel_iommu_accel.c b/hw/i386/intel_iommu_accel.c index ebfc503d64..748a6c7e1c 100644 --- a/hw/i386/intel_iommu_accel.c +++ b/hw/i386/intel_iommu_accel.c @@ -13,6 +13,7 @@ #include "intel_iommu_internal.h" #include "intel_iommu_accel.h" #include "hw/pci/pci_bus.h" +#include "trace.h" =20 bool vtd_check_hiod_accel(IntelIOMMUState *s, VTDHostIOMMUDevice *vtd_hiod, Error **errp) @@ -68,3 +69,116 @@ VTDHostIOMMUDevice *vtd_find_hiod_iommufd(VTDAddressSpa= ce *as) } return NULL; } + +static bool vtd_create_fs_hwpt(HostIOMMUDeviceIOMMUFD *idev, + VTDPASIDEntry *pe, uint32_t *fs_hwpt_id, + Error **errp) +{ + struct iommu_hwpt_vtd_s1 vtd =3D {}; + + vtd.flags =3D (VTD_SM_PASID_ENTRY_SRE(pe) ? IOMMU_VTD_S1_SRE : 0) | + (VTD_SM_PASID_ENTRY_WPE(pe) ? IOMMU_VTD_S1_WPE : 0) | + (VTD_SM_PASID_ENTRY_EAFE(pe) ? IOMMU_VTD_S1_EAFE : 0); + vtd.addr_width =3D vtd_pe_get_fs_aw(pe); + vtd.pgtbl_addr =3D (uint64_t)vtd_pe_get_fspt_base(pe); + + return iommufd_backend_alloc_hwpt(idev->iommufd, idev->devid, idev->hw= pt_id, + 0, IOMMU_HWPT_DATA_VTD_S1, sizeof(vt= d), + &vtd, fs_hwpt_id, errp); +} + +static void vtd_destroy_old_fs_hwpt(HostIOMMUDeviceIOMMUFD *idev, + VTDAddressSpace *vtd_as) +{ + if (!vtd_as->fs_hwpt_id) { + return; + } + iommufd_backend_free_id(idev->iommufd, vtd_as->fs_hwpt_id); + vtd_as->fs_hwpt_id =3D 0; +} + +static bool vtd_device_attach_iommufd(VTDHostIOMMUDevice *vtd_hiod, + VTDAddressSpace *vtd_as, Error **err= p) +{ + HostIOMMUDeviceIOMMUFD *idev =3D HOST_IOMMU_DEVICE_IOMMUFD(vtd_hiod->h= iod); + VTDPASIDEntry *pe =3D &vtd_as->pasid_cache_entry.pasid_entry; + uint32_t hwpt_id =3D idev->hwpt_id; + bool ret; + + /* + * We can get here only if flts=3Don, the supported PGTT is FST or PT. + * Catch invalid PGTT when processing invalidation request to avoid + * attaching to wrong hwpt. + */ + if (!vtd_pe_pgtt_is_fst(pe) && !vtd_pe_pgtt_is_pt(pe)) { + error_setg(errp, "Invalid PGTT type %d", + (uint8_t)VTD_SM_PASID_ENTRY_PGTT(pe)); + return false; + } + + if (vtd_pe_pgtt_is_fst(pe)) { + if (!vtd_create_fs_hwpt(idev, pe, &hwpt_id, errp)) { + return false; + } + } + + ret =3D host_iommu_device_iommufd_attach_hwpt(idev, hwpt_id, errp); + trace_vtd_device_attach_hwpt(idev->devid, vtd_as->pasid, hwpt_id, ret); + if (ret) { + /* Destroy old fs_hwpt if it's a replacement */ + vtd_destroy_old_fs_hwpt(idev, vtd_as); + if (vtd_pe_pgtt_is_fst(pe)) { + vtd_as->fs_hwpt_id =3D hwpt_id; + } + } else if (vtd_pe_pgtt_is_fst(pe)) { + iommufd_backend_free_id(idev->iommufd, hwpt_id); + } + + return ret; +} + +static bool vtd_device_detach_iommufd(VTDHostIOMMUDevice *vtd_hiod, + VTDAddressSpace *vtd_as, Error **err= p) +{ + HostIOMMUDeviceIOMMUFD *idev =3D HOST_IOMMU_DEVICE_IOMMUFD(vtd_hiod->h= iod); + IntelIOMMUState *s =3D vtd_as->iommu_state; + uint32_t pasid =3D vtd_as->pasid; + bool ret; + + if (s->dmar_enabled && s->root_scalable) { + ret =3D host_iommu_device_iommufd_detach_hwpt(idev, errp); + trace_vtd_device_detach_hwpt(idev->devid, pasid, ret); + } else { + /* + * If DMAR remapping is disabled or guest switches to legacy mode, + * we fallback to the default HWPT which contains shadow page tabl= e. + * So guest DMA could still work. + */ + ret =3D host_iommu_device_iommufd_attach_hwpt(idev, idev->hwpt_id,= errp); + trace_vtd_device_reattach_def_hwpt(idev->devid, pasid, idev->hwpt_= id, + ret); + } + + if (ret) { + vtd_destroy_old_fs_hwpt(idev, vtd_as); + } + + return ret; +} + +bool vtd_propagate_guest_pasid(VTDAddressSpace *vtd_as, Error **errp) +{ + VTDPASIDCacheEntry *pc_entry =3D &vtd_as->pasid_cache_entry; + VTDHostIOMMUDevice *vtd_hiod =3D vtd_find_hiod_iommufd(vtd_as); + + /* Ignore emulated device or legacy VFIO backed device */ + if (!vtd_as->iommu_state->fsts || !vtd_hiod) { + return true; + } + + if (pc_entry->valid) { + return vtd_device_attach_iommufd(vtd_hiod, vtd_as, errp); + } + + return vtd_device_detach_iommufd(vtd_hiod, vtd_as, errp); +} diff --git a/hw/i386/trace-events b/hw/i386/trace-events index b704f4f90c..5a3ee1cf64 100644 --- a/hw/i386/trace-events +++ b/hw/i386/trace-events @@ -73,6 +73,9 @@ vtd_warn_invalid_qi_tail(uint16_t tail) "tail 0x%"PRIx16 vtd_warn_ir_vector(uint16_t sid, int index, int vec, int target) "sid 0x%"= PRIx16" index %d vec %d (should be: %d)" vtd_warn_ir_trigger(uint16_t sid, int index, int trig, int target) "sid 0x= %"PRIx16" index %d trigger %d (should be: %d)" vtd_reset_exit(void) "" +vtd_device_attach_hwpt(uint32_t dev_id, uint32_t pasid, uint32_t hwpt_id, = int ret) "dev_id %d pasid %d hwpt_id %d, ret: %d" +vtd_device_detach_hwpt(uint32_t dev_id, uint32_t pasid, int ret) "dev_id %= d pasid %d ret: %d" +vtd_device_reattach_def_hwpt(uint32_t dev_id, uint32_t pasid, uint32_t hwp= t_id, int ret) "dev_id %d pasid %d hwpt_id %d, ret: %d" =20 # amd_iommu.c amdvi_evntlog_fail(uint64_t addr, uint32_t head) "error: fail to write at = addr 0x%"PRIx64" + offset 0x%"PRIx32 --=20 2.47.1 From nobody Mon Dec 15 12:39:58 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1765781600; cv=none; d=zohomail.com; s=zohoarc; b=GDvvPh+s384wIHvOP5WKxgMRuuFF32hLf26tzblOgpZ3A/dWGQBrsmft9VF7j4LkGrnosmaYqnMgPsivWjrrUlnCgwo/ilBp0IISXyshSko9nkVF4GkgU3m3y1lbGuW4bjezQ6mCZ6iTEYm5U8JhAvV3FHMY97yxcwr8Vb6zt1I= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1765781600; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=m3naiYxWS5ZvvUUxPb5dO7xHsKvO251OsQupkxbRfiM=; b=hWcIkRYCu4OOnJcVOMncci3e8EZbxIoUdXb2x8zcUyIdWxpUWrkFIDZkWhw/YkiLndZEiRCBSZaqoVIpYAmf6lJC7fQ1tUetBBdRWse3ZzpzmzJwf8Xwg5Zm2yZle7mb/1uivzo9jWRazBM61vUU+pNSMeB1QMdqYIqKu3dTYUc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1765781600659597.0815931376933; Sun, 14 Dec 2025 22:53:20 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vV2Rc-0000EO-E4; Mon, 15 Dec 2025 01:52:32 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vV2RO-0008Ue-5D for qemu-devel@nongnu.org; Mon, 15 Dec 2025 01:52:21 -0500 Received: from mgamail.intel.com ([198.175.65.15]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vV2RK-0000u9-Gm for qemu-devel@nongnu.org; Mon, 15 Dec 2025 01:52:17 -0500 Received: from orviesa009.jf.intel.com ([10.64.159.149]) by orvoesa107.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Dec 2025 22:52:14 -0800 Received: from unknown (HELO gnr-sp-2s-612.sh.intel.com) ([10.112.230.229]) by orviesa009-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Dec 2025 22:52:10 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1765781535; x=1797317535; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Q3ZfVnvLRRI30A+V2H4/C3KAT4Hd80xvS2oaSTaFW54=; b=T4RIsexATCJ1K7s723gcT7hSQrrWG2j9rLczQUdwldv+PsfvgHjqRUxD S0FACOCDhYERyBgrsPxaKB+OleJawXRxxPQa7lmb/D5PBlghF9jDDbPa7 VDDAa2EF+zlknZWfCqWvZlpc5FhizB6Und6kXbMnsvadrzcrwfBerR1x0 jQDV2gU2Lwg81ORA6cxlJ4P/ySyVh/aLzbovoYVoZe46kEwaR73Mj9owO CcjOXGsLcQUpoo95mIqTXyMLkKQl1HEoIJB5VC6Gas3sLwgsIGtGgovDP f8HuqrPsnDDifaFiOtK7XlRbYwewcSPsSVnaFl9VT72qwgDni6YaFmppf g==; X-CSE-ConnectionGUID: laiwtPHTSm+KgeVoZ9Rfag== X-CSE-MsgGUID: 6HCZu8c6STSrASQzaVKphQ== X-IronPort-AV: E=McAfee;i="6800,10657,11642"; a="71305038" X-IronPort-AV: E=Sophos;i="6.21,150,1763452800"; d="scan'208";a="71305038" X-CSE-ConnectionGUID: 2dm1dxN7QO2Ci1mK4SW7LQ== X-CSE-MsgGUID: WXETWwMURl29Via+BeFcdg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.21,150,1763452800"; d="scan'208";a="197408838" From: Zhenzhong Duan To: qemu-devel@nongnu.org Cc: alex@shazbot.org, clg@redhat.com, eric.auger@redhat.com, mst@redhat.com, jasowang@redhat.com, peterx@redhat.com, ddutile@redhat.com, jgg@nvidia.com, nicolinc@nvidia.com, skolothumtho@nvidia.com, joao.m.martins@oracle.com, clement.mathieu--drif@eviden.com, kevin.tian@intel.com, yi.l.liu@intel.com, chao.p.peng@intel.com, Yi Sun , Zhenzhong Duan Subject: [PATCH v9 14/19] intel_iommu_accel: Propagate PASID-based iotlb invalidation to host Date: Mon, 15 Dec 2025 01:50:38 -0500 Message-ID: <20251215065046.86991-15-zhenzhong.duan@intel.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20251215065046.86991-1-zhenzhong.duan@intel.com> References: <20251215065046.86991-1-zhenzhong.duan@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=198.175.65.15; envelope-from=zhenzhong.duan@intel.com; helo=mgamail.intel.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1765781603311158500 Content-Type: text/plain; charset="utf-8" From: Yi Liu This traps the guest PASID-based iotlb invalidation request and propagate it to host. Intel VT-d 3.0 supports nested translation in PASID granularity. Guest SVA support could be implemented by configuring nested translation on specific pasid. This is also known as dual stage DMA translation. Under such configuration, guest owns the GVA->GPA translation which is configured as first stage page table on host side for a specific pasid, and host owns GPA->HPA translation. As guest owns first stage translation table, piotlb invalidation should be propagated to host since host IOMMU will cache first level page table related mappings during DMA address translation. Signed-off-by: Yi Liu Signed-off-by: Yi Sun Signed-off-by: Zhenzhong Duan Reviewed-by: Eric Auger --- hw/i386/intel_iommu_accel.h | 10 +++++ hw/i386/intel_iommu_internal.h | 6 +++ hw/i386/intel_iommu.c | 11 ++++-- hw/i386/intel_iommu_accel.c | 69 ++++++++++++++++++++++++++++++++++ 4 files changed, 93 insertions(+), 3 deletions(-) diff --git a/hw/i386/intel_iommu_accel.h b/hw/i386/intel_iommu_accel.h index 82821ec0ef..3b0ecc7e22 100644 --- a/hw/i386/intel_iommu_accel.h +++ b/hw/i386/intel_iommu_accel.h @@ -17,6 +17,9 @@ bool vtd_check_hiod_accel(IntelIOMMUState *s, VTDHostIOMM= UDevice *vtd_hiod, Error **errp); VTDHostIOMMUDevice *vtd_find_hiod_iommufd(VTDAddressSpace *as); bool vtd_propagate_guest_pasid(VTDAddressSpace *vtd_as, Error **errp); +void vtd_flush_host_piotlb_all_locked(IntelIOMMUState *s, uint16_t domain_= id, + uint32_t pasid, hwaddr addr, + uint64_t npages, bool ih); #else static inline bool vtd_check_hiod_accel(IntelIOMMUState *s, VTDHostIOMMUDevice *vtd_hiod, @@ -37,5 +40,12 @@ static inline bool vtd_propagate_guest_pasid(VTDAddressS= pace *vtd_as, { return true; } + +static inline void vtd_flush_host_piotlb_all_locked(IntelIOMMUState *s, + uint16_t domain_id, + uint32_t pasid, hwaddr= addr, + uint64_t npages, bool = ih) +{ +} #endif #endif diff --git a/hw/i386/intel_iommu_internal.h b/hw/i386/intel_iommu_internal.h index e987322e93..a2ca79f925 100644 --- a/hw/i386/intel_iommu_internal.h +++ b/hw/i386/intel_iommu_internal.h @@ -622,6 +622,12 @@ typedef struct VTDPASIDCacheInfo { uint32_t pasid; } VTDPASIDCacheInfo; =20 +typedef struct VTDPIOTLBInvInfo { + uint16_t domain_id; + uint32_t pasid; + struct iommu_hwpt_vtd_s1_invalidate *inv_data; +} VTDPIOTLBInvInfo; + /* PASID Table Related Definitions */ #define VTD_PASID_DIR_BASE_ADDR_MASK (~0xfffULL) #define VTD_PASID_TABLE_BASE_ADDR_MASK (~0xfffULL) diff --git a/hw/i386/intel_iommu.c b/hw/i386/intel_iommu.c index fd58fbdac7..e27f055d03 100644 --- a/hw/i386/intel_iommu.c +++ b/hw/i386/intel_iommu.c @@ -2967,6 +2967,8 @@ static void vtd_piotlb_pasid_invalidate(IntelIOMMUSta= te *s, vtd_iommu_lock(s); g_hash_table_foreach_remove(s->iotlb, vtd_hash_remove_by_pasid, &info); + vtd_flush_host_piotlb_all_locked(s, domain_id, pasid, 0, (uint64_t)-1, + false); vtd_iommu_unlock(s); =20 QLIST_FOREACH(vtd_as, &s->vtd_as_with_notifiers, next) { @@ -2986,7 +2988,8 @@ static void vtd_piotlb_pasid_invalidate(IntelIOMMUSta= te *s, } =20 static void vtd_piotlb_page_invalidate(IntelIOMMUState *s, uint16_t domain= _id, - uint32_t pasid, hwaddr addr, uint8_= t am) + uint32_t pasid, hwaddr addr, uint8_= t am, + bool ih) { VTDIOTLBPageInvInfo info; =20 @@ -2998,6 +3001,7 @@ static void vtd_piotlb_page_invalidate(IntelIOMMUStat= e *s, uint16_t domain_id, vtd_iommu_lock(s); g_hash_table_foreach_remove(s->iotlb, vtd_hash_remove_by_page_piotlb, &info); + vtd_flush_host_piotlb_all_locked(s, domain_id, pasid, addr, 1 << am, i= h); vtd_iommu_unlock(s); =20 vtd_iotlb_page_invalidate_notify(s, domain_id, addr, am, pasid); @@ -3029,7 +3033,8 @@ static bool vtd_process_piotlb_desc(IntelIOMMUState *= s, case VTD_INV_DESC_PIOTLB_PSI_IN_PASID: am =3D VTD_INV_DESC_PIOTLB_AM(inv_desc->val[1]); addr =3D (hwaddr) VTD_INV_DESC_PIOTLB_ADDR(inv_desc->val[1]); - vtd_piotlb_page_invalidate(s, domain_id, pasid, addr, am); + vtd_piotlb_page_invalidate(s, domain_id, pasid, addr, am, + VTD_INV_DESC_PIOTLB_IH(inv_desc)); break; =20 default: @@ -5176,7 +5181,7 @@ static int vtd_pri_perform_implicit_invalidation(VTDA= ddressSpace *vtd_as, ret =3D 0; switch (pgtt) { case VTD_SM_PASID_ENTRY_FST: - vtd_piotlb_page_invalidate(s, domain_id, vtd_as->pasid, addr, 0); + vtd_piotlb_page_invalidate(s, domain_id, vtd_as->pasid, addr, 0, f= alse); break; /* Room for other pgtt values */ default: diff --git a/hw/i386/intel_iommu_accel.c b/hw/i386/intel_iommu_accel.c index 748a6c7e1c..2996e4b640 100644 --- a/hw/i386/intel_iommu_accel.c +++ b/hw/i386/intel_iommu_accel.c @@ -182,3 +182,72 @@ bool vtd_propagate_guest_pasid(VTDAddressSpace *vtd_as= , Error **errp) =20 return vtd_device_detach_iommufd(vtd_hiod, vtd_as, errp); } + +/* + * This function is a loop function for the s->vtd_address_spaces + * list with VTDPIOTLBInvInfo as execution filter. It propagates + * the piotlb invalidation to host. + */ +static void vtd_flush_host_piotlb_locked(gpointer key, gpointer value, + gpointer user_data) +{ + VTDPIOTLBInvInfo *piotlb_info =3D user_data; + VTDAddressSpace *vtd_as =3D value; + VTDHostIOMMUDevice *vtd_hiod =3D vtd_find_hiod_iommufd(vtd_as); + VTDPASIDCacheEntry *pc_entry =3D &vtd_as->pasid_cache_entry; + uint16_t did; + + if (!vtd_hiod) { + return; + } + + assert(vtd_as->pasid =3D=3D PCI_NO_PASID); + + /* Nothing to do if there is no first stage HWPT attached */ + if (!pc_entry->valid || + !vtd_pe_pgtt_is_fst(&pc_entry->pasid_entry)) { + return; + } + + did =3D VTD_SM_PASID_ENTRY_DID(&pc_entry->pasid_entry); + + if (piotlb_info->domain_id =3D=3D did && piotlb_info->pasid =3D=3D PAS= ID_0) { + HostIOMMUDeviceIOMMUFD *idev =3D + HOST_IOMMU_DEVICE_IOMMUFD(vtd_hiod->hiod); + uint32_t entry_num =3D 1; /* Only implement one request for simpli= city */ + Error *local_err =3D NULL; + struct iommu_hwpt_vtd_s1_invalidate *cache =3D piotlb_info->inv_da= ta; + + if (!iommufd_backend_invalidate_cache(idev->iommufd, vtd_as->fs_hw= pt_id, + IOMMU_HWPT_INVALIDATE_DATA_V= TD_S1, + sizeof(*cache), &entry_num, = cache, + &local_err)) { + /* Something wrong in kernel, but trying to continue */ + error_report_err(local_err); + } + } +} + +void vtd_flush_host_piotlb_all_locked(IntelIOMMUState *s, uint16_t domain_= id, + uint32_t pasid, hwaddr addr, + uint64_t npages, bool ih) +{ + struct iommu_hwpt_vtd_s1_invalidate cache_info =3D { 0 }; + VTDPIOTLBInvInfo piotlb_info; + + cache_info.addr =3D addr; + cache_info.npages =3D npages; + cache_info.flags =3D ih ? IOMMU_VTD_INV_FLAGS_LEAF : 0; + + piotlb_info.domain_id =3D domain_id; + piotlb_info.pasid =3D pasid; + piotlb_info.inv_data =3D &cache_info; + + /* + * Go through each vtd_as instance in s->vtd_address_spaces, find out + * affected host devices which need host piotlb invalidation. Piotlb + * invalidation should check pasid cache per architecture point of vie= w. + */ + g_hash_table_foreach(s->vtd_address_spaces, + vtd_flush_host_piotlb_locked, &piotlb_info); +} --=20 2.47.1 From nobody Mon Dec 15 12:39:58 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1765781571; cv=none; d=zohomail.com; s=zohoarc; b=V2a+zIIBS7sYHFvLV6SC+U3KmyoAzUjOnlrys7pKjeHFNudpGFc8bPCl7Tu/0/WuN4QsYljWXaFFpTfgaOvP3TsBb0hUNWc/hh/tzDGKlpX02hCH7Si9nFOwXGyQdkoL5uJL0EMrvsaDpA7iLNsMdW6fpempkm/NBx3/15emjEw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1765781571; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=CkvVoiVcGfFm78d1kNcu8eAczRDlOfNNFEMmCRJT/w4=; b=RAJzHkhcFSpwVRDJAS7VbVm+xwuAkbDDQoVsPApjflKhDE3cmRDqCrrJUwx4ezZoUaklP+GZSzafXure1UyDnU1e0Z07mp5JKN8SGwI5ip3oV0tZuD6sACiQaizGf0t+BLWR7As8IJDzodqfgzCMdCRGtGnuIYEsYj7J3I8vFuI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1765781571756781.8204668621546; Sun, 14 Dec 2025 22:52:51 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vV2Ri-0000Z6-SX; Mon, 15 Dec 2025 01:52:38 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vV2RT-0008WQ-N5 for qemu-devel@nongnu.org; Mon, 15 Dec 2025 01:52:26 -0500 Received: from mgamail.intel.com ([198.175.65.15]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vV2RO-0000u9-SM for qemu-devel@nongnu.org; Mon, 15 Dec 2025 01:52:20 -0500 Received: from orviesa009.jf.intel.com ([10.64.159.149]) by orvoesa107.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Dec 2025 22:52:19 -0800 Received: from unknown (HELO gnr-sp-2s-612.sh.intel.com) ([10.112.230.229]) by orviesa009-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Dec 2025 22:52:14 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1765781540; x=1797317540; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=FcPKH15Pp4X6wXLsOEyML7aQuUoKDmokaarwxceYBcc=; b=aOIGq46LExrJdx/EEizQQZa2/i9UU+w78nDoOXaDKh9ehHr8pVpSK/uA br8IJzshcB1c83t+HLhWCn2kQLmuQFSttVM71Tu+iwuOsauitd3CHCZ78 l2+C7n8I/kATg20kzrmQBC2yf1Yw3kwE5w76Ph5YOJgBn8wmAu/YFKEHb T7/bbyaLAi61x4kkTPUmTzYKDK9Wp4WpzYuB/k/rPQd6fOXNFc687Zc/l N6uNVBs13g/sq71Ei1tTNvTg6J86HsLm4QbB+zQolbsJDD2arZi8Z8sRH Uo7UsqcUGqs8bW5e3G6vW0s/F/YGJ4skkWUY6+iPa5+gPStkXJycz3r39 Q==; X-CSE-ConnectionGUID: 4OJ+HmxcSo+0KpRGw9nc3w== X-CSE-MsgGUID: l+dFMySBQ8OhE0epEQ8aYw== X-IronPort-AV: E=McAfee;i="6800,10657,11642"; a="71305046" X-IronPort-AV: E=Sophos;i="6.21,150,1763452800"; d="scan'208";a="71305046" X-CSE-ConnectionGUID: Tnn3g22eQv+FD4t7tChR0Q== X-CSE-MsgGUID: sQuDSF6qQDydmpAsrb0smA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.21,150,1763452800"; d="scan'208";a="197408856" From: Zhenzhong Duan To: qemu-devel@nongnu.org Cc: alex@shazbot.org, clg@redhat.com, eric.auger@redhat.com, mst@redhat.com, jasowang@redhat.com, peterx@redhat.com, ddutile@redhat.com, jgg@nvidia.com, nicolinc@nvidia.com, skolothumtho@nvidia.com, joao.m.martins@oracle.com, clement.mathieu--drif@eviden.com, kevin.tian@intel.com, yi.l.liu@intel.com, chao.p.peng@intel.com, Zhenzhong Duan Subject: [PATCH v9 15/19] intel_iommu: Replay all pasid bindings when either SRTP or TE bit is changed Date: Mon, 15 Dec 2025 01:50:39 -0500 Message-ID: <20251215065046.86991-16-zhenzhong.duan@intel.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20251215065046.86991-1-zhenzhong.duan@intel.com> References: <20251215065046.86991-1-zhenzhong.duan@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=198.175.65.15; envelope-from=zhenzhong.duan@intel.com; helo=mgamail.intel.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1765781573281158500 Content-Type: text/plain; charset="utf-8" From: Yi Liu When either 'Set Root Table Pointer' or 'Translation Enable' bit is changed, all pasid bindings on host side become stale and need to be updated. Introduce a helper function vtd_replay_pasid_bindings_all() to go through a= ll pasid entries in all passthrough devices to update host side bindings. Signed-off-by: Yi Liu Signed-off-by: Zhenzhong Duan Reviewed-by: Eric Auger --- hw/i386/intel_iommu.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/hw/i386/intel_iommu.c b/hw/i386/intel_iommu.c index e27f055d03..0de8f62fd4 100644 --- a/hw/i386/intel_iommu.c +++ b/hw/i386/intel_iommu.c @@ -76,6 +76,7 @@ struct vtd_iotlb_key { =20 static void vtd_address_space_refresh_all(IntelIOMMUState *s); static void vtd_address_space_unmap(VTDAddressSpace *as, IOMMUNotifier *n); +static void vtd_replay_pasid_bindings_all(IntelIOMMUState *s); =20 static void vtd_pasid_cache_reset_locked(IntelIOMMUState *s) { @@ -2629,6 +2630,7 @@ static void vtd_handle_gcmd_srtp(IntelIOMMUState *s) vtd_set_clear_mask_long(s, DMAR_GSTS_REG, 0, VTD_GSTS_RTPS); vtd_reset_caches(s); vtd_address_space_refresh_all(s); + vtd_replay_pasid_bindings_all(s); } =20 /* Set Interrupt Remap Table Pointer */ @@ -2663,6 +2665,7 @@ static void vtd_handle_gcmd_te(IntelIOMMUState *s, bo= ol en) =20 vtd_reset_caches(s); vtd_address_space_refresh_all(s); + vtd_replay_pasid_bindings_all(s); } =20 /* Handle Interrupt Remap Enable/Disable */ @@ -3162,6 +3165,13 @@ static void vtd_pasid_cache_sync(IntelIOMMUState *s,= VTDPASIDCacheInfo *pc_info) vtd_iommu_unlock(s); } =20 +static void vtd_replay_pasid_bindings_all(IntelIOMMUState *s) +{ + VTDPASIDCacheInfo pc_info =3D { .type =3D VTD_INV_DESC_PASIDC_G_GLOBAL= }; + + vtd_pasid_cache_sync(s, &pc_info); +} + static bool vtd_process_pasid_desc(IntelIOMMUState *s, VTDInvDesc *inv_desc) { --=20 2.47.1 From nobody Mon Dec 15 12:39:58 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1765781601; cv=none; d=zohomail.com; s=zohoarc; b=TsG7DSBV1o0odNnL7wBxmfDVBdTNymbfG0Rn2DEf4ObP/Q34v1/HUooQd2rXAYXd9urbZOxOzsBxnYGmo7+fCRlHgjonTelg9H5+zRf7RVc2uOhPlfXMV7YJz+c2C9o2Io29d9TbZBaN8B4/oRzvbjaHCbBsrcZiHYZgI3pJ8uY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1765781601; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=Vhcuni1C8gL7jDAAAv3FssBAk63XVpGO55vBMgK7AmY=; b=igOUolHABcbrfu+cD6kDITKRFXGe5aoEpssMnCgTnqI1glhw5oadgjfWIsiuKdn4eFsm/w1RzOELZqo9grAM/+YWTaGi+Jrh4ANJ7qvqdaQoJwhCmEoqPZfnAFj7Ty7P3Gvax5bkzb1ZV1nevaC+jNHqtUvJcJy4aPgumAXB4yw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 17657816016860.7708001815807393; Sun, 14 Dec 2025 22:53:21 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vV2Rf-0000NV-Qg; Mon, 15 Dec 2025 01:52:35 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vV2RX-00006R-Lb for qemu-devel@nongnu.org; Mon, 15 Dec 2025 01:52:30 -0500 Received: from mgamail.intel.com ([198.175.65.15]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vV2RU-0000u9-Kf for qemu-devel@nongnu.org; Mon, 15 Dec 2025 01:52:27 -0500 Received: from orviesa009.jf.intel.com ([10.64.159.149]) by orvoesa107.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Dec 2025 22:52:23 -0800 Received: from unknown (HELO gnr-sp-2s-612.sh.intel.com) ([10.112.230.229]) by orviesa009-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Dec 2025 22:52:19 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1765781545; x=1797317545; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=IMxQX/FsnIkAxDv6gCcu+JCLY3OWIvjAbmph5ZPGLKU=; b=OqVzB264cFy0U8rUdZ2xVBAfR8fII+TKeXdVoKj079UmeLOgGhSsW1+G Cc7W4NFk3vRQ/BUfwlru/VVdP8kAR2fRYxIR2X+nRUPGUh8eG6ALyws0q PfqROJct+UEeHfrkRPtroLOJHMVMb1u1i9h0Eu20EUE12ndzy7TTYgJAo lGz1GeTc7CSzr4KcineLhFG7oh636bhVJvGXTF0fX9YAKv6U+flnsL9R8 9P3W3igD1fsUtUcYN8vVU3OrooFoeUag0l8urZ/0HzPDU6V0YekJE9HP4 MIXoxCcglPGOkXiHtWOr9hqemZOjJkBBKJVlfF4O+CRYvZcgpN9nuhAPI g==; X-CSE-ConnectionGUID: VnmhcVtrSm+AhY4bJYiRrA== X-CSE-MsgGUID: Crcc43O1RwKRi1sD7r7XLg== X-IronPort-AV: E=McAfee;i="6800,10657,11642"; a="71305081" X-IronPort-AV: E=Sophos;i="6.21,150,1763452800"; d="scan'208";a="71305081" X-CSE-ConnectionGUID: UWSiFc5RRmWxjfFGD6QdYg== X-CSE-MsgGUID: Q74zyquOQZGtI74Xh/NybA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.21,150,1763452800"; d="scan'208";a="197408862" From: Zhenzhong Duan To: qemu-devel@nongnu.org Cc: alex@shazbot.org, clg@redhat.com, eric.auger@redhat.com, mst@redhat.com, jasowang@redhat.com, peterx@redhat.com, ddutile@redhat.com, jgg@nvidia.com, nicolinc@nvidia.com, skolothumtho@nvidia.com, joao.m.martins@oracle.com, clement.mathieu--drif@eviden.com, kevin.tian@intel.com, yi.l.liu@intel.com, chao.p.peng@intel.com, Zhenzhong Duan Subject: [PATCH v9 16/19] intel_iommu: Replay pasid bindings after context cache invalidation Date: Mon, 15 Dec 2025 01:50:40 -0500 Message-ID: <20251215065046.86991-17-zhenzhong.duan@intel.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20251215065046.86991-1-zhenzhong.duan@intel.com> References: <20251215065046.86991-1-zhenzhong.duan@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=198.175.65.15; envelope-from=zhenzhong.duan@intel.com; helo=mgamail.intel.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1765781603246158500 Content-Type: text/plain; charset="utf-8" From: Yi Liu This replays guest pasid bindings after context cache invalidation. Actually, programmer should issue pasid cache invalidation with proper granularity after issuing context cache invalidation. We see old linux such as 6.7.0-rc2 not following the spec, it sends pasid cache invalidation before context cache invalidation, then QEMU depends on context cache invalidation to get pasid entry and setup binding. Signed-off-by: Yi Liu Signed-off-by: Zhenzhong Duan Reviewed-by: Eric Auger --- hw/i386/intel_iommu.c | 42 ++++++++++++++++++++++++++++++++++++++++++ hw/i386/trace-events | 1 + 2 files changed, 43 insertions(+) diff --git a/hw/i386/intel_iommu.c b/hw/i386/intel_iommu.c index 0de8f62fd4..7e304e2988 100644 --- a/hw/i386/intel_iommu.c +++ b/hw/i386/intel_iommu.c @@ -77,6 +77,8 @@ struct vtd_iotlb_key { static void vtd_address_space_refresh_all(IntelIOMMUState *s); static void vtd_address_space_unmap(VTDAddressSpace *as, IOMMUNotifier *n); static void vtd_replay_pasid_bindings_all(IntelIOMMUState *s); +static void vtd_pasid_cache_sync_locked(gpointer key, gpointer value, + gpointer user_data); =20 static void vtd_pasid_cache_reset_locked(IntelIOMMUState *s) { @@ -2322,6 +2324,37 @@ static void vtd_context_global_invalidate(IntelIOMMU= State *s) * VT-d emulation codes. */ vtd_iommu_replay_all(s); + /* + * Same for pasid cache invalidation, per VT-d spec 6.5.2.1, a global + * context cache invalidation should be followed by global PASID cache + * invalidation. In order to work with guest not following spec, + * handle global PASID cache invalidation here. + */ + vtd_replay_pasid_bindings_all(s); +} + +static void vtd_pasid_cache_devsi(VTDAddressSpace *vtd_as) +{ + IntelIOMMUState *s =3D vtd_as->iommu_state; + PCIBus *bus =3D vtd_as->bus; + uint8_t devfn =3D vtd_as->devfn; + struct vtd_as_key key =3D { + .bus =3D bus, + .devfn =3D devfn, + .pasid =3D vtd_as->pasid, + }; + VTDPASIDCacheInfo pc_info; + + if (!s->fsts || !s->root_scalable || !s->dmar_enabled) { + return; + } + + trace_vtd_pasid_cache_devsi(pci_bus_num(bus), + VTD_PCI_SLOT(devfn), VTD_PCI_FUNC(devfn)); + + /* We fake to be global invalidation just to bypass all checks */ + pc_info.type =3D VTD_INV_DESC_PASIDC_G_GLOBAL; + vtd_pasid_cache_sync_locked(&key, vtd_as, &pc_info); } =20 /* Do a context-cache device-selective invalidation. @@ -2382,6 +2415,15 @@ static void vtd_context_device_invalidate(IntelIOMMU= State *s, * happened. */ vtd_address_space_sync(vtd_as); + /* + * Per spec 6.5.2.1, context flush should be followed by PASID + * cache and iotlb flush. In order to work with a guest which = does + * not follow spec and missed PASID cache flush, e.g., linux + * 6.7.0-rc2, we have vtd_pasid_cache_devsi() to invalidate PA= SID + * cache of passthrough device. Host iommu driver would flush + * piotlb when a pasid unbind is passed down to it. + */ + vtd_pasid_cache_devsi(vtd_as); } } } diff --git a/hw/i386/trace-events b/hw/i386/trace-events index 5a3ee1cf64..5fa5e93b68 100644 --- a/hw/i386/trace-events +++ b/hw/i386/trace-events @@ -28,6 +28,7 @@ vtd_pasid_cache_reset(void) "" vtd_inv_desc_pasid_cache_gsi(void) "" vtd_inv_desc_pasid_cache_dsi(uint16_t domain) "Domain selective PC invalid= ation domain 0x%"PRIx16 vtd_inv_desc_pasid_cache_psi(uint16_t domain, uint32_t pasid) "PASID selec= tive PC invalidation domain 0x%"PRIx16" pasid 0x%"PRIx32 +vtd_pasid_cache_devsi(uint8_t bus, uint8_t dev, uint8_t fn) "Dev selective= PC invalidation dev: %02"PRIx8":%02"PRIx8".%02"PRIx8 vtd_re_not_present(uint8_t bus) "Root entry bus %"PRIu8" not present" vtd_ce_not_present(uint8_t bus, uint8_t devfn) "Context entry bus %"PRIu8"= devfn %"PRIu8" not present" vtd_iotlb_page_hit(uint16_t sid, uint64_t addr, uint64_t slpte, uint16_t d= omain) "IOTLB page hit sid 0x%"PRIx16" iova 0x%"PRIx64" slpte 0x%"PRIx64" d= omain 0x%"PRIx16 --=20 2.47.1 From nobody Mon Dec 15 12:39:58 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1765781578; cv=none; d=zohomail.com; s=zohoarc; b=hTzoCGHzI0n1YwT2ruUu8kMO6FFFWGWeHadT5LLnvI/ddoSkFzW2gw/6izFYBgSn0ES6S5kS8d2YI2T69sjdLwQ6oqYSElCwq3xKzzxo74XZZ2r111v8vKnqRIbuxKkZz39x0LYPnp/YuoV9XDb74jkyul5ijA73pSwObKICcLk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1765781578; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=tx/pFsnSCicqWKaTj9AKLumolW1vRPpIwqE3knzYu3c=; b=IzZkL5MA1RC3sP1dqg6t57JlU8XBDotvQW+tgujMra3P8t5x2h3HqL85bODmMhCrkzCwvShxQcQvumFMxwXnT6Ui6f5HxqoMinHU3KhHXZWkB0RPpZldjkIJZPkGM2j9n5nkudksudsYBoa9/zNdND+LL2TtQobJhUAHJ8BmaV0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1765781578807594.6555693991687; Sun, 14 Dec 2025 22:52:58 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vV2Rh-0000W8-5H; Mon, 15 Dec 2025 01:52:37 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vV2Ra-00007g-RG for qemu-devel@nongnu.org; Mon, 15 Dec 2025 01:52:31 -0500 Received: from mgamail.intel.com ([198.175.65.15]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vV2RZ-0000u9-1N for qemu-devel@nongnu.org; Mon, 15 Dec 2025 01:52:30 -0500 Received: from orviesa009.jf.intel.com ([10.64.159.149]) by orvoesa107.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Dec 2025 22:52:28 -0800 Received: from unknown (HELO gnr-sp-2s-612.sh.intel.com) ([10.112.230.229]) by orviesa009-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Dec 2025 22:52:23 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1765781550; x=1797317550; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=hFAN9fo13oKyMqz6aFqkrlF1drPiFgR9r5J/part/VA=; b=B4DbgVptIflcV8N1wUf8xMK4FgXWoS0aQOzdX4WuD7xxTJRBRRJfg/C3 Jm+MIeC9r6n5BSXLrDyk4lqwbEJr2Y3aeQHZPBP1+zW1HQVJieWdBkJqz sx96JVSJ8Enjt1ndPgs8dB4BjHE+QPtFfxahpMZjfTdsnERf9/heHwiaU wlx+7+wZn5a+ecCpAysDsqqINpbcRmxyVC7821/U50Q1lNGm+lmCG32uR uBagtm0llTOZZd0KkMzVAz94HDur5Om0tiDKbbaLL9uWKjm4Ax4OqWlF9 cBkjmUfWIsrRu1b3H7sbioUmAfF7lperzX6rjnTaoUpEVW3mee7eVWdIP A==; X-CSE-ConnectionGUID: sxBKwSpKTyGOcPOJuMQJrQ== X-CSE-MsgGUID: jfm3Cr/rScSZzabJOpc6IQ== X-IronPort-AV: E=McAfee;i="6800,10657,11642"; a="71305096" X-IronPort-AV: E=Sophos;i="6.21,150,1763452800"; d="scan'208";a="71305096" X-CSE-ConnectionGUID: cW6yZOTlTtCHmf9nDylsig== X-CSE-MsgGUID: NCzSin3TT3Ou1/Vl9AD2Ew== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.21,150,1763452800"; d="scan'208";a="197408875" From: Zhenzhong Duan To: qemu-devel@nongnu.org Cc: alex@shazbot.org, clg@redhat.com, eric.auger@redhat.com, mst@redhat.com, jasowang@redhat.com, peterx@redhat.com, ddutile@redhat.com, jgg@nvidia.com, nicolinc@nvidia.com, skolothumtho@nvidia.com, joao.m.martins@oracle.com, clement.mathieu--drif@eviden.com, kevin.tian@intel.com, yi.l.liu@intel.com, chao.p.peng@intel.com, Zhenzhong Duan Subject: [PATCH v9 17/19] intel_iommu: Add migration support with x-flts=on Date: Mon, 15 Dec 2025 01:50:41 -0500 Message-ID: <20251215065046.86991-18-zhenzhong.duan@intel.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20251215065046.86991-1-zhenzhong.duan@intel.com> References: <20251215065046.86991-1-zhenzhong.duan@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=198.175.65.15; envelope-from=zhenzhong.duan@intel.com; helo=mgamail.intel.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1765781579377158500 Content-Type: text/plain; charset="utf-8" When x-flts=3Don, we set up bindings to nested HWPT in host, after migration, VFIO device binds to nesting parent HWPT by default. We need to re-establish the bindings to nested HWPT, or else device DMA will break. Signed-off-by: Zhenzhong Duan Reviewed-by: Eric Auger --- hw/i386/intel_iommu.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/hw/i386/intel_iommu.c b/hw/i386/intel_iommu.c index 7e304e2988..7220a3d9f4 100644 --- a/hw/i386/intel_iommu.c +++ b/hw/i386/intel_iommu.c @@ -4090,6 +4090,13 @@ static int vtd_post_load(void *opaque, int version_i= d) */ vtd_switch_address_space_all(iommu); =20 + /* + * Bindings to nested HWPT in host is set up dynamically depending + * on pasid entry configuration from guest. After migration, we + * need to re-establish the bindings before restoring device's DMA. + */ + vtd_replay_pasid_bindings_all(iommu); + return 0; } =20 --=20 2.47.1 From nobody Mon Dec 15 12:39:58 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1765781665; cv=none; d=zohomail.com; s=zohoarc; b=C5uFBhT6LF7rbBWgc36FLGi9o1KdKp0jtJlkCxFHU4F7uulSDpaPOUa+aEB9DjhU25lIaJZbJCBGc3k6y67yIKGrkKezSsAbDsUpgYIiBSFn0SYKoYLN0MmoA2Fw3NKuJRAGkOnoIM5Cm7mC6L6UaIb59LFeIfcZEpxLKZHZbnQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1765781665; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=RBLR333qyCtBl1TglkxHVa+sj6Ava/U6etpysRC7fA8=; b=lILlj8y/BAdoqZCOsmJIMgtjJPeNojcjIxUC8125A4YT8JEv5v7xQQvmOsOc61WL6rrJCVQ6HsgZ9lDmJbJ5HDxY1fij74IiUFrpe7pIWuSgOM6+QD1JOQXtMfJl85y3Q/++wKLGJYE/wM91KB+VrWlnxL7geslHyWtOnVTO2PI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1765781665187206.4678566184267; Sun, 14 Dec 2025 22:54:25 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vV2Rv-0001gE-U9; Mon, 15 Dec 2025 01:52:52 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vV2Rp-0001Mw-2C for qemu-devel@nongnu.org; Mon, 15 Dec 2025 01:52:45 -0500 Received: from mgamail.intel.com ([198.175.65.15]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vV2Rm-00014A-UX for qemu-devel@nongnu.org; Mon, 15 Dec 2025 01:52:44 -0500 Received: from orviesa009.jf.intel.com ([10.64.159.149]) by orvoesa107.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Dec 2025 22:52:32 -0800 Received: from unknown (HELO gnr-sp-2s-612.sh.intel.com) ([10.112.230.229]) by orviesa009-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Dec 2025 22:52:27 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1765781564; x=1797317564; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=uwwMgZDoWs1LOscTwMg6pcryjtTBJBniguJPPb91ufM=; b=hiSgG08Wp4EhOQiZIPE2a8NgLABFhzhP49EY8uxgGUpGzCkvSIZUa3k2 eP45x2pKjFOyFDfAKzxyZ6WIX2/4uRk0DMRoDJ+Ob56G7PCHnbozyQn8Z JCkcykhQ7AGYXBqo30adj1KGASZLUbLjdfc4PGX30paYatRjSvcv5F4Ce //DyOeYI/XxhFuqMs4n8Dsqb/cY0VNbHumD2f8KeMsje46HsCOn/9fhLR TedHBibjSaUWHcFPX5ovTTOANZPzYptF5RvmeQcM7l24y18399DNH4HD1 u8jB9zSHAPxg0cUfTHSgD7hRpJYf+jmNDOLCe1guwo1LAmF4ROUsmpYsA A==; X-CSE-ConnectionGUID: +GTuU97sQZaoXNv9GyZncA== X-CSE-MsgGUID: sINEC6BYQn2Y7LtMMa2qzw== X-IronPort-AV: E=McAfee;i="6800,10657,11642"; a="71305102" X-IronPort-AV: E=Sophos;i="6.21,150,1763452800"; d="scan'208";a="71305102" X-CSE-ConnectionGUID: q08C/DrgR/uycIFtw931VA== X-CSE-MsgGUID: ciFajZhYRgC6837i8Pe6xg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.21,150,1763452800"; d="scan'208";a="197408882" From: Zhenzhong Duan To: qemu-devel@nongnu.org Cc: alex@shazbot.org, clg@redhat.com, eric.auger@redhat.com, mst@redhat.com, jasowang@redhat.com, peterx@redhat.com, ddutile@redhat.com, jgg@nvidia.com, nicolinc@nvidia.com, skolothumtho@nvidia.com, joao.m.martins@oracle.com, clement.mathieu--drif@eviden.com, kevin.tian@intel.com, yi.l.liu@intel.com, chao.p.peng@intel.com, Zhenzhong Duan Subject: [PATCH v9 18/19] intel_iommu: Enable host device when x-flts=on in scalable mode Date: Mon, 15 Dec 2025 01:50:42 -0500 Message-ID: <20251215065046.86991-19-zhenzhong.duan@intel.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20251215065046.86991-1-zhenzhong.duan@intel.com> References: <20251215065046.86991-1-zhenzhong.duan@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=198.175.65.15; envelope-from=zhenzhong.duan@intel.com; helo=mgamail.intel.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1765781667412158500 Content-Type: text/plain; charset="utf-8" Now that all infrastructures of supporting passthrough device running with first stage translation are there, enable it now. Signed-off-by: Zhenzhong Duan Reviewed-by: Eric Auger Reviewed-by: Yi Liu --- hw/i386/intel_iommu_accel.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/hw/i386/intel_iommu_accel.c b/hw/i386/intel_iommu_accel.c index 2996e4b640..89f3d55f6f 100644 --- a/hw/i386/intel_iommu_accel.c +++ b/hw/i386/intel_iommu_accel.c @@ -47,9 +47,7 @@ bool vtd_check_hiod_accel(IntelIOMMUState *s, VTDHostIOMM= UDevice *vtd_hiod, return false; } =20 - error_setg(errp, - "host IOMMU is incompatible with guest first stage translat= ion"); - return false; + return true; } =20 VTDHostIOMMUDevice *vtd_find_hiod_iommufd(VTDAddressSpace *as) --=20 2.47.1 From nobody Mon Dec 15 12:39:58 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1765781666; cv=none; d=zohomail.com; s=zohoarc; b=Q+FzE44aWrsUSkS6KOeNfqZK655KV4k/nTCn1TicA02NJT/QMAkK//lqSaubqKALhiAY6hKY1OXo1M/3H5u86Gdretix9G32iw3KoeUUK1ocihUS7qs0Y+eqZz5XmZyL/kNLs98JxCooCIbJgfj0+yymAaQKTT6Cza2cFJcWx+U= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1765781666; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=UdQdI/Jpwlc5RWUUQfdkuRLu4FIAV4gQP1RXjeJ97AE=; b=Gi85TOBa/cI0EaDwDN7//KMl7h15m14qOkgIjuNvxJwrWM0CIytcMD84Pi1RpbDpewOKULNRNE8YDytW2atjc7FSPwv9FfkqALsgdovHHdEeXqSREHhIVJMcploaJ3tObZQguZAXYPnBcNLiNifXuVf2pRlQlJH6WUgt9OiqhbI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1765781666495910.8377120335103; Sun, 14 Dec 2025 22:54:26 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vV2Rx-0001qQ-85; Mon, 15 Dec 2025 01:52:53 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vV2Rv-0001gF-Pd for qemu-devel@nongnu.org; Mon, 15 Dec 2025 01:52:51 -0500 Received: from mgamail.intel.com ([198.175.65.15]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vV2Rr-00014a-90 for qemu-devel@nongnu.org; Mon, 15 Dec 2025 01:52:49 -0500 Received: from orviesa009.jf.intel.com ([10.64.159.149]) by orvoesa107.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Dec 2025 22:52:36 -0800 Received: from unknown (HELO gnr-sp-2s-612.sh.intel.com) ([10.112.230.229]) by orviesa009-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Dec 2025 22:52:32 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1765781568; x=1797317568; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=ufcuUMz/hQmkYT72gGQ4dMgb8/t5QPR7rlb6CAuNZmI=; b=gZbYvvlwc/wDrj8IvkjtQQMkWGq7OecpsmPrev905YJuXWygn2z90uC8 QWBsSj8ggE5Cm9xCRs3sdDQTkZ5qnZBMsedJGBGf8giYnH+tyHXiv6ohv 0SiCZdeKWZ8pQSbIlURn0CrozpxkTW0OWuBx3qD6ZXyfM8GKsUSbxjAPI aFaDykqb84YNxxVDHNGcpfduQIgGQf94FpTOrAD6GYBIEKU5/9BfaLMTN Wjlc73o3M8Qs/P8rDl9pjyFsAvpx+agDEhUr6IjVHlj+JHCR7UuUAroGo BwmBz9dot0TAUrGyspb2HM4VkJ6kV6bPoRvhJHJa7QLmscxGeR6rYy+Yr Q==; X-CSE-ConnectionGUID: OUb9nSXNRO6okFpVLjP5Zg== X-CSE-MsgGUID: ArBw2MzUSzKwacX8liNeMQ== X-IronPort-AV: E=McAfee;i="6800,10657,11642"; a="71305111" X-IronPort-AV: E=Sophos;i="6.21,150,1763452800"; d="scan'208";a="71305111" X-CSE-ConnectionGUID: jXHWPOwkR6WYYjX6J0YZMw== X-CSE-MsgGUID: X4u+/RQCQyObahkw35em4A== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.21,150,1763452800"; d="scan'208";a="197408888" From: Zhenzhong Duan To: qemu-devel@nongnu.org Cc: alex@shazbot.org, clg@redhat.com, eric.auger@redhat.com, mst@redhat.com, jasowang@redhat.com, peterx@redhat.com, ddutile@redhat.com, jgg@nvidia.com, nicolinc@nvidia.com, skolothumtho@nvidia.com, joao.m.martins@oracle.com, clement.mathieu--drif@eviden.com, kevin.tian@intel.com, yi.l.liu@intel.com, chao.p.peng@intel.com, Zhenzhong Duan Subject: [PATCH v9 19/19] docs/devel: Add IOMMUFD nesting documentation Date: Mon, 15 Dec 2025 01:50:43 -0500 Message-ID: <20251215065046.86991-20-zhenzhong.duan@intel.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20251215065046.86991-1-zhenzhong.duan@intel.com> References: <20251215065046.86991-1-zhenzhong.duan@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=198.175.65.15; envelope-from=zhenzhong.duan@intel.com; helo=mgamail.intel.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1765781667426158500 Content-Type: text/plain; charset="utf-8" Add documentation about using IOMMUFD backed VFIO device with intel_iommu w= ith x-flts=3Don. Suggested-by: Yi Liu Signed-off-by: Zhenzhong Duan Reviewed-by: Eric Auger --- docs/devel/vfio-iommufd.rst | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/docs/devel/vfio-iommufd.rst b/docs/devel/vfio-iommufd.rst index 3d1c11f175..6ebb4a89ba 100644 --- a/docs/devel/vfio-iommufd.rst +++ b/docs/devel/vfio-iommufd.rst @@ -164,3 +164,20 @@ RAM discarding for mdev. =20 ``vfio-ap`` and ``vfio-ccw`` devices don't have same issue as their backend devices are always mdev and RAM discarding is force enabled. + +Usage with intel_iommu featuring x-flts=3Don +------------------------------------------ + +Only IOMMUFD backed VFIO device is supported when intel_iommu is configured +with x-flts=3Don, for legacy container backed VFIO device, below error sho= ws: + +.. code-block:: none + + qemu-system-x86_64: -device vfio-pci,host=3D0000:02:00.0: vfio 0000:02= :00.0: Failed to set vIOMMU: Need IOMMUFD backend when x-flts=3Don + +VFIO device under PCI bridge is unsupported, use PCIE bridge if necessary, +otherwise below error shows: + +.. code-block:: none + + qemu-system-x86_64: -device vfio-pci,host=3D0000:02:00.0,bus=3Dbridge1= ,iommufd=3Diommufd0: vfio 0000:02:00.0: Failed to set vIOMMU: Host device d= ownstream to a PCI bridge is unsupported when x-flts=3Don --=20 2.47.1