Skip to contentSkip to conversation

net: set endianness on all backend devices

PATCH In review Laurent Vivier 4 participants 7 messages Jan 13, 2016 – Jan 26, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 net: set endianness on all backend devices

commit 5be7d9f1b1452613b95c6ba70b8d7ad3d0797991
vhost-net: tell tap backend about the vnet endianness

makes vhost net to set the endianness of the device, but only for the first device.

In case of multiqueue, we have multiple devices... This patch sets the endianness for all the devices of the interface.

---
 hw/net/vhost_net.c | 23 +++++++++++------------
 1 file changed, 11 insertions(+), 12 deletions(-)
hw/net/vhost_net.c +11 -12
index 318c3e6..10e233a 100644
@@ -300,21 +300,19 @@ int vhost_net_start(VirtIODevice *dev, NetClientState *ncs,
     BusState *qbus = BUS(qdev_get_parent_bus(DEVICE(dev)));
     VirtioBusState *vbus = VIRTIO_BUS(qbus);
     VirtioBusClass *k = VIRTIO_BUS_GET_CLASS(vbus);
-    int r, e, i;
+    int r, e, i, j;
 
     if (!k->set_guest_notifiers) {
         error_report("binding does not support guest notifiers");
-        r = -ENOSYS;
-        goto err;
+        return -ENOSYS;
     }
 
-    r = vhost_net_set_vnet_endian(dev, ncs[0].peer, true);
-    if (r < 0) {
-        goto err;
-    }
-
-    for (i = 0; i < total_queues; i++) {
-        vhost_net_set_vq_index(get_vhost_net(ncs[i].peer), i * 2);
+    for (j = 0; j < total_queues; j++) {
+        r = vhost_net_set_vnet_endian(dev, ncs[j].peer, true);
+        if (r < 0) {
+            goto err_endian;
+        }
+        vhost_net_set_vq_index(get_vhost_net(ncs[j].peer), j * 2);
     }
 
     r = k->set_guest_notifiers(qbus->parent, total_queues * 2, true);
@@ -343,8 +341,9 @@ err_start:
         fflush(stderr);
     }
 err_endian:
-    vhost_net_set_vnet_endian(dev, ncs[0].peer, false);
-err:
+    while (--j >= 0) {
+        vhost_net_set_vnet_endian(dev, ncs[j].peer, false);
+    }
     return r;
 }
 
Signature · 1 line
1.8.3.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 11 lines · On Wed, 13 Jan 2016 20:26:25 +0100 Laurent Vivier <[email protected]> wrote:

commit 5be7d9f1b1452613b95c6ba70b8d7ad3d0797991
vhost-net: tell tap backend about the vnet endianness

makes vhost net to set the endianness of the device, but only for the first device.

In case of multiqueue, we have multiple devices... This patch sets the endianness for all the devices of the interface.

---

Thanks for fixing this bug... it's been there since 2.4.0. I guess we should backport this to 2.4 and 2.5. Cc'ing stable.

Quoted 49 lines
 hw/net/vhost_net.c | 23 +++++++++++------------
 1 file changed, 11 insertions(+), 12 deletions(-)
hw/net/vhost_net.c +11 -12
index 318c3e6..10e233a 100644
@@ -300,21 +300,19 @@ int vhost_net_start(VirtIODevice *dev, NetClientState *ncs,
     BusState *qbus = BUS(qdev_get_parent_bus(DEVICE(dev)));
     VirtioBusState *vbus = VIRTIO_BUS(qbus);
     VirtioBusClass *k = VIRTIO_BUS_GET_CLASS(vbus);
-    int r, e, i;
+    int r, e, i, j;
 
     if (!k->set_guest_notifiers) {
         error_report("binding does not support guest notifiers");
-        r = -ENOSYS;
-        goto err;
+        return -ENOSYS;
     }
 
-    r = vhost_net_set_vnet_endian(dev, ncs[0].peer, true);
-    if (r < 0) {
-        goto err;
-    }
-
-    for (i = 0; i < total_queues; i++) {
-        vhost_net_set_vq_index(get_vhost_net(ncs[i].peer), i * 2);
+    for (j = 0; j < total_queues; j++) {
+        r = vhost_net_set_vnet_endian(dev, ncs[j].peer, true);
+        if (r < 0) {
+            goto err_endian;
+        }
+        vhost_net_set_vq_index(get_vhost_net(ncs[j].peer), j * 2);
     }
 
     r = k->set_guest_notifiers(qbus->parent, total_queues * 2, true);
@@ -343,8 +341,9 @@ err_start:
         fflush(stderr);
     }
 err_endian:
-    vhost_net_set_vnet_endian(dev, ncs[0].peer, false);
-err:
+    while (--j >= 0) {
+        vhost_net_set_vnet_endian(dev, ncs[j].peer, false);
+    }
     return r;
 }
 
Reviewed-by
#2 lore raw
Quoted 9 lines · On Thu, 14 Jan 2016 09:01:49 +0100 Greg Kurz <[email protected]> wrote:
Quoted 6 lines · On Wed, 13 Jan 2016 20:26:25 +0100 Laurent Vivier <[email protected]> wrote:

commit 5be7d9f1b1452613b95c6ba70b8d7ad3d0797991
vhost-net: tell tap backend about the vnet endianness

makes vhost net to set the endianness of the device, but only for the first device.

Quoted 8 lines
Quoted 5 lines

In case of multiqueue, we have multiple devices... This patch sets the endianness for all the devices of the interface.

---

Thanks for fixing this bug... it's been there since 2.4.0. I guess we should backport this to 2.4 and 2.5. Cc'ing stable.

Agree on backporting this.

Quoted 5 lines
Quoted 3 lines
 hw/net/vhost_net.c | 23 +++++++++++------------
 1 file changed, 11 insertions(+), 12 deletions(-)
Quoted 10 lines

hw/net/vhost_net.c int vhost_net_start(VirtIODevice *dev, NetClientState *ncs, · line 303

Quoted 10 lines
hw/net/vhost_net.c +1 -1
index 318c3e6..10e233a 100644
@@ -300,21 +300,19 @@ int vhost_net_start(VirtIODevice *dev, NetClientState *ncs,
     BusState *qbus = BUS(qdev_get_parent_bus(DEVICE(dev)));
     VirtioBusState *vbus = VIRTIO_BUS(qbus);
     VirtioBusClass *k = VIRTIO_BUS_GET_CLASS(vbus);
-    int r, e, i;
+    int r, e, i, j;

Nice alphabet soup ;)

#3 lore raw
In reply to Laurent Vivier

ping

[added Jason in cc:]

Quoted 61 lines · Laurent Vivier

commit 5be7d9f1b1452613b95c6ba70b8d7ad3d0797991
vhost-net: tell tap backend about the vnet endianness

makes vhost net to set the endianness of the device, but only for the first device.

In case of multiqueue, we have multiple devices... This patch sets the endianness for all the devices of the interface.

---
 hw/net/vhost_net.c | 23 +++++++++++------------
 1 file changed, 11 insertions(+), 12 deletions(-)
hw/net/vhost_net.c +11 -12
index 318c3e6..10e233a 100644
@@ -300,21 +300,19 @@ int vhost_net_start(VirtIODevice *dev, NetClientState *ncs,
     BusState *qbus = BUS(qdev_get_parent_bus(DEVICE(dev)));
     VirtioBusState *vbus = VIRTIO_BUS(qbus);
     VirtioBusClass *k = VIRTIO_BUS_GET_CLASS(vbus);
-    int r, e, i;
+    int r, e, i, j;
 
     if (!k->set_guest_notifiers) {
         error_report("binding does not support guest notifiers");
-        r = -ENOSYS;
-        goto err;
+        return -ENOSYS;
     }
 
-    r = vhost_net_set_vnet_endian(dev, ncs[0].peer, true);
-    if (r < 0) {
-        goto err;
-    }
-
-    for (i = 0; i < total_queues; i++) {
-        vhost_net_set_vq_index(get_vhost_net(ncs[i].peer), i * 2);
+    for (j = 0; j < total_queues; j++) {
+        r = vhost_net_set_vnet_endian(dev, ncs[j].peer, true);
+        if (r < 0) {
+            goto err_endian;
+        }
+        vhost_net_set_vq_index(get_vhost_net(ncs[j].peer), j * 2);
     }
 
     r = k->set_guest_notifiers(qbus->parent, total_queues * 2, true);
@@ -343,8 +341,9 @@ err_start:
         fflush(stderr);
     }
 err_endian:
-    vhost_net_set_vnet_endian(dev, ncs[0].peer, false);
-err:
+    while (--j >= 0) {
+        vhost_net_set_vnet_endian(dev, ncs[j].peer, false);
+    }
     return r;
 }
 
Reviewed-by
#4 lore raw
Quoted 52 lines · Laurent Vivier

ping

[added Jason in cc:]

Quoted 47 lines · Laurent Vivier

commit 5be7d9f1b1452613b95c6ba70b8d7ad3d0797991
vhost-net: tell tap backend about the vnet endianness

makes vhost net to set the endianness of the device, but only for the first device.

In case of multiqueue, we have multiple devices... This patch sets the endianness for all the devices of the interface.

---
 hw/net/vhost_net.c | 23 +++++++++++------------
 1 file changed, 11 insertions(+), 12 deletions(-)
hw/net/vhost_net.c +8 -10
index 318c3e6..10e233a 100644
@@ -300,21 +300,19 @@ int vhost_net_start(VirtIODevice *dev, NetClientState *ncs,
     BusState *qbus = BUS(qdev_get_parent_bus(DEVICE(dev)));
     VirtioBusState *vbus = VIRTIO_BUS(qbus);
     VirtioBusClass *k = VIRTIO_BUS_GET_CLASS(vbus);
-    int r, e, i;
+    int r, e, i, j;
 
     if (!k->set_guest_notifiers) {
         error_report("binding does not support guest notifiers");
-        r = -ENOSYS;
-        goto err;
+        return -ENOSYS;
     }
 
-    r = vhost_net_set_vnet_endian(dev, ncs[0].peer, true);
-    if (r < 0) {
-        goto err;
-    }
-
-    for (i = 0; i < total_queues; i++) {
-        vhost_net_set_vq_index(get_vhost_net(ncs[i].peer), i * 2);
+    for (j = 0; j < total_queues; j++) {
+        r = vhost_net_set_vnet_endian(dev, ncs[j].peer, true);
+        if (r < 0) {
+            goto err_endian;
+        }
+        vhost_net_set_vq_index(get_vhost_net(ncs[j].peer), j * 2);
     }
 
Quoted 13 lines

hw/net/vhost_net.c err_start: · line 349

Quoted 13 lines
hw/net/vhost_net.c +3 -2
     r = k->set_guest_notifiers(qbus->parent, total_queues * 2, true);
@@ -343,8 +341,9 @@ err_start:
         fflush(stderr);
     }
 err_endian:
-    vhost_net_set_vnet_endian(dev, ncs[0].peer, false);
-err:
+    while (--j >= 0) {
+        vhost_net_set_vnet_endian(dev, ncs[j].peer, false);
+    }
     return r;
 }
 
#5 lore raw
Quoted 55 lines · Jason Wang
Quoted 52 lines · Laurent Vivier

ping

[added Jason in cc:]

Quoted 47 lines · Laurent Vivier

commit 5be7d9f1b1452613b95c6ba70b8d7ad3d0797991
vhost-net: tell tap backend about the vnet endianness

makes vhost net to set the endianness of the device, but only for the first device.

In case of multiqueue, we have multiple devices... This patch sets the endianness for all the devices of the interface.

---
 hw/net/vhost_net.c | 23 +++++++++++------------
 1 file changed, 11 insertions(+), 12 deletions(-)
hw/net/vhost_net.c +8 -10
index 318c3e6..10e233a 100644
@@ -300,21 +300,19 @@ int vhost_net_start(VirtIODevice *dev, NetClientState *ncs,
     BusState *qbus = BUS(qdev_get_parent_bus(DEVICE(dev)));
     VirtioBusState *vbus = VIRTIO_BUS(qbus);
     VirtioBusClass *k = VIRTIO_BUS_GET_CLASS(vbus);
-    int r, e, i;
+    int r, e, i, j;
 
     if (!k->set_guest_notifiers) {
         error_report("binding does not support guest notifiers");
-        r = -ENOSYS;
-        goto err;
+        return -ENOSYS;
     }
 
-    r = vhost_net_set_vnet_endian(dev, ncs[0].peer, true);
-    if (r < 0) {
-        goto err;
-    }
-
-    for (i = 0; i < total_queues; i++) {
-        vhost_net_set_vq_index(get_vhost_net(ncs[i].peer), i * 2);
+    for (j = 0; j < total_queues; j++) {
+        r = vhost_net_set_vnet_endian(dev, ncs[j].peer, true);
+        if (r < 0) {
+            goto err_endian;
+        }
+        vhost_net_set_vq_index(get_vhost_net(ncs[j].peer), j * 2);
     }
 
Quoted 15 lines
Quoted 5 lines
Quoted 5 lines
hw/net/vhost_net.c +0 -0
     r = k->set_guest_notifiers(qbus->parent, total_queues * 2, true);
@@ -343,8 +341,9 @@ err_start:
         fflush(stderr);
     }
 err_endian:
Quoted 8 lines

hw/net/vhost_net.c err_start: · line 349

Quoted 8 lines
hw/net/vhost_net.c +3 -2
-    vhost_net_set_vnet_endian(dev, ncs[0].peer, false);
-err:
+    while (--j >= 0) {
+        vhost_net_set_vnet_endian(dev, ncs[j].peer, false);
+    }
     return r;
 }
 

Thanks Jason.

Who can pick this in his tree ?

Laurent

#6 lore raw
Quoted 72 lines · On Tue, 26 Jan 2016 11:53:21 +0100 Laurent Vivier <[email protected]> wrote:
Quoted 55 lines · Jason Wang
Quoted 52 lines · Laurent Vivier

ping

[added Jason in cc:]

Quoted 47 lines · Laurent Vivier

commit 5be7d9f1b1452613b95c6ba70b8d7ad3d0797991
vhost-net: tell tap backend about the vnet endianness

makes vhost net to set the endianness of the device, but only for the first device.

In case of multiqueue, we have multiple devices... This patch sets the endianness for all the devices of the interface.

---
 hw/net/vhost_net.c | 23 +++++++++++------------
 1 file changed, 11 insertions(+), 12 deletions(-)
hw/net/vhost_net.c +8 -10
index 318c3e6..10e233a 100644
@@ -300,21 +300,19 @@ int vhost_net_start(VirtIODevice *dev, NetClientState *ncs,
     BusState *qbus = BUS(qdev_get_parent_bus(DEVICE(dev)));
     VirtioBusState *vbus = VIRTIO_BUS(qbus);
     VirtioBusClass *k = VIRTIO_BUS_GET_CLASS(vbus);
-    int r, e, i;
+    int r, e, i, j;
 
     if (!k->set_guest_notifiers) {
         error_report("binding does not support guest notifiers");
-        r = -ENOSYS;
-        goto err;
+        return -ENOSYS;
     }
 
-    r = vhost_net_set_vnet_endian(dev, ncs[0].peer, true);
-    if (r < 0) {
-        goto err;
-    }
-
-    for (i = 0; i < total_queues; i++) {
-        vhost_net_set_vq_index(get_vhost_net(ncs[i].peer), i * 2);
+    for (j = 0; j < total_queues; j++) {
+        r = vhost_net_set_vnet_endian(dev, ncs[j].peer, true);
+        if (r < 0) {
+            goto err_endian;
+        }
+        vhost_net_set_vq_index(get_vhost_net(ncs[j].peer), j * 2);
     }
 
Quoted 15 lines
Quoted 5 lines
Quoted 5 lines
hw/net/vhost_net.c +0 -0
     r = k->set_guest_notifiers(qbus->parent, total_queues * 2, true);
@@ -343,8 +341,9 @@ err_start:
         fflush(stderr);
     }
 err_endian:
Quoted 8 lines

hw/net/vhost_net.c err_start: · line 349

Quoted 8 lines
hw/net/vhost_net.c +3 -2
-    vhost_net_set_vnet_endian(dev, ncs[0].peer, false);
-err:
+    while (--j >= 0) {
+        vhost_net_set_vnet_endian(dev, ncs[j].peer, false);
+    }
     return r;
 }
 
Quoted 4 lines

Thanks Jason.

Who can pick this in his tree ?

According to MAINTAINERS, this must go through Michael's tree, but it looks like he is very busy reworking memory barriers in the kernel...

Quoted 2 lines

Laurent

--
Greg