1 | The following changes since commit 8507c9d5c9a62de2a0e281b640f995e26eac46af: | 1 | The following changes since commit 9cf289af47bcfae5c75de37d8e5d6fd23705322c: |
---|---|---|---|
2 | 2 | ||
3 | Merge remote-tracking branch 'remotes/kevin/tags/for-upstream' into staging (2020-11-03 15:59:44 +0000) | 3 | Merge tag 'qga-pull-request' of gitlab.com:marcandre.lureau/qemu into staging (2022-05-04 03:42:49 -0700) |
4 | 4 | ||
5 | are available in the Git repository at: | 5 | are available in the Git repository at: |
6 | 6 | ||
7 | https://gitlab.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 fc107d86840b3364e922c26cf7631b7fd38ce523: | 9 | for you to fetch changes up to bef2e050d6a7feb865854c65570c496ac5a8cf53: |
10 | 10 | ||
11 | util/vfio-helpers: Assert offset is aligned to page size (2020-11-03 19:06:23 +0000) | 11 | util/event-loop-base: Introduce options to set the thread pool size (2022-05-04 17:02:19 +0100) |
12 | 12 | ||
13 | ---------------------------------------------------------------- | 13 | ---------------------------------------------------------------- |
14 | Pull request for 5.2 | 14 | Pull request |
15 | 15 | ||
16 | NVMe fixes to solve IOMMU issues on non-x86 and error message/tracing | 16 | Add new thread-pool-min/thread-pool-max parameters to control the thread pool |
17 | improvements. Elena Afanasova's ioeventfd fixes are also included. | 17 | used for async I/O. |
18 | |||
19 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
20 | 18 | ||
21 | ---------------------------------------------------------------- | 19 | ---------------------------------------------------------------- |
22 | 20 | ||
23 | Elena Afanasova (2): | 21 | Nicolas Saenz Julienne (3): |
24 | accel/kvm: add PIO ioeventfds only in case kvm_eventfds_allowed is | 22 | Introduce event-loop-base abstract class |
25 | true | 23 | util/main-loop: Introduce the main loop into QOM |
26 | softmmu/memory: fix memory_region_ioeventfd_equal() | 24 | util/event-loop-base: Introduce options to set the thread pool size |
27 | 25 | ||
28 | Eric Auger (4): | 26 | qapi/qom.json | 43 ++++++++-- |
29 | block/nvme: Change size and alignment of IDENTIFY response buffer | 27 | meson.build | 26 +++--- |
30 | block/nvme: Change size and alignment of queue | 28 | include/block/aio.h | 10 +++ |
31 | block/nvme: Change size and alignment of prp_list_pages | 29 | include/block/thread-pool.h | 3 + |
32 | block/nvme: Align iov's va and size on host page size | 30 | include/qemu/main-loop.h | 10 +++ |
33 | 31 | include/sysemu/event-loop-base.h | 41 +++++++++ | |
34 | Philippe Mathieu-Daudé (27): | 32 | include/sysemu/iothread.h | 6 +- |
35 | MAINTAINERS: Cover "block/nvme.h" file | 33 | event-loop-base.c | 140 +++++++++++++++++++++++++++++++ |
36 | block/nvme: Use hex format to display offset in trace events | 34 | iothread.c | 68 +++++---------- |
37 | block/nvme: Report warning with warn_report() | 35 | util/aio-posix.c | 1 + |
38 | block/nvme: Trace controller capabilities | 36 | util/async.c | 20 +++++ |
39 | block/nvme: Trace nvme_poll_queue() per queue | 37 | util/main-loop.c | 65 ++++++++++++++ |
40 | block/nvme: Improve nvme_free_req_queue_wait() trace information | 38 | util/thread-pool.c | 55 +++++++++++- |
41 | block/nvme: Trace queue pair creation/deletion | 39 | 13 files changed, 419 insertions(+), 69 deletions(-) |
42 | block/nvme: Move definitions before structure declarations | 40 | create mode 100644 include/sysemu/event-loop-base.h |
43 | block/nvme: Use unsigned integer for queue counter/size | 41 | create mode 100644 event-loop-base.c |
44 | block/nvme: Make nvme_identify() return boolean indicating error | ||
45 | block/nvme: Make nvme_init_queue() return boolean indicating error | ||
46 | block/nvme: Introduce Completion Queue definitions | ||
47 | block/nvme: Use definitions instead of magic values in add_io_queue() | ||
48 | block/nvme: Correctly initialize Admin Queue Attributes | ||
49 | block/nvme: Simplify ADMIN queue access | ||
50 | block/nvme: Simplify nvme_cmd_sync() | ||
51 | block/nvme: Set request_alignment at initialization | ||
52 | block/nvme: Correct minimum device page size | ||
53 | block/nvme: Fix use of write-only doorbells page on Aarch64 arch | ||
54 | block/nvme: Fix nvme_submit_command() on big-endian host | ||
55 | util/vfio-helpers: Improve reporting unsupported IOMMU type | ||
56 | util/vfio-helpers: Trace PCI I/O config accesses | ||
57 | util/vfio-helpers: Trace PCI BAR region info | ||
58 | util/vfio-helpers: Trace where BARs are mapped | ||
59 | util/vfio-helpers: Improve DMA trace events | ||
60 | util/vfio-helpers: Convert vfio_dump_mapping to trace events | ||
61 | util/vfio-helpers: Assert offset is aligned to page size | ||
62 | |||
63 | MAINTAINERS | 2 + | ||
64 | include/block/nvme.h | 18 ++-- | ||
65 | accel/kvm/kvm-all.c | 6 +- | ||
66 | block/nvme.c | 209 ++++++++++++++++++++++++------------------- | ||
67 | softmmu/memory.c | 11 ++- | ||
68 | util/vfio-helpers.c | 43 +++++---- | ||
69 | block/trace-events | 30 ++++--- | ||
70 | util/trace-events | 10 ++- | ||
71 | 8 files changed, 195 insertions(+), 134 deletions(-) | ||
72 | 42 | ||
73 | -- | 43 | -- |
74 | 2.28.0 | 44 | 2.35.1 |
75 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: Elena Afanasova <eafanasova@gmail.com> | ||
2 | 1 | ||
3 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
4 | Signed-off-by: Elena Afanasova <eafanasova@gmail.com> | ||
5 | Message-Id: <20201017210102.26036-1-eafanasova@gmail.com> | ||
6 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
7 | --- | ||
8 | accel/kvm/kvm-all.c | 6 ++++-- | ||
9 | 1 file changed, 4 insertions(+), 2 deletions(-) | ||
10 | |||
11 | diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c | ||
12 | index XXXXXXX..XXXXXXX 100644 | ||
13 | --- a/accel/kvm/kvm-all.c | ||
14 | +++ b/accel/kvm/kvm-all.c | ||
15 | @@ -XXX,XX +XXX,XX @@ static int kvm_init(MachineState *ms) | ||
16 | |||
17 | kvm_memory_listener_register(s, &s->memory_listener, | ||
18 | &address_space_memory, 0); | ||
19 | - memory_listener_register(&kvm_io_listener, | ||
20 | - &address_space_io); | ||
21 | + if (kvm_eventfds_allowed) { | ||
22 | + memory_listener_register(&kvm_io_listener, | ||
23 | + &address_space_io); | ||
24 | + } | ||
25 | memory_listener_register(&kvm_coalesced_pio_listener, | ||
26 | &address_space_io); | ||
27 | |||
28 | -- | ||
29 | 2.28.0 | ||
30 | diff view generated by jsdifflib |
1 | From: Philippe Mathieu-Daudé <philmd@redhat.com> | 1 | From: Nicolas Saenz Julienne <nsaenzju@redhat.com> |
---|---|---|---|
2 | 2 | ||
3 | The QEMU_VFIO_DEBUG definition is only modifiable at build-time. | 3 | Introduce the 'event-loop-base' abstract class, it'll hold the |
4 | Trace events can be enabled at run-time. As we prefer the latter, | 4 | properties common to all event loops and provide the necessary hooks for |
5 | convert qemu_vfio_dump_mappings() to use trace events instead | 5 | their creation and maintenance. Then have iothread inherit from it. |
6 | of fprintf(). | 6 | |
7 | 7 | EventLoopBaseClass is defined as user creatable and provides a hook for | |
8 | Reviewed-by: Fam Zheng <fam@euphon.net> | 8 | its children to attach themselves to the user creatable class 'complete' |
9 | function. It also provides an update_params() callback to propagate | ||
10 | property changes onto its children. | ||
11 | |||
12 | The new 'event-loop-base' class will live in the root directory. It is | ||
13 | built on its own using the 'link_whole' option (there are no direct | ||
14 | function dependencies between the class and its children, it all happens | ||
15 | trough 'constructor' magic). And also imposes new compilation | ||
16 | dependencies: | ||
17 | |||
18 | qom <- event-loop-base <- blockdev (iothread.c) | ||
19 | |||
20 | And in subsequent patches: | ||
21 | |||
22 | qom <- event-loop-base <- qemuutil (util/main-loop.c) | ||
23 | |||
24 | All this forced some amount of reordering in meson.build: | ||
25 | |||
26 | - Moved qom build definition before qemuutil. Doing it the other way | ||
27 | around (i.e. moving qemuutil after qom) isn't possible as a lot of | ||
28 | core libraries that live in between the two depend on it. | ||
29 | |||
30 | - Process the 'hw' subdir earlier, as it introduces files into the | ||
31 | 'qom' source set. | ||
32 | |||
33 | No functional changes intended. | ||
34 | |||
35 | Signed-off-by: Nicolas Saenz Julienne <nsaenzju@redhat.com> | ||
9 | Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> | 36 | Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> |
10 | Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com> | 37 | Acked-by: Markus Armbruster <armbru@redhat.com> |
11 | Message-id: 20201103020733.2303148-7-philmd@redhat.com | 38 | Message-id: 20220425075723.20019-2-nsaenzju@redhat.com |
12 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | 39 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> |
13 | Tested-by: Eric Auger <eric.auger@redhat.com> | ||
14 | --- | 40 | --- |
15 | util/vfio-helpers.c | 19 ++++--------------- | 41 | qapi/qom.json | 22 +++++-- |
16 | util/trace-events | 1 + | 42 | meson.build | 23 ++++--- |
17 | 2 files changed, 5 insertions(+), 15 deletions(-) | 43 | include/sysemu/event-loop-base.h | 36 +++++++++++ |
18 | 44 | include/sysemu/iothread.h | 6 +- | |
19 | diff --git a/util/vfio-helpers.c b/util/vfio-helpers.c | 45 | event-loop-base.c | 104 +++++++++++++++++++++++++++++++ |
46 | iothread.c | 65 ++++++------------- | ||
47 | 6 files changed, 192 insertions(+), 64 deletions(-) | ||
48 | create mode 100644 include/sysemu/event-loop-base.h | ||
49 | create mode 100644 event-loop-base.c | ||
50 | |||
51 | diff --git a/qapi/qom.json b/qapi/qom.json | ||
20 | index XXXXXXX..XXXXXXX 100644 | 52 | index XXXXXXX..XXXXXXX 100644 |
21 | --- a/util/vfio-helpers.c | 53 | --- a/qapi/qom.json |
22 | +++ b/util/vfio-helpers.c | 54 | +++ b/qapi/qom.json |
23 | @@ -XXX,XX +XXX,XX @@ QEMUVFIOState *qemu_vfio_open_pci(const char *device, Error **errp) | 55 | @@ -XXX,XX +XXX,XX @@ |
24 | return s; | 56 | '*repeat': 'bool', |
57 | '*grab-toggle': 'GrabToggleKeys' } } | ||
58 | |||
59 | +## | ||
60 | +# @EventLoopBaseProperties: | ||
61 | +# | ||
62 | +# Common properties for event loops | ||
63 | +# | ||
64 | +# @aio-max-batch: maximum number of requests in a batch for the AIO engine, | ||
65 | +# 0 means that the engine will use its default. | ||
66 | +# (default: 0) | ||
67 | +# | ||
68 | +# Since: 7.1 | ||
69 | +## | ||
70 | +{ 'struct': 'EventLoopBaseProperties', | ||
71 | + 'data': { '*aio-max-batch': 'int' } } | ||
72 | + | ||
73 | ## | ||
74 | # @IothreadProperties: | ||
75 | # | ||
76 | @@ -XXX,XX +XXX,XX @@ | ||
77 | # algorithm detects it is spending too long polling without | ||
78 | # encountering events. 0 selects a default behaviour (default: 0) | ||
79 | # | ||
80 | -# @aio-max-batch: maximum number of requests in a batch for the AIO engine, | ||
81 | -# 0 means that the engine will use its default | ||
82 | -# (default:0, since 6.1) | ||
83 | +# The @aio-max-batch option is available since 6.1. | ||
84 | # | ||
85 | # Since: 2.0 | ||
86 | ## | ||
87 | { 'struct': 'IothreadProperties', | ||
88 | + 'base': 'EventLoopBaseProperties', | ||
89 | 'data': { '*poll-max-ns': 'int', | ||
90 | '*poll-grow': 'int', | ||
91 | - '*poll-shrink': 'int', | ||
92 | - '*aio-max-batch': 'int' } } | ||
93 | + '*poll-shrink': 'int' } } | ||
94 | |||
95 | ## | ||
96 | # @MemoryBackendProperties: | ||
97 | diff --git a/meson.build b/meson.build | ||
98 | index XXXXXXX..XXXXXXX 100644 | ||
99 | --- a/meson.build | ||
100 | +++ b/meson.build | ||
101 | @@ -XXX,XX +XXX,XX @@ subdir('qom') | ||
102 | subdir('authz') | ||
103 | subdir('crypto') | ||
104 | subdir('ui') | ||
105 | +subdir('hw') | ||
106 | |||
107 | |||
108 | if enable_modules | ||
109 | @@ -XXX,XX +XXX,XX @@ if enable_modules | ||
110 | modulecommon = declare_dependency(link_whole: libmodulecommon, compile_args: '-DBUILD_DSO') | ||
111 | endif | ||
112 | |||
113 | +qom_ss = qom_ss.apply(config_host, strict: false) | ||
114 | +libqom = static_library('qom', qom_ss.sources() + genh, | ||
115 | + dependencies: [qom_ss.dependencies()], | ||
116 | + name_suffix: 'fa') | ||
117 | +qom = declare_dependency(link_whole: libqom) | ||
118 | + | ||
119 | +event_loop_base = files('event-loop-base.c') | ||
120 | +event_loop_base = static_library('event-loop-base', sources: event_loop_base + genh, | ||
121 | + build_by_default: true) | ||
122 | +event_loop_base = declare_dependency(link_whole: event_loop_base, | ||
123 | + dependencies: [qom]) | ||
124 | + | ||
125 | stub_ss = stub_ss.apply(config_all, strict: false) | ||
126 | |||
127 | util_ss.add_all(trace_ss) | ||
128 | @@ -XXX,XX +XXX,XX @@ subdir('monitor') | ||
129 | subdir('net') | ||
130 | subdir('replay') | ||
131 | subdir('semihosting') | ||
132 | -subdir('hw') | ||
133 | subdir('tcg') | ||
134 | subdir('fpu') | ||
135 | subdir('accel') | ||
136 | @@ -XXX,XX +XXX,XX @@ qemu_syms = custom_target('qemu.syms', output: 'qemu.syms', | ||
137 | capture: true, | ||
138 | command: [undefsym, nm, '@INPUT@']) | ||
139 | |||
140 | -qom_ss = qom_ss.apply(config_host, strict: false) | ||
141 | -libqom = static_library('qom', qom_ss.sources() + genh, | ||
142 | - dependencies: [qom_ss.dependencies()], | ||
143 | - name_suffix: 'fa') | ||
144 | - | ||
145 | -qom = declare_dependency(link_whole: libqom) | ||
146 | - | ||
147 | authz_ss = authz_ss.apply(config_host, strict: false) | ||
148 | libauthz = static_library('authz', authz_ss.sources() + genh, | ||
149 | dependencies: [authz_ss.dependencies()], | ||
150 | @@ -XXX,XX +XXX,XX @@ libblockdev = static_library('blockdev', blockdev_ss.sources() + genh, | ||
151 | build_by_default: false) | ||
152 | |||
153 | blockdev = declare_dependency(link_whole: [libblockdev], | ||
154 | - dependencies: [block]) | ||
155 | + dependencies: [block, event_loop_base]) | ||
156 | |||
157 | qmp_ss = qmp_ss.apply(config_host, strict: false) | ||
158 | libqmp = static_library('qmp', qmp_ss.sources() + genh, | ||
159 | diff --git a/include/sysemu/event-loop-base.h b/include/sysemu/event-loop-base.h | ||
160 | new file mode 100644 | ||
161 | index XXXXXXX..XXXXXXX | ||
162 | --- /dev/null | ||
163 | +++ b/include/sysemu/event-loop-base.h | ||
164 | @@ -XXX,XX +XXX,XX @@ | ||
165 | +/* | ||
166 | + * QEMU event-loop backend | ||
167 | + * | ||
168 | + * Copyright (C) 2022 Red Hat Inc | ||
169 | + * | ||
170 | + * Authors: | ||
171 | + * Nicolas Saenz Julienne <nsaenzju@redhat.com> | ||
172 | + * | ||
173 | + * This work is licensed under the terms of the GNU GPL, version 2 or later. | ||
174 | + * See the COPYING file in the top-level directory. | ||
175 | + */ | ||
176 | +#ifndef QEMU_EVENT_LOOP_BASE_H | ||
177 | +#define QEMU_EVENT_LOOP_BASE_H | ||
178 | + | ||
179 | +#include "qom/object.h" | ||
180 | +#include "block/aio.h" | ||
181 | +#include "qemu/typedefs.h" | ||
182 | + | ||
183 | +#define TYPE_EVENT_LOOP_BASE "event-loop-base" | ||
184 | +OBJECT_DECLARE_TYPE(EventLoopBase, EventLoopBaseClass, | ||
185 | + EVENT_LOOP_BASE) | ||
186 | + | ||
187 | +struct EventLoopBaseClass { | ||
188 | + ObjectClass parent_class; | ||
189 | + | ||
190 | + void (*init)(EventLoopBase *base, Error **errp); | ||
191 | + void (*update_params)(EventLoopBase *base, Error **errp); | ||
192 | +}; | ||
193 | + | ||
194 | +struct EventLoopBase { | ||
195 | + Object parent; | ||
196 | + | ||
197 | + /* AioContext AIO engine parameters */ | ||
198 | + int64_t aio_max_batch; | ||
199 | +}; | ||
200 | +#endif | ||
201 | diff --git a/include/sysemu/iothread.h b/include/sysemu/iothread.h | ||
202 | index XXXXXXX..XXXXXXX 100644 | ||
203 | --- a/include/sysemu/iothread.h | ||
204 | +++ b/include/sysemu/iothread.h | ||
205 | @@ -XXX,XX +XXX,XX @@ | ||
206 | #include "block/aio.h" | ||
207 | #include "qemu/thread.h" | ||
208 | #include "qom/object.h" | ||
209 | +#include "sysemu/event-loop-base.h" | ||
210 | |||
211 | #define TYPE_IOTHREAD "iothread" | ||
212 | |||
213 | struct IOThread { | ||
214 | - Object parent_obj; | ||
215 | + EventLoopBase parent_obj; | ||
216 | |||
217 | QemuThread thread; | ||
218 | AioContext *ctx; | ||
219 | @@ -XXX,XX +XXX,XX @@ struct IOThread { | ||
220 | int64_t poll_max_ns; | ||
221 | int64_t poll_grow; | ||
222 | int64_t poll_shrink; | ||
223 | - | ||
224 | - /* AioContext AIO engine parameters */ | ||
225 | - int64_t aio_max_batch; | ||
226 | }; | ||
227 | typedef struct IOThread IOThread; | ||
228 | |||
229 | diff --git a/event-loop-base.c b/event-loop-base.c | ||
230 | new file mode 100644 | ||
231 | index XXXXXXX..XXXXXXX | ||
232 | --- /dev/null | ||
233 | +++ b/event-loop-base.c | ||
234 | @@ -XXX,XX +XXX,XX @@ | ||
235 | +/* | ||
236 | + * QEMU event-loop base | ||
237 | + * | ||
238 | + * Copyright (C) 2022 Red Hat Inc | ||
239 | + * | ||
240 | + * Authors: | ||
241 | + * Stefan Hajnoczi <stefanha@redhat.com> | ||
242 | + * Nicolas Saenz Julienne <nsaenzju@redhat.com> | ||
243 | + * | ||
244 | + * This work is licensed under the terms of the GNU GPL, version 2 or later. | ||
245 | + * See the COPYING file in the top-level directory. | ||
246 | + */ | ||
247 | + | ||
248 | +#include "qemu/osdep.h" | ||
249 | +#include "qom/object_interfaces.h" | ||
250 | +#include "qapi/error.h" | ||
251 | +#include "sysemu/event-loop-base.h" | ||
252 | + | ||
253 | +typedef struct { | ||
254 | + const char *name; | ||
255 | + ptrdiff_t offset; /* field's byte offset in EventLoopBase struct */ | ||
256 | +} EventLoopBaseParamInfo; | ||
257 | + | ||
258 | +static EventLoopBaseParamInfo aio_max_batch_info = { | ||
259 | + "aio-max-batch", offsetof(EventLoopBase, aio_max_batch), | ||
260 | +}; | ||
261 | + | ||
262 | +static void event_loop_base_get_param(Object *obj, Visitor *v, | ||
263 | + const char *name, void *opaque, Error **errp) | ||
264 | +{ | ||
265 | + EventLoopBase *event_loop_base = EVENT_LOOP_BASE(obj); | ||
266 | + EventLoopBaseParamInfo *info = opaque; | ||
267 | + int64_t *field = (void *)event_loop_base + info->offset; | ||
268 | + | ||
269 | + visit_type_int64(v, name, field, errp); | ||
270 | +} | ||
271 | + | ||
272 | +static void event_loop_base_set_param(Object *obj, Visitor *v, | ||
273 | + const char *name, void *opaque, Error **errp) | ||
274 | +{ | ||
275 | + EventLoopBaseClass *bc = EVENT_LOOP_BASE_GET_CLASS(obj); | ||
276 | + EventLoopBase *base = EVENT_LOOP_BASE(obj); | ||
277 | + EventLoopBaseParamInfo *info = opaque; | ||
278 | + int64_t *field = (void *)base + info->offset; | ||
279 | + int64_t value; | ||
280 | + | ||
281 | + if (!visit_type_int64(v, name, &value, errp)) { | ||
282 | + return; | ||
283 | + } | ||
284 | + | ||
285 | + if (value < 0) { | ||
286 | + error_setg(errp, "%s value must be in range [0, %" PRId64 "]", | ||
287 | + info->name, INT64_MAX); | ||
288 | + return; | ||
289 | + } | ||
290 | + | ||
291 | + *field = value; | ||
292 | + | ||
293 | + if (bc->update_params) { | ||
294 | + bc->update_params(base, errp); | ||
295 | + } | ||
296 | + | ||
297 | + return; | ||
298 | +} | ||
299 | + | ||
300 | +static void event_loop_base_complete(UserCreatable *uc, Error **errp) | ||
301 | +{ | ||
302 | + EventLoopBaseClass *bc = EVENT_LOOP_BASE_GET_CLASS(uc); | ||
303 | + EventLoopBase *base = EVENT_LOOP_BASE(uc); | ||
304 | + | ||
305 | + if (bc->init) { | ||
306 | + bc->init(base, errp); | ||
307 | + } | ||
308 | +} | ||
309 | + | ||
310 | +static void event_loop_base_class_init(ObjectClass *klass, void *class_data) | ||
311 | +{ | ||
312 | + UserCreatableClass *ucc = USER_CREATABLE_CLASS(klass); | ||
313 | + ucc->complete = event_loop_base_complete; | ||
314 | + | ||
315 | + object_class_property_add(klass, "aio-max-batch", "int", | ||
316 | + event_loop_base_get_param, | ||
317 | + event_loop_base_set_param, | ||
318 | + NULL, &aio_max_batch_info); | ||
319 | +} | ||
320 | + | ||
321 | +static const TypeInfo event_loop_base_info = { | ||
322 | + .name = TYPE_EVENT_LOOP_BASE, | ||
323 | + .parent = TYPE_OBJECT, | ||
324 | + .instance_size = sizeof(EventLoopBase), | ||
325 | + .class_size = sizeof(EventLoopBaseClass), | ||
326 | + .class_init = event_loop_base_class_init, | ||
327 | + .abstract = true, | ||
328 | + .interfaces = (InterfaceInfo[]) { | ||
329 | + { TYPE_USER_CREATABLE }, | ||
330 | + { } | ||
331 | + } | ||
332 | +}; | ||
333 | + | ||
334 | +static void register_types(void) | ||
335 | +{ | ||
336 | + type_register_static(&event_loop_base_info); | ||
337 | +} | ||
338 | +type_init(register_types); | ||
339 | diff --git a/iothread.c b/iothread.c | ||
340 | index XXXXXXX..XXXXXXX 100644 | ||
341 | --- a/iothread.c | ||
342 | +++ b/iothread.c | ||
343 | @@ -XXX,XX +XXX,XX @@ | ||
344 | #include "qemu/module.h" | ||
345 | #include "block/aio.h" | ||
346 | #include "block/block.h" | ||
347 | +#include "sysemu/event-loop-base.h" | ||
348 | #include "sysemu/iothread.h" | ||
349 | #include "qapi/error.h" | ||
350 | #include "qapi/qapi-commands-misc.h" | ||
351 | @@ -XXX,XX +XXX,XX @@ static void iothread_init_gcontext(IOThread *iothread) | ||
352 | iothread->main_loop = g_main_loop_new(iothread->worker_context, TRUE); | ||
25 | } | 353 | } |
26 | 354 | ||
27 | -static void qemu_vfio_dump_mapping(IOVAMapping *m) | 355 | -static void iothread_set_aio_context_params(IOThread *iothread, Error **errp) |
356 | +static void iothread_set_aio_context_params(EventLoopBase *base, Error **errp) | ||
357 | { | ||
358 | + IOThread *iothread = IOTHREAD(base); | ||
359 | ERRP_GUARD(); | ||
360 | |||
361 | + if (!iothread->ctx) { | ||
362 | + return; | ||
363 | + } | ||
364 | + | ||
365 | aio_context_set_poll_params(iothread->ctx, | ||
366 | iothread->poll_max_ns, | ||
367 | iothread->poll_grow, | ||
368 | @@ -XXX,XX +XXX,XX @@ static void iothread_set_aio_context_params(IOThread *iothread, Error **errp) | ||
369 | } | ||
370 | |||
371 | aio_context_set_aio_params(iothread->ctx, | ||
372 | - iothread->aio_max_batch, | ||
373 | + iothread->parent_obj.aio_max_batch, | ||
374 | errp); | ||
375 | } | ||
376 | |||
377 | -static void iothread_complete(UserCreatable *obj, Error **errp) | ||
378 | + | ||
379 | +static void iothread_init(EventLoopBase *base, Error **errp) | ||
380 | { | ||
381 | Error *local_error = NULL; | ||
382 | - IOThread *iothread = IOTHREAD(obj); | ||
383 | + IOThread *iothread = IOTHREAD(base); | ||
384 | char *thread_name; | ||
385 | |||
386 | iothread->stopping = false; | ||
387 | @@ -XXX,XX +XXX,XX @@ static void iothread_complete(UserCreatable *obj, Error **errp) | ||
388 | */ | ||
389 | iothread_init_gcontext(iothread); | ||
390 | |||
391 | - iothread_set_aio_context_params(iothread, &local_error); | ||
392 | + iothread_set_aio_context_params(base, &local_error); | ||
393 | if (local_error) { | ||
394 | error_propagate(errp, local_error); | ||
395 | aio_context_unref(iothread->ctx); | ||
396 | @@ -XXX,XX +XXX,XX @@ static void iothread_complete(UserCreatable *obj, Error **errp) | ||
397 | * to inherit. | ||
398 | */ | ||
399 | thread_name = g_strdup_printf("IO %s", | ||
400 | - object_get_canonical_path_component(OBJECT(obj))); | ||
401 | + object_get_canonical_path_component(OBJECT(base))); | ||
402 | qemu_thread_create(&iothread->thread, thread_name, iothread_run, | ||
403 | iothread, QEMU_THREAD_JOINABLE); | ||
404 | g_free(thread_name); | ||
405 | @@ -XXX,XX +XXX,XX @@ static IOThreadParamInfo poll_grow_info = { | ||
406 | static IOThreadParamInfo poll_shrink_info = { | ||
407 | "poll-shrink", offsetof(IOThread, poll_shrink), | ||
408 | }; | ||
409 | -static IOThreadParamInfo aio_max_batch_info = { | ||
410 | - "aio-max-batch", offsetof(IOThread, aio_max_batch), | ||
411 | -}; | ||
412 | |||
413 | static void iothread_get_param(Object *obj, Visitor *v, | ||
414 | const char *name, IOThreadParamInfo *info, Error **errp) | ||
415 | @@ -XXX,XX +XXX,XX @@ static void iothread_set_poll_param(Object *obj, Visitor *v, | ||
416 | } | ||
417 | } | ||
418 | |||
419 | -static void iothread_get_aio_param(Object *obj, Visitor *v, | ||
420 | - const char *name, void *opaque, Error **errp) | ||
28 | -{ | 421 | -{ |
29 | - if (QEMU_VFIO_DEBUG) { | 422 | - IOThreadParamInfo *info = opaque; |
30 | - printf(" vfio mapping %p %" PRIx64 " to %" PRIx64 "\n", m->host, | 423 | - |
31 | - (uint64_t)m->size, (uint64_t)m->iova); | 424 | - iothread_get_param(obj, v, name, info, errp); |
425 | -} | ||
426 | - | ||
427 | -static void iothread_set_aio_param(Object *obj, Visitor *v, | ||
428 | - const char *name, void *opaque, Error **errp) | ||
429 | -{ | ||
430 | - IOThread *iothread = IOTHREAD(obj); | ||
431 | - IOThreadParamInfo *info = opaque; | ||
432 | - | ||
433 | - if (!iothread_set_param(obj, v, name, info, errp)) { | ||
434 | - return; | ||
435 | - } | ||
436 | - | ||
437 | - if (iothread->ctx) { | ||
438 | - aio_context_set_aio_params(iothread->ctx, | ||
439 | - iothread->aio_max_batch, | ||
440 | - errp); | ||
32 | - } | 441 | - } |
33 | -} | 442 | -} |
34 | - | 443 | - |
35 | static void qemu_vfio_dump_mappings(QEMUVFIOState *s) | 444 | static void iothread_class_init(ObjectClass *klass, void *class_data) |
36 | { | 445 | { |
37 | - int i; | 446 | - UserCreatableClass *ucc = USER_CREATABLE_CLASS(klass); |
38 | - | 447 | - ucc->complete = iothread_complete; |
39 | - if (QEMU_VFIO_DEBUG) { | 448 | + EventLoopBaseClass *bc = EVENT_LOOP_BASE_CLASS(klass); |
40 | - printf("vfio mappings\n"); | 449 | + |
41 | - for (i = 0; i < s->nr_mappings; ++i) { | 450 | + bc->init = iothread_init; |
42 | - qemu_vfio_dump_mapping(&s->mappings[i]); | 451 | + bc->update_params = iothread_set_aio_context_params; |
43 | - } | 452 | |
44 | + for (int i = 0; i < s->nr_mappings; ++i) { | 453 | object_class_property_add(klass, "poll-max-ns", "int", |
45 | + trace_qemu_vfio_dump_mapping(s->mappings[i].host, | 454 | iothread_get_poll_param, |
46 | + s->mappings[i].iova, | 455 | @@ -XXX,XX +XXX,XX @@ static void iothread_class_init(ObjectClass *klass, void *class_data) |
47 | + s->mappings[i].size); | 456 | iothread_get_poll_param, |
48 | } | 457 | iothread_set_poll_param, |
458 | NULL, &poll_shrink_info); | ||
459 | - object_class_property_add(klass, "aio-max-batch", "int", | ||
460 | - iothread_get_aio_param, | ||
461 | - iothread_set_aio_param, | ||
462 | - NULL, &aio_max_batch_info); | ||
49 | } | 463 | } |
50 | 464 | ||
51 | diff --git a/util/trace-events b/util/trace-events | 465 | static const TypeInfo iothread_info = { |
52 | index XXXXXXX..XXXXXXX 100644 | 466 | .name = TYPE_IOTHREAD, |
53 | --- a/util/trace-events | 467 | - .parent = TYPE_OBJECT, |
54 | +++ b/util/trace-events | 468 | + .parent = TYPE_EVENT_LOOP_BASE, |
55 | @@ -XXX,XX +XXX,XX @@ qemu_mutex_unlock(void *mutex, const char *file, const int line) "released mutex | 469 | .class_init = iothread_class_init, |
56 | qemu_vfio_dma_reset_temporary(void *s) "s %p" | 470 | .instance_size = sizeof(IOThread), |
57 | qemu_vfio_ram_block_added(void *s, void *p, size_t size) "s %p host %p size 0x%zx" | 471 | .instance_init = iothread_instance_init, |
58 | qemu_vfio_ram_block_removed(void *s, void *p, size_t size) "s %p host %p size 0x%zx" | 472 | .instance_finalize = iothread_instance_finalize, |
59 | +qemu_vfio_dump_mapping(void *host, uint64_t iova, size_t size) "vfio mapping %p to iova 0x%08" PRIx64 " size 0x%zx" | 473 | - .interfaces = (InterfaceInfo[]) { |
60 | qemu_vfio_find_mapping(void *s, void *p) "s %p host %p" | 474 | - {TYPE_USER_CREATABLE}, |
61 | qemu_vfio_new_mapping(void *s, void *host, size_t size, int index, uint64_t iova) "s %p host %p size 0x%zx index %d iova 0x%"PRIx64 | 475 | - {} |
62 | qemu_vfio_do_mapping(void *s, void *host, uint64_t iova, size_t size) "s %p host %p <-> iova 0x%"PRIx64 " size 0x%zx" | 476 | - }, |
477 | }; | ||
478 | |||
479 | static void iothread_register_types(void) | ||
480 | @@ -XXX,XX +XXX,XX @@ static int query_one_iothread(Object *object, void *opaque) | ||
481 | info->poll_max_ns = iothread->poll_max_ns; | ||
482 | info->poll_grow = iothread->poll_grow; | ||
483 | info->poll_shrink = iothread->poll_shrink; | ||
484 | - info->aio_max_batch = iothread->aio_max_batch; | ||
485 | + info->aio_max_batch = iothread->parent_obj.aio_max_batch; | ||
486 | |||
487 | QAPI_LIST_APPEND(*tail, info); | ||
488 | return 0; | ||
63 | -- | 489 | -- |
64 | 2.28.0 | 490 | 2.35.1 |
65 | diff view generated by jsdifflib |
1 | From: Philippe Mathieu-Daudé <philmd@redhat.com> | 1 | From: Nicolas Saenz Julienne <nsaenzju@redhat.com> |
---|---|---|---|
2 | 2 | ||
3 | Just for consistency, following the example documented since | 3 | 'event-loop-base' provides basic property handling for all 'AioContext' |
4 | commit e3fe3988d7 ("error: Document Error API usage rules"), | 4 | based event loops. So let's define a new 'MainLoopClass' that inherits |
5 | return a boolean value indicating an error is set or not. | 5 | from it. This will permit tweaking the main loop's properties through |
6 | Directly pass errp as the local_err is not requested in our | 6 | qapi as well as through the command line using the '-object' keyword[1]. |
7 | case. | 7 | Only one instance of 'MainLoopClass' might be created at any time. |
8 | 8 | ||
9 | Tested-by: Eric Auger <eric.auger@redhat.com> | 9 | 'EventLoopBaseClass' learns a new callback, 'can_be_deleted()' so as to |
10 | Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com> | 10 | mark 'MainLoop' as non-deletable. |
11 | |||
12 | [1] For example: | ||
13 | -object main-loop,id=main-loop,aio-max-batch=<value> | ||
14 | |||
15 | Signed-off-by: Nicolas Saenz Julienne <nsaenzju@redhat.com> | ||
11 | Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> | 16 | Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> |
12 | Message-id: 20201029093306.1063879-11-philmd@redhat.com | 17 | Acked-by: Markus Armbruster <armbru@redhat.com> |
18 | Message-id: 20220425075723.20019-3-nsaenzju@redhat.com | ||
13 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | 19 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> |
14 | Tested-by: Eric Auger <eric.auger@redhat.com> | ||
15 | --- | 20 | --- |
16 | block/nvme.c | 12 +++++++----- | 21 | qapi/qom.json | 13 ++++++++ |
17 | 1 file changed, 7 insertions(+), 5 deletions(-) | 22 | meson.build | 3 +- |
18 | 23 | include/qemu/main-loop.h | 10 ++++++ | |
19 | diff --git a/block/nvme.c b/block/nvme.c | 24 | include/sysemu/event-loop-base.h | 1 + |
20 | index XXXXXXX..XXXXXXX 100644 | 25 | event-loop-base.c | 13 ++++++++ |
21 | --- a/block/nvme.c | 26 | util/main-loop.c | 56 ++++++++++++++++++++++++++++++++ |
22 | +++ b/block/nvme.c | 27 | 6 files changed, 95 insertions(+), 1 deletion(-) |
23 | @@ -XXX,XX +XXX,XX @@ static int nvme_cmd_sync(BlockDriverState *bs, NVMeQueuePair *q, | 28 | |
24 | return ret; | 29 | diff --git a/qapi/qom.json b/qapi/qom.json |
30 | index XXXXXXX..XXXXXXX 100644 | ||
31 | --- a/qapi/qom.json | ||
32 | +++ b/qapi/qom.json | ||
33 | @@ -XXX,XX +XXX,XX @@ | ||
34 | '*poll-grow': 'int', | ||
35 | '*poll-shrink': 'int' } } | ||
36 | |||
37 | +## | ||
38 | +# @MainLoopProperties: | ||
39 | +# | ||
40 | +# Properties for the main-loop object. | ||
41 | +# | ||
42 | +# Since: 7.1 | ||
43 | +## | ||
44 | +{ 'struct': 'MainLoopProperties', | ||
45 | + 'base': 'EventLoopBaseProperties', | ||
46 | + 'data': {} } | ||
47 | + | ||
48 | ## | ||
49 | # @MemoryBackendProperties: | ||
50 | # | ||
51 | @@ -XXX,XX +XXX,XX @@ | ||
52 | { 'name': 'input-linux', | ||
53 | 'if': 'CONFIG_LINUX' }, | ||
54 | 'iothread', | ||
55 | + 'main-loop', | ||
56 | { 'name': 'memory-backend-epc', | ||
57 | 'if': 'CONFIG_LINUX' }, | ||
58 | 'memory-backend-file', | ||
59 | @@ -XXX,XX +XXX,XX @@ | ||
60 | 'input-linux': { 'type': 'InputLinuxProperties', | ||
61 | 'if': 'CONFIG_LINUX' }, | ||
62 | 'iothread': 'IothreadProperties', | ||
63 | + 'main-loop': 'MainLoopProperties', | ||
64 | 'memory-backend-epc': { 'type': 'MemoryBackendEpcProperties', | ||
65 | 'if': 'CONFIG_LINUX' }, | ||
66 | 'memory-backend-file': 'MemoryBackendFileProperties', | ||
67 | diff --git a/meson.build b/meson.build | ||
68 | index XXXXXXX..XXXXXXX 100644 | ||
69 | --- a/meson.build | ||
70 | +++ b/meson.build | ||
71 | @@ -XXX,XX +XXX,XX @@ libqemuutil = static_library('qemuutil', | ||
72 | sources: util_ss.sources() + stub_ss.sources() + genh, | ||
73 | dependencies: [util_ss.dependencies(), libm, threads, glib, socket, malloc, pixman]) | ||
74 | qemuutil = declare_dependency(link_with: libqemuutil, | ||
75 | - sources: genh + version_res) | ||
76 | + sources: genh + version_res, | ||
77 | + dependencies: [event_loop_base]) | ||
78 | |||
79 | if have_system or have_user | ||
80 | decodetree = generator(find_program('scripts/decodetree.py'), | ||
81 | diff --git a/include/qemu/main-loop.h b/include/qemu/main-loop.h | ||
82 | index XXXXXXX..XXXXXXX 100644 | ||
83 | --- a/include/qemu/main-loop.h | ||
84 | +++ b/include/qemu/main-loop.h | ||
85 | @@ -XXX,XX +XXX,XX @@ | ||
86 | #define QEMU_MAIN_LOOP_H | ||
87 | |||
88 | #include "block/aio.h" | ||
89 | +#include "qom/object.h" | ||
90 | +#include "sysemu/event-loop-base.h" | ||
91 | |||
92 | #define SIG_IPI SIGUSR1 | ||
93 | |||
94 | +#define TYPE_MAIN_LOOP "main-loop" | ||
95 | +OBJECT_DECLARE_TYPE(MainLoop, MainLoopClass, MAIN_LOOP) | ||
96 | + | ||
97 | +struct MainLoop { | ||
98 | + EventLoopBase parent_obj; | ||
99 | +}; | ||
100 | +typedef struct MainLoop MainLoop; | ||
101 | + | ||
102 | /** | ||
103 | * qemu_init_main_loop: Set up the process so that it can run the main loop. | ||
104 | * | ||
105 | diff --git a/include/sysemu/event-loop-base.h b/include/sysemu/event-loop-base.h | ||
106 | index XXXXXXX..XXXXXXX 100644 | ||
107 | --- a/include/sysemu/event-loop-base.h | ||
108 | +++ b/include/sysemu/event-loop-base.h | ||
109 | @@ -XXX,XX +XXX,XX @@ struct EventLoopBaseClass { | ||
110 | |||
111 | void (*init)(EventLoopBase *base, Error **errp); | ||
112 | void (*update_params)(EventLoopBase *base, Error **errp); | ||
113 | + bool (*can_be_deleted)(EventLoopBase *base); | ||
114 | }; | ||
115 | |||
116 | struct EventLoopBase { | ||
117 | diff --git a/event-loop-base.c b/event-loop-base.c | ||
118 | index XXXXXXX..XXXXXXX 100644 | ||
119 | --- a/event-loop-base.c | ||
120 | +++ b/event-loop-base.c | ||
121 | @@ -XXX,XX +XXX,XX @@ static void event_loop_base_complete(UserCreatable *uc, Error **errp) | ||
122 | } | ||
25 | } | 123 | } |
26 | 124 | ||
27 | -static void nvme_identify(BlockDriverState *bs, int namespace, Error **errp) | 125 | +static bool event_loop_base_can_be_deleted(UserCreatable *uc) |
28 | +/* Returns true on success, false on failure. */ | 126 | +{ |
29 | +static bool nvme_identify(BlockDriverState *bs, int namespace, Error **errp) | 127 | + EventLoopBaseClass *bc = EVENT_LOOP_BASE_GET_CLASS(uc); |
128 | + EventLoopBase *backend = EVENT_LOOP_BASE(uc); | ||
129 | + | ||
130 | + if (bc->can_be_deleted) { | ||
131 | + return bc->can_be_deleted(backend); | ||
132 | + } | ||
133 | + | ||
134 | + return true; | ||
135 | +} | ||
136 | + | ||
137 | static void event_loop_base_class_init(ObjectClass *klass, void *class_data) | ||
30 | { | 138 | { |
31 | BDRVNVMeState *s = bs->opaque; | 139 | UserCreatableClass *ucc = USER_CREATABLE_CLASS(klass); |
32 | + bool ret = false; | 140 | ucc->complete = event_loop_base_complete; |
33 | union { | 141 | + ucc->can_be_deleted = event_loop_base_can_be_deleted; |
34 | NvmeIdCtrl ctrl; | 142 | |
35 | NvmeIdNs ns; | 143 | object_class_property_add(klass, "aio-max-batch", "int", |
36 | @@ -XXX,XX +XXX,XX @@ static void nvme_identify(BlockDriverState *bs, int namespace, Error **errp) | 144 | event_loop_base_get_param, |
37 | goto out; | 145 | diff --git a/util/main-loop.c b/util/main-loop.c |
38 | } | 146 | index XXXXXXX..XXXXXXX 100644 |
39 | 147 | --- a/util/main-loop.c | |
40 | + ret = true; | 148 | +++ b/util/main-loop.c |
41 | s->blkshift = lbaf->ds; | 149 | @@ -XXX,XX +XXX,XX @@ |
42 | out: | 150 | #include "qemu/error-report.h" |
43 | qemu_vfio_dma_unmap(s->vfio, id); | 151 | #include "qemu/queue.h" |
44 | qemu_vfree(id); | 152 | #include "qemu/compiler.h" |
45 | + | 153 | +#include "qom/object.h" |
46 | + return ret; | 154 | |
155 | #ifndef _WIN32 | ||
156 | #include <sys/wait.h> | ||
157 | @@ -XXX,XX +XXX,XX @@ int qemu_init_main_loop(Error **errp) | ||
158 | return 0; | ||
47 | } | 159 | } |
48 | 160 | ||
49 | static bool nvme_poll_queue(NVMeQueuePair *q) | 161 | +static void main_loop_update_params(EventLoopBase *base, Error **errp) |
50 | @@ -XXX,XX +XXX,XX @@ static int nvme_init(BlockDriverState *bs, const char *device, int namespace, | 162 | +{ |
51 | uint64_t cap; | 163 | + if (!qemu_aio_context) { |
52 | uint64_t timeout_ms; | 164 | + error_setg(errp, "qemu aio context not ready"); |
53 | uint64_t deadline, now; | 165 | + return; |
54 | - Error *local_err = NULL; | 166 | + } |
55 | volatile NvmeBar *regs = NULL; | 167 | + |
56 | 168 | + aio_context_set_aio_params(qemu_aio_context, base->aio_max_batch, errp); | |
57 | qemu_co_mutex_init(&s->dma_map_lock); | 169 | +} |
58 | @@ -XXX,XX +XXX,XX @@ static int nvme_init(BlockDriverState *bs, const char *device, int namespace, | 170 | + |
59 | &s->irq_notifier[MSIX_SHARED_IRQ_IDX], | 171 | +MainLoop *mloop; |
60 | false, nvme_handle_event, nvme_poll_cb); | 172 | + |
61 | 173 | +static void main_loop_init(EventLoopBase *base, Error **errp) | |
62 | - nvme_identify(bs, namespace, &local_err); | 174 | +{ |
63 | - if (local_err) { | 175 | + MainLoop *m = MAIN_LOOP(base); |
64 | - error_propagate(errp, local_err); | 176 | + |
65 | + if (!nvme_identify(bs, namespace, errp)) { | 177 | + if (mloop) { |
66 | ret = -EIO; | 178 | + error_setg(errp, "only one main-loop instance allowed"); |
67 | goto out; | 179 | + return; |
68 | } | 180 | + } |
181 | + | ||
182 | + main_loop_update_params(base, errp); | ||
183 | + | ||
184 | + mloop = m; | ||
185 | + return; | ||
186 | +} | ||
187 | + | ||
188 | +static bool main_loop_can_be_deleted(EventLoopBase *base) | ||
189 | +{ | ||
190 | + return false; | ||
191 | +} | ||
192 | + | ||
193 | +static void main_loop_class_init(ObjectClass *oc, void *class_data) | ||
194 | +{ | ||
195 | + EventLoopBaseClass *bc = EVENT_LOOP_BASE_CLASS(oc); | ||
196 | + | ||
197 | + bc->init = main_loop_init; | ||
198 | + bc->update_params = main_loop_update_params; | ||
199 | + bc->can_be_deleted = main_loop_can_be_deleted; | ||
200 | +} | ||
201 | + | ||
202 | +static const TypeInfo main_loop_info = { | ||
203 | + .name = TYPE_MAIN_LOOP, | ||
204 | + .parent = TYPE_EVENT_LOOP_BASE, | ||
205 | + .class_init = main_loop_class_init, | ||
206 | + .instance_size = sizeof(MainLoop), | ||
207 | +}; | ||
208 | + | ||
209 | +static void main_loop_register_types(void) | ||
210 | +{ | ||
211 | + type_register_static(&main_loop_info); | ||
212 | +} | ||
213 | + | ||
214 | +type_init(main_loop_register_types) | ||
215 | + | ||
216 | static int max_priority; | ||
217 | |||
218 | #ifndef _WIN32 | ||
69 | -- | 219 | -- |
70 | 2.28.0 | 220 | 2.35.1 |
71 | diff view generated by jsdifflib |
1 | From: Elena Afanasova <eafanasova@gmail.com> | 1 | From: Nicolas Saenz Julienne <nsaenzju@redhat.com> |
---|---|---|---|
2 | 2 | ||
3 | Eventfd can be registered with a zero length when fast_mmio is true. | 3 | The thread pool regulates itself: when idle, it kills threads until |
4 | Handle this case properly when dispatching through QEMU. | 4 | empty, when in demand, it creates new threads until full. This behaviour |
5 | doesn't play well with latency sensitive workloads where the price of | ||
6 | creating a new thread is too high. For example, when paired with qemu's | ||
7 | '-mlock', or using safety features like SafeStack, creating a new thread | ||
8 | has been measured take multiple milliseconds. | ||
5 | 9 | ||
6 | Signed-off-by: Elena Afanasova <eafanasova@gmail.com> | 10 | In order to mitigate this let's introduce a new 'EventLoopBase' |
7 | Message-id: cf71a62eb04e61932ff8ffdd02e0b2aab4f495a0.camel@gmail.com | 11 | property to set the thread pool size. The threads will be created during |
12 | the pool's initialization or upon updating the property's value, remain | ||
13 | available during its lifetime regardless of demand, and destroyed upon | ||
14 | freeing it. A properly characterized workload will then be able to | ||
15 | configure the pool to avoid any latency spikes. | ||
16 | |||
17 | Signed-off-by: Nicolas Saenz Julienne <nsaenzju@redhat.com> | ||
18 | Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
19 | Acked-by: Markus Armbruster <armbru@redhat.com> | ||
20 | Message-id: 20220425075723.20019-4-nsaenzju@redhat.com | ||
8 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | 21 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> |
9 | --- | 22 | --- |
10 | softmmu/memory.c | 11 +++++++++-- | 23 | qapi/qom.json | 10 +++++- |
11 | 1 file changed, 9 insertions(+), 2 deletions(-) | 24 | include/block/aio.h | 10 ++++++ |
25 | include/block/thread-pool.h | 3 ++ | ||
26 | include/sysemu/event-loop-base.h | 4 +++ | ||
27 | event-loop-base.c | 23 +++++++++++++ | ||
28 | iothread.c | 3 ++ | ||
29 | util/aio-posix.c | 1 + | ||
30 | util/async.c | 20 ++++++++++++ | ||
31 | util/main-loop.c | 9 ++++++ | ||
32 | util/thread-pool.c | 55 +++++++++++++++++++++++++++++--- | ||
33 | 10 files changed, 133 insertions(+), 5 deletions(-) | ||
12 | 34 | ||
13 | diff --git a/softmmu/memory.c b/softmmu/memory.c | 35 | diff --git a/qapi/qom.json b/qapi/qom.json |
14 | index XXXXXXX..XXXXXXX 100644 | 36 | index XXXXXXX..XXXXXXX 100644 |
15 | --- a/softmmu/memory.c | 37 | --- a/qapi/qom.json |
16 | +++ b/softmmu/memory.c | 38 | +++ b/qapi/qom.json |
17 | @@ -XXX,XX +XXX,XX @@ static bool memory_region_ioeventfd_before(MemoryRegionIoeventfd *a, | 39 | @@ -XXX,XX +XXX,XX @@ |
18 | static bool memory_region_ioeventfd_equal(MemoryRegionIoeventfd *a, | 40 | # 0 means that the engine will use its default. |
19 | MemoryRegionIoeventfd *b) | 41 | # (default: 0) |
42 | # | ||
43 | +# @thread-pool-min: minimum number of threads reserved in the thread pool | ||
44 | +# (default:0) | ||
45 | +# | ||
46 | +# @thread-pool-max: maximum number of threads the thread pool can contain | ||
47 | +# (default:64) | ||
48 | +# | ||
49 | # Since: 7.1 | ||
50 | ## | ||
51 | { 'struct': 'EventLoopBaseProperties', | ||
52 | - 'data': { '*aio-max-batch': 'int' } } | ||
53 | + 'data': { '*aio-max-batch': 'int', | ||
54 | + '*thread-pool-min': 'int', | ||
55 | + '*thread-pool-max': 'int' } } | ||
56 | |||
57 | ## | ||
58 | # @IothreadProperties: | ||
59 | diff --git a/include/block/aio.h b/include/block/aio.h | ||
60 | index XXXXXXX..XXXXXXX 100644 | ||
61 | --- a/include/block/aio.h | ||
62 | +++ b/include/block/aio.h | ||
63 | @@ -XXX,XX +XXX,XX @@ struct AioContext { | ||
64 | QSLIST_HEAD(, Coroutine) scheduled_coroutines; | ||
65 | QEMUBH *co_schedule_bh; | ||
66 | |||
67 | + int thread_pool_min; | ||
68 | + int thread_pool_max; | ||
69 | /* Thread pool for performing work and receiving completion callbacks. | ||
70 | * Has its own locking. | ||
71 | */ | ||
72 | @@ -XXX,XX +XXX,XX @@ void aio_context_set_poll_params(AioContext *ctx, int64_t max_ns, | ||
73 | void aio_context_set_aio_params(AioContext *ctx, int64_t max_batch, | ||
74 | Error **errp); | ||
75 | |||
76 | +/** | ||
77 | + * aio_context_set_thread_pool_params: | ||
78 | + * @ctx: the aio context | ||
79 | + * @min: min number of threads to have readily available in the thread pool | ||
80 | + * @min: max number of threads the thread pool can contain | ||
81 | + */ | ||
82 | +void aio_context_set_thread_pool_params(AioContext *ctx, int64_t min, | ||
83 | + int64_t max, Error **errp); | ||
84 | #endif | ||
85 | diff --git a/include/block/thread-pool.h b/include/block/thread-pool.h | ||
86 | index XXXXXXX..XXXXXXX 100644 | ||
87 | --- a/include/block/thread-pool.h | ||
88 | +++ b/include/block/thread-pool.h | ||
89 | @@ -XXX,XX +XXX,XX @@ | ||
90 | |||
91 | #include "block/block.h" | ||
92 | |||
93 | +#define THREAD_POOL_MAX_THREADS_DEFAULT 64 | ||
94 | + | ||
95 | typedef int ThreadPoolFunc(void *opaque); | ||
96 | |||
97 | typedef struct ThreadPool ThreadPool; | ||
98 | @@ -XXX,XX +XXX,XX @@ BlockAIOCB *thread_pool_submit_aio(ThreadPool *pool, | ||
99 | int coroutine_fn thread_pool_submit_co(ThreadPool *pool, | ||
100 | ThreadPoolFunc *func, void *arg); | ||
101 | void thread_pool_submit(ThreadPool *pool, ThreadPoolFunc *func, void *arg); | ||
102 | +void thread_pool_update_params(ThreadPool *pool, struct AioContext *ctx); | ||
103 | |||
104 | #endif | ||
105 | diff --git a/include/sysemu/event-loop-base.h b/include/sysemu/event-loop-base.h | ||
106 | index XXXXXXX..XXXXXXX 100644 | ||
107 | --- a/include/sysemu/event-loop-base.h | ||
108 | +++ b/include/sysemu/event-loop-base.h | ||
109 | @@ -XXX,XX +XXX,XX @@ struct EventLoopBase { | ||
110 | |||
111 | /* AioContext AIO engine parameters */ | ||
112 | int64_t aio_max_batch; | ||
113 | + | ||
114 | + /* AioContext thread pool parameters */ | ||
115 | + int64_t thread_pool_min; | ||
116 | + int64_t thread_pool_max; | ||
117 | }; | ||
118 | #endif | ||
119 | diff --git a/event-loop-base.c b/event-loop-base.c | ||
120 | index XXXXXXX..XXXXXXX 100644 | ||
121 | --- a/event-loop-base.c | ||
122 | +++ b/event-loop-base.c | ||
123 | @@ -XXX,XX +XXX,XX @@ | ||
124 | #include "qemu/osdep.h" | ||
125 | #include "qom/object_interfaces.h" | ||
126 | #include "qapi/error.h" | ||
127 | +#include "block/thread-pool.h" | ||
128 | #include "sysemu/event-loop-base.h" | ||
129 | |||
130 | typedef struct { | ||
131 | @@ -XXX,XX +XXX,XX @@ typedef struct { | ||
132 | ptrdiff_t offset; /* field's byte offset in EventLoopBase struct */ | ||
133 | } EventLoopBaseParamInfo; | ||
134 | |||
135 | +static void event_loop_base_instance_init(Object *obj) | ||
136 | +{ | ||
137 | + EventLoopBase *base = EVENT_LOOP_BASE(obj); | ||
138 | + | ||
139 | + base->thread_pool_max = THREAD_POOL_MAX_THREADS_DEFAULT; | ||
140 | +} | ||
141 | + | ||
142 | static EventLoopBaseParamInfo aio_max_batch_info = { | ||
143 | "aio-max-batch", offsetof(EventLoopBase, aio_max_batch), | ||
144 | }; | ||
145 | +static EventLoopBaseParamInfo thread_pool_min_info = { | ||
146 | + "thread-pool-min", offsetof(EventLoopBase, thread_pool_min), | ||
147 | +}; | ||
148 | +static EventLoopBaseParamInfo thread_pool_max_info = { | ||
149 | + "thread-pool-max", offsetof(EventLoopBase, thread_pool_max), | ||
150 | +}; | ||
151 | |||
152 | static void event_loop_base_get_param(Object *obj, Visitor *v, | ||
153 | const char *name, void *opaque, Error **errp) | ||
154 | @@ -XXX,XX +XXX,XX @@ static void event_loop_base_class_init(ObjectClass *klass, void *class_data) | ||
155 | event_loop_base_get_param, | ||
156 | event_loop_base_set_param, | ||
157 | NULL, &aio_max_batch_info); | ||
158 | + object_class_property_add(klass, "thread-pool-min", "int", | ||
159 | + event_loop_base_get_param, | ||
160 | + event_loop_base_set_param, | ||
161 | + NULL, &thread_pool_min_info); | ||
162 | + object_class_property_add(klass, "thread-pool-max", "int", | ||
163 | + event_loop_base_get_param, | ||
164 | + event_loop_base_set_param, | ||
165 | + NULL, &thread_pool_max_info); | ||
166 | } | ||
167 | |||
168 | static const TypeInfo event_loop_base_info = { | ||
169 | .name = TYPE_EVENT_LOOP_BASE, | ||
170 | .parent = TYPE_OBJECT, | ||
171 | .instance_size = sizeof(EventLoopBase), | ||
172 | + .instance_init = event_loop_base_instance_init, | ||
173 | .class_size = sizeof(EventLoopBaseClass), | ||
174 | .class_init = event_loop_base_class_init, | ||
175 | .abstract = true, | ||
176 | diff --git a/iothread.c b/iothread.c | ||
177 | index XXXXXXX..XXXXXXX 100644 | ||
178 | --- a/iothread.c | ||
179 | +++ b/iothread.c | ||
180 | @@ -XXX,XX +XXX,XX @@ static void iothread_set_aio_context_params(EventLoopBase *base, Error **errp) | ||
181 | aio_context_set_aio_params(iothread->ctx, | ||
182 | iothread->parent_obj.aio_max_batch, | ||
183 | errp); | ||
184 | + | ||
185 | + aio_context_set_thread_pool_params(iothread->ctx, base->thread_pool_min, | ||
186 | + base->thread_pool_max, errp); | ||
187 | } | ||
188 | |||
189 | |||
190 | diff --git a/util/aio-posix.c b/util/aio-posix.c | ||
191 | index XXXXXXX..XXXXXXX 100644 | ||
192 | --- a/util/aio-posix.c | ||
193 | +++ b/util/aio-posix.c | ||
194 | @@ -XXX,XX +XXX,XX @@ | ||
195 | |||
196 | #include "qemu/osdep.h" | ||
197 | #include "block/block.h" | ||
198 | +#include "block/thread-pool.h" | ||
199 | #include "qemu/main-loop.h" | ||
200 | #include "qemu/rcu.h" | ||
201 | #include "qemu/rcu_queue.h" | ||
202 | diff --git a/util/async.c b/util/async.c | ||
203 | index XXXXXXX..XXXXXXX 100644 | ||
204 | --- a/util/async.c | ||
205 | +++ b/util/async.c | ||
206 | @@ -XXX,XX +XXX,XX @@ AioContext *aio_context_new(Error **errp) | ||
207 | |||
208 | ctx->aio_max_batch = 0; | ||
209 | |||
210 | + ctx->thread_pool_min = 0; | ||
211 | + ctx->thread_pool_max = THREAD_POOL_MAX_THREADS_DEFAULT; | ||
212 | + | ||
213 | return ctx; | ||
214 | fail: | ||
215 | g_source_destroy(&ctx->source); | ||
216 | @@ -XXX,XX +XXX,XX @@ void qemu_set_current_aio_context(AioContext *ctx) | ||
217 | assert(!get_my_aiocontext()); | ||
218 | set_my_aiocontext(ctx); | ||
219 | } | ||
220 | + | ||
221 | +void aio_context_set_thread_pool_params(AioContext *ctx, int64_t min, | ||
222 | + int64_t max, Error **errp) | ||
223 | +{ | ||
224 | + | ||
225 | + if (min > max || !max || min > INT_MAX || max > INT_MAX) { | ||
226 | + error_setg(errp, "bad thread-pool-min/thread-pool-max values"); | ||
227 | + return; | ||
228 | + } | ||
229 | + | ||
230 | + ctx->thread_pool_min = min; | ||
231 | + ctx->thread_pool_max = max; | ||
232 | + | ||
233 | + if (ctx->thread_pool) { | ||
234 | + thread_pool_update_params(ctx->thread_pool, ctx); | ||
235 | + } | ||
236 | +} | ||
237 | diff --git a/util/main-loop.c b/util/main-loop.c | ||
238 | index XXXXXXX..XXXXXXX 100644 | ||
239 | --- a/util/main-loop.c | ||
240 | +++ b/util/main-loop.c | ||
241 | @@ -XXX,XX +XXX,XX @@ | ||
242 | #include "sysemu/replay.h" | ||
243 | #include "qemu/main-loop.h" | ||
244 | #include "block/aio.h" | ||
245 | +#include "block/thread-pool.h" | ||
246 | #include "qemu/error-report.h" | ||
247 | #include "qemu/queue.h" | ||
248 | #include "qemu/compiler.h" | ||
249 | @@ -XXX,XX +XXX,XX @@ int qemu_init_main_loop(Error **errp) | ||
250 | |||
251 | static void main_loop_update_params(EventLoopBase *base, Error **errp) | ||
20 | { | 252 | { |
21 | - return !memory_region_ioeventfd_before(a, b) | 253 | + ERRP_GUARD(); |
22 | - && !memory_region_ioeventfd_before(b, a); | 254 | + |
23 | + if (int128_eq(a->addr.start, b->addr.start) && | 255 | if (!qemu_aio_context) { |
24 | + (!int128_nz(a->addr.size) || !int128_nz(b->addr.size) || | 256 | error_setg(errp, "qemu aio context not ready"); |
25 | + (int128_eq(a->addr.size, b->addr.size) && | 257 | return; |
26 | + (a->match_data == b->match_data) && | 258 | } |
27 | + ((a->match_data && (a->data == b->data)) || !a->match_data) && | 259 | |
28 | + (a->e == b->e)))) | 260 | aio_context_set_aio_params(qemu_aio_context, base->aio_max_batch, errp); |
29 | + return true; | 261 | + if (*errp) { |
262 | + return; | ||
263 | + } | ||
264 | + | ||
265 | + aio_context_set_thread_pool_params(qemu_aio_context, base->thread_pool_min, | ||
266 | + base->thread_pool_max, errp); | ||
267 | } | ||
268 | |||
269 | MainLoop *mloop; | ||
270 | diff --git a/util/thread-pool.c b/util/thread-pool.c | ||
271 | index XXXXXXX..XXXXXXX 100644 | ||
272 | --- a/util/thread-pool.c | ||
273 | +++ b/util/thread-pool.c | ||
274 | @@ -XXX,XX +XXX,XX @@ struct ThreadPool { | ||
275 | QemuMutex lock; | ||
276 | QemuCond worker_stopped; | ||
277 | QemuSemaphore sem; | ||
278 | - int max_threads; | ||
279 | QEMUBH *new_thread_bh; | ||
280 | |||
281 | /* The following variables are only accessed from one AioContext. */ | ||
282 | @@ -XXX,XX +XXX,XX @@ struct ThreadPool { | ||
283 | int new_threads; /* backlog of threads we need to create */ | ||
284 | int pending_threads; /* threads created but not running yet */ | ||
285 | bool stopping; | ||
286 | + int min_threads; | ||
287 | + int max_threads; | ||
288 | }; | ||
289 | |||
290 | +static inline bool back_to_sleep(ThreadPool *pool, int ret) | ||
291 | +{ | ||
292 | + /* | ||
293 | + * The semaphore timed out, we should exit the loop except when: | ||
294 | + * - There is work to do, we raced with the signal. | ||
295 | + * - The max threads threshold just changed, we raced with the signal. | ||
296 | + * - The thread pool forces a minimum number of readily available threads. | ||
297 | + */ | ||
298 | + if (ret == -1 && (!QTAILQ_EMPTY(&pool->request_list) || | ||
299 | + pool->cur_threads > pool->max_threads || | ||
300 | + pool->cur_threads <= pool->min_threads)) { | ||
301 | + return true; | ||
302 | + } | ||
30 | + | 303 | + |
31 | + return false; | 304 | + return false; |
32 | } | 305 | +} |
33 | 306 | + | |
34 | /* Range of memory in the global map. Addresses are absolute. */ | 307 | static void *worker_thread(void *opaque) |
308 | { | ||
309 | ThreadPool *pool = opaque; | ||
310 | @@ -XXX,XX +XXX,XX @@ static void *worker_thread(void *opaque) | ||
311 | ret = qemu_sem_timedwait(&pool->sem, 10000); | ||
312 | qemu_mutex_lock(&pool->lock); | ||
313 | pool->idle_threads--; | ||
314 | - } while (ret == -1 && !QTAILQ_EMPTY(&pool->request_list)); | ||
315 | - if (ret == -1 || pool->stopping) { | ||
316 | + } while (back_to_sleep(pool, ret)); | ||
317 | + if (ret == -1 || pool->stopping || | ||
318 | + pool->cur_threads > pool->max_threads) { | ||
319 | break; | ||
320 | } | ||
321 | |||
322 | @@ -XXX,XX +XXX,XX @@ void thread_pool_submit(ThreadPool *pool, ThreadPoolFunc *func, void *arg) | ||
323 | thread_pool_submit_aio(pool, func, arg, NULL, NULL); | ||
324 | } | ||
325 | |||
326 | +void thread_pool_update_params(ThreadPool *pool, AioContext *ctx) | ||
327 | +{ | ||
328 | + qemu_mutex_lock(&pool->lock); | ||
329 | + | ||
330 | + pool->min_threads = ctx->thread_pool_min; | ||
331 | + pool->max_threads = ctx->thread_pool_max; | ||
332 | + | ||
333 | + /* | ||
334 | + * We either have to: | ||
335 | + * - Increase the number available of threads until over the min_threads | ||
336 | + * threshold. | ||
337 | + * - Decrease the number of available threads until under the max_threads | ||
338 | + * threshold. | ||
339 | + * - Do nothing. The current number of threads fall in between the min and | ||
340 | + * max thresholds. We'll let the pool manage itself. | ||
341 | + */ | ||
342 | + for (int i = pool->cur_threads; i < pool->min_threads; i++) { | ||
343 | + spawn_thread(pool); | ||
344 | + } | ||
345 | + | ||
346 | + for (int i = pool->cur_threads; i > pool->max_threads; i--) { | ||
347 | + qemu_sem_post(&pool->sem); | ||
348 | + } | ||
349 | + | ||
350 | + qemu_mutex_unlock(&pool->lock); | ||
351 | +} | ||
352 | + | ||
353 | static void thread_pool_init_one(ThreadPool *pool, AioContext *ctx) | ||
354 | { | ||
355 | if (!ctx) { | ||
356 | @@ -XXX,XX +XXX,XX @@ static void thread_pool_init_one(ThreadPool *pool, AioContext *ctx) | ||
357 | qemu_mutex_init(&pool->lock); | ||
358 | qemu_cond_init(&pool->worker_stopped); | ||
359 | qemu_sem_init(&pool->sem, 0); | ||
360 | - pool->max_threads = 64; | ||
361 | pool->new_thread_bh = aio_bh_new(ctx, spawn_thread_bh_fn, pool); | ||
362 | |||
363 | QLIST_INIT(&pool->head); | ||
364 | QTAILQ_INIT(&pool->request_list); | ||
365 | + | ||
366 | + thread_pool_update_params(pool, ctx); | ||
367 | } | ||
368 | |||
369 | ThreadPool *thread_pool_new(AioContext *ctx) | ||
35 | -- | 370 | -- |
36 | 2.28.0 | 371 | 2.35.1 |
37 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: Philippe Mathieu-Daudé <philmd@redhat.com> | ||
2 | 1 | ||
3 | The "block/nvme.h" header is shared by both the NVMe block | ||
4 | driver and the NVMe emulated device. Add the 'F:' entry on | ||
5 | both sections, so all maintainers/reviewers are notified | ||
6 | when it is changed. | ||
7 | |||
8 | Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com> | ||
9 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
10 | Reviewed-by: Klaus Jensen <k.jensen@samsung.com> | ||
11 | Message-Id: <20200701140634.25994-1-philmd@redhat.com> | ||
12 | --- | ||
13 | MAINTAINERS | 2 ++ | ||
14 | 1 file changed, 2 insertions(+) | ||
15 | |||
16 | diff --git a/MAINTAINERS b/MAINTAINERS | ||
17 | index XXXXXXX..XXXXXXX 100644 | ||
18 | --- a/MAINTAINERS | ||
19 | +++ b/MAINTAINERS | ||
20 | @@ -XXX,XX +XXX,XX @@ M: Klaus Jensen <its@irrelevant.dk> | ||
21 | L: qemu-block@nongnu.org | ||
22 | S: Supported | ||
23 | F: hw/block/nvme* | ||
24 | +F: include/block/nvme.h | ||
25 | F: tests/qtest/nvme-test.c | ||
26 | F: docs/specs/nvme.txt | ||
27 | T: git git://git.infradead.org/qemu-nvme.git nvme-next | ||
28 | @@ -XXX,XX +XXX,XX @@ R: Fam Zheng <fam@euphon.net> | ||
29 | L: qemu-block@nongnu.org | ||
30 | S: Supported | ||
31 | F: block/nvme* | ||
32 | +F: include/block/nvme.h | ||
33 | T: git https://github.com/stefanha/qemu.git block | ||
34 | |||
35 | Bootdevice | ||
36 | -- | ||
37 | 2.28.0 | ||
38 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: Philippe Mathieu-Daudé <philmd@redhat.com> | ||
2 | 1 | ||
3 | Use the same format used for the hw/vfio/ trace events. | ||
4 | |||
5 | Suggested-by: Eric Auger <eric.auger@redhat.com> | ||
6 | Reviewed-by: Eric Auger <eric.auger@redhat.com> | ||
7 | Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
8 | Tested-by: Eric Auger <eric.auger@redhat.com> | ||
9 | Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com> | ||
10 | Message-id: 20201029093306.1063879-3-philmd@redhat.com | ||
11 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
12 | Tested-by: Eric Auger <eric.auger@redhat.com> | ||
13 | --- | ||
14 | block/trace-events | 12 ++++++------ | ||
15 | 1 file changed, 6 insertions(+), 6 deletions(-) | ||
16 | |||
17 | diff --git a/block/trace-events b/block/trace-events | ||
18 | index XXXXXXX..XXXXXXX 100644 | ||
19 | --- a/block/trace-events | ||
20 | +++ b/block/trace-events | ||
21 | @@ -XXX,XX +XXX,XX @@ nvme_submit_command(void *s, int index, int cid) "s %p queue %d cid %d" | ||
22 | nvme_submit_command_raw(int c0, int c1, int c2, int c3, int c4, int c5, int c6, int c7) "%02x %02x %02x %02x %02x %02x %02x %02x" | ||
23 | nvme_handle_event(void *s) "s %p" | ||
24 | nvme_poll_cb(void *s) "s %p" | ||
25 | -nvme_prw_aligned(void *s, int is_write, uint64_t offset, uint64_t bytes, int flags, int niov) "s %p is_write %d offset %"PRId64" bytes %"PRId64" flags %d niov %d" | ||
26 | -nvme_write_zeroes(void *s, uint64_t offset, uint64_t bytes, int flags) "s %p offset %"PRId64" bytes %"PRId64" flags %d" | ||
27 | +nvme_prw_aligned(void *s, int is_write, uint64_t offset, uint64_t bytes, int flags, int niov) "s %p is_write %d offset 0x%"PRIx64" bytes %"PRId64" flags %d niov %d" | ||
28 | +nvme_write_zeroes(void *s, uint64_t offset, uint64_t bytes, int flags) "s %p offset 0x%"PRIx64" bytes %"PRId64" flags %d" | ||
29 | nvme_qiov_unaligned(const void *qiov, int n, void *base, size_t size, int align) "qiov %p n %d base %p size 0x%zx align 0x%x" | ||
30 | -nvme_prw_buffered(void *s, uint64_t offset, uint64_t bytes, int niov, int is_write) "s %p offset %"PRId64" bytes %"PRId64" niov %d is_write %d" | ||
31 | -nvme_rw_done(void *s, int is_write, uint64_t offset, uint64_t bytes, int ret) "s %p is_write %d offset %"PRId64" bytes %"PRId64" ret %d" | ||
32 | -nvme_dsm(void *s, uint64_t offset, uint64_t bytes) "s %p offset %"PRId64" bytes %"PRId64"" | ||
33 | -nvme_dsm_done(void *s, uint64_t offset, uint64_t bytes, int ret) "s %p offset %"PRId64" bytes %"PRId64" ret %d" | ||
34 | +nvme_prw_buffered(void *s, uint64_t offset, uint64_t bytes, int niov, int is_write) "s %p offset 0x%"PRIx64" bytes %"PRId64" niov %d is_write %d" | ||
35 | +nvme_rw_done(void *s, int is_write, uint64_t offset, uint64_t bytes, int ret) "s %p is_write %d offset 0x%"PRIx64" bytes %"PRId64" ret %d" | ||
36 | +nvme_dsm(void *s, uint64_t offset, uint64_t bytes) "s %p offset 0x%"PRIx64" bytes %"PRId64"" | ||
37 | +nvme_dsm_done(void *s, uint64_t offset, uint64_t bytes, int ret) "s %p offset 0x%"PRIx64" bytes %"PRId64" ret %d" | ||
38 | nvme_dma_map_flush(void *s) "s %p" | ||
39 | nvme_free_req_queue_wait(void *q) "q %p" | ||
40 | nvme_cmd_map_qiov(void *s, void *cmd, void *req, void *qiov, int entries) "s %p cmd %p req %p qiov %p entries %d" | ||
41 | -- | ||
42 | 2.28.0 | ||
43 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: Philippe Mathieu-Daudé <philmd@redhat.com> | ||
2 | 1 | ||
3 | Instead of displaying warning on stderr, use warn_report() | ||
4 | which also displays it on the monitor. | ||
5 | |||
6 | Reviewed-by: Eric Auger <eric.auger@redhat.com> | ||
7 | Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
8 | Tested-by: Eric Auger <eric.auger@redhat.com> | ||
9 | Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com> | ||
10 | Message-id: 20201029093306.1063879-4-philmd@redhat.com | ||
11 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
12 | Tested-by: Eric Auger <eric.auger@redhat.com> | ||
13 | --- | ||
14 | block/nvme.c | 4 ++-- | ||
15 | 1 file changed, 2 insertions(+), 2 deletions(-) | ||
16 | |||
17 | diff --git a/block/nvme.c b/block/nvme.c | ||
18 | index XXXXXXX..XXXXXXX 100644 | ||
19 | --- a/block/nvme.c | ||
20 | +++ b/block/nvme.c | ||
21 | @@ -XXX,XX +XXX,XX @@ static bool nvme_process_completion(NVMeQueuePair *q) | ||
22 | } | ||
23 | cid = le16_to_cpu(c->cid); | ||
24 | if (cid == 0 || cid > NVME_QUEUE_SIZE) { | ||
25 | - fprintf(stderr, "Unexpected CID in completion queue: %" PRIu32 "\n", | ||
26 | - cid); | ||
27 | + warn_report("NVMe: Unexpected CID in completion queue: %"PRIu32", " | ||
28 | + "queue size: %u", cid, NVME_QUEUE_SIZE); | ||
29 | continue; | ||
30 | } | ||
31 | trace_nvme_complete_command(s, q->index, cid); | ||
32 | -- | ||
33 | 2.28.0 | ||
34 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: Philippe Mathieu-Daudé <philmd@redhat.com> | ||
2 | 1 | ||
3 | Controllers have different capabilities and report them in the | ||
4 | CAP register. We are particularly interested by the page size | ||
5 | limits. | ||
6 | |||
7 | Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
8 | Reviewed-by: Eric Auger <eric.auger@redhat.com> | ||
9 | Tested-by: Eric Auger <eric.auger@redhat.com> | ||
10 | Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com> | ||
11 | Message-id: 20201029093306.1063879-5-philmd@redhat.com | ||
12 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
13 | Tested-by: Eric Auger <eric.auger@redhat.com> | ||
14 | --- | ||
15 | block/nvme.c | 13 +++++++++++++ | ||
16 | block/trace-events | 2 ++ | ||
17 | 2 files changed, 15 insertions(+) | ||
18 | |||
19 | diff --git a/block/nvme.c b/block/nvme.c | ||
20 | index XXXXXXX..XXXXXXX 100644 | ||
21 | --- a/block/nvme.c | ||
22 | +++ b/block/nvme.c | ||
23 | @@ -XXX,XX +XXX,XX @@ static int nvme_init(BlockDriverState *bs, const char *device, int namespace, | ||
24 | * Initialization". */ | ||
25 | |||
26 | cap = le64_to_cpu(regs->cap); | ||
27 | + trace_nvme_controller_capability_raw(cap); | ||
28 | + trace_nvme_controller_capability("Maximum Queue Entries Supported", | ||
29 | + 1 + NVME_CAP_MQES(cap)); | ||
30 | + trace_nvme_controller_capability("Contiguous Queues Required", | ||
31 | + NVME_CAP_CQR(cap)); | ||
32 | + trace_nvme_controller_capability("Doorbell Stride", | ||
33 | + 2 << (2 + NVME_CAP_DSTRD(cap))); | ||
34 | + trace_nvme_controller_capability("Subsystem Reset Supported", | ||
35 | + NVME_CAP_NSSRS(cap)); | ||
36 | + trace_nvme_controller_capability("Memory Page Size Minimum", | ||
37 | + 1 << (12 + NVME_CAP_MPSMIN(cap))); | ||
38 | + trace_nvme_controller_capability("Memory Page Size Maximum", | ||
39 | + 1 << (12 + NVME_CAP_MPSMAX(cap))); | ||
40 | if (!NVME_CAP_CSS(cap)) { | ||
41 | error_setg(errp, "Device doesn't support NVMe command set"); | ||
42 | ret = -EINVAL; | ||
43 | diff --git a/block/trace-events b/block/trace-events | ||
44 | index XXXXXXX..XXXXXXX 100644 | ||
45 | --- a/block/trace-events | ||
46 | +++ b/block/trace-events | ||
47 | @@ -XXX,XX +XXX,XX @@ qed_aio_write_postfill(void *s, void *acb, uint64_t start, size_t len, uint64_t | ||
48 | qed_aio_write_main(void *s, void *acb, int ret, uint64_t offset, size_t len) "s %p acb %p ret %d offset %"PRIu64" len %zu" | ||
49 | |||
50 | # nvme.c | ||
51 | +nvme_controller_capability_raw(uint64_t value) "0x%08"PRIx64 | ||
52 | +nvme_controller_capability(const char *desc, uint64_t value) "%s: %"PRIu64 | ||
53 | nvme_kick(void *s, int queue) "s %p queue %d" | ||
54 | nvme_dma_flush_queue_wait(void *s) "s %p" | ||
55 | nvme_error(int cmd_specific, int sq_head, int sqid, int cid, int status) "cmd_specific %d sq_head %d sqid %d cid %d status 0x%x" | ||
56 | -- | ||
57 | 2.28.0 | ||
58 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: Philippe Mathieu-Daudé <philmd@redhat.com> | ||
2 | 1 | ||
3 | As we want to enable multiple queues, report the event | ||
4 | in each nvme_poll_queue() call, rather than once in | ||
5 | the callback calling nvme_poll_queues(). | ||
6 | |||
7 | Reviewed-by: Eric Auger <eric.auger@redhat.com> | ||
8 | Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
9 | Tested-by: Eric Auger <eric.auger@redhat.com> | ||
10 | Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com> | ||
11 | Message-id: 20201029093306.1063879-6-philmd@redhat.com | ||
12 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
13 | Tested-by: Eric Auger <eric.auger@redhat.com> | ||
14 | --- | ||
15 | block/nvme.c | 2 +- | ||
16 | block/trace-events | 2 +- | ||
17 | 2 files changed, 2 insertions(+), 2 deletions(-) | ||
18 | |||
19 | diff --git a/block/nvme.c b/block/nvme.c | ||
20 | index XXXXXXX..XXXXXXX 100644 | ||
21 | --- a/block/nvme.c | ||
22 | +++ b/block/nvme.c | ||
23 | @@ -XXX,XX +XXX,XX @@ static bool nvme_poll_queue(NVMeQueuePair *q) | ||
24 | const size_t cqe_offset = q->cq.head * NVME_CQ_ENTRY_BYTES; | ||
25 | NvmeCqe *cqe = (NvmeCqe *)&q->cq.queue[cqe_offset]; | ||
26 | |||
27 | + trace_nvme_poll_queue(q->s, q->index); | ||
28 | /* | ||
29 | * Do an early check for completions. q->lock isn't needed because | ||
30 | * nvme_process_completion() only runs in the event loop thread and | ||
31 | @@ -XXX,XX +XXX,XX @@ static bool nvme_poll_cb(void *opaque) | ||
32 | BDRVNVMeState *s = container_of(e, BDRVNVMeState, | ||
33 | irq_notifier[MSIX_SHARED_IRQ_IDX]); | ||
34 | |||
35 | - trace_nvme_poll_cb(s); | ||
36 | return nvme_poll_queues(s); | ||
37 | } | ||
38 | |||
39 | diff --git a/block/trace-events b/block/trace-events | ||
40 | index XXXXXXX..XXXXXXX 100644 | ||
41 | --- a/block/trace-events | ||
42 | +++ b/block/trace-events | ||
43 | @@ -XXX,XX +XXX,XX @@ nvme_complete_command(void *s, int index, int cid) "s %p queue %d cid %d" | ||
44 | nvme_submit_command(void *s, int index, int cid) "s %p queue %d cid %d" | ||
45 | nvme_submit_command_raw(int c0, int c1, int c2, int c3, int c4, int c5, int c6, int c7) "%02x %02x %02x %02x %02x %02x %02x %02x" | ||
46 | nvme_handle_event(void *s) "s %p" | ||
47 | -nvme_poll_cb(void *s) "s %p" | ||
48 | +nvme_poll_queue(void *s, unsigned q_index) "s %p q #%u" | ||
49 | nvme_prw_aligned(void *s, int is_write, uint64_t offset, uint64_t bytes, int flags, int niov) "s %p is_write %d offset 0x%"PRIx64" bytes %"PRId64" flags %d niov %d" | ||
50 | nvme_write_zeroes(void *s, uint64_t offset, uint64_t bytes, int flags) "s %p offset 0x%"PRIx64" bytes %"PRId64" flags %d" | ||
51 | nvme_qiov_unaligned(const void *qiov, int n, void *base, size_t size, int align) "qiov %p n %d base %p size 0x%zx align 0x%x" | ||
52 | -- | ||
53 | 2.28.0 | ||
54 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: Philippe Mathieu-Daudé <philmd@redhat.com> | ||
2 | 1 | ||
3 | What we want to trace is the block driver state and the queue index. | ||
4 | |||
5 | Suggested-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
6 | Reviewed-by: Eric Auger <eric.auger@redhat.com> | ||
7 | Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
8 | Tested-by: Eric Auger <eric.auger@redhat.com> | ||
9 | Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com> | ||
10 | Message-id: 20201029093306.1063879-7-philmd@redhat.com | ||
11 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
12 | Tested-by: Eric Auger <eric.auger@redhat.com> | ||
13 | --- | ||
14 | block/nvme.c | 2 +- | ||
15 | block/trace-events | 2 +- | ||
16 | 2 files changed, 2 insertions(+), 2 deletions(-) | ||
17 | |||
18 | diff --git a/block/nvme.c b/block/nvme.c | ||
19 | index XXXXXXX..XXXXXXX 100644 | ||
20 | --- a/block/nvme.c | ||
21 | +++ b/block/nvme.c | ||
22 | @@ -XXX,XX +XXX,XX @@ static NVMeRequest *nvme_get_free_req(NVMeQueuePair *q) | ||
23 | |||
24 | while (q->free_req_head == -1) { | ||
25 | if (qemu_in_coroutine()) { | ||
26 | - trace_nvme_free_req_queue_wait(q); | ||
27 | + trace_nvme_free_req_queue_wait(q->s, q->index); | ||
28 | qemu_co_queue_wait(&q->free_req_queue, &q->lock); | ||
29 | } else { | ||
30 | qemu_mutex_unlock(&q->lock); | ||
31 | diff --git a/block/trace-events b/block/trace-events | ||
32 | index XXXXXXX..XXXXXXX 100644 | ||
33 | --- a/block/trace-events | ||
34 | +++ b/block/trace-events | ||
35 | @@ -XXX,XX +XXX,XX @@ nvme_rw_done(void *s, int is_write, uint64_t offset, uint64_t bytes, int ret) "s | ||
36 | nvme_dsm(void *s, uint64_t offset, uint64_t bytes) "s %p offset 0x%"PRIx64" bytes %"PRId64"" | ||
37 | nvme_dsm_done(void *s, uint64_t offset, uint64_t bytes, int ret) "s %p offset 0x%"PRIx64" bytes %"PRId64" ret %d" | ||
38 | nvme_dma_map_flush(void *s) "s %p" | ||
39 | -nvme_free_req_queue_wait(void *q) "q %p" | ||
40 | +nvme_free_req_queue_wait(void *s, unsigned q_index) "s %p q #%u" | ||
41 | nvme_cmd_map_qiov(void *s, void *cmd, void *req, void *qiov, int entries) "s %p cmd %p req %p qiov %p entries %d" | ||
42 | nvme_cmd_map_qiov_pages(void *s, int i, uint64_t page) "s %p page[%d] 0x%"PRIx64 | ||
43 | nvme_cmd_map_qiov_iov(void *s, int i, void *page, int pages) "s %p iov[%d] %p pages %d" | ||
44 | -- | ||
45 | 2.28.0 | ||
46 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: Philippe Mathieu-Daudé <philmd@redhat.com> | ||
2 | 1 | ||
3 | Reviewed-by: Eric Auger <eric.auger@redhat.com> | ||
4 | Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
5 | Tested-by: Eric Auger <eric.auger@redhat.com> | ||
6 | Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com> | ||
7 | Message-id: 20201029093306.1063879-8-philmd@redhat.com | ||
8 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
9 | Tested-by: Eric Auger <eric.auger@redhat.com> | ||
10 | --- | ||
11 | block/nvme.c | 3 +++ | ||
12 | block/trace-events | 2 ++ | ||
13 | 2 files changed, 5 insertions(+) | ||
14 | |||
15 | diff --git a/block/nvme.c b/block/nvme.c | ||
16 | index XXXXXXX..XXXXXXX 100644 | ||
17 | --- a/block/nvme.c | ||
18 | +++ b/block/nvme.c | ||
19 | @@ -XXX,XX +XXX,XX @@ static void nvme_init_queue(BDRVNVMeState *s, NVMeQueue *q, | ||
20 | |||
21 | static void nvme_free_queue_pair(NVMeQueuePair *q) | ||
22 | { | ||
23 | + trace_nvme_free_queue_pair(q->index, q); | ||
24 | if (q->completion_bh) { | ||
25 | qemu_bh_delete(q->completion_bh); | ||
26 | } | ||
27 | @@ -XXX,XX +XXX,XX @@ static NVMeQueuePair *nvme_create_queue_pair(BDRVNVMeState *s, | ||
28 | if (!q) { | ||
29 | return NULL; | ||
30 | } | ||
31 | + trace_nvme_create_queue_pair(idx, q, size, aio_context, | ||
32 | + event_notifier_get_fd(s->irq_notifier)); | ||
33 | q->prp_list_pages = qemu_try_memalign(s->page_size, | ||
34 | s->page_size * NVME_NUM_REQS); | ||
35 | if (!q->prp_list_pages) { | ||
36 | diff --git a/block/trace-events b/block/trace-events | ||
37 | index XXXXXXX..XXXXXXX 100644 | ||
38 | --- a/block/trace-events | ||
39 | +++ b/block/trace-events | ||
40 | @@ -XXX,XX +XXX,XX @@ nvme_dsm(void *s, uint64_t offset, uint64_t bytes) "s %p offset 0x%"PRIx64" byte | ||
41 | nvme_dsm_done(void *s, uint64_t offset, uint64_t bytes, int ret) "s %p offset 0x%"PRIx64" bytes %"PRId64" ret %d" | ||
42 | nvme_dma_map_flush(void *s) "s %p" | ||
43 | nvme_free_req_queue_wait(void *s, unsigned q_index) "s %p q #%u" | ||
44 | +nvme_create_queue_pair(unsigned q_index, void *q, unsigned size, void *aio_context, int fd) "index %u q %p size %u aioctx %p fd %d" | ||
45 | +nvme_free_queue_pair(unsigned q_index, void *q) "index %u q %p" | ||
46 | nvme_cmd_map_qiov(void *s, void *cmd, void *req, void *qiov, int entries) "s %p cmd %p req %p qiov %p entries %d" | ||
47 | nvme_cmd_map_qiov_pages(void *s, int i, uint64_t page) "s %p page[%d] 0x%"PRIx64 | ||
48 | nvme_cmd_map_qiov_iov(void *s, int i, void *page, int pages) "s %p iov[%d] %p pages %d" | ||
49 | -- | ||
50 | 2.28.0 | ||
51 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: Philippe Mathieu-Daudé <philmd@redhat.com> | ||
2 | 1 | ||
3 | To be able to use some definitions in structure declarations, | ||
4 | move them earlier. No logical change. | ||
5 | |||
6 | Reviewed-by: Eric Auger <eric.auger@redhat.com> | ||
7 | Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
8 | Tested-by: Eric Auger <eric.auger@redhat.com> | ||
9 | Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com> | ||
10 | Message-id: 20201029093306.1063879-9-philmd@redhat.com | ||
11 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
12 | Tested-by: Eric Auger <eric.auger@redhat.com> | ||
13 | --- | ||
14 | block/nvme.c | 19 ++++++++++--------- | ||
15 | 1 file changed, 10 insertions(+), 9 deletions(-) | ||
16 | |||
17 | diff --git a/block/nvme.c b/block/nvme.c | ||
18 | index XXXXXXX..XXXXXXX 100644 | ||
19 | --- a/block/nvme.c | ||
20 | +++ b/block/nvme.c | ||
21 | @@ -XXX,XX +XXX,XX @@ | ||
22 | |||
23 | typedef struct BDRVNVMeState BDRVNVMeState; | ||
24 | |||
25 | +/* Same index is used for queues and IRQs */ | ||
26 | +#define INDEX_ADMIN 0 | ||
27 | +#define INDEX_IO(n) (1 + n) | ||
28 | + | ||
29 | +/* This driver shares a single MSIX IRQ for the admin and I/O queues */ | ||
30 | +enum { | ||
31 | + MSIX_SHARED_IRQ_IDX = 0, | ||
32 | + MSIX_IRQ_COUNT = 1 | ||
33 | +}; | ||
34 | + | ||
35 | typedef struct { | ||
36 | int32_t head, tail; | ||
37 | uint8_t *queue; | ||
38 | @@ -XXX,XX +XXX,XX @@ typedef struct { | ||
39 | QEMUBH *completion_bh; | ||
40 | } NVMeQueuePair; | ||
41 | |||
42 | -#define INDEX_ADMIN 0 | ||
43 | -#define INDEX_IO(n) (1 + n) | ||
44 | - | ||
45 | -/* This driver shares a single MSIX IRQ for the admin and I/O queues */ | ||
46 | -enum { | ||
47 | - MSIX_SHARED_IRQ_IDX = 0, | ||
48 | - MSIX_IRQ_COUNT = 1 | ||
49 | -}; | ||
50 | - | ||
51 | struct BDRVNVMeState { | ||
52 | AioContext *aio_context; | ||
53 | QEMUVFIOState *vfio; | ||
54 | -- | ||
55 | 2.28.0 | ||
56 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: Philippe Mathieu-Daudé <philmd@redhat.com> | ||
2 | 1 | ||
3 | We can not have negative queue count/size/index, use unsigned type. | ||
4 | Rename 'nr_queues' as 'queue_count' to match the spec naming. | ||
5 | |||
6 | Reviewed-by: Eric Auger <eric.auger@redhat.com> | ||
7 | Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
8 | Tested-by: Eric Auger <eric.auger@redhat.com> | ||
9 | Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com> | ||
10 | Message-id: 20201029093306.1063879-10-philmd@redhat.com | ||
11 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
12 | Tested-by: Eric Auger <eric.auger@redhat.com> | ||
13 | --- | ||
14 | block/nvme.c | 38 ++++++++++++++++++-------------------- | ||
15 | block/trace-events | 10 +++++----- | ||
16 | 2 files changed, 23 insertions(+), 25 deletions(-) | ||
17 | |||
18 | diff --git a/block/nvme.c b/block/nvme.c | ||
19 | index XXXXXXX..XXXXXXX 100644 | ||
20 | --- a/block/nvme.c | ||
21 | +++ b/block/nvme.c | ||
22 | @@ -XXX,XX +XXX,XX @@ struct BDRVNVMeState { | ||
23 | * [1..]: io queues. | ||
24 | */ | ||
25 | NVMeQueuePair **queues; | ||
26 | - int nr_queues; | ||
27 | + unsigned queue_count; | ||
28 | size_t page_size; | ||
29 | /* How many uint32_t elements does each doorbell entry take. */ | ||
30 | size_t doorbell_scale; | ||
31 | @@ -XXX,XX +XXX,XX @@ static QemuOptsList runtime_opts = { | ||
32 | }; | ||
33 | |||
34 | static void nvme_init_queue(BDRVNVMeState *s, NVMeQueue *q, | ||
35 | - int nentries, int entry_bytes, Error **errp) | ||
36 | + unsigned nentries, size_t entry_bytes, Error **errp) | ||
37 | { | ||
38 | size_t bytes; | ||
39 | int r; | ||
40 | @@ -XXX,XX +XXX,XX @@ static void nvme_free_req_queue_cb(void *opaque) | ||
41 | |||
42 | static NVMeQueuePair *nvme_create_queue_pair(BDRVNVMeState *s, | ||
43 | AioContext *aio_context, | ||
44 | - int idx, int size, | ||
45 | + unsigned idx, size_t size, | ||
46 | Error **errp) | ||
47 | { | ||
48 | int i, r; | ||
49 | @@ -XXX,XX +XXX,XX @@ static bool nvme_poll_queues(BDRVNVMeState *s) | ||
50 | bool progress = false; | ||
51 | int i; | ||
52 | |||
53 | - for (i = 0; i < s->nr_queues; i++) { | ||
54 | + for (i = 0; i < s->queue_count; i++) { | ||
55 | if (nvme_poll_queue(s->queues[i])) { | ||
56 | progress = true; | ||
57 | } | ||
58 | @@ -XXX,XX +XXX,XX @@ static void nvme_handle_event(EventNotifier *n) | ||
59 | static bool nvme_add_io_queue(BlockDriverState *bs, Error **errp) | ||
60 | { | ||
61 | BDRVNVMeState *s = bs->opaque; | ||
62 | - int n = s->nr_queues; | ||
63 | + unsigned n = s->queue_count; | ||
64 | NVMeQueuePair *q; | ||
65 | NvmeCmd cmd; | ||
66 | - int queue_size = NVME_QUEUE_SIZE; | ||
67 | + unsigned queue_size = NVME_QUEUE_SIZE; | ||
68 | |||
69 | q = nvme_create_queue_pair(s, bdrv_get_aio_context(bs), | ||
70 | n, queue_size, errp); | ||
71 | @@ -XXX,XX +XXX,XX @@ static bool nvme_add_io_queue(BlockDriverState *bs, Error **errp) | ||
72 | .cdw11 = cpu_to_le32(0x3), | ||
73 | }; | ||
74 | if (nvme_cmd_sync(bs, s->queues[INDEX_ADMIN], &cmd)) { | ||
75 | - error_setg(errp, "Failed to create CQ io queue [%d]", n); | ||
76 | + error_setg(errp, "Failed to create CQ io queue [%u]", n); | ||
77 | goto out_error; | ||
78 | } | ||
79 | cmd = (NvmeCmd) { | ||
80 | @@ -XXX,XX +XXX,XX @@ static bool nvme_add_io_queue(BlockDriverState *bs, Error **errp) | ||
81 | .cdw11 = cpu_to_le32(0x1 | (n << 16)), | ||
82 | }; | ||
83 | if (nvme_cmd_sync(bs, s->queues[INDEX_ADMIN], &cmd)) { | ||
84 | - error_setg(errp, "Failed to create SQ io queue [%d]", n); | ||
85 | + error_setg(errp, "Failed to create SQ io queue [%u]", n); | ||
86 | goto out_error; | ||
87 | } | ||
88 | s->queues = g_renew(NVMeQueuePair *, s->queues, n + 1); | ||
89 | s->queues[n] = q; | ||
90 | - s->nr_queues++; | ||
91 | + s->queue_count++; | ||
92 | return true; | ||
93 | out_error: | ||
94 | nvme_free_queue_pair(q); | ||
95 | @@ -XXX,XX +XXX,XX @@ static int nvme_init(BlockDriverState *bs, const char *device, int namespace, | ||
96 | ret = -EINVAL; | ||
97 | goto out; | ||
98 | } | ||
99 | - s->nr_queues = 1; | ||
100 | + s->queue_count = 1; | ||
101 | QEMU_BUILD_BUG_ON(NVME_QUEUE_SIZE & 0xF000); | ||
102 | regs->aqa = cpu_to_le32((NVME_QUEUE_SIZE << AQA_ACQS_SHIFT) | | ||
103 | (NVME_QUEUE_SIZE << AQA_ASQS_SHIFT)); | ||
104 | @@ -XXX,XX +XXX,XX @@ static int nvme_enable_disable_write_cache(BlockDriverState *bs, bool enable, | ||
105 | |||
106 | static void nvme_close(BlockDriverState *bs) | ||
107 | { | ||
108 | - int i; | ||
109 | BDRVNVMeState *s = bs->opaque; | ||
110 | |||
111 | - for (i = 0; i < s->nr_queues; ++i) { | ||
112 | + for (unsigned i = 0; i < s->queue_count; ++i) { | ||
113 | nvme_free_queue_pair(s->queues[i]); | ||
114 | } | ||
115 | g_free(s->queues); | ||
116 | @@ -XXX,XX +XXX,XX @@ static coroutine_fn int nvme_co_prw_aligned(BlockDriverState *bs, | ||
117 | }; | ||
118 | |||
119 | trace_nvme_prw_aligned(s, is_write, offset, bytes, flags, qiov->niov); | ||
120 | - assert(s->nr_queues > 1); | ||
121 | + assert(s->queue_count > 1); | ||
122 | req = nvme_get_free_req(ioq); | ||
123 | assert(req); | ||
124 | |||
125 | @@ -XXX,XX +XXX,XX @@ static coroutine_fn int nvme_co_flush(BlockDriverState *bs) | ||
126 | .ret = -EINPROGRESS, | ||
127 | }; | ||
128 | |||
129 | - assert(s->nr_queues > 1); | ||
130 | + assert(s->queue_count > 1); | ||
131 | req = nvme_get_free_req(ioq); | ||
132 | assert(req); | ||
133 | nvme_submit_command(ioq, req, &cmd, nvme_rw_cb, &data); | ||
134 | @@ -XXX,XX +XXX,XX @@ static coroutine_fn int nvme_co_pwrite_zeroes(BlockDriverState *bs, | ||
135 | cmd.cdw12 = cpu_to_le32(cdw12); | ||
136 | |||
137 | trace_nvme_write_zeroes(s, offset, bytes, flags); | ||
138 | - assert(s->nr_queues > 1); | ||
139 | + assert(s->queue_count > 1); | ||
140 | req = nvme_get_free_req(ioq); | ||
141 | assert(req); | ||
142 | |||
143 | @@ -XXX,XX +XXX,XX @@ static int coroutine_fn nvme_co_pdiscard(BlockDriverState *bs, | ||
144 | return -ENOTSUP; | ||
145 | } | ||
146 | |||
147 | - assert(s->nr_queues > 1); | ||
148 | + assert(s->queue_count > 1); | ||
149 | |||
150 | buf = qemu_try_memalign(s->page_size, s->page_size); | ||
151 | if (!buf) { | ||
152 | @@ -XXX,XX +XXX,XX @@ static void nvme_detach_aio_context(BlockDriverState *bs) | ||
153 | { | ||
154 | BDRVNVMeState *s = bs->opaque; | ||
155 | |||
156 | - for (int i = 0; i < s->nr_queues; i++) { | ||
157 | + for (unsigned i = 0; i < s->queue_count; i++) { | ||
158 | NVMeQueuePair *q = s->queues[i]; | ||
159 | |||
160 | qemu_bh_delete(q->completion_bh); | ||
161 | @@ -XXX,XX +XXX,XX @@ static void nvme_attach_aio_context(BlockDriverState *bs, | ||
162 | aio_set_event_notifier(new_context, &s->irq_notifier[MSIX_SHARED_IRQ_IDX], | ||
163 | false, nvme_handle_event, nvme_poll_cb); | ||
164 | |||
165 | - for (int i = 0; i < s->nr_queues; i++) { | ||
166 | + for (unsigned i = 0; i < s->queue_count; i++) { | ||
167 | NVMeQueuePair *q = s->queues[i]; | ||
168 | |||
169 | q->completion_bh = | ||
170 | @@ -XXX,XX +XXX,XX @@ static void nvme_aio_plug(BlockDriverState *bs) | ||
171 | |||
172 | static void nvme_aio_unplug(BlockDriverState *bs) | ||
173 | { | ||
174 | - int i; | ||
175 | BDRVNVMeState *s = bs->opaque; | ||
176 | assert(s->plugged); | ||
177 | s->plugged = false; | ||
178 | - for (i = INDEX_IO(0); i < s->nr_queues; i++) { | ||
179 | + for (unsigned i = INDEX_IO(0); i < s->queue_count; i++) { | ||
180 | NVMeQueuePair *q = s->queues[i]; | ||
181 | qemu_mutex_lock(&q->lock); | ||
182 | nvme_kick(q); | ||
183 | diff --git a/block/trace-events b/block/trace-events | ||
184 | index XXXXXXX..XXXXXXX 100644 | ||
185 | --- a/block/trace-events | ||
186 | +++ b/block/trace-events | ||
187 | @@ -XXX,XX +XXX,XX @@ qed_aio_write_main(void *s, void *acb, int ret, uint64_t offset, size_t len) "s | ||
188 | # nvme.c | ||
189 | nvme_controller_capability_raw(uint64_t value) "0x%08"PRIx64 | ||
190 | nvme_controller_capability(const char *desc, uint64_t value) "%s: %"PRIu64 | ||
191 | -nvme_kick(void *s, int queue) "s %p queue %d" | ||
192 | +nvme_kick(void *s, unsigned q_index) "s %p q #%u" | ||
193 | nvme_dma_flush_queue_wait(void *s) "s %p" | ||
194 | nvme_error(int cmd_specific, int sq_head, int sqid, int cid, int status) "cmd_specific %d sq_head %d sqid %d cid %d status 0x%x" | ||
195 | -nvme_process_completion(void *s, int index, int inflight) "s %p queue %d inflight %d" | ||
196 | -nvme_process_completion_queue_plugged(void *s, int index) "s %p queue %d" | ||
197 | -nvme_complete_command(void *s, int index, int cid) "s %p queue %d cid %d" | ||
198 | -nvme_submit_command(void *s, int index, int cid) "s %p queue %d cid %d" | ||
199 | +nvme_process_completion(void *s, unsigned q_index, int inflight) "s %p q #%u inflight %d" | ||
200 | +nvme_process_completion_queue_plugged(void *s, unsigned q_index) "s %p q #%u" | ||
201 | +nvme_complete_command(void *s, unsigned q_index, int cid) "s %p q #%u cid %d" | ||
202 | +nvme_submit_command(void *s, unsigned q_index, int cid) "s %p q #%u cid %d" | ||
203 | nvme_submit_command_raw(int c0, int c1, int c2, int c3, int c4, int c5, int c6, int c7) "%02x %02x %02x %02x %02x %02x %02x %02x" | ||
204 | nvme_handle_event(void *s) "s %p" | ||
205 | nvme_poll_queue(void *s, unsigned q_index) "s %p q #%u" | ||
206 | -- | ||
207 | 2.28.0 | ||
208 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: Philippe Mathieu-Daudé <philmd@redhat.com> | ||
2 | 1 | ||
3 | Just for consistency, following the example documented since | ||
4 | commit e3fe3988d7 ("error: Document Error API usage rules"), | ||
5 | return a boolean value indicating an error is set or not. | ||
6 | Directly pass errp as the local_err is not requested in our | ||
7 | case. This simplifies a bit nvme_create_queue_pair(). | ||
8 | |||
9 | Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
10 | Tested-by: Eric Auger <eric.auger@redhat.com> | ||
11 | Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com> | ||
12 | Message-id: 20201029093306.1063879-12-philmd@redhat.com | ||
13 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
14 | Tested-by: Eric Auger <eric.auger@redhat.com> | ||
15 | --- | ||
16 | block/nvme.c | 16 +++++++--------- | ||
17 | 1 file changed, 7 insertions(+), 9 deletions(-) | ||
18 | |||
19 | diff --git a/block/nvme.c b/block/nvme.c | ||
20 | index XXXXXXX..XXXXXXX 100644 | ||
21 | --- a/block/nvme.c | ||
22 | +++ b/block/nvme.c | ||
23 | @@ -XXX,XX +XXX,XX @@ static QemuOptsList runtime_opts = { | ||
24 | }, | ||
25 | }; | ||
26 | |||
27 | -static void nvme_init_queue(BDRVNVMeState *s, NVMeQueue *q, | ||
28 | +/* Returns true on success, false on failure. */ | ||
29 | +static bool nvme_init_queue(BDRVNVMeState *s, NVMeQueue *q, | ||
30 | unsigned nentries, size_t entry_bytes, Error **errp) | ||
31 | { | ||
32 | size_t bytes; | ||
33 | @@ -XXX,XX +XXX,XX @@ static void nvme_init_queue(BDRVNVMeState *s, NVMeQueue *q, | ||
34 | q->queue = qemu_try_memalign(s->page_size, bytes); | ||
35 | if (!q->queue) { | ||
36 | error_setg(errp, "Cannot allocate queue"); | ||
37 | - return; | ||
38 | + return false; | ||
39 | } | ||
40 | memset(q->queue, 0, bytes); | ||
41 | r = qemu_vfio_dma_map(s->vfio, q->queue, bytes, false, &q->iova); | ||
42 | if (r) { | ||
43 | error_setg(errp, "Cannot map queue"); | ||
44 | + return false; | ||
45 | } | ||
46 | + return true; | ||
47 | } | ||
48 | |||
49 | static void nvme_free_queue_pair(NVMeQueuePair *q) | ||
50 | @@ -XXX,XX +XXX,XX @@ static NVMeQueuePair *nvme_create_queue_pair(BDRVNVMeState *s, | ||
51 | Error **errp) | ||
52 | { | ||
53 | int i, r; | ||
54 | - Error *local_err = NULL; | ||
55 | NVMeQueuePair *q; | ||
56 | uint64_t prp_list_iova; | ||
57 | |||
58 | @@ -XXX,XX +XXX,XX @@ static NVMeQueuePair *nvme_create_queue_pair(BDRVNVMeState *s, | ||
59 | req->prp_list_iova = prp_list_iova + i * s->page_size; | ||
60 | } | ||
61 | |||
62 | - nvme_init_queue(s, &q->sq, size, NVME_SQ_ENTRY_BYTES, &local_err); | ||
63 | - if (local_err) { | ||
64 | - error_propagate(errp, local_err); | ||
65 | + if (!nvme_init_queue(s, &q->sq, size, NVME_SQ_ENTRY_BYTES, errp)) { | ||
66 | goto fail; | ||
67 | } | ||
68 | q->sq.doorbell = &s->doorbells[idx * s->doorbell_scale].sq_tail; | ||
69 | |||
70 | - nvme_init_queue(s, &q->cq, size, NVME_CQ_ENTRY_BYTES, &local_err); | ||
71 | - if (local_err) { | ||
72 | - error_propagate(errp, local_err); | ||
73 | + if (!nvme_init_queue(s, &q->cq, size, NVME_CQ_ENTRY_BYTES, errp)) { | ||
74 | goto fail; | ||
75 | } | ||
76 | q->cq.doorbell = &s->doorbells[idx * s->doorbell_scale].cq_head; | ||
77 | -- | ||
78 | 2.28.0 | ||
79 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: Philippe Mathieu-Daudé <philmd@redhat.com> | ||
2 | 1 | ||
3 | Rename Submission Queue flags with 'Sq' to differentiate | ||
4 | submission queue flags from command queue flags, and introduce | ||
5 | Completion Queue flag definitions. | ||
6 | |||
7 | Reviewed-by: Eric Auger <eric.auger@redhat.com> | ||
8 | Tested-by: Eric Auger <eric.auger@redhat.com> | ||
9 | Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com> | ||
10 | Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
11 | Message-id: 20201029093306.1063879-13-philmd@redhat.com | ||
12 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
13 | Tested-by: Eric Auger <eric.auger@redhat.com> | ||
14 | --- | ||
15 | include/block/nvme.h | 18 ++++++++++++------ | ||
16 | 1 file changed, 12 insertions(+), 6 deletions(-) | ||
17 | |||
18 | diff --git a/include/block/nvme.h b/include/block/nvme.h | ||
19 | index XXXXXXX..XXXXXXX 100644 | ||
20 | --- a/include/block/nvme.h | ||
21 | +++ b/include/block/nvme.h | ||
22 | @@ -XXX,XX +XXX,XX @@ typedef struct QEMU_PACKED NvmeCreateCq { | ||
23 | #define NVME_CQ_FLAGS_PC(cq_flags) (cq_flags & 0x1) | ||
24 | #define NVME_CQ_FLAGS_IEN(cq_flags) ((cq_flags >> 1) & 0x1) | ||
25 | |||
26 | +enum NvmeFlagsCq { | ||
27 | + NVME_CQ_PC = 1, | ||
28 | + NVME_CQ_IEN = 2, | ||
29 | +}; | ||
30 | + | ||
31 | typedef struct QEMU_PACKED NvmeCreateSq { | ||
32 | uint8_t opcode; | ||
33 | uint8_t flags; | ||
34 | @@ -XXX,XX +XXX,XX @@ typedef struct QEMU_PACKED NvmeCreateSq { | ||
35 | #define NVME_SQ_FLAGS_PC(sq_flags) (sq_flags & 0x1) | ||
36 | #define NVME_SQ_FLAGS_QPRIO(sq_flags) ((sq_flags >> 1) & 0x3) | ||
37 | |||
38 | -enum NvmeQueueFlags { | ||
39 | - NVME_Q_PC = 1, | ||
40 | - NVME_Q_PRIO_URGENT = 0, | ||
41 | - NVME_Q_PRIO_HIGH = 1, | ||
42 | - NVME_Q_PRIO_NORMAL = 2, | ||
43 | - NVME_Q_PRIO_LOW = 3, | ||
44 | +enum NvmeFlagsSq { | ||
45 | + NVME_SQ_PC = 1, | ||
46 | + | ||
47 | + NVME_SQ_PRIO_URGENT = 0, | ||
48 | + NVME_SQ_PRIO_HIGH = 1, | ||
49 | + NVME_SQ_PRIO_NORMAL = 2, | ||
50 | + NVME_SQ_PRIO_LOW = 3, | ||
51 | }; | ||
52 | |||
53 | typedef struct QEMU_PACKED NvmeIdentify { | ||
54 | -- | ||
55 | 2.28.0 | ||
56 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: Philippe Mathieu-Daudé <philmd@redhat.com> | ||
2 | 1 | ||
3 | Replace magic values by definitions, and simplifiy since the | ||
4 | number of queues will never reach 64K. | ||
5 | |||
6 | Reviewed-by: Eric Auger <eric.auger@redhat.com> | ||
7 | Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
8 | Tested-by: Eric Auger <eric.auger@redhat.com> | ||
9 | Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com> | ||
10 | Message-id: 20201029093306.1063879-14-philmd@redhat.com | ||
11 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
12 | Tested-by: Eric Auger <eric.auger@redhat.com> | ||
13 | --- | ||
14 | block/nvme.c | 9 +++++---- | ||
15 | 1 file changed, 5 insertions(+), 4 deletions(-) | ||
16 | |||
17 | diff --git a/block/nvme.c b/block/nvme.c | ||
18 | index XXXXXXX..XXXXXXX 100644 | ||
19 | --- a/block/nvme.c | ||
20 | +++ b/block/nvme.c | ||
21 | @@ -XXX,XX +XXX,XX @@ static bool nvme_add_io_queue(BlockDriverState *bs, Error **errp) | ||
22 | NvmeCmd cmd; | ||
23 | unsigned queue_size = NVME_QUEUE_SIZE; | ||
24 | |||
25 | + assert(n <= UINT16_MAX); | ||
26 | q = nvme_create_queue_pair(s, bdrv_get_aio_context(bs), | ||
27 | n, queue_size, errp); | ||
28 | if (!q) { | ||
29 | @@ -XXX,XX +XXX,XX @@ static bool nvme_add_io_queue(BlockDriverState *bs, Error **errp) | ||
30 | cmd = (NvmeCmd) { | ||
31 | .opcode = NVME_ADM_CMD_CREATE_CQ, | ||
32 | .dptr.prp1 = cpu_to_le64(q->cq.iova), | ||
33 | - .cdw10 = cpu_to_le32(((queue_size - 1) << 16) | (n & 0xFFFF)), | ||
34 | - .cdw11 = cpu_to_le32(0x3), | ||
35 | + .cdw10 = cpu_to_le32(((queue_size - 1) << 16) | n), | ||
36 | + .cdw11 = cpu_to_le32(NVME_CQ_IEN | NVME_CQ_PC), | ||
37 | }; | ||
38 | if (nvme_cmd_sync(bs, s->queues[INDEX_ADMIN], &cmd)) { | ||
39 | error_setg(errp, "Failed to create CQ io queue [%u]", n); | ||
40 | @@ -XXX,XX +XXX,XX @@ static bool nvme_add_io_queue(BlockDriverState *bs, Error **errp) | ||
41 | cmd = (NvmeCmd) { | ||
42 | .opcode = NVME_ADM_CMD_CREATE_SQ, | ||
43 | .dptr.prp1 = cpu_to_le64(q->sq.iova), | ||
44 | - .cdw10 = cpu_to_le32(((queue_size - 1) << 16) | (n & 0xFFFF)), | ||
45 | - .cdw11 = cpu_to_le32(0x1 | (n << 16)), | ||
46 | + .cdw10 = cpu_to_le32(((queue_size - 1) << 16) | n), | ||
47 | + .cdw11 = cpu_to_le32(NVME_SQ_PC | (n << 16)), | ||
48 | }; | ||
49 | if (nvme_cmd_sync(bs, s->queues[INDEX_ADMIN], &cmd)) { | ||
50 | error_setg(errp, "Failed to create SQ io queue [%u]", n); | ||
51 | -- | ||
52 | 2.28.0 | ||
53 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: Philippe Mathieu-Daudé <philmd@redhat.com> | ||
2 | 1 | ||
3 | From the specification chapter 3.1.8 "AQA - Admin Queue Attributes" | ||
4 | the Admin Submission Queue Size field is a 0’s based value: | ||
5 | |||
6 | Admin Submission Queue Size (ASQS): | ||
7 | |||
8 | Defines the size of the Admin Submission Queue in entries. | ||
9 | Enabling a controller while this field is cleared to 00h | ||
10 | produces undefined results. The minimum size of the Admin | ||
11 | Submission Queue is two entries. The maximum size of the | ||
12 | Admin Submission Queue is 4096 entries. | ||
13 | This is a 0’s based value. | ||
14 | |||
15 | This bug has never been hit because the device initialization | ||
16 | uses a single command synchronously :) | ||
17 | |||
18 | Reviewed-by: Eric Auger <eric.auger@redhat.com> | ||
19 | Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
20 | Tested-by: Eric Auger <eric.auger@redhat.com> | ||
21 | Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com> | ||
22 | Message-id: 20201029093306.1063879-15-philmd@redhat.com | ||
23 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
24 | Tested-by: Eric Auger <eric.auger@redhat.com> | ||
25 | --- | ||
26 | block/nvme.c | 6 +++--- | ||
27 | 1 file changed, 3 insertions(+), 3 deletions(-) | ||
28 | |||
29 | diff --git a/block/nvme.c b/block/nvme.c | ||
30 | index XXXXXXX..XXXXXXX 100644 | ||
31 | --- a/block/nvme.c | ||
32 | +++ b/block/nvme.c | ||
33 | @@ -XXX,XX +XXX,XX @@ static int nvme_init(BlockDriverState *bs, const char *device, int namespace, | ||
34 | goto out; | ||
35 | } | ||
36 | s->queue_count = 1; | ||
37 | - QEMU_BUILD_BUG_ON(NVME_QUEUE_SIZE & 0xF000); | ||
38 | - regs->aqa = cpu_to_le32((NVME_QUEUE_SIZE << AQA_ACQS_SHIFT) | | ||
39 | - (NVME_QUEUE_SIZE << AQA_ASQS_SHIFT)); | ||
40 | + QEMU_BUILD_BUG_ON((NVME_QUEUE_SIZE - 1) & 0xF000); | ||
41 | + regs->aqa = cpu_to_le32(((NVME_QUEUE_SIZE - 1) << AQA_ACQS_SHIFT) | | ||
42 | + ((NVME_QUEUE_SIZE - 1) << AQA_ASQS_SHIFT)); | ||
43 | regs->asq = cpu_to_le64(s->queues[INDEX_ADMIN]->sq.iova); | ||
44 | regs->acq = cpu_to_le64(s->queues[INDEX_ADMIN]->cq.iova); | ||
45 | |||
46 | -- | ||
47 | 2.28.0 | ||
48 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: Philippe Mathieu-Daudé <philmd@redhat.com> | ||
2 | 1 | ||
3 | We don't need to dereference from BDRVNVMeState each time. | ||
4 | Use a NVMeQueuePair pointer on the admin queue. | ||
5 | The nvme_init() becomes easier to review, matching the style | ||
6 | of nvme_add_io_queue(). | ||
7 | |||
8 | Reviewed-by: Eric Auger <eric.auger@redhat.com> | ||
9 | Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
10 | Tested-by: Eric Auger <eric.auger@redhat.com> | ||
11 | Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com> | ||
12 | Message-id: 20201029093306.1063879-16-philmd@redhat.com | ||
13 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
14 | Tested-by: Eric Auger <eric.auger@redhat.com> | ||
15 | --- | ||
16 | block/nvme.c | 12 ++++++------ | ||
17 | 1 file changed, 6 insertions(+), 6 deletions(-) | ||
18 | |||
19 | diff --git a/block/nvme.c b/block/nvme.c | ||
20 | index XXXXXXX..XXXXXXX 100644 | ||
21 | --- a/block/nvme.c | ||
22 | +++ b/block/nvme.c | ||
23 | @@ -XXX,XX +XXX,XX @@ static int nvme_init(BlockDriverState *bs, const char *device, int namespace, | ||
24 | Error **errp) | ||
25 | { | ||
26 | BDRVNVMeState *s = bs->opaque; | ||
27 | + NVMeQueuePair *q; | ||
28 | AioContext *aio_context = bdrv_get_aio_context(bs); | ||
29 | int ret; | ||
30 | uint64_t cap; | ||
31 | @@ -XXX,XX +XXX,XX @@ static int nvme_init(BlockDriverState *bs, const char *device, int namespace, | ||
32 | |||
33 | /* Set up admin queue. */ | ||
34 | s->queues = g_new(NVMeQueuePair *, 1); | ||
35 | - s->queues[INDEX_ADMIN] = nvme_create_queue_pair(s, aio_context, 0, | ||
36 | - NVME_QUEUE_SIZE, | ||
37 | - errp); | ||
38 | - if (!s->queues[INDEX_ADMIN]) { | ||
39 | + q = nvme_create_queue_pair(s, aio_context, 0, NVME_QUEUE_SIZE, errp); | ||
40 | + if (!q) { | ||
41 | ret = -EINVAL; | ||
42 | goto out; | ||
43 | } | ||
44 | + s->queues[INDEX_ADMIN] = q; | ||
45 | s->queue_count = 1; | ||
46 | QEMU_BUILD_BUG_ON((NVME_QUEUE_SIZE - 1) & 0xF000); | ||
47 | regs->aqa = cpu_to_le32(((NVME_QUEUE_SIZE - 1) << AQA_ACQS_SHIFT) | | ||
48 | ((NVME_QUEUE_SIZE - 1) << AQA_ASQS_SHIFT)); | ||
49 | - regs->asq = cpu_to_le64(s->queues[INDEX_ADMIN]->sq.iova); | ||
50 | - regs->acq = cpu_to_le64(s->queues[INDEX_ADMIN]->cq.iova); | ||
51 | + regs->asq = cpu_to_le64(q->sq.iova); | ||
52 | + regs->acq = cpu_to_le64(q->cq.iova); | ||
53 | |||
54 | /* After setting up all control registers we can enable device now. */ | ||
55 | regs->cc = cpu_to_le32((ctz32(NVME_CQ_ENTRY_BYTES) << CC_IOCQES_SHIFT) | | ||
56 | -- | ||
57 | 2.28.0 | ||
58 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: Philippe Mathieu-Daudé <philmd@redhat.com> | ||
2 | 1 | ||
3 | As all commands use the ADMIN queue, it is pointless to pass | ||
4 | it as argument each time. Remove the argument, and rename the | ||
5 | function as nvme_admin_cmd_sync() to make this new behavior | ||
6 | clearer. | ||
7 | |||
8 | Reviewed-by: Eric Auger <eric.auger@redhat.com> | ||
9 | Tested-by: Eric Auger <eric.auger@redhat.com> | ||
10 | Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com> | ||
11 | Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
12 | Message-id: 20201029093306.1063879-17-philmd@redhat.com | ||
13 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
14 | Tested-by: Eric Auger <eric.auger@redhat.com> | ||
15 | --- | ||
16 | block/nvme.c | 19 ++++++++++--------- | ||
17 | 1 file changed, 10 insertions(+), 9 deletions(-) | ||
18 | |||
19 | diff --git a/block/nvme.c b/block/nvme.c | ||
20 | index XXXXXXX..XXXXXXX 100644 | ||
21 | --- a/block/nvme.c | ||
22 | +++ b/block/nvme.c | ||
23 | @@ -XXX,XX +XXX,XX @@ static void nvme_submit_command(NVMeQueuePair *q, NVMeRequest *req, | ||
24 | qemu_mutex_unlock(&q->lock); | ||
25 | } | ||
26 | |||
27 | -static void nvme_cmd_sync_cb(void *opaque, int ret) | ||
28 | +static void nvme_admin_cmd_sync_cb(void *opaque, int ret) | ||
29 | { | ||
30 | int *pret = opaque; | ||
31 | *pret = ret; | ||
32 | aio_wait_kick(); | ||
33 | } | ||
34 | |||
35 | -static int nvme_cmd_sync(BlockDriverState *bs, NVMeQueuePair *q, | ||
36 | - NvmeCmd *cmd) | ||
37 | +static int nvme_admin_cmd_sync(BlockDriverState *bs, NvmeCmd *cmd) | ||
38 | { | ||
39 | + BDRVNVMeState *s = bs->opaque; | ||
40 | + NVMeQueuePair *q = s->queues[INDEX_ADMIN]; | ||
41 | AioContext *aio_context = bdrv_get_aio_context(bs); | ||
42 | NVMeRequest *req; | ||
43 | int ret = -EINPROGRESS; | ||
44 | @@ -XXX,XX +XXX,XX @@ static int nvme_cmd_sync(BlockDriverState *bs, NVMeQueuePair *q, | ||
45 | if (!req) { | ||
46 | return -EBUSY; | ||
47 | } | ||
48 | - nvme_submit_command(q, req, cmd, nvme_cmd_sync_cb, &ret); | ||
49 | + nvme_submit_command(q, req, cmd, nvme_admin_cmd_sync_cb, &ret); | ||
50 | |||
51 | AIO_WAIT_WHILE(aio_context, ret == -EINPROGRESS); | ||
52 | return ret; | ||
53 | @@ -XXX,XX +XXX,XX @@ static bool nvme_identify(BlockDriverState *bs, int namespace, Error **errp) | ||
54 | |||
55 | memset(id, 0, sizeof(*id)); | ||
56 | cmd.dptr.prp1 = cpu_to_le64(iova); | ||
57 | - if (nvme_cmd_sync(bs, s->queues[INDEX_ADMIN], &cmd)) { | ||
58 | + if (nvme_admin_cmd_sync(bs, &cmd)) { | ||
59 | error_setg(errp, "Failed to identify controller"); | ||
60 | goto out; | ||
61 | } | ||
62 | @@ -XXX,XX +XXX,XX @@ static bool nvme_identify(BlockDriverState *bs, int namespace, Error **errp) | ||
63 | memset(id, 0, sizeof(*id)); | ||
64 | cmd.cdw10 = 0; | ||
65 | cmd.nsid = cpu_to_le32(namespace); | ||
66 | - if (nvme_cmd_sync(bs, s->queues[INDEX_ADMIN], &cmd)) { | ||
67 | + if (nvme_admin_cmd_sync(bs, &cmd)) { | ||
68 | error_setg(errp, "Failed to identify namespace"); | ||
69 | goto out; | ||
70 | } | ||
71 | @@ -XXX,XX +XXX,XX @@ static bool nvme_add_io_queue(BlockDriverState *bs, Error **errp) | ||
72 | .cdw10 = cpu_to_le32(((queue_size - 1) << 16) | n), | ||
73 | .cdw11 = cpu_to_le32(NVME_CQ_IEN | NVME_CQ_PC), | ||
74 | }; | ||
75 | - if (nvme_cmd_sync(bs, s->queues[INDEX_ADMIN], &cmd)) { | ||
76 | + if (nvme_admin_cmd_sync(bs, &cmd)) { | ||
77 | error_setg(errp, "Failed to create CQ io queue [%u]", n); | ||
78 | goto out_error; | ||
79 | } | ||
80 | @@ -XXX,XX +XXX,XX @@ static bool nvme_add_io_queue(BlockDriverState *bs, Error **errp) | ||
81 | .cdw10 = cpu_to_le32(((queue_size - 1) << 16) | n), | ||
82 | .cdw11 = cpu_to_le32(NVME_SQ_PC | (n << 16)), | ||
83 | }; | ||
84 | - if (nvme_cmd_sync(bs, s->queues[INDEX_ADMIN], &cmd)) { | ||
85 | + if (nvme_admin_cmd_sync(bs, &cmd)) { | ||
86 | error_setg(errp, "Failed to create SQ io queue [%u]", n); | ||
87 | goto out_error; | ||
88 | } | ||
89 | @@ -XXX,XX +XXX,XX @@ static int nvme_enable_disable_write_cache(BlockDriverState *bs, bool enable, | ||
90 | .cdw11 = cpu_to_le32(enable ? 0x01 : 0x00), | ||
91 | }; | ||
92 | |||
93 | - ret = nvme_cmd_sync(bs, s->queues[INDEX_ADMIN], &cmd); | ||
94 | + ret = nvme_admin_cmd_sync(bs, &cmd); | ||
95 | if (ret) { | ||
96 | error_setg(errp, "Failed to configure NVMe write cache"); | ||
97 | } | ||
98 | -- | ||
99 | 2.28.0 | ||
100 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: Philippe Mathieu-Daudé <philmd@redhat.com> | ||
2 | 1 | ||
3 | Commit bdd6a90a9e5 ("block: Add VFIO based NVMe driver") | ||
4 | sets the request_alignment in nvme_refresh_limits(). | ||
5 | For consistency, also set it during initialization. | ||
6 | |||
7 | Reported-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
8 | Reviewed-by: Eric Auger <eric.auger@redhat.com> | ||
9 | Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
10 | Tested-by: Eric Auger <eric.auger@redhat.com> | ||
11 | Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com> | ||
12 | Message-id: 20201029093306.1063879-18-philmd@redhat.com | ||
13 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
14 | Tested-by: Eric Auger <eric.auger@redhat.com> | ||
15 | --- | ||
16 | block/nvme.c | 1 + | ||
17 | 1 file changed, 1 insertion(+) | ||
18 | |||
19 | diff --git a/block/nvme.c b/block/nvme.c | ||
20 | index XXXXXXX..XXXXXXX 100644 | ||
21 | --- a/block/nvme.c | ||
22 | +++ b/block/nvme.c | ||
23 | @@ -XXX,XX +XXX,XX @@ static int nvme_init(BlockDriverState *bs, const char *device, int namespace, | ||
24 | s->page_size = MAX(4096, 1 << NVME_CAP_MPSMIN(cap)); | ||
25 | s->doorbell_scale = (4 << NVME_CAP_DSTRD(cap)) / sizeof(uint32_t); | ||
26 | bs->bl.opt_mem_alignment = s->page_size; | ||
27 | + bs->bl.request_alignment = s->page_size; | ||
28 | timeout_ms = MIN(500 * NVME_CAP_TO(cap), 30000); | ||
29 | |||
30 | /* Reset device to get a clean state. */ | ||
31 | -- | ||
32 | 2.28.0 | ||
33 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: Philippe Mathieu-Daudé <philmd@redhat.com> | ||
2 | 1 | ||
3 | While trying to simplify the code using a macro, we forgot | ||
4 | the 12-bit shift... Correct that. | ||
5 | |||
6 | Fixes: fad1eb68862 ("block/nvme: Use register definitions from 'block/nvme.h'") | ||
7 | Reported-by: Eric Auger <eric.auger@redhat.com> | ||
8 | Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
9 | Reviewed-by: Eric Auger <eric.auger@redhat.com> | ||
10 | Tested-by: Eric Auger <eric.auger@redhat.com> | ||
11 | Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com> | ||
12 | Message-id: 20201029093306.1063879-19-philmd@redhat.com | ||
13 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
14 | Tested-by: Eric Auger <eric.auger@redhat.com> | ||
15 | --- | ||
16 | block/nvme.c | 2 +- | ||
17 | 1 file changed, 1 insertion(+), 1 deletion(-) | ||
18 | |||
19 | diff --git a/block/nvme.c b/block/nvme.c | ||
20 | index XXXXXXX..XXXXXXX 100644 | ||
21 | --- a/block/nvme.c | ||
22 | +++ b/block/nvme.c | ||
23 | @@ -XXX,XX +XXX,XX @@ static int nvme_init(BlockDriverState *bs, const char *device, int namespace, | ||
24 | goto out; | ||
25 | } | ||
26 | |||
27 | - s->page_size = MAX(4096, 1 << NVME_CAP_MPSMIN(cap)); | ||
28 | + s->page_size = 1u << (12 + NVME_CAP_MPSMIN(cap)); | ||
29 | s->doorbell_scale = (4 << NVME_CAP_DSTRD(cap)) / sizeof(uint32_t); | ||
30 | bs->bl.opt_mem_alignment = s->page_size; | ||
31 | bs->bl.request_alignment = s->page_size; | ||
32 | -- | ||
33 | 2.28.0 | ||
34 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: Eric Auger <eric.auger@redhat.com> | ||
2 | 1 | ||
3 | In preparation of 64kB host page support, let's change the size | ||
4 | and alignment of the IDENTIFY command response buffer so that | ||
5 | the VFIO DMA MAP succeeds. We align on the host page size. | ||
6 | |||
7 | Signed-off-by: Eric Auger <eric.auger@redhat.com> | ||
8 | Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com> | ||
9 | Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
10 | Tested-by: Eric Auger <eric.auger@redhat.com> | ||
11 | Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com> | ||
12 | Message-id: 20201029093306.1063879-20-philmd@redhat.com | ||
13 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
14 | Tested-by: Eric Auger <eric.auger@redhat.com> | ||
15 | --- | ||
16 | block/nvme.c | 9 +++++---- | ||
17 | 1 file changed, 5 insertions(+), 4 deletions(-) | ||
18 | |||
19 | diff --git a/block/nvme.c b/block/nvme.c | ||
20 | index XXXXXXX..XXXXXXX 100644 | ||
21 | --- a/block/nvme.c | ||
22 | +++ b/block/nvme.c | ||
23 | @@ -XXX,XX +XXX,XX @@ static bool nvme_identify(BlockDriverState *bs, int namespace, Error **errp) | ||
24 | .opcode = NVME_ADM_CMD_IDENTIFY, | ||
25 | .cdw10 = cpu_to_le32(0x1), | ||
26 | }; | ||
27 | + size_t id_size = QEMU_ALIGN_UP(sizeof(*id), qemu_real_host_page_size); | ||
28 | |||
29 | - id = qemu_try_memalign(s->page_size, sizeof(*id)); | ||
30 | + id = qemu_try_memalign(qemu_real_host_page_size, id_size); | ||
31 | if (!id) { | ||
32 | error_setg(errp, "Cannot allocate buffer for identify response"); | ||
33 | goto out; | ||
34 | } | ||
35 | - r = qemu_vfio_dma_map(s->vfio, id, sizeof(*id), true, &iova); | ||
36 | + r = qemu_vfio_dma_map(s->vfio, id, id_size, true, &iova); | ||
37 | if (r) { | ||
38 | error_setg(errp, "Cannot map buffer for DMA"); | ||
39 | goto out; | ||
40 | } | ||
41 | |||
42 | - memset(id, 0, sizeof(*id)); | ||
43 | + memset(id, 0, id_size); | ||
44 | cmd.dptr.prp1 = cpu_to_le64(iova); | ||
45 | if (nvme_admin_cmd_sync(bs, &cmd)) { | ||
46 | error_setg(errp, "Failed to identify controller"); | ||
47 | @@ -XXX,XX +XXX,XX @@ static bool nvme_identify(BlockDriverState *bs, int namespace, Error **errp) | ||
48 | s->supports_write_zeroes = !!(oncs & NVME_ONCS_WRITE_ZEROES); | ||
49 | s->supports_discard = !!(oncs & NVME_ONCS_DSM); | ||
50 | |||
51 | - memset(id, 0, sizeof(*id)); | ||
52 | + memset(id, 0, id_size); | ||
53 | cmd.cdw10 = 0; | ||
54 | cmd.nsid = cpu_to_le32(namespace); | ||
55 | if (nvme_admin_cmd_sync(bs, &cmd)) { | ||
56 | -- | ||
57 | 2.28.0 | ||
58 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: Eric Auger <eric.auger@redhat.com> | ||
2 | 1 | ||
3 | In preparation of 64kB host page support, let's change the size | ||
4 | and alignment of the queue so that the VFIO DMA MAP succeeds. | ||
5 | We align on the host page size. | ||
6 | |||
7 | Signed-off-by: Eric Auger <eric.auger@redhat.com> | ||
8 | Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
9 | Tested-by: Eric Auger <eric.auger@redhat.com> | ||
10 | Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com> | ||
11 | Message-id: 20201029093306.1063879-21-philmd@redhat.com | ||
12 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
13 | Tested-by: Eric Auger <eric.auger@redhat.com> | ||
14 | --- | ||
15 | block/nvme.c | 4 ++-- | ||
16 | 1 file changed, 2 insertions(+), 2 deletions(-) | ||
17 | |||
18 | diff --git a/block/nvme.c b/block/nvme.c | ||
19 | index XXXXXXX..XXXXXXX 100644 | ||
20 | --- a/block/nvme.c | ||
21 | +++ b/block/nvme.c | ||
22 | @@ -XXX,XX +XXX,XX @@ static bool nvme_init_queue(BDRVNVMeState *s, NVMeQueue *q, | ||
23 | size_t bytes; | ||
24 | int r; | ||
25 | |||
26 | - bytes = ROUND_UP(nentries * entry_bytes, s->page_size); | ||
27 | + bytes = ROUND_UP(nentries * entry_bytes, qemu_real_host_page_size); | ||
28 | q->head = q->tail = 0; | ||
29 | - q->queue = qemu_try_memalign(s->page_size, bytes); | ||
30 | + q->queue = qemu_try_memalign(qemu_real_host_page_size, bytes); | ||
31 | if (!q->queue) { | ||
32 | error_setg(errp, "Cannot allocate queue"); | ||
33 | return false; | ||
34 | -- | ||
35 | 2.28.0 | ||
36 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: Eric Auger <eric.auger@redhat.com> | ||
2 | 1 | ||
3 | In preparation of 64kB host page support, let's change the size | ||
4 | and alignment of the prp_list_pages so that the VFIO DMA MAP succeeds | ||
5 | with 64kB host page size. We align on the host page size. | ||
6 | |||
7 | Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com> | ||
8 | Signed-off-by: Eric Auger <eric.auger@redhat.com> | ||
9 | Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
10 | Tested-by: Eric Auger <eric.auger@redhat.com> | ||
11 | Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com> | ||
12 | Message-id: 20201029093306.1063879-22-philmd@redhat.com | ||
13 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
14 | Tested-by: Eric Auger <eric.auger@redhat.com> | ||
15 | --- | ||
16 | block/nvme.c | 11 ++++++----- | ||
17 | 1 file changed, 6 insertions(+), 5 deletions(-) | ||
18 | |||
19 | diff --git a/block/nvme.c b/block/nvme.c | ||
20 | index XXXXXXX..XXXXXXX 100644 | ||
21 | --- a/block/nvme.c | ||
22 | +++ b/block/nvme.c | ||
23 | @@ -XXX,XX +XXX,XX @@ static NVMeQueuePair *nvme_create_queue_pair(BDRVNVMeState *s, | ||
24 | int i, r; | ||
25 | NVMeQueuePair *q; | ||
26 | uint64_t prp_list_iova; | ||
27 | + size_t bytes; | ||
28 | |||
29 | q = g_try_new0(NVMeQueuePair, 1); | ||
30 | if (!q) { | ||
31 | @@ -XXX,XX +XXX,XX @@ static NVMeQueuePair *nvme_create_queue_pair(BDRVNVMeState *s, | ||
32 | } | ||
33 | trace_nvme_create_queue_pair(idx, q, size, aio_context, | ||
34 | event_notifier_get_fd(s->irq_notifier)); | ||
35 | - q->prp_list_pages = qemu_try_memalign(s->page_size, | ||
36 | - s->page_size * NVME_NUM_REQS); | ||
37 | + bytes = QEMU_ALIGN_UP(s->page_size * NVME_NUM_REQS, | ||
38 | + qemu_real_host_page_size); | ||
39 | + q->prp_list_pages = qemu_try_memalign(qemu_real_host_page_size, bytes); | ||
40 | if (!q->prp_list_pages) { | ||
41 | goto fail; | ||
42 | } | ||
43 | - memset(q->prp_list_pages, 0, s->page_size * NVME_NUM_REQS); | ||
44 | + memset(q->prp_list_pages, 0, bytes); | ||
45 | qemu_mutex_init(&q->lock); | ||
46 | q->s = s; | ||
47 | q->index = idx; | ||
48 | qemu_co_queue_init(&q->free_req_queue); | ||
49 | q->completion_bh = aio_bh_new(aio_context, nvme_process_completion_bh, q); | ||
50 | - r = qemu_vfio_dma_map(s->vfio, q->prp_list_pages, | ||
51 | - s->page_size * NVME_NUM_REQS, | ||
52 | + r = qemu_vfio_dma_map(s->vfio, q->prp_list_pages, bytes, | ||
53 | false, &prp_list_iova); | ||
54 | if (r) { | ||
55 | goto fail; | ||
56 | -- | ||
57 | 2.28.0 | ||
58 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: Eric Auger <eric.auger@redhat.com> | ||
2 | 1 | ||
3 | Make sure iov's va and size are properly aligned on the | ||
4 | host page size. | ||
5 | |||
6 | Signed-off-by: Eric Auger <eric.auger@redhat.com> | ||
7 | Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com> | ||
8 | Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
9 | Tested-by: Eric Auger <eric.auger@redhat.com> | ||
10 | Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com> | ||
11 | Message-id: 20201029093306.1063879-23-philmd@redhat.com | ||
12 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
13 | Tested-by: Eric Auger <eric.auger@redhat.com> | ||
14 | --- | ||
15 | block/nvme.c | 14 ++++++++------ | ||
16 | 1 file changed, 8 insertions(+), 6 deletions(-) | ||
17 | |||
18 | diff --git a/block/nvme.c b/block/nvme.c | ||
19 | index XXXXXXX..XXXXXXX 100644 | ||
20 | --- a/block/nvme.c | ||
21 | +++ b/block/nvme.c | ||
22 | @@ -XXX,XX +XXX,XX @@ static coroutine_fn int nvme_cmd_map_qiov(BlockDriverState *bs, NvmeCmd *cmd, | ||
23 | for (i = 0; i < qiov->niov; ++i) { | ||
24 | bool retry = true; | ||
25 | uint64_t iova; | ||
26 | + size_t len = QEMU_ALIGN_UP(qiov->iov[i].iov_len, | ||
27 | + qemu_real_host_page_size); | ||
28 | try_map: | ||
29 | r = qemu_vfio_dma_map(s->vfio, | ||
30 | qiov->iov[i].iov_base, | ||
31 | - qiov->iov[i].iov_len, | ||
32 | - true, &iova); | ||
33 | + len, true, &iova); | ||
34 | if (r == -ENOMEM && retry) { | ||
35 | retry = false; | ||
36 | trace_nvme_dma_flush_queue_wait(s); | ||
37 | @@ -XXX,XX +XXX,XX @@ static inline bool nvme_qiov_aligned(BlockDriverState *bs, | ||
38 | BDRVNVMeState *s = bs->opaque; | ||
39 | |||
40 | for (i = 0; i < qiov->niov; ++i) { | ||
41 | - if (!QEMU_PTR_IS_ALIGNED(qiov->iov[i].iov_base, s->page_size) || | ||
42 | - !QEMU_IS_ALIGNED(qiov->iov[i].iov_len, s->page_size)) { | ||
43 | + if (!QEMU_PTR_IS_ALIGNED(qiov->iov[i].iov_base, | ||
44 | + qemu_real_host_page_size) || | ||
45 | + !QEMU_IS_ALIGNED(qiov->iov[i].iov_len, qemu_real_host_page_size)) { | ||
46 | trace_nvme_qiov_unaligned(qiov, i, qiov->iov[i].iov_base, | ||
47 | qiov->iov[i].iov_len, s->page_size); | ||
48 | return false; | ||
49 | @@ -XXX,XX +XXX,XX @@ static int nvme_co_prw(BlockDriverState *bs, uint64_t offset, uint64_t bytes, | ||
50 | int r; | ||
51 | uint8_t *buf = NULL; | ||
52 | QEMUIOVector local_qiov; | ||
53 | - | ||
54 | + size_t len = QEMU_ALIGN_UP(bytes, qemu_real_host_page_size); | ||
55 | assert(QEMU_IS_ALIGNED(offset, s->page_size)); | ||
56 | assert(QEMU_IS_ALIGNED(bytes, s->page_size)); | ||
57 | assert(bytes <= s->max_transfer); | ||
58 | @@ -XXX,XX +XXX,XX @@ static int nvme_co_prw(BlockDriverState *bs, uint64_t offset, uint64_t bytes, | ||
59 | } | ||
60 | s->stats.unaligned_accesses++; | ||
61 | trace_nvme_prw_buffered(s, offset, bytes, qiov->niov, is_write); | ||
62 | - buf = qemu_try_memalign(s->page_size, bytes); | ||
63 | + buf = qemu_try_memalign(qemu_real_host_page_size, len); | ||
64 | |||
65 | if (!buf) { | ||
66 | return -ENOMEM; | ||
67 | -- | ||
68 | 2.28.0 | ||
69 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: Philippe Mathieu-Daudé <philmd@redhat.com> | ||
2 | 1 | ||
3 | qemu_vfio_pci_map_bar() calls mmap(), and mmap(2) states: | ||
4 | |||
5 | 'offset' must be a multiple of the page size as returned | ||
6 | by sysconf(_SC_PAGE_SIZE). | ||
7 | |||
8 | In commit f68453237b9 we started to use an offset of 4K which | ||
9 | broke this contract on Aarch64 arch. | ||
10 | |||
11 | Fix by mapping at offset 0, and and accessing doorbells at offset=4K. | ||
12 | |||
13 | Fixes: f68453237b9 ("block/nvme: Map doorbells pages write-only") | ||
14 | Reported-by: Eric Auger <eric.auger@redhat.com> | ||
15 | Reviewed-by: Eric Auger <eric.auger@redhat.com> | ||
16 | Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
17 | Tested-by: Eric Auger <eric.auger@redhat.com> | ||
18 | Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com> | ||
19 | Message-id: 20201029093306.1063879-24-philmd@redhat.com | ||
20 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
21 | Tested-by: Eric Auger <eric.auger@redhat.com> | ||
22 | --- | ||
23 | block/nvme.c | 11 +++++++---- | ||
24 | 1 file changed, 7 insertions(+), 4 deletions(-) | ||
25 | |||
26 | diff --git a/block/nvme.c b/block/nvme.c | ||
27 | index XXXXXXX..XXXXXXX 100644 | ||
28 | --- a/block/nvme.c | ||
29 | +++ b/block/nvme.c | ||
30 | @@ -XXX,XX +XXX,XX @@ typedef struct { | ||
31 | struct BDRVNVMeState { | ||
32 | AioContext *aio_context; | ||
33 | QEMUVFIOState *vfio; | ||
34 | + void *bar0_wo_map; | ||
35 | /* Memory mapped registers */ | ||
36 | volatile struct { | ||
37 | uint32_t sq_tail; | ||
38 | @@ -XXX,XX +XXX,XX @@ static int nvme_init(BlockDriverState *bs, const char *device, int namespace, | ||
39 | } | ||
40 | } | ||
41 | |||
42 | - s->doorbells = qemu_vfio_pci_map_bar(s->vfio, 0, sizeof(NvmeBar), | ||
43 | - NVME_DOORBELL_SIZE, PROT_WRITE, errp); | ||
44 | + s->bar0_wo_map = qemu_vfio_pci_map_bar(s->vfio, 0, 0, | ||
45 | + sizeof(NvmeBar) + NVME_DOORBELL_SIZE, | ||
46 | + PROT_WRITE, errp); | ||
47 | + s->doorbells = (void *)((uintptr_t)s->bar0_wo_map + sizeof(NvmeBar)); | ||
48 | if (!s->doorbells) { | ||
49 | ret = -EINVAL; | ||
50 | goto out; | ||
51 | @@ -XXX,XX +XXX,XX @@ static void nvme_close(BlockDriverState *bs) | ||
52 | &s->irq_notifier[MSIX_SHARED_IRQ_IDX], | ||
53 | false, NULL, NULL); | ||
54 | event_notifier_cleanup(&s->irq_notifier[MSIX_SHARED_IRQ_IDX]); | ||
55 | - qemu_vfio_pci_unmap_bar(s->vfio, 0, (void *)s->doorbells, | ||
56 | - sizeof(NvmeBar), NVME_DOORBELL_SIZE); | ||
57 | + qemu_vfio_pci_unmap_bar(s->vfio, 0, s->bar0_wo_map, | ||
58 | + 0, sizeof(NvmeBar) + NVME_DOORBELL_SIZE); | ||
59 | qemu_vfio_close(s->vfio); | ||
60 | |||
61 | g_free(s->device); | ||
62 | -- | ||
63 | 2.28.0 | ||
64 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: Philippe Mathieu-Daudé <philmd@redhat.com> | ||
2 | 1 | ||
3 | The Completion Queue Command Identifier is a 16-bit value, | ||
4 | so nvme_submit_command() is unlikely to work on big-endian | ||
5 | hosts, as the relevant bits are truncated. | ||
6 | Fix by using the correct byte-swap function. | ||
7 | |||
8 | Fixes: bdd6a90a9e5 ("block: Add VFIO based NVMe driver") | ||
9 | Reported-by: Keith Busch <kbusch@kernel.org> | ||
10 | Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com> | ||
11 | Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
12 | Message-id: 20201029093306.1063879-25-philmd@redhat.com | ||
13 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
14 | Tested-by: Eric Auger <eric.auger@redhat.com> | ||
15 | --- | ||
16 | block/nvme.c | 2 +- | ||
17 | 1 file changed, 1 insertion(+), 1 deletion(-) | ||
18 | |||
19 | diff --git a/block/nvme.c b/block/nvme.c | ||
20 | index XXXXXXX..XXXXXXX 100644 | ||
21 | --- a/block/nvme.c | ||
22 | +++ b/block/nvme.c | ||
23 | @@ -XXX,XX +XXX,XX @@ static void nvme_submit_command(NVMeQueuePair *q, NVMeRequest *req, | ||
24 | assert(!req->cb); | ||
25 | req->cb = cb; | ||
26 | req->opaque = opaque; | ||
27 | - cmd->cid = cpu_to_le32(req->cid); | ||
28 | + cmd->cid = cpu_to_le16(req->cid); | ||
29 | |||
30 | trace_nvme_submit_command(q->s, q->index, req->cid); | ||
31 | nvme_trace_command(cmd); | ||
32 | -- | ||
33 | 2.28.0 | ||
34 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: Philippe Mathieu-Daudé <philmd@redhat.com> | ||
2 | 1 | ||
3 | Change the confuse "VFIO IOMMU check failed" error message by | ||
4 | the explicit "VFIO IOMMU Type1 is not supported" once. | ||
5 | |||
6 | Example on POWER: | ||
7 | |||
8 | $ qemu-system-ppc64 -drive if=none,id=nvme0,file=nvme://0001:01:00.0/1,format=raw | ||
9 | qemu-system-ppc64: -drive if=none,id=nvme0,file=nvme://0001:01:00.0/1,format=raw: VFIO IOMMU Type1 is not supported | ||
10 | |||
11 | Suggested-by: Alex Williamson <alex.williamson@redhat.com> | ||
12 | Reviewed-by: Fam Zheng <fam@euphon.net> | ||
13 | Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
14 | Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com> | ||
15 | Message-id: 20201103020733.2303148-2-philmd@redhat.com | ||
16 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
17 | Tested-by: Eric Auger <eric.auger@redhat.com> | ||
18 | --- | ||
19 | util/vfio-helpers.c | 2 +- | ||
20 | 1 file changed, 1 insertion(+), 1 deletion(-) | ||
21 | |||
22 | diff --git a/util/vfio-helpers.c b/util/vfio-helpers.c | ||
23 | index XXXXXXX..XXXXXXX 100644 | ||
24 | --- a/util/vfio-helpers.c | ||
25 | +++ b/util/vfio-helpers.c | ||
26 | @@ -XXX,XX +XXX,XX @@ static int qemu_vfio_init_pci(QEMUVFIOState *s, const char *device, | ||
27 | } | ||
28 | |||
29 | if (!ioctl(s->container, VFIO_CHECK_EXTENSION, VFIO_TYPE1_IOMMU)) { | ||
30 | - error_setg_errno(errp, errno, "VFIO IOMMU check failed"); | ||
31 | + error_setg_errno(errp, errno, "VFIO IOMMU Type1 is not supported"); | ||
32 | ret = -EINVAL; | ||
33 | goto fail_container; | ||
34 | } | ||
35 | -- | ||
36 | 2.28.0 | ||
37 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: Philippe Mathieu-Daudé <philmd@redhat.com> | ||
2 | 1 | ||
3 | We sometime get kernel panic with some devices on Aarch64 | ||
4 | hosts. Alex Williamson suggests it might be broken PCIe | ||
5 | root complex. Add trace event to record the latest I/O | ||
6 | access before crashing. In case, assert our accesses are | ||
7 | aligned. | ||
8 | |||
9 | Reviewed-by: Fam Zheng <fam@euphon.net> | ||
10 | Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
11 | Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com> | ||
12 | Message-id: 20201103020733.2303148-3-philmd@redhat.com | ||
13 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
14 | Tested-by: Eric Auger <eric.auger@redhat.com> | ||
15 | --- | ||
16 | util/vfio-helpers.c | 8 ++++++++ | ||
17 | util/trace-events | 2 ++ | ||
18 | 2 files changed, 10 insertions(+) | ||
19 | |||
20 | diff --git a/util/vfio-helpers.c b/util/vfio-helpers.c | ||
21 | index XXXXXXX..XXXXXXX 100644 | ||
22 | --- a/util/vfio-helpers.c | ||
23 | +++ b/util/vfio-helpers.c | ||
24 | @@ -XXX,XX +XXX,XX @@ static int qemu_vfio_pci_read_config(QEMUVFIOState *s, void *buf, | ||
25 | { | ||
26 | int ret; | ||
27 | |||
28 | + trace_qemu_vfio_pci_read_config(buf, ofs, size, | ||
29 | + s->config_region_info.offset, | ||
30 | + s->config_region_info.size); | ||
31 | + assert(QEMU_IS_ALIGNED(s->config_region_info.offset + ofs, size)); | ||
32 | do { | ||
33 | ret = pread(s->device, buf, size, s->config_region_info.offset + ofs); | ||
34 | } while (ret == -1 && errno == EINTR); | ||
35 | @@ -XXX,XX +XXX,XX @@ static int qemu_vfio_pci_write_config(QEMUVFIOState *s, void *buf, int size, int | ||
36 | { | ||
37 | int ret; | ||
38 | |||
39 | + trace_qemu_vfio_pci_write_config(buf, ofs, size, | ||
40 | + s->config_region_info.offset, | ||
41 | + s->config_region_info.size); | ||
42 | + assert(QEMU_IS_ALIGNED(s->config_region_info.offset + ofs, size)); | ||
43 | do { | ||
44 | ret = pwrite(s->device, buf, size, s->config_region_info.offset + ofs); | ||
45 | } while (ret == -1 && errno == EINTR); | ||
46 | diff --git a/util/trace-events b/util/trace-events | ||
47 | index XXXXXXX..XXXXXXX 100644 | ||
48 | --- a/util/trace-events | ||
49 | +++ b/util/trace-events | ||
50 | @@ -XXX,XX +XXX,XX @@ qemu_vfio_new_mapping(void *s, void *host, size_t size, int index, uint64_t iova | ||
51 | qemu_vfio_do_mapping(void *s, void *host, size_t size, uint64_t iova) "s %p host %p size 0x%zx iova 0x%"PRIx64 | ||
52 | qemu_vfio_dma_map(void *s, void *host, size_t size, bool temporary, uint64_t *iova) "s %p host %p size 0x%zx temporary %d iova %p" | ||
53 | qemu_vfio_dma_unmap(void *s, void *host) "s %p host %p" | ||
54 | +qemu_vfio_pci_read_config(void *buf, int ofs, int size, uint64_t region_ofs, uint64_t region_size) "read cfg ptr %p ofs 0x%x size 0x%x (region addr 0x%"PRIx64" size 0x%"PRIx64")" | ||
55 | +qemu_vfio_pci_write_config(void *buf, int ofs, int size, uint64_t region_ofs, uint64_t region_size) "write cfg ptr %p ofs 0x%x size 0x%x (region addr 0x%"PRIx64" size 0x%"PRIx64")" | ||
56 | -- | ||
57 | 2.28.0 | ||
58 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: Philippe Mathieu-Daudé <philmd@redhat.com> | ||
2 | 1 | ||
3 | For debug purpose, trace BAR regions info. | ||
4 | |||
5 | Reviewed-by: Fam Zheng <fam@euphon.net> | ||
6 | Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
7 | Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com> | ||
8 | Message-id: 20201103020733.2303148-4-philmd@redhat.com | ||
9 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
10 | Tested-by: Eric Auger <eric.auger@redhat.com> | ||
11 | --- | ||
12 | util/vfio-helpers.c | 8 ++++++++ | ||
13 | util/trace-events | 1 + | ||
14 | 2 files changed, 9 insertions(+) | ||
15 | |||
16 | diff --git a/util/vfio-helpers.c b/util/vfio-helpers.c | ||
17 | index XXXXXXX..XXXXXXX 100644 | ||
18 | --- a/util/vfio-helpers.c | ||
19 | +++ b/util/vfio-helpers.c | ||
20 | @@ -XXX,XX +XXX,XX @@ static inline void assert_bar_index_valid(QEMUVFIOState *s, int index) | ||
21 | |||
22 | static int qemu_vfio_pci_init_bar(QEMUVFIOState *s, int index, Error **errp) | ||
23 | { | ||
24 | + g_autofree char *barname = NULL; | ||
25 | assert_bar_index_valid(s, index); | ||
26 | s->bar_region_info[index] = (struct vfio_region_info) { | ||
27 | .index = VFIO_PCI_BAR0_REGION_INDEX + index, | ||
28 | @@ -XXX,XX +XXX,XX @@ static int qemu_vfio_pci_init_bar(QEMUVFIOState *s, int index, Error **errp) | ||
29 | error_setg_errno(errp, errno, "Failed to get BAR region info"); | ||
30 | return -errno; | ||
31 | } | ||
32 | + barname = g_strdup_printf("bar[%d]", index); | ||
33 | + trace_qemu_vfio_region_info(barname, s->bar_region_info[index].offset, | ||
34 | + s->bar_region_info[index].size, | ||
35 | + s->bar_region_info[index].cap_offset); | ||
36 | |||
37 | return 0; | ||
38 | } | ||
39 | @@ -XXX,XX +XXX,XX @@ static int qemu_vfio_init_pci(QEMUVFIOState *s, const char *device, | ||
40 | ret = -errno; | ||
41 | goto fail; | ||
42 | } | ||
43 | + trace_qemu_vfio_region_info("config", s->config_region_info.offset, | ||
44 | + s->config_region_info.size, | ||
45 | + s->config_region_info.cap_offset); | ||
46 | |||
47 | for (i = 0; i < ARRAY_SIZE(s->bar_region_info); i++) { | ||
48 | ret = qemu_vfio_pci_init_bar(s, i, errp); | ||
49 | diff --git a/util/trace-events b/util/trace-events | ||
50 | index XXXXXXX..XXXXXXX 100644 | ||
51 | --- a/util/trace-events | ||
52 | +++ b/util/trace-events | ||
53 | @@ -XXX,XX +XXX,XX @@ qemu_vfio_dma_map(void *s, void *host, size_t size, bool temporary, uint64_t *io | ||
54 | qemu_vfio_dma_unmap(void *s, void *host) "s %p host %p" | ||
55 | qemu_vfio_pci_read_config(void *buf, int ofs, int size, uint64_t region_ofs, uint64_t region_size) "read cfg ptr %p ofs 0x%x size 0x%x (region addr 0x%"PRIx64" size 0x%"PRIx64")" | ||
56 | qemu_vfio_pci_write_config(void *buf, int ofs, int size, uint64_t region_ofs, uint64_t region_size) "write cfg ptr %p ofs 0x%x size 0x%x (region addr 0x%"PRIx64" size 0x%"PRIx64")" | ||
57 | +qemu_vfio_region_info(const char *desc, uint64_t region_ofs, uint64_t region_size, uint32_t cap_offset) "region '%s' addr 0x%"PRIx64" size 0x%"PRIx64" cap_ofs 0x%"PRIx32 | ||
58 | -- | ||
59 | 2.28.0 | ||
60 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: Philippe Mathieu-Daudé <philmd@redhat.com> | ||
2 | 1 | ||
3 | For debugging purpose, trace where a BAR is mapped. | ||
4 | |||
5 | Reviewed-by: Fam Zheng <fam@euphon.net> | ||
6 | Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
7 | Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com> | ||
8 | Message-id: 20201103020733.2303148-5-philmd@redhat.com | ||
9 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
10 | Tested-by: Eric Auger <eric.auger@redhat.com> | ||
11 | --- | ||
12 | util/vfio-helpers.c | 2 ++ | ||
13 | util/trace-events | 1 + | ||
14 | 2 files changed, 3 insertions(+) | ||
15 | |||
16 | diff --git a/util/vfio-helpers.c b/util/vfio-helpers.c | ||
17 | index XXXXXXX..XXXXXXX 100644 | ||
18 | --- a/util/vfio-helpers.c | ||
19 | +++ b/util/vfio-helpers.c | ||
20 | @@ -XXX,XX +XXX,XX @@ void *qemu_vfio_pci_map_bar(QEMUVFIOState *s, int index, | ||
21 | p = mmap(NULL, MIN(size, s->bar_region_info[index].size - offset), | ||
22 | prot, MAP_SHARED, | ||
23 | s->device, s->bar_region_info[index].offset + offset); | ||
24 | + trace_qemu_vfio_pci_map_bar(index, s->bar_region_info[index].offset , | ||
25 | + size, offset, p); | ||
26 | if (p == MAP_FAILED) { | ||
27 | error_setg_errno(errp, errno, "Failed to map BAR region"); | ||
28 | p = NULL; | ||
29 | diff --git a/util/trace-events b/util/trace-events | ||
30 | index XXXXXXX..XXXXXXX 100644 | ||
31 | --- a/util/trace-events | ||
32 | +++ b/util/trace-events | ||
33 | @@ -XXX,XX +XXX,XX @@ qemu_vfio_dma_unmap(void *s, void *host) "s %p host %p" | ||
34 | qemu_vfio_pci_read_config(void *buf, int ofs, int size, uint64_t region_ofs, uint64_t region_size) "read cfg ptr %p ofs 0x%x size 0x%x (region addr 0x%"PRIx64" size 0x%"PRIx64")" | ||
35 | qemu_vfio_pci_write_config(void *buf, int ofs, int size, uint64_t region_ofs, uint64_t region_size) "write cfg ptr %p ofs 0x%x size 0x%x (region addr 0x%"PRIx64" size 0x%"PRIx64")" | ||
36 | qemu_vfio_region_info(const char *desc, uint64_t region_ofs, uint64_t region_size, uint32_t cap_offset) "region '%s' addr 0x%"PRIx64" size 0x%"PRIx64" cap_ofs 0x%"PRIx32 | ||
37 | +qemu_vfio_pci_map_bar(int index, uint64_t region_ofs, uint64_t region_size, int ofs, void *host) "map region bar#%d addr 0x%"PRIx64" size 0x%"PRIx64" ofs 0x%x host %p" | ||
38 | -- | ||
39 | 2.28.0 | ||
40 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: Philippe Mathieu-Daudé <philmd@redhat.com> | ||
2 | 1 | ||
3 | For debugging purpose, trace where DMA regions are mapped. | ||
4 | |||
5 | Reviewed-by: Fam Zheng <fam@euphon.net> | ||
6 | Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
7 | Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com> | ||
8 | Message-id: 20201103020733.2303148-6-philmd@redhat.com | ||
9 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
10 | Tested-by: Eric Auger <eric.auger@redhat.com> | ||
11 | --- | ||
12 | util/vfio-helpers.c | 3 ++- | ||
13 | util/trace-events | 5 +++-- | ||
14 | 2 files changed, 5 insertions(+), 3 deletions(-) | ||
15 | |||
16 | diff --git a/util/vfio-helpers.c b/util/vfio-helpers.c | ||
17 | index XXXXXXX..XXXXXXX 100644 | ||
18 | --- a/util/vfio-helpers.c | ||
19 | +++ b/util/vfio-helpers.c | ||
20 | @@ -XXX,XX +XXX,XX @@ static int qemu_vfio_do_mapping(QEMUVFIOState *s, void *host, size_t size, | ||
21 | .vaddr = (uintptr_t)host, | ||
22 | .size = size, | ||
23 | }; | ||
24 | - trace_qemu_vfio_do_mapping(s, host, size, iova); | ||
25 | + trace_qemu_vfio_do_mapping(s, host, iova, size); | ||
26 | |||
27 | if (ioctl(s->container, VFIO_IOMMU_MAP_DMA, &dma_map)) { | ||
28 | error_report("VFIO_MAP_DMA failed: %s", strerror(errno)); | ||
29 | @@ -XXX,XX +XXX,XX @@ int qemu_vfio_dma_map(QEMUVFIOState *s, void *host, size_t size, | ||
30 | } | ||
31 | } | ||
32 | } | ||
33 | + trace_qemu_vfio_dma_mapped(s, host, iova0, size); | ||
34 | if (iova) { | ||
35 | *iova = iova0; | ||
36 | } | ||
37 | diff --git a/util/trace-events b/util/trace-events | ||
38 | index XXXXXXX..XXXXXXX 100644 | ||
39 | --- a/util/trace-events | ||
40 | +++ b/util/trace-events | ||
41 | @@ -XXX,XX +XXX,XX @@ qemu_vfio_ram_block_added(void *s, void *p, size_t size) "s %p host %p size 0x%z | ||
42 | qemu_vfio_ram_block_removed(void *s, void *p, size_t size) "s %p host %p size 0x%zx" | ||
43 | qemu_vfio_find_mapping(void *s, void *p) "s %p host %p" | ||
44 | qemu_vfio_new_mapping(void *s, void *host, size_t size, int index, uint64_t iova) "s %p host %p size 0x%zx index %d iova 0x%"PRIx64 | ||
45 | -qemu_vfio_do_mapping(void *s, void *host, size_t size, uint64_t iova) "s %p host %p size 0x%zx iova 0x%"PRIx64 | ||
46 | -qemu_vfio_dma_map(void *s, void *host, size_t size, bool temporary, uint64_t *iova) "s %p host %p size 0x%zx temporary %d iova %p" | ||
47 | +qemu_vfio_do_mapping(void *s, void *host, uint64_t iova, size_t size) "s %p host %p <-> iova 0x%"PRIx64 " size 0x%zx" | ||
48 | +qemu_vfio_dma_map(void *s, void *host, size_t size, bool temporary, uint64_t *iova) "s %p host %p size 0x%zx temporary %d &iova %p" | ||
49 | +qemu_vfio_dma_mapped(void *s, void *host, uint64_t iova, size_t size) "s %p host %p <-> iova 0x%"PRIx64" size 0x%zx" | ||
50 | qemu_vfio_dma_unmap(void *s, void *host) "s %p host %p" | ||
51 | qemu_vfio_pci_read_config(void *buf, int ofs, int size, uint64_t region_ofs, uint64_t region_size) "read cfg ptr %p ofs 0x%x size 0x%x (region addr 0x%"PRIx64" size 0x%"PRIx64")" | ||
52 | qemu_vfio_pci_write_config(void *buf, int ofs, int size, uint64_t region_ofs, uint64_t region_size) "write cfg ptr %p ofs 0x%x size 0x%x (region addr 0x%"PRIx64" size 0x%"PRIx64")" | ||
53 | -- | ||
54 | 2.28.0 | ||
55 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: Philippe Mathieu-Daudé <philmd@redhat.com> | ||
2 | 1 | ||
3 | mmap(2) states: | ||
4 | |||
5 | 'offset' must be a multiple of the page size as returned | ||
6 | by sysconf(_SC_PAGE_SIZE). | ||
7 | |||
8 | Add an assertion to be sure we don't break this contract. | ||
9 | |||
10 | Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com> | ||
11 | Message-id: 20201103020733.2303148-8-philmd@redhat.com | ||
12 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
13 | Tested-by: Eric Auger <eric.auger@redhat.com> | ||
14 | --- | ||
15 | util/vfio-helpers.c | 1 + | ||
16 | 1 file changed, 1 insertion(+) | ||
17 | |||
18 | diff --git a/util/vfio-helpers.c b/util/vfio-helpers.c | ||
19 | index XXXXXXX..XXXXXXX 100644 | ||
20 | --- a/util/vfio-helpers.c | ||
21 | +++ b/util/vfio-helpers.c | ||
22 | @@ -XXX,XX +XXX,XX @@ void *qemu_vfio_pci_map_bar(QEMUVFIOState *s, int index, | ||
23 | Error **errp) | ||
24 | { | ||
25 | void *p; | ||
26 | + assert(QEMU_IS_ALIGNED(offset, qemu_real_host_page_size)); | ||
27 | assert_bar_index_valid(s, index); | ||
28 | p = mmap(NULL, MIN(size, s->bar_region_info[index].size - offset), | ||
29 | prot, MAP_SHARED, | ||
30 | -- | ||
31 | 2.28.0 | ||
32 | diff view generated by jsdifflib |