1 | The following changes since commit f58d9620aa4a514b1227074ff56eefd1334a6225: | 1 | The following changes since commit 15ef89d2a1a7b93845a6b09c2ee8e1979f6eb30b: |
---|---|---|---|
2 | 2 | ||
3 | Merge remote-tracking branch 'remotes/rth/tags/pull-dt-20180326' into staging (2018-03-27 10:27:34 +0100) | 3 | Update version for v7.0.0-rc1 release (2022-03-22 22:58:44 +0000) |
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 f5a53faad4bfbf1b86012a13055d2a1a774a42b6: | 9 | for you to fetch changes up to 2539eade4f689eda7e9fe45486f18334bfbafaf0: |
10 | 10 | ||
11 | MAINTAINERS: add include/block/aio-wait.h (2018-03-27 13:05:48 +0100) | 11 | hw: Fix misleading hexadecimal format (2022-03-24 10:38:42 +0000) |
12 | |||
13 | ---------------------------------------------------------------- | ||
14 | Pull request | ||
15 | |||
16 | Philippe found cases where the 0x%d format string was used, leading to | ||
17 | misleading output. The patches look harmless and could save people time, so I | ||
18 | think it's worth including them in 7.0. | ||
12 | 19 | ||
13 | ---------------------------------------------------------------- | 20 | ---------------------------------------------------------------- |
14 | 21 | ||
15 | ---------------------------------------------------------------- | 22 | Philippe Mathieu-Daudé (2): |
23 | block: Fix misleading hexadecimal format | ||
24 | hw: Fix misleading hexadecimal format | ||
16 | 25 | ||
17 | Stefan Hajnoczi (4): | 26 | block/parallels-ext.c | 2 +- |
18 | queue: add QSIMPLEQ_PREPEND() | 27 | hw/i386/sgx.c | 2 +- |
19 | coroutine: avoid co_queue_wakeup recursion | 28 | hw/i386/trace-events | 6 +++--- |
20 | coroutine: add test-aio coroutine queue chaining test case | 29 | hw/misc/trace-events | 4 ++-- |
21 | MAINTAINERS: add include/block/aio-wait.h | 30 | hw/scsi/trace-events | 4 ++-- |
22 | 31 | 5 files changed, 9 insertions(+), 9 deletions(-) | |
23 | MAINTAINERS | 1 + | ||
24 | include/qemu/coroutine_int.h | 1 - | ||
25 | include/qemu/queue.h | 8 ++++ | ||
26 | block/io.c | 3 +- | ||
27 | tests/test-aio.c | 65 ++++++++++++++++++++----- | ||
28 | util/qemu-coroutine-lock.c | 34 ------------- | ||
29 | util/qemu-coroutine.c | 110 +++++++++++++++++++++++-------------------- | ||
30 | 7 files changed, 121 insertions(+), 101 deletions(-) | ||
31 | 32 | ||
32 | -- | 33 | -- |
33 | 2.14.3 | 34 | 2.35.1 |
34 | 35 | ||
35 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | QSIMPLEQ_CONCAT(a, b) joins a = a + b. The new QSIMPLEQ_PREPEND(a, b) | ||
2 | API joins a = b + a. | ||
3 | 1 | ||
4 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
5 | Reviewed-by: Paolo Bonzini <pbonzini@redhat.com> | ||
6 | Message-id: 20180322152834.12656-2-stefanha@redhat.com | ||
7 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
8 | --- | ||
9 | include/qemu/queue.h | 8 ++++++++ | ||
10 | 1 file changed, 8 insertions(+) | ||
11 | |||
12 | diff --git a/include/qemu/queue.h b/include/qemu/queue.h | ||
13 | index XXXXXXX..XXXXXXX 100644 | ||
14 | --- a/include/qemu/queue.h | ||
15 | +++ b/include/qemu/queue.h | ||
16 | @@ -XXX,XX +XXX,XX @@ struct { \ | ||
17 | } \ | ||
18 | } while (/*CONSTCOND*/0) | ||
19 | |||
20 | +#define QSIMPLEQ_PREPEND(head1, head2) do { \ | ||
21 | + if (!QSIMPLEQ_EMPTY((head2))) { \ | ||
22 | + *(head2)->sqh_last = (head1)->sqh_first; \ | ||
23 | + (head1)->sqh_first = (head2)->sqh_first; \ | ||
24 | + QSIMPLEQ_INIT((head2)); \ | ||
25 | + } \ | ||
26 | +} while (/*CONSTCOND*/0) | ||
27 | + | ||
28 | #define QSIMPLEQ_LAST(head, type, field) \ | ||
29 | (QSIMPLEQ_EMPTY((head)) ? \ | ||
30 | NULL : \ | ||
31 | -- | ||
32 | 2.14.3 | ||
33 | |||
34 | diff view generated by jsdifflib |
1 | The include/block/aio-wait.h header file was added by commit | 1 | From: Philippe Mathieu-Daudé <f4bug@amsat.org> |
---|---|---|---|
2 | 7719f3c968c59e1bcda7e177679dc765b59e578f ("block: extract | ||
3 | AIO_WAIT_WHILE() from BlockDriverState") without updating MAINTAINERS. | ||
4 | 2 | ||
5 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | 3 | "0x%u" format is very misleading, replace by "0x%x". |
6 | Reviewed-by: Eric Blake <eblake@redhat.com> | 4 | |
7 | Message-id: 20180312132204.23683-1-stefanha@redhat.com | 5 | Found running: |
6 | |||
7 | $ git grep -E '0x%[0-9]*([lL]*|" ?PRI)[dDuU]' block/ | ||
8 | |||
9 | Inspired-by: Richard Henderson <richard.henderson@linaro.org> | ||
10 | Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
11 | Reviewed-by: Hanna Reitz <hreitz@redhat.com> | ||
12 | Reviewed-by: Daniel P. Berrangé <berrange@redhat.com> | ||
13 | Reviewed-by: Denis V. Lunev <den@openvz.org> | ||
14 | Message-id: 20220323114718.58714-2-philippe.mathieu.daude@gmail.com | ||
8 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | 15 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> |
9 | --- | 16 | --- |
10 | MAINTAINERS | 1 + | 17 | block/parallels-ext.c | 2 +- |
11 | 1 file changed, 1 insertion(+) | 18 | 1 file changed, 1 insertion(+), 1 deletion(-) |
12 | 19 | ||
13 | diff --git a/MAINTAINERS b/MAINTAINERS | 20 | diff --git a/block/parallels-ext.c b/block/parallels-ext.c |
14 | index XXXXXXX..XXXXXXX 100644 | 21 | index XXXXXXX..XXXXXXX 100644 |
15 | --- a/MAINTAINERS | 22 | --- a/block/parallels-ext.c |
16 | +++ b/MAINTAINERS | 23 | +++ b/block/parallels-ext.c |
17 | @@ -XXX,XX +XXX,XX @@ F: util/aio-*.c | 24 | @@ -XXX,XX +XXX,XX @@ static int parallels_parse_format_extension(BlockDriverState *bs, |
18 | F: block/io.c | 25 | break; |
19 | F: migration/block* | 26 | |
20 | F: include/block/aio.h | 27 | default: |
21 | +F: include/block/aio-wait.h | 28 | - error_setg(errp, "Unknown feature: 0x%" PRIu64, fh.magic); |
22 | F: scripts/qemugdb/aio.py | 29 | + error_setg(errp, "Unknown feature: 0x%" PRIx64, fh.magic); |
23 | T: git git://github.com/stefanha/qemu.git block | 30 | goto fail; |
31 | } | ||
24 | 32 | ||
25 | -- | 33 | -- |
26 | 2.14.3 | 34 | 2.35.1 |
27 | 35 | ||
28 | 36 | diff view generated by jsdifflib |
1 | qemu_aio_coroutine_enter() is (indirectly) called recursively when | 1 | From: Philippe Mathieu-Daudé <f4bug@amsat.org> |
---|---|---|---|
2 | processing co_queue_wakeup. This can lead to stack exhaustion. | ||
3 | 2 | ||
4 | This patch rewrites co_queue_wakeup in an iterative fashion (instead of | 3 | "0x%u" format is very misleading, replace by "0x%x". |
5 | recursive) with bounded memory usage to prevent stack exhaustion. | ||
6 | 4 | ||
7 | qemu_co_queue_run_restart() is inlined into qemu_aio_coroutine_enter() | 5 | Found running: |
8 | and the qemu_coroutine_enter() call is turned into a loop to avoid | ||
9 | recursion. | ||
10 | 6 | ||
11 | There is one change that is worth mentioning: Previously, when | 7 | $ git grep -E '0x%[0-9]*([lL]*|" ?PRI)[dDuU]' hw/ |
12 | coroutine A queued coroutine B, qemu_co_queue_run_restart() entered | ||
13 | coroutine B from coroutine A. If A was terminating then it would still | ||
14 | stay alive until B yielded. After this patch B is entered by A's parent | ||
15 | so that a A can be deleted immediately if it is terminating. | ||
16 | 8 | ||
17 | It is safe to make this change since B could never interact with A if it | 9 | Inspired-by: Richard Henderson <richard.henderson@linaro.org> |
18 | was terminating anyway. | 10 | Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org> |
19 | 11 | Reviewed-by: Daniel P. Berrangé <berrange@redhat.com> | |
20 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | 12 | Message-id: 20220323114718.58714-3-philippe.mathieu.daude@gmail.com |
21 | Reviewed-by: Paolo Bonzini <pbonzini@redhat.com> | ||
22 | Message-id: 20180322152834.12656-3-stefanha@redhat.com | ||
23 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | 13 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> |
24 | --- | 14 | --- |
25 | include/qemu/coroutine_int.h | 1 - | 15 | hw/i386/sgx.c | 2 +- |
26 | block/io.c | 3 +- | 16 | hw/i386/trace-events | 6 +++--- |
27 | util/qemu-coroutine-lock.c | 34 ------------- | 17 | hw/misc/trace-events | 4 ++-- |
28 | util/qemu-coroutine.c | 110 +++++++++++++++++++++++-------------------- | 18 | hw/scsi/trace-events | 4 ++-- |
29 | 4 files changed, 60 insertions(+), 88 deletions(-) | 19 | 4 files changed, 8 insertions(+), 8 deletions(-) |
30 | 20 | ||
31 | diff --git a/include/qemu/coroutine_int.h b/include/qemu/coroutine_int.h | 21 | diff --git a/hw/i386/sgx.c b/hw/i386/sgx.c |
32 | index XXXXXXX..XXXXXXX 100644 | 22 | index XXXXXXX..XXXXXXX 100644 |
33 | --- a/include/qemu/coroutine_int.h | 23 | --- a/hw/i386/sgx.c |
34 | +++ b/include/qemu/coroutine_int.h | 24 | +++ b/hw/i386/sgx.c |
35 | @@ -XXX,XX +XXX,XX @@ Coroutine *qemu_coroutine_new(void); | 25 | @@ -XXX,XX +XXX,XX @@ void pc_machine_init_sgx_epc(PCMachineState *pcms) |
36 | void qemu_coroutine_delete(Coroutine *co); | 26 | } |
37 | CoroutineAction qemu_coroutine_switch(Coroutine *from, Coroutine *to, | 27 | |
38 | CoroutineAction action); | 28 | if ((sgx_epc->base + sgx_epc->size) < sgx_epc->base) { |
39 | -void coroutine_fn qemu_co_queue_run_restart(Coroutine *co); | 29 | - error_report("Size of all 'sgx-epc' =0x%"PRIu64" causes EPC to wrap", |
40 | 30 | + error_report("Size of all 'sgx-epc' =0x%"PRIx64" causes EPC to wrap", | |
41 | #endif | 31 | sgx_epc->size); |
42 | diff --git a/block/io.c b/block/io.c | 32 | exit(EXIT_FAILURE); |
33 | } | ||
34 | diff --git a/hw/i386/trace-events b/hw/i386/trace-events | ||
43 | index XXXXXXX..XXXXXXX 100644 | 35 | index XXXXXXX..XXXXXXX 100644 |
44 | --- a/block/io.c | 36 | --- a/hw/i386/trace-events |
45 | +++ b/block/io.c | 37 | +++ b/hw/i386/trace-events |
46 | @@ -XXX,XX +XXX,XX @@ static void coroutine_fn bdrv_co_yield_to_drain(BlockDriverState *bs, | 38 | @@ -XXX,XX +XXX,XX @@ vtd_fault_disabled(void) "Fault processing disabled for context entry" |
47 | BdrvCoDrainData data; | 39 | vtd_replay_ce_valid(const char *mode, uint8_t bus, uint8_t dev, uint8_t fn, uint16_t domain, uint64_t hi, uint64_t lo) "%s: replay valid context device %02"PRIx8":%02"PRIx8".%02"PRIx8" domain 0x%"PRIx16" hi 0x%"PRIx64" lo 0x%"PRIx64 |
48 | 40 | vtd_replay_ce_invalid(uint8_t bus, uint8_t dev, uint8_t fn) "replay invalid context device %02"PRIx8":%02"PRIx8".%02"PRIx8 | |
49 | /* Calling bdrv_drain() from a BH ensures the current coroutine yields and | 41 | vtd_page_walk_level(uint64_t addr, uint32_t level, uint64_t start, uint64_t end) "walk (base=0x%"PRIx64", level=%"PRIu32") iova range 0x%"PRIx64" - 0x%"PRIx64 |
50 | - * other coroutines run if they were queued from | 42 | -vtd_page_walk_one(uint16_t domain, uint64_t iova, uint64_t gpa, uint64_t mask, int perm) "domain 0x%"PRIu16" iova 0x%"PRIx64" -> gpa 0x%"PRIx64" mask 0x%"PRIx64" perm %d" |
51 | - * qemu_co_queue_run_restart(). */ | 43 | +vtd_page_walk_one(uint16_t domain, uint64_t iova, uint64_t gpa, uint64_t mask, int perm) "domain 0x%"PRIx16" iova 0x%"PRIx64" -> gpa 0x%"PRIx64" mask 0x%"PRIx64" perm %d" |
52 | + * other coroutines run if they were queued by aio_co_enter(). */ | 44 | vtd_page_walk_one_skip_map(uint64_t iova, uint64_t mask, uint64_t translated) "iova 0x%"PRIx64" mask 0x%"PRIx64" translated 0x%"PRIx64 |
53 | 45 | vtd_page_walk_one_skip_unmap(uint64_t iova, uint64_t mask) "iova 0x%"PRIx64" mask 0x%"PRIx64 | |
54 | assert(qemu_in_coroutine()); | 46 | vtd_page_walk_skip_read(uint64_t iova, uint64_t next) "Page walk skip iova 0x%"PRIx64" - 0x%"PRIx64" due to unable to read" |
55 | data = (BdrvCoDrainData) { | 47 | vtd_page_walk_skip_reserve(uint64_t iova, uint64_t next) "Page walk skip iova 0x%"PRIx64" - 0x%"PRIx64" due to rsrv set" |
56 | diff --git a/util/qemu-coroutine-lock.c b/util/qemu-coroutine-lock.c | 48 | vtd_switch_address_space(uint8_t bus, uint8_t slot, uint8_t fn, bool on) "Device %02x:%02x.%x switching address space (iommu enabled=%d)" |
49 | vtd_as_unmap_whole(uint8_t bus, uint8_t slot, uint8_t fn, uint64_t iova, uint64_t size) "Device %02x:%02x.%x start 0x%"PRIx64" size 0x%"PRIx64 | ||
50 | -vtd_translate_pt(uint16_t sid, uint64_t addr) "source id 0x%"PRIu16", iova 0x%"PRIx64 | ||
51 | -vtd_pt_enable_fast_path(uint16_t sid, bool success) "sid 0x%"PRIu16" %d" | ||
52 | +vtd_translate_pt(uint16_t sid, uint64_t addr) "source id 0x%"PRIx16", iova 0x%"PRIx64 | ||
53 | +vtd_pt_enable_fast_path(uint16_t sid, bool success) "sid 0x%"PRIx16" %d" | ||
54 | vtd_irq_generate(uint64_t addr, uint64_t data) "addr 0x%"PRIx64" data 0x%"PRIx64 | ||
55 | vtd_reg_read(uint64_t addr, uint64_t size) "addr 0x%"PRIx64" size 0x%"PRIx64 | ||
56 | vtd_reg_write(uint64_t addr, uint64_t size, uint64_t val) "addr 0x%"PRIx64" size 0x%"PRIx64" value 0x%"PRIx64 | ||
57 | diff --git a/hw/misc/trace-events b/hw/misc/trace-events | ||
57 | index XXXXXXX..XXXXXXX 100644 | 58 | index XXXXXXX..XXXXXXX 100644 |
58 | --- a/util/qemu-coroutine-lock.c | 59 | --- a/hw/misc/trace-events |
59 | +++ b/util/qemu-coroutine-lock.c | 60 | +++ b/hw/misc/trace-events |
60 | @@ -XXX,XX +XXX,XX @@ void coroutine_fn qemu_co_queue_wait_impl(CoQueue *queue, QemuLockable *lock) | 61 | @@ -XXX,XX +XXX,XX @@ |
61 | } | 62 | # See docs/devel/tracing.rst for syntax documentation. |
62 | } | 63 | |
63 | 64 | # allwinner-cpucfg.c | |
64 | -/** | 65 | -allwinner_cpucfg_cpu_reset(uint8_t cpu_id, uint32_t reset_addr) "id %u, reset_addr 0x%" PRIu32 |
65 | - * qemu_co_queue_run_restart: | 66 | +allwinner_cpucfg_cpu_reset(uint8_t cpu_id, uint32_t reset_addr) "id %u, reset_addr 0x%" PRIx32 |
66 | - * | 67 | allwinner_cpucfg_read(uint64_t offset, uint64_t data, unsigned size) "offset 0x%" PRIx64 " data 0x%" PRIx64 " size %" PRIu32 |
67 | - * Enter each coroutine that was previously marked for restart by | 68 | allwinner_cpucfg_write(uint64_t offset, uint64_t data, unsigned size) "offset 0x%" PRIx64 " data 0x%" PRIx64 " size %" PRIu32 |
68 | - * qemu_co_queue_next() or qemu_co_queue_restart_all(). This function is | 69 | |
69 | - * invoked by the core coroutine code when the current coroutine yields or | 70 | @@ -XXX,XX +XXX,XX @@ imx7_gpr_write(uint64_t offset, uint64_t value) "addr 0x%08" PRIx64 "value 0x%08 |
70 | - * terminates. | 71 | |
71 | - */ | 72 | # mos6522.c |
72 | -void qemu_co_queue_run_restart(Coroutine *co) | 73 | mos6522_set_counter(int index, unsigned int val) "T%d.counter=%d" |
73 | -{ | 74 | -mos6522_get_next_irq_time(uint16_t latch, int64_t d, int64_t delta) "latch=%d counter=0x%"PRId64 " delta_next=0x%"PRId64 |
74 | - Coroutine *next; | 75 | +mos6522_get_next_irq_time(uint16_t latch, int64_t d, int64_t delta) "latch=%d counter=0x%"PRIx64 " delta_next=0x%"PRIx64 |
75 | - QSIMPLEQ_HEAD(, Coroutine) tmp_queue_wakeup = | 76 | mos6522_set_sr_int(void) "set sr_int" |
76 | - QSIMPLEQ_HEAD_INITIALIZER(tmp_queue_wakeup); | 77 | mos6522_write(uint64_t addr, const char *name, uint64_t val) "reg=0x%"PRIx64 " [%s] val=0x%"PRIx64 |
77 | - | 78 | mos6522_read(uint64_t addr, const char *name, unsigned val) "reg=0x%"PRIx64 " [%s] val=0x%x" |
78 | - trace_qemu_co_queue_run_restart(co); | 79 | diff --git a/hw/scsi/trace-events b/hw/scsi/trace-events |
79 | - | ||
80 | - /* Because "co" has yielded, any coroutine that we wakeup can resume it. | ||
81 | - * If this happens and "co" terminates, co->co_queue_wakeup becomes | ||
82 | - * invalid memory. Therefore, use a temporary queue and do not touch | ||
83 | - * the "co" coroutine as soon as you enter another one. | ||
84 | - * | ||
85 | - * In its turn resumed "co" can populate "co_queue_wakeup" queue with | ||
86 | - * new coroutines to be woken up. The caller, who has resumed "co", | ||
87 | - * will be responsible for traversing the same queue, which may cause | ||
88 | - * a different wakeup order but not any missing wakeups. | ||
89 | - */ | ||
90 | - QSIMPLEQ_CONCAT(&tmp_queue_wakeup, &co->co_queue_wakeup); | ||
91 | - | ||
92 | - while ((next = QSIMPLEQ_FIRST(&tmp_queue_wakeup))) { | ||
93 | - QSIMPLEQ_REMOVE_HEAD(&tmp_queue_wakeup, co_queue_next); | ||
94 | - qemu_coroutine_enter(next); | ||
95 | - } | ||
96 | -} | ||
97 | - | ||
98 | static bool qemu_co_queue_do_restart(CoQueue *queue, bool single) | ||
99 | { | ||
100 | Coroutine *next; | ||
101 | diff --git a/util/qemu-coroutine.c b/util/qemu-coroutine.c | ||
102 | index XXXXXXX..XXXXXXX 100644 | 80 | index XXXXXXX..XXXXXXX 100644 |
103 | --- a/util/qemu-coroutine.c | 81 | --- a/hw/scsi/trace-events |
104 | +++ b/util/qemu-coroutine.c | 82 | +++ b/hw/scsi/trace-events |
105 | @@ -XXX,XX +XXX,XX @@ static void coroutine_delete(Coroutine *co) | 83 | @@ -XXX,XX +XXX,XX @@ lsi_bad_phase_interrupt(void) "Phase mismatch interrupt" |
106 | 84 | lsi_bad_selection(uint32_t id) "Selected absent target %"PRIu32 | |
107 | void qemu_aio_coroutine_enter(AioContext *ctx, Coroutine *co) | 85 | lsi_do_dma_unavailable(void) "DMA no data available" |
108 | { | 86 | lsi_do_dma(uint64_t addr, int len) "DMA addr=0x%"PRIx64" len=%d" |
109 | - Coroutine *self = qemu_coroutine_self(); | 87 | -lsi_queue_command(uint32_t tag) "Queueing tag=0x%"PRId32 |
110 | - CoroutineAction ret; | 88 | +lsi_queue_command(uint32_t tag) "Queueing tag=0x%"PRIx32 |
111 | - | 89 | lsi_add_msg_byte_error(void) "MSG IN data too long" |
112 | - /* Cannot rely on the read barrier for co in aio_co_wake(), as there are | 90 | lsi_add_msg_byte(uint8_t data) "MSG IN 0x%02x" |
113 | - * callers outside of aio_co_wake() */ | 91 | lsi_reselect(int id) "Reselected target %d" |
114 | - const char *scheduled = atomic_mb_read(&co->scheduled); | 92 | @@ -XXX,XX +XXX,XX @@ lsi_do_msgout_noop(void) "MSG: No Operation" |
115 | - | 93 | lsi_do_msgout_extended(uint8_t msg, uint8_t len) "Extended message 0x%x (len %d)" |
116 | - trace_qemu_aio_coroutine_enter(ctx, self, co, co->entry_arg); | 94 | lsi_do_msgout_ignored(const char *msg) "%s (ignored)" |
117 | - | 95 | lsi_do_msgout_simplequeue(uint8_t select_tag) "SIMPLE queue tag=0x%x" |
118 | - /* if the Coroutine has already been scheduled, entering it again will | 96 | -lsi_do_msgout_abort(uint32_t tag) "MSG: ABORT TAG tag=0x%"PRId32 |
119 | - * cause us to enter it twice, potentially even after the coroutine has | 97 | +lsi_do_msgout_abort(uint32_t tag) "MSG: ABORT TAG tag=0x%"PRIx32 |
120 | - * been deleted */ | 98 | lsi_do_msgout_clearqueue(uint32_t tag) "MSG: CLEAR QUEUE tag=0x%"PRIx32 |
121 | - if (scheduled) { | 99 | lsi_do_msgout_busdevicereset(uint32_t tag) "MSG: BUS DEVICE RESET tag=0x%"PRIx32 |
122 | - fprintf(stderr, | 100 | lsi_do_msgout_select(int id) "Select LUN %d" |
123 | - "%s: Co-routine was already scheduled in '%s'\n", | ||
124 | - __func__, scheduled); | ||
125 | - abort(); | ||
126 | - } | ||
127 | - | ||
128 | - if (co->caller) { | ||
129 | - fprintf(stderr, "Co-routine re-entered recursively\n"); | ||
130 | - abort(); | ||
131 | - } | ||
132 | - | ||
133 | - co->caller = self; | ||
134 | - co->ctx = ctx; | ||
135 | - | ||
136 | - /* Store co->ctx before anything that stores co. Matches | ||
137 | - * barrier in aio_co_wake and qemu_co_mutex_wake. | ||
138 | - */ | ||
139 | - smp_wmb(); | ||
140 | - | ||
141 | - ret = qemu_coroutine_switch(self, co, COROUTINE_ENTER); | ||
142 | - | ||
143 | - qemu_co_queue_run_restart(co); | ||
144 | - | ||
145 | - /* Beware, if ret == COROUTINE_YIELD and qemu_co_queue_run_restart() | ||
146 | - * has started any other coroutine, "co" might have been reentered | ||
147 | - * and even freed by now! So be careful and do not touch it. | ||
148 | - */ | ||
149 | - | ||
150 | - switch (ret) { | ||
151 | - case COROUTINE_YIELD: | ||
152 | - return; | ||
153 | - case COROUTINE_TERMINATE: | ||
154 | - assert(!co->locks_held); | ||
155 | - trace_qemu_coroutine_terminate(co); | ||
156 | - coroutine_delete(co); | ||
157 | - return; | ||
158 | - default: | ||
159 | - abort(); | ||
160 | + QSIMPLEQ_HEAD(, Coroutine) pending = QSIMPLEQ_HEAD_INITIALIZER(pending); | ||
161 | + Coroutine *from = qemu_coroutine_self(); | ||
162 | + | ||
163 | + QSIMPLEQ_INSERT_TAIL(&pending, co, co_queue_next); | ||
164 | + | ||
165 | + /* Run co and any queued coroutines */ | ||
166 | + while (!QSIMPLEQ_EMPTY(&pending)) { | ||
167 | + Coroutine *to = QSIMPLEQ_FIRST(&pending); | ||
168 | + CoroutineAction ret; | ||
169 | + | ||
170 | + /* Cannot rely on the read barrier for to in aio_co_wake(), as there are | ||
171 | + * callers outside of aio_co_wake() */ | ||
172 | + const char *scheduled = atomic_mb_read(&to->scheduled); | ||
173 | + | ||
174 | + QSIMPLEQ_REMOVE_HEAD(&pending, co_queue_next); | ||
175 | + | ||
176 | + trace_qemu_aio_coroutine_enter(ctx, from, to, to->entry_arg); | ||
177 | + | ||
178 | + /* if the Coroutine has already been scheduled, entering it again will | ||
179 | + * cause us to enter it twice, potentially even after the coroutine has | ||
180 | + * been deleted */ | ||
181 | + if (scheduled) { | ||
182 | + fprintf(stderr, | ||
183 | + "%s: Co-routine was already scheduled in '%s'\n", | ||
184 | + __func__, scheduled); | ||
185 | + abort(); | ||
186 | + } | ||
187 | + | ||
188 | + if (to->caller) { | ||
189 | + fprintf(stderr, "Co-routine re-entered recursively\n"); | ||
190 | + abort(); | ||
191 | + } | ||
192 | + | ||
193 | + to->caller = from; | ||
194 | + to->ctx = ctx; | ||
195 | + | ||
196 | + /* Store to->ctx before anything that stores to. Matches | ||
197 | + * barrier in aio_co_wake and qemu_co_mutex_wake. | ||
198 | + */ | ||
199 | + smp_wmb(); | ||
200 | + | ||
201 | + ret = qemu_coroutine_switch(from, to, COROUTINE_ENTER); | ||
202 | + | ||
203 | + /* Queued coroutines are run depth-first; previously pending coroutines | ||
204 | + * run after those queued more recently. | ||
205 | + */ | ||
206 | + QSIMPLEQ_PREPEND(&pending, &to->co_queue_wakeup); | ||
207 | + | ||
208 | + switch (ret) { | ||
209 | + case COROUTINE_YIELD: | ||
210 | + break; | ||
211 | + case COROUTINE_TERMINATE: | ||
212 | + assert(!to->locks_held); | ||
213 | + trace_qemu_coroutine_terminate(to); | ||
214 | + coroutine_delete(to); | ||
215 | + break; | ||
216 | + default: | ||
217 | + abort(); | ||
218 | + } | ||
219 | } | ||
220 | } | ||
221 | |||
222 | -- | 101 | -- |
223 | 2.14.3 | 102 | 2.35.1 |
224 | 103 | ||
225 | 104 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | Check that two coroutines can queue each other repeatedly without | ||
2 | hitting stack exhaustion. | ||
3 | 1 | ||
4 | Switch to qemu_init_main_loop() in main() because coroutines use | ||
5 | qemu_get_aio_context() - they don't know about test-aio's ctx variable. | ||
6 | |||
7 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
8 | Reviewed-by: Paolo Bonzini <pbonzini@redhat.com> | ||
9 | Message-id: 20180322152834.12656-4-stefanha@redhat.com | ||
10 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
11 | --- | ||
12 | tests/test-aio.c | 65 ++++++++++++++++++++++++++++++++++++++++++++------------ | ||
13 | 1 file changed, 52 insertions(+), 13 deletions(-) | ||
14 | |||
15 | diff --git a/tests/test-aio.c b/tests/test-aio.c | ||
16 | index XXXXXXX..XXXXXXX 100644 | ||
17 | --- a/tests/test-aio.c | ||
18 | +++ b/tests/test-aio.c | ||
19 | @@ -XXX,XX +XXX,XX @@ | ||
20 | #include "qemu/timer.h" | ||
21 | #include "qemu/sockets.h" | ||
22 | #include "qemu/error-report.h" | ||
23 | +#include "qemu/coroutine.h" | ||
24 | +#include "qemu/main-loop.h" | ||
25 | |||
26 | static AioContext *ctx; | ||
27 | |||
28 | @@ -XXX,XX +XXX,XX @@ static void test_source_timer_schedule(void) | ||
29 | timer_del(&data.timer); | ||
30 | } | ||
31 | |||
32 | +/* | ||
33 | + * Check that aio_co_enter() can chain many times | ||
34 | + * | ||
35 | + * Two coroutines should be able to invoke each other via aio_co_enter() many | ||
36 | + * times without hitting a limit like stack exhaustion. In other words, the | ||
37 | + * calls should be chained instead of nested. | ||
38 | + */ | ||
39 | + | ||
40 | +typedef struct { | ||
41 | + Coroutine *other; | ||
42 | + unsigned i; | ||
43 | + unsigned max; | ||
44 | +} ChainData; | ||
45 | + | ||
46 | +static void coroutine_fn chain(void *opaque) | ||
47 | +{ | ||
48 | + ChainData *data = opaque; | ||
49 | + | ||
50 | + for (data->i = 0; data->i < data->max; data->i++) { | ||
51 | + /* Queue up the other coroutine... */ | ||
52 | + aio_co_enter(ctx, data->other); | ||
53 | + | ||
54 | + /* ...and give control to it */ | ||
55 | + qemu_coroutine_yield(); | ||
56 | + } | ||
57 | +} | ||
58 | + | ||
59 | +static void test_queue_chaining(void) | ||
60 | +{ | ||
61 | + /* This number of iterations hit stack exhaustion in the past: */ | ||
62 | + ChainData data_a = { .max = 25000 }; | ||
63 | + ChainData data_b = { .max = 25000 }; | ||
64 | + | ||
65 | + data_b.other = qemu_coroutine_create(chain, &data_a); | ||
66 | + data_a.other = qemu_coroutine_create(chain, &data_b); | ||
67 | + | ||
68 | + qemu_coroutine_enter(data_b.other); | ||
69 | + | ||
70 | + g_assert_cmpint(data_a.i, ==, data_a.max); | ||
71 | + g_assert_cmpint(data_b.i, ==, data_b.max - 1); | ||
72 | + | ||
73 | + /* Allow the second coroutine to terminate */ | ||
74 | + qemu_coroutine_enter(data_a.other); | ||
75 | + | ||
76 | + g_assert_cmpint(data_b.i, ==, data_b.max); | ||
77 | +} | ||
78 | |||
79 | /* End of tests. */ | ||
80 | |||
81 | int main(int argc, char **argv) | ||
82 | { | ||
83 | - Error *local_error = NULL; | ||
84 | - GSource *src; | ||
85 | - | ||
86 | - init_clocks(NULL); | ||
87 | - | ||
88 | - ctx = aio_context_new(&local_error); | ||
89 | - if (!ctx) { | ||
90 | - error_reportf_err(local_error, "Failed to create AIO Context: "); | ||
91 | - exit(1); | ||
92 | - } | ||
93 | - src = aio_get_g_source(ctx); | ||
94 | - g_source_attach(src, NULL); | ||
95 | - g_source_unref(src); | ||
96 | + qemu_init_main_loop(&error_fatal); | ||
97 | + ctx = qemu_get_aio_context(); | ||
98 | |||
99 | while (g_main_context_iteration(NULL, false)); | ||
100 | |||
101 | @@ -XXX,XX +XXX,XX @@ int main(int argc, char **argv) | ||
102 | g_test_add_func("/aio/external-client", test_aio_external_client); | ||
103 | g_test_add_func("/aio/timer/schedule", test_timer_schedule); | ||
104 | |||
105 | + g_test_add_func("/aio/coroutine/queue-chaining", test_queue_chaining); | ||
106 | + | ||
107 | g_test_add_func("/aio-gsource/flush", test_source_flush); | ||
108 | g_test_add_func("/aio-gsource/bh/schedule", test_source_bh_schedule); | ||
109 | g_test_add_func("/aio-gsource/bh/schedule10", test_source_bh_schedule10); | ||
110 | -- | ||
111 | 2.14.3 | ||
112 | |||
113 | diff view generated by jsdifflib |