1 | The following changes since commit 0b5e750bea635b167eb03d86c3d9a09bbd43bc06: | 1 | The following changes since commit 887cba855bb6ff4775256f7968409281350b568c: |
---|---|---|---|
2 | 2 | ||
3 | Merge remote-tracking branch 'remotes/stefanha/tags/block-pull-request' into staging (2019-02-12 10:53:37 +0000) | 3 | configure: Fix cross-building for RISCV host (v5) (2023-07-11 17:56:09 +0100) |
4 | 4 | ||
5 | are available in the Git repository at: | 5 | are available in the Git repository at: |
6 | 6 | ||
7 | git://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 42824b4d16da56a50ff4027f6cd22378e0e2666e: | 9 | for you to fetch changes up to 75dcb4d790bbe5327169fd72b185960ca58e2fa6: |
10 | 10 | ||
11 | virtio-blk: set correct config size for the host driver (2019-02-13 16:18:17 +0800) | 11 | virtio-blk: fix host notifier issues during dataplane start/stop (2023-07-12 15:20:32 -0400) |
12 | 12 | ||
13 | ---------------------------------------------------------------- | 13 | ---------------------------------------------------------------- |
14 | Pull request | 14 | Pull request |
15 | 15 | ||
16 | Fix a virtio-blk migration regression. | ||
17 | |||
18 | ---------------------------------------------------------------- | 16 | ---------------------------------------------------------------- |
19 | 17 | ||
20 | Changpeng Liu (1): | 18 | Stefan Hajnoczi (1): |
21 | virtio-blk: set correct config size for the host driver | 19 | virtio-blk: fix host notifier issues during dataplane start/stop |
22 | 20 | ||
23 | hw/block/virtio-blk.c | 13 +++++++++---- | 21 | hw/block/dataplane/virtio-blk.c | 67 +++++++++++++++++++-------------- |
24 | 1 file changed, 9 insertions(+), 4 deletions(-) | 22 | 1 file changed, 38 insertions(+), 29 deletions(-) |
25 | 23 | ||
26 | -- | 24 | -- |
27 | 2.20.1 | 25 | 2.40.1 |
28 | |||
29 | diff view generated by jsdifflib |
1 | From: Changpeng Liu <changpeng.liu@intel.com> | 1 | The main loop thread can consume 100% CPU when using --device |
---|---|---|---|
2 | virtio-blk-pci,iothread=<iothread>. ppoll() constantly returns but | ||
3 | reading virtqueue host notifiers fails with EAGAIN. The file descriptors | ||
4 | are stale and remain registered with the AioContext because of bugs in | ||
5 | the virtio-blk dataplane start/stop code. | ||
2 | 6 | ||
3 | Commit caa1ee43 "vhost-user-blk: add discard/write zeroes features | 7 | The problem is that the dataplane start/stop code involves drain |
4 | support" added fields to struct virtio_blk_config. This changes | 8 | operations, which call virtio_blk_drained_begin() and |
5 | the size of the config space and breaks migration from QEMU 3.1 | 9 | virtio_blk_drained_end() at points where the host notifier is not |
6 | and older: | 10 | operational: |
11 | - In virtio_blk_data_plane_start(), blk_set_aio_context() drains after | ||
12 | vblk->dataplane_started has been set to true but the host notifier has | ||
13 | not been attached yet. | ||
14 | - In virtio_blk_data_plane_stop(), blk_drain() and blk_set_aio_context() | ||
15 | drain after the host notifier has already been detached but with | ||
16 | vblk->dataplane_started still set to true. | ||
7 | 17 | ||
8 | qemu-system-ppc64: get_pci_config_device: Bad config data: i=0x10 read: 41 device: 1 cmask: ff wmask: 80 w1cmask:0 | 18 | I would like to simplify ->ioeventfd_start/stop() to avoid interactions |
9 | qemu-system-ppc64: Failed to load PCIDevice:config | 19 | with drain entirely, but couldn't find a way to do that. Instead, this |
10 | qemu-system-ppc64: Failed to load virtio-blk:virtio | 20 | patch accepts the fragile nature of the code and reorders it so that |
11 | qemu-system-ppc64: error while loading state for instance 0x0 of device 'pci@800000020000000:01.0/virtio-blk' | 21 | vblk->dataplane_started is false during drain operations. This way the |
12 | qemu-system-ppc64: load of migration failed: Invalid argument | 22 | virtio_blk_drained_begin() and virtio_blk_drained_end() calls don't |
23 | touch the host notifier. The result is that | ||
24 | virtio_blk_data_plane_start() and virtio_blk_data_plane_stop() have | ||
25 | complete control over the host notifier and stale file descriptors are | ||
26 | no longer left in the AioContext. | ||
13 | 27 | ||
14 | Since virtio-blk doesn't support the "discard" and "write zeroes" | 28 | This patch fixes the 100% CPU consumption in the main loop thread and |
15 | features, it shouldn't even expose the associated fields in the | 29 | correctly moves host notifier processing to the IOThread. |
16 | config space actually. Just include all fields up to num_queues to | ||
17 | match QEMU 3.1 and older. | ||
18 | 30 | ||
19 | Signed-off-by: Changpeng Liu <changpeng.liu@intel.com> | 31 | Fixes: 1665d9326fd2 ("virtio-blk: implement BlockDevOps->drained_begin()") |
20 | Reviewed-by: Michael S. Tsirkin <mst@redhat.com> | 32 | Reported-by: Lukáš Doktor <ldoktor@redhat.com> |
21 | Message-id: 1550022537-27565-1-git-send-email-changpeng.liu@intel.com | 33 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> |
22 | Message-Id: <1550022537-27565-1-git-send-email-changpeng.liu@intel.com> | 34 | Tested-by: Lukas Doktor <ldoktor@redhat.com> |
35 | Message-id: 20230704151527.193586-1-stefanha@redhat.com | ||
23 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | 36 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> |
24 | --- | 37 | --- |
25 | hw/block/virtio-blk.c | 13 +++++++++---- | 38 | hw/block/dataplane/virtio-blk.c | 67 +++++++++++++++++++-------------- |
26 | 1 file changed, 9 insertions(+), 4 deletions(-) | 39 | 1 file changed, 38 insertions(+), 29 deletions(-) |
27 | 40 | ||
28 | diff --git a/hw/block/virtio-blk.c b/hw/block/virtio-blk.c | 41 | diff --git a/hw/block/dataplane/virtio-blk.c b/hw/block/dataplane/virtio-blk.c |
29 | index XXXXXXX..XXXXXXX 100644 | 42 | index XXXXXXX..XXXXXXX 100644 |
30 | --- a/hw/block/virtio-blk.c | 43 | --- a/hw/block/dataplane/virtio-blk.c |
31 | +++ b/hw/block/virtio-blk.c | 44 | +++ b/hw/block/dataplane/virtio-blk.c |
32 | @@ -XXX,XX +XXX,XX @@ | 45 | @@ -XXX,XX +XXX,XX @@ int virtio_blk_data_plane_start(VirtIODevice *vdev) |
33 | #include "hw/virtio/virtio-bus.h" | 46 | |
34 | #include "hw/virtio/virtio-access.h" | 47 | memory_region_transaction_commit(); |
35 | 48 | ||
36 | +/* We don't support discard yet, hide associated config fields. */ | 49 | - /* |
37 | +#define VIRTIO_BLK_CFG_SIZE offsetof(struct virtio_blk_config, \ | 50 | - * These fields are visible to the IOThread so we rely on implicit barriers |
38 | + max_discard_sectors) | 51 | - * in aio_context_acquire() on the write side and aio_notify_accept() on |
52 | - * the read side. | ||
53 | - */ | ||
54 | - s->starting = false; | ||
55 | - vblk->dataplane_started = true; | ||
56 | trace_virtio_blk_data_plane_start(s); | ||
57 | |||
58 | old_context = blk_get_aio_context(s->conf->conf.blk); | ||
59 | @@ -XXX,XX +XXX,XX @@ int virtio_blk_data_plane_start(VirtIODevice *vdev) | ||
60 | event_notifier_set(virtio_queue_get_host_notifier(vq)); | ||
61 | } | ||
62 | |||
63 | + /* | ||
64 | + * These fields must be visible to the IOThread when it processes the | ||
65 | + * virtqueue, otherwise it will think dataplane has not started yet. | ||
66 | + * | ||
67 | + * Make sure ->dataplane_started is false when blk_set_aio_context() is | ||
68 | + * called above so that draining does not cause the host notifier to be | ||
69 | + * detached/attached prematurely. | ||
70 | + */ | ||
71 | + s->starting = false; | ||
72 | + vblk->dataplane_started = true; | ||
73 | + smp_wmb(); /* paired with aio_notify_accept() on the read side */ | ||
39 | + | 74 | + |
40 | static void virtio_blk_init_request(VirtIOBlock *s, VirtQueue *vq, | 75 | /* Get this show started by hooking up our callbacks */ |
41 | VirtIOBlockReq *req) | 76 | if (!blk_in_drain(s->conf->conf.blk)) { |
42 | { | 77 | aio_context_acquire(s->ctx); |
43 | @@ -XXX,XX +XXX,XX @@ static void virtio_blk_update_config(VirtIODevice *vdev, uint8_t *config) | 78 | @@ -XXX,XX +XXX,XX @@ int virtio_blk_data_plane_start(VirtIODevice *vdev) |
44 | blkcfg.alignment_offset = 0; | 79 | fail_guest_notifiers: |
45 | blkcfg.wce = blk_enable_write_cache(s->blk); | 80 | vblk->dataplane_disabled = true; |
46 | virtio_stw_p(vdev, &blkcfg.num_queues, s->conf.num_queues); | 81 | s->starting = false; |
47 | - memcpy(config, &blkcfg, sizeof(struct virtio_blk_config)); | 82 | - vblk->dataplane_started = true; |
48 | + memcpy(config, &blkcfg, VIRTIO_BLK_CFG_SIZE); | 83 | return -ENOSYS; |
49 | + QEMU_BUILD_BUG_ON(VIRTIO_BLK_CFG_SIZE > sizeof(blkcfg)); | ||
50 | } | 84 | } |
51 | 85 | ||
52 | static void virtio_blk_set_config(VirtIODevice *vdev, const uint8_t *config) | 86 | @@ -XXX,XX +XXX,XX @@ void virtio_blk_data_plane_stop(VirtIODevice *vdev) |
53 | @@ -XXX,XX +XXX,XX @@ static void virtio_blk_set_config(VirtIODevice *vdev, const uint8_t *config) | 87 | aio_wait_bh_oneshot(s->ctx, virtio_blk_data_plane_stop_bh, s); |
54 | VirtIOBlock *s = VIRTIO_BLK(vdev); | ||
55 | struct virtio_blk_config blkcfg; | ||
56 | |||
57 | - memcpy(&blkcfg, config, sizeof(blkcfg)); | ||
58 | + memcpy(&blkcfg, config, VIRTIO_BLK_CFG_SIZE); | ||
59 | + QEMU_BUILD_BUG_ON(VIRTIO_BLK_CFG_SIZE > sizeof(blkcfg)); | ||
60 | |||
61 | aio_context_acquire(blk_get_aio_context(s->blk)); | ||
62 | blk_set_enable_write_cache(s->blk, blkcfg.wce != 0); | ||
63 | @@ -XXX,XX +XXX,XX @@ static void virtio_blk_device_realize(DeviceState *dev, Error **errp) | ||
64 | return; | ||
65 | } | 88 | } |
66 | 89 | ||
67 | - virtio_init(vdev, "virtio-blk", VIRTIO_ID_BLOCK, | 90 | + /* |
68 | - sizeof(struct virtio_blk_config)); | 91 | + * Batch all the host notifiers in a single transaction to avoid |
69 | + virtio_init(vdev, "virtio-blk", VIRTIO_ID_BLOCK, VIRTIO_BLK_CFG_SIZE); | 92 | + * quadratic time complexity in address_space_update_ioeventfds(). |
70 | 93 | + */ | |
71 | s->blk = conf->conf.blk; | 94 | + memory_region_transaction_begin(); |
72 | s->rq = NULL; | 95 | + |
96 | + for (i = 0; i < nvqs; i++) { | ||
97 | + virtio_bus_set_host_notifier(VIRTIO_BUS(qbus), i, false); | ||
98 | + } | ||
99 | + | ||
100 | + /* | ||
101 | + * The transaction expects the ioeventfds to be open when it | ||
102 | + * commits. Do it now, before the cleanup loop. | ||
103 | + */ | ||
104 | + memory_region_transaction_commit(); | ||
105 | + | ||
106 | + for (i = 0; i < nvqs; i++) { | ||
107 | + virtio_bus_cleanup_host_notifier(VIRTIO_BUS(qbus), i); | ||
108 | + } | ||
109 | + | ||
110 | + /* | ||
111 | + * Set ->dataplane_started to false before draining so that host notifiers | ||
112 | + * are not detached/attached anymore. | ||
113 | + */ | ||
114 | + vblk->dataplane_started = false; | ||
115 | + | ||
116 | aio_context_acquire(s->ctx); | ||
117 | |||
118 | /* Wait for virtio_blk_dma_restart_bh() and in flight I/O to complete */ | ||
119 | @@ -XXX,XX +XXX,XX @@ void virtio_blk_data_plane_stop(VirtIODevice *vdev) | ||
120 | |||
121 | aio_context_release(s->ctx); | ||
122 | |||
123 | - /* | ||
124 | - * Batch all the host notifiers in a single transaction to avoid | ||
125 | - * quadratic time complexity in address_space_update_ioeventfds(). | ||
126 | - */ | ||
127 | - memory_region_transaction_begin(); | ||
128 | - | ||
129 | - for (i = 0; i < nvqs; i++) { | ||
130 | - virtio_bus_set_host_notifier(VIRTIO_BUS(qbus), i, false); | ||
131 | - } | ||
132 | - | ||
133 | - /* | ||
134 | - * The transaction expects the ioeventfds to be open when it | ||
135 | - * commits. Do it now, before the cleanup loop. | ||
136 | - */ | ||
137 | - memory_region_transaction_commit(); | ||
138 | - | ||
139 | - for (i = 0; i < nvqs; i++) { | ||
140 | - virtio_bus_cleanup_host_notifier(VIRTIO_BUS(qbus), i); | ||
141 | - } | ||
142 | - | ||
143 | qemu_bh_cancel(s->bh); | ||
144 | notify_guest_bh(s); /* final chance to notify guest */ | ||
145 | |||
146 | /* Clean up guest notifier (irq) */ | ||
147 | k->set_guest_notifiers(qbus->parent, nvqs, false); | ||
148 | |||
149 | - vblk->dataplane_started = false; | ||
150 | s->stopping = false; | ||
151 | } | ||
73 | -- | 152 | -- |
74 | 2.20.1 | 153 | 2.40.1 |
75 | 154 | ||
76 | 155 | diff view generated by jsdifflib |