@samitouri / QOSamiQemu / commits / 76330797b0

intel_iommu: Create the nested hwpt with IOMMU_HWPT_ALLOC_PASID flag

When pasid is enabled, any hwpt attached to non-PASID or PASID should be IOMMU_HWPT_ALLOC_PASID flagged, or else attachment fails. Change vtd_destroy_old_fs_hwpt() to pass in 'VTDHostIOMMUDevice *' for naming consistency. Signed-off-by: Zhenzhong Duan <zhenzhong.duan@intel.com> Reviewed-by: Clement Mathieu--Drif <clement.mathieu--drif@bull.com> Reviewed-by: Yi Liu <yi.l.liu@intel.com> Tested-by: Xudong Hao <xudong.hao@intel.com> Reviewed-by: Michael S. Tsirkin <mst@redhat.com> Signed-off-by: Michael S. Tsirkin <mst@redhat.com> Message-Id: <20260527054658.1021096-5-zhenzhong.duan@intel.com>

Zhenzhong Duan committed May 27, 2026 at 01:46 UTC 76330797b0eab06ebe2cbf5c8a21953da71ba4ba
1 file changed +12 -7
hw/i386/intel_iommu_accel.c
+12 -7
@@ -69,11 +69,13 @@ VTDHostIOMMUDevice *vtd_find_hiod_iommufd(VTDAddressSpace *as)
69 return NULL;
70 }
71
72 -static bool vtd_create_fs_hwpt(HostIOMMUDeviceIOMMUFD *hiodi,
72 +static bool vtd_create_fs_hwpt(VTDHostIOMMUDevice *vtd_hiod,
73 VTDPASIDEntry *pe, uint32_t *fs_hwpt_id,
74 Error **errp)
75 {
76 + HostIOMMUDeviceIOMMUFD *hiodi = HOST_IOMMU_DEVICE_IOMMUFD(vtd_hiod->hiod);
77 struct iommu_hwpt_vtd_s1 vtd = {};
78 + uint32_t flags = vtd_hiod->iommu_state->pasid ? IOMMU_HWPT_ALLOC_PASID : 0;
79
80 vtd.flags = (VTD_SM_PASID_ENTRY_SRE(pe) ? IOMMU_VTD_S1_SRE : 0) |
81 (VTD_SM_PASID_ENTRY_WPE(pe) ? IOMMU_VTD_S1_WPE : 0) |
@@ -82,13 +84,16 @@ static bool vtd_create_fs_hwpt(HostIOMMUDeviceIOMMUFD *hiodi,
84 vtd.pgtbl_addr = (uint64_t)vtd_pe_get_fspt_base(pe);
85
86 return iommufd_backend_alloc_hwpt(hiodi->iommufd, hiodi->devid,
85 - hiodi->hwpt_id, 0, IOMMU_HWPT_DATA_VTD_S1,
86 - sizeof(vtd), &vtd, fs_hwpt_id, errp);
87 + hiodi->hwpt_id, flags,
88 + IOMMU_HWPT_DATA_VTD_S1, sizeof(vtd), &vtd,
89 + fs_hwpt_id, errp);
90 }
91
89 -static void vtd_destroy_old_fs_hwpt(HostIOMMUDeviceIOMMUFD *hiodi,
92 +static void vtd_destroy_old_fs_hwpt(VTDHostIOMMUDevice *vtd_hiod,
93 VTDAddressSpace *vtd_as)
94 {
95 + HostIOMMUDeviceIOMMUFD *hiodi = HOST_IOMMU_DEVICE_IOMMUFD(vtd_hiod->hiod);
96 +
97 if (!vtd_as->fs_hwpt_id) {
98 return;
99 }
@@ -116,7 +121,7 @@ static bool vtd_device_attach_iommufd(VTDHostIOMMUDevice *vtd_hiod,
121 }
122
123 if (vtd_pe_pgtt_is_fst(pe)) {
119 - if (!vtd_create_fs_hwpt(hiodi, pe, &hwpt_id, errp)) {
124 + if (!vtd_create_fs_hwpt(vtd_hiod, pe, &hwpt_id, errp)) {
125 return false;
126 }
127 }
@@ -126,7 +131,7 @@ static bool vtd_device_attach_iommufd(VTDHostIOMMUDevice *vtd_hiod,
131 trace_vtd_device_attach_hwpt(hiodi->devid, IOMMU_NO_PASID, hwpt_id, ret);
132 if (ret) {
133 /* Destroy old fs_hwpt if it's a replacement */
129 - vtd_destroy_old_fs_hwpt(hiodi, vtd_as);
134 + vtd_destroy_old_fs_hwpt(vtd_hiod, vtd_as);
135 if (vtd_pe_pgtt_is_fst(pe)) {
136 vtd_as->fs_hwpt_id = hwpt_id;
137 }
@@ -161,7 +166,7 @@ static bool vtd_device_detach_iommufd(VTDHostIOMMUDevice *vtd_hiod,
166 }
167
168 if (ret) {
164 - vtd_destroy_old_fs_hwpt(hiodi, vtd_as);
169 + vtd_destroy_old_fs_hwpt(vtd_hiod, vtd_as);
170 }
171
172 return ret;