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") Cc: stable@vger.kernel.org Signed-off-by: Lu Baolu --- drivers/iommu/intel/iommu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c index 5a2e705a2f2e..a8c0ccae844e 100644 --- a/drivers/iommu/intel/iommu.c +++ b/drivers/iommu/intel/iommu.c @@ -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; } -- 2.43.0