1 | The following changes since commit 8bac3ba57eecc466b7e73dabf7d19328a59f684e: | 1 | The following changes since commit ca61fa4b803e5d0abaf6f1ceb690f23bb78a4def: |
---|---|---|---|
2 | 2 | ||
3 | Merge remote-tracking branch 'remotes/rth/tags/pull-rx-20200408' into staging (2020-04-09 13:23:30 +0100) | 3 | Merge remote-tracking branch 'remotes/quic/tags/pull-hex-20211006' into staging (2021-10-06 12:11:14 -0700) |
4 | 4 | ||
5 | are available in the Git repository at: | 5 | are available in the Git repository at: |
6 | 6 | ||
7 | https://github.com/stefanha/qemu.git tags/block-pull-request | 7 | https://gitlab.com/stefanha/qemu.git tags/block-pull-request |
8 | 8 | ||
9 | for you to fetch changes up to 5710a3e09f9b85801e5ce70797a4a511e5fc9e2c: | 9 | for you to fetch changes up to 1cc7eada97914f090125e588497986f6f7900514: |
10 | 10 | ||
11 | async: use explicit memory barriers (2020-04-09 16:17:14 +0100) | 11 | iothread: use IOThreadParamInfo in iothread_[set|get]_param() (2021-10-07 15:29:50 +0100) |
12 | 12 | ||
13 | ---------------------------------------------------------------- | 13 | ---------------------------------------------------------------- |
14 | Pull request | 14 | Pull request |
15 | 15 | ||
16 | Fixes for QEMU on aarch64 ARM hosts and fdmon-io_uring. | ||
17 | |||
18 | ---------------------------------------------------------------- | 16 | ---------------------------------------------------------------- |
19 | 17 | ||
20 | Paolo Bonzini (2): | 18 | Stefano Garzarella (2): |
21 | aio-wait: delegate polling of main AioContext if BQL not held | 19 | iothread: rename PollParamInfo to IOThreadParamInfo |
22 | async: use explicit memory barriers | 20 | iothread: use IOThreadParamInfo in iothread_[set|get]_param() |
23 | 21 | ||
24 | Stefan Hajnoczi (1): | 22 | iothread.c | 28 +++++++++++++++------------- |
25 | aio-posix: signal-proof fdmon-io_uring | 23 | 1 file changed, 15 insertions(+), 13 deletions(-) |
26 | |||
27 | include/block/aio-wait.h | 22 ++++++++++++++++++++++ | ||
28 | include/block/aio.h | 29 ++++++++++------------------- | ||
29 | util/aio-posix.c | 16 ++++++++++++++-- | ||
30 | util/aio-win32.c | 17 ++++++++++++++--- | ||
31 | util/async.c | 16 ++++++++++++---- | ||
32 | util/fdmon-io_uring.c | 10 ++++++++-- | ||
33 | 6 files changed, 80 insertions(+), 30 deletions(-) | ||
34 | 24 | ||
35 | -- | 25 | -- |
36 | 2.25.1 | 26 | 2.31.1 |
37 | 27 | ||
28 | |||
29 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | The io_uring_enter(2) syscall returns with errno=EINTR when interrupted | ||
2 | by a signal. Retry the syscall in this case. | ||
3 | 1 | ||
4 | It's essential to do this in the io_uring_submit_and_wait() case. My | ||
5 | interpretation of the Linux v5.5 io_uring_enter(2) code is that it | ||
6 | shouldn't affect the io_uring_submit() case, but there is no guarantee | ||
7 | this will always be the case. Let's check for -EINTR around both APIs. | ||
8 | |||
9 | Note that the liburing APIs have -errno return values. | ||
10 | |||
11 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
12 | Reviewed-by: Stefano Garzarella <sgarzare@redhat.com> | ||
13 | Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com> | ||
14 | Message-id: 20200408091139.273851-1-stefanha@redhat.com | ||
15 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
16 | --- | ||
17 | util/fdmon-io_uring.c | 10 ++++++++-- | ||
18 | 1 file changed, 8 insertions(+), 2 deletions(-) | ||
19 | |||
20 | diff --git a/util/fdmon-io_uring.c b/util/fdmon-io_uring.c | ||
21 | index XXXXXXX..XXXXXXX 100644 | ||
22 | --- a/util/fdmon-io_uring.c | ||
23 | +++ b/util/fdmon-io_uring.c | ||
24 | @@ -XXX,XX +XXX,XX @@ static struct io_uring_sqe *get_sqe(AioContext *ctx) | ||
25 | } | ||
26 | |||
27 | /* No free sqes left, submit pending sqes first */ | ||
28 | - ret = io_uring_submit(ring); | ||
29 | + do { | ||
30 | + ret = io_uring_submit(ring); | ||
31 | + } while (ret == -EINTR); | ||
32 | + | ||
33 | assert(ret > 1); | ||
34 | sqe = io_uring_get_sqe(ring); | ||
35 | assert(sqe); | ||
36 | @@ -XXX,XX +XXX,XX @@ static int fdmon_io_uring_wait(AioContext *ctx, AioHandlerList *ready_list, | ||
37 | |||
38 | fill_sq_ring(ctx); | ||
39 | |||
40 | - ret = io_uring_submit_and_wait(&ctx->fdmon_io_uring, wait_nr); | ||
41 | + do { | ||
42 | + ret = io_uring_submit_and_wait(&ctx->fdmon_io_uring, wait_nr); | ||
43 | + } while (ret == -EINTR); | ||
44 | + | ||
45 | assert(ret >= 0); | ||
46 | |||
47 | return process_cq_ring(ctx, ready_list); | ||
48 | -- | ||
49 | 2.25.1 | ||
50 | diff view generated by jsdifflib |
1 | From: Paolo Bonzini <pbonzini@redhat.com> | 1 | From: Stefano Garzarella <sgarzare@redhat.com> |
---|---|---|---|
2 | 2 | ||
3 | Any thread that is not a iothread returns NULL for qemu_get_current_aio_context(). | 3 | Commit 1793ad0247 ("iothread: add aio-max-batch parameter") added |
4 | As a result, it would also return true for | 4 | a new parameter (aio-max-batch) to IOThread and used PollParamInfo |
5 | in_aio_context_home_thread(qemu_get_aio_context()), causing | 5 | structure to handle it. |
6 | AIO_WAIT_WHILE to invoke aio_poll() directly. This is incorrect | ||
7 | if the BQL is not held, because aio_poll() does not expect to | ||
8 | run concurrently from multiple threads, and it can actually | ||
9 | happen when savevm writes to the vmstate file from the | ||
10 | migration thread. | ||
11 | 6 | ||
12 | Therefore, restrict in_aio_context_home_thread to return true | 7 | Since it is not a parameter of the polling mechanism, we rename the |
13 | for the main AioContext only if the BQL is held. | 8 | structure to a more generic IOThreadParamInfo. |
14 | 9 | ||
15 | The function is moved to aio-wait.h because it is mostly used | 10 | Suggested-by: Kevin Wolf <kwolf@redhat.com> |
16 | there and to avoid a circular reference between main-loop.h | 11 | Signed-off-by: Stefano Garzarella <sgarzare@redhat.com> |
17 | and block/aio.h. | 12 | Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com> |
18 | 13 | Message-id: 20210727145936.147032-2-sgarzare@redhat.com | |
19 | Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> | ||
20 | Message-Id: <20200407140746.8041-5-pbonzini@redhat.com> | ||
21 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | 14 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> |
22 | --- | 15 | --- |
23 | include/block/aio-wait.h | 22 ++++++++++++++++++++++ | 16 | iothread.c | 14 +++++++------- |
24 | include/block/aio.h | 29 ++++++++++------------------- | 17 | 1 file changed, 7 insertions(+), 7 deletions(-) |
25 | 2 files changed, 32 insertions(+), 19 deletions(-) | ||
26 | 18 | ||
27 | diff --git a/include/block/aio-wait.h b/include/block/aio-wait.h | 19 | diff --git a/iothread.c b/iothread.c |
28 | index XXXXXXX..XXXXXXX 100644 | 20 | index XXXXXXX..XXXXXXX 100644 |
29 | --- a/include/block/aio-wait.h | 21 | --- a/iothread.c |
30 | +++ b/include/block/aio-wait.h | 22 | +++ b/iothread.c |
31 | @@ -XXX,XX +XXX,XX @@ | 23 | @@ -XXX,XX +XXX,XX @@ static void iothread_complete(UserCreatable *obj, Error **errp) |
32 | #define QEMU_AIO_WAIT_H | 24 | typedef struct { |
33 | 25 | const char *name; | |
34 | #include "block/aio.h" | 26 | ptrdiff_t offset; /* field's byte offset in IOThread struct */ |
35 | +#include "qemu/main-loop.h" | 27 | -} PollParamInfo; |
36 | 28 | +} IOThreadParamInfo; | |
37 | /** | 29 | |
38 | * AioWait: | 30 | -static PollParamInfo poll_max_ns_info = { |
39 | @@ -XXX,XX +XXX,XX @@ void aio_wait_kick(void); | 31 | +static IOThreadParamInfo poll_max_ns_info = { |
40 | */ | 32 | "poll-max-ns", offsetof(IOThread, poll_max_ns), |
41 | void aio_wait_bh_oneshot(AioContext *ctx, QEMUBHFunc *cb, void *opaque); | 33 | }; |
42 | 34 | -static PollParamInfo poll_grow_info = { | |
43 | +/** | 35 | +static IOThreadParamInfo poll_grow_info = { |
44 | + * in_aio_context_home_thread: | 36 | "poll-grow", offsetof(IOThread, poll_grow), |
45 | + * @ctx: the aio context | 37 | }; |
46 | + * | 38 | -static PollParamInfo poll_shrink_info = { |
47 | + * Return whether we are running in the thread that normally runs @ctx. Note | 39 | +static IOThreadParamInfo poll_shrink_info = { |
48 | + * that acquiring/releasing ctx does not affect the outcome, each AioContext | 40 | "poll-shrink", offsetof(IOThread, poll_shrink), |
49 | + * still only has one home thread that is responsible for running it. | 41 | }; |
50 | + */ | 42 | -static PollParamInfo aio_max_batch_info = { |
51 | +static inline bool in_aio_context_home_thread(AioContext *ctx) | 43 | +static IOThreadParamInfo aio_max_batch_info = { |
52 | +{ | 44 | "aio-max-batch", offsetof(IOThread, aio_max_batch), |
53 | + if (ctx == qemu_get_current_aio_context()) { | 45 | }; |
54 | + return true; | 46 | |
55 | + } | 47 | @@ -XXX,XX +XXX,XX @@ static void iothread_get_param(Object *obj, Visitor *v, |
56 | + | 48 | const char *name, void *opaque, Error **errp) |
57 | + if (ctx == qemu_get_aio_context()) { | 49 | { |
58 | + return qemu_mutex_iothread_locked(); | 50 | IOThread *iothread = IOTHREAD(obj); |
59 | + } else { | 51 | - PollParamInfo *info = opaque; |
60 | + return false; | 52 | + IOThreadParamInfo *info = opaque; |
61 | + } | 53 | int64_t *field = (void *)iothread + info->offset; |
62 | +} | 54 | |
63 | + | 55 | visit_type_int64(v, name, field, errp); |
64 | #endif /* QEMU_AIO_WAIT_H */ | 56 | @@ -XXX,XX +XXX,XX @@ static bool iothread_set_param(Object *obj, Visitor *v, |
65 | diff --git a/include/block/aio.h b/include/block/aio.h | 57 | const char *name, void *opaque, Error **errp) |
66 | index XXXXXXX..XXXXXXX 100644 | 58 | { |
67 | --- a/include/block/aio.h | 59 | IOThread *iothread = IOTHREAD(obj); |
68 | +++ b/include/block/aio.h | 60 | - PollParamInfo *info = opaque; |
69 | @@ -XXX,XX +XXX,XX @@ struct AioContext { | 61 | + IOThreadParamInfo *info = opaque; |
70 | AioHandlerList deleted_aio_handlers; | 62 | int64_t *field = (void *)iothread + info->offset; |
71 | 63 | int64_t value; | |
72 | /* Used to avoid unnecessary event_notifier_set calls in aio_notify; | 64 | |
73 | - * accessed with atomic primitives. If this field is 0, everything | ||
74 | - * (file descriptors, bottom halves, timers) will be re-evaluated | ||
75 | - * before the next blocking poll(), thus the event_notifier_set call | ||
76 | - * can be skipped. If it is non-zero, you may need to wake up a | ||
77 | - * concurrent aio_poll or the glib main event loop, making | ||
78 | - * event_notifier_set necessary. | ||
79 | + * only written from the AioContext home thread, or under the BQL in | ||
80 | + * the case of the main AioContext. However, it is read from any | ||
81 | + * thread so it is still accessed with atomic primitives. | ||
82 | + * | ||
83 | + * If this field is 0, everything (file descriptors, bottom halves, | ||
84 | + * timers) will be re-evaluated before the next blocking poll() or | ||
85 | + * io_uring wait; therefore, the event_notifier_set call can be | ||
86 | + * skipped. If it is non-zero, you may need to wake up a concurrent | ||
87 | + * aio_poll or the glib main event loop, making event_notifier_set | ||
88 | + * necessary. | ||
89 | * | ||
90 | * Bit 0 is reserved for GSource usage of the AioContext, and is 1 | ||
91 | * between a call to aio_ctx_prepare and the next call to aio_ctx_check. | ||
92 | @@ -XXX,XX +XXX,XX @@ void aio_co_enter(AioContext *ctx, struct Coroutine *co); | ||
93 | */ | ||
94 | AioContext *qemu_get_current_aio_context(void); | ||
95 | |||
96 | -/** | ||
97 | - * in_aio_context_home_thread: | ||
98 | - * @ctx: the aio context | ||
99 | - * | ||
100 | - * Return whether we are running in the thread that normally runs @ctx. Note | ||
101 | - * that acquiring/releasing ctx does not affect the outcome, each AioContext | ||
102 | - * still only has one home thread that is responsible for running it. | ||
103 | - */ | ||
104 | -static inline bool in_aio_context_home_thread(AioContext *ctx) | ||
105 | -{ | ||
106 | - return ctx == qemu_get_current_aio_context(); | ||
107 | -} | ||
108 | - | ||
109 | /** | ||
110 | * aio_context_setup: | ||
111 | * @ctx: the aio context | ||
112 | -- | 65 | -- |
113 | 2.25.1 | 66 | 2.31.1 |
114 | 67 | ||
68 | diff view generated by jsdifflib |
1 | From: Paolo Bonzini <pbonzini@redhat.com> | 1 | From: Stefano Garzarella <sgarzare@redhat.com> |
---|---|---|---|
2 | 2 | ||
3 | When using C11 atomics, non-seqcst reads and writes do not participate | 3 | Commit 0445409d74 ("iothread: generalize |
4 | in the total order of seqcst operations. In util/async.c and util/aio-posix.c, | 4 | iothread_set_param/iothread_get_param") moved common code to set and |
5 | in particular, the pattern that we use | 5 | get IOThread parameters in two new functions. |
6 | 6 | ||
7 | write ctx->notify_me write bh->scheduled | 7 | These functions are called inside callbacks, so we don't need to use an |
8 | read bh->scheduled read ctx->notify_me | 8 | opaque pointer. Let's replace `void *opaque` parameter with |
9 | if !bh->scheduled, sleep if ctx->notify_me, notify | 9 | `IOThreadParamInfo *info`. |
10 | 10 | ||
11 | needs to use seqcst operations for both the write and the read. In | 11 | Suggested-by: Kevin Wolf <kwolf@redhat.com> |
12 | general this is something that we do not want, because there can be | 12 | Signed-off-by: Stefano Garzarella <sgarzare@redhat.com> |
13 | many sources that are polled in addition to bottom halves. The | 13 | Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com> |
14 | alternative is to place a seqcst memory barrier between the write | 14 | Message-id: 20210727145936.147032-3-sgarzare@redhat.com |
15 | and the read. This also comes with a disadvantage, in that the | ||
16 | memory barrier is implicit on strongly-ordered architectures and | ||
17 | it wastes a few dozen clock cycles. | ||
18 | |||
19 | Fortunately, ctx->notify_me is never written concurrently by two | ||
20 | threads, so we can assert that and relax the writes to ctx->notify_me. | ||
21 | The resulting solution works and performs well on both aarch64 and x86. | ||
22 | |||
23 | Note that the atomic_set/atomic_read combination is not an atomic | ||
24 | read-modify-write, and therefore it is even weaker than C11 ATOMIC_RELAXED; | ||
25 | on x86, ATOMIC_RELAXED compiles to a locked operation. | ||
26 | |||
27 | Analyzed-by: Ying Fang <fangying1@huawei.com> | ||
28 | Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> | ||
29 | Tested-by: Ying Fang <fangying1@huawei.com> | ||
30 | Message-Id: <20200407140746.8041-6-pbonzini@redhat.com> | ||
31 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | 15 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> |
32 | --- | 16 | --- |
33 | util/aio-posix.c | 16 ++++++++++++++-- | 17 | iothread.c | 18 ++++++++++-------- |
34 | util/aio-win32.c | 17 ++++++++++++++--- | 18 | 1 file changed, 10 insertions(+), 8 deletions(-) |
35 | util/async.c | 16 ++++++++++++---- | ||
36 | 3 files changed, 40 insertions(+), 9 deletions(-) | ||
37 | 19 | ||
38 | diff --git a/util/aio-posix.c b/util/aio-posix.c | 20 | diff --git a/iothread.c b/iothread.c |
39 | index XXXXXXX..XXXXXXX 100644 | 21 | index XXXXXXX..XXXXXXX 100644 |
40 | --- a/util/aio-posix.c | 22 | --- a/iothread.c |
41 | +++ b/util/aio-posix.c | 23 | +++ b/iothread.c |
42 | @@ -XXX,XX +XXX,XX @@ bool aio_poll(AioContext *ctx, bool blocking) | 24 | @@ -XXX,XX +XXX,XX @@ static IOThreadParamInfo aio_max_batch_info = { |
43 | int64_t timeout; | 25 | }; |
44 | int64_t start = 0; | 26 | |
45 | 27 | static void iothread_get_param(Object *obj, Visitor *v, | |
46 | + /* | 28 | - const char *name, void *opaque, Error **errp) |
47 | + * There cannot be two concurrent aio_poll calls for the same AioContext (or | 29 | + const char *name, IOThreadParamInfo *info, Error **errp) |
48 | + * an aio_poll concurrent with a GSource prepare/check/dispatch callback). | 30 | { |
49 | + * We rely on this below to avoid slow locked accesses to ctx->notify_me. | 31 | IOThread *iothread = IOTHREAD(obj); |
50 | + */ | 32 | - IOThreadParamInfo *info = opaque; |
51 | assert(in_aio_context_home_thread(ctx)); | 33 | int64_t *field = (void *)iothread + info->offset; |
52 | 34 | ||
53 | /* aio_notify can avoid the expensive event_notifier_set if | 35 | visit_type_int64(v, name, field, errp); |
54 | @@ -XXX,XX +XXX,XX @@ bool aio_poll(AioContext *ctx, bool blocking) | 36 | } |
55 | * so disable the optimization now. | 37 | |
56 | */ | 38 | static bool iothread_set_param(Object *obj, Visitor *v, |
57 | if (blocking) { | 39 | - const char *name, void *opaque, Error **errp) |
58 | - atomic_add(&ctx->notify_me, 2); | 40 | + const char *name, IOThreadParamInfo *info, Error **errp) |
59 | + atomic_set(&ctx->notify_me, atomic_read(&ctx->notify_me) + 2); | 41 | { |
60 | + /* | 42 | IOThread *iothread = IOTHREAD(obj); |
61 | + * Write ctx->notify_me before computing the timeout | 43 | - IOThreadParamInfo *info = opaque; |
62 | + * (reading bottom half flags, etc.). Pairs with | 44 | int64_t *field = (void *)iothread + info->offset; |
63 | + * smp_mb in aio_notify(). | 45 | int64_t value; |
64 | + */ | 46 | |
65 | + smp_mb(); | 47 | @@ -XXX,XX +XXX,XX @@ static bool iothread_set_param(Object *obj, Visitor *v, |
48 | static void iothread_get_poll_param(Object *obj, Visitor *v, | ||
49 | const char *name, void *opaque, Error **errp) | ||
50 | { | ||
51 | + IOThreadParamInfo *info = opaque; | ||
52 | |||
53 | - iothread_get_param(obj, v, name, opaque, errp); | ||
54 | + iothread_get_param(obj, v, name, info, errp); | ||
55 | } | ||
56 | |||
57 | static void iothread_set_poll_param(Object *obj, Visitor *v, | ||
58 | const char *name, void *opaque, Error **errp) | ||
59 | { | ||
60 | IOThread *iothread = IOTHREAD(obj); | ||
61 | + IOThreadParamInfo *info = opaque; | ||
62 | |||
63 | - if (!iothread_set_param(obj, v, name, opaque, errp)) { | ||
64 | + if (!iothread_set_param(obj, v, name, info, errp)) { | ||
65 | return; | ||
66 | } | 66 | } |
67 | 67 | ||
68 | qemu_lockcnt_inc(&ctx->list_lock); | 68 | @@ -XXX,XX +XXX,XX @@ static void iothread_set_poll_param(Object *obj, Visitor *v, |
69 | @@ -XXX,XX +XXX,XX @@ bool aio_poll(AioContext *ctx, bool blocking) | 69 | static void iothread_get_aio_param(Object *obj, Visitor *v, |
70 | const char *name, void *opaque, Error **errp) | ||
71 | { | ||
72 | + IOThreadParamInfo *info = opaque; | ||
73 | |||
74 | - iothread_get_param(obj, v, name, opaque, errp); | ||
75 | + iothread_get_param(obj, v, name, info, errp); | ||
76 | } | ||
77 | |||
78 | static void iothread_set_aio_param(Object *obj, Visitor *v, | ||
79 | const char *name, void *opaque, Error **errp) | ||
80 | { | ||
81 | IOThread *iothread = IOTHREAD(obj); | ||
82 | + IOThreadParamInfo *info = opaque; | ||
83 | |||
84 | - if (!iothread_set_param(obj, v, name, opaque, errp)) { | ||
85 | + if (!iothread_set_param(obj, v, name, info, errp)) { | ||
86 | return; | ||
70 | } | 87 | } |
71 | 88 | ||
72 | if (blocking) { | ||
73 | - atomic_sub(&ctx->notify_me, 2); | ||
74 | + /* Finish the poll before clearing the flag. */ | ||
75 | + atomic_store_release(&ctx->notify_me, atomic_read(&ctx->notify_me) - 2); | ||
76 | aio_notify_accept(ctx); | ||
77 | } | ||
78 | |||
79 | diff --git a/util/aio-win32.c b/util/aio-win32.c | ||
80 | index XXXXXXX..XXXXXXX 100644 | ||
81 | --- a/util/aio-win32.c | ||
82 | +++ b/util/aio-win32.c | ||
83 | @@ -XXX,XX +XXX,XX @@ bool aio_poll(AioContext *ctx, bool blocking) | ||
84 | int count; | ||
85 | int timeout; | ||
86 | |||
87 | + /* | ||
88 | + * There cannot be two concurrent aio_poll calls for the same AioContext (or | ||
89 | + * an aio_poll concurrent with a GSource prepare/check/dispatch callback). | ||
90 | + * We rely on this below to avoid slow locked accesses to ctx->notify_me. | ||
91 | + */ | ||
92 | + assert(in_aio_context_home_thread(ctx)); | ||
93 | progress = false; | ||
94 | |||
95 | /* aio_notify can avoid the expensive event_notifier_set if | ||
96 | @@ -XXX,XX +XXX,XX @@ bool aio_poll(AioContext *ctx, bool blocking) | ||
97 | * so disable the optimization now. | ||
98 | */ | ||
99 | if (blocking) { | ||
100 | - atomic_add(&ctx->notify_me, 2); | ||
101 | + atomic_set(&ctx->notify_me, atomic_read(&ctx->notify_me) + 2); | ||
102 | + /* | ||
103 | + * Write ctx->notify_me before computing the timeout | ||
104 | + * (reading bottom half flags, etc.). Pairs with | ||
105 | + * smp_mb in aio_notify(). | ||
106 | + */ | ||
107 | + smp_mb(); | ||
108 | } | ||
109 | |||
110 | qemu_lockcnt_inc(&ctx->list_lock); | ||
111 | @@ -XXX,XX +XXX,XX @@ bool aio_poll(AioContext *ctx, bool blocking) | ||
112 | ret = WaitForMultipleObjects(count, events, FALSE, timeout); | ||
113 | if (blocking) { | ||
114 | assert(first); | ||
115 | - assert(in_aio_context_home_thread(ctx)); | ||
116 | - atomic_sub(&ctx->notify_me, 2); | ||
117 | + atomic_store_release(&ctx->notify_me, atomic_read(&ctx->notify_me) - 2); | ||
118 | aio_notify_accept(ctx); | ||
119 | } | ||
120 | |||
121 | diff --git a/util/async.c b/util/async.c | ||
122 | index XXXXXXX..XXXXXXX 100644 | ||
123 | --- a/util/async.c | ||
124 | +++ b/util/async.c | ||
125 | @@ -XXX,XX +XXX,XX @@ aio_ctx_prepare(GSource *source, gint *timeout) | ||
126 | { | ||
127 | AioContext *ctx = (AioContext *) source; | ||
128 | |||
129 | - atomic_or(&ctx->notify_me, 1); | ||
130 | + atomic_set(&ctx->notify_me, atomic_read(&ctx->notify_me) | 1); | ||
131 | + | ||
132 | + /* | ||
133 | + * Write ctx->notify_me before computing the timeout | ||
134 | + * (reading bottom half flags, etc.). Pairs with | ||
135 | + * smp_mb in aio_notify(). | ||
136 | + */ | ||
137 | + smp_mb(); | ||
138 | |||
139 | /* We assume there is no timeout already supplied */ | ||
140 | *timeout = qemu_timeout_ns_to_ms(aio_compute_timeout(ctx)); | ||
141 | @@ -XXX,XX +XXX,XX @@ aio_ctx_check(GSource *source) | ||
142 | QEMUBH *bh; | ||
143 | BHListSlice *s; | ||
144 | |||
145 | - atomic_and(&ctx->notify_me, ~1); | ||
146 | + /* Finish computing the timeout before clearing the flag. */ | ||
147 | + atomic_store_release(&ctx->notify_me, atomic_read(&ctx->notify_me) & ~1); | ||
148 | aio_notify_accept(ctx); | ||
149 | |||
150 | QSLIST_FOREACH_RCU(bh, &ctx->bh_list, next) { | ||
151 | @@ -XXX,XX +XXX,XX @@ LuringState *aio_get_linux_io_uring(AioContext *ctx) | ||
152 | void aio_notify(AioContext *ctx) | ||
153 | { | ||
154 | /* Write e.g. bh->scheduled before reading ctx->notify_me. Pairs | ||
155 | - * with atomic_or in aio_ctx_prepare or atomic_add in aio_poll. | ||
156 | + * with smp_mb in aio_ctx_prepare or aio_poll. | ||
157 | */ | ||
158 | smp_mb(); | ||
159 | - if (ctx->notify_me) { | ||
160 | + if (atomic_read(&ctx->notify_me)) { | ||
161 | event_notifier_set(&ctx->notifier); | ||
162 | atomic_mb_set(&ctx->notified, true); | ||
163 | } | ||
164 | -- | 89 | -- |
165 | 2.25.1 | 90 | 2.31.1 |
166 | 91 | ||
92 | diff view generated by jsdifflib |