Skip to content

Commit 2431925

Browse files
hao022Saeed Mahameed
authored andcommitted
net/mlx5: Avoid panic when setting vport rate
If we try to set VFs rate on a VF (not PF) net device, the kernel will be crash. The commands are show as below: $ echo 2 > /sys/class/net/$MLX_PF0/device/sriov_numvfs $ ip link set $MLX_VF0 vf 0 max_tx_rate 2 min_tx_rate 1 If not applied the first patch ("net/mlx5: Avoid panic when setting vport mac, getting vport config"), the command: $ ip link set $MLX_VF0 vf 0 rate 100 can also crash the kernel. [ 1650.006388] RIP: 0010:mlx5_eswitch_set_vport_rate+0x1f/0x260 [mlx5_core] [ 1650.007092] do_setlink+0x982/0xd20 [ 1650.007129] __rtnl_newlink+0x528/0x7d0 [ 1650.007374] rtnl_newlink+0x43/0x60 [ 1650.007407] rtnetlink_rcv_msg+0x2a2/0x320 [ 1650.007484] netlink_rcv_skb+0xcb/0x100 [ 1650.007519] netlink_unicast+0x17f/0x230 [ 1650.007554] netlink_sendmsg+0x2d2/0x3d0 [ 1650.007592] sock_sendmsg+0x36/0x50 [ 1650.007625] ___sys_sendmsg+0x280/0x2a0 [ 1650.007963] __sys_sendmsg+0x58/0xa0 [ 1650.007998] do_syscall_64+0x5b/0x180 [ 1650.009438] entry_SYSCALL_64_after_hwframe+0x44/0xa9 Fixes: c9497c9 ("net/mlx5: Add support for setting VF min rate") Cc: Mohamad Haj Yahia <mohamad@mellanox.com> Signed-off-by: Tonghao Zhang <xiangxia.m.yue@gmail.com> Reviewed-by: Roi Dayan <roid@mellanox.com> Acked-by: Saeed Mahameed <saeedm@mellanox.com> Signed-off-by: Saeed Mahameed <saeedm@mellanox.com>
1 parent 6e77c41 commit 2431925

File tree

1 file changed

+9
-4
lines changed
  • drivers/net/ethernet/mellanox/mlx5/core

1 file changed

+9
-4
lines changed

drivers/net/ethernet/mellanox/mlx5/core/eswitch.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2297,19 +2297,24 @@ static int normalize_vports_min_rate(struct mlx5_eswitch *esw, u32 divider)
22972297
int mlx5_eswitch_set_vport_rate(struct mlx5_eswitch *esw, int vport,
22982298
u32 max_rate, u32 min_rate)
22992299
{
2300-
u32 fw_max_bw_share = MLX5_CAP_QOS(esw->dev, max_tsar_bw_share);
2301-
bool min_rate_supported = MLX5_CAP_QOS(esw->dev, esw_bw_share) &&
2302-
fw_max_bw_share >= MLX5_MIN_BW_SHARE;
2303-
bool max_rate_supported = MLX5_CAP_QOS(esw->dev, esw_rate_limit);
23042300
struct mlx5_vport *evport;
2301+
u32 fw_max_bw_share;
23052302
u32 previous_min_rate;
23062303
u32 divider;
2304+
bool min_rate_supported;
2305+
bool max_rate_supported;
23072306
int err = 0;
23082307

23092308
if (!ESW_ALLOWED(esw))
23102309
return -EPERM;
23112310
if (!LEGAL_VPORT(esw, vport))
23122311
return -EINVAL;
2312+
2313+
fw_max_bw_share = MLX5_CAP_QOS(esw->dev, max_tsar_bw_share);
2314+
min_rate_supported = MLX5_CAP_QOS(esw->dev, esw_bw_share) &&
2315+
fw_max_bw_share >= MLX5_MIN_BW_SHARE;
2316+
max_rate_supported = MLX5_CAP_QOS(esw->dev, esw_rate_limit);
2317+
23132318
if ((min_rate && !min_rate_supported) || (max_rate && !max_rate_supported))
23142319
return -EOPNOTSUPP;
23152320

0 commit comments

Comments
 (0)