Skip to contentSkip to conversation

net/virtio: fix kernel set features for multi-queue devices

PATCH Applied Thierry Herbelot 3 participants 4 messages May 28, 2021 – Jun 17, 2021 Network drivers

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 net/virtio: fix kernel set features for multi-queue devices

Restore the original code, where VHOST_SET_FEATURES is applied to all vhostfds of the device.

Fixes cc0151b34dee ("net/virtio: add virtio-user features ops")
Cc Maxime Coquelin <[email protected]>
Cc Chenbo Xia <[email protected]>
---
 drivers/net/virtio/virtio_user/vhost_kernel.c | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)
drivers/net/virtio/virtio_user/vhost_kernel.c +12 -1
index ad46f10a9300..d65f89e1fc16 100644
@@ -158,6 +158,8 @@ static int
 vhost_kernel_set_features(struct virtio_user_dev *dev, uint64_t features)
 {
 	struct vhost_kernel_data *data = dev->backend_data;
+	uint32_t i;
+	int ret;
 
 	/* We don't need memory protection here */
 	features &= ~(1ULL << VIRTIO_F_IOMMU_PLATFORM);
@@ -166,7 +168,16 @@ vhost_kernel_set_features(struct virtio_user_dev *dev, uint64_t features)
 	features &= ~VHOST_KERNEL_HOST_OFFLOADS_MASK;
 	features &= ~(1ULL << VIRTIO_NET_F_MQ);
 
-	return vhost_kernel_ioctl(data->vhostfds[0], VHOST_SET_FEATURES, &features);
+	for (i = 0; i < dev->max_queue_pairs; ++i) {
+		if (data->vhostfds[i] < 0)
+			continue;
+
+		ret = vhost_kernel_ioctl(data->vhostfds[i], VHOST_SET_FEATURES, &features);
+		if (ret < 0)
+			return ret;
+	}
+
+	return 0;
 }
 
 static int
Signature · 1 line
2.29.2
Reviewed-by on v1 1/1
#1 lore raw
Quoted 35 lines · Thierry Herbelot

Restore the original code, where VHOST_SET_FEATURES is applied to all vhostfds of the device.

Fixes cc0151b34dee ("net/virtio: add virtio-user features ops")
Cc Maxime Coquelin <[email protected]>
Cc Chenbo Xia <[email protected]>
---
 drivers/net/virtio/virtio_user/vhost_kernel.c | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)
drivers/net/virtio/virtio_user/vhost_kernel.c +5 -1
index ad46f10a9300..d65f89e1fc16 100644
@@ -158,6 +158,8 @@ static int
 vhost_kernel_set_features(struct virtio_user_dev *dev, uint64_t features)
 {
 	struct vhost_kernel_data *data = dev->backend_data;
+	uint32_t i;
+	int ret;
 
 	/* We don't need memory protection here */
 	features &= ~(1ULL << VIRTIO_F_IOMMU_PLATFORM);
@@ -166,7 +168,16 @@ vhost_kernel_set_features(struct virtio_user_dev *dev, uint64_t features)
 	features &= ~VHOST_KERNEL_HOST_OFFLOADS_MASK;
 	features &= ~(1ULL << VIRTIO_NET_F_MQ);
 
-	return vhost_kernel_ioctl(data->vhostfds[0], VHOST_SET_FEATURES, &features);
+	for (i = 0; i < dev->max_queue_pairs; ++i) {
+		if (data->vhostfds[i] < 0)
+			continue;

drivers/net/virtio/virtio_user/vhost_kernel.c vhost_kernel_set_features(struct virtio_user_dev *dev, uint64_t features) · line 183

Quoted 10 lines
drivers/net/virtio/virtio_user/vhost_kernel.c +7 -0
+
+		ret = vhost_kernel_ioctl(data->vhostfds[i], VHOST_SET_FEATURES, &features);
+		if (ret < 0)
+			return ret;
+	}
+
+	return 0;
 }
 
 static int

Thanks for fixing it, it should be the last one...

Except GET_FEATURES that was also queried for every queue pair, but I don't think it makes sense to query it and just drop the value read. What do you think?

Thanks,
Maxime

#2 lore raw

Hello Maxime,

Quoted 46 lines · Maxime Coquelin
Quoted 43 lines · Thierry Herbelot

Restore the original code, where VHOST_SET_FEATURES is applied to all vhostfds of the device.

Fixes cc0151b34dee ("net/virtio: add virtio-user features ops")
Cc Maxime Coquelin <[email protected]>
Cc Chenbo Xia <[email protected]>
---
  drivers/net/virtio/virtio_user/vhost_kernel.c | 13 ++++++++++++-
  1 file changed, 12 insertions(+), 1 deletion(-)
drivers/net/virtio/virtio_user/vhost_kernel.c +12 -1
index ad46f10a9300..d65f89e1fc16 100644
@@ -158,6 +158,8 @@ static int
  vhost_kernel_set_features(struct virtio_user_dev *dev, uint64_t features)
  {
  	struct vhost_kernel_data *data = dev->backend_data;
+	uint32_t i;
+	int ret;
 
  	/* We don't need memory protection here */
  	features &= ~(1ULL << VIRTIO_F_IOMMU_PLATFORM);
@@ -166,7 +168,16 @@ vhost_kernel_set_features(struct virtio_user_dev *dev, uint64_t features)
  	features &= ~VHOST_KERNEL_HOST_OFFLOADS_MASK;
  	features &= ~(1ULL << VIRTIO_NET_F_MQ);
 
-	return vhost_kernel_ioctl(data->vhostfds[0], VHOST_SET_FEATURES, &features);
+	for (i = 0; i < dev->max_queue_pairs; ++i) {
+		if (data->vhostfds[i] < 0)
+			continue;
+
+		ret = vhost_kernel_ioctl(data->vhostfds[i], VHOST_SET_FEATURES, &features);
+		if (ret < 0)
+			return ret;
+	}
+
+	return 0;
  }
 
Quoted 8 lines

drivers/net/virtio/virtio_user/vhost_kernel.c vhost_kernel_set_features(struct virtio_user_dev *dev, uint64_t features) · line 183

Quoted 2 lines
drivers/net/virtio/virtio_user/vhost_kernel.c +0 -0
  static int

Thanks for fixing it, it should be the last one...

Except GET_FEATURES that was also queried for every queue pair, but I don't think it makes sense to query it and just drop the value read. What do you think?

Indeed, GET_FEATURES returns a single value: let's assume the value for the first queue pair is the right one.

Thierry

Quoted 6 lines

Thanks,
Maxime

Signature · 9 lines
Thierry Herbelot
Senior Software Engineer
Tel: +33 1 39 30 92 61
http://www.6wind.com/

Follow us:
https://www.linkedin.com/company/6wind/
https://twitter.com/6WINDsoftware
https://www.youtube.com/user/6windsoftware
#3 lore raw
In reply to Thierry Herbelot
Quoted 8 lines · Thierry Herbelot

Restore the original code, where VHOST_SET_FEATURES is applied to all vhostfds of the device.

Fixes cc0151b34dee ("net/virtio: add virtio-user features ops")
Cc Maxime Coquelin <[email protected]>
Cc Chenbo Xia <[email protected]>
Quoted 5 lines
---
 drivers/net/virtio/virtio_user/vhost_kernel.c | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

Applied to dpdk-next-virtio/main.

Thanks,
Maxime