From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0E530352003; Wed, 10 Jun 2026 15:35:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781105747; cv=none; b=KJMN9ofmOrrhSWNtlKdwUBLB3GLv3+mP6DbyBKCb4gL1tzzY23rB9beGuSlcj7KFEGCV2gp4acLw/mW56HmwjhYNliEE/yaI3paDU9M7t1m2zyrjjj3Z3HZPC8FMe+JqNLDMd5Xr+DFp5YqcxlsAjVoPkuGqqSMlUkaFp0RESSE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781105747; c=relaxed/simple; bh=VtshOWRTdhBq7cyq4VD6EjdN/YDisPTWdZvCJkgZu88=; h=Date:From:To:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=CjBCOSrTtsiB3jlgTua/qyxRa0cLKZ7p1RgI4CJKXqOelEcwwhHQJ/62uZkh9FMZzNRyO18SXMljO0NQ9qBT9467HneU5B7Wm5NNR0vBMy2d8wbg8EPTdAboPTebG+sSSxDayDYRZKRnZiuKOyojo5xjv9icM1/NbYpt1Z93Jzs= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=KPKnr69O; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="KPKnr69O" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6F21B1F00893; Wed, 10 Jun 2026 15:35:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1781105746; bh=Ww6bCvxOileVZW2P/NfL7I2CLtavMpnRN0+79/WS85E=; h=Date:From:To:Cc:Subject:In-Reply-To:References; b=KPKnr69OKuGQmKXjEgizX57ZHmcZ6MKWc2WM/2wh/jC17K3xggkah0yN3S7QkFTni kcuDS/umKsyhf0jWFuPZiooZFidqC0bOObcsqiK66qwKQ8T+oAvv6f21tzliMCccSv Unpl3DNgVpfhPx3dleaUknod9SYOBRl1rCXxwGjVeCiVuufQpll/N+14XfOe74fmwE 2NCyVIXokoHew5VL0/oFOP11run5iRjAkakUEKkKFy6vWB6MEgXfIaNDegiclp3Uei nL8JDZ19K23SF7jrI+U6NUuCeS+tkWhqtWWkCbe8BdTKYTQUWN6uHNW+/KZiwseNkU w51+tZPO7aXYQ== Date: Wed, 10 Jun 2026 08:35:44 -0700 From: Jakub Kicinski To: Yuho Choi Cc: Sunil Goutham , Linu Cherian , Geetha sowjanya , hariprasad , Subbaraya Sundeep , Andrew Lunn , "David S . Miller" , Eric Dumazet , Paolo Abeni , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, , Ratheesh Kannoth Subject: Re: [PATCH net-next v2] octeontx2-af: Fix PCI device reference leaks in debugfs Message-ID: <20260610083544.0da95356@kernel.org> In-Reply-To: <20260608165546.61347-1-dbgh9129@gmail.com> References: <20260608165546.61347-1-dbgh9129@gmail.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit 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 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? > 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(-) > > diff --git a/drivers/net/ethernet/marvell/octeontx2/af/rvu_debugfs.c b/drivers/net/ethernet/marvell/octeontx2/af/rvu_debugfs.c > index fa461489acdd..04ba091773b6 100644 > --- a/drivers/net/ethernet/marvell/octeontx2/af/rvu_debugfs.c > +++ b/drivers/net/ethernet/marvell/octeontx2/af/rvu_debugfs.c > @@ -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; >