net/virtio-user: fix virtio net status management
PATCH 1/1 net/virtio-user: fix virtio net status management
Apart from the virtio status, there should be also a network related status for link status management, current implementation mixes up these two statuses.
One issue caused by this mixup is when virtio-user running in server mode and vhost as a client connects to it, a RARP packet will be generated by virtio-user due to VIRTIO_NET_S_ANNOUNCE bit is detected in the "status" in interrupt handler.
VIRTIO_NET_S_LINK_UP and VIRTIO_NET_S_ANNOUNCE should be managed by a separated field. This patch adds a "net_status" field for this purpose.
--- drivers/net/virtio/virtio_user/virtio_user_dev.h | 1 + drivers/net/virtio/virtio_user_ethdev.c | 10 +++++----- 2 files changed, 6 insertions(+), 5 deletions(-)
drivers/net/virtio/virtio_user/virtio_user_dev.h +1 -0
@@ -44,6 +44,7 @@ struct virtio_user_dev {* (Vhost-user only) */ uint8_t status; +uint16_t net_status;uint16_t port_id;uint8_t mac_addr[RTE_ETHER_ADDR_LEN ];char path[PATH_MAX ];
drivers/net/virtio/virtio_user_ethdev.c +5 -5
@@ -205,7 +205,7 @@ virtio_user_read_dev_config(struct virtio_hw *hw, size_t offset, } r =recv (dev->vhostfd, buf,128 ,MSG_PEEK );if (r ==0 || (r <0 && errno !=EAGAIN )) { - dev->status &= (~VIRTIO_NET_S_LINK_UP ); + dev->net_status &= (~VIRTIO_NET_S_LINK_UP );PMD_DRV_LOG (ERR ,"virtio-user port %u is down" , hw->port_id);
@@ -217,7 +217,7 @@ virtio_user_read_dev_config(struct virtio_hw *hw, size_t offset, virtio_user_delayed_handler, (void *)hw); }else { - dev->status |=VIRTIO_NET_S_LINK_UP ; + dev->net_status |=VIRTIO_NET_S_LINK_UP ; }if (fcntl (dev->vhostfd,F_SETFL , flags & ~O_NONBLOCK ) ==-1 ) {
@@ -225,12 +225,12 @@ virtio_user_read_dev_config(struct virtio_hw *hw, size_t offset,return ; } }else if (dev->is_server) { - dev->status &= (~VIRTIO_NET_S_LINK_UP ); + dev->net_status &= (~VIRTIO_NET_S_LINK_UP );if (virtio_user_server_reconnect (dev) >=0 ) - dev->status |=VIRTIO_NET_S_LINK_UP ; + dev->net_status |=VIRTIO_NET_S_LINK_UP ; } - *(uint16_t *)dst = dev->status; + *(uint16_t *)dst = dev->net_status; }if (offset == offsetof(struct virtio_net_config , max_virtqueue_pairs))
Signature · 1 line
2.15.1
Quoted 85 lines
-----Original Message-----
From: Wang, Xiao W <[email protected]>
Sent: Tuesday, July 28, 2020 2:52 PM
To: [email protected]
Cc: [email protected]; Wang, Zhihong <[email protected]>; Xia, Chenbo <[email protected]>; Wang, Xiao W <[email protected]>; [email protected]
Subject: [PATCH]net/virtio-user: fix virtio net status managementApart from the virtio status, there should be also a network related status for link status management, current implementation mixes up these two statuses.
One issue caused by this mixup is when virtio-user running in server mode and vhost as a client connects to it, a RARP packet will be generated by virtio-user due to
VIRTIO_NET_S_ANNOUNCEbit is detected in the "status"
in interrupt handler.
VIRTIO_NET_S_LINK_UPandVIRTIO_NET_S_ANNOUNCEshould be managed by a separated field. This patch adds a "net_status" field for this purpose.Fixes e9efa4d93821 ("net/virtio-user: add new virtual PCI driver")Signed-off-by Xiao Wang <[email protected]>--- drivers/net/virtio/virtio_user/virtio_user_dev.h | 1 + drivers/net/virtio/virtio_user_ethdev.c | 10 +++++----- 2 files changed, 6 insertions(+), 5 deletions(-)drivers/net/virtio/virtio_user/virtio_user_dev.h +1
-0@@ -44,6 +44,7 @@ struct virtio_user_dev {* (Vhost-user only) */ uint8_t status; +uint16_t net_status;uint16_t port_id;uint8_t mac_addr[RTE_ETHER_ADDR_LEN ];char path[PATH_MAX ];drivers/net/virtio/virtio_user_ethdev.c +1
-1@@ -205,7 +205,7 @@ virtio_user_read_dev_config(struct virtio_hw *hw,size_t offset, } r =recv (dev->vhostfd, buf,128 ,MSG_PEEK );if (r ==0 || (r <0 && errno !=EAGAIN )) { - dev->status &= (~VIRTIO_NET_S_LINK_UP ); + dev->net_status &= (~VIRTIO_NET_S_LINK_UP ); PMD_DRV_LOG(ERR, "virtio-user port %u is down",drivers/net/virtio/virtio_user_ethdev.c +1
-1hw->port_id);@@ -217,7 +217,7 @@ virtio_user_read_dev_config(struct virtio_hw *hw,size_t offset, virtio_user_delayed_handler, (void *)hw); }else { - dev->status |=VIRTIO_NET_S_LINK_UP ; + dev->net_status |=VIRTIO_NET_S_LINK_UP ; } if (fcntl(dev->vhostfd, F_SETFL,drivers/net/virtio/virtio_user_ethdev.c +3
-3flags & ~O_NONBLOCK) == -1) {@@ -225,12 +225,12 @@ virtio_user_read_dev_config(struct virtio_hw *hw,size_t offset, return; } }else if (dev->is_server) { - dev->status &= (~VIRTIO_NET_S_LINK_UP ); + dev->net_status &= (~VIRTIO_NET_S_LINK_UP );if (virtio_user_server_reconnect (dev) >=0 ) - dev->status |=VIRTIO_NET_S_LINK_UP ; + dev->net_status |=VIRTIO_NET_S_LINK_UP ; } - *(uint16_t *)dst = dev->status; + *(uint16_t *)dst = dev->net_status; }
Quoted 3 lines
if (offset ==
offsetof(struct virtio_net_config, max_virtqueue_pairs))
--
2.15.1
Quoted 12 lines · Xiao Wang
Apart from the virtio status, there should be also a network related status for link status management, current implementation mixes up these two statuses.
One issue caused by this mixup is when virtio-user running in server mode and vhost as a client connects to it, a RARP packet will be generated by virtio-user due to
VIRTIO_NET_S_ANNOUNCEbit is detected in the "status" in interrupt handler.
VIRTIO_NET_S_LINK_UPandVIRTIO_NET_S_ANNOUNCEshould be managed by a separated field. This patch adds a "net_status" field for this purpose.
Quoted 9 lines
Fixes e9efa4d93821 ("net/virtio-user: add new virtual PCI driver")Signed-off-by Xiao Wang <[email protected]>--- drivers/net/virtio/virtio_user/virtio_user_dev.h | 1 + drivers/net/virtio/virtio_user_ethdev.c | 10 +++++----- 2 files changed, 6 insertions(+), 5 deletions(-)
As discussed off-list, I will add Adrian's signn-off, as he also proposed same patch earlier.
Thanks,
Maxime
Maxime Coquelin
AppliedQuoted 12 lines · Xiao Wang
Apart from the virtio status, there should be also a network related status for link status management, current implementation mixes up these two statuses.
One issue caused by this mixup is when virtio-user running in server mode and vhost as a client connects to it, a RARP packet will be generated by virtio-user due to
VIRTIO_NET_S_ANNOUNCEbit is detected in the "status" in interrupt handler.
VIRTIO_NET_S_LINK_UPandVIRTIO_NET_S_ANNOUNCEshould be managed by a separated field. This patch adds a "net_status" field for this purpose.
Quoted 8 lines
Fixes e9efa4d93821 ("net/virtio-user: add new virtual PCI driver")Signed-off-by Xiao Wang <[email protected]>--- drivers/net/virtio/virtio_user/virtio_user_dev.h | 1 + drivers/net/virtio/virtio_user_ethdev.c | 10 +++++----- 2 files changed, 6 insertions(+), 5 deletions(-)
Applied to dpdk-next-virtio/master
Thanks,
Maxime