octeontx2-af: Fix PCI device reference leaks in debugfs
PATCH v2 1/1 octeontx2-af: Fix PCI device reference leaks in debugfs
cgx_print_stats(), cgx_print_dmac_flt(), and cgx_print_fwdata() look up the RVU AF device with pci_get_device() and pass the returned pointer directly to pci_get_drvdata(). pci_get_device() returns a PCI device with an elevated reference count, so the lookup reference is leaked on every debugfs read.
Store the returned PCI device pointer, check it before reading driver data, and release the lookup reference after pci_get_drvdata(). In cgx_print_dmac_flt(), release the AF lookup reference before reusing pdev for pci_get_domain_bus_and_slot().
---
Changes in v2:
- Keep using the local RVU AF pdev returned by pci_get_device() instead of cgx->pdev, because cgx->pdev belongs to the CGX/RPM device.
- Rebase on current net-next so netdev CI can apply the patch.
.../marvell/octeontx2/af/rvu_debugfs.c | 31 +++++++++++++++---- 1 file changed, 25 insertions(+), 6 deletions(-)
drivers/net/ethernet/marvell/octeontx2/af/rvu_debugfs.c +25 -6
@@ -2838,9 +2838,16 @@ static int cgx_print_stats(struct seq_file *s, int lmac_id)int stat =0 , err =0 ;u64 tx_stat, rx_stat;struct rvu *rvu; +struct pci_dev *pdev =NULL ; + + pdev =pci_get_device (PCI_VENDOR_ID_CAVIUM , +PCI_DEVID_OCTEONTX2_RVU_AF ,NULL ); +if (!pdev) +return -ENODEV ; + + rvu =pci_get_drvdata (pdev); +pci_dev_put (pdev); - rvu =pci_get_drvdata (pci_get_device (PCI_VENDOR_ID_CAVIUM , -PCI_DEVID_OCTEONTX2_RVU_AF ,NULL ));if (!rvu)return -ENODEV ;
@@ -2958,8 +2965,13 @@ static int cgx_print_dmac_flt(struct seq_file *s, int lmac_id)u64 cfg, mac;int pf; - rvu =pci_get_drvdata (pci_get_device (PCI_VENDOR_ID_CAVIUM , -PCI_DEVID_OCTEONTX2_RVU_AF ,NULL )); + pdev =pci_get_device (PCI_VENDOR_ID_CAVIUM , +PCI_DEVID_OCTEONTX2_RVU_AF ,NULL ); +if (!pdev) +return -ENODEV ; + + rvu =pci_get_drvdata (pdev); +pci_dev_put (pdev);if (!rvu)return -ENODEV ;
@@ -3014,9 +3026,16 @@ static int cgx_print_fwdata(struct seq_file *s, int lmac_id)struct phy_s *phy;struct rvu *rvu;int cgx_id, i; +struct pci_dev *pdev =NULL ; + + pdev =pci_get_device (PCI_VENDOR_ID_CAVIUM , +PCI_DEVID_OCTEONTX2_RVU_AF ,NULL ); +if (!pdev) +return -ENODEV ; + + rvu =pci_get_drvdata (pdev); +pci_dev_put (pdev); - rvu =pci_get_drvdata (pci_get_device (PCI_VENDOR_ID_CAVIUM , -PCI_DEVID_OCTEONTX2_RVU_AF ,NULL ));if (!rvu)return -ENODEV ;
Signature · 1 line
2.43.0
Jakub Kicinski
maintainerQuoted 11 lines · On Mon, 8 Jun 2026 12:55:46 -0400 Yuho Choi wrote:
cgx_print_stats(),cgx_print_dmac_flt(), andcgx_print_fwdata()look up the RVU AF device withpci_get_device()and pass the returned pointer directly topci_get_drvdata().pci_get_device()returns a PCI device with an elevated reference count, so the lookup reference is leaked on every debugfs read.Store the returned PCI device pointer, check it before reading driver data, and release the lookup reference after
pci_get_drvdata(). Incgx_print_dmac_flt(), release the AF lookup reference before reusing pdev forpci_get_domain_bus_and_slot().
Quoted 4 lines
Fixes f967488d095e ("octeontx2-af: Add per CGX port level NIX Rx/Tx counters")Fixes dbc52debf95f ("octeontx2-af: Debugfs support for DMAC filters")Fixes 49f02e6877d1 ("Octeontx2-af: Debugfs support for firmware data")Signed-off-by Yuho Choi <[email protected]>
Marvell, please review patches from external contributors promptly.
Review question sort of based on a Sashiko comment - this is part of the rvu device driver, AFAIU, does anything prevent the AF from getting removed (via sysfs for instance) while this code is using its priv?
Quoted 65 lines
Changes in v2:
- Keep using the local RVU AF pdev returned bypci_get_device()instead ofcgx->pdev, becausecgx->pdevbelongs to the CGX/RPM device.
- Rebase on current net-next so netdev CI can apply the patch..../marvell/octeontx2/af/rvu_debugfs.c | 31 +++++++++++++++---- 1 file changed, 25 insertions(+), 6 deletions(-)drivers/net/ethernet/marvell/octeontx2/af/rvu_debugfs.c +25
-6@@ -2838,9 +2838,16 @@ static int cgx_print_stats(struct seq_file *s, int lmac_id)int stat =0 , err =0 ;u64 tx_stat, rx_stat;struct rvu *rvu; +struct pci_dev *pdev =NULL ; + + pdev =pci_get_device (PCI_VENDOR_ID_CAVIUM , +PCI_DEVID_OCTEONTX2_RVU_AF ,NULL ); +if (!pdev) +return -ENODEV ; + + rvu =pci_get_drvdata (pdev); +pci_dev_put (pdev); - rvu =pci_get_drvdata (pci_get_device (PCI_VENDOR_ID_CAVIUM , -PCI_DEVID_OCTEONTX2_RVU_AF ,NULL ));if (!rvu)return -ENODEV ;@@ -2958,8 +2965,13 @@ static int cgx_print_dmac_flt(struct seq_file *s, int lmac_id)u64 cfg, mac;int pf; - rvu =pci_get_drvdata (pci_get_device (PCI_VENDOR_ID_CAVIUM , -PCI_DEVID_OCTEONTX2_RVU_AF ,NULL )); + pdev =pci_get_device (PCI_VENDOR_ID_CAVIUM , +PCI_DEVID_OCTEONTX2_RVU_AF ,NULL ); +if (!pdev) +return -ENODEV ; + + rvu =pci_get_drvdata (pdev); +pci_dev_put (pdev);if (!rvu)return -ENODEV ;@@ -3014,9 +3026,16 @@ static int cgx_print_fwdata(struct seq_file *s, int lmac_id)struct phy_s *phy;struct rvu *rvu;int cgx_id, i; +struct pci_dev *pdev =NULL ; + + pdev =pci_get_device (PCI_VENDOR_ID_CAVIUM , +PCI_DEVID_OCTEONTX2_RVU_AF ,NULL ); +if (!pdev) +return -ENODEV ; + + rvu =pci_get_drvdata (pdev); +pci_dev_put (pdev); - rvu =pci_get_drvdata (pci_get_device (PCI_VENDOR_ID_CAVIUM , -PCI_DEVID_OCTEONTX2_RVU_AF ,NULL ));if (!rvu)return -ENODEV ;
Ratheesh Kannoth
maintainerQuoted 17 lines · Jakub Kicinski
Quoted 11 lines · On Mon, 8 Jun 2026 12:55:46 -0400 Yuho Choi wrote:
cgx_print_stats(),cgx_print_dmac_flt(), andcgx_print_fwdata()look up the RVU AF device withpci_get_device()and pass the returned pointer directly topci_get_drvdata().pci_get_device()returns a PCI device with an elevated reference count, so the lookup reference is leaked on every debugfs read.Store the returned PCI device pointer, check it before reading driver data, and release the lookup reference after
pci_get_drvdata(). Incgx_print_dmac_flt(), release the AF lookup reference before reusing pdev forpci_get_domain_bus_and_slot().Quoted 4 lines
Fixes f967488d095e ("octeontx2-af: Add per CGX port level NIX Rx/Tx counters")Fixes dbc52debf95f ("octeontx2-af: Debugfs support for DMAC filters")Fixes 49f02e6877d1 ("Octeontx2-af: Debugfs support for firmware data")Signed-off-by Yuho Choi <[email protected]>
Quoted 5 lines
Marvell, please review patches from external contributors promptly.
Review question sort of based on a Sashiko comment - this is part of the rvu device driver, AFAIU, does anything prevent the AF from getting removed (via sysfs for instance) while this code is using its priv?
RVU AF driver's teardown sequence prevents the race here. In rvu_remove(), the very first call is rvu_dbg_exit(rvu), which calls debugfs_remove_recursive() on the debugfs root. ASFAIK, debugfs_remove_recursive() will block until all active readers (i.e., any in-progress seq_file read callbacks like cgx_print_stats(), cgx_print_dmac_flt(), and cgx_print_fwdata()) have completed before the removal proceeds. Only after rvu_dbg_exit() returns does rvu_remove() proceed to free the rvu structure.
A better approach would be to pass the rvu object(rvu structure has pdev field) while creating the debugfs file itself, e.g.:
RVU_DEBUG_SEQ_FOPS(cgx_dmac_flt, cgx_dmac_flt_display, s/NULL/rvu);
This would eliminate the pci_get_device() lookup entirely. We will post this as a code clean-up patch to net-next.
Jakub Kicinski
maintainerQuoted 14 lines · On Thu, 11 Jun 2026 07:51:08 +0530 Ratheesh Kannoth wrote:
Quoted 3 lines
Review question sort of based on a Sashiko comment - this is part of the rvu device driver, AFAIU, does anything prevent the AF from getting removed (via sysfs for instance) while this code is using its priv?
RVU AF driver's teardown sequence prevents the race here. In
rvu_remove(), the very first call isrvu_dbg_exit(rvu), which callsdebugfs_remove_recursive()on the debugfs root. ASFAIK,debugfs_remove_recursive()will block until all active readers (i.e., any in-progressseq_fileread callbacks likecgx_print_stats(),cgx_print_dmac_flt(), andcgx_print_fwdata()) have completed before the removal proceeds. Only afterrvu_dbg_exit()returns doesrvu_remove()proceed to free the rvu structure.
Quoted 7 lines
A better approach would be to pass the rvu object(rvu structure has pdev field) while creating the debugfs file itself, e.g.:
RVU_DEBUG_SEQ_FOPS(cgx_dmac_flt, cgx_dmac_flt_display, s/NULL/rvu);This would eliminate the
pci_get_device()lookup entirely. We will post this as a code clean-up patch to net-next.
Oh, that's much better, somehow I assumed that this dance is necessary because we are accessing a different PCI device.
Also, since you're actively working upstream and nobody else on the CC list responded - should you perhaps be added to maintainers for this driver so that you're CCed on patches? (instead of one of the useless ones)
Quoted 7 lines
Oh, that's much better, somehow I assumed that this dance is necessary because we are accessing a different PCI device.
Also, since you're actively working upstream and nobody else on the CC list responded - should you perhaps be added to maintainers for this driver so that you're CCed on patches? (instead of one of the useless ones)
Thank you for reviewing this patch.
If Marvell posts a cleanup patch for this issue, could you please include:
or otherwise mention this report?
I will hold off on sending another revision for now.
Ratheesh Kannoth
maintainerQuoted 8 lines · 최유호
Quoted 7 lines
Oh, that's much better, somehow I assumed that this dance is necessary because we are accessing a different PCI device.
Also, since you're actively working upstream and nobody else on the CC list responded - should you perhaps be added to maintainers for this driver so that you're CCed on patches? (instead of one of the useless ones)
Quoted 6 lines
Thank you for reviewing this patch.
If Marvell posts a cleanup patch for this issue, could you please include:
Reported-by Yuho Choi [email protected]or otherwise mention this report?
I will hold off on sending another revision for now.
Thank you for catching this issue and for posting the fix!
We currently have a large backlog of patches queued up to post upstream, so there will likely be a bit of a delay if we handle the submission from our
side. If you have the bandwidth and would like to post this (passing rvu object to debugfs file) yourself, please feel free—we will gladly help review and test it promptly.
Alternatively, if you prefer that Marvell takes it over and posts the cleanup, we will definitely include your tag to ensure proper credit.
Quoted 10 lines · Ratheesh Kannoth
Thank you for catching this issue and for posting the fix!
We currently have a large backlog of patches queued up to post upstream, so there will likely be a bit of a delay if we handle the submission from our
side. If you have the bandwidth and would like to post this (passing rvu object to debugfs file) yourself, please feel free—we will gladly help review and test it promptly.Alternatively, if you prefer that Marvell takes it over and posts the cleanup, we will definitely include your tag to ensure proper credit.
Thank you for the clarification and for offering to handle the cleanup from your side.
I would prefer to wait for Marvell’s cleanup patch rather than posting another revision myself. Please include my Reported-by tag or otherwise mention this report when you post the patch.
Thanks again for your help with the review and testing.
Ratheesh Kannoth
maintainerQuoted 23 lines · Jakub Kicinski
Quoted 14 lines · On Thu, 11 Jun 2026 07:51:08 +0530 Ratheesh Kannoth wrote:
Quoted 3 lines
Review question sort of based on a Sashiko comment - this is part of the rvu device driver, AFAIU, does anything prevent the AF from getting removed (via sysfs for instance) while this code is using its priv?
RVU AF driver's teardown sequence prevents the race here. In
rvu_remove(), the very first call isrvu_dbg_exit(rvu), which callsdebugfs_remove_recursive()on the debugfs root. ASFAIK,debugfs_remove_recursive()will block until all active readers (i.e., any in-progressseq_fileread callbacks likecgx_print_stats(),cgx_print_dmac_flt(), andcgx_print_fwdata()) have completed before the removal proceeds. Only afterrvu_dbg_exit()returns doesrvu_remove()proceed to free the rvu structure.Quoted 7 lines
A better approach would be to pass the rvu object(rvu structure has pdev field) while creating the debugfs file itself, e.g.:
RVU_DEBUG_SEQ_FOPS(cgx_dmac_flt, cgx_dmac_flt_display, s/NULL/rvu);This would eliminate the
pci_get_device()lookup entirely. We will post this as a code clean-up patch to net-next.
Quoted 7 lines
Oh, that's much better, somehow I assumed that this dance is necessary because we are accessing a different PCI device.
Also, since you're actively working upstream and nobody else on the CC list responded - should you perhaps be added to maintainers for this driver so that you're CCed on patches? (instead of one of the useless ones)
Thank you for the feedback, and I would be glad to be added to the MAINTAINERS file for the RVU driver to help with reviews and tracking moving forward.
Regarding the review coverage from our side, a few of
listed maintainers have transitioned out of the organization, and the remaining team members have been tightly coupled with some critical internal deliverables recently. However, we absolutely recognize the importance of consistent upstream engagement. Moving forward, we are aligning our internal focus to ensure we actively participate in review cycles and maintain a steady presence on the list.
I will prepare and submit a formal patch to update the MAINTAINERS file.
Regarding the code cleanup discussed above, we will get the net-next patch ready to replace the pci_get_device() lookup with the direct rvu context pass.
Thanks again for your guidance and support.