[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 59/91] hw/virtio: Fix the de-initialization of vhost-user devices
From: |
Michael S. Tsirkin |
Subject: |
[PULL 59/91] hw/virtio: Fix the de-initialization of vhost-user devices |
Date: |
Tue, 2 Jul 2024 10:10:00 -0400 |
From: Thomas Huth <thuth@redhat.com>
The unrealize functions of the various vhost-user devices are
calling the corresponding vhost_*_set_status() functions with a
status of 0 to shut down the device correctly.
Now these vhost_*_set_status() functions all follow this scheme:
bool should_start = virtio_device_should_start(vdev, status);
if (vhost_dev_is_started(&vvc->vhost_dev) == should_start) {
return;
}
if (should_start) {
/* ... do the initialization stuff ... */
} else {
/* ... do the cleanup stuff ... */
}
The problem here is virtio_device_should_start(vdev, 0) currently
always returns "true" since it internally only looks at vdev->started
instead of looking at the "status" parameter. Thus once the device
got started once, virtio_device_should_start() always returns true
and thus the vhost_*_set_status() functions return early, without
ever doing any clean-up when being called with status == 0. This
causes e.g. problems when trying to hot-plug and hot-unplug a vhost
user devices multiple times since the de-initialization step is
completely skipped during the unplug operation.
This bug has been introduced in commit 9f6bcfd99f ("hw/virtio: move
vm_running check to virtio_device_started") which replaced
should_start = status & VIRTIO_CONFIG_S_DRIVER_OK;
with
should_start = virtio_device_started(vdev, status);
which later got replaced by virtio_device_should_start(). This blocked
the possibility to set should_start to false in case the status flag
VIRTIO_CONFIG_S_DRIVER_OK was not set.
Fix it by adjusting the virtio_device_should_start() function to
only consider the status flag instead of vdev->started. Since this
function is only used in the various vhost_*_set_status() functions
for exactly the same purpose, it should be fine to fix it in this
central place there without any risk to change the behavior of other
code.
Fixes: 9f6bcfd99f ("hw/virtio: move vm_running check to virtio_device_started")
Buglink: https://issues.redhat.com/browse/RHEL-40708
Signed-off-by: Thomas Huth <thuth@redhat.com>
Message-Id: <20240618121958.88673-1-thuth@redhat.com>
Reviewed-by: Manos Pitsidianakis <manos.pitsidianakis@linaro.org>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
include/hw/virtio/virtio.h | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/include/hw/virtio/virtio.h b/include/hw/virtio/virtio.h
index 1451926a13..7512afbc84 100644
--- a/include/hw/virtio/virtio.h
+++ b/include/hw/virtio/virtio.h
@@ -472,9 +472,9 @@ static inline bool virtio_device_started(VirtIODevice
*vdev, uint8_t status)
* @vdev - the VirtIO device
* @status - the devices status bits
*
- * This is similar to virtio_device_started() but also encapsulates a
- * check on the VM status which would prevent a device starting
- * anyway.
+ * This is similar to virtio_device_started() but ignores vdev->started
+ * and also encapsulates a check on the VM status which would prevent a
+ * device from starting anyway.
*/
static inline bool virtio_device_should_start(VirtIODevice *vdev, uint8_t
status)
{
@@ -482,7 +482,7 @@ static inline bool virtio_device_should_start(VirtIODevice
*vdev, uint8_t status
return false;
}
- return virtio_device_started(vdev, status);
+ return status & VIRTIO_CONFIG_S_DRIVER_OK;
}
static inline void virtio_set_started(VirtIODevice *vdev, bool started)
--
MST
- [PULL 50/91] vhost-user-server: do not set memory fd non-blocking, (continued)
- [PULL 50/91] vhost-user-server: do not set memory fd non-blocking, Michael S. Tsirkin, 2024/07/02
- [PULL 49/91] libvhost-user: mask F_INFLIGHT_SHMFD if memfd is not supported, Michael S. Tsirkin, 2024/07/02
- [PULL 51/91] contrib/vhost-user-blk: fix bind() using the right size of the address, Michael S. Tsirkin, 2024/07/02
- [PULL 52/91] contrib/vhost-user-*: use QEMU bswap helper functions, Michael S. Tsirkin, 2024/07/02
- [PULL 54/91] libvhost-user: enable it on any POSIX system, Michael S. Tsirkin, 2024/07/02
- [PULL 55/91] contrib/vhost-user-blk: enable it on any POSIX system, Michael S. Tsirkin, 2024/07/02
- [PULL 53/91] vhost-user: enable frontends on any POSIX system, Michael S. Tsirkin, 2024/07/02
- [PULL 56/91] hostmem: add a new memory backend based on POSIX shm_open(), Michael S. Tsirkin, 2024/07/02
- [PULL 58/91] tests/qtest/vhost-user-test: add a test case for memory-backend-shm, Michael S. Tsirkin, 2024/07/02
- [PULL 57/91] tests/qtest/vhost-user-blk-test: use memory-backend-shm, Michael S. Tsirkin, 2024/07/02
- [PULL 59/91] hw/virtio: Fix the de-initialization of vhost-user devices,
Michael S. Tsirkin <=
- [PULL 60/91] hw/arm/virt-acpi-build: Drop local iort_node_offset, Michael S. Tsirkin, 2024/07/02
- [PULL 61/91] hw/i386/fw_cfg: Add etc/e820 to fw_cfg late, Michael S. Tsirkin, 2024/07/02
- [PULL 62/91] hw/arm/virt-acpi-build: Fix id_count in build_iort_id_mapping, Michael S. Tsirkin, 2024/07/02
- [PULL 63/91] uefi-test-tools/UefiTestToolsPkg: Add RISC-V support, Michael S. Tsirkin, 2024/07/02
- [PULL 30/91] linux-headers: update to 6.10-rc1, Michael S. Tsirkin, 2024/07/02
- [PULL 66/91] qtest: bios-tables-test: Rename aarch64 tests with aarch64 in them, Michael S. Tsirkin, 2024/07/02
- [PULL 64/91] uefi-test-tools: Add support for python based build script, Michael S. Tsirkin, 2024/07/02
- [PULL 67/91] tests/qtest/bios-tables-test.c: Add support for arch in path, Michael S. Tsirkin, 2024/07/02
- [PULL 70/91] tests/data/acpi: Move x86 ACPI tables under x86/${machine} path, Michael S. Tsirkin, 2024/07/02
- [PULL 71/91] tests/data/acpi/virt: Move ARM64 ACPI tables under aarch64/${machine} path, Michael S. Tsirkin, 2024/07/02