qemu/hw/block
Stefan Hajnoczi 75dcb4d790 virtio-blk: fix host notifier issues during dataplane start/stop
The main loop thread can consume 100% CPU when using --device
virtio-blk-pci,iothread=<iothread>. ppoll() constantly returns but
reading virtqueue host notifiers fails with EAGAIN. The file descriptors
are stale and remain registered with the AioContext because of bugs in
the virtio-blk dataplane start/stop code.

The problem is that the dataplane start/stop code involves drain
operations, which call virtio_blk_drained_begin() and
virtio_blk_drained_end() at points where the host notifier is not
operational:
- In virtio_blk_data_plane_start(), blk_set_aio_context() drains after
  vblk->dataplane_started has been set to true but the host notifier has
  not been attached yet.
- In virtio_blk_data_plane_stop(), blk_drain() and blk_set_aio_context()
  drain after the host notifier has already been detached but with
  vblk->dataplane_started still set to true.

I would like to simplify ->ioeventfd_start/stop() to avoid interactions
with drain entirely, but couldn't find a way to do that. Instead, this
patch accepts the fragile nature of the code and reorders it so that
vblk->dataplane_started is false during drain operations. This way the
virtio_blk_drained_begin() and virtio_blk_drained_end() calls don't
touch the host notifier. The result is that
virtio_blk_data_plane_start() and virtio_blk_data_plane_stop() have
complete control over the host notifier and stale file descriptors are
no longer left in the AioContext.

This patch fixes the 100% CPU consumption in the main loop thread and
correctly moves host notifier processing to the IOThread.

Fixes: 1665d9326f ("virtio-blk: implement BlockDevOps->drained_begin()")
Reported-by: Lukáš Doktor <ldoktor@redhat.com>
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
Tested-by: Lukas Doktor <ldoktor@redhat.com>
Message-id: 20230704151527.193586-1-stefanha@redhat.com
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
2023-07-12 15:20:32 -04:00
..
dataplane virtio-blk: fix host notifier issues during dataplane start/stop 2023-07-12 15:20:32 -04:00
block.c pflash: Fix blk_pread_nonzeroes() 2023-03-07 16:53:18 +01:00
cdrom.c
ecc.c vmstate: Constify some VMStateDescriptions 2021-05-02 17:24:50 +02:00
fdc-internal.h hw/block/fdc: Declare shared prototypes in fdc-internal.h 2021-06-25 08:53:28 -04:00
fdc-isa.c hw: Replace isa_get_irq() by isa_bus_get_irq() when ISABus is available 2023-02-27 22:29:02 +01:00
fdc-sysbus.c hw/block/fdc-sysbus: Always mark sysbus floppy controllers as not having DMA 2022-06-11 11:36:14 +02:00
fdc.c hw/block: replace TABs with space 2023-03-24 11:45:46 +01:00
hd-geometry.c hw/block/hd-geometry: Do not override specified bios-chs-trans 2022-08-02 11:21:56 +02:00
Kconfig hw/block/fdc: Extract SysBus floppy controllers to fdc-sysbus.c 2021-06-25 08:53:28 -04:00
m25p80.c m25p80: Improve error when the backend file size does not match the device 2023-03-07 16:53:18 +01:00
m25p80_sfdp.c m25p80: Add the is25wp256 SFPD table 2023-02-07 09:02:04 +01:00
m25p80_sfdp.h m25p80: Add the is25wp256 SFPD table 2023-02-07 09:02:04 +01:00
meson.build meson: Replace softmmu_ss -> system_ss 2023-06-20 10:01:30 +02:00
nand.c hw/block: replace TABs with space 2023-03-24 11:45:46 +01:00
onenand.c hw/block: replace TABs with space 2023-03-24 11:45:46 +01:00
pflash_cfi01.c Drop duplicate #include 2023-02-08 07:28:05 +01:00
pflash_cfi02.c Revert "hw/block/pflash_cfi: Error out if dev length isn't power of 2" 2022-11-08 15:53:40 -05:00
swim.c qbus: Rename qbus_create_inplace() to qbus_init() 2021-09-30 13:42:10 +01:00
tc58128.c hw/block: replace TABs with space 2023-03-24 11:45:46 +01:00
trace-events virtio-blk: add some trace events for zoned emulation 2023-05-15 08:18:10 -04:00
trace.h
vhost-user-blk.c vhost-user: fully use new backend/frontend naming 2023-06-26 09:50:00 -04:00
virtio-blk-common.c virtio-blk: add zoned storage emulation for zoned devices 2023-05-15 08:18:10 -04:00
virtio-blk.c block: add blk_io_plug_call() API 2023-06-01 07:34:03 -04:00
xen-block.c xen-block: implement BlockDevOps->drained_begin() 2023-05-30 17:32:02 +02:00
xen_blkif.h