[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 63/63] virtio: Always reset vhost devices
From: |
Michael S. Tsirkin |
Subject: |
[PULL 63/63] virtio: Always reset vhost devices |
Date: |
Sun, 21 Jul 2024 20:19:04 -0400 |
From: Hanna Czenczek <hreitz@redhat.com>
Requiring `vhost_started` to be true for resetting vhost devices in
`virtio_reset()` seems like the wrong condition: Most importantly, the
preceding `virtio_set_status(vdev, 0)` call will (for vhost devices) end
up in `vhost_dev_stop()` (through vhost devices' `.set_status`
implementations), setting `vdev->vhost_started = false`. Therefore, the
gated `vhost_reset_device()` call is unreachable.
`vhost_started` is not documented, so it is hard to say what exactly it
is supposed to mean, but judging from the fact that `vhost_dev_start()`
sets it and `vhost_dev_stop()` clears it, it seems like it indicates
whether there is a vhost back-end, and whether that back-end is
currently running and processing virtio requests.
Making a reset conditional on whether the vhost back-end is processing
virtio requests seems wrong; in fact, it is probably better to reset it
only when it is not currently processing requests, which is exactly the
current order of operations in `virtio_reset()`: First, the back-end is
stopped through `virtio_set_status(vdev, 0)`, then we want to send a
reset.
Therefore, we should drop the `vhost_started` condition, but in its
stead we then have to verify that we can indeed send a reset to this
vhost device, by not just checking `k->get_vhost != NULL` (introduced by
commit 95e1019a4a9), but also that the vhost back-end is connected
(`hdev = k->get_vhost(); hdev != NULL && hdev->vhost_ops != NULL`).
Signed-off-by: Hanna Czenczek <hreitz@redhat.com>
Message-Id: <20240710112310.316551-1-hreitz@redhat.com>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
hw/virtio/virtio.c | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c
index 397c261c3c..624fdcae91 100644
--- a/hw/virtio/virtio.c
+++ b/hw/virtio/virtio.c
@@ -2275,8 +2275,12 @@ void virtio_reset(void *opaque)
vdev->device_endian = virtio_default_endian();
}
- if (vdev->vhost_started && k->get_vhost) {
- vhost_reset_device(k->get_vhost(vdev));
+ if (k->get_vhost) {
+ struct vhost_dev *hdev = k->get_vhost(vdev);
+ /* Only reset when vhost back-end is connected */
+ if (hdev && hdev->vhost_ops) {
+ vhost_reset_device(hdev);
+ }
}
if (k->reset) {
--
MST
- [PULL 51/63] hw/riscv/virt-acpi-build.c: Add namespace devices for PLIC and APLIC, (continued)
- [PULL 51/63] hw/riscv/virt-acpi-build.c: Add namespace devices for PLIC and APLIC, Michael S. Tsirkin, 2024/07/21
- [PULL 52/63] hw/riscv/virt-acpi-build.c: Update the HID of RISC-V UART, Michael S. Tsirkin, 2024/07/21
- [PULL 43/63] physmem: Add helper function to destroy CPU AddressSpace, Michael S. Tsirkin, 2024/07/21
- [PULL 48/63] virtio-iommu: Remove the end point on detach, Michael S. Tsirkin, 2024/07/21
- [PULL 61/63] backends: Initial support for SPDM socket support, Michael S. Tsirkin, 2024/07/21
- [PULL 54/63] acpi/gpex: Create PCI link devices outside PCI root bridge, Michael S. Tsirkin, 2024/07/21
- [PULL 53/63] tests/acpi: Allow DSDT acpi table changes for aarch64, Michael S. Tsirkin, 2024/07/21
- [PULL 58/63] tests/qtest/bios-tables-test.c: Enable basic testing for RISC-V, Michael S. Tsirkin, 2024/07/21
- [PULL 60/63] hw/pci: Add all Data Object Types defined in PCIe r6.0, Michael S. Tsirkin, 2024/07/21
- [PULL 59/63] tests/acpi: Add expected ACPI AML files for RISC-V, Michael S. Tsirkin, 2024/07/21
- [PULL 63/63] virtio: Always reset vhost devices,
Michael S. Tsirkin <=
- [PULL 57/63] tests/acpi: Add empty ACPI data files for RISC-V, Michael S. Tsirkin, 2024/07/21
- [PULL 62/63] hw/nvme: Add SPDM over DOE support, Michael S. Tsirkin, 2024/07/21
- [PULL 56/63] tests/qtest/bios-tables-test.c: Remove the fall back path, Michael S. Tsirkin, 2024/07/21
- Re: [PULL 00/63] virtio,pci,pc: features,fixes, Richard Henderson, 2024/07/22
- Re: [PULL 00/63] virtio,pci,pc: features,fixes, Michael S. Tsirkin, 2024/07/22
- Re: [PULL 00/63] virtio,pci,pc: features,fixes, Richard Henderson, 2024/07/22
- Re: [PULL 00/63] virtio,pci,pc: features,fixes, Michael S. Tsirkin, 2024/07/23
- Re: [PULL 00/63] virtio,pci,pc: features,fixes, Hanna Czenczek, 2024/07/23
- Re: [PULL 00/63] virtio,pci,pc: features,fixes, Michael S. Tsirkin, 2024/07/23
- Re: [PULL 00/63] virtio,pci,pc: features,fixes, Hanna Czenczek, 2024/07/23