From ca96ac44dcd290566090b2435bc828fded356ad9 Mon Sep 17 00:00:00 2001 From: Stefan Hajnoczi Date: Tue, 28 Jul 2015 18:34:09 +0200 Subject: AioContext: force event loop iteration using BH The notify_me optimization introduced in commit eabc97797310 ("AioContext: fix broken ctx->dispatching optimization") skips event_notifier_set() calls when the event loop thread is not blocked in ppoll(2). This optimization causes a deadlock if two aio_context_acquire() calls race. notify_me = 0 during the race so the winning thread can enter ppoll(2) unaware that the other thread is waiting its turn to acquire the AioContext. This patch forces ppoll(2) to return by scheduling a BH instead of calling aio_notify(). The following deadlock with virtio-blk dataplane is fixed: qemu ... -object iothread,id=iothread0 \ -drive if=none,id=drive0,file=test.img,... \ -device virtio-blk-pci,iothread=iothread0,drive=drive0 This command-line results in a hang early on without this patch. Thanks to Paolo Bonzini for investigating this bug with me. Cc: Christian Borntraeger Cc: Cornelia Huck Cc: Paolo Bonzini Signed-off-by: Stefan Hajnoczi Signed-off-by: Paolo Bonzini Message-id: 1438101249-25166-4-git-send-email-pbonzini@redhat.com Message-Id: <1438014819-18125-3-git-send-email-stefanha@redhat.com> Signed-off-by: Paolo Bonzini Signed-off-by: Stefan Hajnoczi --- include/block/aio.h | 3 +++ 1 file changed, 3 insertions(+) (limited to 'include/block') diff --git a/include/block/aio.h b/include/block/aio.h index 9dd32e0f13..400b1b0020 100644 --- a/include/block/aio.h +++ b/include/block/aio.h @@ -114,6 +114,9 @@ struct AioContext { bool notified; EventNotifier notifier; + /* Scheduling this BH forces the event loop it iterate */ + QEMUBH *notify_dummy_bh; + /* Thread pool for performing work and receiving completion callbacks */ struct ThreadPool *thread_pool; -- cgit v1.2.3