All of lore.kernel.org
 help / color / mirror / Atom feed
From: Kevin Wolf <kwolf@redhat.com>
To: qemu-block@nongnu.org
Cc: kwolf@redhat.com, qemu-devel@nongnu.org
Subject: [PULL 05/16] monitor: use aio_co_reschedule_self()
Date: Wed,  7 Feb 2024 22:55:55 +0100	[thread overview]
Message-ID: <20240207215606.206038-6-kwolf@redhat.com> (raw)
In-Reply-To: <20240207215606.206038-1-kwolf@redhat.com>

From: Stefan Hajnoczi <stefanha@redhat.com>

The aio_co_reschedule_self() API is designed to avoid the race
condition between scheduling the coroutine in another AioContext and
yielding.

The QMP dispatch code uses the open-coded version that appears
susceptible to the race condition at first glance:

  aio_co_schedule(qemu_get_aio_context(), qemu_coroutine_self());
  qemu_coroutine_yield();

The code is actually safe because the iohandler and qemu_aio_context
AioContext run under the Big QEMU Lock. Nevertheless, set a good example
and use aio_co_reschedule_self() so it's obvious that there is no race.

Suggested-by: Hanna Reitz <hreitz@redhat.com>
Reviewed-by: Manos Pitsidianakis <manos.pitsidianakis@linaro.org>
Reviewed-by: Hanna Czenczek <hreitz@redhat.com>
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
Message-ID: <20240206190610.107963-6-stefanha@redhat.com>
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
Acked-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
 qapi/qmp-dispatch.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)

diff --git a/qapi/qmp-dispatch.c b/qapi/qmp-dispatch.c
index 176b549473..f3488afeef 100644
--- a/qapi/qmp-dispatch.c
+++ b/qapi/qmp-dispatch.c
@@ -212,8 +212,7 @@ QDict *coroutine_mixed_fn qmp_dispatch(const QmpCommandList *cmds, QObject *requ
              * executing the command handler so that it can make progress if it
              * involves an AIO_WAIT_WHILE().
              */
-            aio_co_schedule(qemu_get_aio_context(), qemu_coroutine_self());
-            qemu_coroutine_yield();
+            aio_co_reschedule_self(qemu_get_aio_context());
         }
 
         monitor_set_cur(qemu_coroutine_self(), cur_mon);
@@ -227,9 +226,7 @@ QDict *coroutine_mixed_fn qmp_dispatch(const QmpCommandList *cmds, QObject *requ
              * Move back to iohandler_ctx so that nested event loops for
              * qemu_aio_context don't start new monitor commands.
              */
-            aio_co_schedule(iohandler_get_aio_context(),
-                            qemu_coroutine_self());
-            qemu_coroutine_yield();
+            aio_co_reschedule_self(iohandler_get_aio_context());
         }
     } else {
        /*
-- 
2.43.0



  parent reply	other threads:[~2024-02-07 21:58 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-07 21:55 [PULL 00/16] Block layer patches Kevin Wolf
2024-02-07 21:55 ` [PULL 01/16] virtio-blk: enforce iothread-vq-mapping validation Kevin Wolf
2024-02-07 21:55 ` [PULL 02/16] virtio-blk: clarify that there is at least 1 virtqueue Kevin Wolf
2024-02-07 21:55 ` [PULL 03/16] virtio-blk: add vq_rq[] bounds check in virtio_blk_dma_restart_cb() Kevin Wolf
2024-02-07 21:55 ` [PULL 04/16] virtio-blk: declare VirtIOBlock::rq with a type Kevin Wolf
2024-02-07 21:55 ` Kevin Wolf [this message]
2024-02-07 21:55 ` [PULL 06/16] block-backend: Allow concurrent context changes Kevin Wolf
2024-02-07 21:55 ` [PULL 07/16] scsi: Await request purging Kevin Wolf
2024-02-07 21:55 ` [PULL 08/16] iotests: fix leak of tmpdir in dry-run mode Kevin Wolf
2024-02-07 21:55 ` [PULL 09/16] iotests: give tempdir an identifying name Kevin Wolf
2024-02-07 21:56 ` [PULL 10/16] virtio-blk: do not use C99 mixed declarations Kevin Wolf
2024-02-07 21:56 ` [PULL 11/16] scsi: Don't ignore most usb-storage properties Kevin Wolf
2024-02-07 21:56 ` [PULL 12/16] blkio: Respect memory-alignment for bounce buffer allocations Kevin Wolf
2024-02-07 21:56 ` [PULL 13/16] virtio-scsi: Attach event vq notifier with no_poll Kevin Wolf
2024-02-07 21:56 ` [PULL 14/16] virtio: Re-enable notifications after drain Kevin Wolf
2024-02-07 21:56 ` [PULL 15/16] virtio-blk: Use ioeventfd_attach in start_ioeventfd Kevin Wolf
2024-02-07 21:56 ` [PULL 16/16] virtio-blk: avoid using ioeventfd state in irqfd conditional Kevin Wolf
2024-02-09 11:22 ` [PULL 00/16] Block layer patches Peter Maydell

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240207215606.206038-6-kwolf@redhat.com \
    --to=kwolf@redhat.com \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.