All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] iommu/amd: Fix PCI device reference leak in PPR handling
@ 2026-08-14 13:39 Ruoyu Wang
  2026-08-16 14:48 ` Markus Elfring
  2026-08-22 14:09 ` Vasant Hegde
  0 siblings, 2 replies; 4+ messages in thread
From: Ruoyu Wang @ 2026-08-14 13:39 UTC (permalink / raw)
  To: Joerg Roedel, Suravee Suthikulpanit, Will Deacon, Robin Murphy,
	Jason Gunthorpe, Wei Huang, Vasant Hegde
  Cc: iommu, linux-kernel, Ruoyu Wang

pci_get_domain_bus_and_slot() takes a reference on the returned PCI
device. iommu_call_iopf_notifier() fails to release it after either
reporting a valid PPR fault or completing a rejected request. Each
handled request therefore leaks a reference and can prevent the PCI
device from being released.

Call pci_dev_put() after the final use of the lookup reference on both
paths.

This issue was found by a static analysis checker and confirmed by
manual source review.

Fixes: 978d626b8f1a ("iommu/amd: Add IO page fault notifier handler")
Signed-off-by: Ruoyu Wang <ruoyuw560@gmail.com>
---
 drivers/iommu/amd/ppr.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/iommu/amd/ppr.c b/drivers/iommu/amd/ppr.c
index 1f8d2823bea42..1e4392b17bd8f 100644
--- a/drivers/iommu/amd/ppr.c
+++ b/drivers/iommu/amd/ppr.c
@@ -151,6 +151,7 @@ static void iommu_call_iopf_notifier(struct amd_iommu *iommu, u64 *raw)
 
 	/* Submit event */
 	iommu_report_device_fault(&pdev->dev, &event);
+	pci_dev_put(pdev);
 
 	return;
 
@@ -159,6 +160,7 @@ static void iommu_call_iopf_notifier(struct amd_iommu *iommu, u64 *raw)
 	amd_iommu_complete_ppr(&pdev->dev, PPR_PASID(raw[0]),
 			       IOMMU_PAGE_RESP_FAILURE,
 			       PPR_TAG(raw[0]) & 0x1FF);
+	pci_dev_put(pdev);
 }
 
 void amd_iommu_poll_ppr_log(struct amd_iommu *iommu)
-- 
2.51.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] iommu/amd: Fix PCI device reference leak in PPR handling
  2026-08-14 13:39 [PATCH] iommu/amd: Fix PCI device reference leak in PPR handling Ruoyu Wang
@ 2026-08-16 14:48 ` Markus Elfring
  2026-08-22 14:09 ` Vasant Hegde
  1 sibling, 0 replies; 4+ messages in thread
From: Markus Elfring @ 2026-08-16 14:48 UTC (permalink / raw)
  To: Ruoyu Wang, iommu, Jason Gunthorpe, Jörg Rödel,
	Robin Murphy, Suravee Suthikulpanit, Vasant Hegde, Wei Huang,
	Will Deacon
  Cc: LKML, kernel-janitors

…
> Call pci_dev_put() after the final use of the lookup reference on both
> paths.
…

How do you think about to apply the attribute “__free(pci_dev_put)”
also in the implementation of the function “iommu_call_iopf_notifier”?
https://elixir.bootlin.com/linux/v7.2-rc7/source/include/linux/pci.h#L1269

https://elixir.bootlin.com/linux/v7.2-rc7/source/drivers/iommu/amd/ppr.c#L107-L162

Regards,
Markus


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] iommu/amd: Fix PCI device reference leak in PPR handling
  2026-08-14 13:39 [PATCH] iommu/amd: Fix PCI device reference leak in PPR handling Ruoyu Wang
  2026-08-16 14:48 ` Markus Elfring
@ 2026-08-22 14:09 ` Vasant Hegde
  2026-08-23  6:20   ` Markus Elfring
  1 sibling, 1 reply; 4+ messages in thread
From: Vasant Hegde @ 2026-08-22 14:09 UTC (permalink / raw)
  To: Ruoyu Wang, Joerg Roedel, Suravee Suthikulpanit, Will Deacon,
	Robin Murphy, Jason Gunthorpe, Wei Huang
  Cc: iommu, linux-kernel



On 8/14/2026 7:09 PM, Ruoyu Wang wrote:
> [You don't often get email from ruoyuw560@gmail.com. Learn why this is important at https://aka.ms/LearnAboutSenderIdentification ]
> 
> pci_get_domain_bus_and_slot() takes a reference on the returned PCI
> device. iommu_call_iopf_notifier() fails to release it after either
> reporting a valid PPR fault or completing a rejected request. Each
> handled request therefore leaks a reference and can prevent the PCI
> device from being released.
> 
> Call pci_dev_put() after the final use of the lookup reference on both
> paths.

This was recently fixed by commit af3b69b16383.

-Vasant


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: iommu/amd: Fix PCI device reference leak in PPR handling
  2026-08-22 14:09 ` Vasant Hegde
@ 2026-08-23  6:20   ` Markus Elfring
  0 siblings, 0 replies; 4+ messages in thread
From: Markus Elfring @ 2026-08-23  6:20 UTC (permalink / raw)
  To: Ruoyu Wang, iommu
  Cc: LKML, Jason Gunthorpe, Jörg Rödel, Robin Murphy,
	Shuai Xue, Suravee Suthikulpanit, Vasant Hegde, Wei Huang,
	Will Deacon

…
> > Call pci_dev_put() after the final use of the lookup reference on both
> > paths.
> 
> This was recently fixed by commit af3b69b16383.

See also:
https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git/log/drivers/iommu/amd/ppr.c/?h=next-20260821

iommu/amd: Put PCI device after handling PPR faults
2026-07-30

Regards,
Markus

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-08-23  6:20 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-08-14 13:39 [PATCH] iommu/amd: Fix PCI device reference leak in PPR handling Ruoyu Wang
2026-08-16 14:48 ` Markus Elfring
2026-08-22 14:09 ` Vasant Hegde
2026-08-23  6:20   ` Markus Elfring

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.