qemu/hw/virtio
yaozhenguo 963b027645 virtio/vhost-user: fix qemu abort when hotunplug vhost-user-net device
During the hot-unplugging of vhost-user-net type network cards,
the vhost_user_cleanup function may add the same rcu node to
the rcu linked list. The function call in this case is as follows:

vhost_user_cleanup
    ->vhost_user_host_notifier_remove
        ->call_rcu(n, vhost_user_host_notifier_free, rcu);
    ->g_free_rcu(n, rcu);

When this happens, QEMU will abort in try_dequeue:

if (head == &dummy && qatomic_mb_read(&tail) == &dummy.next) {
    abort();
}

backtrace is as follows:
0  __pthread_kill_implementation () at /usr/lib64/libc.so.6
1  raise () at /usr/lib64/libc.so.6
2  abort () at /usr/lib64/libc.so.6
3  try_dequeue () at ../util/rcu.c:235
4  call_rcu_thread (0) at ../util/rcu.c:288
5  qemu_thread_start (0) at ../util/qemu-thread-posix.c:541
6  start_thread () at /usr/lib64/libc.so.6
7  clone3 () at /usr/lib64/libc.so.6

The reason for the abort is that adding two identical nodes to
the rcu linked list will cause the rcu linked list to become a ring,
but when the dummy node is added after the two identical nodes,
the ring is opened. But only one node is added to list with
rcu_call_count added twice. This will cause rcu try_dequeue abort.

This happens when n->addr != 0. In some scenarios, this does happen.
For example, this situation will occur when using a 32-queue DPU
vhost-user-net type network card for hot-unplug testing, because
VhostUserHostNotifier->addr will be cleared during the processing of
VHOST_USER_BACKEND_VRING_HOST_NOTIFIER_MSG. However,it is asynchronous,
so we cannot guarantee that VhostUserHostNotifier->addr is zero in
vhost_user_cleanup. Therefore, it is necessary to merge g_free_rcu
and vhost_user_host_notifier_free into one rcu node.

Fixes: 503e355465 ("virtio/vhost-user: dynamically assign VhostUserHostNotifiers")
Signed-off-by: yaozhenguo <yaozhenguo@jd.com>
Message-Id: <20241011102913.45582-1-yaozhenguo@jd.com>
Reviewed-by: Stefano Garzarella <sgarzare@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
2024-11-04 16:03:24 -05:00
..
Kconfig Hi, 2024-09-26 17:10:39 +01:00
meson.build hw/virtio: move stubs out of stubs/ 2024-04-18 11:17:27 +02:00
trace-events virtio-iommu: Add trace point on virtio_iommu_detach_endpoint_from_domain 2024-07-22 20:15:42 -04:00
trace.h trace: switch position of headers to what Meson requires 2020-08-21 06:18:24 -04:00
vdpa-dev-pci.c vdpa: add vdpa-dev-pci support 2022-12-21 06:35:28 -05:00
vdpa-dev.c vdpa-dev: Fix the issue of device status not updating when configuration interruption is triggered 2024-04-09 02:31:27 -04:00
vhost-backend.c vhost: Add worker backend callouts 2023-12-25 11:34:55 -05:00
vhost-iova-tree.c util: accept iova_tree_remove_parameter by value 2022-09-02 10:22:39 +08:00
vhost-iova-tree.h util: accept iova_tree_remove_parameter by value 2022-09-02 10:22:39 +08:00
vhost-scsi-pci.c hw/virtio: move virtio-pci.h into shared include space 2022-05-16 04:38:40 -04:00
vhost-shadow-virtqueue.c hw/virtio: freeing leaked memory from vhost_svq_get_buf in vhost_svq_poll 2024-10-02 16:14:29 +04:00
vhost-shadow-virtqueue.h vhost: Expose vhost_svq_available_slots() 2023-10-18 10:41:50 -04:00
vhost-stub.c vhost: Add vhost_get_max_memslots() 2023-10-12 14:15:22 +02:00
vhost-user-base.c hw/virtio: Free vqs after vhost_dev_cleanup() 2024-07-01 17:16:05 -04:00
vhost-user-blk-pci.c hw/virtio: move virtio-pci.h into shared include space 2022-05-16 04:38:40 -04:00
vhost-user-device-pci.c virtio: split into vhost-user-base and vhost-user-device 2024-02-14 06:01:39 -05:00
vhost-user-device.c virtio: split into vhost-user-base and vhost-user-device 2024-02-14 06:01:39 -05:00
vhost-user-fs-pci.c hw/virtio: move virtio-pci.h into shared include space 2022-05-16 04:38:40 -04:00
vhost-user-fs.c vhost,vhost-user: Add VIRTIO_F_IN_ORDER to vhost feature bits 2024-07-21 14:45:56 -04:00
vhost-user-gpio-pci.c hw/virtio: add vhost-user-gpio-pci boilerplate 2022-10-07 09:41:51 -04:00
vhost-user-gpio.c hw/virtio: derive vhost-user-gpio from vhost-user-base 2024-02-14 06:01:44 -05:00
vhost-user-i2c-pci.c hw/virtio: move virtio-pci.h into shared include space 2022-05-16 04:38:40 -04:00
vhost-user-i2c.c hw/virtio: derive vhost-user-i2c from vhost-user-base 2024-02-14 06:01:49 -05:00
vhost-user-input-pci.c hw/virtio: derive vhost-user-input from vhost-user-base 2024-02-14 06:09:32 -05:00
vhost-user-input.c hw/virtio: derive vhost-user-input from vhost-user-base 2024-02-14 06:09:32 -05:00
vhost-user-rng-pci.c hw/virtio: move virtio-pci.h into shared include space 2022-05-16 04:38:40 -04:00
vhost-user-rng.c hw/virtio: derive vhost-user-rng from vhost-user-base 2024-02-14 06:01:42 -05:00
vhost-user-scmi-pci.c hw/virtio: Add vhost-user-scmi-pci boilerplate 2023-07-10 16:17:08 -04:00
vhost-user-scmi.c bulk: Access existing variables initialized to &S->F when available 2024-03-12 11:46:16 +01:00
vhost-user-scsi-pci.c hw/virtio: move virtio-pci.h into shared include space 2022-05-16 04:38:40 -04:00
vhost-user-snd-pci.c hw/virtio: add vhost-user-snd and vhost-user-snd-pci devices 2024-02-14 06:09:03 -05:00
vhost-user-snd.c hw/virtio: add vhost-user-snd and vhost-user-snd-pci devices 2024-02-14 06:09:03 -05:00
vhost-user-vsock-pci.c hw/virtio: move virtio-pci.h into shared include space 2022-05-16 04:38:40 -04:00
vhost-user-vsock.c vhost,vhost-user: Add VIRTIO_F_IN_ORDER to vhost feature bits 2024-07-21 14:45:56 -04:00
vhost-user.c virtio/vhost-user: fix qemu abort when hotunplug vhost-user-net device 2024-11-04 16:03:24 -05:00
vhost-vdpa.c util/hexdump: Add unit_len and block_len to qemu_hexdump_line 2024-06-05 12:14:18 -07:00
vhost-vsock-common.c vhost-vsock: add VIRTIO_F_RING_PACKED to feature_bits 2024-07-01 14:56:23 -04:00
vhost-vsock-pci.c hw/virtio: move virtio-pci.h into shared include space 2022-05-16 04:38:40 -04:00
vhost-vsock.c hw/virtio/vhost-vsock: Fix missing ERRP_GUARD() for error_prepend() 2024-03-12 11:45:45 +01:00
vhost.c vhost: Remove unused vhost_dev_{load|save}_inflight 2024-10-03 17:26:06 +03:00
virtio-9p-pci.c hw/virtio: move virtio-pci.h into shared include space 2022-05-16 04:38:40 -04:00
virtio-acpi.c license: Update deprecated SPDX tag GPL-2.0+ to GPL-2.0-or-later 2024-09-20 10:11:59 +03:00
virtio-balloon-pci.c hw/virtio: move virtio-pci.h into shared include space 2022-05-16 04:38:40 -04:00
virtio-balloon.c migration: remove migration.h references 2024-03-11 16:28:59 -04:00
virtio-blk-pci.c hw/virtio: move virtio-pci.h into shared include space 2022-05-16 04:38:40 -04:00
virtio-bus.c virtio: stop ioeventfd on reset 2022-06-14 16:50:30 +02:00
virtio-config-io.c hw/virtio: Extract config read/write accessors to virtio-config-io.c 2022-12-21 07:32:24 -05:00
virtio-crypto-pci.c Use DECLARE_*CHECKER* macros 2020-09-09 09:27:09 -04:00
virtio-crypto.c virtio,pc,pci: features, fixes, cleanups 2024-09-12 16:17:27 +01:00
virtio-hmp-cmds.c virtio: Move HMP commands from monitor/ to hw/virtio/ 2023-02-04 07:56:54 +01:00
virtio-input-host-pci.c hw/virtio: move virtio-pci.h into shared include space 2022-05-16 04:38:40 -04:00
virtio-input-pci.c virtio-input-pci: add virtio-multitouch-pci 2023-05-28 13:08:25 +04:00
virtio-iommu-pci.c hw/virtio: Free VirtIOIOMMUPCI::vdev.reserved_regions[] on finalize() 2023-11-27 15:27:41 +00:00
virtio-iommu.c virtio-iommu: Add trace point on virtio_iommu_detach_endpoint_from_domain 2024-07-22 20:15:42 -04:00
virtio-md-pci.c hw/mem/memory-device: Remove legacy_align from memory_device_pre_plug() 2024-06-19 12:40:49 +02:00
virtio-md-stubs.c hw/virtio: move stubs out of stubs/ 2024-04-18 11:17:27 +02:00
virtio-mem-pci.c virtio-mem: Expose device memory dynamically via multiple memslots if enabled 2023-10-12 14:15:22 +02:00
virtio-mem-pci.h virtio-md-pci: New parent type for virtio-mem-pci and virtio-pmem-pci 2023-07-12 09:27:25 +02:00
virtio-mem.c virtio-mem: Add support for suspend+wake-up with plugged memory 2024-09-24 11:33:35 +02:00
virtio-mmio.c hw: Use device_class_set_legacy_reset() instead of opencoding 2024-09-13 15:31:44 +01:00
virtio-net-pci.c Revert "virtio-net: Implement SR-IOV VF" 2024-08-01 04:32:00 -04:00
virtio-pci.c virtio-pci: fix memory_region_find for VirtIOPCIRegion's MR 2024-11-04 16:03:24 -05:00
virtio-pmem-pci.c virtio-md-pci: New parent type for virtio-mem-pci and virtio-pmem-pci 2023-07-12 09:27:25 +02:00
virtio-pmem-pci.h virtio-md-pci: New parent type for virtio-mem-pci and virtio-pmem-pci 2023-07-12 09:27:25 +02:00
virtio-pmem.c Revert "hw/virtio/virtio-pmem: Replace impossible check by assertion" 2023-11-06 13:53:59 +01:00
virtio-qmp.c virtio-mem: Add support for suspend+wake-up with plugged memory 2024-09-24 11:33:35 +02:00
virtio-qmp.h qmp: remove virtio_list, search QOM tree instead 2023-10-04 04:54:24 -04:00
virtio-rng-pci.c virtio-rng-pci: Allow setting nvectors, so we can use MSI-X 2022-11-07 13:12:20 -05:00
virtio-rng.c virtio-rng: block max-bytes=0 2024-08-01 04:32:00 -04:00
virtio-scsi-pci.c hw/virtio: move virtio-pci.h into shared include space 2022-05-16 04:38:40 -04:00
virtio-serial-pci.c hw/virtio: move virtio-pci.h into shared include space 2022-05-16 04:38:40 -04:00
virtio-stub.c qmp: add QMP command x-query-virtio-queue-element 2022-10-09 16:38:45 -04:00
virtio.c virtio: rename virtio_split_packed_update_used_idx 2024-09-11 09:46:05 -04:00