qemu-e2k/hw
Stefan Hajnoczi a937f8e857 virtio-blk: simplify virtio_blk_dma_restart_cb()
virtio_blk_dma_restart_cb() is tricky because the BH must deal with
virtio_blk_data_plane_start()/virtio_blk_data_plane_stop() being called.

There are two issues with the code:

1. virtio_blk_realize() should use qdev_add_vm_change_state_handler()
   instead of qemu_add_vm_change_state_handler(). This ensures the
   ordering with virtio_init()'s vm change state handler that calls
   virtio_blk_data_plane_start()/virtio_blk_data_plane_stop() is
   well-defined. Then blk's AioContext is guaranteed to be up-to-date in
   virtio_blk_dma_restart_cb() and it's no longer necessary to have a
   special case for virtio_blk_data_plane_start().

2. Only blk_drain() waits for virtio_blk_dma_restart_cb()'s
   blk_inc_in_flight() to be decremented. The bdrv_drain() family of
   functions do not wait for BlockBackend's in_flight counter to reach
   zero. virtio_blk_data_plane_stop() relies on blk_set_aio_context()'s
   implicit drain, but that's a bdrv_drain() and not a blk_drain().
   Note that virtio_blk_reset() already correctly relies on blk_drain().
   If virtio_blk_data_plane_stop() switches to blk_drain() then we can
   properly wait for pending virtio_blk_dma_restart_bh() calls.

Once these issues are taken care of the code becomes simpler. This
change is in preparation for multiple IOThreads in virtio-blk where we
need to clean up the multi-threading behavior.

I ran the reproducer from commit 49b44549ac ("virtio-blk: On restart,
process queued requests in the proper context") to check that there is
no regression.

Cc: Sergio Lopez <slp@redhat.com>
Cc: Kevin Wolf <kwolf@redhat.com>
Cc: Emanuele Giuseppe Esposito <eesposit@redhat.com>
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
Acked-by: Michael S. Tsirkin <mst@redhat.com>
Reviewed-by: Emanuele Giuseppe Esposito <eesposit@redhat.com>
Message-id: 20221102182337.252202-1-stefanha@redhat.com
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
2023-01-23 15:01:23 -05:00
..
9pfs coroutine: Split qemu/coroutine-core.h off qemu/coroutine.h 2023-01-20 07:21:46 +01:00
acpi acpi: cpuhp: fix guest-visible maximum access size to the legacy reg block 2023-01-08 01:54:23 -05:00
adc hw/adc: Make adci[*] R/W in NPCM7XX ADC 2022-07-18 13:20:14 +01:00
alpha include/hw/pci: Break inclusion loop pci_bridge.h and cxl.h 2023-01-08 01:54:22 -05:00
arm hw/i2c/versatile_i2c: Rename versatile_i2c -> arm_sbcon_i2c 2023-01-23 13:32:38 +00:00
audio include/hw/pci: Split pci_device.h off pci.h 2023-01-08 01:54:22 -05:00
avr Remove qemu-common.h include from most units 2022-04-06 14:31:55 +02:00
block virtio-blk: simplify virtio_blk_dma_restart_cb() 2023-01-23 15:01:23 -05:00
char hw/riscv: spike: Decouple create_fdt() dependency to ELF loading 2023-01-20 10:14:13 +10:00
core bulk: Rename TARGET_FMT_plx -> HWADDR_FMT_plx 2023-01-18 11:14:34 +01:00
cpu hw/cpu: Mark arm11 and realview mpcore as target-independent code 2023-01-16 17:51:20 +01:00
cris Do not include exec/address-spaces.h if it's not really necessary 2021-05-02 17:24:51 +02:00
cxl hw/cxl/cxl-host: Fix an error message typo 2023-01-17 10:02:37 +01:00
display Monitor patches for 2023-01-19 2023-01-19 18:58:03 +00:00
dma bulk: Rename TARGET_FMT_plx -> HWADDR_FMT_plx 2023-01-18 11:14:34 +01:00
gpio hw/gpio/omap_gpio: Use CamelCase for TYPE_OMAP2_GPIO type name 2023-01-12 17:15:09 +00:00
hppa hw: Remove unused MAX_IDE_BUS define 2022-10-31 11:32:07 +01:00
hyperv hw/hyperv/vmbus: Use device_cold_reset() and bus_cold_reset() 2022-12-16 15:55:32 +00:00
i2c hw/i2c/versatile_i2c: Rename versatile_i2c -> arm_sbcon_i2c 2023-01-23 13:32:38 +00:00
i386 trivial branch pull request 20230118 2023-01-19 15:05:29 +00:00
ide virtio,pc,pci: features, cleanups, fixes 2023-01-09 10:07:12 +00:00
input hw/input/tsc2xxx: Constify set_transform()'s MouseTransformInfo arg 2023-01-05 14:11:15 +00:00
intc Header cleanup patches for 2023-01-20 2023-01-20 13:17:55 +00:00
ipack include/hw/pci: Split pci_device.h off pci.h 2023-01-08 01:54:22 -05:00
ipmi include/hw/pci: Split pci_device.h off pci.h 2023-01-08 01:54:22 -05:00
isa hw/usb/hcd-uhci: Introduce TYPE_ defines for device models 2023-01-13 16:22:57 +01:00
loongarch hw/intc/loongarch_pch: Change default irq number of pch irq controller 2023-01-06 14:12:43 +08:00
m68k hw: Add compat machines for 8.0 2022-12-21 06:35:28 -05:00
mem hw/cxl/device: Add Flex Bus Port DVSEC 2022-12-21 07:32:24 -05:00
microblaze hw/microblaze: pass random seed to fdt 2022-09-21 19:59:56 +02:00
mips hw/mips/boston: Rename MachineState 'mc' pointer to 'ms' 2023-01-13 16:22:57 +01:00
misc bulk: Rename TARGET_FMT_plx -> HWADDR_FMT_plx 2023-01-18 11:14:34 +01:00
net bulk: Rename TARGET_FMT_plx -> HWADDR_FMT_plx 2023-01-18 11:14:34 +01:00
nios2 hw/nios2: set machine->fdt in nios2_load_dtb() 2022-10-17 16:15:10 -03:00
nubus qbus: Rename qbus_create_inplace() to qbus_init() 2021-09-30 13:42:10 +01:00
nvme hw/nvme updates 2023-01-11 16:41:13 +00:00
nvram qapi machine: Elide redundant has_FOO in generated C 2022-12-14 20:04:47 +01:00
openrisc openrisc: re-randomize rng-seed on reboot 2022-10-27 11:34:31 +01:00
pci bulk: Rename TARGET_FMT_plx -> HWADDR_FMT_plx 2023-01-18 11:14:34 +01:00
pci-bridge bulk: Rename TARGET_FMT_plx -> HWADDR_FMT_plx 2023-01-18 11:14:34 +01:00
pci-host Header cleanup patches for 2023-01-20 2023-01-20 13:17:55 +00:00
pcmcia hw/pcmcia: Do not register PCMCIA type if not required 2021-05-02 17:24:50 +02:00
ppc Header cleanup patches for 2023-01-20 2023-01-20 13:17:55 +00:00
rdma hw/pvrdma: Protect against buggy or malicious guest driver 2023-01-16 18:49:38 +01:00
remote hw/pci/pci: Factor out pci_bus_map_irqs() from pci_bus_irqs() 2023-01-13 16:22:57 +01:00
riscv hw/riscv/virt.c: move create_fw_cfg() back to virt_machine_init() 2023-01-20 10:14:14 +10:00
rtc bulk: Rename TARGET_FMT_plx -> HWADDR_FMT_plx 2023-01-18 11:14:34 +01:00
rx rx: re-randomize rng-seed on reboot 2022-10-27 11:34:31 +01:00
s390x s390x/pv: Implement a CGS check helper 2023-01-18 12:27:21 +01:00
scsi vhost-scsi: fix memleak of vsc->inflight 2023-01-08 01:54:23 -05:00
sd hw/arm/omap: Drop useless casts from void * to pointer 2023-01-12 17:15:09 +00:00
sensor hw/sensor: Add Renesas ISL69259 device model 2022-07-14 16:24:38 +02:00
sh4 bulk: Rename TARGET_FMT_plx -> HWADDR_FMT_plx 2023-01-18 11:14:34 +01:00
smbios include/hw/pci: Split pci_device.h off pci.h 2023-01-08 01:54:22 -05:00
sparc machine: make memory-backend a link property 2022-05-12 12:29:44 +02:00
sparc64 hw/sparc64/niagara: Use blk_name() instead of open-coding it 2023-01-20 07:25:01 +01:00
ssi trivial branch pull request 20230118 2023-01-19 15:05:29 +00:00
timer bulk: Rename TARGET_FMT_plx -> HWADDR_FMT_plx 2023-01-18 11:14:34 +01:00
tpm hw/tpm: Move tpm_ppi.c out of target-specific source set 2023-01-16 17:51:20 +01:00
tricore hw/tricore: fix inclusion of tricore_testboard 2021-07-20 20:10:21 +02:00
usb ccid-card-emulated: fix cast warning/error 2023-01-16 18:46:03 +01:00
vfio include/hw/pci: Split pci_device.h off pci.h 2023-01-08 01:54:22 -05:00
virtio Header cleanup patches for 2023-01-20 2023-01-20 13:17:55 +00:00
watchdog include/hw/pci: Split pci_device.h off pci.h 2023-01-08 01:54:22 -05:00
xen bulk: Rename TARGET_FMT_plx -> HWADDR_FMT_plx 2023-01-18 11:14:34 +01:00
xenpv Warn user if the vga flag is passed but no vga device is created 2022-05-09 08:21:14 +02:00
xtensa hw/xtensa: fix reset value of MIROUT register of MX PIC 2022-05-06 15:27:40 -07:00
Kconfig hw/loongarch: Add support loongson3 virt machine type. 2022-06-06 18:09:03 +00:00
meson.build hw/loongarch: Add support loongson3 virt machine type. 2022-06-06 18:09:03 +00:00