Skip to content

Commit f3fbda3

Browse files
jacob-kelleranguy11
authored andcommitted
ice: Correctly initialize queue context values
The ice_alloc_lan_q_ctx function allocates the queue context array for a given traffic class. This function uses devm_kcalloc which will zero-allocate the structure. Thus, prior to any queue being setup by ice_ena_vsi_txq, the q_ctx structure will have a q_handle of 0 and a q_teid of 0. These are potentially valid values. Modify the ice_alloc_lan_q_ctx function to initialize every member of the q_ctx array to have invalid values. Modify ice_dis_vsi_txq to ensure that it assigns q_teid to an invalid value when it assigns q_handle to the invalid value as well. This will allow other code to check whether the queue context is currently valid before operating on it. Reviewed-by: Simon Horman <[email protected]> Reviewed-by: Daniel Machon <[email protected]> Signed-off-by: Jacob Keller <[email protected]> Signed-off-by: Dave Ertman <[email protected]> Tested-by: Sujai Buvaneswaran <[email protected]> Signed-off-by: Tony Nguyen <[email protected]>
1 parent 9d0cd5d commit f3fbda3

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

drivers/net/ethernet/intel/ice/ice_common.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4700,6 +4700,7 @@ ice_dis_vsi_txq(struct ice_port_info *pi, u16 vsi_handle, u8 tc, u8 num_queues,
47004700
break;
47014701
ice_free_sched_node(pi, node);
47024702
q_ctx->q_handle = ICE_INVAL_Q_HANDLE;
4703+
q_ctx->q_teid = ICE_INVAL_TEID;
47034704
}
47044705
mutex_unlock(&pi->sched_lock);
47054706
kfree(qg_list);

drivers/net/ethernet/intel/ice/ice_sched.c

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -569,18 +569,24 @@ ice_alloc_lan_q_ctx(struct ice_hw *hw, u16 vsi_handle, u8 tc, u16 new_numqs)
569569
{
570570
struct ice_vsi_ctx *vsi_ctx;
571571
struct ice_q_ctx *q_ctx;
572+
u16 idx;
572573

573574
vsi_ctx = ice_get_vsi_ctx(hw, vsi_handle);
574575
if (!vsi_ctx)
575576
return -EINVAL;
576577
/* allocate LAN queue contexts */
577578
if (!vsi_ctx->lan_q_ctx[tc]) {
578-
vsi_ctx->lan_q_ctx[tc] = devm_kcalloc(ice_hw_to_dev(hw),
579-
new_numqs,
580-
sizeof(*q_ctx),
581-
GFP_KERNEL);
582-
if (!vsi_ctx->lan_q_ctx[tc])
579+
q_ctx = devm_kcalloc(ice_hw_to_dev(hw), new_numqs,
580+
sizeof(*q_ctx), GFP_KERNEL);
581+
if (!q_ctx)
583582
return -ENOMEM;
583+
584+
for (idx = 0; idx < new_numqs; idx++) {
585+
q_ctx[idx].q_handle = ICE_INVAL_Q_HANDLE;
586+
q_ctx[idx].q_teid = ICE_INVAL_TEID;
587+
}
588+
589+
vsi_ctx->lan_q_ctx[tc] = q_ctx;
584590
vsi_ctx->num_lan_q_entries[tc] = new_numqs;
585591
return 0;
586592
}
@@ -592,9 +598,16 @@ ice_alloc_lan_q_ctx(struct ice_hw *hw, u16 vsi_handle, u8 tc, u16 new_numqs)
592598
sizeof(*q_ctx), GFP_KERNEL);
593599
if (!q_ctx)
594600
return -ENOMEM;
601+
595602
memcpy(q_ctx, vsi_ctx->lan_q_ctx[tc],
596603
prev_num * sizeof(*q_ctx));
597604
devm_kfree(ice_hw_to_dev(hw), vsi_ctx->lan_q_ctx[tc]);
605+
606+
for (idx = prev_num; idx < new_numqs; idx++) {
607+
q_ctx[idx].q_handle = ICE_INVAL_Q_HANDLE;
608+
q_ctx[idx].q_teid = ICE_INVAL_TEID;
609+
}
610+
598611
vsi_ctx->lan_q_ctx[tc] = q_ctx;
599612
vsi_ctx->num_lan_q_entries[tc] = new_numqs;
600613
}

0 commit comments

Comments
 (0)