> From: Lu Baolu <baolu.lu@xxxxxxxxxxxxxxx> > Sent: Thursday, March 9, 2023 10:57 AM > > @@ -4689,17 +4704,21 @@ static int intel_iommu_disable_iopf(struct device > *dev) > { > struct device_domain_info *info = dev_iommu_priv_get(dev); > struct intel_iommu *iommu = info->iommu; > - int ret; > > - ret = iommu_unregister_device_fault_handler(dev); > - if (ret) > - return ret; > + if (!info->pri_enabled) > + return -EINVAL; > > - ret = iopf_queue_remove_device(iommu->iopf_queue, dev); > - if (ret) > - iommu_register_device_fault_handler(dev, > iommu_queue_iopf, dev); > + pci_disable_pri(to_pci_dev(dev)); > + info->pri_enabled = 0; > > - return ret; > + /* > + * With pri_enabled checked, unregistering fault handler and > + * removing device from iopf queue should never fail. > + */ > + iommu_unregister_device_fault_handler(dev); > + iopf_queue_remove_device(iommu->iopf_queue, dev); > + > + return 0; > } PCIe spec says that clearing the enable bit doesn't mean in-fly page requests are completed: -- Enable (E) - This field, when set, indicates that the Page Request Interface is allowed to make page requests. If this field is Clear, the Page Request Interface is not allowed to issue page requests. If both this field and the Stopped field are Clear, then the Page Request Interface will not issue new page requests, but has outstanding page requests that have been transmitted or are queued for transmission