ice_sriov_set_msix_vec_count() rebuilds the VF VSI and rewrites the VF
queue and interrupt mappings without vf->cfg_lock. The PCI core only
makes sure that no driver is bound to the VF, the PF can still reset the
VF at the same time, e.g. from ndo_set_vf_mac() or ndo_set_vf_vlan().
Such a reset rebuilds the same VSI under vf->cfg_lock, and one rebuild
frees the VSI arrays that the other one still uses. Reproducer, with one
VF that has no driver bound:
while :; do
ip link set $PF vf 0 mac 02:00:00:00:02:01
ip link set $PF vf 0 mac 02:00:00:00:02:02
done &
while :; do
echo 33 > /sys/bus/pci/devices/$VF/sriov_vf_msix_count
echo 17 > /sys/bus/pci/devices/$VF/sriov_vf_msix_count
done
The first MAC change already oopses, with RTNL held:
BUG: kernel NULL pointer dereference, address: 0000000000000000
RIP: 0010:ice_free_q_vector+0x16/0x140 [ice]
Call Trace:
ice_vsi_free_q_vectors+0x20/0x40 [ice]
ice_vsi_decfg+0x59/0xc0 [ice]
ice_reset_vf+0x38f/0x5a0 [ice]
__ice_set_vf_mac+0x10a/0x160 [ice]
do_setvfinfo+0x5d/0x450
do_setlink.constprop.0+0x57f/0xd20
rtnl_newlink+0x4a4/0x9b0
Take vf->cfg_lock for the whole change, like the other paths that
reconfigure a VF do. It nests in the device locks of the PF and the VF,
which the PCI core holds here; the reset paths take vf->cfg_lock without
any device lock.
Fixes: 05c16687e0cc ("ice: set MSI-X vector count on VF")
Reported-by: Petr Oros <por…@redhat.com>
Closes: https://lore.kernel.org/netdev/2026…@redhat.com
Signed-off-by: Przemek Kitszel <prze…@intel.com>
---
drivers/net/ethernet/intel/ice/ice_sriov.c | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/drivers/net/ethernet/intel/ice/ice_sriov.c b/drivers/net/ethernet/intel/ice/ice_sriov.c
index c49f48b5ae38..5916cf7bf914 100644
--- a/drivers/net/ethernet/intel/ice/ice_sriov.c
+++ b/drivers/net/ethernet/intel/ice/ice_sriov.c
@@ -957,14 +957,18 @@ int ice_sriov_set_msix_vec_count(struct pci_dev *vf_dev, int msix_vec_count)
if (!vf)
return -ENOENT;
+ mutex_lock(&vf->cfg_lock);
+
vsi = ice_get_vf_vsi(vf);
if (!vsi) {
+ mutex_unlock(&vf->cfg_lock);
ice_put_vf(vf);
return -ENOENT;
}
/* No need to rebuild if we're setting to the same value */
if (msix_vec_count == vf->num_msix) {
+ mutex_unlock(&vf->cfg_lock);
ice_put_vf(vf);
return 0;
}
@@ -998,6 +1002,7 @@ int ice_sriov_set_msix_vec_count(struct pci_dev *vf_dev, int msix_vec_count)
vf->vf_id, vf->num_msix, vf->num_vf_qs);
ice_ena_vf_mappings(vf);
+ mutex_unlock(&vf->cfg_lock);
ice_put_vf(vf);
return 0;
@@ -1012,6 +1017,7 @@ int ice_sriov_set_msix_vec_count(struct pci_dev *vf_dev, int msix_vec_count)
vf->first_vector_idx = ice_virt_get_irqs(pf, vf->num_msix);
if (vf->first_vector_idx < 0) {
+ mutex_unlock(&vf->cfg_lock);
ice_put_vf(vf);
return -EINVAL;
}
@@ -1024,6 +1030,7 @@ int ice_sriov_set_msix_vec_count(struct pci_dev *vf_dev, int msix_vec_count)
}
ice_ena_vf_mappings(vf);
+ mutex_unlock(&vf->cfg_lock);
ice_put_vf(vf);
return -EINVAL;
--
2.51.1