Skip to contentSkip to conversation

iommu/vt-d: Block translation before removing IOPF in blocking attach

PATCH New Lu Baolu 1 participant 1 message Nov 23

Subsystems (3)
lore
Share & tools
lore

Lu Baolu

author maintainer
#0 lore raw

PATCH 1/1 iommu/vt-d: Block translation before removing IOPF in blocking attach

blocking_domain_attach_dev() drops the old domain's IOPF reference before it calls device_block_translation(). When that is the last reference, intel_iommu_disable_iopf() calls iopf_queue_remove_device() while the RID still translates through the old domain and its page requests are still being reported. This is wrong in two ways:

- iopf_queue_remove_device() requires that no iommu_report_device_fault() is still running for the device. A report can have linked its group into the pending list without having called the iopf_handler yet; iopf_queue_remove_device() then responds to and frees that group, and the reporter hands the freed group to the handler.

- With iopf_refcount already zero, the drain in device_block_translation() -> intel_pasid_tear_down_entry() -> intel_iommu_drain_pasid_prq() returns early, so the PRQ for the RID is never drained on this path at all.

The removal was placed first by commit 17fce9d2336d ("iommu/vt-d: Put iopf enablement in domain attach path") because the old domain was then taken from info->domain, which device_block_translation() clears. Commit 91b55eb171cb ("iommu/vt-d: Use old domain parameter when attaching the blocking domain") switched to the @old parameter, so the order can now be swapped. Backports need that commit as well.

Fixes 17fce9d2336d ("iommu/vt-d: Put iopf enablement in domain attach path")
---
 drivers/iommu/intel/iommu.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iommu/intel/iommu.c +1 -1
index 5a2e705a2f2e..a8c0ccae844e 100644
@@ -2897,8 +2897,8 @@ static int blocking_domain_attach_dev(struct iommu_domain *domain,
 				      struct device *dev,
 				      struct iommu_domain *old)
 {
-	iopf_for_domain_remove(old, dev);
 	device_block_translation(dev);
+	iopf_for_domain_remove(old, dev);
 	return 0;
 }
 
Signature · 1 line
2.43.0