qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Si-Wei Liu <si-wei.liu@oracle.com>
To: qemu-devel@nongnu.org
Cc: si-wei.liu@oracle.com, eperezma@redhat.com, jasowang@redhat.com,
	eli@mellanox.com, mst@redhat.com
Subject: [PATCH 3/7] virtio-net: Only enable userland vq if using tap backend
Date: Tue, 29 Mar 2022 23:33:13 -0700	[thread overview]
Message-ID: <1648621997-22416-4-git-send-email-si-wei.liu@oracle.com> (raw)
In-Reply-To: <1648621997-22416-1-git-send-email-si-wei.liu@oracle.com>

From: Eugenio Pérez <eperezma@redhat.com>

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. Do not resort on them unless actually possible.

Signed-off-by: Eugenio Pérez <eperezma@redhat.com>
---
 hw/net/virtio-net.c        |  4 ++++
 hw/virtio/virtio.c         | 21 +++++++++++++--------
 include/hw/virtio/virtio.h |  2 ++
 3 files changed, 19 insertions(+), 8 deletions(-)

diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c
index ffaf481..9cdf777 100644
--- a/hw/net/virtio-net.c
+++ b/hw/net/virtio-net.c
@@ -3523,6 +3523,10 @@ 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_TAP) {
+        /* Only tap can use userspace networking */
+        vdev->disable_ioeventfd_handler = true;
+    }
     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);
diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c
index 9d637e0..806603b 100644
--- a/hw/virtio/virtio.c
+++ b/hw/virtio/virtio.c
@@ -3708,17 +3708,22 @@ static int virtio_device_start_ioeventfd_impl(VirtIODevice *vdev)
             err = r;
             goto assign_error;
         }
-        event_notifier_set_handler(&vq->host_notifier,
-                                   virtio_queue_host_notifier_read);
+
+        if (!vdev->disable_ioeventfd_handler) {
+            event_notifier_set_handler(&vq->host_notifier,
+                                       virtio_queue_host_notifier_read);
+        }
     }
 
-    for (n = 0; n < VIRTIO_QUEUE_MAX; n++) {
-        /* Kick right away to begin processing requests already in vring */
-        VirtQueue *vq = &vdev->vq[n];
-        if (!vq->vring.num) {
-            continue;
+    if (!vdev->disable_ioeventfd_handler) {
+        for (n = 0; n < VIRTIO_QUEUE_MAX; n++) {
+            /* Kick right away to begin processing requests already in vring */
+            VirtQueue *vq = &vdev->vq[n];
+            if (!vq->vring.num) {
+                continue;
+            }
+            event_notifier_set(&vq->host_notifier);
         }
-        event_notifier_set(&vq->host_notifier);
     }
     memory_region_transaction_commit();
     return 0;
diff --git a/include/hw/virtio/virtio.h b/include/hw/virtio/virtio.h
index b31c450..b6ce5f0 100644
--- a/include/hw/virtio/virtio.h
+++ b/include/hw/virtio/virtio.h
@@ -105,6 +105,8 @@ struct VirtIODevice
     VMChangeStateEntry *vmstate;
     char *bus_name;
     uint8_t device_endian;
+    /* backend does not support userspace handler */
+    bool disable_ioeventfd_handler;
     bool use_guest_notifier_mask;
     AddressSpace *dma_as;
     QLIST_HEAD(, VirtQueue) *vector_queues;
-- 
1.8.3.1



  parent reply	other threads:[~2022-03-30  6:51 UTC|newest]

Thread overview: 50+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-30  6:33 [PATCH 0/7] vhost-vdpa multiqueue fixes Si-Wei Liu
2022-03-30  6:33 ` [PATCH 1/7] virtio-net: align ctrl_vq index for non-mq guest for vhost_vdpa Si-Wei Liu
2022-03-30  9:00   ` Jason Wang
2022-03-30 15:47     ` Si-Wei Liu
2022-03-31  8:39       ` Jason Wang
2022-04-01 22:32         ` Si-Wei Liu
2022-04-02  2:10           ` Jason Wang
2022-04-05 23:26             ` Si-Wei Liu
2022-03-30  6:33 ` [PATCH 2/7] virtio-net: Fix indentation Si-Wei Liu
2022-03-30  9:01   ` Jason Wang
2022-03-30  6:33 ` Si-Wei Liu [this message]
2022-03-30  9:07   ` [PATCH 3/7] virtio-net: Only enable userland vq if using tap backend Jason Wang
2022-03-30  6:33 ` [PATCH 4/7] virtio: don't read pending event on host notifier if disabled Si-Wei Liu
2022-03-30  9:14   ` Jason Wang
2022-03-30 16:40     ` Si-Wei Liu
2022-03-31  8:36       ` Jason Wang
2022-04-01 20:37         ` Si-Wei Liu
2022-04-02  2:00           ` Jason Wang
2022-04-05 19:18             ` Si-Wei Liu
2022-04-07  7:05               ` Jason Wang
2022-04-08  1:02                 ` Si-Wei Liu
2022-04-11  8:49                   ` Jason Wang
2022-03-30  6:33 ` [PATCH 5/7] vhost-vdpa: fix improper cleanup in net_init_vhost_vdpa Si-Wei Liu
2022-03-30  9:15   ` Jason Wang
2022-03-30  6:33 ` [PATCH 6/7] vhost-net: fix improper cleanup in vhost_net_start Si-Wei Liu
2022-03-30  9:30   ` Jason Wang
2022-03-30  6:33 ` [PATCH 7/7] vhost-vdpa: backend feature should set only once Si-Wei Liu
2022-03-30  9:28   ` Jason Wang
2022-03-30 16:24   ` Stefano Garzarella
2022-03-30 17:12     ` Si-Wei Liu
2022-03-30 17:32       ` Stefano Garzarella
2022-03-30 18:27         ` Eugenio Perez Martin
2022-03-30 22:44           ` Si-Wei Liu
2022-03-30 19:01   ` Eugenio Perez Martin
2022-03-30 23:03     ` Si-Wei Liu
2022-03-31  8:02       ` Eugenio Perez Martin
2022-03-31  8:54         ` Jason Wang
2022-03-31  9:19           ` Eugenio Perez Martin
2022-04-01  2:39             ` Jason Wang
2022-04-01  4:18               ` Si-Wei Liu
2022-04-02  1:33                 ` Jason Wang
2022-03-31 21:15         ` Si-Wei Liu
2022-04-01  8:21           ` Eugenio Perez Martin
2022-04-27  4:28 ` [PATCH 0/7] vhost-vdpa multiqueue fixes Jason Wang
2022-04-27  8:29   ` Si-Wei Liu
2022-04-27  8:38     ` Jason Wang
2022-04-27  9:09       ` Si-Wei Liu
2022-04-29  2:30         ` Jason Wang
2022-04-30  2:07           ` Si-Wei Liu
2022-05-05  8:40             ` Jason Wang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1648621997-22416-4-git-send-email-si-wei.liu@oracle.com \
    --to=si-wei.liu@oracle.com \
    --cc=eli@mellanox.com \
    --cc=eperezma@redhat.com \
    --cc=jasowang@redhat.com \
    --cc=mst@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).