Skip to content

Commit 6927d35

Browse files
Yang Yingliangjoergroedel
authored andcommitted
iommu/vt-d: Fix PCI device refcount leak in prq_event_thread()
As comment of pci_get_domain_bus_and_slot() says, it returns a pci device with refcount increment, when finish using it, the caller must decrease the reference count by calling pci_dev_put(). So call pci_dev_put() after using the 'pdev' to avoid refcount leak. Besides, if the 'pdev' is null or intel_svm_prq_report() returns error, there is no need to trace this fault. Fixes: 06f4b8d ("iommu/vt-d: Remove unnecessary SVA data accesses in page fault path") Suggested-by: Lu Baolu <[email protected]> Signed-off-by: Yang Yingliang <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Lu Baolu <[email protected]> Signed-off-by: Joerg Roedel <[email protected]>
1 parent e65a689 commit 6927d35

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

drivers/iommu/intel/svm.c

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -748,12 +748,16 @@ static irqreturn_t prq_event_thread(int irq, void *d)
748748
* If prq is to be handled outside iommu driver via receiver of
749749
* the fault notifiers, we skip the page response here.
750750
*/
751-
if (!pdev || intel_svm_prq_report(iommu, &pdev->dev, req))
752-
handle_bad_prq_event(iommu, req, QI_RESP_INVALID);
751+
if (!pdev)
752+
goto bad_req;
753753

754-
trace_prq_report(iommu, &pdev->dev, req->qw_0, req->qw_1,
755-
req->priv_data[0], req->priv_data[1],
756-
iommu->prq_seq_number++);
754+
if (intel_svm_prq_report(iommu, &pdev->dev, req))
755+
handle_bad_prq_event(iommu, req, QI_RESP_INVALID);
756+
else
757+
trace_prq_report(iommu, &pdev->dev, req->qw_0, req->qw_1,
758+
req->priv_data[0], req->priv_data[1],
759+
iommu->prq_seq_number++);
760+
pci_dev_put(pdev);
757761
prq_advance:
758762
head = (head + sizeof(*req)) & PRQ_RING_MASK;
759763
}

0 commit comments

Comments
 (0)