Skip to contentSkip to conversation

vdpa: Fix SIGSEGV on failed vdpa devices

PATCH Superseded Eugenio Pérez 2 participants 7 messages Nov 19, 2021 – Nov 22, 2021 Networking

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover vdpa: Fix SIGSEGV on failed vdpa devices

Qemu falls back on userland handlers even if vhost-user and vhost-vdpa cases. These assumes a tap device can handle the packets.

If a vdpa device fail to start, it can trigger a sigsegv because of that. Add dummy receivers that return no progress so it can keep running.

Tested with a modified version of vp_vdpa to fail negotiation.

This is another bersion of the patch proposed in [1], but the subject didn't match the patch anymore.

[1] https://lists.nongnu.org/archive/html/qemu-devel/2021-11/msg03719.html

Eugenio Pérez (3):
virtio-net: Fix indentation
vdpa: Add dummy receive callbacks
virtio-net: Fix log message

 hw/net/virtio-net.c | 13 +++++++------
 net/vhost-vdpa.c    | 16 ++++++++++++++++
 2 files changed, 23 insertions(+), 6 deletions(-)
Signature · 1 line
2.27.0
#1 lore raw

PATCH 1/3 virtio-net: Fix indentation

---
 hw/net/virtio-net.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/net/virtio-net.c +1 -1
index f2014d5ea0..004acf858f 100644
@@ -3501,7 +3501,7 @@ static void virtio_net_device_realize(DeviceState *dev, Error **errp)
     nc = qemu_get_queue(n->nic);
     nc->rxfilter_notify_enabled = 1;
 
-   if (nc->peer && nc->peer->info->type == NET_CLIENT_DRIVER_VHOST_VDPA) {
+    if (nc->peer && nc->peer->info->type == NET_CLIENT_DRIVER_VHOST_VDPA) {
         struct virtio_net_config netcfg = {};
         memcpy(&netcfg.mac, &n->nic_conf.macaddr, ETH_ALEN);
         vhost_net_set_config(get_vhost_net(nc->peer),
Signature · 1 line
2.27.0
#2 lore raw

PATCH 2/3 vdpa: Add dummy receive callbacks

In reply to Eugenio Pérez

Qemu falls back on userland handlers even if vhost-user and vhost-vdpa cases. These assumes a tap device can handle the packets.

If a vdpa device fail to start, it can trigger a sigsegv because of that. Add dummy receivers that return no progress so it can keep running.

Fixes 1e0a84ea49 ("vhost-vdpa: introduce vhost-vdpa net client")
---
 net/vhost-vdpa.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)
net/vhost-vdpa.c +16 -0
index 2e3c22a8c7..4c75b78304 100644
@@ -170,9 +170,25 @@ static bool vhost_vdpa_check_peer_type(NetClientState *nc, ObjectClass *oc,
     return true;
 }
 
+/** Dummy receive in case qemu falls back to userland tap networking */
+static ssize_t vhost_vdpa_receive_iov(NetClientState *nc,
+                                      const struct iovec *iov, int iovcnt)
+{
+    return 0;
+}
+
+/** Dummy receive in case qemu falls back to userland tap networking */
+static ssize_t vhost_vdpa_receive_raw(NetClientState *nc, const uint8_t *buf,
+                                      size_t size)
+{
+    return 0;
+}
+
 static NetClientInfo net_vhost_vdpa_info = {
         .type = NET_CLIENT_DRIVER_VHOST_VDPA,
         .size = sizeof(VhostVDPAState),
+        .receive_iov = vhost_vdpa_receive_iov,
+        .receive_raw = vhost_vdpa_receive_raw,
         .cleanup = vhost_vdpa_cleanup,
         .has_vnet_hdr = vhost_vdpa_has_vnet_hdr,
         .has_ufo = vhost_vdpa_has_ufo,
Signature · 1 line
2.27.0
#3 lore raw

Re: [PATCH 2/3] vdpa: Add dummy receive callbacks

Quoted 25 lines · Eugenio Pérez

Qemu falls back on userland handlers even if vhost-user and vhost-vdpa cases. These assumes a tap device can handle the packets.

If a vdpa device fail to start, it can trigger a sigsegv because of that. Add dummy receivers that return no progress so it can keep running.

Fixes 1e0a84ea49 ("vhost-vdpa: introduce vhost-vdpa net client")
---
 net/vhost-vdpa.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)
net/vhost-vdpa.c +3 -0
index 2e3c22a8c7..4c75b78304 100644
@@ -170,9 +170,25 @@ static bool vhost_vdpa_check_peer_type(NetClientState *nc, ObjectClass *oc,
     return true;
 }
 
+/** Dummy receive in case qemu falls back to userland tap networking */
+static ssize_t vhost_vdpa_receive_iov(NetClientState *nc,
+                                      const struct iovec *iov, int iovcnt)

net/vhost-vdpa.c static bool vhost_vdpa_check_peer_type(NetClientState *nc, ObjectClass *oc, · line 185

Quoted 10 lines
net/vhost-vdpa.c +10 -0
+{
+    return 0;
+}
+
+/** Dummy receive in case qemu falls back to userland tap networking */
+static ssize_t vhost_vdpa_receive_raw(NetClientState *nc, const uint8_t *buf,
+                                      size_t size)
+{
+    return 0;
+}

It looks to me the .receive_raw is not need, in nc_sendv_compat() we had:

=>  if (flags & QEMU_NET_PACKET_FLAG_RAW && nc->info->receive_raw) {
        ret = nc->info->receive_raw(nc, buffer, offset);
    } else {
        ret = nc->info->receive(nc, buffer, offset);
    }

Thanks

Quoted 12 lines
net/vhost-vdpa.c +3 -1
+
 static NetClientInfo net_vhost_vdpa_info = {
         .type = NET_CLIENT_DRIVER_VHOST_VDPA,
         .size = sizeof(VhostVDPAState),
+        .receive_iov = vhost_vdpa_receive_iov,
+        .receive_raw = vhost_vdpa_receive_raw,
         .cleanup = vhost_vdpa_cleanup,
         .has_vnet_hdr = vhost_vdpa_has_vnet_hdr,
         .has_ufo = vhost_vdpa_has_ufo,
--

2.27.0

#4 lore raw

Re: [PATCH 2/3] vdpa: Add dummy receive callbacks

Quoted 40 lines · Jason Wang
Quoted 25 lines · Eugenio Pérez

Qemu falls back on userland handlers even if vhost-user and vhost-vdpa cases. These assumes a tap device can handle the packets.

If a vdpa device fail to start, it can trigger a sigsegv because of that. Add dummy receivers that return no progress so it can keep running.

Fixes 1e0a84ea49 ("vhost-vdpa: introduce vhost-vdpa net client")
---
 net/vhost-vdpa.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)
net/vhost-vdpa.c +3 -0
index 2e3c22a8c7..4c75b78304 100644
@@ -170,9 +170,25 @@ static bool vhost_vdpa_check_peer_type(NetClientState *nc, ObjectClass *oc,
     return true;
 }
 
+/** Dummy receive in case qemu falls back to userland tap networking */
+static ssize_t vhost_vdpa_receive_iov(NetClientState *nc,
+                                      const struct iovec *iov, int iovcnt)

net/vhost-vdpa.c static bool vhost_vdpa_check_peer_type(NetClientState *nc, ObjectClass *oc, · line 185

Quoted 10 lines
net/vhost-vdpa.c +10 -0
+{
+    return 0;
+}
+
+/** Dummy receive in case qemu falls back to userland tap networking */
+static ssize_t vhost_vdpa_receive_raw(NetClientState *nc, const uint8_t *buf,
+                                      size_t size)
+{
+    return 0;
+}

It looks to me the .receive_raw is not need, in nc_sendv_compat() we had:

Quoted 6 lines
=>  if (flags & QEMU_NET_PACKET_FLAG_RAW && nc->info->receive_raw) {
        ret = nc->info->receive_raw(nc, buffer, offset);
    } else {
        ret = nc->info->receive(nc, buffer, offset);
    }

Right, I will delete the _raw part.

Thanks!

Quoted 15 lines

Thanks

Quoted 12 lines
net/vhost-vdpa.c +3 -1
+
 static NetClientInfo net_vhost_vdpa_info = {
         .type = NET_CLIENT_DRIVER_VHOST_VDPA,
         .size = sizeof(VhostVDPAState),
+        .receive_iov = vhost_vdpa_receive_iov,
+        .receive_raw = vhost_vdpa_receive_raw,
         .cleanup = vhost_vdpa_cleanup,
         .has_vnet_hdr = vhost_vdpa_has_vnet_hdr,
         .has_ufo = vhost_vdpa_has_ufo,
--

2.27.0

#5 lore raw

PATCH 3/3 virtio-net: Fix log message

In reply to Eugenio Pérez

The message has never been true in the case of non tap networking, so only tell that userland networking will be used if possible.

---
 hw/net/virtio-net.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)
hw/net/virtio-net.c +6 -5
index 004acf858f..442082dd8c 100644
@@ -245,6 +245,7 @@ static void virtio_net_vhost_status(VirtIONet *n, uint8_t status)
     NetClientState *nc = qemu_get_queue(n->nic);
     int queue_pairs = n->multiqueue ? n->max_queue_pairs : 1;
     int cvq = n->max_ncs - n->max_queue_pairs;
+    bool tap_backend = nc->peer->info->type == NET_CLIENT_DRIVER_TAP;
 
     if (!get_vhost_net(nc->peer)) {
         return;
@@ -258,9 +259,9 @@ static void virtio_net_vhost_status(VirtIONet *n, uint8_t status)
         int r, i;
 
         if (n->needs_vnet_hdr_swap) {
-            error_report("backend does not support %s vnet headers; "
-                         "falling back on userspace virtio",
-                         virtio_is_big_endian(vdev) ? "BE" : "LE");
+            error_report("backend does not support %s vnet headers%s",
+                    virtio_is_big_endian(vdev) ? "BE" : "LE",
+                    tap_backend ? "; falling back on userspace virtio" : "");
             return;
         }
 
@@ -288,8 +289,8 @@ static void virtio_net_vhost_status(VirtIONet *n, uint8_t status)
         n->vhost_started = 1;
         r = vhost_net_start(vdev, n->nic->ncs, queue_pairs, cvq);
         if (r < 0) {
-            error_report("unable to start vhost net: %d: "
-                         "falling back on userspace virtio", -r);
+            error_report("unable to start vhost net: %d%s", -r,
+                       tap_backend ? " falling back on userspace virtio" : "");
             n->vhost_started = 0;
         }
     } else {
Signature · 1 line
2.27.0
#6 lore raw
In reply to Eugenio Pérez
Quoted 8 lines · Eugenio Pérez

Qemu falls back on userland handlers even if vhost-user and vhost-vdpa cases. These assumes a tap device can handle the packets.

If a vdpa device fail to start, it can trigger a sigsegv because of that. Add dummy receivers that return no progress so it can keep running.

Quoted 7 lines

Tested with a modified version of vp_vdpa to fail negotiation.

This is another bersion of the patch proposed in [1], but the subject didn't match the patch anymore.

[1] https://lists.nongnu.org/archive/html/qemu-devel/2021-11/msg03719.html

As discussed, we need to consider fixing the gRARP transmission issue on top, any idea on that?

Thanks

Quoted 13 lines

Eugenio Pérez (3):
virtio-net: Fix indentation
vdpa: Add dummy receive callbacks
virtio-net: Fix log message

 hw/net/virtio-net.c | 13 +++++++------
 net/vhost-vdpa.c    | 16 ++++++++++++++++
 2 files changed, 23 insertions(+), 6 deletions(-)

--
2.27.0