The spec says:
mtu only exists if VIRTIO_NET_F_MTU is set
status only exists if VIRTIO_NET_F_STATUS is set
We should only show MTU and STATUS conditionally depending on
the feature bits.
Signed-off-by: Si-Wei Liu <si-wei.liu@oracle.com>
---
drivers/vdpa/mlx5/net/mlx5_vnet.c | 22 ++++++++++++++--------
1 file changed, 14 insertions(+), 8 deletions(-)
diff --git a/drivers/vdpa/mlx5/net/mlx5_vnet.c b/drivers/vdpa/mlx5/net/mlx5_vnet.c
index 3a6dbbc6..3d49eae 100644
--- a/drivers/vdpa/mlx5/net/mlx5_vnet.c
+++ b/drivers/vdpa/mlx5/net/mlx5_vnet.c
@@ -3009,6 +3009,8 @@ static int event_handler(struct notifier_block *nb, unsigned long event, void *p
struct mlx5_vdpa_wq_ent *wqent;
if (event == MLX5_EVENT_TYPE_PORT_CHANGE) {
+ if (!(ndev->mvdev.actual_features & BIT_ULL(VIRTIO_NET_F_STATUS)))
+ return NOTIFY_DONE;
switch (eqe->sub_type) {
case MLX5_PORT_CHANGE_SUBTYPE_DOWN:
case MLX5_PORT_CHANGE_SUBTYPE_ACTIVE:
@@ -3118,16 +3120,20 @@ static int mlx5_vdpa_dev_add(struct vdpa_mgmt_dev *v_mdev, const char *name,
goto err_alloc;
}
- err = query_mtu(mdev, &mtu);
- if (err)
- goto err_alloc;
+ if (device_features & BIT_ULL(VIRTIO_NET_F_MTU)) {
+ err = query_mtu(mdev, &mtu);
+ if (err)
+ goto err_alloc;
- ndev->config.mtu = cpu_to_mlx5vdpa16(mvdev, mtu);
+ ndev->config.mtu = cpu_to_mlx5vdpa16(mvdev, mtu);
+ }
- if (get_link_state(mvdev))
- ndev->config.status |= cpu_to_mlx5vdpa16(mvdev, VIRTIO_NET_S_LINK_UP);
- else
- ndev->config.status &= cpu_to_mlx5vdpa16(mvdev, ~VIRTIO_NET_S_LINK_UP);
+ if (device_features & BIT_ULL(VIRTIO_NET_F_STATUS)) {
+ if (get_link_state(mvdev))
+ ndev->config.status |= cpu_to_mlx5vdpa16(mvdev, VIRTIO_NET_S_LINK_UP);
+ else
+ ndev->config.status &= cpu_to_mlx5vdpa16(mvdev, ~VIRTIO_NET_S_LINK_UP);
+ }
if (add_config->mask & (1 << VDPA_ATTR_DEV_NET_CFG_MACADDR)) {
memcpy(ndev->config.mac, add_config->net.mac, ETH_ALEN);
--
1.8.3.1
On Tue, Jan 31, 2023 at 03:22:24PM -0800, Si-Wei Liu wrote:
> The spec says:
> mtu only exists if VIRTIO_NET_F_MTU is set
> status only exists if VIRTIO_NET_F_STATUS is set
>
> We should only show MTU and STATUS conditionally depending on
> the feature bits.
>
> Signed-off-by: Si-Wei Liu <si-wei.liu@oracle.com>
so change the subject pls. it seems to say you are showing them
when you previously didn't, what's going on is something like:
make MTU/status access conditional on feature bits
> ---
> drivers/vdpa/mlx5/net/mlx5_vnet.c | 22 ++++++++++++++--------
> 1 file changed, 14 insertions(+), 8 deletions(-)
>
> diff --git a/drivers/vdpa/mlx5/net/mlx5_vnet.c b/drivers/vdpa/mlx5/net/mlx5_vnet.c
> index 3a6dbbc6..3d49eae 100644
> --- a/drivers/vdpa/mlx5/net/mlx5_vnet.c
> +++ b/drivers/vdpa/mlx5/net/mlx5_vnet.c
> @@ -3009,6 +3009,8 @@ static int event_handler(struct notifier_block *nb, unsigned long event, void *p
> struct mlx5_vdpa_wq_ent *wqent;
>
> if (event == MLX5_EVENT_TYPE_PORT_CHANGE) {
> + if (!(ndev->mvdev.actual_features & BIT_ULL(VIRTIO_NET_F_STATUS)))
> + return NOTIFY_DONE;
> switch (eqe->sub_type) {
> case MLX5_PORT_CHANGE_SUBTYPE_DOWN:
> case MLX5_PORT_CHANGE_SUBTYPE_ACTIVE:
> @@ -3118,16 +3120,20 @@ static int mlx5_vdpa_dev_add(struct vdpa_mgmt_dev *v_mdev, const char *name,
> goto err_alloc;
> }
>
> - err = query_mtu(mdev, &mtu);
> - if (err)
> - goto err_alloc;
> + if (device_features & BIT_ULL(VIRTIO_NET_F_MTU)) {
> + err = query_mtu(mdev, &mtu);
> + if (err)
> + goto err_alloc;
>
> - ndev->config.mtu = cpu_to_mlx5vdpa16(mvdev, mtu);
> + ndev->config.mtu = cpu_to_mlx5vdpa16(mvdev, mtu);
> + }
>
> - if (get_link_state(mvdev))
> - ndev->config.status |= cpu_to_mlx5vdpa16(mvdev, VIRTIO_NET_S_LINK_UP);
> - else
> - ndev->config.status &= cpu_to_mlx5vdpa16(mvdev, ~VIRTIO_NET_S_LINK_UP);
> + if (device_features & BIT_ULL(VIRTIO_NET_F_STATUS)) {
> + if (get_link_state(mvdev))
> + ndev->config.status |= cpu_to_mlx5vdpa16(mvdev, VIRTIO_NET_S_LINK_UP);
> + else
> + ndev->config.status &= cpu_to_mlx5vdpa16(mvdev, ~VIRTIO_NET_S_LINK_UP);
> + }
>
> if (add_config->mask & (1 << VDPA_ATTR_DEV_NET_CFG_MACADDR)) {
> memcpy(ndev->config.mac, add_config->net.mac, ETH_ALEN);
> --
> 1.8.3.1
On 2/3/2023 12:14 AM, Michael S. Tsirkin wrote:
> On Tue, Jan 31, 2023 at 03:22:24PM -0800, Si-Wei Liu wrote:
>> The spec says:
>> mtu only exists if VIRTIO_NET_F_MTU is set
>> status only exists if VIRTIO_NET_F_STATUS is set
>>
>> We should only show MTU and STATUS conditionally depending on
>> the feature bits.
>>
>> Signed-off-by: Si-Wei Liu <si-wei.liu@oracle.com>
> so change the subject pls. it seems to say you are showing them
> when you previously didn't, what's going on is something like:
>
> make MTU/status access conditional on feature bits
I ever considered something similar as I wrote it, but there's no actual
config space access involved, and what the code is doing is to prohibit
*presenting* the related field to config space subject to feature bit.
So maybe this is more accurate?
make MTU/status presence conditional on feature bits
Thanks,
-Siwei
>
>> ---
>> drivers/vdpa/mlx5/net/mlx5_vnet.c | 22 ++++++++++++++--------
>> 1 file changed, 14 insertions(+), 8 deletions(-)
>>
>> diff --git a/drivers/vdpa/mlx5/net/mlx5_vnet.c b/drivers/vdpa/mlx5/net/mlx5_vnet.c
>> index 3a6dbbc6..3d49eae 100644
>> --- a/drivers/vdpa/mlx5/net/mlx5_vnet.c
>> +++ b/drivers/vdpa/mlx5/net/mlx5_vnet.c
>> @@ -3009,6 +3009,8 @@ static int event_handler(struct notifier_block *nb, unsigned long event, void *p
>> struct mlx5_vdpa_wq_ent *wqent;
>>
>> if (event == MLX5_EVENT_TYPE_PORT_CHANGE) {
>> + if (!(ndev->mvdev.actual_features & BIT_ULL(VIRTIO_NET_F_STATUS)))
>> + return NOTIFY_DONE;
>> switch (eqe->sub_type) {
>> case MLX5_PORT_CHANGE_SUBTYPE_DOWN:
>> case MLX5_PORT_CHANGE_SUBTYPE_ACTIVE:
>> @@ -3118,16 +3120,20 @@ static int mlx5_vdpa_dev_add(struct vdpa_mgmt_dev *v_mdev, const char *name,
>> goto err_alloc;
>> }
>>
>> - err = query_mtu(mdev, &mtu);
>> - if (err)
>> - goto err_alloc;
>> + if (device_features & BIT_ULL(VIRTIO_NET_F_MTU)) {
>> + err = query_mtu(mdev, &mtu);
>> + if (err)
>> + goto err_alloc;
>>
>> - ndev->config.mtu = cpu_to_mlx5vdpa16(mvdev, mtu);
>> + ndev->config.mtu = cpu_to_mlx5vdpa16(mvdev, mtu);
>> + }
>>
>> - if (get_link_state(mvdev))
>> - ndev->config.status |= cpu_to_mlx5vdpa16(mvdev, VIRTIO_NET_S_LINK_UP);
>> - else
>> - ndev->config.status &= cpu_to_mlx5vdpa16(mvdev, ~VIRTIO_NET_S_LINK_UP);
>> + if (device_features & BIT_ULL(VIRTIO_NET_F_STATUS)) {
>> + if (get_link_state(mvdev))
>> + ndev->config.status |= cpu_to_mlx5vdpa16(mvdev, VIRTIO_NET_S_LINK_UP);
>> + else
>> + ndev->config.status &= cpu_to_mlx5vdpa16(mvdev, ~VIRTIO_NET_S_LINK_UP);
>> + }
>>
>> if (add_config->mask & (1 << VDPA_ATTR_DEV_NET_CFG_MACADDR)) {
>> memcpy(ndev->config.mac, add_config->net.mac, ETH_ALEN);
>> --
>> 1.8.3.1
On 01/02/2023 1:22, Si-Wei Liu wrote:
> The spec says:
> mtu only exists if VIRTIO_NET_F_MTU is set
> status only exists if VIRTIO_NET_F_STATUS is set
>
> We should only show MTU and STATUS conditionally depending on
> the feature bits.
>
> Signed-off-by: Si-Wei Liu <si-wei.liu@oracle.com>
> ---
> drivers/vdpa/mlx5/net/mlx5_vnet.c | 22 ++++++++++++++--------
> 1 file changed, 14 insertions(+), 8 deletions(-)
>
> diff --git a/drivers/vdpa/mlx5/net/mlx5_vnet.c b/drivers/vdpa/mlx5/net/mlx5_vnet.c
> index 3a6dbbc6..3d49eae 100644
> --- a/drivers/vdpa/mlx5/net/mlx5_vnet.c
> +++ b/drivers/vdpa/mlx5/net/mlx5_vnet.c
> @@ -3009,6 +3009,8 @@ static int event_handler(struct notifier_block *nb, unsigned long event, void *p
> struct mlx5_vdpa_wq_ent *wqent;
>
> if (event == MLX5_EVENT_TYPE_PORT_CHANGE) {
> + if (!(ndev->mvdev.actual_features & BIT_ULL(VIRTIO_NET_F_STATUS)))
> + return NOTIFY_DONE;
> switch (eqe->sub_type) {
> case MLX5_PORT_CHANGE_SUBTYPE_DOWN:
> case MLX5_PORT_CHANGE_SUBTYPE_ACTIVE:
> @@ -3118,16 +3120,20 @@ static int mlx5_vdpa_dev_add(struct vdpa_mgmt_dev *v_mdev, const char *name,
> goto err_alloc;
> }
>
> - err = query_mtu(mdev, &mtu);
> - if (err)
> - goto err_alloc;
> + if (device_features & BIT_ULL(VIRTIO_NET_F_MTU)) {
> + err = query_mtu(mdev, &mtu);
> + if (err)
> + goto err_alloc;
device_features is not defined as a local variable. It is defined in the
next patch.
>
> - ndev->config.mtu = cpu_to_mlx5vdpa16(mvdev, mtu);
> + ndev->config.mtu = cpu_to_mlx5vdpa16(mvdev, mtu);
> + }
>
> - if (get_link_state(mvdev))
> - ndev->config.status |= cpu_to_mlx5vdpa16(mvdev, VIRTIO_NET_S_LINK_UP);
> - else
> - ndev->config.status &= cpu_to_mlx5vdpa16(mvdev, ~VIRTIO_NET_S_LINK_UP);
> + if (device_features & BIT_ULL(VIRTIO_NET_F_STATUS)) {
> + if (get_link_state(mvdev))
> + ndev->config.status |= cpu_to_mlx5vdpa16(mvdev, VIRTIO_NET_S_LINK_UP);
> + else
> + ndev->config.status &= cpu_to_mlx5vdpa16(mvdev, ~VIRTIO_NET_S_LINK_UP);
> + }
>
> if (add_config->mask & (1 << VDPA_ATTR_DEV_NET_CFG_MACADDR)) {
> memcpy(ndev->config.mac, add_config->net.mac, ETH_ALEN);
On 2/2/2023 5:31 AM, Eli Cohen wrote:
>
> On 01/02/2023 1:22, Si-Wei Liu wrote:
>> The spec says:
>> mtu only exists if VIRTIO_NET_F_MTU is set
>> status only exists if VIRTIO_NET_F_STATUS is set
>>
>> We should only show MTU and STATUS conditionally depending on
>> the feature bits.
>>
>> Signed-off-by: Si-Wei Liu <si-wei.liu@oracle.com>
>> ---
>> drivers/vdpa/mlx5/net/mlx5_vnet.c | 22 ++++++++++++++--------
>> 1 file changed, 14 insertions(+), 8 deletions(-)
>>
>> diff --git a/drivers/vdpa/mlx5/net/mlx5_vnet.c
>> b/drivers/vdpa/mlx5/net/mlx5_vnet.c
>> index 3a6dbbc6..3d49eae 100644
>> --- a/drivers/vdpa/mlx5/net/mlx5_vnet.c
>> +++ b/drivers/vdpa/mlx5/net/mlx5_vnet.c
>> @@ -3009,6 +3009,8 @@ static int event_handler(struct notifier_block
>> *nb, unsigned long event, void *p
>> struct mlx5_vdpa_wq_ent *wqent;
>> if (event == MLX5_EVENT_TYPE_PORT_CHANGE) {
>> + if (!(ndev->mvdev.actual_features &
>> BIT_ULL(VIRTIO_NET_F_STATUS)))
>> + return NOTIFY_DONE;
>> switch (eqe->sub_type) {
>> case MLX5_PORT_CHANGE_SUBTYPE_DOWN:
>> case MLX5_PORT_CHANGE_SUBTYPE_ACTIVE:
>> @@ -3118,16 +3120,20 @@ static int mlx5_vdpa_dev_add(struct
>> vdpa_mgmt_dev *v_mdev, const char *name,
>> goto err_alloc;
>> }
>> - err = query_mtu(mdev, &mtu);
>> - if (err)
>> - goto err_alloc;
>> + if (device_features & BIT_ULL(VIRTIO_NET_F_MTU)) {
>> + err = query_mtu(mdev, &mtu);
>> + if (err)
>> + goto err_alloc;
> device_features is not defined as a local variable. It is defined in
> the next patch.
Good catch! Will revise and post a v3.
Thanks!
-Siwei
>> - ndev->config.mtu = cpu_to_mlx5vdpa16(mvdev, mtu);
>> + ndev->config.mtu = cpu_to_mlx5vdpa16(mvdev, mtu);
>> + }
>> - if (get_link_state(mvdev))
>> - ndev->config.status |= cpu_to_mlx5vdpa16(mvdev,
>> VIRTIO_NET_S_LINK_UP);
>> - else
>> - ndev->config.status &= cpu_to_mlx5vdpa16(mvdev,
>> ~VIRTIO_NET_S_LINK_UP);
>> + if (device_features & BIT_ULL(VIRTIO_NET_F_STATUS)) {
>> + if (get_link_state(mvdev))
>> + ndev->config.status |= cpu_to_mlx5vdpa16(mvdev,
>> VIRTIO_NET_S_LINK_UP);
>> + else
>> + ndev->config.status &= cpu_to_mlx5vdpa16(mvdev,
>> ~VIRTIO_NET_S_LINK_UP);
>> + }
>> if (add_config->mask & (1 << VDPA_ATTR_DEV_NET_CFG_MACADDR)) {
>> memcpy(ndev->config.mac, add_config->net.mac, ETH_ALEN);
© 2016 - 2026 Red Hat, Inc.