Netdev List
 help / color / mirror / Atom feed
From: Przemek Kitszel <przemyslaw.kitszel@intel.com>
To: netdev@vger.kernel.org, pabeni@redhat.com, willemb@google.com,
	donald.hunter@gmail.com, jiri@resnulli.us
Cc: intel-wired-lan@lists.osuosl.org, anthony.l.nguyen@intel.com,
	davem@davemloft.net, edumazet@kernel.org, kuba@kernel.org,
	horms@kernel.org, andrew+netdev@lunn.ch,
	Petr Oros <poros@redhat.com>,
	Przemek Kitszel <przemyslaw.kitszel@intel.com>
Subject: [PATCH net 2/3] ice: lock VF config while changing its MSI-X vector count
Date: Wed,  2 Dec 2026 13:48:02 +0100	[thread overview]
Message-ID: <20261202124956.18277-3-przemyslaw.kitszel@intel.com> (raw)
In-Reply-To: <20261202124956.18277-1-przemyslaw.kitszel@intel.com>

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 <poros@redhat.com>
Closes: https://lore.kernel.org/netdev/20261126094321.40071-1-poros@redhat.com
Signed-off-by: Przemek Kitszel <przemyslaw.kitszel@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


  parent reply	other threads:[~2026-12-02 12:50 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-02 12:48 [PATCH net 0/3] ice, devlink: fixes needed for XLVF Przemek Kitszel
2026-12-02 12:48 ` [PATCH net 1/3] ice: move only the valid VF queues on LAG reclaim and reset rebuild Przemek Kitszel
2026-12-02 12:48 ` Przemek Kitszel [this message]
2026-12-02 12:48 ` [PATCH net 3/3] devlink: make room for many nested instances in a dev message Przemek Kitszel
2026-12-02 12:54 ` [PATCH net 0/3] ice, devlink: fixes needed for XLVF netdev-bot+sinfo

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261202124956.18277-3-przemyslaw.kitszel@intel.com \
    --to=przemyslaw.kitszel@intel.com \
    --cc=andrew+netdev@lunn.ch \
    --cc=anthony.l.nguyen@intel.com \
    --cc=davem@davemloft.net \
    --cc=donald.hunter@gmail.com \
    --cc=edumazet@kernel.org \
    --cc=horms@kernel.org \
    --cc=intel-wired-lan@lists.osuosl.org \
    --cc=jiri@resnulli.us \
    --cc=kuba@kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=poros@redhat.com \
    --cc=willemb@google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox