From: Saeed Mahameed <saeed@kernel•org>
To: "David S. Miller" <davem@davemloft•net>,
Jakub Kicinski <kuba@kernel•org>
Cc: netdev@vger•kernel.org, Maxim Mikityanskiy <maximmi@mellanox•com>,
Jesper Dangaard Brouer <brouer@redhat•com>,
Tariq Toukan <tariqt@nvidia•com>,
Saeed Mahameed <saeedm@nvidia•com>
Subject: [net 5/6] net/mlx5e: Fix division by 0 in mlx5e_select_queue
Date: Mon, 22 Mar 2021 13:25:23 -0700 [thread overview]
Message-ID: <20210322202524.68886-6-saeed@kernel.org> (raw)
In-Reply-To: <20210322202524.68886-1-saeed@kernel.org>
From: Maxim Mikityanskiy <maximmi@mellanox•com>
mlx5e_select_queue compares num_tc_x_num_ch to real_num_tx_queues to
determine if HTB and/or PTP offloads are active. If they are, it
calculates netdev_pick_tx() % num_tc_x_num_ch to prevent it from
selecting HTB and PTP queues for regular traffic. However, before the
channels are first activated, num_tc_x_num_ch is zero. If
ndo_select_queue gets called at this point, the HTB/PTP check will pass,
and mlx5e_select_queue will attempt to take a modulo by num_tc_x_num_ch,
which equals to zero.
This commit fixes the bug by assigning num_tc_x_num_ch to a non-zero
value before registering the netdev.
Fixes: 214baf22870c ("net/mlx5e: Support HTB offload")
Reported-by: Jesper Dangaard Brouer <brouer@redhat•com>
Signed-off-by: Maxim Mikityanskiy <maximmi@mellanox•com>
Reviewed-by: Tariq Toukan <tariqt@nvidia•com>
Signed-off-by: Saeed Mahameed <saeedm@nvidia•com>
---
drivers/net/ethernet/mellanox/mlx5/core/en_main.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_main.c b/drivers/net/ethernet/mellanox/mlx5/core/en_main.c
index c8b8249846a9..158f947a8503 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/en_main.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/en_main.c
@@ -4979,6 +4979,11 @@ void mlx5e_build_nic_params(struct mlx5e_priv *priv, struct mlx5e_xsk *xsk, u16
priv->max_nch);
params->num_tc = 1;
+ /* Set an initial non-zero value, so that mlx5e_select_queue won't
+ * divide by zero if called before first activating channels.
+ */
+ priv->num_tc_x_num_ch = params->num_channels * params->num_tc;
+
/* SQ */
params->log_sq_size = is_kdump_kernel() ?
MLX5E_PARAMS_MINIMUM_LOG_SQ_SIZE :
--
2.30.2
next prev parent reply other threads:[~2021-03-22 20:26 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-03-22 20:25 [pull request][net 0/6] mlx5 fixes 2021-03-22 Saeed Mahameed
2021-03-22 20:25 ` [net 1/6] net/mlx5: Add back multicast stats for uplink representor Saeed Mahameed
2021-03-23 0:30 ` patchwork-bot+netdevbpf
2021-03-22 20:25 ` [net 2/6] net/mlx5e: Allow to match on MPLS parameters only for MPLS over UDP Saeed Mahameed
2021-03-22 20:25 ` [net 3/6] net/mlx5e: Offload tuple rewrite for non-CT flows Saeed Mahameed
2021-03-22 20:25 ` [net 4/6] net/mlx5e: Fix error path for ethtool set-priv-flag Saeed Mahameed
2021-03-22 20:25 ` Saeed Mahameed [this message]
2021-03-22 20:25 ` [net 6/6] net/mlx5: SF, do not use ecpu bit for vhca state processing Saeed Mahameed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210322202524.68886-6-saeed@kernel.org \
--to=saeed@kernel$(echo .)org \
--cc=brouer@redhat$(echo .)com \
--cc=davem@davemloft$(echo .)net \
--cc=kuba@kernel$(echo .)org \
--cc=maximmi@mellanox$(echo .)com \
--cc=netdev@vger$(echo .)kernel.org \
--cc=saeedm@nvidia$(echo .)com \
--cc=tariqt@nvidia$(echo .)com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox