thebeanogamer / rpms / qemu-kvm

Forked from rpms/qemu-kvm 5 months ago
Clone
0727d3
From c9b51d54530c526f14ca0f3b9fc0bfa0b60d45ee Mon Sep 17 00:00:00 2001
0727d3
From: Si-Wei Liu <si-wei.liu@oracle.com>
0727d3
Date: Fri, 6 May 2022 19:28:18 -0700
0727d3
Subject: [PATCH 20/24] virtio-net: don't handle mq request in userspace
0727d3
 handler for vhost-vdpa
0727d3
MIME-Version: 1.0
0727d3
Content-Type: text/plain; charset=UTF-8
0727d3
Content-Transfer-Encoding: 8bit
0727d3
0727d3
RH-Author: Jason Wang <jasowang@redhat.com>
0727d3
RH-MergeRequest: 187: Multiqueue fixes for vhost-vDPA
0727d3
RH-Commit: [7/7] 0e6684d12e42752deae8f5ebc56456fed174e0ed
0727d3
RH-Bugzilla: 2069946
0727d3
RH-Acked-by: Eugenio PĂ©rez <eperezma@redhat.com>
0727d3
RH-Acked-by: Cindy Lu <lulu@redhat.com>
0727d3
RH-Acked-by: Laurent Vivier <lvivier@redhat.com>
0727d3
0727d3
virtio_queue_host_notifier_read() tends to read pending event
0727d3
left behind on ioeventfd in the vhost_net_stop() path, and
0727d3
attempts to handle outstanding kicks from userspace vq handler.
0727d3
However, in the ctrl_vq handler, virtio_net_handle_mq() has a
0727d3
recursive call into virtio_net_set_status(), which may lead to
0727d3
segmentation fault as shown in below stack trace:
0727d3
0727d3
0  0x000055f800df1780 in qdev_get_parent_bus (dev=0x0) at ../hw/core/qdev.c:376
0727d3
1  0x000055f800c68ad8 in virtio_bus_device_iommu_enabled (vdev=vdev@entry=0x0) at ../hw/virtio/virtio-bus.c:331
0727d3
2  0x000055f800d70d7f in vhost_memory_unmap (dev=<optimized out>) at ../hw/virtio/vhost.c:318
0727d3
3  0x000055f800d70d7f in vhost_memory_unmap (dev=<optimized out>, buffer=0x7fc19bec5240, len=2052, is_write=1, access_len=2052) at ../hw/virtio/vhost.c:336
0727d3
4  0x000055f800d71867 in vhost_virtqueue_stop (dev=dev@entry=0x55f8037ccc30, vdev=vdev@entry=0x55f8044ec590, vq=0x55f8037cceb0, idx=0) at ../hw/virtio/vhost.c:1241
0727d3
5  0x000055f800d7406c in vhost_dev_stop (hdev=hdev@entry=0x55f8037ccc30, vdev=vdev@entry=0x55f8044ec590) at ../hw/virtio/vhost.c:1839
0727d3
6  0x000055f800bf00a7 in vhost_net_stop_one (net=0x55f8037ccc30, dev=0x55f8044ec590) at ../hw/net/vhost_net.c:315
0727d3
7  0x000055f800bf0678 in vhost_net_stop (dev=dev@entry=0x55f8044ec590, ncs=0x55f80452bae0, data_queue_pairs=data_queue_pairs@entry=7, cvq=cvq@entry=1)
0727d3
   at ../hw/net/vhost_net.c:423
0727d3
8  0x000055f800d4e628 in virtio_net_set_status (status=<optimized out>, n=0x55f8044ec590) at ../hw/net/virtio-net.c:296
0727d3
9  0x000055f800d4e628 in virtio_net_set_status (vdev=vdev@entry=0x55f8044ec590, status=15 '\017') at ../hw/net/virtio-net.c:370
0727d3
10 0x000055f800d534d8 in virtio_net_handle_ctrl (iov_cnt=<optimized out>, iov=<optimized out>, cmd=0 '\000', n=0x55f8044ec590) at ../hw/net/virtio-net.c:1408
0727d3
11 0x000055f800d534d8 in virtio_net_handle_ctrl (vdev=0x55f8044ec590, vq=0x7fc1a7e888d0) at ../hw/net/virtio-net.c:1452
0727d3
12 0x000055f800d69f37 in virtio_queue_host_notifier_read (vq=0x7fc1a7e888d0) at ../hw/virtio/virtio.c:2331
0727d3
13 0x000055f800d69f37 in virtio_queue_host_notifier_read (n=n@entry=0x7fc1a7e8894c) at ../hw/virtio/virtio.c:3575
0727d3
14 0x000055f800c688e6 in virtio_bus_cleanup_host_notifier (bus=<optimized out>, n=n@entry=14) at ../hw/virtio/virtio-bus.c:312
0727d3
15 0x000055f800d73106 in vhost_dev_disable_notifiers (hdev=hdev@entry=0x55f8035b51b0, vdev=vdev@entry=0x55f8044ec590)
0727d3
   at ../../../include/hw/virtio/virtio-bus.h:35
0727d3
16 0x000055f800bf00b2 in vhost_net_stop_one (net=0x55f8035b51b0, dev=0x55f8044ec590) at ../hw/net/vhost_net.c:316
0727d3
17 0x000055f800bf0678 in vhost_net_stop (dev=dev@entry=0x55f8044ec590, ncs=0x55f80452bae0, data_queue_pairs=data_queue_pairs@entry=7, cvq=cvq@entry=1)
0727d3
   at ../hw/net/vhost_net.c:423
0727d3
18 0x000055f800d4e628 in virtio_net_set_status (status=<optimized out>, n=0x55f8044ec590) at ../hw/net/virtio-net.c:296
0727d3
19 0x000055f800d4e628 in virtio_net_set_status (vdev=0x55f8044ec590, status=15 '\017') at ../hw/net/virtio-net.c:370
0727d3
20 0x000055f800d6c4b2 in virtio_set_status (vdev=0x55f8044ec590, val=<optimized out>) at ../hw/virtio/virtio.c:1945
0727d3
21 0x000055f800d11d9d in vm_state_notify (running=running@entry=false, state=state@entry=RUN_STATE_SHUTDOWN) at ../softmmu/runstate.c:333
0727d3
22 0x000055f800d04e7a in do_vm_stop (state=state@entry=RUN_STATE_SHUTDOWN, send_stop=send_stop@entry=false) at ../softmmu/cpus.c:262
0727d3
23 0x000055f800d04e99 in vm_shutdown () at ../softmmu/cpus.c:280
0727d3
24 0x000055f800d126af in qemu_cleanup () at ../softmmu/runstate.c:812
0727d3
25 0x000055f800ad5b13 in main (argc=<optimized out>, argv=<optimized out>, envp=<optimized out>) at ../softmmu/main.c:51
0727d3
0727d3
For now, temporarily disable handling MQ request from the ctrl_vq
0727d3
userspace hanlder to avoid the recursive virtio_net_set_status()
0727d3
call. Some rework is needed to allow changing the number of
0727d3
queues without going through a full virtio_net_set_status cycle,
0727d3
particularly for vhost-vdpa backend.
0727d3
0727d3
This patch will need to be reverted as soon as future patches of
0727d3
having the change of #queues handled in userspace is merged.
0727d3
0727d3
Fixes: 402378407db ("vhost-vdpa: multiqueue support")
0727d3
Signed-off-by: Si-Wei Liu <si-wei.liu@oracle.com>
0727d3
Acked-by: Jason Wang <jasowang@redhat.com>
0727d3
Message-Id: <1651890498-24478-8-git-send-email-si-wei.liu@oracle.com>
0727d3
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
0727d3
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
0727d3
(cherry picked from commit 2a7888cc3aa31faee839fa5dddad354ff8941f4c)
0727d3
Signed-off-by: Jason Wang <jasowang@redhat.com>
0727d3
---
0727d3
 hw/net/virtio-net.c | 13 +++++++++++++
0727d3
 1 file changed, 13 insertions(+)
0727d3
0727d3
diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c
0727d3
index f118379bb4..7e172ef829 100644
0727d3
--- a/hw/net/virtio-net.c
0727d3
+++ b/hw/net/virtio-net.c
0727d3
@@ -1373,6 +1373,7 @@ static int virtio_net_handle_mq(VirtIONet *n, uint8_t cmd,
0727d3
 {
0727d3
     VirtIODevice *vdev = VIRTIO_DEVICE(n);
0727d3
     uint16_t queue_pairs;
0727d3
+    NetClientState *nc = qemu_get_queue(n->nic);
0727d3
 
0727d3
     virtio_net_disable_rss(n);
0727d3
     if (cmd == VIRTIO_NET_CTRL_MQ_HASH_CONFIG) {
0727d3
@@ -1404,6 +1405,18 @@ static int virtio_net_handle_mq(VirtIONet *n, uint8_t cmd,
0727d3
         return VIRTIO_NET_ERR;
0727d3
     }
0727d3
 
0727d3
+    /* Avoid changing the number of queue_pairs for vdpa device in
0727d3
+     * userspace handler. A future fix is needed to handle the mq
0727d3
+     * change in userspace handler with vhost-vdpa. Let's disable
0727d3
+     * the mq handling from userspace for now and only allow get
0727d3
+     * done through the kernel. Ripples may be seen when falling
0727d3
+     * back to userspace, but without doing it qemu process would
0727d3
+     * crash on a recursive entry to virtio_net_set_status().
0727d3
+     */
0727d3
+    if (nc->peer && nc->peer->info->type == NET_CLIENT_DRIVER_VHOST_VDPA) {
0727d3
+        return VIRTIO_NET_ERR;
0727d3
+    }
0727d3
+
0727d3
     n->curr_queue_pairs = queue_pairs;
0727d3
     /* stop the backend before changing the number of queue_pairs to avoid handling a
0727d3
      * disabled queue */
0727d3
-- 
0727d3
2.35.3
0727d3