net/liquidio: drop cached VF pci_dev LUT
Subsystems (3)
PATCH v3 1/1 net/liquidio: drop cached VF pci_dev LUT
The PF SR-IOV enable path caches VF pci_dev pointers in dpiring_to_vfpcidev_lut[] by iterating with pci_get_device(). Those entries do not own a reference, because the iterator drops the previous device reference on each step. The cached pointer is then dereferenced later when handling OCTEON_VF_FLR_REQUEST.
Replace the cached VF mapping with runtime lookup on the mailbox DPI
ring: derive the VF index from q_no, resolve the VF via exported PCI IOV helpers, validate it with the PF pointer and VF ID, then issue pcie_flr() and drop the reference with pci_dev_put(). Remove the unused VF lookup table initialization and cleanup.
---
Changes in v3:
- Drop unrelated Xgene PCI probe note from the commit message.
Changes in v2:
- Replace use of pci_iov_virtfn_bus() with runtime VF lookup using exported helpers.
.../net/ethernet/cavium/liquidio/lio_main.c | 27 --------------- .../ethernet/cavium/liquidio/octeon_device.h | 3 -- .../ethernet/cavium/liquidio/octeon_mailbox.c | 33 ++++++++++++++++++- 3 files changed, 32 insertions(+), 31 deletions(-)
drivers/net/ethernet/cavium/liquidio/lio_main.c +0 -27
@@ -3779,9 +3779,7 @@ static int setup_nic_devices(struct octeon_device *octeon_dev)static int octeon_enable_sriov (struct octeon_device *oct) {unsigned int num_vfs_alloced = oct->sriov_info.num_vfs_alloced; -struct pci_dev *vfdev;int err; -u32 u;if (OCTEON_CN23XX_PF (oct) && num_vfs_alloced) { err = pci_enable_sriov(oct->pci_dev,
@@ -3794,23 +3792,6 @@ static int octeon_enable_sriov(struct octeon_device *oct)return err; } oct->sriov_info.sriov_enabled =1 ; - -/* init lookup table that maps DPI ring number to VF pci_dev -* struct pointer -*/ - u =0 ; - vfdev =pci_get_device (PCI_VENDOR_ID_CAVIUM , -OCTEON_CN23XX_VF_VID ,NULL ); -while (vfdev) { -if (vfdev->is_virtfn && - (vfdev->physfn == oct->pci_dev)) { - oct->sriov_info.dpiring_to_vfpcidev_lut[u] = - vfdev; - u += oct->sriov_info.rings_per_vf; - } - vfdev =pci_get_device (PCI_VENDOR_ID_CAVIUM , -OCTEON_CN23XX_VF_VID , vfdev); - } }return num_vfs_alloced;
@@ -3818,8 +3799,6 @@ static int octeon_enable_sriov(struct octeon_device *oct)static int lio_pci_sriov_disable (struct octeon_device *oct) { -int u; -if (pci_vfs_assigned (oct->pci_dev)) {dev_err (&oct->pci_dev->dev,"VFs are still assigned to VMs.\n" );return -EPERM ;
@@ -3827,12 +3806,6 @@ static int lio_pci_sriov_disable(struct octeon_device *oct)pci_disable_sriov (oct->pci_dev); - u =0 ; -while (u <MAX_POSSIBLE_VFS ) { - oct->sriov_info.dpiring_to_vfpcidev_lut[u] =NULL ; - u += oct->sriov_info.rings_per_vf; - } - oct->sriov_info.num_vfs_alloced =0 ;dev_info (&oct->pci_dev->dev,"oct->pf_num:%d disabled VFs\n" , oct->pf_num);
drivers/net/ethernet/cavium/liquidio/octeon_device.h +0 -3
@@ -390,9 +390,6 @@ struct octeon_sriov_info {struct lio_trusted_vf trusted_vf; -/*lookup table that maps DPI ring number to VF pci_dev struct pointer*/ -struct pci_dev *dpiring_to_vfpcidev_lut[MAX_POSSIBLE_VFS ]; -u64 vf_macaddr[MAX_POSSIBLE_VFS ];u16 vf_vlantci[MAX_POSSIBLE_VFS ];
drivers/net/ethernet/cavium/liquidio/octeon_mailbox.c +32 -1
@@ -26,6 +26,31 @@#include "octeon_mailbox.h" #include "cn23xx_pf_device.h" +static struct pci_dev *lio_vf_pci_dev_by_qno (struct octeon_device *oct,u32 q_no) +{ +struct pci_dev *vfdev =NULL ; +int vfidx; + +if (!oct->sriov_info.rings_per_vf) +return NULL ; + +if (q_no % oct->sriov_info.rings_per_vf) +return NULL ; + + vfidx = q_no / oct->sriov_info.rings_per_vf; +if (vfidx >= oct->sriov_info.num_vfs_alloced) +return NULL ; + +while ((vfdev =pci_get_device (PCI_VENDOR_ID_CAVIUM , +OCTEON_CN23XX_VF_VID , vfdev))) { +if (pci_physfn (vfdev) &&pci_physfn (vfdev) == oct->pci_dev && +pci_iov_vf_id (vfdev) == vfidx) +return vfdev; + } + +return NULL ; +} +/** * octeon_mbox_read: * @mbox: Pointer mailbox
@@ -237,6 +262,7 @@ static int octeon_mbox_process_cmd(struct octeon_mbox *mbox, struct octeon_mbox_cmd *mbox_cmd) {struct octeon_device *oct = mbox->oct_dev; +struct pci_dev *vfdev;switch (mbox_cmd->msg.s.cmd) {case OCTEON_VF_ACTIVE :
@@ -260,7 +286,12 @@ static int octeon_mbox_process_cmd(struct octeon_mbox *mbox,dev_info (&oct->pci_dev->dev,"got a request for FLR from VF that owns DPI ring %u\n" , mbox->q_no); -pcie_flr (oct->sriov_info.dpiring_to_vfpcidev_lut[mbox->q_no]); + vfdev =lio_vf_pci_dev_by_qno (oct, mbox->q_no); +if (!vfdev) +break ; + +pcie_flr (vfdev); +pci_dev_put (vfdev);break ;case OCTEON_PF_CHANGED_VF_MACADDR :
Signature · 1 line
2.43.0
This patch was applied to netdev/net.git (main) by Paolo Abeni <[email protected]>:
Hello:
This patch was applied to netdev/net.git (main)
by Paolo Abeni <[email protected]>:
Quoted 6 lines · On Wed, 1 Jul 2026 00:08:47 -0400 you wrote:
The PF SR-IOV enable path caches VF
pci_devpointers in dpiring_to_vfpcidev_lut[] by iterating withpci_get_device(). Those entries do not own a reference, because the iterator drops the previous device reference on each step. The cached pointer is then dereferenced later when handlingOCTEON_VF_FLR_REQUEST.
Quoted 7 lines
Replace the cached VF mapping with runtime lookup on the mailbox DPI
ring: derive the VF index fromq_no, resolve the VF via exported PCI IOV helpers, validate it with the PF pointer and VF ID, then issuepcie_flr()and drop the reference withpci_dev_put(). Remove the unused VF lookup table initialization and cleanup.[...]
Here is the summary with links:
- [v3] net/liquidio: drop cached VF pci_dev LUT
https://git.kernel.org/netdev/net/c/5c0e3ba4f500
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html