Netdev List
 help / color / mirror / Atom feed
From: Changyul Lee <lcy8047@gmail.com>
To: Tony Nguyen <anthony.l.nguyen@intel.com>,
	Przemek Kitszel <przemyslaw.kitszel@intel.com>
Cc: Andrew Lunn <andrew+netdev@lunn.ch>,
	"David S. Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@kernel.org>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
	Larysa Zaremba <larysa.zaremba@intel.com>,
	Simon Horman <horms@kernel.org>,
	Michal Swiatkowski <michal.swiatkowski@linux.intel.com>,
	intel-wired-lan@lists.osuosl.org, netdev@vger.kernel.org,
	linux-kernel@vger.kernel.org, Changyul Lee <lcy8047@gmail.com>
Subject: [PATCH iwl-net] ice: protect VF lifetime during LLDP configuration
Date: Wed, 18 Nov 2026 20:44:46 -0500	[thread overview]
Message-ID: <20261119014446.577784-1-lcy8047@gmail.com> (raw)

ice_free_vfs() can free a VF or its VSI while ice_cfg_sw_rx_lldp()
is configuring LLDP. Taking table_lock here would reverse the lock
order because ethtool already holds RTNL and ice_free_vfs() takes
RTNL under table_lock.

Look up each VF by ID to hold a reference. Hold the VF's cfg_lock
while configuring its VSI to prevent ice_free_vfs() from releasing
the VSI during configuration.

Fixes: 2296345416b0 ("ice: receive LLDP on trusted VFs")
Signed-off-by: Changyul Lee <lcy8047@gmail.com>
---
Found with a static analysis tool we are developing.

Compile-tested only, with x86_64_defconfig plus PCI_IOV, ICE, DCB and
W=1.

Taking cfg_lock under RTNL follows the order set by commit ae82ccd68774
("ice: attach and detach VF representors outside of vf->cfg_lock") in
dev-queue.

 drivers/net/ethernet/intel/ice/ice_lib.c | 15 +++++++++------
 1 file changed, 9 insertions(+), 6 deletions(-)

diff --git a/drivers/net/ethernet/intel/ice/ice_lib.c b/drivers/net/ethernet/intel/ice/ice_lib.c
index 773a656ba92e..4068a1aac8e8 100644
--- a/drivers/net/ethernet/intel/ice/ice_lib.c
+++ b/drivers/net/ethernet/intel/ice/ice_lib.c
@@ -2207,7 +2207,6 @@ void ice_cfg_sw_rx_lldp(struct ice_pf *pf, bool enable)
 {
 	struct ice_vsi *vsi;
 	struct ice_vf *vf;
-	unsigned int bkt;
 
 	vsi = ice_get_main_vsi(pf);
 	ice_vsi_cfg_sw_lldp(vsi, false, enable);
@@ -2215,14 +2214,18 @@ void ice_cfg_sw_rx_lldp(struct ice_pf *pf, bool enable)
 	if (!test_bit(ICE_FLAG_SRIOV_ENA, pf->flags))
 		return;
 
-	ice_for_each_vf(pf, bkt, vf) {
-		vsi = ice_get_vf_vsi(vf);
-
-		if (WARN_ON(!vsi))
+	for (u16 vf_id = 0; vf_id < pf->vfs.num_supported; vf_id++) {
+		vf = ice_get_vf_by_id(pf, vf_id);
+		if (!vf)
 			continue;
 
-		if (ice_vf_is_lldp_ena(vf))
+		mutex_lock(&vf->cfg_lock);
+		vsi = ice_get_vf_vsi(vf);
+		if (vsi && ice_vf_is_lldp_ena(vf))
 			ice_vsi_cfg_sw_lldp(vsi, false, enable);
+		mutex_unlock(&vf->cfg_lock);
+
+		ice_put_vf(vf);
 	}
 }
 

base-commit: c2c187fd5fa667cedb0b946f5f7a5099fb8e8402
-- 
2.43.0


                 reply	other threads:[~2026-11-19  1:44 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20261119014446.577784-1-lcy8047@gmail.com \
    --to=lcy8047@gmail.com \
    --cc=andrew+netdev@lunn.ch \
    --cc=anthony.l.nguyen@intel.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@kernel.org \
    --cc=horms@kernel.org \
    --cc=intel-wired-lan@lists.osuosl.org \
    --cc=kuba@kernel.org \
    --cc=larysa.zaremba@intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=michal.swiatkowski@linux.intel.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=przemyslaw.kitszel@intel.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