block: add missed aio_context_acquire into blk_unref
RFC 1/1 block: add missed aio_context_acquire into blk_unref
Recently we expirience hang with iothreads enabled with the following call trace:
Thread 1 (Thread 0x7fa95efebc80 (LWP 177117)):
0 ppoll () from /lib64/libc.so.6 2 qemu_poll_ns () at qemu-timer.c:313 3 aio_poll () at aio-posix.c:457 4 bdrv_flush () at block/io.c:2641 5 bdrv_close () at block.c:2143 6 bdrv_delete () at block.c:2352 7 bdrv_unref () at block.c:3429 8 blk_remove_bs () at block/block-backend.c:427 9 blk_delete () at block/block-backend.c:178
10 blk_unref () at block/block-backend.c:226
11 object_property_del_all () at qom/object.c:399
12 object_finalize () at qom/object.c:461
13 object_unref () at qom/object.c:898
14 object_property_del_child () at qom/object.c:422
15 qmp_marshal_device_del () at qmp-marshal.c:1145
16 handle_qmp_command () at /usr/src/debug/qemu-2.6.0/monitor.c:3929
Technically bdrv_flush() stucks in
while (rwco.ret == NOT_DONE) {
aio_poll(aio_context, true);
}but rwco.ret is equal to 0 thus we have missed wakeup. Code investigation reveals that we do not have performed aio_context_acquire() on this call stack.
This patch adds missed lock.
--- block/block-backend.c | 4 ++++ 1 file changed, 4 insertions(+)
block/block-backend.c +4 -0
@@ -273,7 +273,11 @@ void blk_unref(BlockBackend *blk)if (blk) {assert (blk->refcnt >0 );if (!--blk->refcnt) { +AioContext *ctx =blk_get_aio_context (blk); + +aio_context_acquire (ctx);blk_delete (blk); +aio_context_release (ctx); } } }
Signature · 1 line
2.7.4
@Subject: Do you mean "PATCH for-2.9?"? Because "RFC" to me means "please do not merge". ;-)
I wouldn't mind a change like this to go into 2.9.
Quoted 44 lines · Denis V. Lunev
Recently we expirience hang with iothreads enabled with the following call trace:
Thread 1 (Thread0x7fa95efebc80(LWP 177117)):0 ppoll () from /lib64/libc.so.6 2 qemu_poll_ns () at qemu-timer.c:313 3 aio_poll () at aio-posix.c:457 4 bdrv_flush () at block/io.c:2641 5 bdrv_close () at block.c:2143 6 bdrv_delete () at block.c:2352 7 bdrv_unref () at block.c:3429 8 blk_remove_bs () at block/block-backend.c:427 9 blk_delete () at block/block-backend.c:17810
blk_unref() atblock/block-backend.c:226
11object_property_del_all() atqom/object.c:399
12object_finalize() atqom/object.c:461
13object_unref() atqom/object.c:898
14object_property_del_child() atqom/object.c:422
15qmp_marshal_device_del() at qmp-marshal.c:1145
16handle_qmp_command() at/usr/src/debug/qemu-2.6.0/monitor.c:3929Technically
bdrv_flush()stucks inwhile (rwco.ret == NOT_DONE) { aio_poll(aio_context, true); }but rwco.ret is equal to 0 thus we have missed wakeup. Code investigation reveals that we do not have performed
aio_context_acquire()on this call stack.This patch adds missed lock.
Signed-off-by Denis V. Lunev <[email protected]>CC Kevin Wolf <[email protected]>CC Max Reitz <[email protected]>CC Eric Blake <[email protected]>CC Markus Armbruster <[email protected]>--- block/block-backend.c | 4 ++++ 1 file changed, 4 insertions(+)block/block-backend.c +0
-0
block/block-backend.c void blk_unref(BlockBackend *blk) · line 280
Quoted 8 lines
block/block-backend.c +4
-0@@ -273,7 +273,11 @@ void blk_unref(BlockBackend *blk)if (blk) {assert (blk->refcnt >0 );if (!--blk->refcnt) { +AioContext *ctx =blk_get_aio_context (blk); + +aio_context_acquire (ctx);blk_delete (blk); +aio_context_release (ctx);
But I don't think this is quite the correct place. The caller of blk_unref() should have acquired the AioContext already. As far as I can tell in this case that would be originally release_drive() in hw/core/qdev-properties-system.c and then blk_detach_dev().
I think the former would be the somehow more correct place but I can imagine the latter to be more useful in reality. I'll leave it to you.
(As an alternative, you may of course convince me that this patch is indeed correct and should be taken as-is. :-))
Max
Quoted 4 lines
block/block-backend.c +0
-0} } }
Quoted 4 lines · Max Reitz
@Subject: Do you mean "PATCH for-2.9?"? Because "RFC" to me means "please do not merge". ;-)
I wouldn't mind a change like this to go into 2.9.
I am quite sure that problem is here but unsure about the place. Here I use term 'RFC' as 'Can we start the discussion'?
Quoted 58 lines · Denis V. Lunev
Quoted 44 lines
Recently we expirience hang with iothreads enabled with the following call trace:
Thread 1 (Thread0x7fa95efebc80(LWP 177117)):0 ppoll () from /lib64/libc.so.6 2 qemu_poll_ns () at qemu-timer.c:313 3 aio_poll () at aio-posix.c:457 4 bdrv_flush () at block/io.c:2641 5 bdrv_close () at block.c:2143 6 bdrv_delete () at block.c:2352 7 bdrv_unref () at block.c:3429 8 blk_remove_bs () at block/block-backend.c:427 9 blk_delete () at block/block-backend.c:17810
blk_unref() atblock/block-backend.c:226
11object_property_del_all() atqom/object.c:399
12object_finalize() atqom/object.c:461
13object_unref() atqom/object.c:898
14object_property_del_child() atqom/object.c:422
15qmp_marshal_device_del() at qmp-marshal.c:1145
16handle_qmp_command() at/usr/src/debug/qemu-2.6.0/monitor.c:3929Technically
bdrv_flush()stucks inwhile (rwco.ret == NOT_DONE) { aio_poll(aio_context, true); }but rwco.ret is equal to 0 thus we have missed wakeup. Code investigation reveals that we do not have performed
aio_context_acquire()on this call stack.This patch adds missed lock.
Signed-off-by Denis V. Lunev <[email protected]>CC Kevin Wolf <[email protected]>CC Max Reitz <[email protected]>CC Eric Blake <[email protected]>CC Markus Armbruster <[email protected]>--- block/block-backend.c | 4 ++++ 1 file changed, 4 insertions(+)block/block-backend.c +0
-0block/block-backend.c void blk_unref(BlockBackend *blk) · line 280
Quoted 8 lines
block/block-backend.c +4
-0@@ -273,7 +273,11 @@ void blk_unref(BlockBackend *blk)if (blk) {assert (blk->refcnt >0 );if (!--blk->refcnt) { +AioContext *ctx =blk_get_aio_context (blk); + +aio_context_acquire (ctx);blk_delete (blk); +aio_context_release (ctx);But I don't think this is quite the correct place. The caller of
blk_unref()should have acquired the AioContext already. As far as I can tell in this case that would be originallyrelease_drive()inhw/core/qdev-properties-system.cand thenblk_detach_dev().
Quoted 5 lines
I think the former would be the somehow more correct place but I can imagine the latter to be more useful in reality. I'll leave it to you.
(As an alternative, you may of course convince me that this patch is indeed correct and should be taken as-is. :-))
ha-ha ;) no, I not going to try to convince you and that is why the patch was
marked as RFC. I like release_drive() place. This should solve the problem for me.
Thank you for the quick answer and good proposal.
Den