]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob - releases/4.14.111/net-mlx5-avoid-panic-when-setting-vport-rate.patch
Linux 4.14.111
[thirdparty/kernel/stable-queue.git] / releases / 4.14.111 / net-mlx5-avoid-panic-when-setting-vport-rate.patch
1 From e3b1977d1f982a3f07d2fcbde552b3a07ac94dbc Mon Sep 17 00:00:00 2001
2 From: Tonghao Zhang <xiangxia.m.yue@gmail.com>
3 Date: Mon, 4 Mar 2019 00:27:16 -0800
4 Subject: net/mlx5: Avoid panic when setting vport rate
5
6 [ Upstream commit 24319258660a84dd77f4be026a55b10a12524919 ]
7
8 If we try to set VFs rate on a VF (not PF) net device, the kernel
9 will be crash. The commands are show as below:
10
11 $ echo 2 > /sys/class/net/$MLX_PF0/device/sriov_numvfs
12 $ ip link set $MLX_VF0 vf 0 max_tx_rate 2 min_tx_rate 1
13
14 If not applied the first patch ("net/mlx5: Avoid panic when setting
15 vport mac, getting vport config"), the command:
16
17 $ ip link set $MLX_VF0 vf 0 rate 100
18
19 can also crash the kernel.
20
21 [ 1650.006388] RIP: 0010:mlx5_eswitch_set_vport_rate+0x1f/0x260 [mlx5_core]
22 [ 1650.007092] do_setlink+0x982/0xd20
23 [ 1650.007129] __rtnl_newlink+0x528/0x7d0
24 [ 1650.007374] rtnl_newlink+0x43/0x60
25 [ 1650.007407] rtnetlink_rcv_msg+0x2a2/0x320
26 [ 1650.007484] netlink_rcv_skb+0xcb/0x100
27 [ 1650.007519] netlink_unicast+0x17f/0x230
28 [ 1650.007554] netlink_sendmsg+0x2d2/0x3d0
29 [ 1650.007592] sock_sendmsg+0x36/0x50
30 [ 1650.007625] ___sys_sendmsg+0x280/0x2a0
31 [ 1650.007963] __sys_sendmsg+0x58/0xa0
32 [ 1650.007998] do_syscall_64+0x5b/0x180
33 [ 1650.009438] entry_SYSCALL_64_after_hwframe+0x44/0xa9
34
35 Fixes: c9497c98901c ("net/mlx5: Add support for setting VF min rate")
36 Cc: Mohamad Haj Yahia <mohamad@mellanox.com>
37 Signed-off-by: Tonghao Zhang <xiangxia.m.yue@gmail.com>
38 Reviewed-by: Roi Dayan <roid@mellanox.com>
39 Acked-by: Saeed Mahameed <saeedm@mellanox.com>
40 Signed-off-by: Saeed Mahameed <saeedm@mellanox.com>
41 Signed-off-by: Sasha Levin <sashal@kernel.org>
42 ---
43 drivers/net/ethernet/mellanox/mlx5/core/eswitch.c | 13 +++++++++----
44 1 file changed, 9 insertions(+), 4 deletions(-)
45
46 diff --git a/drivers/net/ethernet/mellanox/mlx5/core/eswitch.c b/drivers/net/ethernet/mellanox/mlx5/core/eswitch.c
47 index 2f93e6e9dc9e..2aec0c021b6c 100644
48 --- a/drivers/net/ethernet/mellanox/mlx5/core/eswitch.c
49 +++ b/drivers/net/ethernet/mellanox/mlx5/core/eswitch.c
50 @@ -1966,19 +1966,24 @@ static int normalize_vports_min_rate(struct mlx5_eswitch *esw, u32 divider)
51 int mlx5_eswitch_set_vport_rate(struct mlx5_eswitch *esw, int vport,
52 u32 max_rate, u32 min_rate)
53 {
54 - u32 fw_max_bw_share = MLX5_CAP_QOS(esw->dev, max_tsar_bw_share);
55 - bool min_rate_supported = MLX5_CAP_QOS(esw->dev, esw_bw_share) &&
56 - fw_max_bw_share >= MLX5_MIN_BW_SHARE;
57 - bool max_rate_supported = MLX5_CAP_QOS(esw->dev, esw_rate_limit);
58 struct mlx5_vport *evport;
59 + u32 fw_max_bw_share;
60 u32 previous_min_rate;
61 u32 divider;
62 + bool min_rate_supported;
63 + bool max_rate_supported;
64 int err = 0;
65
66 if (!ESW_ALLOWED(esw))
67 return -EPERM;
68 if (!LEGAL_VPORT(esw, vport))
69 return -EINVAL;
70 +
71 + fw_max_bw_share = MLX5_CAP_QOS(esw->dev, max_tsar_bw_share);
72 + min_rate_supported = MLX5_CAP_QOS(esw->dev, esw_bw_share) &&
73 + fw_max_bw_share >= MLX5_MIN_BW_SHARE;
74 + max_rate_supported = MLX5_CAP_QOS(esw->dev, esw_rate_limit);
75 +
76 if ((min_rate && !min_rate_supported) || (max_rate && !max_rate_supported))
77 return -EOPNOTSUPP;
78
79 --
80 2.19.1
81