1 | The following changes since commit cc6613e244e86c66f83467eab5284825d7057cea: | 1 | The following changes since commit d145c0da22cde391d8c6672d33146ce306e8bf75: |
---|---|---|---|
2 | 2 | ||
3 | Merge remote-tracking branch 'remotes/stefanha/tags/tracing-pull-request' into staging (2019-09-03 11:06:09 +0100) | 3 | Merge tag 'pull-tcg-20230701' of https://gitlab.com/rth7680/qemu into staging (2023-07-01 08:55:37 +0200) |
4 | 4 | ||
5 | are available in the Git repository at: | 5 | are available in the Git repository at: |
6 | 6 | ||
7 | https://github.com/stefanha/qemu.git tags/block-pull-request | 7 | https://gitlab.com/stefanha/qemu.git tags/block-pull-request |
8 | 8 | ||
9 | for you to fetch changes up to ebb6ff25cd888a52a64a9adc3692541c6d1d9a42: | 9 | for you to fetch changes up to c21eae1ccc782440f320accb6f90c66cb8f45ee9: |
10 | 10 | ||
11 | virtio-blk: Cancel the pending BH when the dataplane is reset (2019-09-03 16:11:18 +0100) | 11 | block/blkio: fix module_block.py parsing (2023-07-04 17:28:25 +0200) |
12 | 12 | ||
13 | ---------------------------------------------------------------- | 13 | ---------------------------------------------------------------- |
14 | Pull request | 14 | Pull request |
15 | 15 | ||
16 | Fix --enable-modules with the blkio block driver. | ||
17 | |||
16 | ---------------------------------------------------------------- | 18 | ---------------------------------------------------------------- |
17 | 19 | ||
18 | Philippe Mathieu-Daudé (1): | 20 | Stefan Hajnoczi (1): |
19 | virtio-blk: Cancel the pending BH when the dataplane is reset | 21 | block/blkio: fix module_block.py parsing |
20 | 22 | ||
21 | hw/block/dataplane/virtio-blk.c | 3 +++ | 23 | block/blkio.c | 108 ++++++++++++++++++++++++++------------------------ |
22 | 1 file changed, 3 insertions(+) | 24 | 1 file changed, 56 insertions(+), 52 deletions(-) |
23 | 25 | ||
24 | -- | 26 | -- |
25 | 2.21.0 | 27 | 2.40.1 |
26 | |||
27 | diff view generated by jsdifflib |
1 | From: Philippe Mathieu-Daudé <philmd@redhat.com> | 1 | When QEMU is built with --enable-modules, the module_block.py script |
---|---|---|---|
2 | parses block/*.c to find block drivers that are built as modules. The | ||
3 | script generates a table of block drivers called block_driver_modules[]. | ||
4 | This table is used for block driver module loading. | ||
2 | 5 | ||
3 | When 'system_reset' is called, the main loop clear the memory | 6 | The blkio.c driver uses macros to define its BlockDriver structs. This |
4 | region cache before the BH has a chance to execute. Later when | 7 | was done to avoid code duplication but the module_block.py script is |
5 | the deferred function is called, some assumptions that were | 8 | unable to parse the macro. The result is that libblkio-based block |
6 | made when scheduling them are no longer true when they actually | 9 | drivers can be built as modules but will not be found at runtime. |
7 | execute. | ||
8 | 10 | ||
9 | This is what happens using a virtio-blk device (fresh RHEL7.8 install): | 11 | One fix is to make the module_block.py script or build system fancier so |
12 | it can parse C macros (e.g. by parsing the preprocessed source code). I | ||
13 | chose not to do this because it raises the complexity of the build, | ||
14 | making future issues harder to debug. | ||
10 | 15 | ||
11 | $ (sleep 12.3; echo system_reset; sleep 12.3; echo system_reset; sleep 1; echo q) \ | 16 | Keep things simple: use the macro to avoid duplicating BlockDriver |
12 | | qemu-system-x86_64 -m 4G -smp 8 -boot menu=on \ | 17 | function pointers but define .format_name and .protocol_name manually |
13 | -device virtio-blk-pci,id=image1,drive=drive_image1 \ | 18 | for each BlockDriver. This way the module_block.py is able to parse the |
14 | -drive file=/var/lib/libvirt/images/rhel78.qcow2,if=none,id=drive_image1,format=qcow2,cache=none \ | 19 | code. |
15 | -device virtio-net-pci,netdev=net0,id=nic0,mac=52:54:00:c4:e7:84 \ | ||
16 | -netdev tap,id=net0,script=/bin/true,downscript=/bin/true,vhost=on \ | ||
17 | -monitor stdio -serial null -nographic | ||
18 | (qemu) system_reset | ||
19 | (qemu) system_reset | ||
20 | (qemu) qemu-system-x86_64: hw/virtio/virtio.c:225: vring_get_region_caches: Assertion `caches != NULL' failed. | ||
21 | Aborted | ||
22 | 20 | ||
23 | (gdb) bt | 21 | Also get rid of the block driver name macros (e.g. DRIVER_IO_URING) |
24 | Thread 1 (Thread 0x7f109c17b680 (LWP 10939)): | 22 | because module_block.py cannot parse them either. |
25 | #0 0x00005604083296d1 in vring_get_region_caches (vq=0x56040a24bdd0) at hw/virtio/virtio.c:227 | ||
26 | #1 0x000056040832972b in vring_avail_flags (vq=0x56040a24bdd0) at hw/virtio/virtio.c:235 | ||
27 | #2 0x000056040832d13d in virtio_should_notify (vdev=0x56040a240630, vq=0x56040a24bdd0) at hw/virtio/virtio.c:1648 | ||
28 | #3 0x000056040832d1f8 in virtio_notify_irqfd (vdev=0x56040a240630, vq=0x56040a24bdd0) at hw/virtio/virtio.c:1662 | ||
29 | #4 0x00005604082d213d in notify_guest_bh (opaque=0x56040a243ec0) at hw/block/dataplane/virtio-blk.c:75 | ||
30 | #5 0x000056040883dc35 in aio_bh_call (bh=0x56040a243f10) at util/async.c:90 | ||
31 | #6 0x000056040883dccd in aio_bh_poll (ctx=0x560409161980) at util/async.c:118 | ||
32 | #7 0x0000560408842af7 in aio_dispatch (ctx=0x560409161980) at util/aio-posix.c:460 | ||
33 | #8 0x000056040883e068 in aio_ctx_dispatch (source=0x560409161980, callback=0x0, user_data=0x0) at util/async.c:261 | ||
34 | #9 0x00007f10a8fca06d in g_main_context_dispatch () at /lib64/libglib-2.0.so.0 | ||
35 | #10 0x0000560408841445 in glib_pollfds_poll () at util/main-loop.c:215 | ||
36 | #11 0x00005604088414bf in os_host_main_loop_wait (timeout=0) at util/main-loop.c:238 | ||
37 | #12 0x00005604088415c4 in main_loop_wait (nonblocking=0) at util/main-loop.c:514 | ||
38 | #13 0x0000560408416b1e in main_loop () at vl.c:1923 | ||
39 | #14 0x000056040841e0e8 in main (argc=20, argv=0x7ffc2c3f9c58, envp=0x7ffc2c3f9d00) at vl.c:4578 | ||
40 | 23 | ||
41 | Fix this by cancelling the BH when the virtio dataplane is stopped. | 24 | Fixes: fd66dbd424f5 ("blkio: add libblkio block driver") |
42 | 25 | Reported-by: Qing Wang <qinwang@redhat.com> | |
43 | [This is version of the patch was modified as discussed with Philippe on | 26 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> |
44 | the mailing list thread. | 27 | Reviewed-by: Stefano Garzarella <sgarzare@redhat.com> |
45 | --Stefan] | 28 | Message-id: 20230704123436.187761-1-stefanha@redhat.com |
46 | 29 | Cc: Stefano Garzarella <sgarzare@redhat.com> | |
47 | Reported-by: Yihuang Yu <yihyu@redhat.com> | ||
48 | Suggested-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
49 | Fixes: https://bugs.launchpad.net/qemu/+bug/1839428 | ||
50 | Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com> | ||
51 | Message-Id: <20190816171503.24761-1-philmd@redhat.com> | ||
52 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | 30 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> |
53 | --- | 31 | --- |
54 | hw/block/dataplane/virtio-blk.c | 3 +++ | 32 | block/blkio.c | 108 ++++++++++++++++++++++++++------------------------ |
55 | 1 file changed, 3 insertions(+) | 33 | 1 file changed, 56 insertions(+), 52 deletions(-) |
56 | 34 | ||
57 | diff --git a/hw/block/dataplane/virtio-blk.c b/hw/block/dataplane/virtio-blk.c | 35 | diff --git a/block/blkio.c b/block/blkio.c |
58 | index XXXXXXX..XXXXXXX 100644 | 36 | index XXXXXXX..XXXXXXX 100644 |
59 | --- a/hw/block/dataplane/virtio-blk.c | 37 | --- a/block/blkio.c |
60 | +++ b/hw/block/dataplane/virtio-blk.c | 38 | +++ b/block/blkio.c |
61 | @@ -XXX,XX +XXX,XX @@ void virtio_blk_data_plane_stop(VirtIODevice *vdev) | 39 | @@ -XXX,XX +XXX,XX @@ |
62 | virtio_bus_cleanup_host_notifier(VIRTIO_BUS(qbus), i); | 40 | |
41 | #include "block/block-io.h" | ||
42 | |||
43 | -/* | ||
44 | - * Keep the QEMU BlockDriver names identical to the libblkio driver names. | ||
45 | - * Using macros instead of typing out the string literals avoids typos. | ||
46 | - */ | ||
47 | -#define DRIVER_IO_URING "io_uring" | ||
48 | -#define DRIVER_NVME_IO_URING "nvme-io_uring" | ||
49 | -#define DRIVER_VIRTIO_BLK_VFIO_PCI "virtio-blk-vfio-pci" | ||
50 | -#define DRIVER_VIRTIO_BLK_VHOST_USER "virtio-blk-vhost-user" | ||
51 | -#define DRIVER_VIRTIO_BLK_VHOST_VDPA "virtio-blk-vhost-vdpa" | ||
52 | - | ||
53 | /* | ||
54 | * Allocated bounce buffers are kept in a list sorted by buffer address. | ||
55 | */ | ||
56 | @@ -XXX,XX +XXX,XX @@ static int blkio_file_open(BlockDriverState *bs, QDict *options, int flags, | ||
57 | return ret; | ||
63 | } | 58 | } |
64 | 59 | ||
65 | + qemu_bh_cancel(s->bh); | 60 | - if (strcmp(blkio_driver, DRIVER_IO_URING) == 0) { |
66 | + notify_guest_bh(s); /* final chance to notify guest */ | 61 | + if (strcmp(blkio_driver, "io_uring") == 0) { |
62 | ret = blkio_io_uring_open(bs, options, flags, errp); | ||
63 | - } else if (strcmp(blkio_driver, DRIVER_NVME_IO_URING) == 0) { | ||
64 | + } else if (strcmp(blkio_driver, "nvme-io_uring") == 0) { | ||
65 | ret = blkio_nvme_io_uring(bs, options, flags, errp); | ||
66 | - } else if (strcmp(blkio_driver, DRIVER_VIRTIO_BLK_VFIO_PCI) == 0) { | ||
67 | + } else if (strcmp(blkio_driver, "virtio-blk-vfio-pci") == 0) { | ||
68 | ret = blkio_virtio_blk_common_open(bs, options, flags, errp); | ||
69 | - } else if (strcmp(blkio_driver, DRIVER_VIRTIO_BLK_VHOST_USER) == 0) { | ||
70 | + } else if (strcmp(blkio_driver, "virtio-blk-vhost-user") == 0) { | ||
71 | ret = blkio_virtio_blk_common_open(bs, options, flags, errp); | ||
72 | - } else if (strcmp(blkio_driver, DRIVER_VIRTIO_BLK_VHOST_VDPA) == 0) { | ||
73 | + } else if (strcmp(blkio_driver, "virtio-blk-vhost-vdpa") == 0) { | ||
74 | ret = blkio_virtio_blk_common_open(bs, options, flags, errp); | ||
75 | } else { | ||
76 | g_assert_not_reached(); | ||
77 | @@ -XXX,XX +XXX,XX @@ static void blkio_refresh_limits(BlockDriverState *bs, Error **errp) | ||
78 | * - truncate | ||
79 | */ | ||
80 | |||
81 | -#define BLKIO_DRIVER(name, ...) \ | ||
82 | - { \ | ||
83 | - .format_name = name, \ | ||
84 | - .protocol_name = name, \ | ||
85 | - .instance_size = sizeof(BDRVBlkioState), \ | ||
86 | - .bdrv_file_open = blkio_file_open, \ | ||
87 | - .bdrv_close = blkio_close, \ | ||
88 | - .bdrv_co_getlength = blkio_co_getlength, \ | ||
89 | - .bdrv_co_truncate = blkio_truncate, \ | ||
90 | - .bdrv_co_get_info = blkio_co_get_info, \ | ||
91 | - .bdrv_attach_aio_context = blkio_attach_aio_context, \ | ||
92 | - .bdrv_detach_aio_context = blkio_detach_aio_context, \ | ||
93 | - .bdrv_co_pdiscard = blkio_co_pdiscard, \ | ||
94 | - .bdrv_co_preadv = blkio_co_preadv, \ | ||
95 | - .bdrv_co_pwritev = blkio_co_pwritev, \ | ||
96 | - .bdrv_co_flush_to_disk = blkio_co_flush, \ | ||
97 | - .bdrv_co_pwrite_zeroes = blkio_co_pwrite_zeroes, \ | ||
98 | - .bdrv_refresh_limits = blkio_refresh_limits, \ | ||
99 | - .bdrv_register_buf = blkio_register_buf, \ | ||
100 | - .bdrv_unregister_buf = blkio_unregister_buf, \ | ||
101 | - __VA_ARGS__ \ | ||
102 | - } | ||
103 | +/* | ||
104 | + * Do not include .format_name and .protocol_name because module_block.py | ||
105 | + * does not parse macros in the source code. | ||
106 | + */ | ||
107 | +#define BLKIO_DRIVER_COMMON \ | ||
108 | + .instance_size = sizeof(BDRVBlkioState), \ | ||
109 | + .bdrv_file_open = blkio_file_open, \ | ||
110 | + .bdrv_close = blkio_close, \ | ||
111 | + .bdrv_co_getlength = blkio_co_getlength, \ | ||
112 | + .bdrv_co_truncate = blkio_truncate, \ | ||
113 | + .bdrv_co_get_info = blkio_co_get_info, \ | ||
114 | + .bdrv_attach_aio_context = blkio_attach_aio_context, \ | ||
115 | + .bdrv_detach_aio_context = blkio_detach_aio_context, \ | ||
116 | + .bdrv_co_pdiscard = blkio_co_pdiscard, \ | ||
117 | + .bdrv_co_preadv = blkio_co_preadv, \ | ||
118 | + .bdrv_co_pwritev = blkio_co_pwritev, \ | ||
119 | + .bdrv_co_flush_to_disk = blkio_co_flush, \ | ||
120 | + .bdrv_co_pwrite_zeroes = blkio_co_pwrite_zeroes, \ | ||
121 | + .bdrv_refresh_limits = blkio_refresh_limits, \ | ||
122 | + .bdrv_register_buf = blkio_register_buf, \ | ||
123 | + .bdrv_unregister_buf = blkio_unregister_buf, | ||
124 | |||
125 | -static BlockDriver bdrv_io_uring = BLKIO_DRIVER( | ||
126 | - DRIVER_IO_URING, | ||
127 | +/* | ||
128 | + * Use the same .format_name and .protocol_name as the libblkio driver name for | ||
129 | + * consistency. | ||
130 | + */ | ||
67 | + | 131 | + |
68 | /* Clean up guest notifier (irq) */ | 132 | +static BlockDriver bdrv_io_uring = { |
69 | k->set_guest_notifiers(qbus->parent, nvqs, false); | 133 | + .format_name = "io_uring", |
70 | 134 | + .protocol_name = "io_uring", | |
135 | .bdrv_needs_filename = true, | ||
136 | -); | ||
137 | + BLKIO_DRIVER_COMMON | ||
138 | +}; | ||
139 | |||
140 | -static BlockDriver bdrv_nvme_io_uring = BLKIO_DRIVER( | ||
141 | - DRIVER_NVME_IO_URING, | ||
142 | -); | ||
143 | +static BlockDriver bdrv_nvme_io_uring = { | ||
144 | + .format_name = "nvme-io_uring", | ||
145 | + .protocol_name = "nvme-io_uring", | ||
146 | + BLKIO_DRIVER_COMMON | ||
147 | +}; | ||
148 | |||
149 | -static BlockDriver bdrv_virtio_blk_vfio_pci = BLKIO_DRIVER( | ||
150 | - DRIVER_VIRTIO_BLK_VFIO_PCI | ||
151 | -); | ||
152 | +static BlockDriver bdrv_virtio_blk_vfio_pci = { | ||
153 | + .format_name = "virtio-blk-vfio-pci", | ||
154 | + .protocol_name = "virtio-blk-vfio-pci", | ||
155 | + BLKIO_DRIVER_COMMON | ||
156 | +}; | ||
157 | |||
158 | -static BlockDriver bdrv_virtio_blk_vhost_user = BLKIO_DRIVER( | ||
159 | - DRIVER_VIRTIO_BLK_VHOST_USER | ||
160 | -); | ||
161 | +static BlockDriver bdrv_virtio_blk_vhost_user = { | ||
162 | + .format_name = "virtio-blk-vhost-user", | ||
163 | + .protocol_name = "virtio-blk-vhost-user", | ||
164 | + BLKIO_DRIVER_COMMON | ||
165 | +}; | ||
166 | |||
167 | -static BlockDriver bdrv_virtio_blk_vhost_vdpa = BLKIO_DRIVER( | ||
168 | - DRIVER_VIRTIO_BLK_VHOST_VDPA | ||
169 | -); | ||
170 | +static BlockDriver bdrv_virtio_blk_vhost_vdpa = { | ||
171 | + .format_name = "virtio-blk-vhost-vdpa", | ||
172 | + .protocol_name = "virtio-blk-vhost-vdpa", | ||
173 | + BLKIO_DRIVER_COMMON | ||
174 | +}; | ||
175 | |||
176 | static void bdrv_blkio_init(void) | ||
177 | { | ||
71 | -- | 178 | -- |
72 | 2.21.0 | 179 | 2.40.1 |
73 | |||
74 | diff view generated by jsdifflib |