QEMU-Devel Archive on lore.kernel.org
 help / color / mirror / Atom feed
* Can we make QMP commands in Rust always be coroutine safe?
@ 2026-05-05  8:44 Markus Armbruster
  2026-05-05  8:58 ` Manos Pitsidianakis
  2026-05-05 10:51 ` Paolo Bonzini
  0 siblings, 2 replies; 4+ messages in thread
From: Markus Armbruster @ 2026-05-05  8:44 UTC (permalink / raw)
  To: qemu-devel, qemu-rust, Paolo Bonzini, Kevin Wolf, Hanna Czenczek,
	Stefan Hajnoczi

QMP commands that perform potentially blocking I/O can profit from
running in a coroutine.  Ideally, we'd run all commands in coroutine
context: most of them don't care, a few profit.  However, some existing
commands may need fixing to run safely there.  Since we don't know which
ones do, running in couroutine context is opt-in.  From
docs/devel/qapi-code-gen.rst section "Commands":

    Member 'coroutine' tells the QMP dispatcher whether the command handler
    is safe to be run in a coroutine.  It defaults to false.  If it is true,
    the command handler is called from coroutine context and may yield while
    waiting for an external event (such as I/O completion) in order to avoid
    blocking the guest and other background operations.

    Coroutine safety can be hard to prove, similar to thread safety.  Common
    pitfalls are:

    - The BQL isn't held across ``qemu_coroutine_yield()``, so
      operations that used to assume that they execute atomically may have
      to be more careful to protect against changes in the global state.

    - Nested event loops (``AIO_WAIT_WHILE()`` etc.) are problematic in
      coroutine context and can easily lead to deadlocks.  They should be
      replaced by yielding and reentering the coroutine when the condition
      becomes false.

    Since the command handler may assume coroutine context, any callers
    other than the QMP dispatcher must also call it in coroutine context.
    In particular, HMP commands calling such a QMP command handler must be
    marked ``.coroutine = true`` in hmp-commands.hx.

    It is an error to specify both ``'coroutine': true`` and ``'allow-oob': true``
    for a command.  We don't currently have a use case for both together and
    without a use case, it's not entirely clear what the semantics should
    be.

Can we make commands written in Rust always coroutine safe?



^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-05-12 14:18 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-05-05  8:44 Can we make QMP commands in Rust always be coroutine safe? Markus Armbruster
2026-05-05  8:58 ` Manos Pitsidianakis
2026-05-05 10:51 ` Paolo Bonzini
2026-05-12 14:16   ` Kevin Wolf

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox