Skip to contentSkip to conversation

iwl-net: ice: fix locking in ice_dcb_rebuild()

PATCH Superseded Bart Van Assche via Intel-wired-lan 3 participants 3 messages Mar 20 – Mar 26

Subsystems (2)

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 iwl-net: ice: fix locking in ice_dcb_rebuild()

Move the mutex_lock() call up to prevent that DCB settings change after the first ice_query_port_ets() call. The second ice_query_port_ets() call in ice_dcb_rebuild() is already protected by pf->tc_mutex.

This also fixes a bug in an error path, as before taking the first "goto dcb_error" in the function jumped over mutex_lock() to mutex_unlock().

This bug has been detected by the clang thread-safety analyzer.

Cc Tony Nguyen <[email protected]>
Cc Przemek Kitszel <[email protected]>
Cc Aleksandr Loktionov <[email protected]>
Fixes 242b5e068b25 ("ice: Fix DCB rebuild after reset")
---
 drivers/net/ethernet/intel/ice/ice_dcb_lib.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/net/ethernet/intel/ice/ice_dcb_lib.c +2 -2
index bd77f1c001ee..78ded6876581 100644
@@ -537,14 +537,14 @@ void ice_dcb_rebuild(struct ice_pf *pf)
 	struct ice_dcbx_cfg *err_cfg;
 	int ret;
 
+	mutex_lock(&pf->tc_mutex);
+
 	ret = ice_query_port_ets(pf->hw.port_info, &buf, sizeof(buf), NULL);
 	if (ret) {
 		dev_err(dev, "Query Port ETS failed\n");
 		goto dcb_error;
 	}
 
-	mutex_lock(&pf->tc_mutex);
-
 	if (!pf->hw.port_info->qos_cfg.is_sw_lldp)
 		ice_cfg_etsrec_defaults(pf->hw.port_info);
 
#1 lore raw
Quoted 9 lines · Bart Van Assche via Intel-wired-lan

Move the mutex_lock() call up to prevent that DCB settings change after the first ice_query_port_ets() call. The second ice_query_port_ets() call in ice_dcb_rebuild() is already protected by pf->tc_mutex.

This also fixes a bug in an error path, as before taking the first "goto dcb_error" in the function jumped over mutex_lock() to mutex_unlock().

This bug has been detected by the clang thread-safety analyzer.

nit:
I believe the subject should be
[PATCH iwl-net] ice: fix locking in ice_dcb_rebuild()
since iwl-net is the target tree name.

Reviewed-by on v1 1/1
#2 lore raw
In reply to Bart Van Assche via Intel-wired-lan
Quoted 45 lines

-----Original Message-----
From: Bart Van Assche <[email protected]>
Sent: Friday, March 20, 2026 5:07 PM
To: Nguyen, Anthony L <[email protected]>
Cc: Kitszel, Przemyslaw <[email protected]>; intel-wired- [email protected]; Bart Van Assche <[email protected]>; Loktionov, Aleksandr <[email protected]>
Subject: [PATCH] iwl-net: ice: fix locking in ice_dcb_rebuild()

Move the mutex_lock() call up to prevent that DCB settings change after the first ice_query_port_ets() call. The second ice_query_port_ets() call in ice_dcb_rebuild() is already protected by pf->tc_mutex.

This also fixes a bug in an error path, as before taking the first "goto dcb_error" in the function jumped over mutex_lock() to mutex_unlock().

This bug has been detected by the clang thread-safety analyzer.

Cc Tony Nguyen <[email protected]>
Cc Przemek Kitszel <[email protected]>
Cc Aleksandr Loktionov <[email protected]>
Fixes 242b5e068b25 ("ice: Fix DCB rebuild after reset")
---
 drivers/net/ethernet/intel/ice/ice_dcb_lib.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/net/ethernet/intel/ice/ice_dcb_lib.c +2 -0
index bd77f1c001ee..78ded6876581 100644
@@ -537,14 +537,14 @@ void ice_dcb_rebuild(struct ice_pf *pf)
 	struct ice_dcbx_cfg *err_cfg;
 	int ret;
 
+	mutex_lock(&pf->tc_mutex);
+
 	ret = ice_query_port_ets(pf->hw.port_info, &buf, sizeof(buf),

drivers/net/ethernet/intel/ice/ice_dcb_lib.c void ice_dcb_rebuild(struct ice_pf *pf) · line 550

Quoted 10 lines
drivers/net/ethernet/intel/ice/ice_dcb_lib.c +0 -2
 NULL);
 	if (ret) {
 		dev_err(dev, "Query Port ETS failed\n");
 		goto dcb_error;
 	}
 
-	mutex_lock(&pf->tc_mutex);
-
 	if (!pf->hw.port_info->qos_cfg.is_sw_lldp)
 		ice_cfg_etsrec_defaults(pf->hw.port_info);

I'd recommend to add Cc: [email protected]