Skip to content

Commit 573da3c

Browse files
Eran Ben Elishagregkh
authored andcommitted
net/mlx5e: Fix TXQ indices to be sequential
[ Upstream commit c55d8b1 ] Cited patch changed (channel index, tc) => (TXQ index) mapping to be a static one, in order to keep indices consistent when changing number of channels or TCs. For 32 channels (OOB) and 8 TCs, real num of TXQs is 256. When reducing the amount of channels to 8, the real num of TXQs will be changed to 64. This indices method is buggy: - Channel #0, TC 3, the TXQ index is 96. - Index 8 is not valid, as there is no such TXQ from driver perspective (As it represents channel raspberrypi#8, TC 0, which is not valid with the above configuration). As part of driver's select queue, it calls netdev_pick_tx which returns an index in the range of real number of TXQs. Depends on the return value, with the examples above, driver could have returned index larger than the real number of tx queues, or crash the kernel as it tries to read invalid address of SQ which was not allocated. Fix that by allocating sequential TXQ indices, and hold a new mapping between (channel index, tc) => (real TXQ index). This mapping will be updated as part of priv channels activation, and is used in mlx5e_select_queue to find the selected queue index. The existing indices mapping (channel_tc2txq) is no longer needed, as it is used only for statistics structures and can be calculated on run time. Delete its definintion and updates. Fixes: 8bfaf07 ("net/mlx5e: Present SW stats when state is not opened") Signed-off-by: Eran Ben Elisha <eranbe@mellanox.com> Signed-off-by: Saeed Mahameed <saeedm@mellanox.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 280cec4 commit 573da3c

4 files changed

Lines changed: 15 additions & 22 deletions

File tree

‎drivers/net/ethernet/mellanox/mlx5/core/en.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -792,7 +792,7 @@ struct mlx5e_xsk {
792792
struct mlx5e_priv {
793793
/* priv data path fields - start */
794794
struct mlx5e_txqsq *txq2sq[MLX5E_MAX_NUM_CHANNELS * MLX5E_MAX_NUM_TC];
795-
int channel_tc2txq[MLX5E_MAX_NUM_CHANNELS][MLX5E_MAX_NUM_TC];
795+
int channel_tc2realtxq[MLX5E_MAX_NUM_CHANNELS][MLX5E_MAX_NUM_TC];
796796
#ifdef CONFIG_MLX5_CORE_EN_DCB
797797
struct mlx5e_dcbx_dp dcbx_dp;
798798
#endif

‎drivers/net/ethernet/mellanox/mlx5/core/en_main.c‎

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1678,11 +1678,10 @@ static int mlx5e_open_sqs(struct mlx5e_channel *c,
16781678
struct mlx5e_params *params,
16791679
struct mlx5e_channel_param *cparam)
16801680
{
1681-
struct mlx5e_priv *priv = c->priv;
16821681
int err, tc;
16831682

16841683
for (tc = 0; tc < params->num_tc; tc++) {
1685-
int txq_ix = c->ix + tc * priv->max_nch;
1684+
int txq_ix = c->ix + tc * params->num_channels;
16861685

16871686
err = mlx5e_open_txqsq(c, c->priv->tisn[tc], txq_ix,
16881687
params, &cparam->sq, &c->sq[tc], tc);
@@ -2856,26 +2855,21 @@ static void mlx5e_netdev_set_tcs(struct net_device *netdev)
28562855
netdev_set_tc_queue(netdev, tc, nch, 0);
28572856
}
28582857

2859-
static void mlx5e_build_tc2txq_maps(struct mlx5e_priv *priv)
2858+
static void mlx5e_build_txq_maps(struct mlx5e_priv *priv)
28602859
{
2861-
int i, tc;
2860+
int i, ch;
28622861

2863-
for (i = 0; i < priv->max_nch; i++)
2864-
for (tc = 0; tc < priv->profile->max_tc; tc++)
2865-
priv->channel_tc2txq[i][tc] = i + tc * priv->max_nch;
2866-
}
2862+
ch = priv->channels.num;
28672863

2868-
static void mlx5e_build_tx2sq_maps(struct mlx5e_priv *priv)
2869-
{
2870-
struct mlx5e_channel *c;
2871-
struct mlx5e_txqsq *sq;
2872-
int i, tc;
2864+
for (i = 0; i < ch; i++) {
2865+
int tc;
2866+
2867+
for (tc = 0; tc < priv->channels.params.num_tc; tc++) {
2868+
struct mlx5e_channel *c = priv->channels.c[i];
2869+
struct mlx5e_txqsq *sq = &c->sq[tc];
28732870

2874-
for (i = 0; i < priv->channels.num; i++) {
2875-
c = priv->channels.c[i];
2876-
for (tc = 0; tc < c->num_tc; tc++) {
2877-
sq = &c->sq[tc];
28782871
priv->txq2sq[sq->txq_ix] = sq;
2872+
priv->channel_tc2realtxq[i][tc] = i + tc * ch;
28792873
}
28802874
}
28812875
}
@@ -2890,7 +2884,7 @@ void mlx5e_activate_priv_channels(struct mlx5e_priv *priv)
28902884
netif_set_real_num_tx_queues(netdev, num_txqs);
28912885
netif_set_real_num_rx_queues(netdev, num_rxqs);
28922886

2893-
mlx5e_build_tx2sq_maps(priv);
2887+
mlx5e_build_txq_maps(priv);
28942888
mlx5e_activate_channels(&priv->channels);
28952889
mlx5e_xdp_tx_enable(priv);
28962890
netif_tx_start_all_queues(priv->netdev);
@@ -4968,7 +4962,6 @@ static int mlx5e_nic_init(struct mlx5_core_dev *mdev,
49684962
if (err)
49694963
mlx5_core_err(mdev, "TLS initialization failed, %d\n", err);
49704964
mlx5e_build_nic_netdev(netdev);
4971-
mlx5e_build_tc2txq_maps(priv);
49724965

49734966
return 0;
49744967
}

‎drivers/net/ethernet/mellanox/mlx5/core/en_stats.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1435,7 +1435,7 @@ static int mlx5e_grp_channels_fill_strings(struct mlx5e_priv *priv, u8 *data,
14351435
for (j = 0; j < NUM_SQ_STATS; j++)
14361436
sprintf(data + (idx++) * ETH_GSTRING_LEN,
14371437
sq_stats_desc[j].format,
1438-
priv->channel_tc2txq[i][tc]);
1438+
i + tc * max_nch);
14391439

14401440
for (i = 0; i < max_nch; i++) {
14411441
for (j = 0; j < NUM_XSKSQ_STATS * is_xsk; j++)

‎drivers/net/ethernet/mellanox/mlx5/core/en_tx.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ u16 mlx5e_select_queue(struct net_device *dev, struct sk_buff *skb,
9393
if (txq_ix >= num_channels)
9494
txq_ix = priv->txq2sq[txq_ix]->ch_ix;
9595

96-
return priv->channel_tc2txq[txq_ix][up];
96+
return priv->channel_tc2realtxq[txq_ix][up];
9797
}
9898

9999
static inline int mlx5e_skb_l2_header_offset(struct sk_buff *skb)

0 commit comments

Comments
 (0)