vdpa/mlx5: Avoid losing link state updates
Michael S. Tsirkin
maintainerQuoted 11 lines · Eli Cohen
Current code ignores link state updates if
VIRTIO_NET_F_STATUSwas not negotiated. However, link state updates could be received before feature negotiation was completed , therefore causing link state events to be lost, possibly leaving the link state down.Add code to detect if
VIRTIO_NET_F_STATUSwas set and update the link state. We add a spinlock to serialize updated to config.status to maintain its integrity.Fixes 033779a708f0 ("vdpa/mlx5: make MTU/STATUS presence conditional on feature bits")Signed-off-by Eli Cohen <[email protected]>
Hmm I don't get it.
link state changes are config updates are they not? probe sequence is:
err = virtio_features_ok(dev);
if (err)
goto err;
err = drv->probe(dev);
if (err)
goto err;
/* If probe didn't do it, mark device DRIVER_OK ourselves. */
if (!(dev->config->get_status(dev) & VIRTIO_CONFIG_S_DRIVER_OK))
virtio_device_ready(dev);
if (drv->scan)
drv->scan(dev);
virtio_config_enable(dev);Looks like config changes that trigger before negotiation are queued, not lost.
Was there an actual bug you observed or is this theoretical?
Thanks!
Quoted 155 lines
--- drivers/vdpa/mlx5/net/mlx5_vnet.c | 91 ++++++++++++++++++++----------- drivers/vdpa/mlx5/net/mlx5_vnet.h | 2 + 2 files changed, 60 insertions(+), 33 deletions(-)drivers/vdpa/mlx5/net/mlx5_vnet.c +58
-33@@ -2298,10 +2298,62 @@ static void update_cvq_info(struct mlx5_vdpa_dev *mvdev) } } +static bool f_status_was_set (u64 old,u64 new) +{ +if (!(old &BIT_ULL (VIRTIO_NET_F_STATUS )) && + (new &BIT_ULL (VIRTIO_NET_F_STATUS ))) +return true; + +return false; +} + +static u8 query_vport_state (struct mlx5_core_dev *mdev,u8 opmod,u16 vport) +{ +u32 out[MLX5_ST_SZ_DW (query_vport_state_out)] = {}; +u32 in[MLX5_ST_SZ_DW (query_vport_state_in)] = {}; +int err; + +MLX5_SET (query_vport_state_in, in, opcode,MLX5_CMD_OP_QUERY_VPORT_STATE ); +MLX5_SET (query_vport_state_in, in, op_mod, opmod); +MLX5_SET (query_vport_state_in, in, vport_number, vport); +if (vport) +MLX5_SET (query_vport_state_in, in, other_vport,1 ); + + err =mlx5_cmd_exec_inout (mdev, query_vport_state, in, out); +if (err) +return 0 ; + +return MLX5_GET (query_vport_state_out, out, state); +} + +static bool get_link_state (struct mlx5_vdpa_dev *mvdev) +{ +if (query_vport_state (mvdev->mdev,MLX5_VPORT_STATE_OP_MOD_VNIC_VPORT ,0 ) == +VPORT_STATE_UP ) +return true; + +return false; +} + +static void update_link_state (struct mlx5_vdpa_dev *mvdev) +{ +struct mlx5_vdpa_net *ndev =to_mlx5_vdpa_ndev (mvdev); +bool up; + + up =get_link_state (mvdev); +spin_lock (&ndev->status_lock); +if (up) + 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 ); +spin_unlock (&ndev->status_lock); +} +static int mlx5_vdpa_set_driver_features (struct vdpa_device *vdev,u64 features) {struct mlx5_vdpa_dev *mvdev =to_mvdev (vdev);struct mlx5_vdpa_net *ndev =to_mlx5_vdpa_ndev (mvdev); +u64 cur_features;int err;print_features (mvdev, features, true);@@ -2310,7 +2362,11 @@ static int mlx5_vdpa_set_driver_features(struct vdpa_device *vdev, u64 features)if (err)return err; + cur_features = ndev->mvdev.actual_features; ndev->mvdev.actual_features = features & ndev->mvdev.mlx_features; +if (f_status_was_set (cur_features, ndev->mvdev.actual_features)) +update_link_state (mvdev); +if (ndev->mvdev.actual_features &BIT_ULL (VIRTIO_NET_F_MQ )) ndev->rqt_size =mlx5vdpa16_to_cpu (mvdev, ndev->config.max_virtqueue_pairs);else @@ -2995,34 +3051,6 @@ struct mlx5_vdpa_mgmtdev {struct mlx5_vdpa_net *ndev; }; -static u8 query_vport_state (struct mlx5_core_dev *mdev,u8 opmod,u16 vport) -{ -u32 out[MLX5_ST_SZ_DW (query_vport_state_out)] = {}; -u32 in[MLX5_ST_SZ_DW (query_vport_state_in)] = {}; -int err; - -MLX5_SET (query_vport_state_in, in, opcode,MLX5_CMD_OP_QUERY_VPORT_STATE ); -MLX5_SET (query_vport_state_in, in, op_mod, opmod); -MLX5_SET (query_vport_state_in, in, vport_number, vport); -if (vport) -MLX5_SET (query_vport_state_in, in, other_vport,1 ); - - err =mlx5_cmd_exec_inout (mdev, query_vport_state, in, out); -if (err) -return 0 ; - -return MLX5_GET (query_vport_state_out, out, state); -} - -static bool get_link_state (struct mlx5_vdpa_dev *mvdev) -{ -if (query_vport_state (mvdev->mdev,MLX5_VPORT_STATE_OP_MOD_VNIC_VPORT ,0 ) == -VPORT_STATE_UP ) -return true; - -return false; -} -static void update_carrier (struct work_struct *work) {struct mlx5_vdpa_wq_ent *wqent;@@ -3032,11 +3060,7 @@ static void update_carrier(struct work_struct *work) wqent = container_of(work, struct mlx5_vdpa_wq_ent, work); mvdev = wqent->mvdev; ndev =to_mlx5_vdpa_ndev (mvdev); -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 ); - +update_link_state (mvdev);if (ndev->nb_registered && ndev->config_cb.callback) ndev->config_cb.callback (ndev->config_cb.private);@@ -3172,6 +3196,7 @@ static int mlx5_vdpa_dev_add(struct vdpa_mgmt_dev *v_mdev, const char *name,init_mvqs (ndev);init_rwsem (&ndev->reslock); +spin_lock_init (&ndev->status_lock); config = &ndev->config;if (add_config->mask &BIT_ULL (VDPA_ATTR_DEV_NET_CFG_MTU )) {drivers/vdpa/mlx5/net/mlx5_vnet.h +2
-0@@ -50,6 +50,8 @@ struct mlx5_vdpa_net {struct mlx5_vdpa_wq_ent cvq_ent;struct hlist_head macvlan_hash[MLX5V_MACVLAN_SIZE ];struct dentry *debugfs; +/* serialize link status updates */ +spinlock_t status_lock; };struct mlx5_vdpa_counter {Signature · 1 line
2.38.1
_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
Michael S. Tsirkin
maintainerQuoted 21 lines · Eli Cohen
Current code ignores link state updates if
VIRTIO_NET_F_STATUSwas not negotiated. However, link state updates could be received before feature negotiation was completed , therefore causing link state events to be lost, possibly leaving the link state down.Add code to detect if
VIRTIO_NET_F_STATUSwas set and update the link state. We add a spinlock to serialize updated to config.status to maintain its integrity.Fixes 033779a708f0 ("vdpa/mlx5: make MTU/STATUS presence conditional on feature bits")Signed-off-by Eli Cohen <[email protected]>--- drivers/vdpa/mlx5/net/mlx5_vnet.c | 91 ++++++++++++++++++++----------- drivers/vdpa/mlx5/net/mlx5_vnet.h | 2 + 2 files changed, 60 insertions(+), 33 deletions(-)drivers/vdpa/mlx5/net/mlx5_vnet.c +0
-0
drivers/vdpa/mlx5/net/mlx5_vnet.c static void update_cvq_info(struct mlx5_vdpa_dev *mvdev) · line 2301
Quoted 4 lines
drivers/vdpa/mlx5/net/mlx5_vnet.c +1
-0@@ -2298,10 +2298,62 @@ static void update_cvq_info(struct mlx5_vdpa_dev *mvdev) } } +static bool f_status_was_set (u64 old,u64 new)
the name is exact reverse of what it does is it not? it is true if status was not set and is being set.
Quoted 141 lines
drivers/vdpa/mlx5/net/mlx5_vnet.c +57
-33+{ +if (!(old &BIT_ULL (VIRTIO_NET_F_STATUS )) && + (new &BIT_ULL (VIRTIO_NET_F_STATUS ))) +return true; + +return false; +} + +static u8 query_vport_state (struct mlx5_core_dev *mdev,u8 opmod,u16 vport) +{ +u32 out[MLX5_ST_SZ_DW (query_vport_state_out)] = {}; +u32 in[MLX5_ST_SZ_DW (query_vport_state_in)] = {}; +int err; + +MLX5_SET (query_vport_state_in, in, opcode,MLX5_CMD_OP_QUERY_VPORT_STATE ); +MLX5_SET (query_vport_state_in, in, op_mod, opmod); +MLX5_SET (query_vport_state_in, in, vport_number, vport); +if (vport) +MLX5_SET (query_vport_state_in, in, other_vport,1 ); + + err =mlx5_cmd_exec_inout (mdev, query_vport_state, in, out); +if (err) +return 0 ; + +return MLX5_GET (query_vport_state_out, out, state); +} + +static bool get_link_state (struct mlx5_vdpa_dev *mvdev) +{ +if (query_vport_state (mvdev->mdev,MLX5_VPORT_STATE_OP_MOD_VNIC_VPORT ,0 ) == +VPORT_STATE_UP ) +return true; + +return false; +} + +static void update_link_state (struct mlx5_vdpa_dev *mvdev) +{ +struct mlx5_vdpa_net *ndev =to_mlx5_vdpa_ndev (mvdev); +bool up; + + up =get_link_state (mvdev); +spin_lock (&ndev->status_lock); +if (up) + 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 ); +spin_unlock (&ndev->status_lock); +} +static int mlx5_vdpa_set_driver_features (struct vdpa_device *vdev,u64 features) {struct mlx5_vdpa_dev *mvdev =to_mvdev (vdev);struct mlx5_vdpa_net *ndev =to_mlx5_vdpa_ndev (mvdev); +u64 cur_features;int err;print_features (mvdev, features, true);@@ -2310,7 +2362,11 @@ static int mlx5_vdpa_set_driver_features(struct vdpa_device *vdev, u64 features)if (err)return err; + cur_features = ndev->mvdev.actual_features; ndev->mvdev.actual_features = features & ndev->mvdev.mlx_features; +if (f_status_was_set (cur_features, ndev->mvdev.actual_features)) +update_link_state (mvdev); +if (ndev->mvdev.actual_features &BIT_ULL (VIRTIO_NET_F_MQ )) ndev->rqt_size =mlx5vdpa16_to_cpu (mvdev, ndev->config.max_virtqueue_pairs);else @@ -2995,34 +3051,6 @@ struct mlx5_vdpa_mgmtdev {struct mlx5_vdpa_net *ndev; }; -static u8 query_vport_state (struct mlx5_core_dev *mdev,u8 opmod,u16 vport) -{ -u32 out[MLX5_ST_SZ_DW (query_vport_state_out)] = {}; -u32 in[MLX5_ST_SZ_DW (query_vport_state_in)] = {}; -int err; - -MLX5_SET (query_vport_state_in, in, opcode,MLX5_CMD_OP_QUERY_VPORT_STATE ); -MLX5_SET (query_vport_state_in, in, op_mod, opmod); -MLX5_SET (query_vport_state_in, in, vport_number, vport); -if (vport) -MLX5_SET (query_vport_state_in, in, other_vport,1 ); - - err =mlx5_cmd_exec_inout (mdev, query_vport_state, in, out); -if (err) -return 0 ; - -return MLX5_GET (query_vport_state_out, out, state); -} - -static bool get_link_state (struct mlx5_vdpa_dev *mvdev) -{ -if (query_vport_state (mvdev->mdev,MLX5_VPORT_STATE_OP_MOD_VNIC_VPORT ,0 ) == -VPORT_STATE_UP ) -return true; - -return false; -} -static void update_carrier (struct work_struct *work) {struct mlx5_vdpa_wq_ent *wqent;@@ -3032,11 +3060,7 @@ static void update_carrier(struct work_struct *work) wqent = container_of(work, struct mlx5_vdpa_wq_ent, work); mvdev = wqent->mvdev; ndev =to_mlx5_vdpa_ndev (mvdev); -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 ); - +update_link_state (mvdev);if (ndev->nb_registered && ndev->config_cb.callback) ndev->config_cb.callback (ndev->config_cb.private);@@ -3172,6 +3196,7 @@ static int mlx5_vdpa_dev_add(struct vdpa_mgmt_dev *v_mdev, const char *name,init_mvqs (ndev);init_rwsem (&ndev->reslock); +spin_lock_init (&ndev->status_lock); config = &ndev->config;if (add_config->mask &BIT_ULL (VDPA_ATTR_DEV_NET_CFG_MTU )) {drivers/vdpa/mlx5/net/mlx5_vnet.h +2
-0@@ -50,6 +50,8 @@ struct mlx5_vdpa_net {struct mlx5_vdpa_wq_ent cvq_ent;struct hlist_head macvlan_hash[MLX5V_MACVLAN_SIZE ];struct dentry *debugfs; +/* serialize link status updates */ +spinlock_t status_lock; };struct mlx5_vdpa_counter {Signature · 1 line
2.38.1
_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
Michael S. Tsirkin
maintainerQuoted 30 lines · Eli Cohen
Quoted 17 lines · Michael S. Tsirkin
Quoted 16 lines · Eli Cohen
Current code ignores link state updates if
VIRTIO_NET_F_STATUSwas not negotiated. However, link state updates could be received before feature negotiation was completed , therefore causing link state events to be lost, possibly leaving the link state down.Add code to detect if
VIRTIO_NET_F_STATUSwas set and update the link state. We add a spinlock to serialize updated to config.status to maintain its integrity.Fixes 033779a708f0 ("vdpa/mlx5: make MTU/STATUS presence conditional on feature bits")Signed-off-by Eli Cohen <[email protected]>--- drivers/vdpa/mlx5/net/mlx5_vnet.c | 91 ++++++++++++++++++++----------- drivers/vdpa/mlx5/net/mlx5_vnet.h | 2 + 2 files changed, 60 insertions(+), 33 deletions(-)Quoted 10 lines
drivers/vdpa/mlx5/net/mlx5_vnet.c static void update_cvq_info(struct mlx5_vdpa_dev *mvdev) · line 2300
Quoted 8 lines
drivers/vdpa/mlx5/net/mlx5_vnet.c +1
-0@@ -2298,10 +2298,62 @@ static void update_cvq_info(struct mlx5_vdpa_dev *mvdev) } } +static bool f_status_was_set (u64 old,u64 new)the name is exact reverse of what it does is it not? it is true if status was not set and is being set.
Quoted 3 lines
I am tracking feature negotiation to check if
VIRTIO_NET_F_STATUS*just became set* and unconditionally update link state.
If you still think the name choice is not good, I can change it.
this is where you use the function currently.
yes the "new" value is currently the value that
was already saved before the call to the function. but the function itself does not care.
but it says nothing about what it does itself.
it gets old and new and tells you whether VIRTIO_NET_F_STATUS flipped from 0 in old to 1 in new.
I am not sure why you need helper, you can write
it in a single statement as:
(~old & new & BIT_ULL(VIRTIO_NET_F_STATUS))
or here practically:
if (~cur_features & ndev->mvdev.actual_features & BIT_ULL(VIRTIO_NET_F_STATUS))
(maybe use a shorter name for cur_features to fit in 80 columns). so I would just open-code, but if you do write a helper then it should make sense by itself and be reusable.
Quoted 128 lines
Quoted 128 lines
Quoted 128 lines
drivers/vdpa/mlx5/net/mlx5_vnet.c +57
-33+{ +if (!(old &BIT_ULL (VIRTIO_NET_F_STATUS )) && + (new &BIT_ULL (VIRTIO_NET_F_STATUS ))) +return true; + +return false; +} + +static u8 query_vport_state (struct mlx5_core_dev *mdev,u8 opmod,u16 vport) +{ +u32 out[MLX5_ST_SZ_DW (query_vport_state_out)] = {}; +u32 in[MLX5_ST_SZ_DW (query_vport_state_in)] = {}; +int err; + +MLX5_SET (query_vport_state_in, in, opcode,MLX5_CMD_OP_QUERY_VPORT_STATE ); +MLX5_SET (query_vport_state_in, in, op_mod, opmod); +MLX5_SET (query_vport_state_in, in, vport_number, vport); +if (vport) +MLX5_SET (query_vport_state_in, in, other_vport,1 ); + + err =mlx5_cmd_exec_inout (mdev, query_vport_state, in, out); +if (err) +return 0 ; + +return MLX5_GET (query_vport_state_out, out, state); +} + +static bool get_link_state (struct mlx5_vdpa_dev *mvdev) +{ +if (query_vport_state (mvdev->mdev,MLX5_VPORT_STATE_OP_MOD_VNIC_VPORT ,0 ) == +VPORT_STATE_UP ) +return true; + +return false; +} + +static void update_link_state (struct mlx5_vdpa_dev *mvdev) +{ +struct mlx5_vdpa_net *ndev =to_mlx5_vdpa_ndev (mvdev); +bool up; + + up =get_link_state (mvdev); +spin_lock (&ndev->status_lock); +if (up) + 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 ); +spin_unlock (&ndev->status_lock); +} +static int mlx5_vdpa_set_driver_features (struct vdpa_device *vdev,u64 features) {struct mlx5_vdpa_dev *mvdev =to_mvdev (vdev);struct mlx5_vdpa_net *ndev =to_mlx5_vdpa_ndev (mvdev); +u64 cur_features;int err;print_features (mvdev, features, true);@@ -2310,7 +2362,11 @@ static int mlx5_vdpa_set_driver_features(struct vdpa_device *vdev, u64 features)if (err)return err; + cur_features = ndev->mvdev.actual_features; ndev->mvdev.actual_features = features & ndev->mvdev.mlx_features; +if (f_status_was_set (cur_features, ndev->mvdev.actual_features)) +update_link_state (mvdev); +if (ndev->mvdev.actual_features &BIT_ULL (VIRTIO_NET_F_MQ )) ndev->rqt_size =mlx5vdpa16_to_cpu (mvdev, ndev->config.max_virtqueue_pairs);else @@ -2995,34 +3051,6 @@ struct mlx5_vdpa_mgmtdev {struct mlx5_vdpa_net *ndev; }; -static u8 query_vport_state (struct mlx5_core_dev *mdev,u8 opmod,u16 vport) -{ -u32 out[MLX5_ST_SZ_DW (query_vport_state_out)] = {}; -u32 in[MLX5_ST_SZ_DW (query_vport_state_in)] = {}; -int err; - -MLX5_SET (query_vport_state_in, in, opcode,MLX5_CMD_OP_QUERY_VPORT_STATE ); -MLX5_SET (query_vport_state_in, in, op_mod, opmod); -MLX5_SET (query_vport_state_in, in, vport_number, vport); -if (vport) -MLX5_SET (query_vport_state_in, in, other_vport,1 ); - - err =mlx5_cmd_exec_inout (mdev, query_vport_state, in, out); -if (err) -return 0 ; - -return MLX5_GET (query_vport_state_out, out, state); -} - -static bool get_link_state (struct mlx5_vdpa_dev *mvdev) -{ -if (query_vport_state (mvdev->mdev,MLX5_VPORT_STATE_OP_MOD_VNIC_VPORT ,0 ) == -VPORT_STATE_UP ) -return true; - -return false; -} -static void update_carrier (struct work_struct *work) {struct mlx5_vdpa_wq_ent *wqent;@@ -3032,11 +3060,7 @@ static void update_carrier(struct work_struct *work) wqent = container_of(work, struct mlx5_vdpa_wq_ent, work); mvdev = wqent->mvdev; ndev =to_mlx5_vdpa_ndev (mvdev); -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 ); - +update_link_state (mvdev);if (ndev->nb_registered && ndev->config_cb.callback) ndev->config_cb.callback (ndev->config_cb.private);@@ -3172,6 +3196,7 @@ static int mlx5_vdpa_dev_add(struct vdpa_mgmt_dev *v_mdev, const char *name,init_mvqs (ndev);init_rwsem (&ndev->reslock); +spin_lock_init (&ndev->status_lock); config = &ndev->config;if (add_config->mask &BIT_ULL (VDPA_ATTR_DEV_NET_CFG_MTU )) {drivers/vdpa/mlx5/net/mlx5_vnet.h +0
-0@@ -50,6 +50,8 @@ struct mlx5_vdpa_net {struct mlx5_vdpa_wq_ent cvq_ent;
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
drivers/vdpa/mlx5/net/mlx5_vnet.h +2
-0struct hlist_head macvlan_hash[MLX5V_MACVLAN_SIZE ];struct dentry *debugfs; +/* serialize link status updates */ +spinlock_t status_lock; };struct mlx5_vdpa_counter {Signature · 1 line
2.38.1
_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization