qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Roman Kagan <rvkagan@yandex-team.ru>
To: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Cc: Kevin Wolf <kwolf@redhat.com>,
	qemu-block@nongnu.org, qemu-devel@nongnu.org,
	Max Reitz <mreitz@redhat.com>,
	yc-core@yandex-team.ru
Subject: Re: [PATCH 3/7] block/nbd: assert attach/detach runs in the proper context
Date: Mon, 15 Mar 2021 22:57:18 +0300	[thread overview]
Message-ID: <YE+8HqhzyQcXRjHB@rvkaganb.lan> (raw)
In-Reply-To: <6bc8bb0e-c22b-ccc1-4f19-5a7076f348ef@virtuozzo.com>

On Mon, Mar 15, 2021 at 07:41:32PM +0300, Vladimir Sementsov-Ogievskiy wrote:
> 15.03.2021 09:06, Roman Kagan wrote:
> > Document (via a comment and an assert) that
> > nbd_client_detach_aio_context and nbd_client_attach_aio_context_bh run
> > in the desired aio_context
> > 
> > Signed-off-by: Roman Kagan <rvkagan@yandex-team.ru>
> > ---
> >   block/nbd.c | 12 ++++++++++++
> >   1 file changed, 12 insertions(+)
> > 
> > diff --git a/block/nbd.c b/block/nbd.c
> > index 1d8edb5b21..658b827d24 100644
> > --- a/block/nbd.c
> > +++ b/block/nbd.c
> > @@ -241,6 +241,12 @@ static void nbd_client_detach_aio_context(BlockDriverState *bs)
> >   {
> >       BDRVNBDState *s = (BDRVNBDState *)bs->opaque;
> > +    /*
> > +     * This runs in the (old, about to be detached) aio context of the @bs so
> > +     * accessing the stuff on @s is concurrency-free.
> > +     */
> > +    assert(qemu_get_current_aio_context() == bdrv_get_aio_context(bs));
> 
> Hmm. I don't think so. The handler is called from bdrv_set_aio_context_ignore(), which have the assertion g_assert(qemu_get_current_aio_context() == qemu_get_aio_context());. There is also a comment above bdrv_set_aio_context_ignore() "The caller must own the AioContext lock for the old AioContext of bs".
> 
> So, we are not in the home context of bs here. We are in the main aio context and we hold AioContext lock of old bs context.

You're absolutely right.  I'm wondering where I got the idea of this
assertion from...

> 
> > +
> >       /* Timer is deleted in nbd_client_co_drain_begin() */
> >       assert(!s->reconnect_delay_timer);
> >       /*
> > @@ -258,6 +264,12 @@ static void nbd_client_attach_aio_context_bh(void *opaque)
> >       BlockDriverState *bs = opaque;
> >       BDRVNBDState *s = (BDRVNBDState *)bs->opaque;
> > +    /*
> > +     * This runs in the (new, just attached) aio context of the @bs so
> > +     * accessing the stuff on @s is concurrency-free.
> > +     */
> > +    assert(qemu_get_current_aio_context() == bdrv_get_aio_context(bs));
> 
> This is correct just because we are in a BH, scheduled for this
> context (I hope we can't reattach some third context prior to entering
> the BH in the second:). So, I don't think this assertion really adds
> something.

Indeed.

> > +
> >       if (s->connection_co) {
> >           /*
> >            * The node is still drained, so we know the coroutine has yielded in
> > 
> 
> I'm not sure that the asserted fact gives us "concurrency-free". For
> this we also need to ensure that all other things in the driver are
> always called in same aio context.. Still, it's a general assumption
> we have when writing block drivers "everything in one aio context, so
> don't care".. Sometime it leads to bugs, as some things are still
> called even from non-coroutine context. Also, Paolo said
> (https://lists.gnu.org/archive/html/qemu-devel/2020-08/msg03814.html)
> that many iothreads will send requests to bs, and the code in driver
> should be thread safe. I don't have good understanding of all these
> things, and what I have is:
> 
> For now (at least we don't have problems in Rhel based downstream) it
> maybe OK to think that in block-driver everything is protected by
> AioContext lock and all concurrency we have inside block driver is
> switching between coroutines but never real parallelism. But in
> general it's not so, and with multiqueue it's not so.. So, I'd not put
> such a comment :)

So the patch is bogus in every respect; let's just drop it.

I hope it doesn't invalidate completely the rest of the series though.

Meanwhile I certainly need to update my idea of concurrency assumptions
in the block layer.

Thanks,
Roman.


  reply	other threads:[~2021-03-15 20:01 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-15  6:06 [PATCH 0/7] block/nbd: decouple reconnect from drain Roman Kagan
2021-03-15  6:06 ` [PATCH 1/7] block/nbd: avoid touching freed connect_thread Roman Kagan
2021-03-15 15:40   ` Vladimir Sementsov-Ogievskiy
2021-03-16 15:29     ` Roman Kagan
2021-04-06 16:21   ` Vladimir Sementsov-Ogievskiy
2021-03-15  6:06 ` [PATCH 2/7] block/nbd: use uniformly nbd_client_connecting_wait Roman Kagan
2021-03-15 15:48   ` Vladimir Sementsov-Ogievskiy
2021-03-15  6:06 ` [PATCH 3/7] block/nbd: assert attach/detach runs in the proper context Roman Kagan
2021-03-15 16:41   ` Vladimir Sementsov-Ogievskiy
2021-03-15 19:57     ` Roman Kagan [this message]
2021-03-15  6:06 ` [PATCH 4/7] block/nbd: transfer reconnection stuff across aio_context switch Roman Kagan
2021-03-15  6:06 ` [PATCH 5/7] block/nbd: better document a case in nbd_co_establish_connection Roman Kagan
2021-03-15  6:06 ` [PATCH 6/7] block/nbd: decouple reconnect from drain Roman Kagan
2021-03-15 20:10   ` Vladimir Sementsov-Ogievskiy
2021-03-16 16:03     ` Roman Kagan
2021-03-16 18:09       ` Vladimir Sementsov-Ogievskiy
2021-03-26  6:16         ` Roman Kagan
2021-03-15  6:06 ` [PATCH 7/7] block/nbd: stop manipulating in_flight counter Roman Kagan
2021-03-15 20:15   ` Vladimir Sementsov-Ogievskiy
2021-03-16 16:08     ` Roman Kagan
2021-03-16 18:37       ` Vladimir Sementsov-Ogievskiy
2021-03-26  7:41         ` Roman Kagan
2021-03-15 19:45 ` [PATCH 0/7] block/nbd: decouple reconnect from drain Vladimir Sementsov-Ogievskiy
2021-03-16 15:52   ` Roman Kagan
2021-03-16 14:41 ` Eric Blake
2021-03-16 16:10   ` Roman Kagan
2021-03-17  8:35 ` Vladimir Sementsov-Ogievskiy
2021-03-26  8:07   ` Roman Kagan
2021-04-07  7:45   ` Roman Kagan
2021-04-07 10:13     ` Vladimir Sementsov-Ogievskiy

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=YE+8HqhzyQcXRjHB@rvkaganb.lan \
    --to=rvkagan@yandex-team.ru \
    --cc=kwolf@redhat.com \
    --cc=mreitz@redhat.com \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    --cc=vsementsov@virtuozzo.com \
    --cc=yc-core@yandex-team.ru \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).