* [PATCH 0/2] iommu/vt-d: Fix PCI device reference count leak
@ 2022-11-21 11:36 Xiongfeng Wang
2022-11-21 11:36 ` [PATCH 1/2] iommu/vt-d: Fix PCI device reference count leak in has_external pci() Xiongfeng Wang
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Xiongfeng Wang @ 2022-11-21 11:36 UTC (permalink / raw)
To: dwmw2, baolu.lu, joro, will, robin.murphy, jroedel
Cc: iommu, yangyingliang, wangxiongfeng2
for_each_pci_dev() is implemented by pci_get_device(). The comment of
pci_get_device() says that it will increase the reference count for the
returned pci_dev and also decrease the reference count for the input
pci_dev @from if it is not NULL.
If we break for_each_pci_dev() loop with pdev not NULL, we need to call
pci_dev_put() to decrease the reference count.
Xiongfeng Wang (2):
iommu/vt-d: Fix PCI device reference count leak in has_external pci()
iommu/vt-d: Fix PCI device reference count leak in
dmar_dev_scope_init()
drivers/iommu/intel/dmar.c | 1 +
drivers/iommu/intel/iommu.c | 4 +++-
2 files changed, 4 insertions(+), 1 deletion(-)
--
2.20.1
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH 1/2] iommu/vt-d: Fix PCI device reference count leak in has_external pci()
2022-11-21 11:36 [PATCH 0/2] iommu/vt-d: Fix PCI device reference count leak Xiongfeng Wang
@ 2022-11-21 11:36 ` Xiongfeng Wang
2022-11-21 11:36 ` [PATCH 2/2] iommu/vt-d: Fix PCI device reference count leak in dmar_dev_scope_init() Xiongfeng Wang
2022-12-01 4:04 ` [PATCH 0/2] iommu/vt-d: Fix PCI device reference count leak Baolu Lu
2 siblings, 0 replies; 4+ messages in thread
From: Xiongfeng Wang @ 2022-11-21 11:36 UTC (permalink / raw)
To: dwmw2, baolu.lu, joro, will, robin.murphy, jroedel
Cc: iommu, yangyingliang, wangxiongfeng2
for_each_pci_dev() is implemented by pci_get_device(). The comment of
pci_get_device() says that it will increase the reference count for the
returned pci_dev and also decrease the reference count for the input
pci_dev @from if it is not NULL.
If we break for_each_pci_dev() loop with pdev not NULL, we need to call
pci_dev_put() to decrease the reference count. Add the missing
pci_dev_put() before 'return true' to avoid reference count leak.
Fixes: 89a6079df791 ("iommu/vt-d: Force IOMMU on for platform opt in hint")
Signed-off-by: Xiongfeng Wang <wangxiongfeng2@huawei.com>
---
drivers/iommu/intel/iommu.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c
index 996a8b5ee5ee..1343b13fb1c2 100644
--- a/drivers/iommu/intel/iommu.c
+++ b/drivers/iommu/intel/iommu.c
@@ -3854,8 +3854,10 @@ static inline bool has_external_pci(void)
struct pci_dev *pdev = NULL;
for_each_pci_dev(pdev)
- if (pdev->external_facing)
+ if (pdev->external_facing) {
+ pci_dev_put(pdev);
return true;
+ }
return false;
}
--
2.20.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH 2/2] iommu/vt-d: Fix PCI device reference count leak in dmar_dev_scope_init()
2022-11-21 11:36 [PATCH 0/2] iommu/vt-d: Fix PCI device reference count leak Xiongfeng Wang
2022-11-21 11:36 ` [PATCH 1/2] iommu/vt-d: Fix PCI device reference count leak in has_external pci() Xiongfeng Wang
@ 2022-11-21 11:36 ` Xiongfeng Wang
2022-12-01 4:04 ` [PATCH 0/2] iommu/vt-d: Fix PCI device reference count leak Baolu Lu
2 siblings, 0 replies; 4+ messages in thread
From: Xiongfeng Wang @ 2022-11-21 11:36 UTC (permalink / raw)
To: dwmw2, baolu.lu, joro, will, robin.murphy, jroedel
Cc: iommu, yangyingliang, wangxiongfeng2
for_each_pci_dev() is implemented by pci_get_device(). The comment of
pci_get_device() says that it will increase the reference count for the
returned pci_dev and also decrease the reference count for the input
pci_dev @from if it is not NULL.
If we break for_each_pci_dev() loop with pdev not NULL, we need to call
pci_dev_put() to decrease the reference count. Add the missing
pci_dev_put() for the error path to avoid reference count leak.
Fixes: 2e4552893038 ("iommu/vt-d: Unify the way to process DMAR device scope array")
Signed-off-by: Xiongfeng Wang <wangxiongfeng2@huawei.com>
---
drivers/iommu/intel/dmar.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/drivers/iommu/intel/dmar.c b/drivers/iommu/intel/dmar.c
index 5a8f780e7ffd..bc94059a5b87 100644
--- a/drivers/iommu/intel/dmar.c
+++ b/drivers/iommu/intel/dmar.c
@@ -820,6 +820,7 @@ int __init dmar_dev_scope_init(void)
info = dmar_alloc_pci_notify_info(dev,
BUS_NOTIFY_ADD_DEVICE);
if (!info) {
+ pci_dev_put(dev);
return dmar_dev_scope_status;
} else {
dmar_pci_bus_add_dev(info);
--
2.20.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH 0/2] iommu/vt-d: Fix PCI device reference count leak
2022-11-21 11:36 [PATCH 0/2] iommu/vt-d: Fix PCI device reference count leak Xiongfeng Wang
2022-11-21 11:36 ` [PATCH 1/2] iommu/vt-d: Fix PCI device reference count leak in has_external pci() Xiongfeng Wang
2022-11-21 11:36 ` [PATCH 2/2] iommu/vt-d: Fix PCI device reference count leak in dmar_dev_scope_init() Xiongfeng Wang
@ 2022-12-01 4:04 ` Baolu Lu
2 siblings, 0 replies; 4+ messages in thread
From: Baolu Lu @ 2022-12-01 4:04 UTC (permalink / raw)
To: Xiongfeng Wang, dwmw2, joro, will, robin.murphy, jroedel
Cc: baolu.lu, iommu, yangyingliang
On 2022/11/21 19:36, Xiongfeng Wang wrote:
> for_each_pci_dev() is implemented by pci_get_device(). The comment of
> pci_get_device() says that it will increase the reference count for the
> returned pci_dev and also decrease the reference count for the input
> pci_dev @from if it is not NULL.
>
> If we break for_each_pci_dev() loop with pdev not NULL, we need to call
> pci_dev_put() to decrease the reference count.
>
> Xiongfeng Wang (2):
> iommu/vt-d: Fix PCI device reference count leak in has_external pci()
> iommu/vt-d: Fix PCI device reference count leak in
> dmar_dev_scope_init()
Queued for Joerg. Thank you!
Best regards,
baolu
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2022-12-01 4:05 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-11-21 11:36 [PATCH 0/2] iommu/vt-d: Fix PCI device reference count leak Xiongfeng Wang
2022-11-21 11:36 ` [PATCH 1/2] iommu/vt-d: Fix PCI device reference count leak in has_external pci() Xiongfeng Wang
2022-11-21 11:36 ` [PATCH 2/2] iommu/vt-d: Fix PCI device reference count leak in dmar_dev_scope_init() Xiongfeng Wang
2022-12-01 4:04 ` [PATCH 0/2] iommu/vt-d: Fix PCI device reference count leak Baolu Lu
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox