From nobody Mon Feb 9 08:42:34 2026 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=1767680942; cv=none; d=zohomail.com; s=zohoarc; b=DMpyB+UpK2LN8kPDB62UaOeJxX/I+YmiI1igNVR4coxAivmsOkufd3zMeuzDNrlnFRWctf8zN2b3n7a1ieJswVkzJ0hRqhI2NYo8k3M/RK5bPHc0oFaT2M6M/uTC6FdRADYI+qTktibE4L+RfbcZQrNweoSoUrNJ/Iwnfcl1ylM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1767680942; 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=wFVSPCbn11f+QIM9D3p8TmDdJ857w1BlAd1gZWGjN8M=; b=QG7/Yqy2VlbZLdQl2iYLn6ecz1pmj7cjH6/na+ZozaGm6sv9eNm4eQ7HUSSr4wsOtF/KrlYvQaYMuqvSbS2WUgTBDdBT20wLX08fUymgyVxX3Q/aSLrtsha3Oo7GlwMZJ1iLxfmtTqeKNPWMY3imRW58sJOCVbbTVC3ntPdZ+r4= 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 1767680942163720.3336058182643; Mon, 5 Jan 2026 22:29:02 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vd0Ya-0007Db-7b; Tue, 06 Jan 2026 01:28:41 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vd0YN-000756-A2 for qemu-devel@nongnu.org; Tue, 06 Jan 2026 01:28:28 -0500 Received: from mgamail.intel.com ([198.175.65.17]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vd0YK-00035b-Ub for qemu-devel@nongnu.org; Tue, 06 Jan 2026 01:28:27 -0500 Received: from orviesa009.jf.intel.com ([10.64.159.149]) by orvoesa109.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Jan 2026 22:28:23 -0800 Received: from unknown (HELO gnr-sp-2s-612.sh.intel.com) ([10.112.230.229]) by orviesa009-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Jan 2026 22:28:19 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1767680905; x=1799216905; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=8ydPNtiHPPIK4sls1idtaAM8NYnKKaTPn4tEYgzOSQs=; b=c/VEpQFbCqmci3xJ/5hTdBdLTomU4kcii9/KjJTo1/JhtkEKgTeIsZwH VxnwA5qLShkdGkge8qtwvUxkWrpncCDOZEP2rY42M/Bk8T266wsMP3sFQ PlfC6oIt/42rs6JoXS3puGiN8sFhQ6GMSYvHxHs6qYAv84Uce0HVHvVBC lWGoLZ8BqoI1Jr72Et7ulOBUMq82DxygnANl3Qy2MR+sllSRACJy6rxyl N9nBu1yHxALlJsFQnLt0dW00c/AgrLEMjHKZjJUUAHuu6bdz8zQQ2rIp7 5429zcGI1d9foxv6eCb3IlQPPC1Syd0Gm2onXgfHEV80S4wEKuH8OitUP Q==; X-CSE-ConnectionGUID: IcpCdRysTKekXXOF7X2oZQ== X-CSE-MsgGUID: Ww89S1AcQXuVrQ2NjsNbGA== X-IronPort-AV: E=McAfee;i="6800,10657,11662"; a="69025406" X-IronPort-AV: E=Sophos;i="6.21,204,1763452800"; d="scan'208";a="69025406" X-CSE-ConnectionGUID: 61Xge1bBTyemFkGxvNIwuQ== X-CSE-MsgGUID: zzwyS9Z0QHa2h/ehrWGztg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.21,204,1763452800"; d="scan'208";a="202346085" From: Zhenzhong Duan To: qemu-devel@nongnu.org Cc: alex@shazbot.org, clg@redhat.com, eric.auger@redhat.com, mst@redhat.com, jasowang@redhat.com, peterx@redhat.com, ddutile@redhat.com, jgg@nvidia.com, nicolinc@nvidia.com, skolothumtho@nvidia.com, joao.m.martins@oracle.com, clement.mathieu--drif@eviden.com, kevin.tian@intel.com, yi.l.liu@intel.com, chao.p.peng@intel.com, Zhenzhong Duan Subject: [PATCH v10 1/4] hw/pci: Introduce pci_device_get_host_iommu_quirks() Date: Tue, 6 Jan 2026 01:28:03 -0500 Message-ID: <20260106062808.316574-2-zhenzhong.duan@intel.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20260106062808.316574-1-zhenzhong.duan@intel.com> References: <20260106062808.316574-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 (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=198.175.65.17; 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: 1767680944798158500 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 retrieve this raw data in VFIO core. Introduce a new PCIIOMMUOps optional callback, get_host_iommu_quirk() which allows to retrieve the vendor specific hardware information data and convert it into bitmaps defined with enum host_iommu_quirks. pci_device_get_host_iommu_quirks() is a wrapper that can be called on a PCI device potentially protected by a vIOMMU. Suggested-by: Eric Auger Suggested-by: Nicolin Chen Signed-off-by: Zhenzhong Duan Reviewed-by: C=C3=A9dric Le Goater --- include/hw/core/iommu.h | 5 +++++ include/hw/pci/pci.h | 31 +++++++++++++++++++++++++++++++ hw/pci/pci.c | 12 ++++++++++++ 3 files changed, 48 insertions(+) diff --git a/include/hw/core/iommu.h b/include/hw/core/iommu.h index 9b8bb94fc2..6d61410703 100644 --- a/include/hw/core/iommu.h +++ b/include/hw/core/iommu.h @@ -22,4 +22,9 @@ enum viommu_flags { VIOMMU_FLAG_WANT_NESTING_PARENT =3D BIT_ULL(0), }; =20 +/* Host IOMMU quirks. Extracted from host IOMMU capabilities */ +enum host_iommu_quirks { + HOST_IOMMU_QUIRK_NESTING_PARENT_BYPASS_RO =3D BIT_ULL(0), +}; + #endif /* HW_IOMMU_H */ diff --git a/include/hw/pci/pci.h b/include/hw/pci/pci.h index 868817cc05..6fd8984c99 100644 --- a/include/hw/pci/pci.h +++ b/include/hw/pci/pci.h @@ -474,6 +474,23 @@ typedef struct PCIIOMMUOps { * enum viommu_flags. */ uint64_t (*get_viommu_flags)(void *opaque); + /** + * @get_host_iommu_quirks: get host IOMMU quirks + * + * Optional callback, if not implemented, then vIOMMU doesn't support + * converting @type specific hardware information data into a standard + * bitmap format. + * + * @type: IOMMU hardware info type + * + * @caps: IOMMU @type specific hardware information data + * + * @size: size of @caps + * + * Returns: bitmap with each bit representing a host IOMMU quirk defin= ed in + * enum host_iommu_quirks + */ + uint64_t (*get_host_iommu_quirks)(uint32_t type, void *caps, uint32_t = size); /** * @get_iotlb_info: get properties required to initialize a device IOT= LB. * @@ -666,6 +683,20 @@ void pci_device_unset_iommu_device(PCIDevice *dev); */ uint64_t pci_device_get_viommu_flags(PCIDevice *dev); =20 +/** + * pci_device_get_host_iommu_quirks: get host IOMMU quirks. + * + * Returns: bitmap with each bit representing a host IOMMU quirk defined in + * enum host_iommu_quirks. Or 0 if vIOMMU doesn't convert any. + * + * @dev: PCI device pointer. + * @type: IOMMU hardware info type + * @caps: IOMMU @type specific hardware information data + * @size: size of @caps + */ +uint64_t pci_device_get_host_iommu_quirks(PCIDevice *dev, uint32_t type, + void *caps, uint32_t size); + /** * 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 a136e772a3..8cbf5f5d70 100644 --- a/hw/pci/pci.c +++ b/hw/pci/pci.c @@ -3032,6 +3032,18 @@ uint64_t pci_device_get_viommu_flags(PCIDevice *dev) return 0; } =20 +uint64_t pci_device_get_host_iommu_quirks(PCIDevice *dev, uint32_t type, + void *caps, uint32_t size) +{ + PCIBus *iommu_bus; + + pci_device_get_iommu_bus_devfn(dev, &iommu_bus, NULL, NULL); + if (iommu_bus && iommu_bus->iommu_ops->get_host_iommu_quirks) { + return iommu_bus->iommu_ops->get_host_iommu_quirks(type, caps, siz= e); + } + return 0; +} + int pci_pri_request_page(PCIDevice *dev, uint32_t pasid, bool priv_req, bool exec_req, hwaddr addr, bool lpig, uint16_t prgi, bool is_read, bool is_write) --=20 2.47.1 From nobody Mon Feb 9 08:42:34 2026 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=1767680985; cv=none; d=zohomail.com; s=zohoarc; b=bHiJ/xZaBXcQE/guD6VHKtKpDTCIkqreag/xs9ixJdrX77sCol+IRtQEt1wMyVMZ0S7LBQHltlfPuXop9HrWI5Y9/moWfJ2QF1XJ1Qm5o+K1icUBCIv3dy3qC6YVKGdwxwvaM1IMuRtlTK6r+e/Wz6Xvj//Afob6RTxftggfyZU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1767680985; 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=OO3dUPrU7YYuoif1qde0joUTXV8CcAuQqDpqB/emkMw=; b=B4jcaNM+YqLyeOaxxHhOPAIzE3Xm+0xP4vVcsND3nBC1zYfTTpeD7kBd2xyKVXit3XCO991h7xSSb6aMBqVrR0v2zwRmUvW9o+ITpI4hUfQa8U/HqDZdyxCaBS36RH6LN6HkIwAu+onk4G4HYC5Iz4woqXPfQgaG5IAGxCHwnGw= 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 1767680985356383.45213162508605; Mon, 5 Jan 2026 22:29:45 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vd0Yg-0007H9-Ti; Tue, 06 Jan 2026 01:28:47 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vd0YS-00079O-FS for qemu-devel@nongnu.org; Tue, 06 Jan 2026 01:28:34 -0500 Received: from mgamail.intel.com ([198.175.65.17]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vd0YP-00036J-DC for qemu-devel@nongnu.org; Tue, 06 Jan 2026 01:28:30 -0500 Received: from orviesa009.jf.intel.com ([10.64.159.149]) by orvoesa109.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Jan 2026 22:28:27 -0800 Received: from unknown (HELO gnr-sp-2s-612.sh.intel.com) ([10.112.230.229]) by orviesa009-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Jan 2026 22:28:24 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1767680909; x=1799216909; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=96lneYKLZsMOh+cDtpoWjfEObWa/iE8+8j0Li0F8f7I=; b=KwV1Mqj/0vdMe7YCxqF4IslD7HPx2cQkid2yVZxA7BN7ftgtH85LlkMf Asc7FtaBPvMrYpXOsg1Q24ZkXhTYtHsTziKTfP+qRYTwwD6Q9ebO/F344 oMRSryCjCmkkItoQ/InPpZEF+tbZZrPNCnGduop7UnxMlz7hfC1xw4/LV 13YCkbR2/WmzV/daor3SaMFZG4R4/gMIuMpXK1kBx5jKpI4StWYZveiT6 pDGvpkEilXPhLYez8smLlMwCxTO7fa0iPf4C5tlwI4WusxDL3whLLGSXt Te7OgI345JT8gqlwJ37e11hQlMlRgNUemVTggZn5su8R6JT7yJmeefydu Q==; X-CSE-ConnectionGUID: TqQMMJLLQa2w1PWOrGiMwg== X-CSE-MsgGUID: CTj94WnvQ4iCJm6MtajEPQ== X-IronPort-AV: E=McAfee;i="6800,10657,11662"; a="69025413" X-IronPort-AV: E=Sophos;i="6.21,204,1763452800"; d="scan'208";a="69025413" X-CSE-ConnectionGUID: f9Nc6yZ0Qiybobz4xMECdA== X-CSE-MsgGUID: HghobdCMSmaoyrRaJ0+llw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.21,204,1763452800"; d="scan'208";a="202346111" From: Zhenzhong Duan To: qemu-devel@nongnu.org Cc: alex@shazbot.org, clg@redhat.com, eric.auger@redhat.com, mst@redhat.com, jasowang@redhat.com, peterx@redhat.com, ddutile@redhat.com, jgg@nvidia.com, nicolinc@nvidia.com, skolothumtho@nvidia.com, joao.m.martins@oracle.com, clement.mathieu--drif@eviden.com, kevin.tian@intel.com, yi.l.liu@intel.com, chao.p.peng@intel.com, Zhenzhong Duan Subject: [PATCH v10 2/4] intel_iommu_accel: Implement get_host_iommu_quirks() callback Date: Tue, 6 Jan 2026 01:28:04 -0500 Message-ID: <20260106062808.316574-3-zhenzhong.duan@intel.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20260106062808.316574-1-zhenzhong.duan@intel.com> References: <20260106062808.316574-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 (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=198.175.65.17; 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: 1767680986559158500 Content-Type: text/plain; charset="utf-8" Implement get_host_iommu_quirks() callback to retrieve the vendor specific hardware information data and convert it into bitmaps defined with enum host_iommu_quirks. It will be used by VFIO in subsequent patch. Suggested-by: Eric Auger Suggested-by: Nicolin Chen Signed-off-by: Zhenzhong Duan Reviewed-by: C=C3=A9dric Le Goater --- hw/i386/intel_iommu_accel.h | 5 +++++ hw/i386/intel_iommu.c | 2 ++ hw/i386/intel_iommu_accel.c | 21 +++++++++++++++++++++ 3 files changed, 28 insertions(+) diff --git a/hw/i386/intel_iommu_accel.h b/hw/i386/intel_iommu_accel.h index 3b0ecc7e22..b19db6b63b 100644 --- a/hw/i386/intel_iommu_accel.h +++ b/hw/i386/intel_iommu_accel.h @@ -20,6 +20,7 @@ bool vtd_propagate_guest_pasid(VTDAddressSpace *vtd_as, E= rror **errp); void vtd_flush_host_piotlb_all_locked(IntelIOMMUState *s, uint16_t domain_= id, uint32_t pasid, hwaddr addr, uint64_t npages, bool ih); +void vtd_iommu_ops_update_accel(PCIIOMMUOps *ops); #else static inline bool vtd_check_hiod_accel(IntelIOMMUState *s, VTDHostIOMMUDevice *vtd_hiod, @@ -47,5 +48,9 @@ static inline void vtd_flush_host_piotlb_all_locked(Intel= IOMMUState *s, uint64_t npages, bool = ih) { } + +static inline void vtd_iommu_ops_update_accel(PCIIOMMUOps *ops) +{ +} #endif #endif diff --git a/hw/i386/intel_iommu.c b/hw/i386/intel_iommu.c index bb21ae1743..e8a6f50a5a 100644 --- a/hw/i386/intel_iommu.c +++ b/hw/i386/intel_iommu.c @@ -5590,6 +5590,8 @@ static void vtd_class_init(ObjectClass *klass, const = void *data) x86_class->int_remap =3D vtd_int_remap; set_bit(DEVICE_CATEGORY_MISC, dc->categories); dc->desc =3D "Intel IOMMU (VT-d) DMA Remapping device"; + + vtd_iommu_ops_update_accel(&vtd_iommu_ops); } =20 static const TypeInfo vtd_info =3D { diff --git a/hw/i386/intel_iommu_accel.c b/hw/i386/intel_iommu_accel.c index 89f3d55f6f..e1e668b8e0 100644 --- a/hw/i386/intel_iommu_accel.c +++ b/hw/i386/intel_iommu_accel.c @@ -12,6 +12,7 @@ #include "system/iommufd.h" #include "intel_iommu_internal.h" #include "intel_iommu_accel.h" +#include "hw/core/iommu.h" #include "hw/pci/pci_bus.h" #include "trace.h" =20 @@ -249,3 +250,23 @@ void vtd_flush_host_piotlb_all_locked(IntelIOMMUState = *s, uint16_t domain_id, g_hash_table_foreach(s->vtd_address_spaces, vtd_flush_host_piotlb_locked, &piotlb_info); } + +static uint64_t vtd_get_host_iommu_quirks(uint32_t type, + void *caps, uint32_t size) +{ + struct iommu_hw_info_vtd *vtd =3D caps; + uint64_t quirks =3D 0; + + if (type =3D=3D IOMMU_HW_INFO_TYPE_INTEL_VTD && + sizeof(struct iommu_hw_info_vtd) <=3D size && + vtd->flags & IOMMU_HW_INFO_VTD_ERRATA_772415_SPR17) { + quirks |=3D HOST_IOMMU_QUIRK_NESTING_PARENT_BYPASS_RO; + } + + return quirks; +} + +void vtd_iommu_ops_update_accel(PCIIOMMUOps *ops) +{ + ops->get_host_iommu_quirks =3D vtd_get_host_iommu_quirks; +} --=20 2.47.1 From nobody Mon Feb 9 08:42:34 2026 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=1767680946; cv=none; d=zohomail.com; s=zohoarc; b=bXVO633RPM21t5gDpUni2uzhVyC7xaxcINUBZZpkAR7yE4Rpm0hrmCmB9B3sbdL1QhsCDVa4V1XCRg/eCw9nCevMA6yg7H8q7CosiKhBGv2qz+GxCqwjXZix0/KZQgETksr+9nIWT5tqeNxF2G6awr9+08LDJL8ewOoCNEKIFO8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1767680946; 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=C0YocFMjIDXYw2ISZZgqBKYcS4Snndo7ly2sox3T2u8=; b=YiVF3YJvVJ8Gep+YN8aEG5ULFISgTCZ/9q51Pb3zqPqFV4J4pxAvQ2sQ8AMwRW+61ZRd3IZWRv+4oIsUtdTEMTMUhkVKuTQDE9m8qx9ztXlwh+FwvoE0j0vR5kQnXB0btWyyXQHi0fJqXO8sGs/9hgsZIVqpGa454GguTeZ+he4= 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 1767680946833744.6571561031659; Mon, 5 Jan 2026 22:29:06 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vd0Yj-0007I7-G2; Tue, 06 Jan 2026 01:28:49 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vd0Yb-0007FC-Od for qemu-devel@nongnu.org; Tue, 06 Jan 2026 01:28:43 -0500 Received: from mgamail.intel.com ([198.175.65.17]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vd0YX-00036J-RH for qemu-devel@nongnu.org; Tue, 06 Jan 2026 01:28:41 -0500 Received: from orviesa009.jf.intel.com ([10.64.159.149]) by orvoesa109.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Jan 2026 22:28:32 -0800 Received: from unknown (HELO gnr-sp-2s-612.sh.intel.com) ([10.112.230.229]) by orviesa009-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Jan 2026 22:28:28 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1767680918; x=1799216918; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=zfgBGXYiMLAlSpRYihmmTIFmYkA/gPtpGXv1sHyeR0k=; b=VD3c1EyyMnFpXbkrBNO7fCL9+i/bVrIZfBalxGFsmHwJ6VAPE2BV8bwR 1AuMewv8pXkqFJvPWuc92k/uuU1z+9o654Ilh3mwiBsWm+ZMyge7PkL/b 2PGuBYpo8P40QNFMl5tZNQMo48eUzyh0Uq+KZmiKrNWFsUUmGQkCaOW9b rUHDy72XFJwmiUA3rTsD15jDpMTIw+hzbzzDYF4Qygbn/OB1cWzfcMEUj GTWTRvBDjm09mvFiVpuVIvGEBDWrIekxyKxDFemraCC6qzz1TMvBBCkJN vXDNXMV31xhXNmfxh2T1faL3NK3kvutLQRm+pJJvvGzObubD7chPShI25 w==; X-CSE-ConnectionGUID: qMGi47XETbCwedxjjrf6yg== X-CSE-MsgGUID: CVrWk0nUQHiHMuVITkJz/Q== X-IronPort-AV: E=McAfee;i="6800,10657,11662"; a="69025422" X-IronPort-AV: E=Sophos;i="6.21,204,1763452800"; d="scan'208";a="69025422" X-CSE-ConnectionGUID: gu/KpsnfSAu+P0G6jRideg== X-CSE-MsgGUID: Up2kDWJaSGO1rcP+RJC/4g== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.21,204,1763452800"; d="scan'208";a="202346124" From: Zhenzhong Duan To: qemu-devel@nongnu.org Cc: alex@shazbot.org, clg@redhat.com, eric.auger@redhat.com, mst@redhat.com, jasowang@redhat.com, peterx@redhat.com, ddutile@redhat.com, jgg@nvidia.com, nicolinc@nvidia.com, skolothumtho@nvidia.com, joao.m.martins@oracle.com, clement.mathieu--drif@eviden.com, kevin.tian@intel.com, yi.l.liu@intel.com, chao.p.peng@intel.com, Zhenzhong Duan Subject: [PATCH v10 3/4] vfio/listener: Bypass readonly region for dirty tracking Date: Tue, 6 Jan 2026 01:28:05 -0500 Message-ID: <20260106062808.316574-4-zhenzhong.duan@intel.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20260106062808.316574-1-zhenzhong.duan@intel.com> References: <20260106062808.316574-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 (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=198.175.65.17; 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: 1767680948262158500 Content-Type: text/plain; charset="utf-8" When doing dirty tracking or calculating dirty tracking range, readonly regions can be bypassed, because corresponding DMA mappings are readonly and never become dirty. This can optimize dirty tracking a bit for passthrough device. Signed-off-by: Zhenzhong Duan Reviewed-by: C=C3=A9dric Le Goater --- hw/vfio/listener.c | 48 ++++++++++++++++++++++++++++++++++---------- hw/vfio/trace-events | 1 + 2 files changed, 38 insertions(+), 11 deletions(-) diff --git a/hw/vfio/listener.c b/hw/vfio/listener.c index 813621f22f..f193468dee 100644 --- a/hw/vfio/listener.c +++ b/hw/vfio/listener.c @@ -76,8 +76,13 @@ static bool vfio_log_sync_needed(const VFIOContainer *bc= ontainer) 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,7 @@ void vfio_container_region_add(VFIOContainer *bcontaine= r, int ret; Error *err =3D NULL; =20 - if (!vfio_listener_valid_section(section, "region_add")) { + if (!vfio_listener_valid_section(section, false, "region_add")) { return; } =20 @@ -663,7 +668,7 @@ 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, false, "region_del")) { return; } =20 @@ -722,9 +727,10 @@ static void vfio_listener_region_del(MemoryListener *l= istener, } =20 /* - * Fake an IOTLB entry for identity mapping which is needed by dir= ty - * tracking when switch out of PT domain. In fact, in unmap_bitmap, - * only translated_addr field is used to set dirty bitmap. + * Fake an IOTLB entry for writable identity mapping which is need= ed + * by dirty tracking when switch out of PT domain. In fact, in + * unmap_bitmap, only translated_addr field is used to set dirty + * bitmap. * * Note: When switch into PT domain from DMA domain, the whole IOM= MU * MR is deleted without iotlb, before that happen, we depend on @@ -733,7 +739,8 @@ static void vfio_listener_region_del(MemoryListener *li= stener, * it is triggered during switching to block domain because vtd do= es * not support direct switching from DMA to PT domain. */ - if (global_dirty_tracking && memory_region_is_ram(section->mr)) { + if (global_dirty_tracking && memory_region_is_ram(section->mr) && + !section->readonly) { entry.iova =3D iova; entry.translated_addr =3D iova; iotlb =3D &entry; @@ -841,7 +848,8 @@ 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") || + /* Bypass readonly section as it never becomes dirty */ + if (!vfio_listener_valid_section(section, true, "tracking_update") || !vfio_get_section_iova_range(dirty->bcontainer, section, &iova, &end, NULL)) { return; @@ -1100,6 +1108,19 @@ static void vfio_iommu_map_dirty_notify(IOMMUNotifie= r *n, IOMMUTLBEntry *iotlb) if (!mr) { goto out_unlock; } + + /* + * The mapping is readonly when either it's a readonly mapping in guest + * or mapped target is readonly, bypass it for dirty tracking as it + * never becomes dirty. + */ + if (!(iotlb->perm & IOMMU_WO) || mr->readonly) { + trace_vfio_iommu_map_dirty_notify_skip_ro(iova, + iova + iotlb->addr_mask); + rcu_read_unlock(); + return; + } + translated_addr =3D memory_region_get_ram_addr(mr) + xlat; =20 ret =3D vfio_container_query_dirty_bitmap(bcontainer, iova, iotlb->add= r_mask + 1, @@ -1235,7 +1256,12 @@ static void vfio_listener_log_sync(MemoryListener *l= istener, int ret; Error *local_err =3D NULL; =20 - if (vfio_listener_skipped_section(section)) { + /* + * Bypass readonly section as it never becomes dirty, iommu memory sec= tion + * is RW and never bypassed. The readonly mappings in iommu MR are byp= assed + * in vfio_iommu_map_dirty_notify(). + */ + if (vfio_listener_skipped_section(section, true)) { return; } =20 diff --git a/hw/vfio/trace-events b/hw/vfio/trace-events index 3c62bab764..180e3d526b 100644 --- a/hw/vfio/trace-events +++ b/hw/vfio/trace-events @@ -103,6 +103,7 @@ vfio_listener_region_del(uint64_t start, uint64_t end) = "region_del 0x%"PRIx64" - vfio_device_dirty_tracking_update(uint64_t start, uint64_t end, uint64_t m= in, uint64_t max) "section 0x%"PRIx64" - 0x%"PRIx64" -> update [0x%"PRIx64"= - 0x%"PRIx64"]" vfio_device_dirty_tracking_start(int nr_ranges, uint64_t min32, uint64_t m= ax32, uint64_t min64, uint64_t max64, uint64_t minpci, uint64_t maxpci) "nr= _ranges %d 32:[0x%"PRIx64" - 0x%"PRIx64"], 64:[0x%"PRIx64" - 0x%"PRIx64"], = pci64:[0x%"PRIx64" - 0x%"PRIx64"]" vfio_iommu_map_dirty_notify(uint64_t iova_start, uint64_t iova_end) "iommu= dirty @ 0x%"PRIx64" - 0x%"PRIx64 +vfio_iommu_map_dirty_notify_skip_ro(uint64_t iova_start, uint64_t iova_end= ) "iommu dirty @ 0x%"PRIx64" - 0x%"PRIx64 =20 # container.c vfio_container_query_dirty_bitmap(uint64_t iova, uint64_t size, uint64_t b= ackend_flag, uint64_t bitmap_size, uint64_t translated_addr, uint64_t dirty= _pages) "iova=3D0x%"PRIx64" size=3D0x%"PRIx64" backend_flag=3D0x%"PRIx64" b= itmap_size=3D0x%"PRIx64" gpa=3D0x%"PRIx64" dirty_pages=3D%"PRIu64 --=20 2.47.1 From nobody Mon Feb 9 08:42:34 2026 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=1767680943; cv=none; d=zohomail.com; s=zohoarc; b=eeXJLwUwWZwFNq20gIaFiaCDiN5W2IAa7nND2GZZxXcmtXuNmTceeVj3PZ1iMSZve94oCdSHhhSoNBlwJ0c4if77BeTW50GIrawv/UjJ8re2cD4aYxmOBvd1x30b5xJ7cA37rMSDEmduUCxcsi7Ow9sMGBg9VtbnbTJC9/nz3cs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1767680943; 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=zIlrfjvHPLVbrHz8BQ+Vk7TqrcmbK9+PxvP7zyBdiRs=; b=KnxrE9RafmmblZyLz0cNHNxWKEmFURFs6vkHEJiRSXfKN57iueuABeQCg/qk5ZEZBX1U23ToZxN2DPPvcMCum3lhv7+TcOAVPLLn183BrreJoPHm9+0CVOH8+UNHX6CPhMwJdo6GRo8XlJMRlR/+ZjQLrFnXK0y7Kxv9tCzvPrE= 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 1767680943517643.2291009845827; Mon, 5 Jan 2026 22:29:03 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vd0Yl-0007L3-8T; Tue, 06 Jan 2026 01:28:51 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vd0Yd-0007FT-8L for qemu-devel@nongnu.org; Tue, 06 Jan 2026 01:28:43 -0500 Received: from mgamail.intel.com ([198.175.65.17]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vd0YX-00036X-W0 for qemu-devel@nongnu.org; Tue, 06 Jan 2026 01:28:41 -0500 Received: from orviesa009.jf.intel.com ([10.64.159.149]) by orvoesa109.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Jan 2026 22:28:36 -0800 Received: from unknown (HELO gnr-sp-2s-612.sh.intel.com) ([10.112.230.229]) by orviesa009-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Jan 2026 22:28:32 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1767680918; x=1799216918; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=B4SFUiNS4ZBT6eaE6xNWbkXFzOzwS2oRkoe054wIUqY=; b=Ro9+S1mS2rB5lo0z2Qd+PQG7GN7Ey3wzla0bAxzBZO70gTf67h3BPL9J SyM817gx2jSyLlgmQ5vnlWNLc52LC68KAhCf5bUhbwYJlWVTPhERbeBA3 xoubo/bDKuDvFnaZGanakMUoCUgH3zMnOfkPjbXWBT5p+u5vCHr5M4jqu SrEvcqmbZnTOfwz0RoJnU3OrFOnwbNvVGMxsbAfUiOMQnQYd9v/wlMAEz wq96P91aqBvVCVTVhIOfM088yQUP05vr/kbzTqi9RFxVIDWgvToxcZhu5 o5mgkvKDFgbuyvePeyywhl1Zxnko3o3EhcQHIzqbzHUwrtrX5XeXvopNK w==; X-CSE-ConnectionGUID: MFwyH5/CSzWeHo1YgIBirg== X-CSE-MsgGUID: +59lO68GQnGDFdxns7307Q== X-IronPort-AV: E=McAfee;i="6800,10657,11662"; a="69025429" X-IronPort-AV: E=Sophos;i="6.21,204,1763452800"; d="scan'208";a="69025429" X-CSE-ConnectionGUID: dmW0eVngSw2JolVcvJiHdg== X-CSE-MsgGUID: ZIEu7Jd5TRuQrzOWYmTk3g== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.21,204,1763452800"; d="scan'208";a="202346137" From: Zhenzhong Duan To: qemu-devel@nongnu.org Cc: alex@shazbot.org, clg@redhat.com, eric.auger@redhat.com, mst@redhat.com, jasowang@redhat.com, peterx@redhat.com, ddutile@redhat.com, jgg@nvidia.com, nicolinc@nvidia.com, skolothumtho@nvidia.com, joao.m.martins@oracle.com, clement.mathieu--drif@eviden.com, kevin.tian@intel.com, yi.l.liu@intel.com, chao.p.peng@intel.com, Zhenzhong Duan Subject: [PATCH v10 4/4] Workaround for ERRATA_772415_SPR17 Date: Tue, 6 Jan 2026 01:28:06 -0500 Message-ID: <20260106062808.316574-5-zhenzhong.duan@intel.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20260106062808.316574-1-zhenzhong.duan@intel.com> References: <20260106062808.316574-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 (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=198.175.65.17; 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: 1767680944851158500 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. Link https://edc.intel.com/content/www/us/en/design/products-and-solutions/= processors-and-chipsets/eagle-stream/sapphire-rapids-specification-update/ Backup https://cdrdv2.intel.com/v1/dl/getContent/772415 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." Introduce a helper vfio_device_get_host_iommu_quirk_bypass_ro to check if readonly mappings should be bypassed. Signed-off-by: Zhenzhong Duan Reviewed-by: C=C3=A9dric Le Goater --- docs/devel/vfio-iommufd.rst | 9 +++++++++ include/hw/vfio/vfio-container.h | 1 + include/hw/vfio/vfio-device.h | 3 +++ hw/vfio/device.c | 14 ++++++++++++++ hw/vfio/iommufd.c | 9 ++++++++- hw/vfio/listener.c | 6 ++++-- 6 files changed, 39 insertions(+), 3 deletions(-) diff --git a/docs/devel/vfio-iommufd.rst b/docs/devel/vfio-iommufd.rst index cbf59924ba..0ee50339a5 100644 --- a/docs/devel/vfio-iommufd.rst +++ b/docs/devel/vfio-iommufd.rst @@ -181,3 +181,12 @@ otherwise below error shows: .. code-block:: none =20 qemu-system-x86_64: -device vfio-pci,host=3D0000:02:00.0,bus=3Dbridge1= ,iommufd=3Diommufd0: vfio 0000:02:00.0: Failed to set vIOMMU: Host device d= ownstream to a PCI bridge is unsupported when x-flts=3Don + +If host IOMMU has ERRATA_772415_SPR17, running guest with "intel_iommu=3Do= n,sm_off" +is unsupported, kexec or reboot guest from "intel_iommu=3Don,sm_on" to +"intel_iommu=3Don,sm_off" is also unsupported. Configure scalable mode off= as +below if it's not needed by guest: + +.. code-block:: bash + + -device intel-iommu,x-scalable-mode=3Doff diff --git a/include/hw/vfio/vfio-container.h b/include/hw/vfio/vfio-contai= ner.h index 9f6e8cedfc..a7d5c5ed67 100644 --- a/include/hw/vfio/vfio-container.h +++ b/include/hw/vfio/vfio-container.h @@ -52,6 +52,7 @@ struct VFIOContainer { 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/include/hw/vfio/vfio-device.h b/include/hw/vfio/vfio-device.h index 48d00c7bc4..f6f3d0e378 100644 --- a/include/hw/vfio/vfio-device.h +++ b/include/hw/vfio/vfio-device.h @@ -268,6 +268,9 @@ void vfio_device_prepare(VFIODevice *vbasedev, VFIOCont= ainer *bcontainer, void vfio_device_unprepare(VFIODevice *vbasedev); =20 bool vfio_device_get_viommu_flags_want_nesting(VFIODevice *vbasedev); +bool vfio_device_get_host_iommu_quirk_bypass_ro(VFIODevice *vbasedev, + uint32_t type, void *caps, + uint32_t size); =20 int vfio_device_get_region_info(VFIODevice *vbasedev, int index, struct vfio_region_info **info); diff --git a/hw/vfio/device.c b/hw/vfio/device.c index 3bab082322..086f20f676 100644 --- a/hw/vfio/device.c +++ b/hw/vfio/device.c @@ -533,6 +533,20 @@ bool vfio_device_get_viommu_flags_want_nesting(VFIODev= ice *vbasedev) return false; } =20 +bool vfio_device_get_host_iommu_quirk_bypass_ro(VFIODevice *vbasedev, + uint32_t type, void *caps, + uint32_t size) +{ + VFIOPCIDevice *vdev =3D vfio_pci_from_vfio_device(vbasedev); + + if (vdev) { + return !!(pci_device_get_host_iommu_quirks(PCI_DEVICE(vdev), type, + caps, size) & + HOST_IOMMU_QUIRK_NESTING_PARENT_BYPASS_RO); + } + return false; +} + /* * Traditional ioctl() based io */ diff --git a/hw/vfio/iommufd.c b/hw/vfio/iommufd.c index 0bf68620d2..2947e1b80f 100644 --- a/hw/vfio/iommufd.c +++ b/hw/vfio/iommufd.c @@ -351,6 +351,7 @@ static bool iommufd_cdev_autodomains_get(VFIODevice *vb= asedev, VFIOContainer *bcontainer =3D VFIO_IOMMU(container); uint32_t type, flags =3D 0; uint64_t hw_caps; + VendorCaps caps; VFIOIOASHwpt *hwpt; uint32_t hwpt_id; int ret; @@ -396,7 +397,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 @@ -411,6 +413,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 (vfio_device_get_host_iommu_quirk_bypass_ro(vbasedev, type, + &caps, sizeof(caps)= )) { + bcontainer->bypass_ro =3D true; + } } =20 if (cpr_is_incoming()) { diff --git a/hw/vfio/listener.c b/hw/vfio/listener.c index f193468dee..8ba1cd255d 100644 --- a/hw/vfio/listener.c +++ b/hw/vfio/listener.c @@ -502,7 +502,8 @@ void vfio_container_region_add(VFIOContainer *bcontaine= r, int ret; Error *err =3D NULL; =20 - if (!vfio_listener_valid_section(section, false, "region_add")) { + if (!vfio_listener_valid_section(section, bcontainer->bypass_ro, + "region_add")) { return; } =20 @@ -668,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, false, "region_del")) { + if (!vfio_listener_valid_section(section, bcontainer->bypass_ro, + "region_del")) { return; } =20 --=20 2.47.1