iommu/vt-d: Make intel_iommu_drain_pasid_prq() cover faults for RID
Subsystems (3)
Lu Baolu
maintainerPATCH 1/1 iommu/vt-d: Make intel_iommu_drain_pasid_prq() cover faults for RID
This driver supports page faults on PCI RID since commit <9f831c16c69e> ("iommu/vt-d: Remove the pasid present check in prq_event_thread") by allowing the reporting of page faults with the pasid_present field cleared to the upper layer for further handling. The fundamental assumption here is that the detach or replace operations act as a fence for page faults. This implies that all pending page faults associated with a specific RID or PASID are flushed when a domain is detached or replaced from a device RID or PASID.
However, the intel_iommu_drain_pasid_prq() helper does not correctly handle faults for RID. This leads to faults potentially remaining pending in the iommu hardware queue even after the domain is detached, thereby violating the aforementioned assumption.
Fix this issue by extending intel_iommu_drain_pasid_prq() to cover faults for RID.
--- drivers/iommu/intel/prq.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/iommu/intel/prq.c +2 -1
@@ -87,7 +87,8 @@ void intel_iommu_drain_pasid_prq(struct device *dev, u32 pasid)struct page_req_dsc *req; req = &iommu->prq[head /sizeof (*req)]; -if (!req->pasid_present || req->pasid != pasid) { +if (req->rid != sid || + (req->pasid_present && req->pasid != pasid)) { head = (head +sizeof (*req)) &PRQ_RING_MASK ;continue ; }
Signature · 1 line
2.43.0
Quoted 17 lines
From: Lu Baolu <[email protected]>
Sent: Monday, January 20, 2025 4:02 PMThis driver supports page faults on PCI RID since commit <
9f831c16c69e> ("iommu/vt-d: Remove the pasid present check inprq_event_thread") by allowing the reporting of page faults with thepasid_presentfield cleared to the upper layer for further handling. The fundamental assumption here is that the detach or replace operations act as a fence for page faults. This implies that all pending page faults associated with a specific RID or PASID are flushed when a domain is detached or replaced from a device RID or PASID.However, the
intel_iommu_drain_pasid_prq()helper does not correctly handle faults for RID. This leads to faults potentially remaining pending in the iommu hardware queue even after the domain is detached, thereby violating the aforementioned assumption.
Quoted 8 lines
Fix this issue by extending
intel_iommu_drain_pasid_prq()to cover faults for RID.Fixes 9f831c16c69e ("iommu/vt-d: Remove the pasid present check in
prq_event_thread")Suggested-by Kevin Tian <[email protected]>Signed-off-by Lu Baolu <[email protected]>
Quoted 43 lines
From: Lu Baolu <[email protected]>
Sent: Monday, January 20, 2025 4:02 PMThis driver supports page faults on PCI RID since commit <
9f831c16c69e> ("iommu/vt-d: Remove the pasid present check inprq_event_thread") by allowing the reporting of page faults with thepasid_presentfield cleared to the upper layer for further handling. The fundamental assumption here is that the detach or replace operations act as a fence for page faults. This implies that all pending page faults associated with a specific RID or PASID are flushed when a domain is detached or replaced from a device RID or PASID.However, the
intel_iommu_drain_pasid_prq()helper does not correctly handle faults for RID. This leads to faults potentially remaining pending in the iommu hardware queue even after the domain is detached, thereby violating the aforementioned assumption.Fix this issue by extending
intel_iommu_drain_pasid_prq()to cover faults for RID.Fixes 9f831c16c69e ("iommu/vt-d: Remove the pasid present check in
prq_event_thread")Suggested-by Kevin Tian <[email protected]>Signed-off-by Lu Baolu <[email protected]>--- drivers/iommu/intel/prq.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)drivers/iommu/intel/prq.c +2
-1@@ -87,7 +87,8 @@ void intel_iommu_drain_pasid_prq(struct device *dev, u32 pasid)struct page_req_dsc *req; req = &iommu->prq[head /sizeof (*req)]; -if (!req->pasid_present || req->pasid != pasid) { +if (req->rid != sid || + (req->pasid_present && req->pasid != pasid)) { head = (head +sizeof (*req)) &PRQ_RING_MASK ;continue ;
Quoted 1 line
}
Ah you'd also want to skip (!req->pasid_present && pasid != IOMMU_NO_PASID)
Baolu Lu
maintainerQuoted 37 lines · Kevin
Quoted 37 lines
From: Lu Baolu <[email protected]>
Sent: Monday, January 20, 2025 4:02 PMThis driver supports page faults on PCI RID since commit <
9f831c16c69e> ("iommu/vt-d: Remove the pasid present check inprq_event_thread") by allowing the reporting of page faults with thepasid_presentfield cleared to the upper layer for further handling. The fundamental assumption here is that the detach or replace operations act as a fence for page faults. This implies that all pending page faults associated with a specific RID or PASID are flushed when a domain is detached or replaced from a device RID or PASID.However, the
intel_iommu_drain_pasid_prq()helper does not correctly handle faults for RID. This leads to faults potentially remaining pending in the iommu hardware queue even after the domain is detached, thereby violating the aforementioned assumption.Fix this issue by extending
intel_iommu_drain_pasid_prq()to cover faults for RID.Fixes 9f831c16c69e ("iommu/vt-d: Remove the pasid present check in
prq_event_thread")Suggested-by Kevin Tian <[email protected]>Signed-off-by Lu Baolu <[email protected]>--- drivers/iommu/intel/prq.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)drivers/iommu/intel/prq.c +0
-0@@ -87,7 +87,8 @@ void intel_iommu_drain_pasid_prq(struct device *dev, u32 pasid)struct page_req_dsc *req;
Quoted 11 lines
Quoted 7 lines
drivers/iommu/intel/prq.c +2
-1req = &iommu->prq[head /sizeof (*req)]; -if (!req->pasid_present || req->pasid != pasid) { +if (req->rid != sid || + (req->pasid_present && req->pasid != pasid)) { head = (head +sizeof (*req)) &PRQ_RING_MASK ;continue ;}Ah you'd also want to skip (!req->pasid_present && pasid !=
IOMMU_NO_PASID)
Yes. Will make it like this,
drivers/iommu/intel/prq.c +3 -1
@@ -87,7 +87,9 @@ void intel_iommu_drain_pasid_prq(struct device *dev, u32 pasid)struct page_req_dsc *req; req = &iommu->prq[head /sizeof (*req)]; -if (!req->pasid_present || req->pasid != pasid) { +if (req->rid != sid || + (req->pasid_present && pasid != req->pasid) || + (!req->pasid_present && pasid !=IOMMU_NO_PASID )) { head = (head +sizeof (*req)) &PRQ_RING_MASK ;continue ; }
Thanks,
baolu