Re: [PATCH net-next v2] octeontx2-af: Fix PCI device reference leaks in debugfs
From: Ratheesh Kannoth
Date: Wed Jun 10 2026 - 22:29:24 EST
On 2026-06-10 at 21:05:44, Jakub Kicinski (kuba@xxxxxxxxxx) wrote:
> On Mon, 8 Jun 2026 12:55:46 -0400 Yuho Choi wrote:
> > 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().
> >
> > 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 <dbgh9129@xxxxxxxxx>
>
> 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.