From nobody Sat Nov 15 00:44:23 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=1758185992; cv=none; d=zohomail.com; s=zohoarc; b=N/InHGzvIehMHAy/mtMGPcITV1hun1aqvBjc6YeaIDqTDCgCK2q+sGvb1SUtxooiYRImzhTDz61Gs7xJ+29+oifKbHsMPJyboRACIW+SmeANzPWTuL01/P7XcWMThzXRyyHkOJkp+B1v+v55Hxo7sur2cGDXvhdEGV5ExIRYquw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1758185992; 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=QaEEzkeI5IKFHp2feCvdrS6I/Rbnzxc3/s38rtOy8cc=; b=hj3f+VpQJy+DYlZ8jH7jQoIFP+pOc0QVdFV/HLL/fycPLQQTNVJHeYmbNdrdV4F/TZSuN8pzZZsRiutNdHUeCj1dIKmjxBd3GdNTr6sSjmzvlk11uomrTrV97i7XdhTzqHau11tWfYVcpanvXtvyTaS+72np0h+UqeWWECs9wEI= 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 1758185992970613.7791376587151; Thu, 18 Sep 2025 01:59:52 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uzATW-0000id-5n; Thu, 18 Sep 2025 04:58:46 -0400 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 1uzATT-0000gH-Q0 for qemu-devel@nongnu.org; Thu, 18 Sep 2025 04:58:43 -0400 Received: from mgamail.intel.com ([192.198.163.8]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uzATR-0004iq-MY for qemu-devel@nongnu.org; Thu, 18 Sep 2025 04:58:43 -0400 Received: from fmviesa009.fm.intel.com ([10.60.135.149]) by fmvoesa102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Sep 2025 01:58:37 -0700 Received: from unknown (HELO gnr-sp-2s-612.sh.intel.com) ([10.112.230.229]) by fmviesa009-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Sep 2025 01:58:34 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1758185921; x=1789721921; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=PauFapVo+fEKOPZXad/UTloRlbZBHB9uumVac4Y0hT4=; b=FwPSIFXHeeBYS9yX8AWg2G/PUfgVF1mZPjIIVq2Jh8fJOCaL23TQawB4 C4vrwap33hoewxirw+XuN11rgD3Kh+oTtVQd3uNW6QpfwtSBcllZ97Bi9 poewjl2Rk27OmKOq2qv6nR4nPPgIG+6yt+wXoNFX61EV6CoJWgXQwD7/Q 2HU+P1h0D/xweZsi46sszeR/hDfXmI5KjKD6LMAmrFJAwYwBZSc72G4Pn 2jJXMhjtXKQpCDOcB3x/djXFMNW9FegdQ95/WKZeg8Vu6zDK/L9f9UWcF Pqg3KZy7CcOrrDXz7whmvff5IRfawDH8KZ//rJDFnXzwSCSa7jceIr6vR A==; X-CSE-ConnectionGUID: D1JVVPV8QSu85BMRC5lfog== X-CSE-MsgGUID: 5u6P1CybQlOGKtMzIaZxoA== X-IronPort-AV: E=McAfee;i="6800,10657,11556"; a="78109367" X-IronPort-AV: E=Sophos;i="6.18,274,1751266800"; d="scan'208";a="78109367" X-CSE-ConnectionGUID: TLSQ/p4vSfSvraeC3rsMmg== X-CSE-MsgGUID: Sh9+u8v/Rnq6Pz177IErBg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.18,274,1751266800"; d="scan'208";a="175930274" From: Zhenzhong Duan To: qemu-devel@nongnu.org Cc: alex.williamson@redhat.com, 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 v6 01/22] intel_iommu: Rename vtd_ce_get_rid2pasid_entry to vtd_ce_get_pasid_entry Date: Thu, 18 Sep 2025 04:57:40 -0400 Message-ID: <20250918085803.796942-2-zhenzhong.duan@intel.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250918085803.796942-1-zhenzhong.duan@intel.com> References: <20250918085803.796942-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=192.198.163.8; 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_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_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: 1758185993577116600 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 | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/hw/i386/intel_iommu.c b/hw/i386/intel_iommu.c index 83c5e44413..71b70b795d 100644 --- a/hw/i386/intel_iommu.c +++ b/hw/i386/intel_iommu.c @@ -944,10 +944,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; @@ -1025,7 +1023,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 { @@ -1048,7 +1046,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 @@ -1116,7 +1114,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 { @@ -1522,7 +1520,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) */ @@ -1611,7 +1609,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 @@ -1687,7 +1685,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 --=20 2.47.1 From nobody Sat Nov 15 00:44:23 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=1758185971; cv=none; d=zohomail.com; s=zohoarc; b=FmlOkXS+zb5W34q/nbp7RWBcGNTp6TREQrnwZcmGKzxZmy8QOPqErQygdX+oEnqyoL40Pd+KgSfKrzdd6VZiKqjqwNopcUH9CmE8XOIT2nS4887/u3wOMwnSgArd1S698iFxIiI6fT2l9e6tuyFM6ieL6fiVxwHHG/hzGMKCg0k= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1758185971; 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=pRZ1e7nbH7L6P2cRtCGdjEdT7L7IyAng98HFLovwYjw=; b=Fq8+6P55Qs8WPxj+lPqLRQEorWaNJuR1G5GG+Q0AddwszterKujSgofUZSN293g3DoBAxigOb1oVpnJqbNrOCgyiCWnRhkKEFq72HVEabbxuYu9vv6VtWTRaHM1Ox8CvBkGtAOyU+Y03Tfo8RhUg1twrHMmZCzRZH07FsmtanPg= 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 1758185971297677.3464258107023; Thu, 18 Sep 2025 01:59:31 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uzATX-0000kL-HA; Thu, 18 Sep 2025 04:58:48 -0400 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 1uzATV-0000iE-MD for qemu-devel@nongnu.org; Thu, 18 Sep 2025 04:58:45 -0400 Received: from mgamail.intel.com ([192.198.163.8]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uzATT-0004j2-9W for qemu-devel@nongnu.org; Thu, 18 Sep 2025 04:58:45 -0400 Received: from fmviesa009.fm.intel.com ([10.60.135.149]) by fmvoesa102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Sep 2025 01:58:41 -0700 Received: from unknown (HELO gnr-sp-2s-612.sh.intel.com) ([10.112.230.229]) by fmviesa009-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Sep 2025 01:58:38 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1758185923; x=1789721923; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Fe/PC2nZXH6grKp3LPD3ZFdzpbbw2sGj0bmB0sD4EDA=; b=CR1HXvwzGic8RM3FkMD9vTJEjU87vpWlD1OkznUSa7uXfLbu3DLsD02h lrTVBu0y3Vs6Rpez1QaA4g7JZlD/ns21KvgDU9/fMLEqDAQJFQZDOSPkz Mitd9643uUjrUNyXMOkkXyBs9WBHonZf3kj0fYqySIGtn/A2dpfKa+Mux Uha2qPfnDSm0vTRbTC3532SElwn7e+s0Q7FxRa0RtyVZkhTKDwzYa/Lxe TMIY4z2crrRjnahLO7zjweBEidC2LuH5tvtvnRRYwh0eNvA010m4OqhRC J3dk+f1N1Ae61pwgRy/yY3pp+Py+NtWAgHo1f9EsmDHyNfonn1XdRUfK+ w==; X-CSE-ConnectionGUID: zUock9ELQI65vbsa+Gf14Q== X-CSE-MsgGUID: V3sbUdp6SziwGIyKKpwY1A== X-IronPort-AV: E=McAfee;i="6800,10657,11556"; a="78109383" X-IronPort-AV: E=Sophos;i="6.18,274,1751266800"; d="scan'208";a="78109383" X-CSE-ConnectionGUID: EIBwaUZKQ7mrUGStAQpqTQ== X-CSE-MsgGUID: 6ZO2TeYdSUOMkPAlp8SnnA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.18,274,1751266800"; d="scan'208";a="175930290" From: Zhenzhong Duan To: qemu-devel@nongnu.org Cc: alex.williamson@redhat.com, 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 v6 02/22] intel_iommu: Delete RPS capability related supporting code Date: Thu, 18 Sep 2025 04:57:41 -0400 Message-ID: <20250918085803.796942-3-zhenzhong.duan@intel.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250918085803.796942-1-zhenzhong.duan@intel.com> References: <20250918085803.796942-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=192.198.163.8; 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_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_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: 1758185973512116600 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 take 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 simplify the code and doesn't bring any penalty. Opportunistically, s/rid2pasid/rid_pasid and s/RID2PASID/RID_PASID as VTD spec uses RID_PASID terminology. Suggested-by: Yi Liu Signed-off-by: Zhenzhong Duan --- hw/i386/intel_iommu_internal.h | 1 - hw/i386/intel_iommu.c | 49 +++++++++++++--------------------- 2 files changed, 19 insertions(+), 31 deletions(-) diff --git a/hw/i386/intel_iommu_internal.h b/hw/i386/intel_iommu_internal.h index 360e937989..6abe76556a 100644 --- a/hw/i386/intel_iommu_internal.h +++ b/hw/i386/intel_iommu_internal.h @@ -547,7 +547,6 @@ 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 VTD_SM_CONTEXT_ENTRY_RSVD_VAL0(aw) (0x1e0ULL | ~VTD_HAW_MASK(aw)) #define VTD_SM_CONTEXT_ENTRY_RSVD_VAL1 0xffffffffffe00000ULL =20 diff --git a/hw/i386/intel_iommu.c b/hw/i386/intel_iommu.c index 71b70b795d..b976b251bc 100644 --- a/hw/i386/intel_iommu.c +++ b/hw/i386/intel_iommu.c @@ -41,8 +41,7 @@ #include "trace.h" =20 /* context entry operations */ -#define VTD_CE_GET_RID2PASID(ce) \ - ((ce)->val[1] & VTD_SM_CONTEXT_ENTRY_RID2PASID_MASK) +#define RID_PASID 0 #define VTD_CE_GET_PASID_DIR_TABLE(ce) \ ((ce)->val[0] & VTD_PASID_DIR_BASE_ADDR_MASK) =20 @@ -951,7 +950,7 @@ static int vtd_ce_get_pasid_entry(IntelIOMMUState *s, V= TDContextEntry *ce, int ret =3D 0; =20 if (pasid =3D=3D PCI_NO_PASID) { - pasid =3D VTD_CE_GET_RID2PASID(ce); + pasid =3D RID_PASID; } 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); @@ -970,7 +969,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 RID_PASID; } pasid_dir_base =3D VTD_CE_GET_PASID_DIR_TABLE(ce); =20 @@ -1510,15 +1509,14 @@ static inline int vtd_context_entry_rsvd_bits_check= (IntelIOMMUState *s, return 0; } =20 -static int vtd_ce_rid2pasid_check(IntelIOMMUState *s, +static int vtd_ce_rid_pasid_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 RID_PASID(0). */ return vtd_ce_get_pasid_entry(s, ce, &pe, PCI_NO_PASID); } @@ -1581,12 +1579,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 at RID_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); + ret_fr =3D vtd_ce_rid_pasid_check(s, ce); if (ret_fr) { return ret_fr; } @@ -2097,7 +2094,7 @@ 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; + bool rid_pasid =3D (pasid =3D=3D PCI_NO_PASID) && s->root_scalable; VTDIOTLBEntry *iotlb_entry; uint64_t xlat, size; =20 @@ -2111,8 +2108,8 @@ static bool vtd_do_iommu_translate(VTDAddressSpace *v= td_as, PCIBus *bus, =20 cc_entry =3D &vtd_as->context_cache_entry; =20 - /* Try to fetch pte from IOTLB, we don't need RID2PASID logic */ - if (!rid2pasid) { + /* Try to fetch pte from IOTLB, we don't need RID_PASID(0) logic */ + if (!rid_pasid) { 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, @@ -2160,8 +2157,8 @@ static bool vtd_do_iommu_translate(VTDAddressSpace *v= td_as, PCIBus *bus, cc_entry->context_cache_gen =3D s->context_cache_gen; } =20 - if (rid2pasid) { - pasid =3D VTD_CE_GET_RID2PASID(&ce); + if (rid_pasid) { + pasid =3D RID_PASID; } =20 /* @@ -2189,8 +2186,8 @@ static bool vtd_do_iommu_translate(VTDAddressSpace *v= td_as, PCIBus *bus, return true; } =20 - /* Try to fetch pte from IOTLB for RID2PASID slow path */ - if (rid2pasid) { + /* Try to fetch pte from IOTLB for RID_PASID(0) slow path */ + if (rid_pasid) { 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, @@ -2464,20 +2461,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. + * RID_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 RID_P= ASID))) { continue; } =20 @@ -2976,9 +2967,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 RID_PASID) = && vtd_as->pasid !=3D pasid) { continue; } --=20 2.47.1 From nobody Sat Nov 15 00:44:23 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=1758185987; cv=none; d=zohomail.com; s=zohoarc; b=IjlyVBrT/lhkAf4J6/MZk01GY0oHlU7o6Oy+mK6jEIb4BeM8k1kgCWDGu5eTqgm/4wIuJclPUVOeKUCJ5la44qmN0GYxSR0O2KL/xRbA3vaClCDof7eIHKgnEsoZNHnlX++7WnbLXy2DiOtbWmXUIoU/+rQ5iJrwZMJIvD1R3cU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1758185987; 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=DjXxdCnpkbhdPq0kvJw0mWscDF5IHDewWXUvKH3C4CY=; b=j6lCHmQZ0D+kv5zFtJ77eWqOu91icR35MHaYZQNGowA8O6yJafnDozxMNKPbLTDjVfrgT1zbaNCQfMgZCj/Pozmade7TILH/k4zQ4w8AZ+dd4KLNcAE69XDPB0tayPg9UB9Mg75U/IyBFiJ5YS3Bln3G542MjmBdQ9a6RFLIrEw= 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 1758185986832398.8545959171496; Thu, 18 Sep 2025 01:59:46 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uzATe-0000nK-T2; Thu, 18 Sep 2025 04:58:54 -0400 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 1uzATb-0000me-M2 for qemu-devel@nongnu.org; Thu, 18 Sep 2025 04:58:51 -0400 Received: from mgamail.intel.com ([192.198.163.8]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uzATW-0004j2-9K for qemu-devel@nongnu.org; Thu, 18 Sep 2025 04:58:51 -0400 Received: from fmviesa009.fm.intel.com ([10.60.135.149]) by fmvoesa102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Sep 2025 01:58:45 -0700 Received: from unknown (HELO gnr-sp-2s-612.sh.intel.com) ([10.112.230.229]) by fmviesa009-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Sep 2025 01:58:41 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1758185926; x=1789721926; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=AjbysD7Dw26jKG+WhlciddHluhE5wseNQ8YaGsUZaOo=; b=XCJjNOTuIUvzoDirDwBDIzvnvtUlzitxEjdaboxsoMgIE03CsmqouBXU uBYVtXljaXIX3tM/qDERI6oW7KJGPKvkmoMFPhuAGVLPlcUWHCpDct8S2 CMaTmdQOrbq9LKzckwhFJRlZnfn8VFs7gcw2xE74hkbCPNEQA+dRrAjyj g8OtdS8d8xEasuxK75ndyHycDA69Uy9h+JhRm0GndgKnCrM1IDiajiq5/ rT3T++QMswzOb+XiCUw79rAV8Lqyq5W7j+VwcSXx1LirncVS/Wf+Cgy8G W9gIamKfABF5+mZy2USjBwou7ZvDyod+vzJBLLbMuorY89RSy3X9cIg78 g==; X-CSE-ConnectionGUID: TVD56IH+RSykEb3AydPVdw== X-CSE-MsgGUID: Mq7LTj8qRGSo53gUmv3IiA== X-IronPort-AV: E=McAfee;i="6800,10657,11556"; a="78109401" X-IronPort-AV: E=Sophos;i="6.18,274,1751266800"; d="scan'208";a="78109401" X-CSE-ConnectionGUID: I4quVAwQSumRkOZzyAXCGw== X-CSE-MsgGUID: b8OkKJm5Szq2Kjqpy+Uo3w== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.18,274,1751266800"; d="scan'208";a="175930305" From: Zhenzhong Duan To: qemu-devel@nongnu.org Cc: alex.williamson@redhat.com, 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 v6 03/22] intel_iommu: Update terminology to match VTD spec Date: Thu, 18 Sep 2025 04:57:42 -0400 Message-ID: <20250918085803.796942-4-zhenzhong.duan@intel.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250918085803.796942-1-zhenzhong.duan@intel.com> References: <20250918085803.796942-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=192.198.163.8; 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_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_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: 1758185987724116600 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". 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 | 63 ++++----- include/hw/i386/intel_iommu.h | 2 +- hw/i386/intel_iommu.c | 240 +++++++++++++++++---------------- tests/qtest/intel-iommu-test.c | 4 +- 4 files changed, 156 insertions(+), 153 deletions(-) diff --git a/hw/i386/intel_iommu_internal.h b/hw/i386/intel_iommu_internal.h index 6abe76556a..86b8bfc71f 100644 --- a/hw/i386/intel_iommu_internal.h +++ b/hw/i386/intel_iommu_internal.h @@ -195,8 +195,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 */ @@ -210,7 +210,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) @@ -282,7 +282,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 */ @@ -290,7 +290,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, @@ -323,7 +324,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 */ @@ -445,23 +446,23 @@ typedef union VTDInvDesc VTDInvDesc; =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 @@ -535,7 +536,7 @@ typedef struct VTDRootEntry VTDRootEntry; #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) +#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 */ @@ -565,35 +566,35 @@ typedef struct VTDRootEntry VTDRootEntry; /* 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) +#define VTD_SM_PASID_ENTRY_FSPM 3ULL +#define VTD_SM_PASID_ENTRY_FSPTPTR (~0xfffULL) =20 /* 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) +#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) =20 /* Second Level Page Translation Pointer*/ -#define VTD_SM_PASID_ENTRY_SLPTPTR (~0xfffULL) +#define VTD_SM_PASID_ENTRY_SSPTPTR (~0xfffULL) =20 /* 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) +#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) =20 /* Common for both First Level and Second Level */ #define VTD_PML4_LEVEL 4 diff --git a/include/hw/i386/intel_iommu.h b/include/hw/i386/intel_iommu.h index e95477e855..564d4d4236 100644 --- a/include/hw/i386/intel_iommu.h +++ b/include/hw/i386/intel_iommu.h @@ -264,7 +264,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 b976b251bc..a47482ba9d 100644 --- a/hw/i386/intel_iommu.c +++ b/hw/i386/intel_iommu.c @@ -47,9 +47,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 /* @@ -319,7 +319,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 @@ -340,7 +340,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 @@ -747,9 +747,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) @@ -790,13 +790,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; } @@ -805,10 +805,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; @@ -880,13 +880,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 @@ -1007,7 +1007,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) @@ -1023,10 +1024,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 @@ -1095,7 +1096,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) { @@ -1114,14 +1115,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 /* @@ -1136,13 +1137,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); /* @@ -1152,46 +1153,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)) { @@ -1201,30 +1203,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 @@ -1350,7 +1352,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; @@ -1366,21 +1368,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 @@ -1389,12 +1391,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 { @@ -1411,7 +1413,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); @@ -1445,11 +1447,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); } @@ -1563,7 +1565,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, @@ -1670,10 +1672,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) @@ -1910,13 +1911,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); /* @@ -1926,23 +1927,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); @@ -1972,32 +1973,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 { @@ -2005,47 +2006,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 @@ -2199,14 +2200,14 @@ static bool vtd_do_iommu_translate(VTDAddressSpace = *vtd_as, PCIBus *bus, } } =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); @@ -2474,13 +2475,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 { @@ -2972,7 +2973,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); } } @@ -3818,7 +3819,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), @@ -4344,12 +4345,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 @@ -4535,7 +4537,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_MGAW(s->aw_bits); if (s->dma_drain) { s->cap |=3D VTD_CAP_DRAIN; @@ -4571,13 +4573,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) { @@ -4864,12 +4866,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", @@ -4877,7 +4879,7 @@ static bool vtd_decide_config(IntelIOMMUState *s, Err= or **errp) return false; } =20 - if (s->flts && s->aw_bits !=3D VTD_HOST_AW_48BIT) { + if (s->fsts && 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); 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 Sat Nov 15 00:44:23 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=1758186378; cv=none; d=zohomail.com; s=zohoarc; b=a9q2fyjSSR1xv5whnEeab+qjeaTzFMZ3RIVeIwKrM+tt2Ff86EsvkR88cRVkRRAtFR9s7qD1tEwXEXVWiLWt+3Nwd5HWYfSuHVP9OGAdRXPE4FQYdortluD4uZLpOI8bNIZrUPg6eh8KhfFkIzeFJdgkLwVzsUstN6K58SE/sy4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1758186378; 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=EBUALW2JRHONELMcTWncN5SrXl1+29i4kpFnvWiQKfg=; b=j8M2kOMedHZ2V0to74/t47SV+R+5WKte8AiHRhokn8QAy0WmOKyewhPTFv05kQ7pdZ+7EQcqX4Uik3SRAJ6N9hoceO/1nn9thLuugK2z/4xcQoF2qPTOVWYkGdCZ5vhFSPqGn7ItbDa1Z4cGJF7uwLEqGscEKMvGb9Rm4fOElCo= 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 1758186378794132.76151296910461; Thu, 18 Sep 2025 02:06:18 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uzAU0-0000zL-0r; Thu, 18 Sep 2025 04:59:16 -0400 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 1uzATf-0000nf-C5 for qemu-devel@nongnu.org; Thu, 18 Sep 2025 04:58:56 -0400 Received: from mgamail.intel.com ([192.198.163.8]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uzATb-0004jY-Vm for qemu-devel@nongnu.org; Thu, 18 Sep 2025 04:58:53 -0400 Received: from fmviesa009.fm.intel.com ([10.60.135.149]) by fmvoesa102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Sep 2025 01:58:49 -0700 Received: from unknown (HELO gnr-sp-2s-612.sh.intel.com) ([10.112.230.229]) by fmviesa009-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Sep 2025 01:58:45 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1758185932; x=1789721932; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=6jUjg5pnEKUCtmopQiEeK7RdE4CDjp9rACNAGirYJK0=; b=eHtJ0tvPY3bPaX4fffqeSLkn+EAdaBPBxoqwVVQhGu2iv8F9ucsktG+1 DqpvsNEJ6mjnzHJ+KmrjNeovv+bYIEDVOwdyWRpC4T0Ee7BBmQd6HR/vg 3QYkAw5wWmhZ8sfeoBbQBW/V7lCbi7gMaSid2IxO/xeaom/5z460Ri+mB B8AgYlv4pSyKWhsW5ynMbKKKMTD5/SLitKqUQ2KmWTrLz2ViysoeCmd7Z Hty0v/9Oz3+AzMIfFRMw5TFmNdm/91dZ1VpVqdndhKDGNHcaSkzaQ7H71 mfcolFeKwIr4cD0Y9f8A5mjPJZny+ceHvzDjH0Y20Olojywpv3d9gPE2J A==; X-CSE-ConnectionGUID: //Do5RJHTsexakM6wbwY/g== X-CSE-MsgGUID: vSRXZ+HYTd+wDkASf3BlVg== X-IronPort-AV: E=McAfee;i="6800,10657,11556"; a="78109416" X-IronPort-AV: E=Sophos;i="6.18,274,1751266800"; d="scan'208";a="78109416" X-CSE-ConnectionGUID: SDan467lTnu/59LbtCrbJA== X-CSE-MsgGUID: EKGYlsuBRmeDknjsqLY6MQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.18,274,1751266800"; d="scan'208";a="175930318" From: Zhenzhong Duan To: qemu-devel@nongnu.org Cc: alex.williamson@redhat.com, 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 v6 04/22] hw/pci: Export pci_device_get_iommu_bus_devfn() and return bool Date: Thu, 18 Sep 2025 04:57:43 -0400 Message-ID: <20250918085803.796942-5-zhenzhong.duan@intel.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250918085803.796942-1-zhenzhong.duan@intel.com> References: <20250918085803.796942-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=192.198.163.8; 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_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_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: 1758186380765116602 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 c3df9d6656..4d4b9dda4d 100644 --- a/hw/pci/pci.c +++ b/hw/pci/pci.c @@ -2860,20 +2860,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); @@ -2910,6 +2911,7 @@ static void pci_device_get_iommu_bus_devfn(PCIDevice = *dev, devfn =3D parent->devfn; bus =3D parent_bus; } + aliased =3D true; } =20 /* @@ -2944,6 +2946,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 Sat Nov 15 00:44:23 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=1758185967; cv=none; d=zohomail.com; s=zohoarc; b=k08odht2IIucun2ACZpxX1FoYWnuNwE9uEOxG4mtiyK6OSCbIChmvzr+8a/yxBDeqHYDd3M5hxPq2EzN9tQoIOTY3ZdnY48+ojmjdeuURnRv8mK3ya5zFNlPZAsz4s66K6Hi9Mgpcvhwc/SH8TtYw9U/HS6rUwUG84tJgh8klJw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1758185967; 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=xA93UhO+p5NW3ZL9xhPSIcbomQVmcxkuZCEMBbtKq00=; b=h0VkbrGTZsp5rHfy5v4UcjQ5MOXLpSMh215C8IqoUEgExzpoeZ8viLluzxJ45u5SEWOGrNVvy1cqIRfaFrX/2BOU1MLHXbwCNWj446D8D26cx+Z7SSriXbql4lyiFn6k14g6IQeQayMAW5uL3mFUTg767x9PJYMelrQMphOg53o= 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 1758185967623620.4886102575571; Thu, 18 Sep 2025 01:59:27 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uzAU1-000124-LA; Thu, 18 Sep 2025 04:59:18 -0400 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 1uzATi-0000oB-NP for qemu-devel@nongnu.org; Thu, 18 Sep 2025 04:59:00 -0400 Received: from mgamail.intel.com ([192.198.163.8]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uzATe-0004j2-7p for qemu-devel@nongnu.org; Thu, 18 Sep 2025 04:58:58 -0400 Received: from fmviesa009.fm.intel.com ([10.60.135.149]) by fmvoesa102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Sep 2025 01:58:53 -0700 Received: from unknown (HELO gnr-sp-2s-612.sh.intel.com) ([10.112.230.229]) by fmviesa009-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Sep 2025 01:58:49 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1758185934; x=1789721934; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=RSUOvermyX2pxpbuQCt08BT7UyyKZv3uKbqgB/W3tz0=; b=hz6yck21IEtkUjP5zX+F3+/uIey7dwYcMd8j+fWXOaEV19dE9sPT9Gp2 J6OGWku1u5I+G+W4vxXXvFe+hbOw41ef4q5xKKFduoCnuYb1RxXoCjrVg ByLuVCmnIpv/X0G93UMHBB6Oqow/z+M+Id7e3WEBpBh38X+W/Qx1cxRGm sAxc2r7+W1ufcyv3qrw20jXIX15hA7eVfpw0TVkeSBIU2FUK1Eay+7a96 4Z9Uqo3LheWzBUIvQX3tRqOGplmyQPNYHDLK7EIo1eydi78vmZRpHkCvi 346v8S7ngelS8lmnMs7sv/NspaMxbmB7Tlw50lln2Aas37hGBtuHvaHAw Q==; X-CSE-ConnectionGUID: ilhgy0VZRv6GnmAp2c01oQ== X-CSE-MsgGUID: mVI6ZF+iTyKaOVzm3CmL3g== X-IronPort-AV: E=McAfee;i="6800,10657,11556"; a="78109429" X-IronPort-AV: E=Sophos;i="6.18,274,1751266800"; d="scan'208";a="78109429" X-CSE-ConnectionGUID: 84t6334oRWuKZQntlKQM/A== X-CSE-MsgGUID: kjeVKNHoTteAStUj9tuLhA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.18,274,1751266800"; d="scan'208";a="175930332" From: Zhenzhong Duan To: qemu-devel@nongnu.org Cc: alex.williamson@redhat.com, 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 v6 05/22] hw/pci: Introduce pci_device_get_viommu_flags() Date: Thu, 18 Sep 2025 04:57:44 -0400 Message-ID: <20250918085803.796942-6-zhenzhong.duan@intel.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250918085803.796942-1-zhenzhong.duan@intel.com> References: <20250918085803.796942-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=192.198.163.8; 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_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_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: 1758185969643116600 Content-Type: text/plain; charset="utf-8" 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. 3. host IOMMU capabilities are passed to vIOMMU through set_iommu_device() interface which have to be after attach_device(), when get_viommu_flags() is called in attach_device(), there is no way for vIOMMU to get host IOMMU capabilities yet, so only pure vIOMMU flags can be returned. 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: Eric Auger Reviewed-by: Nicolin Chen Reviewed-by: Yi Liu --- MAINTAINERS | 1 + include/hw/iommu.h | 19 +++++++++++++++++++ include/hw/pci/pci.h | 27 +++++++++++++++++++++++++++ hw/pci/pci.c | 11 +++++++++++ 4 files changed, 58 insertions(+) create mode 100644 include/hw/iommu.h diff --git a/MAINTAINERS b/MAINTAINERS index f8cd513d8b..71457e4cde 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -2307,6 +2307,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..65d652950a --- /dev/null +++ b/include/hw/iommu.h @@ -0,0 +1,19 @@ +/* + * 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" + +enum { + /* Nesting parent HWPT will be reused by vIOMMU 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..c54f2b53ae 100644 --- a/include/hw/pci/pci.h +++ b/include/hw/pci/pci.h @@ -462,6 +462,23 @@ 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. Each flag can be + * an expectation or request to other sub-system or just a pure vIOMMU + * capability. vIOMMU can choose which flags to expose. + * + * @opaque: the data passed to pci_setup_iommu(). + * + * Returns: 64bit bitmap with each bit represents a flag that vIOMMU + * wants to expose. See VIOMMU_FLAG_* in include/hw/iommu.h for all + * possible flags currently used. These flags are theoretical which + * are only determined by vIOMMU device properties and independent on + * the actual host capabilities they may depend on. + */ + uint64_t (*get_viommu_flags)(void *opaque); /** * @get_iotlb_info: get properties required to initialize a device IOT= LB. * @@ -644,6 +661,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 a 64bit bitmap with each bit represents a vIOMMU exposed + * flags, 0 if vIOMMU doesn't support that. + * + * @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 4d4b9dda4d..1315ef13ea 100644 --- a/hw/pci/pci.c +++ b/hw/pci/pci.c @@ -3012,6 +3012,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 Sat Nov 15 00:44:23 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=1758186194; cv=none; d=zohomail.com; s=zohoarc; b=BuAexm3hUf0DN4CIiIoMtPQSa5j3Spu+fpb5Ar6jt24+AOcUKnQBsG4MiqNj1iULKZ3CCEi53DKJBWPQsOkadxgjFoTOlwnG+/YhfofjZop/mXigF8Ic7W2Da9BIG1bUK0kothgAe6iu+tHCnEUUA0zX2iia55Fxgv+nmDNa4ZI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1758186194; 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=3f/VSTM2n74828XlTViUiGBs3+PUXZ3hYA/vliOMZh4=; b=QDeAbHwWUzIXNxvPCjZ4dJbg62iXYFRYdI+mg9x/jXHWsZJMYKaKbeEs7vWmvtSKTeJkE5FeCLkVvgKWlSQT8w/wVlZS1G7zSz6ySr7nw/HxFyMHkVqOF7U0P7V4QdItTCeJKaXWqQKFYw5dzTDP3qDlNSvgkCIMJrSsuLANc00= 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 175818619485363.56340277359482; Thu, 18 Sep 2025 02:03:14 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uzATx-0000uh-8t; Thu, 18 Sep 2025 04:59:15 -0400 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 1uzATj-0000oN-TK for qemu-devel@nongnu.org; Thu, 18 Sep 2025 04:59:00 -0400 Received: from mgamail.intel.com ([192.198.163.8]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uzATh-0004jY-K4 for qemu-devel@nongnu.org; Thu, 18 Sep 2025 04:58:59 -0400 Received: from fmviesa009.fm.intel.com ([10.60.135.149]) by fmvoesa102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Sep 2025 01:58:56 -0700 Received: from unknown (HELO gnr-sp-2s-612.sh.intel.com) ([10.112.230.229]) by fmviesa009-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Sep 2025 01:58:53 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1758185937; x=1789721937; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=xVsvA3MC3rq5sMUut+s4X/8edtKB0p4xkhedzqHM/Dc=; b=DqHTGgwQyjeAMuNxK/4axJF9KNXUsaOyn6Sgx3o4H4SdYUEtNdT2TdZl dHA2TPTklCtfarK4vYrM4PUIgyjVoEUMyYXY6ig+HMpVxHQ3roKK1fOs/ 6yXTT+XZ0OCJBteaPgBxDHV04F9WIiJ8Dr5xU/cOHRmovngKsdGHiVkM3 HSHbCZcyQBN5HT668U6jPm7DMSFybTgssXwnel4fza4Oaao3HO2fCipKt 16783Op487jZHZPy992y3pnhQSS+xhBkwfrlvoy48roU6BUGHpV583ef5 B/mFWzpxRtsEGY4vVKTD+nTglNWIohc/2VbfFDl/TUEJ+qSkXellT5NCn w==; X-CSE-ConnectionGUID: NrjPa+3DQcGRjfUu5j85uQ== X-CSE-MsgGUID: XzxF7X4HT5Cw1JbqU11E4A== X-IronPort-AV: E=McAfee;i="6800,10657,11556"; a="78109442" X-IronPort-AV: E=Sophos;i="6.18,274,1751266800"; d="scan'208";a="78109442" X-CSE-ConnectionGUID: MSIbWrv1SdO0Po2syZVcqw== X-CSE-MsgGUID: iyoYgUN/Sm6onr/lZYDczw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.18,274,1751266800"; d="scan'208";a="175930339" From: Zhenzhong Duan To: qemu-devel@nongnu.org Cc: alex.williamson@redhat.com, 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 v6 06/22] intel_iommu: Implement get_viommu_flags() callback Date: Thu, 18 Sep 2025 04:57:45 -0400 Message-ID: <20250918085803.796942-7-zhenzhong.duan@intel.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250918085803.796942-1-zhenzhong.duan@intel.com> References: <20250918085803.796942-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=192.198.163.8; 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_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_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: 1758186196817116600 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 a47482ba9d..83c40975cc 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" @@ -4412,6 +4413,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 caps; + + caps =3D s->fsts ? VIOMMU_FLAG_WANT_NESTING_PARENT : 0; + + return caps; +} + /* Unmap the whole range in the notifier's scope. */ static void vtd_address_space_unmap(VTDAddressSpace *as, IOMMUNotifier *n) { @@ -4842,6 +4853,7 @@ static PCIIOMMUOps vtd_iommu_ops =3D { .register_iotlb_notifier =3D vtd_register_iotlb_notifier, .unregister_iotlb_notifier =3D vtd_unregister_iotlb_notifier, .ats_request_translation =3D vtd_ats_request_translation, + .get_viommu_flags =3D vtd_get_viommu_flags, }; =20 static bool vtd_decide_config(IntelIOMMUState *s, Error **errp) --=20 2.47.1 From nobody Sat Nov 15 00:44:23 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=1758186281; cv=none; d=zohomail.com; s=zohoarc; b=MNHj3nZiN0wi5OJudu86kqO+aJvhbXJMR7czWj2XdC9Fk5iPWCHZt0O+mP3yVpluvpKu5z5/6x/g6cyR/+VaopLdjBl4p5F1z9f8RotW+nynauHRwibr6lCOI8uLR/qMpQ1sjb6kqNxF3PrCJeT0VNHgMYSb/kTlYDlGYQezo3E= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1758186281; 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=uEjSWAxkbPH+5BAe6bsI23Ps5Fn6hxdT1gTZCE5BlvU=; b=CPtqwSQJXcjKMjrzmcEbIpCwwdNRqaVgN1+MdtQIWTf3LC3jYbjV2DXlSeuDsuMz9DSxNYs20GmQ5ZGmPhyzXPq/rGAMkrbyY7HodTfBRdmFFtJE2yVp4cfjFGfRIrNmCgg4iK+NOjivScPdmNuvarO6pA+7YEqQwE1vWKXNxIQ= 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 1758186281094466.06628739116957; Thu, 18 Sep 2025 02:04:41 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uzAU3-00011c-4t; Thu, 18 Sep 2025 04:59:19 -0400 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 1uzATp-0000uZ-If for qemu-devel@nongnu.org; Thu, 18 Sep 2025 04:59:10 -0400 Received: from mgamail.intel.com ([192.198.163.8]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uzATm-0004kl-Nw for qemu-devel@nongnu.org; Thu, 18 Sep 2025 04:59:04 -0400 Received: from fmviesa009.fm.intel.com ([10.60.135.149]) by fmvoesa102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Sep 2025 01:59:00 -0700 Received: from unknown (HELO gnr-sp-2s-612.sh.intel.com) ([10.112.230.229]) by fmviesa009-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Sep 2025 01:58:57 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1758185942; x=1789721942; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=3QbQwAvL99C3pcmh0zP/Z/wXhtsUFSfIes+PM1D7A18=; b=MEVIlOQGfgZ9kD60NrUPEyq/i/AALu50Aj5apsT8RrHVb0PTmbq1eMnG vmARZKwoO8vpvRpyusqwg5y5B+MbW2FlzQ5Qna7nBCRKPGwNsVEUfhWRg i03MSXyhW8QqTdLAjTv5o67hx/pc2EPZEQYk5cZDwTBa2ZBYcXk7ubx6i 1c/vZ5nrIwQsDgJS4txSwM/Y+xI4PtdH9Ij/i9f030PE2thYcS6wEcZSm ZbRl/kRnhfWSvD6Cqn7epZ2OKYElkXIcy0ZKawFVNlvmmOSzg3ZipbOgA YCXLwLyg6SNg1/AQRpDU5bvYAk0dPwhq6J6QTzXDyPWvG9ebfDvZrLYuk g==; X-CSE-ConnectionGUID: HYegYi0nSz6Xq372jTlXOg== X-CSE-MsgGUID: 7ipUqqzuS9+94cof8v4k2w== X-IronPort-AV: E=McAfee;i="6800,10657,11556"; a="78109455" X-IronPort-AV: E=Sophos;i="6.18,274,1751266800"; d="scan'208";a="78109455" X-CSE-ConnectionGUID: I/Fc8bB8SpmcztQnNWq3OQ== X-CSE-MsgGUID: f4wol+GLS2mxaxlB9tH/xA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.18,274,1751266800"; d="scan'208";a="175930346" From: Zhenzhong Duan To: qemu-devel@nongnu.org Cc: alex.williamson@redhat.com, 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 v6 07/22] intel_iommu: Introduce a new structure VTDHostIOMMUDevice Date: Thu, 18 Sep 2025 04:57:46 -0400 Message-ID: <20250918085803.796942-8-zhenzhong.duan@intel.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250918085803.796942-1-zhenzhong.duan@intel.com> References: <20250918085803.796942-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=192.198.163.8; 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_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_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: 1758186281837116600 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 86b8bfc71f..9cdc8d5dbb 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 @@ -608,4 +609,10 @@ typedef struct VTDRootEntry VTDRootEntry; /* 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 564d4d4236..3351892da0 100644 --- a/include/hw/i386/intel_iommu.h +++ b/include/hw/i386/intel_iommu.h @@ -295,7 +295,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 83c40975cc..ba40649c85 100644 --- a/hw/i386/intel_iommu.c +++ b/hw/i386/intel_iommu.c @@ -280,7 +280,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, @@ -4360,6 +4363,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, @@ -4376,7 +4380,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; } @@ -4386,7 +4397,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 Sat Nov 15 00:44:23 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=1758186136; cv=none; d=zohomail.com; s=zohoarc; b=XkcH36IcS5B67OVO73NYPgXOKKL2LjWdJA6JhOXV2RZEMnTUuQEhyZuAUJqZjUu5oXoTlo1baOcy1S0sK/So5yr3VejZUIfJErrFvp+/idAtPu89pulBx77WvepGSlu7ro3FoLirfJcQ6VjT6b+XrfNk1cDDavZYmbQfLEL+49s= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1758186136; 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=Q92aXSyuCXcsVd920AEv4K2xSZIpZx3ngX9yxZ70Gtc=; b=PdYjdbyysl/sNmaYjW7I33RJIOOdhFViPAUPwgyrHHDdC4KB/JQUdQBRyA2ol0GMX0GBG9gZiKGhNxN8RPpxeakznJ+YZ60GiSTWZTaPSv0u9L1jFOLSXtAoyhDciK8CzLTFzp17BeSom1hxGZ+486LP+oXHEoBwe6jqOkiqX4Y= 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 1758186136097721.4929296795079; Thu, 18 Sep 2025 02:02:16 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uzAU3-00019M-K0; Thu, 18 Sep 2025 04:59:19 -0400 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 1uzATu-0000x8-1o for qemu-devel@nongnu.org; Thu, 18 Sep 2025 04:59:13 -0400 Received: from mgamail.intel.com ([192.198.163.8]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uzATr-0004kl-AS for qemu-devel@nongnu.org; Thu, 18 Sep 2025 04:59:09 -0400 Received: from fmviesa009.fm.intel.com ([10.60.135.149]) by fmvoesa102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Sep 2025 01:59:04 -0700 Received: from unknown (HELO gnr-sp-2s-612.sh.intel.com) ([10.112.230.229]) by fmviesa009-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Sep 2025 01:59:01 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1758185947; x=1789721947; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=f4AXeDQrDSC8Bwx0WZxeYxfnR0oD0dSoUF+iu1iKyuA=; b=feeTmIT/t2Ou6k1XcAXNo7Z6GLj1q8u1elzUxxBP2pD+Kp8jM/JE47t2 EuDUhqWA1ss3OpHoAVTO5d+WFpba6+gM521ByDx6OsP9HGHPWXpo47IXN Q3O4UAoifH+KfgEBtfP8DSFgGEDjxBil2SQ3tEGHvxMgxdHB/wYWj4dGt /NpI0crfK3ot2+xp9Qfvv9HYFqBhfTQeOdd03M4NTOWPE3cCS57fW2blS f50iKLL5TsSCojiljRJbgvOYSXmO2P9JFUedq9aYdrtGxo9xqRJJaoofW 6OarzQvFeB4vHjFqs7k4bV/8WV6V+hIRPkx8UYLjgJ492Y+9aGXabbLF6 w==; X-CSE-ConnectionGUID: vtgTpkisSpCc+Sv/uJYJoQ== X-CSE-MsgGUID: TC0CZwyhTaiuk1rbKl+oug== X-IronPort-AV: E=McAfee;i="6800,10657,11556"; a="78109477" X-IronPort-AV: E=Sophos;i="6.18,274,1751266800"; d="scan'208";a="78109477" X-CSE-ConnectionGUID: u9qQ0tTBQGCxzc/l4Q6zfQ== X-CSE-MsgGUID: v4HWSAE6QMWoZDdKJodHkw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.18,274,1751266800"; d="scan'208";a="175930362" From: Zhenzhong Duan To: qemu-devel@nongnu.org Cc: alex.williamson@redhat.com, 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 v6 08/22] vfio/iommufd: Force creating nesting parent HWPT Date: Thu, 18 Sep 2025 04:57:47 -0400 Message-ID: <20250918085803.796942-9-zhenzhong.duan@intel.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250918085803.796942-1-zhenzhong.duan@intel.com> References: <20250918085803.796942-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=192.198.163.8; 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_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_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: 1758186138228116600 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 e7e6243e2d..a964091135 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= ainerBase *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 08f12ac31f..620cc78b77 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" @@ -504,6 +505,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(&vdev->parent_obj) & + VIOMMU_FLAG_WANT_NESTING_PARENT); + } + return false; +} + /* * Traditional ioctl() based io */ diff --git a/hw/vfio/iommufd.c b/hw/vfio/iommufd.c index 8c27222f75..f1684a39b7 100644 --- a/hw/vfio/iommufd.c +++ b/hw/vfio/iommufd.c @@ -379,6 +379,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 Sat Nov 15 00:44:23 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=1758186027; cv=none; d=zohomail.com; s=zohoarc; b=T3nEjMeXLUuxFKgeykXMZzbCd+qBfmSj8UHU3bSxfIcSGG3IxTfhWXIjbUXG5mgHzzosch9eSa1dKfUi78EzwtrMhYAj0pVV4yaxrSDvygDHXfk0qnYJElcBd2Wto5eKvNpRNCQKIXCs49bmc0iA7NPuZZ710+20t+686S3RpK8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1758186027; 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=E8gTPSflIVqAn7WeA2oywI1l9Nofui6KZpkIt3rwoJY=; b=WvK1BToSH7egrsxTRASYi3Un1+6jwRDZFoRm6qUckKWr4Au5eXlPVLdpESGdFgLSkIl8WmP6Qxg6NTiqyQoLtkmk5Apf4no8OoSSwnQZfxaOeOrvie2hxqqpGEGfNnn884a4INytt3JW4Jmqgf9ACs2/G39d4ySi7KcNUZVkcQw= 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 1758186027967478.3194750893657; Thu, 18 Sep 2025 02:00:27 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uzAUA-0001F5-9b; Thu, 18 Sep 2025 04:59:28 -0400 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 1uzATw-0000xQ-As for qemu-devel@nongnu.org; Thu, 18 Sep 2025 04:59:13 -0400 Received: from mgamail.intel.com ([192.198.163.8]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uzATu-0004kz-1z for qemu-devel@nongnu.org; Thu, 18 Sep 2025 04:59:12 -0400 Received: from fmviesa009.fm.intel.com ([10.60.135.149]) by fmvoesa102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Sep 2025 01:59:08 -0700 Received: from unknown (HELO gnr-sp-2s-612.sh.intel.com) ([10.112.230.229]) by fmviesa009-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Sep 2025 01:59:05 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1758185950; x=1789721950; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=p6gnyAA7xY2Xlvul8FV60Qy83JGL2sEDIdofNLNkPmk=; b=A8dD6PBTQMjHIv1raVI6V0x01HOS/6+YLLJkoc8jiT887o9CgSLoEs7K jRjZXLn1TK/JRGWouP+6R/IpCWlMZCeUR5v2Qy+TlINlXv2YjzH3nlorv Jl8rSayhX8nipKqMc6kAW8xuvrJvsAdyGkBQzLt5TdkW+2KwcwasX430x 7ZEKQqhj5ZYoh1wVZIipUu45fTOBSHiBzPLeYJR56fPcEAruYIb/YrxTJ uUUfCpVl8n6OE1ITsmWq8fLDf1KbufZNYlGpbH6HuikneV9RLeGtCm3/e UqBBBhr1ThmWtVQiZxPM02hIn07/4FDw53PDnoEMhiX/LcwHwl+izrkpN w==; X-CSE-ConnectionGUID: yCnvafGxQ2+txK5TIEXXOA== X-CSE-MsgGUID: gxSOos0jS4qfzJFSKLY6lA== X-IronPort-AV: E=McAfee;i="6800,10657,11556"; a="78109498" X-IronPort-AV: E=Sophos;i="6.18,274,1751266800"; d="scan'208";a="78109498" X-CSE-ConnectionGUID: jiPy0jKJSUezm+3S7eIsTg== X-CSE-MsgGUID: BjxqV/ZjSjiYvQJalyad4g== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.18,274,1751266800"; d="scan'208";a="175930369" From: Zhenzhong Duan To: qemu-devel@nongnu.org Cc: alex.williamson@redhat.com, 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 v6 09/22] intel_iommu: Stick to system MR for IOMMUFD backed host device when x-fls=on Date: Thu, 18 Sep 2025 04:57:48 -0400 Message-ID: <20250918085803.796942-10-zhenzhong.duan@intel.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250918085803.796942-1-zhenzhong.duan@intel.com> References: <20250918085803.796942-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=192.198.163.8; 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_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_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: 1758186031298116600 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. Suggested-by: Yi Liu Signed-off-by: Zhenzhong Duan Reviewed-by: Eric Auger Reviewed-by: Yi Liu --- hw/i386/intel_iommu.c | 37 +++++++++++++++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) diff --git a/hw/i386/intel_iommu.c b/hw/i386/intel_iommu.c index ba40649c85..bd80de1670 100644 --- a/hw/i386/intel_iommu.c +++ b/hw/i386/intel_iommu.c @@ -40,6 +40,7 @@ #include "kvm/kvm_i386.h" #include "migration/vmstate.h" #include "trace.h" +#include "system/iommufd.h" =20 /* context entry operations */ #define RID_PASID 0 @@ -1702,6 +1703,24 @@ static bool vtd_dev_pt_enabled(IntelIOMMUState *s, V= TDContextEntry *ce, =20 } =20 +static 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; +} + static bool vtd_as_pt_enabled(VTDAddressSpace *as) { IntelIOMMUState *s; @@ -1710,6 +1729,7 @@ static bool vtd_as_pt_enabled(VTDAddressSpace *as) assert(as); =20 s =3D as->iommu_state; + if (vtd_dev_to_context_entry(s, pci_bus_num(as->bus), as->devfn, &ce)) { /* @@ -1727,12 +1747,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 setup 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 + * fallback 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), --=20 2.47.1 From nobody Sat Nov 15 00:44:23 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=1758186027; cv=none; d=zohomail.com; s=zohoarc; b=DNaDPA6ohVBoxH44103ZYCIcXt8GjleYXY+hpx5+VGaxpyZsVaJtJVTsENdFFYwmtCJJOByfifRBZYQerp3FTSe93CL+0qZXxqAvabnaaqpsZQ4WtXIRmqPH5+4Oh3TQ3OpnoQuVxOtvgDFcqnNaD7N4hA4kRhBbdu3OGQ2XTqw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1758186027; 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=NJhkjEwLTTutmbt2f+ZfNbC/nF/sOTt/I5iecWFS8tM=; b=J8WYDRF/aqIB9/5c5tFFvOZw377l5HAb76jQCDFLUu1b0YPbpPUhQFyIdzCxhTmPltUXqivN8MhFP7BKM/fuC7OQpyypJYyt92fnrobKNdDSWSceW3QcNC42SY7N1CLuXXm8ykYPP/JV9GOOPeDc6TUCujWdWwDs5UhTy4NdEMU= 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 1758186027237537.3218950197711; Thu, 18 Sep 2025 02:00:27 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uzAUJ-0001cD-68; Thu, 18 Sep 2025 04:59:35 -0400 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 1uzAU2-00017B-LL for qemu-devel@nongnu.org; Thu, 18 Sep 2025 04:59:19 -0400 Received: from mgamail.intel.com ([192.198.163.8]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uzATx-0004kl-7e for qemu-devel@nongnu.org; Thu, 18 Sep 2025 04:59:18 -0400 Received: from fmviesa009.fm.intel.com ([10.60.135.149]) by fmvoesa102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Sep 2025 01:59:12 -0700 Received: from unknown (HELO gnr-sp-2s-612.sh.intel.com) ([10.112.230.229]) by fmviesa009-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Sep 2025 01:59:08 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1758185953; x=1789721953; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=SZXvV/kffXuNSmJDYHgXrcVKjLklIAxay4lFrlvpW+k=; b=gJjGfYpHmgCL664opcv/2qmgZL/rES6BkSpRgcSWXFFrjJLKWAneFH29 ILiyV4uwn9I8Sl4tjdnur2XMxwd7BCVRMfe9v+DZiy2JPMdvd+qNpxWaD GShwnpypb2aKtB8ArtWUojDLWeyCAXfTZNtlCh5uxn5F+xaGrFcUIvG8Q KXjAJb4Cs36P4bpSSp6V7eT5JviEXyIofDHN3XmB74FiYPniApWNQN8zH SbhSE6lGpdaSe6+w2IL0i/BAhvPuOeOebVYEeIXm3fI8dZjtBLy7zk4B7 rlp79jjrEVr5x7iGmdw6MoE+juvGB19YDXiSpX1ZaNxrUpoZygVyYWiWb A==; X-CSE-ConnectionGUID: A7cphAKASVuk5wda3IJEog== X-CSE-MsgGUID: oG/4YiQbQaycMsuTzyNWEA== X-IronPort-AV: E=McAfee;i="6800,10657,11556"; a="78109507" X-IronPort-AV: E=Sophos;i="6.18,274,1751266800"; d="scan'208";a="78109507" X-CSE-ConnectionGUID: ub4nWxu/SsKO8uChZt2//Q== X-CSE-MsgGUID: XxXUJboFRcebCkvPIRhEBg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.18,274,1751266800"; d="scan'208";a="175930378" From: Zhenzhong Duan To: qemu-devel@nongnu.org Cc: alex.williamson@redhat.com, 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 v6 10/22] intel_iommu: Check for compatibility with IOMMUFD backed device when x-flts=on Date: Thu, 18 Sep 2025 04:57:49 -0400 Message-ID: <20250918085803.796942-11-zhenzhong.duan@intel.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250918085803.796942-1-zhenzhong.duan@intel.com> References: <20250918085803.796942-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=192.198.163.8; 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_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_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: 1758186028406116600 Content-Type: text/plain; charset="utf-8" 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. Reviewed-by: Yi Liu Signed-off-by: Zhenzhong Duan Reviewed-by: Eric Auger --- hw/i386/intel_iommu.c | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/hw/i386/intel_iommu.c b/hw/i386/intel_iommu.c index bd80de1670..bcfbc5dd46 100644 --- a/hw/i386/intel_iommu.c +++ b/hw/i386/intel_iommu.c @@ -4387,8 +4387,31 @@ static bool vtd_check_hiod(IntelIOMMUState *s, HostI= OMMUDevice *hiod, return true; } =20 +#ifdef CONFIG_IOMMUFD + struct HostIOMMUDeviceCaps *caps =3D &hiod->caps; + struct iommu_hw_info_vtd *vtd =3D &caps->vendor_caps.vtd; + + /* Remaining checks are all first stage translation specific */ + 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; + } +#endif + error_setg(errp, - "host device is uncompatible with first stage translation"); + "host IOMMU is incompatible with guest first stage translat= ion"); return false; } =20 --=20 2.47.1 From nobody Sat Nov 15 00:44:23 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=1758186036; cv=none; d=zohomail.com; s=zohoarc; b=g6uwaFet9lJNVWM2DRgB0KN1Oz6gQdm5F/7qpyUeV/+mXwu+p1qeS/9CjQt167SGxN+l9j6drq+N3JnfvZTP7PSgsJ3r9+mSaQ9GFEFgsYuJzYurxmKivvn9CgV5WTVjWmi62YO2RqF4xUMfJ50bhLU6Vxk/PZwwO5AivGcYZM8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1758186036; 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=Kzpmz2+zI/tTT1FPjs4hGVFmuHYMKv4vS/tilOpSZNE=; b=JzAJNisNW+AlW6yDgrTAtM1pj+MsKlQTV9QlZwHLpjziKU84duAE+KY0lQPB3kJcTmMnGkxjR/fAROJqpdjG68qJd19sLOnY353pqFGzRZ0HPspC/ddR+uihlnwyehEiVWzvIfrZKcQLkCgYpuK6sU2QEEUC/n5n16uoY5gmu+M= 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 1758186036737418.66751454780456; Thu, 18 Sep 2025 02:00:36 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uzAUH-0001JA-TC; Thu, 18 Sep 2025 04:59:34 -0400 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 1uzAU4-0001DE-Oc for qemu-devel@nongnu.org; Thu, 18 Sep 2025 04:59:22 -0400 Received: from mgamail.intel.com ([192.198.163.8]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uzAU1-0004kz-Ug for qemu-devel@nongnu.org; Thu, 18 Sep 2025 04:59:20 -0400 Received: from fmviesa009.fm.intel.com ([10.60.135.149]) by fmvoesa102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Sep 2025 01:59:15 -0700 Received: from unknown (HELO gnr-sp-2s-612.sh.intel.com) ([10.112.230.229]) by fmviesa009-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Sep 2025 01:59:12 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1758185958; x=1789721958; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=2PvmskHophFjbn8eBqcZk0VTV4e4kRaI3iZVHHG9JsY=; b=TL5JRz/mr5yOEzw7DbZ3mC9KuU1X+1e9hH2/e9K/au/ByFp5CC4i+my3 2dKchPHc/5yNyWHv55WrszH9kd2IZYFw19lFgbBzFXDyFdNIG9RkGWvRj LrXBW9yvT2160MQXvOpVlmBWlIYZlZVAXRQr97Efx6+pHA1NJXcAF3O1Z 0EYLrR+Ve/S2qyAyHzfwWOdq258KlUK9wKolH3tEewo835XJQ4q6VXsFQ jvAHT93AdjtYZotqR1HMNBazYXHU9i9GEO2Ak904Q5zeu61L+SeSMPRkV cEt8UYvr/TF69bI280tRGxcawzrLp4boL2tAqzZk3P+3xnRKhq8+SEdbk Q==; X-CSE-ConnectionGUID: INM49y0+SvqTimgCS5KlZQ== X-CSE-MsgGUID: hpOJ1qfuQsS1iVcpF+ADyg== X-IronPort-AV: E=McAfee;i="6800,10657,11556"; a="78109516" X-IronPort-AV: E=Sophos;i="6.18,274,1751266800"; d="scan'208";a="78109516" X-CSE-ConnectionGUID: NJcRnZQuQU+fArgn/260aA== X-CSE-MsgGUID: BR1RQNbSTBCfIaRWFaK+DA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.18,274,1751266800"; d="scan'208";a="175930384" From: Zhenzhong Duan To: qemu-devel@nongnu.org Cc: alex.williamson@redhat.com, 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 v6 11/22] intel_iommu: Fail passthrough device under PCI bridge if x-flts=on Date: Thu, 18 Sep 2025 04:57:50 -0400 Message-ID: <20250918085803.796942-12-zhenzhong.duan@intel.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250918085803.796942-1-zhenzhong.duan@intel.com> References: <20250918085803.796942-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=192.198.163.8; 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_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_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: 1758186038843116600 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 Reviewed-by: Yi Liu --- hw/i386/intel_iommu.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/hw/i386/intel_iommu.c b/hw/i386/intel_iommu.c index bcfbc5dd46..d37d47115a 100644 --- a/hw/i386/intel_iommu.c +++ b/hw/i386/intel_iommu.c @@ -4361,9 +4361,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 @@ -4390,6 +4391,8 @@ static bool vtd_check_hiod(IntelIOMMUState *s, HostIO= MMUDevice *hiod, #ifdef CONFIG_IOMMUFD 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 /* Remaining checks are all first stage translation specific */ if (!object_dynamic_cast(OBJECT(hiod), TYPE_HOST_IOMMU_DEVICE_IOMMUFD)= ) { @@ -4408,6 +4411,12 @@ static bool vtd_check_hiod(IntelIOMMUState *s, HostI= OMMUDevice *hiod, "First stage 1GB large page is unsupported by host IOMM= U"); return false; } + + if (pci_device_get_iommu_bus_devfn(pdev, &bus, NULL, NULL)) { + error_setg(errp, "Host device under PCI bridge is unsupported " + "when x-flts=3Don"); + return false; + } #endif =20 error_setg(errp, @@ -4442,7 +4451,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; --=20 2.47.1 From nobody Sat Nov 15 00:44:23 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=1758186319; cv=none; d=zohomail.com; s=zohoarc; b=AZE9VYPYiyph40Xaq87TFad2pDPMz1mAVc00oWG6yKYdx7cEpd8Jzr9Ih+euOXiMkHMB/JBA5pZkRWrmklkz5tWyp7wi/xqeaL1oeLgNYUpfw0eGDDoWeFyQBUPYLygyVCg/zxSmyBijjdw80Ak8XFrdCajyUmj/2Bnn/trM1vQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1758186319; 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=uE1/p0Vw3d1YqyWVThxwUIqVUCEmpHYgvYZELn2Rn2k=; b=OM2KFPghOwniRNVHiMbApvSxPXM1D8/YyiLWRv6Nu1uEsVLWfkWDl4cCLD9qGNIcKBPfE2sTVznTNC9MpP3cwFkXA7czo1wEXu2oAlwFwyZNIRhmktLl45UgQ1U1yUPMBO60i5ckBkJEwgHKdlSXLVIJwf2dajrHntvuBr8Qdr8= 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 1758186319664153.24457022192814; Thu, 18 Sep 2025 02:05:19 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uzAUM-0001nq-Ph; Thu, 18 Sep 2025 04:59:39 -0400 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 1uzAU8-0001Fa-Px for qemu-devel@nongnu.org; Thu, 18 Sep 2025 04:59:24 -0400 Received: from mgamail.intel.com ([192.198.163.8]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uzAU4-0004kl-LZ for qemu-devel@nongnu.org; Thu, 18 Sep 2025 04:59:24 -0400 Received: from fmviesa009.fm.intel.com ([10.60.135.149]) by fmvoesa102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Sep 2025 01:59:19 -0700 Received: from unknown (HELO gnr-sp-2s-612.sh.intel.com) ([10.112.230.229]) by fmviesa009-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Sep 2025 01:59:16 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1758185960; x=1789721960; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=yQiKzhGBfK8VyD3v53IITrSdxMzYeGm4fZs4KxzhbZU=; b=YDGWk1ZerS4vH7HkUXXWSlqB26tlrSN6Jc+qBLOwBn65F5gUp2//J4Gn 0bBROD7zBGQlcAYde3EZmc1R3EUJ/MmiSv5ViFp2ec667msQJfQvWgaYs SiOKIOJEXMuoqGYsQYjj0WjY9fYiN20jZZN1SSdIVu3hIIM7ptx7FfKW1 KsPWgjcfRlpMvF6pG8vhSgUUZcgzIXpihtiPBQfhnF4MaE88CqRR1e/1M kWXtOkVOv5CnC88Es3C8KzozJUwW5hrF/D9CXxWTQk5yd9mtOWsFipQBx YQRemJBiP3ECqffOcapAGkLuj0OylFFky+0XCpLbIVlh3jPhwwkuS3z71 g==; X-CSE-ConnectionGUID: Rm0C3Fc0TSO6xmP8Q3nkSQ== X-CSE-MsgGUID: x2+iXNFNSMG36ZBAlLrpnw== X-IronPort-AV: E=McAfee;i="6800,10657,11556"; a="78109524" X-IronPort-AV: E=Sophos;i="6.18,274,1751266800"; d="scan'208";a="78109524" X-CSE-ConnectionGUID: NB2D5vfuSp+QLhl3Y+66zA== X-CSE-MsgGUID: c7ZzSddASy20KxQTPKIm1Q== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.18,274,1751266800"; d="scan'208";a="175930394" From: Zhenzhong Duan To: qemu-devel@nongnu.org Cc: alex.williamson@redhat.com, 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 v6 12/22] intel_iommu: Handle PASID cache invalidation Date: Thu, 18 Sep 2025 04:57:51 -0400 Message-ID: <20250918085803.796942-13-zhenzhong.duan@intel.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250918085803.796942-1-zhenzhong.duan@intel.com> References: <20250918085803.796942-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=192.198.163.8; 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_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_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: 1758186320033116600 Content-Type: text/plain; charset="utf-8" This adds PASID cache sync for RID_PASID, non-RID_PASID isn't supported. Adds an new entry VTDPASIDCacheEntry in VTDAddressSpace to cache the pasid entry and track PASID usage and future PASID tagged DMA address translation support in vIOMMU. When guest triggers pasid cache invalidation, QEMU will capture it and update or invalidate pasid cache. vIOMMU emulator could figure out the reason by fetching latest guest pasid entry in memory and compare it with cached PASID entry if it's valid. Signed-off-by: Yi Liu Signed-off-by: Zhenzhong Duan --- hw/i386/intel_iommu_internal.h | 19 +++- include/hw/i386/intel_iommu.h | 6 ++ hw/i386/intel_iommu.c | 157 ++++++++++++++++++++++++++++++--- hw/i386/trace-events | 3 + 4 files changed, 173 insertions(+), 12 deletions(-) diff --git a/hw/i386/intel_iommu_internal.h b/hw/i386/intel_iommu_internal.h index 9cdc8d5dbb..d400bcee21 100644 --- a/hw/i386/intel_iommu_internal.h +++ b/hw/i386/intel_iommu_internal.h @@ -316,6 +316,7 @@ typedef enum VTDFaultReason { * request while disabled */ VTD_FR_IR_SID_ERR =3D 0x26, /* Invalid Source-ID */ =20 + VTD_FR_RTADDR_INV_TTM =3D 0x31, /* Invalid TTM in RTADDR */ /* PASID directory entry access failure */ VTD_FR_PASID_DIR_ACCESS_ERR =3D 0x50, /* The Present(P) field of pasid directory entry is 0 */ @@ -493,6 +494,15 @@ typedef union VTDInvDesc VTDInvDesc; #define VTD_INV_DESC_PIOTLB_RSVD_VAL0 0xfff000000000f1c0ULL #define VTD_INV_DESC_PIOTLB_RSVD_VAL1 0xf80ULL =20 +/* PASID-cache Invalidate Descriptor (pc_inv_dsc) fields */ +#define VTD_INV_DESC_PASIDC_G(x) extract64((x)->val[0], 4, 2) +#define VTD_INV_DESC_PASIDC_G_DSI 0 +#define VTD_INV_DESC_PASIDC_G_PASID_SI 1 +#define VTD_INV_DESC_PASIDC_G_GLOBAL 3 +#define VTD_INV_DESC_PASIDC_DID(x) extract64((x)->val[0], 16, 16) +#define VTD_INV_DESC_PASIDC_PASID(x) extract64((x)->val[0], 32, 20) +#define VTD_INV_DESC_PASIDC_RSVD_VAL0 0xfff000000000f1c0ULL + /* Information about page-selective IOTLB invalidate */ struct VTDIOTLBPageInvInfo { uint16_t domain_id; @@ -552,6 +562,13 @@ typedef struct VTDRootEntry VTDRootEntry; #define VTD_SM_CONTEXT_ENTRY_RSVD_VAL0(aw) (0x1e0ULL | ~VTD_HAW_MASK(aw)) #define VTD_SM_CONTEXT_ENTRY_RSVD_VAL1 0xffffffffffe00000ULL =20 +typedef struct VTDPASIDCacheInfo { + uint8_t type; + uint16_t did; + uint32_t pasid; + bool reset; +} VTDPASIDCacheInfo; + /* PASID Table Related Definitions */ #define VTD_PASID_DIR_BASE_ADDR_MASK (~0xfffULL) #define VTD_PASID_TABLE_BASE_ADDR_MASK (~0xfffULL) @@ -573,7 +590,7 @@ typedef struct VTDRootEntry VTDRootEntry; #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) +#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) diff --git a/include/hw/i386/intel_iommu.h b/include/hw/i386/intel_iommu.h index 3351892da0..ff01e5c82d 100644 --- a/include/hw/i386/intel_iommu.h +++ b/include/hw/i386/intel_iommu.h @@ -95,6 +95,11 @@ struct VTDPASIDEntry { uint64_t val[8]; }; =20 +typedef struct VTDPASIDCacheEntry { + struct VTDPASIDEntry pasid_entry; + bool valid; +} VTDPASIDCacheEntry; + struct VTDAddressSpace { PCIBus *bus; uint8_t devfn; @@ -107,6 +112,7 @@ struct VTDAddressSpace { MemoryRegion iommu_ir_fault; /* Interrupt region for catching fault */ IntelIOMMUState *iommu_state; VTDContextCacheEntry context_cache_entry; + VTDPASIDCacheEntry pasid_cache_entry; QLIST_ENTRY(VTDAddressSpace) next; /* Superset of notifier flags that this address space has */ IOMMUNotifierFlag notifier_flags; diff --git a/hw/i386/intel_iommu.c b/hw/i386/intel_iommu.c index d37d47115a..24061f6dc6 100644 --- a/hw/i386/intel_iommu.c +++ b/hw/i386/intel_iommu.c @@ -1614,7 +1614,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); @@ -3074,6 +3074,144 @@ static bool vtd_process_piotlb_desc(IntelIOMMUState= *s, return true; } =20 +static inline int vtd_dev_get_pe_from_pasid(VTDAddressSpace *vtd_as, + VTDPASIDEntry *pe) +{ + IntelIOMMUState *s =3D vtd_as->iommu_state; + VTDContextEntry ce; + int ret; + + if (!s->root_scalable) { + return -VTD_FR_RTADDR_INV_TTM; + } + + ret =3D vtd_dev_to_context_entry(s, pci_bus_num(vtd_as->bus), vtd_as->= devfn, + &ce); + if (ret) { + return ret; + } + + return vtd_ce_get_pasid_entry(s, &ce, pe, vtd_as->pasid); +} + +/* + * For each IOMMUFD backed device, update or invalidate pasid cache based = on + * the value in memory. + */ +static void vtd_pasid_cache_sync_locked(gpointer key, gpointer value, + gpointer user_data) +{ + VTDPASIDCacheInfo *pc_info =3D user_data; + VTDAddressSpace *vtd_as =3D value; + VTDPASIDCacheEntry *pc_entry =3D &vtd_as->pasid_cache_entry; + VTDPASIDEntry pe; + uint16_t did; + + /* Ignore emulated device or legacy VFIO backed device */ + if (!vtd_find_hiod_iommufd(vtd_as)) { + return; + } + + /* non-RID_PASID isn't supported yet */ + assert(vtd_as->pasid =3D=3D PCI_NO_PASID); + + if (vtd_dev_get_pe_from_pasid(vtd_as, &pe)) { + /* + * No valid pasid entry in guest memory. e.g. pasid entry was modi= fied + * to be either all-zero or non-present. Either case means existing + * pasid cache should be invalidated. + */ + pc_entry->valid =3D false; + return; + } + + /* + * VTD_INV_DESC_PASIDC_G_DSI and VTD_INV_DESC_PASIDC_G_PASID_SI require + * DID check. If DID doesn't match the value in cache or memory, then + * it's not a pasid entry we want to invalidate. + */ + switch (pc_info->type) { + case VTD_INV_DESC_PASIDC_G_PASID_SI: + case VTD_INV_DESC_PASIDC_G_DSI: + if (pc_entry->valid) { + did =3D VTD_SM_PASID_ENTRY_DID(&pc_entry->pasid_entry); + if (pc_info->did =3D=3D did) { + break; + } + } + did =3D VTD_SM_PASID_ENTRY_DID(&pe); + if (pc_info->did =3D=3D did) { + break; + } + return; + } + + pc_entry->pasid_entry =3D pe; + pc_entry->valid =3D true; +} + +static void vtd_pasid_cache_sync(IntelIOMMUState *s, VTDPASIDCacheInfo *pc= _info) +{ + if (!s->fsts || !s->root_scalable || !s->dmar_enabled) { + return; + } + + vtd_iommu_lock(s); + g_hash_table_foreach(s->vtd_address_spaces, vtd_pasid_cache_sync_locke= d, + pc_info); + vtd_iommu_unlock(s); +} + +static bool vtd_process_pasid_desc(IntelIOMMUState *s, + VTDInvDesc *inv_desc) +{ + uint16_t did; + uint32_t pasid; + VTDPASIDCacheInfo pc_info =3D {}; + uint64_t mask[4] =3D {VTD_INV_DESC_PASIDC_RSVD_VAL0, VTD_INV_DESC_ALL_= ONE, + VTD_INV_DESC_ALL_ONE, VTD_INV_DESC_ALL_ONE}; + + if (!vtd_inv_desc_reserved_check(s, inv_desc, mask, true, + __func__, "pasid cache inv")) { + return false; + } + + did =3D VTD_INV_DESC_PASIDC_DID(inv_desc); + pasid =3D VTD_INV_DESC_PASIDC_PASID(inv_desc); + pc_info.type =3D VTD_INV_DESC_PASIDC_G(inv_desc); + + switch (pc_info.type) { + case VTD_INV_DESC_PASIDC_G_DSI: + trace_vtd_inv_desc_pasid_cache_dsi(did); + pc_info.did =3D did; + break; + + case VTD_INV_DESC_PASIDC_G_PASID_SI: + /* PASID selective implies a DID selective */ + trace_vtd_inv_desc_pasid_cache_psi(did, pasid); + /* Currently non-RID_PASID invalidation requests are ignored */ + if (pasid !=3D RID_PASID) { + return true; + } + pc_info.did =3D did; + pc_info.pasid =3D pasid; + break; + + case VTD_INV_DESC_PASIDC_G_GLOBAL: + trace_vtd_inv_desc_pasid_cache_gsi(); + break; + + default: + error_report_once("invalid granularity field in PASID-cache invali= date " + "descriptor, hi: 0x%"PRIx64" lo: 0x%" PRIx64, + inv_desc->val[1], inv_desc->val[0]); + return false; + } + + vtd_pasid_cache_sync(s, &pc_info); + return true; +} + static bool vtd_process_inv_iec_desc(IntelIOMMUState *s, VTDInvDesc *inv_desc) { @@ -3236,6 +3374,13 @@ static bool vtd_process_inv_desc(IntelIOMMUState *s) } break; =20 + case VTD_INV_DESC_PC: + trace_vtd_inv_desc("pasid-cache", inv_desc.val[1], inv_desc.val[0]= ); + if (!vtd_process_pasid_desc(s, &inv_desc)) { + return false; + } + break; + case VTD_INV_DESC_PIOTLB: trace_vtd_inv_desc("p-iotlb", inv_desc.val[1], inv_desc.val[0]); if (!vtd_process_piotlb_desc(s, &inv_desc)) { @@ -3271,16 +3416,6 @@ static bool vtd_process_inv_desc(IntelIOMMUState *s) } break; =20 - /* - * TODO: the entity of below two cases will be implemented in future s= eries. - * To make guest (which integrates scalable mode support patch set in - * iommu driver) work, just return true is enough so far. - */ - case VTD_INV_DESC_PC: - if (s->scalable_mode) { - break; - } - /* fallthrough */ default: error_report_once("%s: invalid inv desc: hi=3D%"PRIx64", lo=3D%"PR= Ix64 " (unknown type)", __func__, inv_desc.hi, diff --git a/hw/i386/trace-events b/hw/i386/trace-events index ac9e1a10aa..298addb24d 100644 --- a/hw/i386/trace-events +++ b/hw/i386/trace-events @@ -24,6 +24,9 @@ vtd_inv_qi_head(uint16_t head) "read head %d" vtd_inv_qi_tail(uint16_t head) "write tail %d" vtd_inv_qi_fetch(void) "" vtd_context_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_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 Sat Nov 15 00:44:23 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=1758186166; cv=none; d=zohomail.com; s=zohoarc; b=PUYbPPesuchNZI9IQz/IURq5Kd9/y2Flh17xm7eg6FdBc0q1qp6EteyjT4Xhe/i533hW9egslUTzsT5JvZ9Tfovy9VlxpJqjayC8h5XtAsGrbe67PzBtKXUETZZiHav7skh+qCeR0wf11lcVMcZz1O3uMB3rK7DvF0T5UcNYoqM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1758186166; 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=SHqRY82vkH9LVHU7SsCcac8bTy4YB4fQDR5gniSwG+c=; b=KbXiR4touw9PfjpAk8h+/66awq8VzC1XFYhWKzPrHifUAIZK3PJvQbHbQF1SKNI0JakfkPBmvIQ7q5LQ5qTFX2HmaPknxou/H+ZTzIRH6033kCMPuqwtb6KIssJik4PHiivFOkv3HDxR622lP11ps5aw7AS6eCc1EZUGZj9j9vM= 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 1758186166231173.19246239006998; Thu, 18 Sep 2025 02:02:46 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uzAUP-000255-Di; Thu, 18 Sep 2025 04:59:41 -0400 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 1uzAUC-0001La-Rf for qemu-devel@nongnu.org; Thu, 18 Sep 2025 04:59:32 -0400 Received: from mgamail.intel.com ([192.198.163.8]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uzAU8-0004kz-LY for qemu-devel@nongnu.org; Thu, 18 Sep 2025 04:59:28 -0400 Received: from fmviesa009.fm.intel.com ([10.60.135.149]) by fmvoesa102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Sep 2025 01:59:23 -0700 Received: from unknown (HELO gnr-sp-2s-612.sh.intel.com) ([10.112.230.229]) by fmviesa009-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Sep 2025 01:59:20 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1758185964; x=1789721964; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=TZ/XrRR3DKUlpIzh8dBEtMUg4bYv8S7lSa4qI7C8fnw=; b=Uz1P+6d8eb8EWA2NNiGqmJJjKDMGFZe2ITqOQj98Ayg7T1SjDvwVBQEO N3Q7brapOO/FH7xsC+sVAmgEymqeGQmfHFb18PUK4ewT4FrswhB5W/hML pjvRsAUmZgOlpIi/reg6N0BfzSdxBC5Wypnl3vFj6asyVxk6Hrh81WhfM WV0Zf5R7JyIYSx8efe/aInRaJF73PPS1c/UnwrYZzSxeT6vOyzLuStEyh nidABKHRWZzITqmyGHHscUbTbw/+7tHZX3WZObaFgggIq0QZko2pVh2Y9 nR+rbA99eM5onk6F/uR2Ivg2R0xjGdpNOAFhlYNA8ToDSwnBVuDa5TxPe w==; X-CSE-ConnectionGUID: Fy18S3pzR4WEsZx4HOYDBw== X-CSE-MsgGUID: OvGyqdqvSQeidTcgVW6v6w== X-IronPort-AV: E=McAfee;i="6800,10657,11556"; a="78109530" X-IronPort-AV: E=Sophos;i="6.18,274,1751266800"; d="scan'208";a="78109530" X-CSE-ConnectionGUID: 8wPEaro/TSWBz5oM8Gb5kg== X-CSE-MsgGUID: 3dnRDlFSSxeUscqQNxSYYw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.18,274,1751266800"; d="scan'208";a="175930412" From: Zhenzhong Duan To: qemu-devel@nongnu.org Cc: alex.williamson@redhat.com, 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 v6 13/22] intel_iommu: Reset pasid cache when system level reset Date: Thu, 18 Sep 2025 04:57:52 -0400 Message-ID: <20250918085803.796942-14-zhenzhong.duan@intel.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250918085803.796942-1-zhenzhong.duan@intel.com> References: <20250918085803.796942-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=192.198.163.8; 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_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_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: 1758186168476116600 Content-Type: text/plain; charset="utf-8" Reset pasid cache when system level reset, for RID_PASID, its vtd_as is allocated by PCI system and never removed, just mark pasid cache invalid. As we already have vtd_pasid_cache_sync_locked() to handle pasid cache invalidation, reuse it to do pasid cache invalidation at system reset level. Currently only IOMMUFD backed VFIO device caches pasid entry, so we don't need to care about emulated device. Signed-off-by: Yi Liu Signed-off-by: Zhenzhong Duan Reviewed-by: Yi Liu --- hw/i386/intel_iommu.c | 15 ++++++++++++++- hw/i386/trace-events | 1 + 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/hw/i386/intel_iommu.c b/hw/i386/intel_iommu.c index 24061f6dc6..a6638e13be 100644 --- a/hw/i386/intel_iommu.c +++ b/hw/i386/intel_iommu.c @@ -85,6 +85,18 @@ 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_pasid_cache_sync_locked(gpointer key, gpointer value, + gpointer user_data); + +static void vtd_pasid_cache_reset_locked(IntelIOMMUState *s) +{ + VTDPASIDCacheInfo pc_info =3D { .reset =3D true }; + + trace_vtd_pasid_cache_reset(); + g_hash_table_foreach(s->vtd_address_spaces, + vtd_pasid_cache_sync_locked, &pc_info); +} + =20 static void vtd_panic_require_caching_mode(void) { @@ -390,6 +402,7 @@ static void vtd_reset_caches(IntelIOMMUState *s) vtd_iommu_lock(s); vtd_reset_iotlb_locked(s); vtd_reset_context_cache_locked(s); + vtd_pasid_cache_reset_locked(s); vtd_iommu_unlock(s); } =20 @@ -3115,7 +3128,7 @@ static void vtd_pasid_cache_sync_locked(gpointer key,= gpointer value, /* non-RID_PASID isn't supported yet */ assert(vtd_as->pasid =3D=3D PCI_NO_PASID); =20 - if (vtd_dev_get_pe_from_pasid(vtd_as, &pe)) { + if (pc_info->reset || vtd_dev_get_pe_from_pasid(vtd_as, &pe)) { /* * No valid pasid entry in guest memory. e.g. pasid entry was modi= fied * to be either all-zero or non-present. Either case means existing diff --git a/hw/i386/trace-events b/hw/i386/trace-events index 298addb24d..b704f4f90c 100644 --- a/hw/i386/trace-events +++ b/hw/i386/trace-events @@ -24,6 +24,7 @@ vtd_inv_qi_head(uint16_t head) "read head %d" vtd_inv_qi_tail(uint16_t head) "write tail %d" vtd_inv_qi_fetch(void) "" vtd_context_cache_reset(void) "" +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 --=20 2.47.1 From nobody Sat Nov 15 00:44:23 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=1758186174; cv=none; d=zohomail.com; s=zohoarc; b=ZjQKiTtAMRvuDB31EXvbQ6UoARIWsS8Kc47KOr3xGERrrChkDytjMdCuFJFSSGSx0yxY4e2gNsu63GpKWBwk10ua8M4rxA/FuOchiBmdgar8gytn/mHqqJVNX9qUkh4ywujjxHO1LRW9PF8zb3JzaYGRk0e46D8ePCHN3pJX9i8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1758186174; 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=pzNNxl5WD+ihSI5GOgL8vnkSPF+fVnA3G3NAR+O1BSE=; b=mSEnHhOmubZADj05BzAWMtr1iuVVUoflvM2DRuctTRl12WVIBYnft0nj+lrUWEjB3xr3MDP/ug/dvM8s34Qrk2j3+orH6BhtqKYi/yAnWC2Kh0r1Dv3oRGeDqlRIalbd8ZOwybkX3jfGAl7kepm4NHtMCivZsk6M4kZ1M50g6mc= 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 1758186174717686.3834978928688; Thu, 18 Sep 2025 02:02:54 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uzAUP-00023k-4F; Thu, 18 Sep 2025 04:59:41 -0400 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 1uzAUL-0001pB-2l for qemu-devel@nongnu.org; Thu, 18 Sep 2025 04:59:37 -0400 Received: from mgamail.intel.com ([192.198.163.8]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uzAUD-0004kl-Vl for qemu-devel@nongnu.org; Thu, 18 Sep 2025 04:59:36 -0400 Received: from fmviesa009.fm.intel.com ([10.60.135.149]) by fmvoesa102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Sep 2025 01:59:27 -0700 Received: from unknown (HELO gnr-sp-2s-612.sh.intel.com) ([10.112.230.229]) by fmviesa009-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Sep 2025 01:59:24 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1758185970; x=1789721970; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=i+NMpkk9mRvGcaJo7YVNDuAo7rFNRmnFq4XiUVElC7o=; b=lmJa6LJfBD0vHNjgYMD4QKpwhKm2EsneRvUCjzyF743kxGUJ/lrzKfIJ 5rozB0C67M6pfXTcps6HrhdeKIjPJGIkedU633Q/XlB53vGEQeQNPatMH MtvINRBbQs37cabXqTdCm34eGKlTa33y9Z2JmtxaB5QUQhSuztYP4lUCF 5HynpH/+Q9UA0YZHK8OZH7beU0bRfjfTTGD5f45UXqUk594BrfZC6a6YV wDhUOGQ97CF3BIoWSGPwlTdVI7k4t3hEZEbfcYgvwWaP0QCMCOOnOy2fs 8gp9PpVtotNJtlX/UpZbltA5XQ5OAIOA6VOqwmFHDcendFkNhTG8HEM60 g==; X-CSE-ConnectionGUID: vaOJaWVVSzeQuLi/JRe1AA== X-CSE-MsgGUID: VCsbdsmdRSK+S5PMYI17TQ== X-IronPort-AV: E=McAfee;i="6800,10657,11556"; a="78109537" X-IronPort-AV: E=Sophos;i="6.18,274,1751266800"; d="scan'208";a="78109537" X-CSE-ConnectionGUID: SOEe3UgUR7Smv1jQMxdUtw== X-CSE-MsgGUID: GfY7XHVDReyGzS/R+rpbQw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.18,274,1751266800"; d="scan'208";a="175930434" From: Zhenzhong Duan To: qemu-devel@nongnu.org Cc: alex.williamson@redhat.com, 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 v6 14/22] intel_iommu: Add some macros and inline functions Date: Thu, 18 Sep 2025 04:57:53 -0400 Message-ID: <20250918085803.796942-15-zhenzhong.duan@intel.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250918085803.796942-1-zhenzhong.duan@intel.com> References: <20250918085803.796942-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=192.198.163.8; 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_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_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: 1758186176585116600 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 macro VTD_SM_PASID_ENTRY_FSPM to use extract64() just like what smmu does, because this macro is used indirectly by new introduced inline functions. 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 | 6 +++++- hw/i386/intel_iommu.c | 30 +++++++++++++++++++++++++++--- 2 files changed, 32 insertions(+), 4 deletions(-) diff --git a/hw/i386/intel_iommu_internal.h b/hw/i386/intel_iommu_internal.h index d400bcee21..3d5ee5ed52 100644 --- a/hw/i386/intel_iommu_internal.h +++ b/hw/i386/intel_iommu_internal.h @@ -592,8 +592,12 @@ typedef struct VTDPASIDCacheInfo { #define VTD_SM_PASID_ENTRY_AW 7ULL /* Adjusted guest-address-widt= h */ #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_BIT(x) extract64((x)->val[2], 0, 1) +/* 00: 4-level paging, 01: 5-level paging, 10-11: Reserved */ +#define VTD_SM_PASID_ENTRY_FSPM(x) extract64((x)->val[2], 2, 2) +#define VTD_SM_PASID_ENTRY_WPE_BIT(x) extract64((x)->val[2], 4, 1) +#define VTD_SM_PASID_ENTRY_EAFE_BIT(x) extract64((x)->val[2], 7, 1) =20 /* First Level Paging Structure */ /* Masks for First Level Paging Entry */ diff --git a/hw/i386/intel_iommu.c b/hw/i386/intel_iommu.c index a6638e13be..5908368c44 100644 --- a/hw/i386/intel_iommu.c +++ b/hw/i386/intel_iommu.c @@ -49,8 +49,7 @@ =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)) +#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 @@ -838,6 +837,31 @@ static inline bool vtd_pe_type_check(IntelIOMMUState *= s, VTDPASIDEntry *pe) } } =20 +static inline dma_addr_t vtd_pe_get_fspt_base(VTDPASIDEntry *pe) +{ + return pe->val[2] & VTD_SM_PASID_ENTRY_FSPTPTR; +} + +/* + * 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) +{ + return 48 + VTD_SM_PASID_ENTRY_FSPM(pe) * 9; +} + +static inline bool vtd_pe_pgtt_is_pt(VTDPASIDEntry *pe) +{ + return (VTD_PE_GET_TYPE(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_PE_GET_TYPE(pe) =3D=3D VTD_SM_PASID_ENTRY_FST); +} + static inline bool vtd_pdire_present(VTDPASIDDirEntry *pdire) { return pdire->val & 1; @@ -1709,7 +1733,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); --=20 2.47.1 From nobody Sat Nov 15 00:44:23 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=1758186024; cv=none; d=zohomail.com; s=zohoarc; b=m4wEOVd5bXa7ei/Zpwn09SF/3w7JjcIJLpALd/TsxAvc1gCmx/zG7EJxMw03dlp0/TOJR6LdzfIW+MVShJiTdp45bdH1/4Ti8SoaoVtjULLKn0uc5wvTe9kTMZkIa6LOEP1lOUqjrSD4mVxONbcPe7MHLGPfWT46EY4/+1lGnJg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1758186024; 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=kd5F6Ts+UhKKKaPWnFFNSWMq7Tx3mfaGWV4Im/ZfiFM=; b=VHyUKAtkbOb4cpTfG1q7XGiak6YdxMjpFWopz/hcIktt1Qv6rBZpDNtn7zNF2tn9iI/MmH3f9y/s7Iwp4lTgYao2F/zEE6Mzl3RZ3/+To1Ff0DM8KPEvIPisH0FDcogrz19gXX+K6WlUcCwUy6XSLKi1gZaEr0xhs+DF2rrlDVU= 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 1758186024306130.88952620853672; Thu, 18 Sep 2025 02:00:24 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uzAUS-0002II-Ff; Thu, 18 Sep 2025 04:59:44 -0400 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 1uzAUR-0002Ev-It for qemu-devel@nongnu.org; Thu, 18 Sep 2025 04:59:43 -0400 Received: from mgamail.intel.com ([192.198.163.8]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uzAUI-0004kz-0K for qemu-devel@nongnu.org; Thu, 18 Sep 2025 04:59:43 -0400 Received: from fmviesa009.fm.intel.com ([10.60.135.149]) by fmvoesa102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Sep 2025 01:59:31 -0700 Received: from unknown (HELO gnr-sp-2s-612.sh.intel.com) ([10.112.230.229]) by fmviesa009-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Sep 2025 01:59:27 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1758185974; x=1789721974; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=YZtYmMerLULntaEfYrrV6J14Z6Y7whKRv8qYk4H8Brw=; b=RdvImZTDN5QfOX7qtrW/AsOepiJ71SlGJC8fg2CjHzfngpbAXGQRyXG+ TeNP9ml/luWkDVnf12ka8Ccs2meGF4yZxVv5DB6YTZfKpHPzjwa//Gil7 vhxZXIbpFgf2pV9IyghEj6zqBbQD6RYFz6mNUmgGhuzJJmi83l3HNMDKn SZinj3J1iCskR/myyH+WKdPQCkJeR0d17OM5rkuKCZbErhm8NkrnDWbXK hm0lE5t/NEdQk8a3GGJO1Mqdr5M/xiruS4BgRKU1XyEYw6GXM/tjswOgh YgRVudTqrK7S8RTnQouBr6Jp+YGH4kBVVPrjM1661muw0Mw6queyk8LHA A==; X-CSE-ConnectionGUID: WfXNmCnQQGensuVUcrSD6A== X-CSE-MsgGUID: 1aV5tU8VQLaENLosLDNVnQ== X-IronPort-AV: E=McAfee;i="6800,10657,11556"; a="78109544" X-IronPort-AV: E=Sophos;i="6.18,274,1751266800"; d="scan'208";a="78109544" X-CSE-ConnectionGUID: teERsLLoQu2LVGVlWUsq5w== X-CSE-MsgGUID: MYoA7UFIStyrGTMhtAej3g== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.18,274,1751266800"; d="scan'208";a="175930449" From: Zhenzhong Duan To: qemu-devel@nongnu.org Cc: alex.williamson@redhat.com, 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 v6 15/22] intel_iommu: Bind/unbind guest page table to host Date: Thu, 18 Sep 2025 04:57:54 -0400 Message-ID: <20250918085803.796942-16-zhenzhong.duan@intel.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250918085803.796942-1-zhenzhong.duan@intel.com> References: <20250918085803.796942-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=192.198.163.8; envelope-from=zhenzhong.duan@intel.com; helo=mgamail.intel.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 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_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, T_SPF_TEMPERROR=0.01 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: 1758186026617116600 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 RID_PASID to a second stage HWPT(GPA->HPA). When PGTT=3DFST, attach RID_PASID 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 --- include/hw/i386/intel_iommu.h | 1 + hw/i386/intel_iommu.c | 152 +++++++++++++++++++++++++++++++++- hw/i386/trace-events | 3 + 3 files changed, 154 insertions(+), 2 deletions(-) diff --git a/include/hw/i386/intel_iommu.h b/include/hw/i386/intel_iommu.h index ff01e5c82d..86614fbb31 100644 --- a/include/hw/i386/intel_iommu.h +++ b/include/hw/i386/intel_iommu.h @@ -104,6 +104,7 @@ struct VTDAddressSpace { PCIBus *bus; uint8_t devfn; uint32_t pasid; + uint32_t fs_hwpt; AddressSpace as; IOMMUMemoryRegion iommu; MemoryRegion root; /* The root container of the device */ diff --git a/hw/i386/intel_iommu.c b/hw/i386/intel_iommu.c index 5908368c44..bfe229d0dc 100644 --- a/hw/i386/intel_iommu.c +++ b/hw/i386/intel_iommu.c @@ -20,6 +20,7 @@ */ =20 #include "qemu/osdep.h" +#include CONFIG_DEVICES /* CONFIG_IOMMUFD */ #include "qemu/error-report.h" #include "qemu/main-loop.h" #include "qapi/error.h" @@ -41,6 +42,9 @@ #include "migration/vmstate.h" #include "trace.h" #include "system/iommufd.h" +#ifdef CONFIG_IOMMUFD +#include +#endif =20 /* context entry operations */ #define RID_PASID 0 @@ -2398,6 +2402,125 @@ static void vtd_context_global_invalidate(IntelIOMM= UState *s) vtd_iommu_replay_all(s); } =20 +#ifdef CONFIG_IOMMUFD +static int vtd_create_fs_hwpt(HostIOMMUDeviceIOMMUFD *idev, + VTDPASIDEntry *pe, uint32_t *fs_hwpt, + Error **errp) +{ + struct iommu_hwpt_vtd_s1 vtd =3D {}; + + vtd.flags =3D (VTD_SM_PASID_ENTRY_SRE_BIT(pe) ? IOMMU_VTD_S1_SRE : 0) | + (VTD_SM_PASID_ENTRY_WPE_BIT(pe) ? IOMMU_VTD_S1_WPE : 0) | + (VTD_SM_PASID_ENTRY_EAFE_BIT(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->hwpt_id, 0, IOMMU_HWPT_DATA_V= TD_S1, + sizeof(vtd), &vtd, fs_hwpt, errp); +} + +static void vtd_destroy_old_fs_hwpt(HostIOMMUDeviceIOMMUFD *idev, + VTDAddressSpace *vtd_as) +{ + if (!vtd_as->fs_hwpt) { + return; + } + iommufd_backend_free_id(idev->iommufd, vtd_as->fs_hwpt); + vtd_as->fs_hwpt =3D 0; +} + +static int vtd_device_attach_iommufd(VTDHostIOMMUDevice *vtd_hiod, + VTDAddressSpace *vtd_as, Error **errp) +{ + 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; + bool ret; + + /* + * We can get here only if flts=3Don, the supported PGTT is FST and 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"); + return -EINVAL; + } + + if (vtd_pe_pgtt_is_pt(pe)) { + hwpt_id =3D idev->hwpt_id; + } else if (vtd_create_fs_hwpt(idev, pe, &hwpt_id, errp)) { + return -EINVAL; + } + + 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 =3D hwpt_id; + } + } else if (vtd_pe_pgtt_is_fst(pe)) { + iommufd_backend_free_id(idev->iommufd, hwpt_id); + } + + return !ret; +} + +static int vtd_device_detach_iommufd(VTDHostIOMMUDevice *vtd_hiod, + VTDAddressSpace *vtd_as, Error **errp) +{ + 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; +} + +static int vtd_bind_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); + int ret; + + assert(vtd_hiod); + + if (pc_entry->valid) { + ret =3D vtd_device_attach_iommufd(vtd_hiod, vtd_as, errp); + } else { + ret =3D vtd_device_detach_iommufd(vtd_hiod, vtd_as, errp); + } + + return ret; +} +#else +static int vtd_bind_guest_pasid(VTDAddressSpace *vtd_as, Error **errp) +{ + return 0; +} +#endif + /* Do a context-cache device-selective invalidation. * @func_mask: FM field after shifting */ @@ -3131,6 +3254,11 @@ static inline int vtd_dev_get_pe_from_pasid(VTDAddre= ssSpace *vtd_as, return vtd_ce_get_pasid_entry(s, &ce, pe, vtd_as->pasid); } =20 +static int vtd_pasid_entry_compare(VTDPASIDEntry *p1, VTDPASIDEntry *p2) +{ + return memcmp(p1, p2, sizeof(*p1)); +} + /* * For each IOMMUFD backed device, update or invalidate pasid cache based = on * the value in memory. @@ -3143,6 +3271,8 @@ static void vtd_pasid_cache_sync_locked(gpointer key,= gpointer value, VTDPASIDCacheEntry *pc_entry =3D &vtd_as->pasid_cache_entry; VTDPASIDEntry pe; uint16_t did; + const char *err_prefix; + Error *local_err =3D NULL; =20 /* Ignore emulated device or legacy VFIO backed device */ if (!vtd_find_hiod_iommufd(vtd_as)) { @@ -3153,13 +3283,18 @@ static void vtd_pasid_cache_sync_locked(gpointer ke= y, gpointer value, assert(vtd_as->pasid =3D=3D PCI_NO_PASID); =20 if (pc_info->reset || vtd_dev_get_pe_from_pasid(vtd_as, &pe)) { + if (!pc_entry->valid) { + return; + } + /* * No valid pasid entry in guest memory. e.g. pasid entry was modi= fied * to be either all-zero or non-present. Either case means existing * pasid cache should be invalidated. */ pc_entry->valid =3D false; - return; + err_prefix =3D "Detaching from HWPT failed: "; + goto do_bind_unbind; } =20 /* @@ -3184,7 +3319,20 @@ static void vtd_pasid_cache_sync_locked(gpointer key= , gpointer value, } =20 pc_entry->pasid_entry =3D pe; - pc_entry->valid =3D true; + if (!pc_entry->valid) { + pc_entry->valid =3D true; + err_prefix =3D "Attaching to HWPT failed: "; + } else if (vtd_pasid_entry_compare(&pe, &pc_entry->pasid_entry)) { + err_prefix =3D "Replacing HWPT attachment failed: "; + } else { + return; + } + +do_bind_unbind: + /* TODO: Fault event injection into guest, report error to QEMU for no= w */ + if (vtd_bind_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/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 Sat Nov 15 00:44:23 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=1758186058; cv=none; d=zohomail.com; s=zohoarc; b=Rc78gmehy55u3uuHV4PCtr3Ipake+FK6GbQkGQ4gBqu1vJtOe4SX8An1yPnV3Y1tAQeZey3cacYTsBuwH+NJss2mhU4MQfVW9zWp4ZDQ7DRTQ4OWYUEL9AXNvGz2+R7GOaLPBZ/uAQnCPRST9BcvmKoFkvCRRapnvEUOZ6dDbuw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1758186058; 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=YzPnl8T1LdQIz/MrkJcmECDpfuhgzGEckwJ5KrV43fA=; b=QFFqSXm5/87eKMrXyZIx3iguRxNBR+AcKBYP8BUThYOplucsO+K3SM3l4O5N2JKR+44sN6pBjGz/nwq3eUd28O4bmAcnnROm9kKgdzc9Ub59WUK5Qu9ZDAjwZeOk78yC8wPfKcSA4AV0j9LZsJH4Qx7yFo8i4zxr20O0nQZNN2I= 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 1758186058665966.2999794357506; Thu, 18 Sep 2025 02:00:58 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uzAUc-00032W-SN; Thu, 18 Sep 2025 04:59:55 -0400 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 1uzAUa-0002pp-Gh for qemu-devel@nongnu.org; Thu, 18 Sep 2025 04:59:52 -0400 Received: from mgamail.intel.com ([192.198.163.8]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uzAUX-0004kl-4g for qemu-devel@nongnu.org; Thu, 18 Sep 2025 04:59:52 -0400 Received: from fmviesa009.fm.intel.com ([10.60.135.149]) by fmvoesa102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Sep 2025 01:59:38 -0700 Received: from unknown (HELO gnr-sp-2s-612.sh.intel.com) ([10.112.230.229]) by fmviesa009-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Sep 2025 01:59:31 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1758185989; x=1789721989; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Kk93UegMJO9MsHInGh48oCIawxlVHG3/YVcWpauVbGI=; b=GaYNoCitnD/99tBzJLQ+IjKxsYa3vzkc+AbkbQqk6blRAY78mfYJKJFP UZ2OxOBkFamn+tsAgm9dSLjHriM3zz82IBIEVCgAzYUvPXRtt3Jz0EzcK TBqCVVNrzxuWON/UQNuExSc/12NLYjqH0oacWP67XuG8DNuhhveg5OJp8 OmHi7wLuXy1leBg2k6Oa3Ytrvfv4DlAmLE/bq7hHykxbRtYGdRC7fCujN INQKN8PfbyecWurgBQqdJcOk5MXUiEGQ7xsdmdCyS/WxgR8hmR6PnZaOc DrnOH4TXiMW8z0emBzCvJU4+lUDZLvisAhS2veriAPnt6IzWTYToV9FNK Q==; X-CSE-ConnectionGUID: KHJh6CnjQLuYZEh/RX96AA== X-CSE-MsgGUID: 3vbR6DySRoCOG6rXHDN/qA== X-IronPort-AV: E=McAfee;i="6800,10657,11556"; a="78109557" X-IronPort-AV: E=Sophos;i="6.18,274,1751266800"; d="scan'208";a="78109557" X-CSE-ConnectionGUID: J+NUDOBfTx+6Bk3rr9NThQ== X-CSE-MsgGUID: mXQwCackTx6EL1J4mRcnWw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.18,274,1751266800"; d="scan'208";a="175930474" From: Zhenzhong Duan To: qemu-devel@nongnu.org Cc: alex.williamson@redhat.com, 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 v6 16/22] intel_iommu: Propagate PASID-based iotlb invalidation to host Date: Thu, 18 Sep 2025 04:57:55 -0400 Message-ID: <20250918085803.796942-17-zhenzhong.duan@intel.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250918085803.796942-1-zhenzhong.duan@intel.com> References: <20250918085803.796942-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=192.198.163.8; 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_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_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: 1758186059215116600 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 --- hw/i386/intel_iommu_internal.h | 6 +++ hw/i386/intel_iommu.c | 85 +++++++++++++++++++++++++++++++++- 2 files changed, 89 insertions(+), 2 deletions(-) diff --git a/hw/i386/intel_iommu_internal.h b/hw/i386/intel_iommu_internal.h index 3d5ee5ed52..d7c1ff4382 100644 --- a/hw/i386/intel_iommu_internal.h +++ b/hw/i386/intel_iommu_internal.h @@ -569,6 +569,12 @@ typedef struct VTDPASIDCacheInfo { bool reset; } 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 bfe229d0dc..92548f9573 100644 --- a/hw/i386/intel_iommu.c +++ b/hw/i386/intel_iommu.c @@ -2514,11 +2514,88 @@ static int vtd_bind_guest_pasid(VTDAddressSpace *vt= d_as, Error **errp) =20 return ret; } + +/* + * 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 RID= _PASID) { + 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, + 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); + } + } +} + +static 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 + * the affected host device 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); +} #else static int vtd_bind_guest_pasid(VTDAddressSpace *vtd_as, Error **errp) { return 0; } + +static void +vtd_flush_host_piotlb_all_locked(IntelIOMMUState *s, + uint16_t domain_id, uint32_t pasid, + hwaddr addr, uint64_t npages, bool ih) +{ +} #endif =20 /* Do a context-cache device-selective invalidation. @@ -3159,6 +3236,7 @@ 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,= 0); vtd_iommu_unlock(s); =20 QLIST_FOREACH(vtd_as, &s->vtd_as_with_notifiers, next) { @@ -3178,7 +3256,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 @@ -3190,6 +3269,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); @@ -3221,7 +3301,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->val[1]= )); break; =20 default: --=20 2.47.1 From nobody Sat Nov 15 00:44:23 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=1758186275; cv=none; d=zohomail.com; s=zohoarc; b=Ulb8grnPJgpFq0021DcRGBOBIecWdBI1/YxF0Rm7BCvG7pP7lZh4PeXTBtq1UNNzt7RNkjMtJamHqSpF30bNjQ2OTCHQWca9+w07BmWVybiLtNbEPb8M31h5VuMiednab5z72kPEbHSqyTcavY4hz5IpFfxfdKmH3sJhEPSQ+jM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1758186275; 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=72qmt/3MOqRQPohGv/rYA8BrIv38aTbDJKOrWdwS8m0=; b=Db3jUMQLC7jQ4x/EXQuDGh7VQVWA0VkdGSez27xZe57oa1Rj1fYK+OnYfnlOgenJmp0FifUGGDoVrdmpR1bhqJWn/Gbz/mzOEiHTBApk1FyCv/LynHEKPVAuVZQ/eJh04onfToyu5jR4aQLxoxc+BQU08IDqvkhAvtNbv7i6RSc= 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 1758186275901391.44062332535964; Thu, 18 Sep 2025 02:04:35 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uzAUd-000335-0e; Thu, 18 Sep 2025 04:59:55 -0400 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 1uzAUb-0002rH-8F for qemu-devel@nongnu.org; Thu, 18 Sep 2025 04:59:53 -0400 Received: from mgamail.intel.com ([192.198.163.8]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uzAUU-0004kz-QW for qemu-devel@nongnu.org; Thu, 18 Sep 2025 04:59:52 -0400 Received: from fmviesa009.fm.intel.com ([10.60.135.149]) by fmvoesa102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Sep 2025 01:59:41 -0700 Received: from unknown (HELO gnr-sp-2s-612.sh.intel.com) ([10.112.230.229]) by fmviesa009-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Sep 2025 01:59:37 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1758185986; x=1789721986; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=23KJ24qa77slLYbUlc7r1JjQRvBtmhjnFhhB58ZbJd0=; b=jS4OzAiCbSvXtlxrh5YLTu+kDmrl4vVJcMd8pF8o1HUrg8V8JqBHVs2Z ApocbrcrDdkORZ4UOWypYM1sCw0A85dBuYL6cO1vWwiON7e6LpkBLvDrM 5FZhmt7fS4+5HtOTwiTwhFS9kOyCyzl+HROxp1ucc+8PRTUxNkGlz5Lbq ZNxTc2+GsytQRdyr5JQ5JEDsYWiQYa/RmjG0QXWQybF5JPQcg1y/QkGd5 /aSslGWNJzq7FSgKwPTigOouWBkIWYiX8NHEPxOlRPcm+PvdHOA62CGjq oCM1akZ8akjpyuGlHZbPEr/sUHkCVQQQOXpJanTMp3ufUyNhQcGR5tqfM A==; X-CSE-ConnectionGUID: fVGlQomlSiexlXaT9o6dDg== X-CSE-MsgGUID: Ky/L0vNgTHueRaplm0Hqcg== X-IronPort-AV: E=McAfee;i="6800,10657,11556"; a="78109564" X-IronPort-AV: E=Sophos;i="6.18,274,1751266800"; d="scan'208";a="78109564" X-CSE-ConnectionGUID: MTP1x3IyRL+SDYgmsG5aBA== X-CSE-MsgGUID: Ed1sULe5SKmXELVhHW61QQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.18,274,1751266800"; d="scan'208";a="175930503" From: Zhenzhong Duan To: qemu-devel@nongnu.org Cc: alex.williamson@redhat.com, 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 v6 17/22] intel_iommu: Replay all pasid bindings when either SRTP or TE bit is changed Date: Thu, 18 Sep 2025 04:57:56 -0400 Message-ID: <20250918085803.796942-18-zhenzhong.duan@intel.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250918085803.796942-1-zhenzhong.duan@intel.com> References: <20250918085803.796942-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=192.198.163.8; 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_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_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: 1758186277931116600 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 92548f9573..74496c7d3b 100644 --- a/hw/i386/intel_iommu.c +++ b/hw/i386/intel_iommu.c @@ -90,6 +90,7 @@ static void vtd_address_space_refresh_all(IntelIOMMUState= *s); static void vtd_address_space_unmap(VTDAddressSpace *as, IOMMUNotifier *n); static void vtd_pasid_cache_sync_locked(gpointer key, gpointer value, gpointer user_data); +static void vtd_replay_pasid_bindings_all(IntelIOMMUState *s); =20 static void vtd_pasid_cache_reset_locked(IntelIOMMUState *s) { @@ -2904,6 +2905,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 */ @@ -2938,6 +2940,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 */ @@ -3428,6 +3431,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 Sat Nov 15 00:44:23 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=1758186378; cv=none; d=zohomail.com; s=zohoarc; b=nHTWslGIQe6WrH6ADj+DTo0U9Hgkhe1WOPJrBfP7nh3XOikjWm5jeoWu9Y4RgvbltyywL/UZPbkYgbdStEK1p9w5LOvqlhUIm3R+wyRlkPrsYxS1SuhiXrV/cGa67piKNMY/wRoZceKaPexI9k2dJ+udDyp/vcoit8Mi7AkPGv0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1758186378; 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=QbnvZxlX2nLHy+csdDSRI/cTe9k8+H5aJI9HWcEI8qQ=; b=gJSWkrnillLLviPCvMR0pBwNwRdy2GJYX3TVIPMbJwskM5rL8ONOmmhfbdZz5iDtTmztv54imdWIjsaSBdPFh3tqmvVRzEt3abmCDSD+BiOg3DFi08sye/K7vudkH/TE04VvL+UesM4kXO+rA9fFSHCk9+hyKDTx10mkKC0uLoU= 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 1758186378265455.50957768428975; Thu, 18 Sep 2025 02:06:18 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uzAUs-000443-DT; Thu, 18 Sep 2025 05:00:10 -0400 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 1uzAUp-0003vk-6X for qemu-devel@nongnu.org; Thu, 18 Sep 2025 05:00:07 -0400 Received: from mgamail.intel.com ([192.198.163.8]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uzAUj-0004rh-8v for qemu-devel@nongnu.org; Thu, 18 Sep 2025 05:00:06 -0400 Received: from fmviesa009.fm.intel.com ([10.60.135.149]) by fmvoesa102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Sep 2025 01:59:45 -0700 Received: from unknown (HELO gnr-sp-2s-612.sh.intel.com) ([10.112.230.229]) by fmviesa009-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Sep 2025 01:59:41 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1758186001; x=1789722001; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=P9+nzVOhX790y/qc4xR49BXWixXcP2jO+tGhon21nMI=; b=VE3kvfaLKit+5mGlK0n5wFu9TCgX4mmUHX4u4tu1yVeprAnVfNxAIg7H Gof8oGQQFTx3GwbTpy8ZJP++Xxsbi/Y8xWEeBK+NhjnD1J2Bkd93wdTEj lYRgbPT9QfUQ7CqOpiLHEzXe7sOzF5p7wItswHfqEmmeWveyHc3l80XWW j0spJLmVyzn8urj7Hk6yp3NfkpG8ek2wglLqXXRW0X0rSRQ5fH8/cgMse H6fLf8cLCUvEGNP8nlfdFiS6+LcZnCLgIBb2viP2l0I5XYLldvLk9BqFD Zh0J45a2Rsc/nOiGx5RRLALiAsZFz2K4K9RiBzL0ntN47GGZISC84C10d Q==; X-CSE-ConnectionGUID: tmojZfV+R0uQVw6rYyUFfg== X-CSE-MsgGUID: Oj8Wm+tPRWuslLDJF2x99g== X-IronPort-AV: E=McAfee;i="6800,10657,11556"; a="78109572" X-IronPort-AV: E=Sophos;i="6.18,274,1751266800"; d="scan'208";a="78109572" X-CSE-ConnectionGUID: r0CFHSsaQ1yefIJz3pYRzQ== X-CSE-MsgGUID: +Zz+DO4lR1yiDhEbbUezyA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.18,274,1751266800"; d="scan'208";a="175930566" From: Zhenzhong Duan To: qemu-devel@nongnu.org Cc: alex.williamson@redhat.com, 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 v6 18/22] iommufd: Introduce a helper function to extract vendor capabilities Date: Thu, 18 Sep 2025 04:57:57 -0400 Message-ID: <20250918085803.796942-19-zhenzhong.duan@intel.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250918085803.796942-1-zhenzhong.duan@intel.com> References: <20250918085803.796942-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=192.198.163.8; 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_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_PASS=-0.001, T_SPF_HELO_TEMPERROR=0.01 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: 1758186378724116600 Content-Type: text/plain; charset="utf-8" In VFIO core, we call iommufd_backend_get_device_info() to return vendor specific hardware information data, but it's not good to extract this raw data in VFIO core. Introduce host_iommu_extract_vendor_caps() to help extracting the raw data and return a bitmap in iommufd.c because it's the place defining iommufd_backend_get_device_info(). The other choice is to put vendor data extracting code in vendor vIOMMU emulation file, but that will make those files mixed with vIOMMU emulation and host IOMMU extracting code, also need a new callback in PCIIOMMUOps. So we choose a simpler way as above. Suggested-by: Nicolin Chen Signed-off-by: Zhenzhong Duan Reviewed-by: Nicolin Chen --- include/hw/iommu.h | 5 +++++ include/system/host_iommu_device.h | 16 ++++++++++++++++ backends/iommufd.c | 13 +++++++++++++ 3 files changed, 34 insertions(+) diff --git a/include/hw/iommu.h b/include/hw/iommu.h index 65d652950a..9b343e64b0 100644 --- a/include/hw/iommu.h +++ b/include/hw/iommu.h @@ -16,4 +16,9 @@ enum { VIOMMU_FLAG_WANT_NESTING_PARENT =3D BIT_ULL(0), }; =20 +enum { + /* Nesting parent HWPT shouldn't have readonly mapping, due to errata = */ + IOMMU_HW_NESTING_PARENT_BYPASS_RO =3D BIT_ULL(0), +}; + #endif /* HW_IOMMU_H */ diff --git a/include/system/host_iommu_device.h b/include/system/host_iommu= _device.h index ab849a4a82..41c9159605 100644 --- a/include/system/host_iommu_device.h +++ b/include/system/host_iommu_device.h @@ -39,6 +39,22 @@ typedef struct HostIOMMUDeviceCaps { uint64_t hw_caps; VendorCaps vendor_caps; } HostIOMMUDeviceCaps; + +/** + * host_iommu_extract_vendor_caps: Extract vendor capabilities + * + * This function converts @type specific hardware information data + * into a standard bitmap format. + * + * @type: IOMMU Hardware Info Types + * + * @VendorCaps: IOMMU @type specific hardware information data + * + * Returns: 64bit bitmap with each bit represents a capability of host + * IOMMU that we want to expose. See IOMMU_HW_* in include/hw/iommu.h + * for all possible capabilities currently exposed. + */ +uint64_t host_iommu_extract_vendor_caps(uint32_t type, VendorCaps *caps); #endif =20 #define TYPE_HOST_IOMMU_DEVICE "host-iommu-device" diff --git a/backends/iommufd.c b/backends/iommufd.c index 2a33c7ab0b..0bb1ed40d3 100644 --- a/backends/iommufd.c +++ b/backends/iommufd.c @@ -19,6 +19,7 @@ #include "migration/cpr.h" #include "monitor/monitor.h" #include "trace.h" +#include "hw/iommu.h" #include "hw/vfio/vfio-device.h" #include #include @@ -410,6 +411,18 @@ bool iommufd_backend_get_device_info(IOMMUFDBackend *b= e, uint32_t devid, return true; } =20 +uint64_t host_iommu_extract_vendor_caps(uint32_t type, VendorCaps *caps) +{ + uint64_t vendor_caps =3D 0; + + if (type =3D=3D IOMMU_HW_INFO_TYPE_INTEL_VTD && + caps->vtd.flags & IOMMU_HW_INFO_VTD_ERRATA_772415_SPR17) { + vendor_caps |=3D IOMMU_HW_NESTING_PARENT_BYPASS_RO; + } + + return vendor_caps; +} + bool iommufd_backend_invalidate_cache(IOMMUFDBackend *be, uint32_t id, uint32_t data_type, uint32_t entry_l= en, uint32_t *entry_num, void *data, --=20 2.47.1 From nobody Sat Nov 15 00:44:23 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=1758186124; cv=none; d=zohomail.com; s=zohoarc; b=TwE+fidSnh+vIb39fi3lDc2yg1dXPOFz6kScZ+nKxPqUpr+0SahqWoRdtURLMJq/Y+xs8mPZS8K8o96q40S/6Wg/UMUVRQmwe1+QlSPvQbq9r5Qc6TSPjhjmRGVG2djG+dK4CHnb6gJwyUBhS8w6jTIxquSv9mXEQZwKoGL0a0w= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1758186124; 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=uubm2MOEqCaMfTXG3oTWByXmQwtGSqOYD+mRPLr1APU=; b=WRqZNptW7blWYsTEmSe9ogqUZuQiHWeu+03M19HjyZyoaU21yytVbW1KevA5ov1eYf45/bDUCA+wJUfb4gxa7hETiYtMlf2pu+DGBSBQ604B9Eo/oEezVHUEJTnzd05WNqrGaiKI3DW/jXBBXHYz7sd4HJptPTTmxLW0aZeZrSI= 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 1758186124498643.4321141483067; Thu, 18 Sep 2025 02:02:04 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uzAUu-00047A-SB; Thu, 18 Sep 2025 05:00:13 -0400 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 1uzAUo-0003tB-Ui for qemu-devel@nongnu.org; Thu, 18 Sep 2025 05:00:07 -0400 Received: from mgamail.intel.com ([192.198.163.8]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uzAUm-0004kl-6D for qemu-devel@nongnu.org; Thu, 18 Sep 2025 05:00:06 -0400 Received: from fmviesa009.fm.intel.com ([10.60.135.149]) by fmvoesa102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Sep 2025 01:59:49 -0700 Received: from unknown (HELO gnr-sp-2s-612.sh.intel.com) ([10.112.230.229]) by fmviesa009-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Sep 2025 01:59:45 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1758186004; x=1789722004; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=CHqmw14bMKZHqF6V7+19ya9aAL7hu+O14g1LnGYZSJ0=; b=Wa+8sdUWF1GPTY88su4KMg/uCcXhj0dxShAz4PONzcwpPw4kLJtjWFfp 6Y3ctxDelQ0mY4y0MOL3rVsgoodTSsTEqOVldQB5LlbWDEtPtjUKXgKvb BbAjxrxHEFAuC74MI4vJAKtfxlQKP5Q8WqHzrE4tnQUDMvw7U9qYGoC0r 04rlDxF9Pp4GtCcbu8W4WEq7fDNpv2oHr59v+anq/n1PVzJvQNduJZNv/ g2IhHNbx6ErZMkuSREVP3WTIK0vMdWbBjJX2B0iiaS/ojE3s9hEETKO8x 1Ato7blNdcryzUR+KI6bqENY9Jy0yiVxM/CCZ9ey3iRkhcVuNMe2R5j4M Q==; X-CSE-ConnectionGUID: KRHjBzmHTemLMxREVvosmA== X-CSE-MsgGUID: wrO+uGbqQEWgsJ03eGMdLQ== X-IronPort-AV: E=McAfee;i="6800,10657,11556"; a="78109580" X-IronPort-AV: E=Sophos;i="6.18,274,1751266800"; d="scan'208";a="78109580" X-CSE-ConnectionGUID: fep0xTKBS8Os4UZlAPhUdg== X-CSE-MsgGUID: eSs6vPQhRu6nkE+sX1Ac/g== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.18,274,1751266800"; d="scan'208";a="175930580" From: Zhenzhong Duan To: qemu-devel@nongnu.org Cc: alex.williamson@redhat.com, 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 v6 19/22] vfio: Add a new element bypass_ro in VFIOContainerBase Date: Thu, 18 Sep 2025 04:57:58 -0400 Message-ID: <20250918085803.796942-20-zhenzhong.duan@intel.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250918085803.796942-1-zhenzhong.duan@intel.com> References: <20250918085803.796942-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=192.198.163.8; 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_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_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: 1758186125974116600 Content-Type: text/plain; charset="utf-8" When bypass_ro is true, readonly memory section is bypassed from mapping in the container. This is a preparing patch to workaround Intel ERRATA_772415, see changelog in next patch for details about the errata. Signed-off-by: Zhenzhong Duan Reviewed-by: C=C3=A9dric Le Goater --- include/hw/vfio/vfio-container-base.h | 1 + hw/vfio/listener.c | 21 ++++++++++++++------- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/include/hw/vfio/vfio-container-base.h b/include/hw/vfio/vfio-c= ontainer-base.h index acbd48a18a..2b9fec217a 100644 --- a/include/hw/vfio/vfio-container-base.h +++ b/include/hw/vfio/vfio-container-base.h @@ -52,6 +52,7 @@ struct VFIOContainerBase { QLIST_HEAD(, VFIODevice) device_list; GList *iova_ranges; NotifierWithReturn cpr_reboot_notifier; + bool bypass_ro; }; =20 #define TYPE_VFIO_IOMMU "vfio-iommu" diff --git a/hw/vfio/listener.c b/hw/vfio/listener.c index e093833165..581ebfda36 100644 --- a/hw/vfio/listener.c +++ b/hw/vfio/listener.c @@ -76,8 +76,13 @@ static bool vfio_log_sync_needed(const VFIOContainerBase= *bcontainer) return true; } =20 -static bool vfio_listener_skipped_section(MemoryRegionSection *section) +static bool vfio_listener_skipped_section(MemoryRegionSection *section, + bool bypass_ro) { + if (bypass_ro && section->readonly) { + return true; + } + return (!memory_region_is_ram(section->mr) && !memory_region_is_iommu(section->mr)) || memory_region_is_protected(section->mr) || @@ -368,9 +373,9 @@ static bool vfio_known_safe_misalignment(MemoryRegionSe= ction *section) } =20 static bool vfio_listener_valid_section(MemoryRegionSection *section, - const char *name) + bool bypass_ro, const char *name) { - if (vfio_listener_skipped_section(section)) { + if (vfio_listener_skipped_section(section, bypass_ro)) { trace_vfio_listener_region_skip(name, section->offset_within_address_space, section->offset_within_address_space + @@ -497,7 +502,8 @@ void vfio_container_region_add(VFIOContainerBase *bcont= ainer, int ret; Error *err =3D NULL; =20 - if (!vfio_listener_valid_section(section, "region_add")) { + if (!vfio_listener_valid_section(section, bcontainer->bypass_ro, + "region_add")) { return; } =20 @@ -663,7 +669,8 @@ static void vfio_listener_region_del(MemoryListener *li= stener, int ret; bool try_unmap =3D true; =20 - if (!vfio_listener_valid_section(section, "region_del")) { + if (!vfio_listener_valid_section(section, bcontainer->bypass_ro, + "region_del")) { return; } =20 @@ -820,7 +827,7 @@ static void vfio_dirty_tracking_update(MemoryListener *= listener, container_of(listener, VFIODirtyRangesListener, listener); hwaddr iova, end; =20 - if (!vfio_listener_valid_section(section, "tracking_update") || + if (!vfio_listener_valid_section(section, false, "tracking_update") || !vfio_get_section_iova_range(dirty->bcontainer, section, &iova, &end, NULL)) { return; @@ -1214,7 +1221,7 @@ static void vfio_listener_log_sync(MemoryListener *li= stener, int ret; Error *local_err =3D NULL; =20 - if (vfio_listener_skipped_section(section)) { + if (vfio_listener_skipped_section(section, false)) { return; } =20 --=20 2.47.1 From nobody Sat Nov 15 00:44:23 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=1758186289; cv=none; d=zohomail.com; s=zohoarc; b=YdOkQAJQTK1lL9ekgVL2y9E8HaLJIm4mpFz+VjTXzX7rtlQAe4rgosGWyxbnq7RbPy8KxdNLgrjMyMT6m68KIhrDLHAV1s7HhRap8ZK7YeTyeBGZ5vWz2W97WftHFAgSI4saQZXs5PN0T7e15HZCOYIuNFlnjzNiwacSo05HU0I= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1758186289; 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=W02ugyj3H8ea7ee7iOEMKWTGcnaUs2VvQgSxaQblZBE=; b=kvHpqFSEmXuJDMwRl8wxqTL/dDQWKyN7f2e5E/K/C6v8D9hQq70ZBSwlfkw/3EPoCLh7eY7LYAsTlPVGCFJcCUfFijVdWjES4PABwcJjT0QEKs1CA8DIU3h3w7Dd+0YONL1Qikrf1zoHLha230VwrhJcv+zDwZY48skAHQxl3ik= 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 17581862889341022.7101389225469; Thu, 18 Sep 2025 02:04:48 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uzAV2-0004Xf-3k; Thu, 18 Sep 2025 05:00:21 -0400 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 1uzAUy-0004On-MR for qemu-devel@nongnu.org; Thu, 18 Sep 2025 05:00:17 -0400 Received: from mgamail.intel.com ([192.198.163.8]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uzAUn-0004kz-7G for qemu-devel@nongnu.org; Thu, 18 Sep 2025 05:00:15 -0400 Received: from fmviesa009.fm.intel.com ([10.60.135.149]) by fmvoesa102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Sep 2025 01:59:52 -0700 Received: from unknown (HELO gnr-sp-2s-612.sh.intel.com) ([10.112.230.229]) by fmviesa009-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Sep 2025 01:59:49 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1758186005; x=1789722005; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=8LVkAItgk/Sc7pz7pxLa9UekS4TJEpBNLS4OC1thLEE=; b=GFsfTgaRs+of+Ml+hc+3awsRbfITYzk5GLQRMJ6S2N/uEeg/WDcrF4kl uLFyfsUqC3y2/vW1l8mxyCpImylS4ZzNUJQXgpU+rcw9Us+Zp6nf8nobt TbUfD07VJKW/NZfc0hHVHZgKFzK7SzwOE431DKN8rwE1MRLvP7/sLj4bF 0pXSiztl7ECmelrwJl7SAUPI4CZlBNbqwLtyTX9fwHXOYj7bq9tB87yx+ 2L1dXU9rfEXOJVTfrozget+KrhJN2yq3fqEB95OYyc53htbSy8b3A5Am2 VrtGOU9nDtFzKP+/kDQYpi9mBRiIfc8NLLuw4nhuCj8XShe6TL30ytVbZ A==; X-CSE-ConnectionGUID: 8NV/2z99Ru+d3wm57BsYdw== X-CSE-MsgGUID: rBTyEmQ9SpmOhH0VOWFFSg== X-IronPort-AV: E=McAfee;i="6800,10657,11556"; a="78109600" X-IronPort-AV: E=Sophos;i="6.18,274,1751266800"; d="scan'208";a="78109600" X-CSE-ConnectionGUID: j1pStgd7RGKE/+by1K9VoQ== X-CSE-MsgGUID: FonvCMUJRXKJXY7vm0zF1Q== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.18,274,1751266800"; d="scan'208";a="175930602" From: Zhenzhong Duan To: qemu-devel@nongnu.org Cc: alex.williamson@redhat.com, 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 v6 20/22] Workaround for ERRATA_772415_SPR17 Date: Thu, 18 Sep 2025 04:57:59 -0400 Message-ID: <20250918085803.796942-21-zhenzhong.duan@intel.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250918085803.796942-1-zhenzhong.duan@intel.com> References: <20250918085803.796942-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=192.198.163.8; 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_SAFE_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: 1758186289834116600 Content-Type: text/plain; charset="utf-8" On a system influenced by ERRATA_772415, IOMMU_HW_INFO_VTD_ERRATA_772415_SP= R17 is repored by IOMMU_DEVICE_GET_HW_INFO. Due to this errata, even the readon= ly range mapped on second stage page table could still be written. Reference from 4th Gen Intel Xeon Processor Scalable Family Specification Update, Errata Details, SPR17. https://edc.intel.com/content/www/us/en/design/products-and-solutions/proce= ssors-and-chipsets/eagle-stream/sapphire-rapids-specification-update/ Also copied the SPR17 details from above link: "Problem: When remapping hardware is configured by system software in scalable mode as Nested (PGTT=3D011b) and with PWSNP field Set in the PASID-table-entry, it may Set Accessed bit and Dirty bit (and Extended Access bit if enabled) in first-stage page-table entries even when second-stage mappings indicate that corresponding first-stage page-table is Read-Only. Implication: Due to this erratum, pages mapped as Read-only in second-stage page-tables may be modified by remapping hardware Access/Dirty bit updates. Workaround: None identified. System software enabling nested translations for a VM should ensure that there are no read-only pages in the corresponding second-stage mappings." Signed-off-by: Zhenzhong Duan --- hw/vfio/iommufd.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/hw/vfio/iommufd.c b/hw/vfio/iommufd.c index f1684a39b7..5d25ce6f97 100644 --- a/hw/vfio/iommufd.c +++ b/hw/vfio/iommufd.c @@ -15,6 +15,7 @@ #include #include =20 +#include "hw/iommu.h" #include "hw/vfio/vfio-device.h" #include "qemu/error-report.h" #include "trace.h" @@ -326,6 +327,7 @@ static bool iommufd_cdev_autodomains_get(VFIODevice *vb= asedev, IOMMUFDBackend *iommufd =3D vbasedev->iommufd; uint32_t type, flags =3D 0; uint64_t hw_caps; + VendorCaps caps; VFIOIOASHwpt *hwpt; uint32_t hwpt_id; int ret; @@ -371,7 +373,8 @@ static bool iommufd_cdev_autodomains_get(VFIODevice *vb= asedev, * instead. */ if (!iommufd_backend_get_device_info(vbasedev->iommufd, vbasedev->devi= d, - &type, NULL, 0, &hw_caps, errp)) { + &type, &caps, sizeof(caps), &hw_c= aps, + errp)) { return false; } =20 @@ -386,6 +389,11 @@ static bool iommufd_cdev_autodomains_get(VFIODevice *v= basedev, */ if (vfio_device_get_viommu_flags_want_nesting(vbasedev)) { flags |=3D IOMMU_HWPT_ALLOC_NEST_PARENT; + + if (host_iommu_extract_vendor_caps(type, &caps) & + IOMMU_HW_NESTING_PARENT_BYPASS_RO) { + container->bcontainer.bypass_ro =3D true; + } } =20 if (cpr_is_incoming()) { --=20 2.47.1 From nobody Sat Nov 15 00:44:23 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=1758186370; cv=none; d=zohomail.com; s=zohoarc; b=i375cqHbyl19FYvEG4xcwBS3IY+pEOcM112nC/GXJjnUVIkaVHQ865aWWu4aeaNWqnFfP4AZx+elPVch/vGkYekurPdFXxCzFL8DC3zvdh1k2VgPXzYCi60nBSggZXRruMOeOP4kJIVVFELpm/Sm5oNhGeTVCzg2/qL6sw68qBs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1758186370; 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=0hAQEecfPuFQwkJ8FDh0KG7iP4DBsT27rZ43113ocq8=; b=bhgXtSyvl66pUUb5IXge2hHakDmSPNYpbNmo9iGN233F/cn56VYwTxBEyyN82Ok1qpfxo67sVIuSrqfvGKcvYg0MkYHv33smP9COh/ikQQ8XjdKxl0Vx+P9vyiZxAel/zRjI0nf+8axk3HjaQNyE1VJSlx7goB73irCje9uye2w= 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 175818637018686.9153778027819; Thu, 18 Sep 2025 02:06:10 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uzAVm-0005CU-On; Thu, 18 Sep 2025 05:01:07 -0400 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 1uzAVB-0004pL-WF for qemu-devel@nongnu.org; Thu, 18 Sep 2025 05:00:39 -0400 Received: from mgamail.intel.com ([192.198.163.8]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uzAV0-0004kl-HU for qemu-devel@nongnu.org; Thu, 18 Sep 2025 05:00:28 -0400 Received: from fmviesa009.fm.intel.com ([10.60.135.149]) by fmvoesa102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Sep 2025 01:59:56 -0700 Received: from unknown (HELO gnr-sp-2s-612.sh.intel.com) ([10.112.230.229]) by fmviesa009-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Sep 2025 01:59:53 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1758186018; x=1789722018; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=7DVwUdERc9eLu9GAqQVuz/4yNyXFWxiqCvoOWIvl1w8=; b=JP1coq1bVx/RZMsyf1cNeLWavRPXNvlHepJdZcqh0OcguJLZ1KXZJe5N e0EwEAPoYZBYfRIUZufAgz8WUmc2hFRjR+JHvQRCogglCphqqDi6kDFwr yvtK7gKU4KF10ISsHUyKBZJd4NAiI/DH7snI0tM+lVLaafbOCiNOSLlFW kGpDeE9sLJlgEpKsDiLaz0QpMBAafXAtq/2qQ5/bOKhqjRzu3ExH5HNmr bMRouZnwC0VWhzYgN8ij7ZwUNyxofu8AAi+7c5SCvpRP6ZCSqGXrk093o AiblRv8ckuTppMovvk4SYdbO0PAs9HGLbIRlvY3cVqb9DKT3x0EqwETu4 Q==; X-CSE-ConnectionGUID: H1kSyoEURySVqlS2RzT2wQ== X-CSE-MsgGUID: QhGNpN6lT++h6bq7oCdpbA== X-IronPort-AV: E=McAfee;i="6800,10657,11556"; a="78109610" X-IronPort-AV: E=Sophos;i="6.18,274,1751266800"; d="scan'208";a="78109610" X-CSE-ConnectionGUID: apQxe+lxSvqzKWBIL9NPIw== X-CSE-MsgGUID: HGOnlh/ISPCYN5fE0mRRnQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.18,274,1751266800"; d="scan'208";a="175930620" From: Zhenzhong Duan To: qemu-devel@nongnu.org Cc: alex.williamson@redhat.com, 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 v6 21/22] intel_iommu: Enable host device when x-flts=on in scalable mode Date: Thu, 18 Sep 2025 04:58:00 -0400 Message-ID: <20250918085803.796942-22-zhenzhong.duan@intel.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250918085803.796942-1-zhenzhong.duan@intel.com> References: <20250918085803.796942-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=192.198.163.8; 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_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, T_SPF_TEMPERROR=0.01 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: 1758186370530116600 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.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/hw/i386/intel_iommu.c b/hw/i386/intel_iommu.c index 74496c7d3b..4bed115017 100644 --- a/hw/i386/intel_iommu.c +++ b/hw/i386/intel_iommu.c @@ -4828,6 +4828,8 @@ static bool vtd_check_hiod(IntelIOMMUState *s, VTDHos= tIOMMUDevice *vtd_hiod, "when x-flts=3Don"); return false; } + + return true; #endif =20 error_setg(errp, --=20 2.47.1 From nobody Sat Nov 15 00:44:23 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=1758186402; cv=none; d=zohomail.com; s=zohoarc; b=T+tYnGiplmvh4RG94tp1YYhlnFGxwYxDShCDEoj5MYOSSLBHk29jmdXiCdXSlVWAjoqmIJd2KN64M/0nyAwtIUy/i8xlk2oxwn0Rk5nAPO0uHIAxueKUSXRP+JkTxb4cbqZfsrBsdfMQMXtfzMlHWmEtilelxmG7kX84JFC4tAg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1758186402; 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=pqfRQ067MTXlhpiApA/O5AhvYOqW/Et1SaeOJrD+ToE=; b=ewOY09bBMolHjGjplwy0QtCT03Vk8xozGRrRc+8OFqtEDLqHk7AGWj6IKEA6TrZUU91Bw1bHrTbpR7WS+EHM02plv223qt46cc3OuvbD6zaNwKAhTNfLtPZRifcQd/EU2engTTwpTWgUlnGJu8HeVe0Sh6RFEpu8vRg4NNtDCRk= 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 17581864026171020.9467981926726; Thu, 18 Sep 2025 02:06:42 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uzAVm-00059u-8H; Thu, 18 Sep 2025 05:01:06 -0400 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 1uzAVC-0004pM-03 for qemu-devel@nongnu.org; Thu, 18 Sep 2025 05:00:39 -0400 Received: from mgamail.intel.com ([192.198.163.8]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uzAUz-0004rh-Ra for qemu-devel@nongnu.org; Thu, 18 Sep 2025 05:00:28 -0400 Received: from fmviesa009.fm.intel.com ([10.60.135.149]) by fmvoesa102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Sep 2025 02:00:00 -0700 Received: from unknown (HELO gnr-sp-2s-612.sh.intel.com) ([10.112.230.229]) by fmviesa009-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Sep 2025 01:59:57 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1758186018; x=1789722018; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=5aArkkeQfXXiaOg1+MuqtlNaHWQhDbD4d91svuiT+64=; b=kFXb1VuMANLJMaCL/yMno6ROgAzbyG04OOz7ncBChimLV4vYJO0UiDLD 1p6uzQkX1r2Sga1zf7r4GiNvGm6jJ5CNtUmflYl2CZOrBT7JK8tuKMoEh W2Af7fM0ztzvheySDlUA1WAFvYOl9Rh/yzNkEOvzzs9LoMfqvfA45umgd uuVkcBzJ3aA8Nbo4MCqmJjzvqwXhhTRl2pDtMpz6aCWfSlEQ41X+y+Veh NeHdYPvSFnMvAjL82+k7v+GAkWoHWozxH6vS6jl69Elia0BlAo7H21iBX WBmYAjoaOZ+7KLxS8RoNrJM9NBKy6Dr854XP8uHMWDa9Sce/z4puja9VG A==; X-CSE-ConnectionGUID: eIYt+28NQMuhPvqf0sO1bQ== X-CSE-MsgGUID: m3/DDQutTMi6L8AnVTStAQ== X-IronPort-AV: E=McAfee;i="6800,10657,11556"; a="78109615" X-IronPort-AV: E=Sophos;i="6.18,274,1751266800"; d="scan'208";a="78109615" X-CSE-ConnectionGUID: MLyoMeKsRR++2mwBufE5lA== X-CSE-MsgGUID: +t3Ipgc1TV6xnAbjYJoqeA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.18,274,1751266800"; d="scan'208";a="175930638" From: Zhenzhong Duan To: qemu-devel@nongnu.org Cc: alex.williamson@redhat.com, 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 v6 22/22] docs/devel: Add IOMMUFD nesting documentation Date: Thu, 18 Sep 2025 04:58:01 -0400 Message-ID: <20250918085803.796942-23-zhenzhong.duan@intel.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250918085803.796942-1-zhenzhong.duan@intel.com> References: <20250918085803.796942-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=192.198.163.8; 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_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_PASS=-0.001, T_SPF_HELO_TEMPERROR=0.01 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: 1758186403295116600 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 --- docs/devel/vfio-iommufd.rst | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/docs/devel/vfio-iommufd.rst b/docs/devel/vfio-iommufd.rst index 3d1c11f175..d9cb9e7f5e 100644 --- a/docs/devel/vfio-iommufd.rst +++ b/docs/devel/vfio-iommufd.rst @@ -164,3 +164,27 @@ 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 with 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, +or else 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 u= nder PCI bridge is unsupported when x-flts=3Don + +If host IOMMU has ERRATA_772415_SPR17, kexec or reboot from "intel_iommu= =3Don,sm_on" +to "intel_iommu=3Don,sm_off" in guest is also unsupported. Configure scala= ble mode +off as below if it's not needed by guest. + +.. code-block:: bash + -device intel-iommu,x-scalable-mode=3Doff --=20 2.47.1