From: Kevin Wolf <kwolf@redhat.com>
To: Fiona Ebner <f.ebner@proxmox.com>
Cc: Paolo Bonzini <pbonzini@redhat.com>,
Markus Armbruster <armbru@redhat.com>,
QEMU Developers <qemu-devel@nongnu.org>,
"open list:Block layer core" <qemu-block@nongnu.org>,
Michael Roth <michael.roth@amd.com>, Fam Zheng <fam@euphon.net>,
Stefan Hajnoczi <stefanha@redhat.com>,
Thomas Lamprecht <t.lamprecht@proxmox.com>,
Peter Xu <peterx@redhat.com>
Subject: Re: QMP (without OOB) function running in thread different from the main thread as part of aio_poll
Date: Thu, 27 Apr 2023 13:03:19 +0200 [thread overview]
Message-ID: <ZEpWd+273aIVZrRV@redhat.com> (raw)
In-Reply-To: <3ba2f8b9-9818-6601-2247-7b0e20d7ab0d@proxmox.com>
Am 26.04.2023 um 16:31 hat Fiona Ebner geschrieben:
> Am 20.04.23 um 08:55 schrieb Paolo Bonzini:
> >
> >
> > Il gio 20 apr 2023, 08:11 Markus Armbruster <armbru@redhat.com
> > <mailto:armbru@redhat.com>> ha scritto:
> >
> > So, splicing in a bottom half unmoored monitor commands from the main
> > loop. We weren't aware of that, as our commit messages show.
> >
> > I guess the commands themselves don't care; all they need is the BQL.
> >
> > However, did we unwittingly change what can get blocked? Before,
> > monitor commands could block only the main thread. Now they can also
> > block vCPU threads. Impact?
> >
> >
> > Monitor commands could always block vCPU threads through the BQL(*).
> > However, aio_poll() only runs in the vCPU threads in very special cases;
> > typically associated to resetting a device which causes a blk_drain() on
> > the device's BlockBackend. So it is not a performance issue.
> >
>
> AFAIU, all generated coroutine wrappers use aio_poll. In my backtrace
> aio_poll happens via blk_pwrite for a pflash device. So a bit more
> often than "very special cases" ;)
Yes, it's a common thing for devices that start requests from the vcpu
thread when handling I/O (as opposed to devices that use an eventfd or
similar mechanisms).
> > However, liberal reuse of the main block layer AioContext could indeed
> > be a *correctness* issue. I need to re-read Fiona's report instead of
> > stopping at the first three lines because it's the evening. :)
>
> For me, being called in a vCPU thread caused problems with a custom QMP
> function patched in by Proxmox. The function uses a newly opened
> BlockBackend and calls qemu_mutex_unlock_iothread() after which
> qemu_get_current_aio_context() returns 0x0 (when running in the main
> thread, it still returns the main thread's AioContext). It then calls
> blk_pwritev which is also a generated coroutine wrapper and the
> assert(qemu_get_current_aio_context() == qemu_get_aio_context());
> in the else branch of the AIO_WAIT_WHILE_INTERNAL macro fails.
>
> Sounds like there's room for improvement in our code :/ I'm not aware
> of something similar in upstream QEMU.
Yes, even if it didn't crash immediately, calling blk_*() without
holding a lock is invalid. In many cases, this is the BQL. If you don't
hold it while calling the function from a vcpu thread, you could run
into races with the main thread, which would probably be very painful to
debug.
Kevin
next prev parent reply other threads:[~2023-04-27 11:04 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-04-19 14:09 QMP (without OOB) function running in thread different from the main thread as part of aio_poll Fiona Ebner
2023-04-19 16:59 ` Paolo Bonzini
2023-04-20 6:11 ` Markus Armbruster
2023-04-20 6:55 ` Paolo Bonzini
2023-04-26 14:31 ` Fiona Ebner
2023-04-27 11:03 ` Kevin Wolf [this message]
2023-04-27 12:27 ` Fiona Ebner
2023-04-27 14:36 ` Juan Quintela
2023-04-27 14:56 ` Peter Xu
2023-04-28 7:53 ` Fiona Ebner
2023-04-28 7:23 ` Fiona Ebner
2023-04-28 7:47 ` Juan Quintela
2023-04-28 8:30 ` Kevin Wolf
2023-04-28 8:38 ` Juan Quintela
2023-04-28 12:22 ` Kevin Wolf
2023-04-28 16:54 ` Juan Quintela
2023-05-02 10:03 ` Fiona Ebner
2023-05-02 10:25 ` Fiona Ebner
2023-05-02 10:35 ` Juan Quintela
2023-05-02 12:49 ` Fiona Ebner
2023-05-02 10:30 ` Juan Quintela
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=ZEpWd+273aIVZrRV@redhat.com \
--to=kwolf@redhat.com \
--cc=armbru@redhat.com \
--cc=f.ebner@proxmox.com \
--cc=fam@euphon.net \
--cc=michael.roth@amd.com \
--cc=pbonzini@redhat.com \
--cc=peterx@redhat.com \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=stefanha@redhat.com \
--cc=t.lamprecht@proxmox.com \
/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.