1 | The following changes since commit d147f7e815f97cb477e223586bcb80c316ae10ea: | 1 | The following changes since commit 3521ade3510eb5cefb2e27a101667f25dad89935: |
---|---|---|---|
2 | 2 | ||
3 | Merge remote-tracking branch 'remotes/bonzini/tags/for-upstream' into staging (2017-10-03 16:27:24 +0100) | 3 | Merge remote-tracking branch 'remotes/thuth-gitlab/tags/pull-request-2021-07-29' into staging (2021-07-29 13:17:20 +0100) |
4 | 4 | ||
5 | are available in the git repository at: | 5 | are available in the Git repository at: |
6 | 6 | ||
7 | git://github.com/stefanha/qemu.git tags/block-pull-request | 7 | https://gitlab.com/stefanha/qemu.git tags/block-pull-request |
8 | 8 | ||
9 | for you to fetch changes up to f708a5e71cba0d784e307334c07ade5f56f827ab: | 9 | for you to fetch changes up to cc8eecd7f105a1dff5876adeb238a14696061a4a: |
10 | 10 | ||
11 | aio: fix assert when remove poll during destroy (2017-10-03 14:36:19 -0400) | 11 | MAINTAINERS: Added myself as a reviewer for the NVMe Block Driver (2021-07-29 17:17:34 +0100) |
12 | |||
13 | ---------------------------------------------------------------- | ||
14 | Pull request | ||
15 | |||
16 | The main fix here is for io_uring. Spurious -EAGAIN errors can happen and the | ||
17 | request needs to be resubmitted. | ||
18 | |||
19 | The MAINTAINERS changes carry no risk and we might as well include them in QEMU | ||
20 | 6.1. | ||
12 | 21 | ||
13 | ---------------------------------------------------------------- | 22 | ---------------------------------------------------------------- |
14 | 23 | ||
15 | ---------------------------------------------------------------- | 24 | Fabian Ebner (1): |
25 | block/io_uring: resubmit when result is -EAGAIN | ||
16 | 26 | ||
17 | Peter Xu (4): | 27 | Philippe Mathieu-Daudé (1): |
18 | qom: provide root container for internal objs | 28 | MAINTAINERS: Added myself as a reviewer for the NVMe Block Driver |
19 | iothread: provide helpers for internal use | ||
20 | iothread: export iothread_stop() | ||
21 | iothread: delay the context release to finalize | ||
22 | 29 | ||
23 | Stefan Hajnoczi (1): | 30 | Stefano Garzarella (1): |
24 | aio: fix assert when remove poll during destroy | 31 | MAINTAINERS: add Stefano Garzarella as io_uring reviewer |
25 | 32 | ||
26 | include/qom/object.h | 11 +++++++++++ | 33 | MAINTAINERS | 2 ++ |
27 | include/sysemu/iothread.h | 9 +++++++++ | 34 | block/io_uring.c | 16 +++++++++++++++- |
28 | iothread.c | 46 ++++++++++++++++++++++++++++++++++++---------- | 35 | 2 files changed, 17 insertions(+), 1 deletion(-) |
29 | qom/object.c | 11 +++++++++++ | ||
30 | util/aio-posix.c | 9 ++++++++- | ||
31 | 5 files changed, 75 insertions(+), 11 deletions(-) | ||
32 | 36 | ||
33 | -- | 37 | -- |
34 | 2.13.6 | 38 | 2.31.1 |
35 | 39 | ||
36 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: Peter Xu <peterx@redhat.com> | ||
2 | 1 | ||
3 | We have object_get_objects_root() to keep user created objects, however | ||
4 | no place for objects that will be used internally. Create such a | ||
5 | container for internal objects. | ||
6 | |||
7 | CC: Andreas Färber <afaerber@suse.de> | ||
8 | CC: Markus Armbruster <armbru@redhat.com> | ||
9 | CC: Paolo Bonzini <pbonzini@redhat.com> | ||
10 | Suggested-by: Daniel P. Berrange <berrange@redhat.com> | ||
11 | Signed-off-by: Peter Xu <peterx@redhat.com> | ||
12 | Reviewed-by: Fam Zheng <famz@redhat.com> | ||
13 | Message-id: 20170928025958.1420-2-peterx@redhat.com | ||
14 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
15 | --- | ||
16 | include/qom/object.h | 11 +++++++++++ | ||
17 | qom/object.c | 11 +++++++++++ | ||
18 | 2 files changed, 22 insertions(+) | ||
19 | |||
20 | diff --git a/include/qom/object.h b/include/qom/object.h | ||
21 | index XXXXXXX..XXXXXXX 100644 | ||
22 | --- a/include/qom/object.h | ||
23 | +++ b/include/qom/object.h | ||
24 | @@ -XXX,XX +XXX,XX @@ Object *object_get_root(void); | ||
25 | Object *object_get_objects_root(void); | ||
26 | |||
27 | /** | ||
28 | + * object_get_internal_root: | ||
29 | + * | ||
30 | + * Get the container object that holds internally used object | ||
31 | + * instances. Any object which is put into this container must not be | ||
32 | + * user visible, and it will not be exposed in the QOM tree. | ||
33 | + * | ||
34 | + * Returns: the internal object container | ||
35 | + */ | ||
36 | +Object *object_get_internal_root(void); | ||
37 | + | ||
38 | +/** | ||
39 | * object_get_canonical_path_component: | ||
40 | * | ||
41 | * Returns: The final component in the object's canonical path. The canonical | ||
42 | diff --git a/qom/object.c b/qom/object.c | ||
43 | index XXXXXXX..XXXXXXX 100644 | ||
44 | --- a/qom/object.c | ||
45 | +++ b/qom/object.c | ||
46 | @@ -XXX,XX +XXX,XX @@ Object *object_get_objects_root(void) | ||
47 | return container_get(object_get_root(), "/objects"); | ||
48 | } | ||
49 | |||
50 | +Object *object_get_internal_root(void) | ||
51 | +{ | ||
52 | + static Object *internal_root; | ||
53 | + | ||
54 | + if (!internal_root) { | ||
55 | + internal_root = object_new("container"); | ||
56 | + } | ||
57 | + | ||
58 | + return internal_root; | ||
59 | +} | ||
60 | + | ||
61 | static void object_get_child_property(Object *obj, Visitor *v, | ||
62 | const char *name, void *opaque, | ||
63 | Error **errp) | ||
64 | -- | ||
65 | 2.13.6 | ||
66 | |||
67 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: Peter Xu <peterx@redhat.com> | ||
2 | 1 | ||
3 | IOThread is a general framework that contains IO loop environment and a | ||
4 | real thread behind. It's also good to be used internally inside qemu. | ||
5 | Provide some helpers for it to create iothreads to be used internally. | ||
6 | |||
7 | Put all the internal used iothreads into the internal object container. | ||
8 | |||
9 | Reviewed-by: Fam Zheng <famz@redhat.com> | ||
10 | Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
11 | Signed-off-by: Peter Xu <peterx@redhat.com> | ||
12 | Message-id: 20170928025958.1420-3-peterx@redhat.com | ||
13 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
14 | --- | ||
15 | include/sysemu/iothread.h | 8 ++++++++ | ||
16 | iothread.c | 16 ++++++++++++++++ | ||
17 | 2 files changed, 24 insertions(+) | ||
18 | |||
19 | diff --git a/include/sysemu/iothread.h b/include/sysemu/iothread.h | ||
20 | index XXXXXXX..XXXXXXX 100644 | ||
21 | --- a/include/sysemu/iothread.h | ||
22 | +++ b/include/sysemu/iothread.h | ||
23 | @@ -XXX,XX +XXX,XX @@ AioContext *iothread_get_aio_context(IOThread *iothread); | ||
24 | void iothread_stop_all(void); | ||
25 | GMainContext *iothread_get_g_main_context(IOThread *iothread); | ||
26 | |||
27 | +/* | ||
28 | + * Helpers used to allocate iothreads for internal use. These | ||
29 | + * iothreads will not be seen by monitor clients when query using | ||
30 | + * "query-iothreads". | ||
31 | + */ | ||
32 | +IOThread *iothread_create(const char *id, Error **errp); | ||
33 | +void iothread_destroy(IOThread *iothread); | ||
34 | + | ||
35 | #endif /* IOTHREAD_H */ | ||
36 | diff --git a/iothread.c b/iothread.c | ||
37 | index XXXXXXX..XXXXXXX 100644 | ||
38 | --- a/iothread.c | ||
39 | +++ b/iothread.c | ||
40 | @@ -XXX,XX +XXX,XX @@ GMainContext *iothread_get_g_main_context(IOThread *iothread) | ||
41 | |||
42 | return iothread->worker_context; | ||
43 | } | ||
44 | + | ||
45 | +IOThread *iothread_create(const char *id, Error **errp) | ||
46 | +{ | ||
47 | + Object *obj; | ||
48 | + | ||
49 | + obj = object_new_with_props(TYPE_IOTHREAD, | ||
50 | + object_get_internal_root(), | ||
51 | + id, errp, NULL); | ||
52 | + | ||
53 | + return IOTHREAD(obj); | ||
54 | +} | ||
55 | + | ||
56 | +void iothread_destroy(IOThread *iothread) | ||
57 | +{ | ||
58 | + object_unparent(OBJECT(iothread)); | ||
59 | +} | ||
60 | -- | ||
61 | 2.13.6 | ||
62 | |||
63 | diff view generated by jsdifflib |
1 | After iothread is enabled internally inside QEMU with GMainContext, we | 1 | From: Stefano Garzarella <sgarzare@redhat.com> |
---|---|---|---|
2 | may encounter this warning when destroying the iothread: | ||
3 | 2 | ||
4 | (qemu-system-x86_64:19925): GLib-CRITICAL **: g_source_remove_poll: | 3 | I've been working with io_uring for a while so I'd like to help |
5 | assertion '!SOURCE_DESTROYED (source)' failed | 4 | with reviews. |
6 | 5 | ||
7 | The problem is that g_source_remove_poll() does not allow to remove one | 6 | Signed-off-by: Stefano Garzarella <sgarzare@redhat.com> |
8 | source from array if the source is detached from its owner | 7 | Message-Id: <20210728131515.131045-1-sgarzare@redhat.com> |
9 | context. (peterx: which IMHO does not make much sense) | ||
10 | |||
11 | Fix it on QEMU side by avoid calling g_source_remove_poll() if we know | ||
12 | the object is during destruction, and we won't leak anything after all | ||
13 | since the array will be gone soon cleanly even with that fd. | ||
14 | |||
15 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
16 | Reviewed-by: Fam Zheng <famz@redhat.com> | ||
17 | Signed-off-by: Peter Xu <peterx@redhat.com> | ||
18 | Message-id: 20170928025958.1420-6-peterx@redhat.com | ||
19 | [peterx: write the commit message] | ||
20 | Signed-off-by: Peter Xu <peterx@redhat.com> | ||
21 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | 8 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> |
22 | --- | 9 | --- |
23 | util/aio-posix.c | 9 ++++++++- | 10 | MAINTAINERS | 1 + |
24 | 1 file changed, 8 insertions(+), 1 deletion(-) | 11 | 1 file changed, 1 insertion(+) |
25 | 12 | ||
26 | diff --git a/util/aio-posix.c b/util/aio-posix.c | 13 | diff --git a/MAINTAINERS b/MAINTAINERS |
27 | index XXXXXXX..XXXXXXX 100644 | 14 | index XXXXXXX..XXXXXXX 100644 |
28 | --- a/util/aio-posix.c | 15 | --- a/MAINTAINERS |
29 | +++ b/util/aio-posix.c | 16 | +++ b/MAINTAINERS |
30 | @@ -XXX,XX +XXX,XX @@ void aio_set_fd_handler(AioContext *ctx, | 17 | @@ -XXX,XX +XXX,XX @@ Linux io_uring |
31 | return; | 18 | M: Aarushi Mehta <mehta.aaru20@gmail.com> |
32 | } | 19 | M: Julia Suvorova <jusual@redhat.com> |
33 | 20 | M: Stefan Hajnoczi <stefanha@redhat.com> | |
34 | - g_source_remove_poll(&ctx->source, &node->pfd); | 21 | +R: Stefano Garzarella <sgarzare@redhat.com> |
35 | + /* If the GSource is in the process of being destroyed then | 22 | L: qemu-block@nongnu.org |
36 | + * g_source_remove_poll() causes an assertion failure. Skip | 23 | S: Maintained |
37 | + * removal in that case, because glib cleans up its state during | 24 | F: block/io_uring.c |
38 | + * destruction anyway. | ||
39 | + */ | ||
40 | + if (!g_source_is_destroyed(&ctx->source)) { | ||
41 | + g_source_remove_poll(&ctx->source, &node->pfd); | ||
42 | + } | ||
43 | |||
44 | /* If the lock is held, just mark the node as deleted */ | ||
45 | if (qemu_lockcnt_count(&ctx->list_lock)) { | ||
46 | -- | 25 | -- |
47 | 2.13.6 | 26 | 2.31.1 |
48 | 27 | ||
49 | diff view generated by jsdifflib |
1 | From: Peter Xu <peterx@redhat.com> | 1 | From: Fabian Ebner <f.ebner@proxmox.com> |
---|---|---|---|
2 | 2 | ||
3 | When gcontext is used with iothread, the context will be destroyed | 3 | Linux SCSI can throw spurious -EAGAIN in some corner cases in its |
4 | during iothread_stop(). That's not good since sometimes we would like | 4 | completion path, which will end up being the result in the completed |
5 | to keep the resources until iothread is destroyed, but we may want to | 5 | io_uring request. |
6 | stop the thread before that point. | ||
7 | 6 | ||
8 | Delay the destruction of gcontext to iothread finalize. Then we can do: | 7 | Resubmitting such requests should allow block jobs to complete, even |
8 | if such spurious errors are encountered. | ||
9 | 9 | ||
10 | iothread_stop(thread); | 10 | Co-authored-by: Stefan Hajnoczi <stefanha@gmail.com> |
11 | some_cleanup_on_resources(); | 11 | Reviewed-by: Stefano Garzarella <sgarzare@redhat.com> |
12 | iothread_destroy(thread); | 12 | Signed-off-by: Fabian Ebner <f.ebner@proxmox.com> |
13 | 13 | Message-id: 20210729091029.65369-1-f.ebner@proxmox.com | |
14 | We may need this patch if we want to run chardev IOs in iothreads and | ||
15 | hopefully clean them up correctly. For more specific information, | ||
16 | please see 2b316774f6 ("qemu-char: do not operate on sources from | ||
17 | finalize callbacks"). | ||
18 | |||
19 | Reviewed-by: Fam Zheng <famz@redhat.com> | ||
20 | Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
21 | Signed-off-by: Peter Xu <peterx@redhat.com> | ||
22 | Message-id: 20170928025958.1420-5-peterx@redhat.com | ||
23 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | 14 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> |
24 | --- | 15 | --- |
25 | iothread.c | 6 ++++-- | 16 | block/io_uring.c | 16 +++++++++++++++- |
26 | 1 file changed, 4 insertions(+), 2 deletions(-) | 17 | 1 file changed, 15 insertions(+), 1 deletion(-) |
27 | 18 | ||
28 | diff --git a/iothread.c b/iothread.c | 19 | diff --git a/block/io_uring.c b/block/io_uring.c |
29 | index XXXXXXX..XXXXXXX 100644 | 20 | index XXXXXXX..XXXXXXX 100644 |
30 | --- a/iothread.c | 21 | --- a/block/io_uring.c |
31 | +++ b/iothread.c | 22 | +++ b/block/io_uring.c |
32 | @@ -XXX,XX +XXX,XX @@ static void *iothread_run(void *opaque) | 23 | @@ -XXX,XX +XXX,XX @@ static void luring_process_completions(LuringState *s) |
33 | g_main_loop_unref(loop); | 24 | total_bytes = ret + luringcb->total_read; |
34 | 25 | ||
35 | g_main_context_pop_thread_default(iothread->worker_context); | 26 | if (ret < 0) { |
36 | - g_main_context_unref(iothread->worker_context); | 27 | - if (ret == -EINTR) { |
37 | - iothread->worker_context = NULL; | 28 | + /* |
38 | } | 29 | + * Only writev/readv/fsync requests on regular files or host block |
39 | } | 30 | + * devices are submitted. Therefore -EAGAIN is not expected but it's |
40 | 31 | + * known to happen sometimes with Linux SCSI. Submit again and hope | |
41 | @@ -XXX,XX +XXX,XX @@ static void iothread_instance_finalize(Object *obj) | 32 | + * the request completes successfully. |
42 | IOThread *iothread = IOTHREAD(obj); | 33 | + * |
43 | 34 | + * For more information, see: | |
44 | iothread_stop(iothread); | 35 | + * https://lore.kernel.org/io-uring/20210727165811.284510-3-axboe@kernel.dk/T/#u |
45 | + if (iothread->worker_context) { | 36 | + * |
46 | + g_main_context_unref(iothread->worker_context); | 37 | + * If the code is changed to submit other types of requests in the |
47 | + iothread->worker_context = NULL; | 38 | + * future, then this workaround may need to be extended to deal with |
48 | + } | 39 | + * genuine -EAGAIN results that should not be resubmitted |
49 | qemu_cond_destroy(&iothread->init_done_cond); | 40 | + * immediately. |
50 | qemu_mutex_destroy(&iothread->init_done_lock); | 41 | + */ |
51 | if (!iothread->ctx) { | 42 | + if (ret == -EINTR || ret == -EAGAIN) { |
43 | luring_resubmit(s, luringcb); | ||
44 | continue; | ||
45 | } | ||
52 | -- | 46 | -- |
53 | 2.13.6 | 47 | 2.31.1 |
54 | 48 | ||
55 | diff view generated by jsdifflib |
1 | From: Peter Xu <peterx@redhat.com> | 1 | From: Philippe Mathieu-Daudé <philmd@redhat.com> |
---|---|---|---|
2 | 2 | ||
3 | So that internal iothread users can explicitly stop one iothread without | 3 | I'm interested in following the activity around the NVMe bdrv. |
4 | destroying it. | ||
5 | 4 | ||
6 | Since at it, fix iothread_stop() to allow it to be called multiple | 5 | Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com> |
7 | times. Before this patch we may call iothread_stop() more than once on | 6 | Message-id: 20210728183340.2018313-1-philmd@redhat.com |
8 | single iothread, while that may not be correct since qemu_thread_join() | ||
9 | is not allowed to run twice. From manual of pthread_join(): | ||
10 | |||
11 | Joining with a thread that has previously been joined results in | ||
12 | undefined behavior. | ||
13 | |||
14 | Reviewed-by: Fam Zheng <famz@redhat.com> | ||
15 | Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
16 | Signed-off-by: Peter Xu <peterx@redhat.com> | ||
17 | Message-id: 20170928025958.1420-4-peterx@redhat.com | ||
18 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | 7 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> |
19 | --- | 8 | --- |
20 | include/sysemu/iothread.h | 1 + | 9 | MAINTAINERS | 1 + |
21 | iothread.c | 24 ++++++++++++++++-------- | 10 | 1 file changed, 1 insertion(+) |
22 | 2 files changed, 17 insertions(+), 8 deletions(-) | ||
23 | 11 | ||
24 | diff --git a/include/sysemu/iothread.h b/include/sysemu/iothread.h | 12 | diff --git a/MAINTAINERS b/MAINTAINERS |
25 | index XXXXXXX..XXXXXXX 100644 | 13 | index XXXXXXX..XXXXXXX 100644 |
26 | --- a/include/sysemu/iothread.h | 14 | --- a/MAINTAINERS |
27 | +++ b/include/sysemu/iothread.h | 15 | +++ b/MAINTAINERS |
28 | @@ -XXX,XX +XXX,XX @@ GMainContext *iothread_get_g_main_context(IOThread *iothread); | 16 | @@ -XXX,XX +XXX,XX @@ F: block/null.c |
29 | * "query-iothreads". | 17 | NVMe Block Driver |
30 | */ | 18 | M: Stefan Hajnoczi <stefanha@redhat.com> |
31 | IOThread *iothread_create(const char *id, Error **errp); | 19 | R: Fam Zheng <fam@euphon.net> |
32 | +void iothread_stop(IOThread *iothread); | 20 | +R: Philippe Mathieu-Daudé <philmd@redhat.com> |
33 | void iothread_destroy(IOThread *iothread); | 21 | L: qemu-block@nongnu.org |
34 | 22 | S: Supported | |
35 | #endif /* IOTHREAD_H */ | 23 | F: block/nvme* |
36 | diff --git a/iothread.c b/iothread.c | ||
37 | index XXXXXXX..XXXXXXX 100644 | ||
38 | --- a/iothread.c | ||
39 | +++ b/iothread.c | ||
40 | @@ -XXX,XX +XXX,XX @@ static void *iothread_run(void *opaque) | ||
41 | return NULL; | ||
42 | } | ||
43 | |||
44 | -static int iothread_stop(Object *object, void *opaque) | ||
45 | +void iothread_stop(IOThread *iothread) | ||
46 | { | ||
47 | - IOThread *iothread; | ||
48 | - | ||
49 | - iothread = (IOThread *)object_dynamic_cast(object, TYPE_IOTHREAD); | ||
50 | - if (!iothread || !iothread->ctx || iothread->stopping) { | ||
51 | - return 0; | ||
52 | + if (!iothread->ctx || iothread->stopping) { | ||
53 | + return; | ||
54 | } | ||
55 | iothread->stopping = true; | ||
56 | aio_notify(iothread->ctx); | ||
57 | @@ -XXX,XX +XXX,XX @@ static int iothread_stop(Object *object, void *opaque) | ||
58 | g_main_loop_quit(iothread->main_loop); | ||
59 | } | ||
60 | qemu_thread_join(&iothread->thread); | ||
61 | +} | ||
62 | + | ||
63 | +static int iothread_stop_iter(Object *object, void *opaque) | ||
64 | +{ | ||
65 | + IOThread *iothread; | ||
66 | + | ||
67 | + iothread = (IOThread *)object_dynamic_cast(object, TYPE_IOTHREAD); | ||
68 | + if (!iothread) { | ||
69 | + return 0; | ||
70 | + } | ||
71 | + iothread_stop(iothread); | ||
72 | return 0; | ||
73 | } | ||
74 | |||
75 | @@ -XXX,XX +XXX,XX @@ static void iothread_instance_finalize(Object *obj) | ||
76 | { | ||
77 | IOThread *iothread = IOTHREAD(obj); | ||
78 | |||
79 | - iothread_stop(obj, NULL); | ||
80 | + iothread_stop(iothread); | ||
81 | qemu_cond_destroy(&iothread->init_done_cond); | ||
82 | qemu_mutex_destroy(&iothread->init_done_lock); | ||
83 | if (!iothread->ctx) { | ||
84 | @@ -XXX,XX +XXX,XX @@ void iothread_stop_all(void) | ||
85 | aio_context_release(ctx); | ||
86 | } | ||
87 | |||
88 | - object_child_foreach(container, iothread_stop, NULL); | ||
89 | + object_child_foreach(container, iothread_stop_iter, NULL); | ||
90 | } | ||
91 | |||
92 | static gpointer iothread_g_main_context_init(gpointer opaque) | ||
93 | -- | 24 | -- |
94 | 2.13.6 | 25 | 2.31.1 |
95 | 26 | ||
96 | diff view generated by jsdifflib |