[v3,5/6] net/virtio-user: don't assume vhost status feature

Message ID 20201026163930.94032-6-amorenoz@redhat.com (mailing list archive)
State Accepted, archived
Delegated to: Maxime Coquelin
Headers
Series net/virtio-user: fix server mode |

Checks

Context Check Description
ci/checkpatch warning coding style issues

Commit Message

Adrian Moreno Oct. 26, 2020, 4:39 p.m. UTC
  There are some status reads and updates that need to happen before the
protocol features are negotiated. Therefore, assuming the backend does
support this feature can lead to failures.

On server mode, do not assume the backend supports
VHOST_USER_PROTOCOL_F_STATUS. Activate it back on reconnection and
cleare it on disconnection.

Fixes: 57912824615f ("net/virtio-user: support vhost status setting")
Cc: maxime.coquelin@redhat.com
Cc: stable@dpdk.org

Signed-off-by: Adrian Moreno <amorenoz@redhat.com>
---
 drivers/net/virtio/virtio_user/virtio_user_dev.c | 6 ++++++
 drivers/net/virtio/virtio_user_ethdev.c          | 8 ++++++++
 2 files changed, 14 insertions(+)
  

Comments

Maxime Coquelin Oct. 28, 2020, 10:37 a.m. UTC | #1
On 10/26/20 5:39 PM, Adrian Moreno wrote:
> There are some status reads and updates that need to happen before the
> protocol features are negotiated. Therefore, assuming the backend does
> support this feature can lead to failures.
> 
> On server mode, do not assume the backend supports
> VHOST_USER_PROTOCOL_F_STATUS. Activate it back on reconnection and
> cleare it on disconnection.
> 
> Fixes: 57912824615f ("net/virtio-user: support vhost status setting")
> Cc: maxime.coquelin@redhat.com
> Cc: stable@dpdk.org
> 
> Signed-off-by: Adrian Moreno <amorenoz@redhat.com>
> ---
>  drivers/net/virtio/virtio_user/virtio_user_dev.c | 6 ++++++
>  drivers/net/virtio/virtio_user_ethdev.c          | 8 ++++++++
>  2 files changed, 14 insertions(+)
> 


Reviewed-by: Maxime Coquelin <maxime.coquelin@redhat.com>

Thanks,
Maxime
  

Patch

diff --git a/drivers/net/virtio/virtio_user/virtio_user_dev.c b/drivers/net/virtio/virtio_user/virtio_user_dev.c
index 36e5619df..053f0267c 100644
--- a/drivers/net/virtio/virtio_user/virtio_user_dev.c
+++ b/drivers/net/virtio/virtio_user/virtio_user_dev.c
@@ -523,6 +523,12 @@  virtio_user_dev_init(struct virtio_user_dev *dev, char *path, int queues,
 		 * later.
 		 */
 		dev->device_features = VIRTIO_USER_SUPPORTED_FEATURES;
+
+		/* We cannot assume VHOST_USER_PROTOCOL_F_STATUS is supported
+		 * until it's negotiated
+		 */
+		dev->protocol_features &=
+			~(1ULL << VHOST_USER_PROTOCOL_F_STATUS);
 	}
 
 
diff --git a/drivers/net/virtio/virtio_user_ethdev.c b/drivers/net/virtio/virtio_user_ethdev.c
index 97ddc5651..142bdc0bd 100644
--- a/drivers/net/virtio/virtio_user_ethdev.c
+++ b/drivers/net/virtio/virtio_user_ethdev.c
@@ -92,6 +92,9 @@  virtio_user_server_reconnect(struct virtio_user_dev *dev)
 					&protocol_features))
 			return -1;
 
+		/* Offer VHOST_USER_PROTOCOL_F_STATUS */
+		dev->protocol_features |=
+			(1ULL << VHOST_USER_PROTOCOL_F_STATUS);
 		dev->protocol_features &= protocol_features;
 
 		if (dev->ops->send_request(dev,
@@ -168,6 +171,11 @@  virtio_user_delayed_handler(void *param)
 		if (dev->vhostfd >= 0) {
 			close(dev->vhostfd);
 			dev->vhostfd = -1;
+			/* Until the featuers are negotiated again, don't assume
+			 * the backend supports VHOST_USER_PROTOCOL_F_STATUS
+			 */
+			dev->protocol_features &=
+				~(1ULL << VHOST_USER_PROTOCOL_F_STATUS);
 		}
 		eth_dev->intr_handle->fd = dev->listenfd;
 		rte_intr_callback_register(eth_dev->intr_handle,