net/mlx5: Avoid panic when setting vport mac, getting vport config
Subsystems (3)
PATCH v2 1/2 net/mlx5: Avoid panic when setting vport mac, getting vport config
From: Tonghao Zhang <[email protected]>
If we try to set VFs mac address 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 mac 00:11:22:33:44:00
[exception RIP: mlx5_eswitch_set_vport_mac+41] [ffffb8b7079e3688] do_setlink at ffffffff8f67f85b [ffffb8b7079e37a8] __rtnl_newlink at ffffffff8f683778 [ffffb8b7079e3b68] rtnl_newlink at ffffffff8f683a63 [ffffb8b7079e3b90] rtnetlink_rcv_msg at ffffffff8f67d812 [ffffb8b7079e3c10] netlink_rcv_skb at ffffffff8f6b88ab [ffffb8b7079e3c60] netlink_unicast at ffffffff8f6b808f [ffffb8b7079e3ca0] netlink_sendmsg at ffffffff8f6b8412 [ffffb8b7079e3d18] sock_sendmsg at ffffffff8f6452f6 [ffffb8b7079e3d30] ___sys_sendmsg at ffffffff8f645860 [ffffb8b7079e3eb0] __sys_sendmsg at ffffffff8f647a38 [ffffb8b7079e3f38] do_syscall_64 at ffffffff8f00401b [ffffb8b7079e3f50] entry_SYSCALL_64_after_hwframe at ffffffff8f80008c
and
[exception RIP: mlx5_eswitch_get_vport_config+12] [ffffa70607e57678] mlx5e_get_vf_config at ffffffffc03c7f8f [mlx5_core] [ffffa70607e57688] do_setlink at ffffffffbc67fa59 [ffffa70607e577a8] __rtnl_newlink at ffffffffbc683778 [ffffa70607e57b68] rtnl_newlink at ffffffffbc683a63 [ffffa70607e57b90] rtnetlink_rcv_msg at ffffffffbc67d812 [ffffa70607e57c10] netlink_rcv_skb at ffffffffbc6b88ab [ffffa70607e57c60] netlink_unicast at ffffffffbc6b808f [ffffa70607e57ca0] netlink_sendmsg at ffffffffbc6b8412 [ffffa70607e57d18] sock_sendmsg at ffffffffbc6452f6 [ffffa70607e57d30] ___sys_sendmsg at ffffffffbc645860 [ffffa70607e57eb0] __sys_sendmsg at ffffffffbc647a38 [ffffa70607e57f38] do_syscall_64 at ffffffffbc00401b [ffffa70607e57f50] entry_SYSCALL_64_after_hwframe at ffffffffbc80008c
---v1->v2: check only the esw is null, instead of ESW_ALLOWED.
--- drivers/net/ethernet/mellanox/mlx5/core/eswitch.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/eswitch.c +2 -2
@@ -1871,7 +1871,7 @@ int mlx5_eswitch_set_vport_mac(struct mlx5_eswitch *esw,u64 node_guid;int err =0 ; -if (!MLX5_CAP_GEN (esw->dev, vport_group_manager)) +if (!esw || !MLX5_CAP_GEN (esw->dev, vport_group_manager))return -EPERM ;if (!LEGAL_VPORT (esw, vport) ||is_multicast_ether_addr (mac))return -EINVAL ;
@@ -1945,7 +1945,7 @@ int mlx5_eswitch_get_vport_config(struct mlx5_eswitch *esw, {struct mlx5_vport *evport; -if (!MLX5_CAP_GEN (esw->dev, vport_group_manager)) +if (!esw || !MLX5_CAP_GEN (esw->dev, vport_group_manager))return -EPERM ;if (!LEGAL_VPORT (esw, vport))return -EINVAL ;
Signature · 1 line
1.8.3.1
PATCH v2 2/2 net/mlx5: Avoid panic when setting vport rate
From: Tonghao Zhang <[email protected]>
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
---v1->v2: change commit log
--- drivers/net/ethernet/mellanox/mlx5/core/eswitch.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/eswitch.c +9 -4
@@ -2116,19 +2116,24 @@ static int normalize_vports_min_rate(struct mlx5_eswitch *esw, u32 divider)int mlx5_eswitch_set_vport_rate (struct mlx5_eswitch *esw,int vport,u32 max_rate,u32 min_rate) { -u32 fw_max_bw_share =MLX5_CAP_QOS (esw->dev, max_tsar_bw_share); -bool min_rate_supported =MLX5_CAP_QOS (esw->dev, esw_bw_share) && - fw_max_bw_share >=MLX5_MIN_BW_SHARE ; -bool max_rate_supported =MLX5_CAP_QOS (esw->dev, esw_rate_limit);struct mlx5_vport *evport; +u32 fw_max_bw_share;u32 previous_min_rate;u32 divider; +bool min_rate_supported; +bool max_rate_supported;int err =0 ;if (!ESW_ALLOWED (esw))return -EPERM ;if (!LEGAL_VPORT (esw, vport))return -EINVAL ; + + fw_max_bw_share =MLX5_CAP_QOS (esw->dev, max_tsar_bw_share); + min_rate_supported =MLX5_CAP_QOS (esw->dev, esw_bw_share) && + fw_max_bw_share >=MLX5_MIN_BW_SHARE ; + max_rate_supported =MLX5_CAP_QOS (esw->dev, esw_rate_limit); +if ((min_rate && !min_rate_supported) || (max_rate && !max_rate_supported))return -EOPNOTSUPP ;
Signature · 1 line
1.8.3.1
Re: [PATCH net v2 2/2] net/mlx5: Avoid panic when setting vport rate
Quoted 62 lines · On 04/03/2019 10:27, [email protected] wrote:
From: Tonghao Zhang <[email protected]>
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 1If 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 100can 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/0xa9Fixes c9497c98901c ("net/mlx5: Add support for setting VF min rate")Cc Mohamad Haj Yahia <[email protected]>Signed-off-by Tonghao Zhang <[email protected]>---
v1->v2: change commit log--- drivers/net/ethernet/mellanox/mlx5/core/eswitch.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-)drivers/net/ethernet/mellanox/mlx5/core/eswitch.c +3
-4@@ -2116,19 +2116,24 @@ static int normalize_vports_min_rate(struct mlx5_eswitch *esw, u32 divider)int mlx5_eswitch_set_vport_rate (struct mlx5_eswitch *esw,int vport,u32 max_rate,u32 min_rate) { -u32 fw_max_bw_share =MLX5_CAP_QOS (esw->dev, max_tsar_bw_share); -bool min_rate_supported =MLX5_CAP_QOS (esw->dev, esw_bw_share) && - fw_max_bw_share >=MLX5_MIN_BW_SHARE ; -bool max_rate_supported =MLX5_CAP_QOS (esw->dev, esw_rate_limit);struct mlx5_vport *evport; +u32 fw_max_bw_share;u32 previous_min_rate;u32 divider; +bool min_rate_supported; +bool max_rate_supported;int err =0 ;if (!ESW_ALLOWED (esw))return -EPERM ;if (!LEGAL_VPORT (esw, vport))
drivers/net/ethernet/mellanox/mlx5/core/eswitch.c static int normalize_vports_min_rate(struct mlx5_eswitch *esw, u32 divider) · line 2139
Quoted 10 lines
drivers/net/ethernet/mellanox/mlx5/core/eswitch.c +6
-0return -EINVAL ; + + fw_max_bw_share =MLX5_CAP_QOS (esw->dev, max_tsar_bw_share); + min_rate_supported =MLX5_CAP_QOS (esw->dev, esw_bw_share) && + fw_max_bw_share >=MLX5_MIN_BW_SHARE ; + max_rate_supported =MLX5_CAP_QOS (esw->dev, esw_rate_limit); +if ((min_rate && !min_rate_supported) || (max_rate && !max_rate_supported))return -EOPNOTSUPP ;
Saeed Mahameed
Acked-byRe: [PATCH net v2 2/2] net/mlx5: Avoid panic when setting vport rate
Quoted 79 lines · Roi Dayan
Quoted 77 lines · On 04/03/2019 10:27, [email protected] wrote:
From: Tonghao Zhang <[email protected]>
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 1If 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 100can 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/0xa9Fixes c9497c98901c ("net/mlx5: Add support for setting VF minrate")
Cc Mohamad Haj Yahia <[email protected]>Signed-off-by Tonghao Zhang <[email protected]>---
v1->v2: change commit log--- drivers/net/ethernet/mellanox/mlx5/core/eswitch.c | 13 +++++++++ ---- 1 file changed, 9 insertions(+), 4 deletions(-)drivers/net/ethernet/mellanox/mlx5/core/eswitch.c +0
-2@@ -2116,19 +2116,24 @@ static int normalize_vports_min_rate(struct mlx5_eswitch *esw, u32 divider) int mlx5_eswitch_set_vport_rate(struct mlx5_eswitch *esw, int vport, u32 max_rate, u32 min_rate) { - u32 fw_max_bw_share = MLX5_CAP_QOS(esw->dev, max_tsar_bw_share); -bool min_rate_supported =MLX5_CAP_QOS (esw->dev, esw_bw_share)&&
drivers/net/ethernet/mellanox/mlx5/core/eswitch.c +0
-1- fw_max_bw_share >=
MLX5_MIN_BW_SHARE;drivers/net/ethernet/mellanox/mlx5/core/eswitch.c +0
-1- bool max_rate_supported = MLX5_CAP_QOS(esw->dev,
esw_rate_limit);drivers/net/ethernet/mellanox/mlx5/core/eswitch.c +8
-0struct mlx5_vport *evport; +u32 fw_max_bw_share;u32 previous_min_rate;u32 divider; +bool min_rate_supported; +bool max_rate_supported;int err =0 ;if (!ESW_ALLOWED (esw))return -EPERM ;if (!LEGAL_VPORT (esw, vport))return -EINVAL ; + + fw_max_bw_share =MLX5_CAP_QOS (esw->dev, max_tsar_bw_share); + min_rate_supported =MLX5_CAP_QOS (esw->dev, esw_bw_share) && + fw_max_bw_share >=MLX5_MIN_BW_SHARE ; + max_rate_supported =MLX5_CAP_QOS (esw->dev, esw_rate_limit);
Quoted 8 lines
Quoted 6 lines
drivers/net/ethernet/mellanox/mlx5/core/eswitch.c +1
-0+ if ((min_rate && !min_rate_supported) || (max_rate &&!max_rate_supported))
return-EOPNOTSUPP;Reviewed-by Roi Dayan <[email protected]>
Quoted 63 lines · On 04/03/2019 10:27, [email protected] wrote:
From: Tonghao Zhang <[email protected]>
If we try to set VFs mac address 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 mac 00:11:22:33:44:00[exception RIP: mlx5_eswitch_set_vport_mac+41] [
ffffb8b7079e3688]do_setlinkatffffffff8f67f85b[ffffb8b7079e37a8]__rtnl_newlinkatffffffff8f683778[ffffb8b7079e3b68]rtnl_newlinkatffffffff8f683a63[ffffb8b7079e3b90]rtnetlink_rcv_msgatffffffff8f67d812[ffffb8b7079e3c10]netlink_rcv_skbatffffffff8f6b88ab[ffffb8b7079e3c60]netlink_unicastatffffffff8f6b808f[ffffb8b7079e3ca0]netlink_sendmsgatffffffff8f6b8412[ffffb8b7079e3d18]sock_sendmsgatffffffff8f6452f6[ffffb8b7079e3d30]___sys_sendmsgatffffffff8f645860[ffffb8b7079e3eb0]__sys_sendmsgatffffffff8f647a38[ffffb8b7079e3f38]do_syscall_64atffffffff8f00401b[ffffb8b7079e3f50]entry_SYSCALL_64_after_hwframeatffffffff8f80008cand
[exception RIP: mlx5_eswitch_get_vport_config+12] [
ffffa70607e57678]mlx5e_get_vf_configatffffffffc03c7f8f[mlx5_core] [ffffa70607e57688]do_setlinkatffffffffbc67fa59[ffffa70607e577a8]__rtnl_newlinkatffffffffbc683778[ffffa70607e57b68]rtnl_newlinkatffffffffbc683a63[ffffa70607e57b90]rtnetlink_rcv_msgatffffffffbc67d812[ffffa70607e57c10]netlink_rcv_skbatffffffffbc6b88ab[ffffa70607e57c60]netlink_unicastatffffffffbc6b808f[ffffa70607e57ca0]netlink_sendmsgatffffffffbc6b8412[ffffa70607e57d18]sock_sendmsgatffffffffbc6452f6[ffffa70607e57d30]___sys_sendmsgatffffffffbc645860[ffffa70607e57eb0]__sys_sendmsgatffffffffbc647a38[ffffa70607e57f38]do_syscall_64atffffffffbc00401b[ffffa70607e57f50]entry_SYSCALL_64_after_hwframeatffffffffbc80008cFixes a8d70a054a718 ("net/mlx5: E-Switch, Disallow vlan/spoofcheck setup if not being esw manager")Cc Eli Cohen <[email protected]>Signed-off-by Tonghao Zhang <[email protected]>---
v1->v2: check only the esw is null, instead ofESW_ALLOWED.--- drivers/net/ethernet/mellanox/mlx5/core/eswitch.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)drivers/net/ethernet/mellanox/mlx5/core/eswitch.c +1
-1@@ -1871,7 +1871,7 @@ int mlx5_eswitch_set_vport_mac(struct mlx5_eswitch *esw,u64 node_guid;int err =0 ; -if (!MLX5_CAP_GEN (esw->dev, vport_group_manager)) +if (!esw || !MLX5_CAP_GEN (esw->dev, vport_group_manager))return -EPERM ;if (!LEGAL_VPORT (esw, vport) ||is_multicast_ether_addr (mac))return -EINVAL ;
drivers/net/ethernet/mellanox/mlx5/core/eswitch.c int mlx5_eswitch_get_vport_config(struct mlx5_eswitch *esw, · line 1951
Quoted 8 lines
drivers/net/ethernet/mellanox/mlx5/core/eswitch.c +1
-1@@ -1945,7 +1945,7 @@ int mlx5_eswitch_get_vport_config(struct mlx5_eswitch *esw, {struct mlx5_vport *evport; -if (!MLX5_CAP_GEN (esw->dev, vport_group_manager)) +if (!esw || !MLX5_CAP_GEN (esw->dev, vport_group_manager))return -EPERM ;if (!LEGAL_VPORT (esw, vport))return -EINVAL ;
Saeed Mahameed
Acked-byQuoted 74 lines · Roi Dayan
Quoted 72 lines · On 04/03/2019 10:27, [email protected] wrote:
From: Tonghao Zhang <[email protected]>
If we try to set VFs mac address 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 mac 00:11:22:33:44:00[exception RIP: mlx5_eswitch_set_vport_mac+41] [
ffffb8b7079e3688]do_setlinkatffffffff8f67f85b[ffffb8b7079e37a8]__rtnl_newlinkatffffffff8f683778[ffffb8b7079e3b68]rtnl_newlinkatffffffff8f683a63[ffffb8b7079e3b90]rtnetlink_rcv_msgatffffffff8f67d812[ffffb8b7079e3c10]netlink_rcv_skbatffffffff8f6b88ab[ffffb8b7079e3c60]netlink_unicastatffffffff8f6b808f[ffffb8b7079e3ca0]netlink_sendmsgatffffffff8f6b8412[ffffb8b7079e3d18]sock_sendmsgatffffffff8f6452f6[ffffb8b7079e3d30]___sys_sendmsgatffffffff8f645860[ffffb8b7079e3eb0]__sys_sendmsgatffffffff8f647a38[ffffb8b7079e3f38]do_syscall_64atffffffff8f00401b[ffffb8b7079e3f50]entry_SYSCALL_64_after_hwframeatffffffff8f80008cand
[exception RIP: mlx5_eswitch_get_vport_config+12] [
ffffa70607e57678]mlx5e_get_vf_configatffffffffc03c7f8f[mlx5_core]
[ffffa70607e57688]do_setlinkatffffffffbc67fa59[ffffa70607e577a8]__rtnl_newlinkatffffffffbc683778[ffffa70607e57b68]rtnl_newlinkatffffffffbc683a63[ffffa70607e57b90]rtnetlink_rcv_msgatffffffffbc67d812[ffffa70607e57c10]netlink_rcv_skbatffffffffbc6b88ab[ffffa70607e57c60]netlink_unicastatffffffffbc6b808f[ffffa70607e57ca0]netlink_sendmsgatffffffffbc6b8412[ffffa70607e57d18]sock_sendmsgatffffffffbc6452f6[ffffa70607e57d30]___sys_sendmsgatffffffffbc645860[ffffa70607e57eb0]__sys_sendmsgatffffffffbc647a38[ffffa70607e57f38]do_syscall_64atffffffffbc00401b[ffffa70607e57f50]entry_SYSCALL_64_after_hwframeatffffffffbc80008cFixes a8d70a054a718 ("net/mlx5: E-Switch, Disallow vlan/spoofchecksetup if not being esw manager")
Cc Eli Cohen <[email protected]>Signed-off-by Tonghao Zhang <[email protected]>---
v1->v2: check only the esw is null, instead ofESW_ALLOWED.--- drivers/net/ethernet/mellanox/mlx5/core/eswitch.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)drivers/net/ethernet/mellanox/mlx5/core/eswitch.c +1
-1@@ -1871,7 +1871,7 @@ int mlx5_eswitch_set_vport_mac(structmlx5_eswitch *esw, u64 node_guid;int err =0 ; -if (!MLX5_CAP_GEN (esw->dev, vport_group_manager)) +if (!esw || !MLX5_CAP_GEN (esw->dev, vport_group_manager))return -EPERM ;if (!LEGAL_VPORT (esw, vport) ||is_multicast_ether_addr (mac))drivers/net/ethernet/mellanox/mlx5/core/eswitch.c +0
-0return -EINVAL ;@@ -1945,7 +1945,7 @@ int mlx5_eswitch_get_vport_config(struct mlx5_eswitch *esw, {struct mlx5_vport *evport;
Quoted 8 lines
Quoted 6 lines
drivers/net/ethernet/mellanox/mlx5/core/eswitch.c +1
-1-if (!MLX5_CAP_GEN (esw->dev, vport_group_manager)) +if (!esw || !MLX5_CAP_GEN (esw->dev, vport_group_manager))return -EPERM ;if (!LEGAL_VPORT (esw, vport))return
-EINVAL;Reviewed-by Roi Dayan <[email protected]>