From: Kevin Wolf <kwolf@redhat.com>
To: Fam Zheng <famz@redhat.com>
Cc: qemu-block@nongnu.org, mreitz@redhat.com, qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [RFC PATCH 4/5] block: Drop AioContext lock in bdrv_drain_poll_top_level()
Date: Tue, 4 Sep 2018 16:50:08 +0200 [thread overview]
Message-ID: <20180904145008.GB4371@localhost.localdomain> (raw)
In-Reply-To: <20180824072456.GE31581@lemon.usersys.redhat.com>
Am 24.08.2018 um 09:24 hat Fam Zheng geschrieben:
> On Fri, 08/17 19:02, Kevin Wolf wrote:
> > Simimlar to AIO_WAIT_WHILE(), bdrv_drain_poll_top_level() needs to
> > release the AioContext lock of the node to be drained before calling
> > aio_poll(). Otherwise, callbacks called by aio_poll() would possibly
> > take the lock a second time and run into a deadlock with a nested
> > AIO_WAIT_WHILE() call.
> >
> > Signed-off-by: Kevin Wolf <kwolf@redhat.com>
> > ---
> > block/io.c | 25 ++++++++++++++++++++++++-
> > 1 file changed, 24 insertions(+), 1 deletion(-)
> >
> > diff --git a/block/io.c b/block/io.c
> > index 7100344c7b..832d2536bf 100644
> > --- a/block/io.c
> > +++ b/block/io.c
> > @@ -268,9 +268,32 @@ bool bdrv_drain_poll(BlockDriverState *bs, bool recursive,
> > static bool bdrv_drain_poll_top_level(BlockDriverState *bs, bool recursive,
> > BdrvChild *ignore_parent)
> > {
> > + AioContext *ctx = bdrv_get_aio_context(bs);
> > +
> > + /*
> > + * We cannot easily release the lock unconditionally here because many
> > + * callers of drain function (like qemu initialisation, tools, etc.) don't
> > + * even hold the main context lock.
> > + *
> > + * This means that we fix potential deadlocks for the case where we are in
> > + * the main context and polling a BDS in a different AioContext, but
> > + * draining a BDS in the main context from a different I/O thread would
> > + * still have this problem. Fortunately, this isn't supposed to happen
> > + * anyway.
> > + */
> > + if (ctx != qemu_get_aio_context()) {
> > + aio_context_release(ctx);
> > + } else {
> > + assert(qemu_get_current_aio_context() == qemu_get_aio_context());
> > + }
> > +
> > /* Execute pending BHs first and check everything else only after the BHs
> > * have executed. */
> > - while (aio_poll(bs->aio_context, false));
> > + while (aio_poll(ctx, false));
> > +
> > + if (ctx != qemu_get_aio_context()) {
> > + aio_context_acquire(ctx);
> > + }
> >
> > return bdrv_drain_poll(bs, recursive, ignore_parent, false);
> > }
>
> The same question as patch 3: why not just use AIO_WAIT_WHILE() here? It takes
> care to not release any lock if both running and polling in the main context
> (taking the in_aio_context_home_thread() branch).
I don't think AIO_WAIT_WHILE() can be non-blocking, though?
There is also no real condition here to check. It's just polling as long
as there is activity to get the pending BH callbacks run. I'm not sure
how I could possibly write this as a AIO_WAIT_WHILE() condition.
After all, this one just doesn't feel like the right use case for
AIO_WAIT_WHILE().
Kevin
next prev parent reply other threads:[~2018-09-04 14:50 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-08-17 17:02 [Qemu-devel] [RFC PATCH 0/5] Fix some jobs/drain/aio_poll related hangs Kevin Wolf
2018-08-17 17:02 ` [Qemu-devel] [RFC PATCH 1/5] blockjob: Wake up BDS when job becomes idle Kevin Wolf
2018-08-17 17:02 ` [Qemu-devel] [RFC PATCH 2/5] tests: Acquire AioContext around job_finish_sync() Kevin Wolf
2018-08-24 7:15 ` Fam Zheng
2018-08-17 17:02 ` [Qemu-devel] [RFC PATCH 3/5] job: Drop AioContext lock around aio_poll() Kevin Wolf
2018-08-24 7:22 ` Fam Zheng
2018-09-04 14:44 ` Kevin Wolf
2018-08-17 17:02 ` [Qemu-devel] [RFC PATCH 4/5] block: Drop AioContext lock in bdrv_drain_poll_top_level() Kevin Wolf
2018-08-24 7:24 ` Fam Zheng
2018-09-04 14:50 ` Kevin Wolf [this message]
2018-08-17 17:02 ` [Qemu-devel] [RFC PATCH 5/5] [WIP] Lock AioContext in bdrv_co_drain_bh_cb() Kevin Wolf
2018-08-18 10:46 ` [Qemu-devel] [RFC PATCH 0/5] Fix some jobs/drain/aio_poll related hangs no-reply
2018-08-21 6:08 ` Fam Zheng
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=20180904145008.GB4371@localhost.localdomain \
--to=kwolf@redhat.com \
--cc=famz@redhat.com \
--cc=mreitz@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.