Skip to contentSkip to conversation

ice: check for unregistering correct number of devlink params

PATCH Superseded Dave Ertman 3 participants 4 messages May 20, 2024 – May 22, 2024

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ice: check for unregistering correct number of devlink params

On module load, the ice driver checks for the lack of a specific PF capabilty to determine if it should reduce the number of devlink params to register. One situation when this test returns true is when the driver loads in safe mode. The same check is not present on the unload path when devlink params are unregistered. This results in the driver triggering a WARN_ON in the kernel devlink code.

Add a symmetrical check in the unload path so that the correct value is sent to the devlink unregister params call.

Fixes 109eb2917284 ("ice: Add tx_scheduling_layers devlink param")
CC Lukasz Czapnik <[email protected]>
---
 drivers/net/ethernet/intel/ice/devlink/devlink.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
drivers/net/ethernet/intel/ice/devlink/devlink.c +7 -1
index c4b69655cdf5..94ad78d2d11e 100644
@@ -1477,8 +1477,14 @@ int ice_devlink_register_params(struct ice_pf *pf)
 
 void ice_devlink_unregister_params(struct ice_pf *pf)
 {
+	size_t params_size = ARRAY_SIZE(ice_devlink_params);
+	struct ice_hw *hw = &pf->hw;
+
+	if (!hw->func_caps.common_cap.tx_sched_topo_comp_mode_en)
+		params_size--;
+
 	devl_params_unregister(priv_to_devlink(pf), ice_devlink_params,
-			       ARRAY_SIZE(ice_devlink_params));
+			       params_size);
 }
 
 #define ICE_DEVLINK_READ_BLK_SIZE (1024 * 1024)
Signature · 1 line
2.44.0
#1 lore raw
Quoted 28 lines · Dave Ertman

On module load, the ice driver checks for the lack of a specific PF capabilty to determine if it should reduce the number of devlink params to register. One situation when this test returns true is when the driver loads in safe mode. The same check is not present on the unload path when devlink params are unregistered. This results in the driver triggering a WARN_ON in the kernel devlink code.

Add a symmetrical check in the unload path so that the correct value is sent to the devlink unregister params call.

Fixes 109eb2917284 ("ice: Add tx_scheduling_layers devlink param")
CC Lukasz Czapnik <[email protected]>
---
 drivers/net/ethernet/intel/ice/devlink/devlink.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
drivers/net/ethernet/intel/ice/devlink/devlink.c +2 -0
index c4b69655cdf5..94ad78d2d11e 100644
@@ -1477,8 +1477,14 @@ int ice_devlink_register_params(struct ice_pf *pf)
 
 void ice_devlink_unregister_params(struct ice_pf *pf)
 {
+	size_t params_size = ARRAY_SIZE(ice_devlink_params);
+	struct ice_hw *hw = &pf->hw;

drivers/net/ethernet/intel/ice/devlink/devlink.c int ice_devlink_register_params(struct ice_pf *pf) · line 1490

Quoted 10 lines
drivers/net/ethernet/intel/ice/devlink/devlink.c +5 -1
+
+	if (!hw->func_caps.common_cap.tx_sched_topo_comp_mode_en)
+		params_size--;
+
 	devl_params_unregister(priv_to_devlink(pf), ice_devlink_params,
-			       ARRAY_SIZE(ice_devlink_params));
+			       params_size);
 }
 
 #define ICE_DEVLINK_READ_BLK_SIZE (1024 * 1024)

What? This makes no sense. Just separate the Tx sched parameter from the list and register it separately based on whether the flag is set. Then only unregister it when the flag is set.

Messing with the parameter size list is brittle and requires us to be extra careful that the Tx sched parameter is last.

NACK. Please fix both the registration and unregistration to avoid this.

Thanks,
Jake

maintainer
#2 lore raw
Quoted 40 lines · Jacob Keller
Quoted 37 lines · Dave Ertman

On module load, the ice driver checks for the lack of a specific PF capabilty to determine if it should reduce the number of devlink params to register. One situation when this test returns true is when the driver loads in safe mode. The same check is not present on the unload path when devlink params are unregistered. This results in the driver triggering a WARN_ON in the kernel devlink code.

Add a symmetrical check in the unload path so that the correct value is sent to the devlink unregister params call.

Fixes 109eb2917284 ("ice: Add tx_scheduling_layers devlink param")
CC Lukasz Czapnik <[email protected]>
---
  drivers/net/ethernet/intel/ice/devlink/devlink.c | 8 +++++++-
  1 file changed, 7 insertions(+), 1 deletion(-)
drivers/net/ethernet/intel/ice/devlink/devlink.c +7 -1
index c4b69655cdf5..94ad78d2d11e 100644
@@ -1477,8 +1477,14 @@ int ice_devlink_register_params(struct ice_pf *pf)
 
  void ice_devlink_unregister_params(struct ice_pf *pf)
  {
+	size_t params_size = ARRAY_SIZE(ice_devlink_params);
+	struct ice_hw *hw = &pf->hw;
+
+	if (!hw->func_caps.common_cap.tx_sched_topo_comp_mode_en)
+		params_size--;
+
  	devl_params_unregister(priv_to_devlink(pf), ice_devlink_params,
-			       ARRAY_SIZE(ice_devlink_params));
+			       params_size);
  }
 
Quoted 9 lines

drivers/net/ethernet/intel/ice/devlink/devlink.c int ice_devlink_register_params(struct ice_pf *pf) · line 1490

Quoted 1 line
drivers/net/ethernet/intel/ice/devlink/devlink.c +0 -0
  #define ICE_DEVLINK_READ_BLK_SIZE (1024 * 1024)

What? This makes no sense. Just separate the Tx sched parameter from the list and register it separately based on whether the flag is set. Then only unregister it when the flag is set.

Messing with the parameter size list is brittle and requires us to be extra careful that the Tx sched parameter is last.

for current situation your proposed solution would be indeed more elegant

Quoted 4 lines

NACK. Please fix both the registration and unregistration to avoid this.

Thanks,
Jake

please note that for general case (multiple conditional params), with possibility of the need of a rollback (when we fail in the middle of params register) current API is not optimal

I have already suggested @Mateusz to extend struct devlink_param by an additional field, so the skipping will be performed by devlink code, with drivers only setting the field. It's still not that convenient as we have typically a global array of params without easy index<->feature mapping. But other drivers will benefit too

#3 lore raw
Quoted 63 lines · Przemek Kitszel
Quoted 40 lines · Jacob Keller
Quoted 37 lines · Dave Ertman

On module load, the ice driver checks for the lack of a specific PF capabilty to determine if it should reduce the number of devlink params to register. One situation when this test returns true is when the driver loads in safe mode. The same check is not present on the unload path when devlink params are unregistered. This results in the driver triggering a WARN_ON in the kernel devlink code.

Add a symmetrical check in the unload path so that the correct value is sent to the devlink unregister params call.

Fixes 109eb2917284 ("ice: Add tx_scheduling_layers devlink param")
CC Lukasz Czapnik <[email protected]>
---
  drivers/net/ethernet/intel/ice/devlink/devlink.c | 8 +++++++-
  1 file changed, 7 insertions(+), 1 deletion(-)
drivers/net/ethernet/intel/ice/devlink/devlink.c +7 -1
index c4b69655cdf5..94ad78d2d11e 100644
@@ -1477,8 +1477,14 @@ int ice_devlink_register_params(struct ice_pf *pf)
 
  void ice_devlink_unregister_params(struct ice_pf *pf)
  {
+	size_t params_size = ARRAY_SIZE(ice_devlink_params);
+	struct ice_hw *hw = &pf->hw;
+
+	if (!hw->func_caps.common_cap.tx_sched_topo_comp_mode_en)
+		params_size--;
+
  	devl_params_unregister(priv_to_devlink(pf), ice_devlink_params,
-			       ARRAY_SIZE(ice_devlink_params));
+			       params_size);
  }
 
Quoted 9 lines

drivers/net/ethernet/intel/ice/devlink/devlink.c int ice_devlink_register_params(struct ice_pf *pf) · line 1490

Quoted 1 line
drivers/net/ethernet/intel/ice/devlink/devlink.c +0 -0
  #define ICE_DEVLINK_READ_BLK_SIZE (1024 * 1024)

What? This makes no sense. Just separate the Tx sched parameter from the list and register it separately based on whether the flag is set. Then only unregister it when the flag is set.

Messing with the parameter size list is brittle and requires us to be extra careful that the Tx sched parameter is last.

for current situation your proposed solution would be indeed more elegant

Quoted 4 lines

NACK. Please fix both the registration and unregistration to avoid this.

Thanks,
Jake

please note that for general case (multiple conditional params), with possibility of the need of a rollback (when we fail in the middle of params register) current API is not optimal

Quoted 5 lines

I have already suggested @Mateusz to extend struct devlink_param by an additional field, so the skipping will be performed by devlink code, with drivers only setting the field. It's still not that convenient as we have typically a global array of params without easy index<->feature mapping. But other drivers will benefit too

This would be more useful. Alternatively, we could just ignore or warn about errors on adding parameters and continue loading rather than trying to unroll.