On 2026/09/08 23:36, Stefan Hajnoczi wrote:
On Tue, Sep 08, 2026 at 03:11:18PM +0900, Akihiko Odaki wrote:
Introduce virtio_complete_reset() as preparation to allow asynchronous
reset. It is unconditionally called in virtio_reset(), but a follow-up
change moves the call to each device implementation.

Signed-off-by: Akihiko Odaki <[email protected]>
---
  include/hw/virtio/virtio.h |  1 +
  hw/virtio/virtio.c         | 14 +++++++++++---
  2 files changed, 12 insertions(+), 3 deletions(-)

diff --git a/include/hw/virtio/virtio.h b/include/hw/virtio/virtio.h
index c99cb19d8865..1431be1389f2 100644
--- a/include/hw/virtio/virtio.h
+++ b/include/hw/virtio/virtio.h
@@ -507,6 +507,7 @@ int virtio_queue_set_host_notifier_mr(VirtIODevice *vdev, 
int n,
                                        MemoryRegion *mr, bool assign);
  int virtio_set_status(VirtIODevice *vdev, uint8_t val);
  void virtio_reset(VirtIODevice *vdev);
+void virtio_complete_reset(VirtIODevice *vdev);
  void virtio_queue_reset(VirtIODevice *vdev, uint32_t queue_index);
  void virtio_queue_enable(VirtIODevice *vdev, uint32_t queue_index);
  void virtio_update_irq(VirtIODevice *vdev);
diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c
index daa5607338c9..8d5f58a02df6 100644
--- a/hw/virtio/virtio.c
+++ b/hw/virtio/virtio.c
@@ -3423,11 +3423,10 @@ int virtio_set_features_ex(VirtIODevice *vdev, const 
uint64_t *features)
  void virtio_reset(VirtIODevice *vdev)
  {
      VirtioDeviceClass *k = VIRTIO_DEVICE_GET_CLASS(vdev);
-    VirtioSharedMemory *shmem;
-    uint64_t features[VIRTIO_FEATURES_NU64S];
-    int i;
virtio_set_status(vdev, 0);
+    vdev->status = VIRTIO_CONFIG_S_FAILED;

Why is the VIRTIO Device Status Register set to FAILED during reset?
I don't see this in the VIRTIO specification.

The intent is to keep the status nonzero until virtio_complete_reset() finishes the reset. Any bit would work, but I chose FAILED because it looks saner than other options; the bit indicates that the guest is not going to interact with the device until the reset completes, which is indeed the case.

Regards,
Akihiko Odaki


+
      if (current_cpu) {
          /* Guest initiated reset */
          vdev->device_endian = virtio_current_cpu_endian();
@@ -3448,6 +3447,15 @@ void virtio_reset(VirtIODevice *vdev)
          k->reset(vdev);
      }
+ virtio_complete_reset(vdev);
+}
+
+void virtio_complete_reset(VirtIODevice *vdev)
+{
+    VirtioSharedMemory *shmem;
+    uint64_t features[VIRTIO_FEATURES_NU64S];
+    int i;
+
      vdev->start_on_kick = false;
      vdev->started = false;
      vdev->broken = false;

--
2.55.0



Reply via email to