diff mbox series

[net,2/2] net/mlx5: Avoid panic when setting VF rate

Message ID 1551607005-16321-2-git-send-email-xiangxia.m.yue@gmail.com
State Changes Requested
Delegated to: David Miller
Headers show
Series [1/2] net/mlx5: Avoid panic when setting vport mac, getting vport config | expand

Commit Message

Tonghao Zhang March 3, 2019, 9:56 a.m. UTC
From: Tonghao Zhang <xiangxia.m.yue@gmail.com>

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 rate 100

Fixes: c9497c98901c ("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>
---
 drivers/net/ethernet/mellanox/mlx5/core/eswitch.c | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

Comments

Roi Dayan March 3, 2019, 2:12 p.m. UTC | #1
On 03/03/2019 11:56, xiangxia.m.yue@gmail.com wrote:
> From: Tonghao Zhang <xiangxia.m.yue@gmail.com>
> 
> 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 rate 100

actually this didn't reproduce with this command + your first fix.

setting rate calls netlink IFLA_VF_TX_RATE which is calling
nfo_get_vf_config() which is now returning error correctly.

we need the netlink call to be IFLA_VF_RATE. seems we get there
when we set min/max_tx_rate.
so i reproduce the error with this command
$ ip link set dev $VF vf 0 max_tx_rate 2 max_tx_rate 1

can you verify and fix the commit msg?

> 
> Fixes: c9497c98901c ("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>
> ---
>  drivers/net/ethernet/mellanox/mlx5/core/eswitch.c | 13 +++++++++----
>  1 file changed, 9 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/net/ethernet/mellanox/mlx5/core/eswitch.c b/drivers/net/ethernet/mellanox/mlx5/core/eswitch.c
> index 774edc9..8c2f1e6 100644
> --- a/drivers/net/ethernet/mellanox/mlx5/core/eswitch.c
> +++ b/drivers/net/ethernet/mellanox/mlx5/core/eswitch.c
> @@ -2122,19 +2122,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;
>  
>
Roi Dayan March 3, 2019, 2:17 p.m. UTC | #2
On 03/03/2019 16:12, Roi Dayan wrote:
> 
> 
> On 03/03/2019 11:56, xiangxia.m.yue@gmail.com wrote:
>> From: Tonghao Zhang <xiangxia.m.yue@gmail.com>
>>
>> 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 rate 100
> 
> actually this didn't reproduce with this command + your first fix.
> 
> setting rate calls netlink IFLA_VF_TX_RATE which is calling
> nfo_get_vf_config() which is now returning error correctly.
> 
> we need the netlink call to be IFLA_VF_RATE. seems we get there
> when we set min/max_tx_rate.
> so i reproduce the error with this command
> $ ip link set dev $VF vf 0 max_tx_rate 2 max_tx_rate 1

i had a typo here. the cmd is
> $ ip link set dev $VF vf 0 max_tx_rate 2 min_tx_rate 1

> 
> can you verify and fix the commit msg?
> 
>>
>> Fixes: c9497c98901c ("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>
>> ---
>>  drivers/net/ethernet/mellanox/mlx5/core/eswitch.c | 13 +++++++++----
>>  1 file changed, 9 insertions(+), 4 deletions(-)
>>
>> diff --git a/drivers/net/ethernet/mellanox/mlx5/core/eswitch.c b/drivers/net/ethernet/mellanox/mlx5/core/eswitch.c
>> index 774edc9..8c2f1e6 100644
>> --- a/drivers/net/ethernet/mellanox/mlx5/core/eswitch.c
>> +++ b/drivers/net/ethernet/mellanox/mlx5/core/eswitch.c
>> @@ -2122,19 +2122,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;
>>  
>>
Roi Dayan March 3, 2019, 2:17 p.m. UTC | #3
On 03/03/2019 16:12, Roi Dayan wrote:
> 
> 
> On 03/03/2019 11:56, xiangxia.m.yue@gmail.com wrote:
>> From: Tonghao Zhang <xiangxia.m.yue@gmail.com>
>>
>> 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 rate 100
> 
> actually this didn't reproduce with this command + your first fix.
> 
> setting rate calls netlink IFLA_VF_TX_RATE which is calling
> nfo_get_vf_config() which is now returning error correctly.
> 
> we need the netlink call to be IFLA_VF_RATE. seems we get there
> when we set min/max_tx_rate.
> so i reproduce the error with this command
> $ ip link set dev $VF vf 0 max_tx_rate 2 max_tx_rate 1

I had a typo here. the cmd is
$ ip link set dev $VF vf 0 max_tx_rate 2 min_tx_rate 1

> 
> can you verify and fix the commit msg?
> 
>>
>> Fixes: c9497c98901c ("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>
>> ---
>>  drivers/net/ethernet/mellanox/mlx5/core/eswitch.c | 13 +++++++++----
>>  1 file changed, 9 insertions(+), 4 deletions(-)
>>
>> diff --git a/drivers/net/ethernet/mellanox/mlx5/core/eswitch.c b/drivers/net/ethernet/mellanox/mlx5/core/eswitch.c
>> index 774edc9..8c2f1e6 100644
>> --- a/drivers/net/ethernet/mellanox/mlx5/core/eswitch.c
>> +++ b/drivers/net/ethernet/mellanox/mlx5/core/eswitch.c
>> @@ -2122,19 +2122,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;
>>  
>>
Tonghao Zhang March 4, 2019, 3:06 a.m. UTC | #4
On Sun, Mar 3, 2019 at 10:17 PM Roi Dayan <roid@mellanox.com> wrote:
>
>
>
> On 03/03/2019 16:12, Roi Dayan wrote:
> >
> >
> > On 03/03/2019 11:56, xiangxia.m.yue@gmail.com wrote:
> >> From: Tonghao Zhang <xiangxia.m.yue@gmail.com>
> >>
> >> 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 rate 100
> >
> > actually this didn't reproduce with this command + your first fix.
> >
> > setting rate calls netlink IFLA_VF_TX_RATE which is calling
> > nfo_get_vf_config() which is now returning error correctly.
> >
> > we need the netlink call to be IFLA_VF_RATE. seems we get there
> > when we set min/max_tx_rate.
> > so i reproduce the error with this command
> > $ ip link set dev $VF vf 0 max_tx_rate 2 max_tx_rate 1
>
> I had a typo here. the cmd is
> $ ip link set dev $VF vf 0 max_tx_rate 2 min_tx_rate 1
>
> >
> > can you verify and fix the commit msg?
Yes, thanks.
> >>
> >> Fixes: c9497c98901c ("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>
> >> ---
> >>  drivers/net/ethernet/mellanox/mlx5/core/eswitch.c | 13 +++++++++----
> >>  1 file changed, 9 insertions(+), 4 deletions(-)
> >>
> >> diff --git a/drivers/net/ethernet/mellanox/mlx5/core/eswitch.c b/drivers/net/ethernet/mellanox/mlx5/core/eswitch.c
> >> index 774edc9..8c2f1e6 100644
> >> --- a/drivers/net/ethernet/mellanox/mlx5/core/eswitch.c
> >> +++ b/drivers/net/ethernet/mellanox/mlx5/core/eswitch.c
> >> @@ -2122,19 +2122,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;
> >>
> >>
diff mbox series

Patch

diff --git a/drivers/net/ethernet/mellanox/mlx5/core/eswitch.c b/drivers/net/ethernet/mellanox/mlx5/core/eswitch.c
index 774edc9..8c2f1e6 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/eswitch.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/eswitch.c
@@ -2122,19 +2122,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;