[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-block] [PULL 22/42] util/async: use qemu_aio_coroutine_enter in co
From: |
Max Reitz |
Subject: |
[Qemu-block] [PULL 22/42] util/async: use qemu_aio_coroutine_enter in co_schedule_bh_cb |
Date: |
Tue, 25 Sep 2018 17:15:21 +0200 |
From: Sergio Lopez <address@hidden>
AIO Coroutines shouldn't by managed by an AioContext different than the
one assigned when they are created. aio_co_enter avoids entering a
coroutine from a different AioContext, calling aio_co_schedule instead.
Scheduled coroutines are then entered by co_schedule_bh_cb using
qemu_coroutine_enter, which just calls qemu_aio_coroutine_enter with the
current AioContext obtained with qemu_get_current_aio_context.
Eventually, co->ctx will be set to the AioContext passed as an argument
to qemu_aio_coroutine_enter.
This means that, if an IO Thread's AioConext is being processed by the
Main Thread (due to aio_poll being called with a BDS AioContext, as it
happens in AIO_WAIT_WHILE among other places), the AioContext from some
coroutines may be wrongly replaced with the one from the Main Thread.
This is the root cause behind some crashes, mainly triggered by the
drain code at block/io.c. The most common are these abort and failed
assertion:
util/async.c:aio_co_schedule
456 if (scheduled) {
457 fprintf(stderr,
458 "%s: Co-routine was already scheduled in '%s'\n",
459 __func__, scheduled);
460 abort();
461 }
util/qemu-coroutine-lock.c:
286 assert(mutex->holder == self);
But it's also known to cause random errors at different locations, and
even SIGSEGV with broken coroutine backtraces.
By using qemu_aio_coroutine_enter directly in co_schedule_bh_cb, we can
pass the correct AioContext as an argument, making sure co->ctx is not
wrongly altered.
Signed-off-by: Sergio Lopez <address@hidden>
Signed-off-by: Kevin Wolf <address@hidden>
---
util/async.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/util/async.c b/util/async.c
index 05979f8014..c10642a385 100644
--- a/util/async.c
+++ b/util/async.c
@@ -400,7 +400,7 @@ static void co_schedule_bh_cb(void *opaque)
/* Protected by write barrier in qemu_aio_coroutine_enter */
atomic_set(&co->scheduled, NULL);
- qemu_coroutine_enter(co);
+ qemu_aio_coroutine_enter(ctx, co);
aio_context_release(ctx);
}
}
--
2.17.1
- [Qemu-block] [PULL 11/42] jobs: remove .exit callback, (continued)
- [Qemu-block] [PULL 11/42] jobs: remove .exit callback, Max Reitz, 2018/09/25
- [Qemu-block] [PULL 16/42] blockdev: document transactional shortcomings, Max Reitz, 2018/09/25
- [Qemu-block] [PULL 13/42] qapi/block-mirror: expose new job properties, Max Reitz, 2018/09/25
- [Qemu-block] [PULL 15/42] block/backup: qapi documentation fixup, Max Reitz, 2018/09/25
- [Qemu-block] [PULL 14/42] qapi/block-stream: expose new job properties, Max Reitz, 2018/09/25
- [Qemu-block] [PULL 19/42] block/linux-aio: acquire AioContext before qemu_laio_process_completions, Max Reitz, 2018/09/25
- [Qemu-block] [PULL 17/42] commit: Add top-node/base-node options, Max Reitz, 2018/09/25
- [Qemu-block] [PULL 18/42] qemu-iotests: Test commit with top-node/base-node, Max Reitz, 2018/09/25
- [Qemu-block] [PULL 20/42] block: Fix use after free error in bdrv_open_inherit(), Max Reitz, 2018/09/25
- [Qemu-block] [PULL 21/42] qemu-iotests: Test snapshot=on with nonexistent TMPDIR, Max Reitz, 2018/09/25
- [Qemu-block] [PULL 22/42] util/async: use qemu_aio_coroutine_enter in co_schedule_bh_cb,
Max Reitz <=
- [Qemu-block] [PULL 25/42] blockjob: Wake up BDS when job becomes idle, Max Reitz, 2018/09/25
- [Qemu-block] [PULL 24/42] job: Fix missing locking due to mismerge, Max Reitz, 2018/09/25
- [Qemu-block] [PULL 23/42] job: Fix nested aio_poll() hanging in job_txn_apply, Max Reitz, 2018/09/25
- [Qemu-block] [PULL 26/42] aio-wait: Increase num_waiters even in home thread, Max Reitz, 2018/09/25
- [Qemu-block] [PULL 27/42] test-bdrv-drain: Drain with block jobs in an I/O thread, Max Reitz, 2018/09/25
- [Qemu-block] [PULL 28/42] test-blockjob: Acquire AioContext around job_cancel_sync(), Max Reitz, 2018/09/25
- [Qemu-block] [PULL 29/42] job: Use AIO_WAIT_WHILE() in job_finish_sync(), Max Reitz, 2018/09/25
- [Qemu-block] [PULL 30/42] test-bdrv-drain: Test AIO_WAIT_WHILE() in completion callback, Max Reitz, 2018/09/25
- [Qemu-block] [PULL 31/42] block: Add missing locking in bdrv_co_drain_bh_cb(), Max Reitz, 2018/09/25
- [Qemu-block] [PULL 32/42] block-backend: Add .drained_poll callback, Max Reitz, 2018/09/25