bnx2x: skip invalid DCBX priorities in bitmaps and FW config
PATCH 1/1 bnx2x: skip invalid DCBX priorities in bitmaps and FW config
When the DCBX application feature is disabled, bnx2x stores INVALID_TRAFFIC_TYPE_PRIORITY (0xffffffff) in traffic_type_priority[]. bnx2x_dcbx_map_nw() uses that value as a shift count, which UBSAN reports as:
shift exponent 4294967295 is too large for 32-bit type 'int'
bnx2x_dcbx_fw_struct() assigns the same sentinel to a u8 before shifting, so UBSAN reports exponent 255.
Skip priorities outside 0..MAX_PFC_PRIORITIES-1 when building COS bitmasks and when filling the firmware TX-start structure. Keep the stored sentinel so disabled-app state remains visible; skipped firmware entries stay zero from the existing memset.
Valid 802.1p priorities 0..7 keep the previous mapping and firmware encoding.
A userspace UBSAN extraction of these two functions reproduces the unpatched shifts and passes after this change. This is not a kernel or hardware test; the driver was not rebuilt or loaded.
--- drivers/net/ethernet/broadcom/bnx2x/bnx2x_dcb.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-)
drivers/net/ethernet/broadcom/bnx2x/bnx2x_dcb.c +13 -3
@@ -350,13 +350,20 @@ static void bnx2x_dcbx_map_nw(struct bnx2x *bp)int i;u32 unmapped = (1 <<MAX_PFC_PRIORITIES ) -1 ;/* all ones */ u32 *ttp = bp->dcbx_port_params.app.traffic_type_priority; -u32 nw_prio =1 << ttp[LLFC_TRAFFIC_TYPE_NW ]; +u32 nw_prio;struct bnx2x_dcbx_cos_params *cos_params = bp->dcbx_port_params.ets.cos_params; +if (ttp[LLFC_TRAFFIC_TYPE_NW ] >=MAX_PFC_PRIORITIES ) +return ; + + nw_prio =1 << ttp[LLFC_TRAFFIC_TYPE_NW ]; +/* get unmapped priorities by clearing mapped bits */ -for (i =0 ; i <LLFC_DRIVER_TRAFFIC_TYPE_MAX ; i++) - unmapped &= ~(1 << ttp[i]); +for (i =0 ; i <LLFC_DRIVER_TRAFFIC_TYPE_MAX ; i++) { +if (ttp[i] <MAX_PFC_PRIORITIES ) + unmapped &= ~(1 << ttp[i]); + }/* find cos for nw prio and extend it with unmapped */ for (i =0 ; i <ARRAY_SIZE (bp->dcbx_port_params.ets.cos_params); i++) {
@@ -1871,6 +1878,9 @@ static void bnx2x_dcbx_fw_struct(struct bnx2x *bp,/* Fill priority parameters */ for (pri =0 ; pri <LLFC_DRIVER_TRAFFIC_TYPE_MAX ; pri++) { +if (ttp[pri] >=MAX_PFC_PRIORITIES ) +continue ; + tt2cos[pri].priority = ttp[pri]; pri_bit =1 << tt2cos[pri].priority;
Signature · 1 line
2.50.1 (Apple Git-155)
Paolo Abeni
maintainerThis is an AI-generated review of your patch. The human sending this email has considered the AI review valid, or at least plausible. Full review at: https://netdev-ai.bots.linux.dev/sashiko/
---
bnx2x: skip invalid DCBX priorities in bitmaps and FW config
This patch avoids shifting by INVALID_TRAFFIC_TYPE_PRIORITY (0xffffffff) in bnx2x_dcbx_map_nw() and bnx2x_dcbx_fw_struct() by skipping any traffic type whose stored priority is outside 0..MAX_PFC_PRIORITIES-1. The stored sentinel itself is left untouched.
Quoted 4 lines
drivers/net/ethernet/broadcom/bnx2x/bnx2x_dcb.c +0
-0
[ ... ]
drivers/net/ethernet/broadcom/bnx2x/bnx2x_dcb.c static void bnx2x_dcbx_fw_struct(struct bnx2x *bp, · line 1886
Quoted 10 lines
drivers/net/ethernet/broadcom/bnx2x/bnx2x_dcb.c +3
-0@@ -1871,6 +1878,9 @@ static void bnx2x_dcbx_fw_struct(struct bnx2x *bp,/* Fill priority parameters */ for (pri =0 ; pri <LLFC_DRIVER_TRAFFIC_TYPE_MAX ; pri++) { +if (ttp[pri] >=MAX_PFC_PRIORITIES ) +continue ; + tt2cos[pri].priority = ttp[pri]; pri_bit =1 << tt2cos[pri].priority;
[Severity: High]
Does this continue change what the firmware is told about unmapped traffic types?
When the DCBX app feature is disabled or reports an error, bnx2x_dcbx_get_ap_feature() fills the whole table with the sentinel:
bp->dcbx_port_params.app.enabled = false; for (index = 0 ; index < LLFC_DRIVER_TRAFFIC_TYPE_MAX; index++) ttp[index] = INVALID_TRAFFIC_TYPE_PRIORITY;
Before this patch, the two assignments in bnx2x_dcbx_fw_struct() truncated that u32 sentinel into the u8 HSI fields, so both tt2cos[pri].priority and pfc_fw_cfg->dcb_outer_pri[pri] ended up as 0xFF, which is the value bnx2x_fw_defs.h documents as "not mapped":
/* used by array traffic_type_to_priority[] to mark traffic type \ that is not mapped to priority*/ #define LLFC_TRAFFIC_TYPE_TO_PRIORITY_UNMAPPED 0xFF
With the new continue, both fields stay 0 from the memset earlier in bnx2x_dcbx_fw_struct(). Since 0 is a valid 802.1p priority, doesn't this now tell the firmware that the NW, iSCSI and FCoE traffic types are each mapped to priority 0, rather than being unmapped?
The only early return in bnx2x_dcbx_fw_struct() is:
/* to disable DCB - the structure must be zeroed */ if ((bp->dcbx_error & DCBX_REMOTE_MIB_ERROR) && !mfw_configured) return;
which tests a different error bit than the app error/disabled bits, so the sentinel state does reach the loop. The UBSAN "exponent 255" report in the commit message confirms that.
The values are not driver-local bookkeeping. bnx2x_dcbx_resume_hw_tx() calls bnx2x_dcbx_fw_struct() and then issues BNX2X_F_CMD_TX_START, which reaches bnx2x_func_send_tx_start():
for (i = 0; i < ARRAY_SIZE(rdata->traffic_type_to_priority_cos); i++) rdata->traffic_type_to_priority_cos[i] = tx_start_params->traffic_type_to_priority_cos[i]; for (i = 0; i < MAX_TRAFFIC_TYPES; i++) rdata->dcb_outer_pri[i] = tx_start_params->dcb_outer_pri[i];
so both arrays go into the DMA-resident flow_control_configuration posted with RAMROD_CMD_ID_COMMON_START_TRAFFIC.
Would it work to keep the firmware encoding and only skip the shift, for example:
if (ttp[pri] >= MAX_PFC_PRIORITIES) {
tt2cos[pri].priority = LLFC_TRAFFIC_TYPE_TO_PRIORITY_UNMAPPED;
pfc_fw_cfg->dcb_outer_pri[pri] =
LLFC_TRAFFIC_TYPE_TO_PRIORITY_UNMAPPED;
continue;
}For accuracy: tt2cos[pri].cos was already 0 before the patch, because the u16 pri_bit = 1 << 255 evaluated to 0 in practice and the COS match loop never fired. The encoding changes are limited to tt2cos[pri].priority and dcb_outer_pri[pri] going from 0xFF to 0.
The commit message says:
Quoted 2 lines
Keep the stored sentinel so disabled-app state remains visible; skipped firmware entries stay zero from the existing memset.
and:
Quoted 2 lines
Valid 802.1p priorities 0..7 keep the previous mapping and firmware encoding.
Could these be reworded to state that the firmware encoding for the invalid/unmapped entries does change from 0xFF to 0, and why that is considered equivalent? The commit message also notes the driver "was not rebuilt or loaded", so this part is untested against firmware.
Signature · 1 line
This is an AI-generated review.