virtio-mmio : fix the crash in the vm shutdown
PATCH 1/1 virtio-mmio : fix the crash in the vm shutdown
The root cause for this crash is the ioeventfd not stopped while the VM stop. The callback for vmstate_change was not implement in virtio-mmio bus
Reproduce step
load the vm with
-M microvm \
-netdev tap,id=net0,vhostforce,script=no,downscript=no \
-device virtio-net-device,netdev=net0\
After the VM boot, login the vm and then shutdown the vm
System will crash
[Current thread is 1 (Thread 0x7ffff6edde00 (LWP 374378))] (gdb) bt
0 0x00005555558f18b4 in qemu_flush_or_purge_queued_packets (purge=false, nc=0x55500252e850) at ../net/net.c:636 1 qemu_flush_queued_packets (nc=0x55500252e850) at ../net/net.c:656 2 0x0000555555b6c363 in virtio_queue_notify_vq (vq=0x7fffe7e2b010) at ../hw/virtio/virtio.c:2339 3 virtio_queue_host_notifier_read (n=0x7fffe7e2b08c) at ../hw/virtio/virtio.c:3583 4 0x0000555555de7b5a in aio_dispatch_handler (ctx=ctx@entry=0x5555567c5780, node=0x555556b83fd0) at ../util/aio-posix.c:329 5 0x0000555555de8454 in aio_dispatch_ready_handlers (ready_list=<optimized out>, ctx=<optimized out>) at ../util/aio-posix.c:359 6 aio_poll (ctx=0x5555567c5780, blocking=blocking@entry=false) at ../util/aio-posix.c:662 7 0x0000555555cce0cc in monitor_cleanup () at ../monitor/monitor.c:645 8 0x0000555555b06bd2 in qemu_cleanup () at ../softmmu/runstate.c:822 9 0x000055555586e693 in main (argc=<optimized out>, argv=<optimized out>, envp=<optimized out>) at ../softmmu/main.c:51
--- hw/virtio/virtio-mmio.c | 12 ++++++++++++ 1 file changed, 12 insertions(+)
hw/virtio/virtio-mmio.c +12 -0
@@ -817,6 +817,17 @@ static char *virtio_mmio_bus_get_dev_path(DeviceState *dev)return path; } +static void virtio_mmio_vmstate_change (DeviceState *d,bool running) +{ +VirtIOMMIOProxy *proxy =VIRTIO_MMIO (d); + +if (running) { +virtio_mmio_start_ioeventfd (proxy); + }else { +virtio_mmio_stop_ioeventfd (proxy); + } +} +static void virtio_mmio_bus_class_init (ObjectClass *klass,void *data) {BusClass *bus_class =BUS_CLASS (klass);
@@ -832,6 +843,7 @@ static void virtio_mmio_bus_class_init(ObjectClass *klass, void *data) k->ioeventfd_enabled = virtio_mmio_ioeventfd_enabled; k->ioeventfd_assign = virtio_mmio_ioeventfd_assign; k->pre_plugged = virtio_mmio_pre_plugged; + k->vmstate_change = virtio_mmio_vmstate_change; k->has_variable_vring_alignment = true; bus_class->max_dev =1 ; bus_class->get_dev_path = virtio_mmio_bus_get_dev_path;
Signature · 1 line
2.21.3
Quoted 26 lines · Cindy Lu
The root cause for this crash is the ioeventfd not stopped while the VM stop. The callback for
vmstate_changewas not implement in virtio-mmio busReproduce step
load the vm with
-M microvm \
-netdev tap,id=net0,vhostforce,script=no,downscript=no \
-device virtio-net-device,netdev=net0\After the VM boot, login the vm and then shutdown the vm
System will crash
[Current thread is 1 (Thread0x7ffff6edde00(LWP 374378))] (gdb) bt0 0x00005555558f18b4 in qemu_flush_or_purge_queued_packets (purge=false, nc=0x55500252e850) at ../net/net.c:636 1 qemu_flush_queued_packets (nc=0x55500252e850) at ../net/net.c:656 2 0x0000555555b6c363 in virtio_queue_notify_vq (vq=0x7fffe7e2b010) at ../hw/virtio/virtio.c:2339 3 virtio_queue_host_notifier_read (n=0x7fffe7e2b08c) at ../hw/virtio/virtio.c:3583 4 0x0000555555de7b5a in aio_dispatch_handler (ctx=ctx@entry=0x5555567c5780, node=0x555556b83fd0) at ../util/aio-posix.c:329 5 0x0000555555de8454 in aio_dispatch_ready_handlers (ready_list=<optimized out>, ctx=<optimized out>) at ../util/aio-posix.c:359 6 aio_poll (ctx=0x5555567c5780, blocking=blocking@entry=false) at ../util/aio-posix.c:662 7 0x0000555555cce0cc in monitor_cleanup () at ../monitor/monitor.c:645 8 0x0000555555b06bd2 in qemu_cleanup () at ../softmmu/runstate.c:822 9 0x000055555586e693 in main (argc=<optimized out>, argv=<optimized out>, envp=<optimized out>) at ../softmmu/main.c:51
Quoted 2 lines
Signed-off-by Cindy Lu <[email protected]>---
Thanks
Quoted 36 lines
hw/virtio/virtio-mmio.c | 12 ++++++++++++ 1 file changed, 12 insertions(+)hw/virtio/virtio-mmio.c +12
-1@@ -817,6 +817,17 @@ static char *virtio_mmio_bus_get_dev_path(DeviceState *dev)return path; } +static void virtio_mmio_vmstate_change (DeviceState *d,bool running) +{ +VirtIOMMIOProxy *proxy =VIRTIO_MMIO (d); + +if (running) { +virtio_mmio_start_ioeventfd (proxy); + }else { +virtio_mmio_stop_ioeventfd (proxy); + } +} +static void virtio_mmio_bus_class_init (ObjectClass *klass,void *data) {BusClass *bus_class =BUS_CLASS (klass);@@ -832,6 +843,7 @@ static void virtio_mmio_bus_class_init(ObjectClass *klass, void *data) k->ioeventfd_enabled = virtio_mmio_ioeventfd_enabled; k->ioeventfd_assign = virtio_mmio_ioeventfd_assign; k->pre_plugged = virtio_mmio_pre_plugged; + k->vmstate_change = virtio_mmio_vmstate_change; k->has_variable_vring_alignment = true; bus_class->max_dev =1 ; bus_class->get_dev_path = virtio_mmio_bus_get_dev_path; --2.21.3