All of lore.kernel.org
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: Emanuele Giuseppe Esposito <eesposit@redhat.com>,
	Stefan Hajnoczi <stefanha@redhat.com>
Cc: qemu-block@nongnu.org, Kevin Wolf <kwolf@redhat.com>,
	Hanna Reitz <hreitz@redhat.com>, John Snow <jsnow@redhat.com>,
	Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>,
	Fam Zheng <fam@euphon.net>,
	qemu-devel@nongnu.org
Subject: Re: [RFC PATCH v2 0/8] Removal of AioContext lock, bs->parents and ->children: new rwlock
Date: Wed, 18 May 2022 14:43:50 +0200	[thread overview]
Message-ID: <6fc3e40e-7682-b9dc-f789-3ca95e0430db@redhat.com> (raw)
In-Reply-To: <cc5e12d1-d25f-d338-bff2-0d3f5cc0def7@redhat.com>

On 5/18/22 14:28, Emanuele Giuseppe Esposito wrote:
> For example, all callers of bdrv_open() always take the AioContext lock.
> Often it is taken very high in the call stack, but it's always taken.

I think it's actually not a problem of who takes the AioContext lock or 
where; the requirements are contradictory:

* IO_OR_GS_CODE() functions, when called from coroutine context, expect 
to be called with the AioContext lock taken (example: 
bdrv_co_yield_to_drain)

* to call these functions with the lock taken, the code has to run in 
the BDS's home iothread.  Attempts to do otherwise results in deadlocks 
(the main loop's AIO_WAIT_WHILEs expect progress from the iothread, that 
cannot happen without releasing the aiocontext lock)

* running the code in the BDS's home iothread is not possible for 
GLOBAL_STATE_CODE() functions (unless the BDS home iothread is the main 
thread, but that cannot be guaranteed in general)

> We might suppose that many callbacks are called under drain and in
> GLOBAL_STATE, which should be enough, but from our experimentation in
> the previous series we saw that currently not everything is under drain,
> leaving some operations unprotected (remember assert_graph_writable
> temporarily disabled, since drain coverage for bdrv_replace_child_noperm
> was not 100%?).
> Therefore we need to add more drains. But isn't drain what we decided to
> drop at the beginning? Why isn't drain good?

To sum up the patch ordering deadlock that we have right now:

* in some cases, graph manipulations are protected by the AioContext lock

* eliminating the AioContext lock is needed to move callbacks to 
coroutine contexts (see above for the deadlock scenario)

* moving callbacks to coroutine context is needed by the graph rwlock 
implementation

On one hand, we cannot protect the graph across manipulations with a 
graph rwlock without removing the AioContext lock; on the other hand, 
the AioContext lock is what _right now_ protects the graph.

So I'd rather go back to Emanuele's draining approach.  It may not be 
beautiful, but it allows progress.  Once that is in place, we can remove 
the AioContext lock (which mostly protects virtio-blk/virtio-scsi code 
right now) and reevaluate our next steps.

Paolo


  reply	other threads:[~2022-05-18 12:48 UTC|newest]

Thread overview: 67+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-26  8:51 [RFC PATCH v2 0/8] Removal of AioContext lock, bs->parents and ->children: new rwlock Emanuele Giuseppe Esposito
2022-04-26  8:51 ` [RFC PATCH v2 1/8] aio_wait_kick: add missing memory barrier Emanuele Giuseppe Esposito
2022-04-28 11:09   ` Stefan Hajnoczi
2022-04-29  8:06     ` Emanuele Giuseppe Esposito
2022-04-30  5:21       ` Stefan Hajnoczi
2022-04-29  8:12   ` Paolo Bonzini
2022-04-26  8:51 ` [RFC PATCH v2 2/8] coroutine-lock: release lock when restarting all coroutines Emanuele Giuseppe Esposito
2022-04-26 14:59   ` Paolo Bonzini
2022-04-28 11:21   ` Stefan Hajnoczi
2022-04-28 22:14     ` Paolo Bonzini
2022-04-29  9:35       ` Emanuele Giuseppe Esposito
2022-04-26  8:51 ` [RFC PATCH v2 3/8] block: introduce a lock to protect graph operations Emanuele Giuseppe Esposito
2022-04-26 15:00   ` Paolo Bonzini
2022-04-28 13:45   ` Stefan Hajnoczi
2022-04-29  8:37     ` Emanuele Giuseppe Esposito
2022-04-30  5:48       ` Stefan Hajnoczi
2022-05-02  7:54         ` Emanuele Giuseppe Esposito
2022-05-03 10:50           ` Stefan Hajnoczi
2022-04-26  8:51 ` [RFC PATCH v2 4/8] async: register/unregister aiocontext in graph lock list Emanuele Giuseppe Esposito
2022-04-28 13:46   ` Stefan Hajnoczi
2022-04-28 22:19     ` Paolo Bonzini
2022-04-29  8:37       ` Emanuele Giuseppe Esposito
2022-04-26  8:51 ` [RFC PATCH v2 5/8] block.c: wrlock in bdrv_replace_child_noperm Emanuele Giuseppe Esposito
2022-04-26 15:07   ` Paolo Bonzini
2022-04-28 13:55   ` Stefan Hajnoczi
2022-04-29  8:41     ` Emanuele Giuseppe Esposito
2022-04-26  8:51 ` [RFC PATCH v2 6/8] block: assert that graph read and writes are performed correctly Emanuele Giuseppe Esposito
2022-04-28 14:43   ` Stefan Hajnoczi
2022-04-26  8:51 ` [RFC PATCH v2 7/8] graph-lock: implement WITH_GRAPH_RDLOCK_GUARD and GRAPH_RDLOCK_GUARD macros Emanuele Giuseppe Esposito
2022-04-28 15:00   ` Stefan Hajnoczi
2022-04-26  8:51 ` [RFC PATCH v2 8/8] mirror: protect drains in coroutine with rdlock Emanuele Giuseppe Esposito
2022-04-27  6:55 ` [RFC PATCH v2 0/8] Removal of AioContext lock, bs->parents and ->children: new rwlock Emanuele Giuseppe Esposito
2022-04-28 10:45   ` Stefan Hajnoczi
2022-04-28 21:56     ` Emanuele Giuseppe Esposito
2022-04-30  5:17       ` Stefan Hajnoczi
2022-05-02  8:02         ` Emanuele Giuseppe Esposito
2022-05-02 13:15           ` Paolo Bonzini
2022-05-03  8:24           ` Kevin Wolf
2022-05-03 11:04           ` Stefan Hajnoczi
2022-04-28 10:34 ` Stefan Hajnoczi
2022-04-29  8:06   ` Emanuele Giuseppe Esposito
2022-05-04 13:39 ` Stefan Hajnoczi
2022-05-17 10:59   ` Stefan Hajnoczi
2022-05-18 12:28     ` Emanuele Giuseppe Esposito
2022-05-18 12:43       ` Paolo Bonzini [this message]
2022-05-18 14:57         ` Stefan Hajnoczi
2022-05-18 16:14         ` Kevin Wolf
2022-05-19 11:27           ` Stefan Hajnoczi
2022-05-19 12:52             ` Kevin Wolf
2022-05-22 15:06           ` Stefan Hajnoczi
2022-05-23  8:48             ` Emanuele Giuseppe Esposito
2022-05-23 13:15               ` Stefan Hajnoczi
2022-05-23 13:54                 ` Emanuele Giuseppe Esposito
2022-05-23 13:02             ` Kevin Wolf
2022-05-23 15:13               ` Stefan Hajnoczi
2022-05-23 16:04                 ` Kevin Wolf
2022-05-23 16:45                   ` Stefan Hajnoczi
2022-05-24  7:55             ` Paolo Bonzini
2022-05-24  8:08               ` Stefan Hajnoczi
2022-05-24  9:17                 ` Paolo Bonzini
2022-05-24 10:20                   ` Stefan Hajnoczi
2022-05-24 17:25                     ` Paolo Bonzini
2022-05-24 10:36         ` Kevin Wolf
2022-05-25  7:41           ` Paolo Bonzini
2022-05-18 14:27       ` Stefan Hajnoczi
2022-05-24 12:10       ` Kevin Wolf
2022-05-25  8:27         ` Emanuele Giuseppe Esposito

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=6fc3e40e-7682-b9dc-f789-3ca95e0430db@redhat.com \
    --to=pbonzini@redhat.com \
    --cc=eesposit@redhat.com \
    --cc=fam@euphon.net \
    --cc=hreitz@redhat.com \
    --cc=jsnow@redhat.com \
    --cc=kwolf@redhat.com \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    --cc=stefanha@redhat.com \
    --cc=vsementsov@virtuozzo.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.