qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Fiona Ebner <f.ebner@proxmox.com>
To: Kevin Wolf <kwolf@redhat.com>
Cc: "open list:Network Block Dev..." <qemu-block@nongnu.org>,
	Hanna Czenczek <hreitz@redhat.com>,
	eesposit@redhat.com, Paolo Bonzini <pbonzini@redhat.com>,
	QEMU Developers <qemu-devel@nongnu.org>,
	Thomas Lamprecht <t.lamprecht@proxmox.com>
Subject: Re: Question about graph locking preconditions regarding qemu_in_main_thread()
Date: Tue, 9 May 2023 16:20:18 +0200	[thread overview]
Message-ID: <b431b9b8-a68d-9b49-8df3-b5e1b424b648@proxmox.com> (raw)
In-Reply-To: <ZFpQXPqW0s95/guu@redhat.com>

Am 09.05.23 um 15:53 schrieb Kevin Wolf:
> Am 09.05.2023 um 12:26 hat Fiona Ebner geschrieben:
>> Am 08.05.23 um 12:40 schrieb Kevin Wolf:
>>> Am 05.05.2023 um 11:35 hat Fiona Ebner geschrieben:
>>>> Hi,
>>>> I noticed that the bdrv_graph_co_rd_lock() and bdrv_graph_co_rd_unlock()
>>>> functions use qemu_in_main_thread() as a conditional to return early.
>>>> What high-level requirements ensure that qemu_in_main_thread() will
>>>> evaluate to the same value during locking and unlocking?
>>>
>>> I think it's actually wrong.
>>>
>>> There are some conditions under which we don't actually need to do
>>> anything for locking: Writing the graph is only possible from the main
>>> context while holding the BQL. So if a reader is running in the main
>>> contextunder the BQL and knows that it won't be interrupted until the
>>> next writer runs, we don't actually need to do anything.
>>>
>>> This is the case if the reader code neither has a nested event loop
>>> (this is forbidden anyway while you hold the lock) nor is a coroutine
>>> (because a writer could run when the coroutine has yielded).
>>
>> Sorry, I don't understand the first part. If bdrv_writev_vmstate() is
>> called, then, because it is a generated coroutine wrapper,
>> AIO_WAIT_WHILE()/aio_poll() is used. And that is the case regardless of
>> whether the lock is held or not, i.e. there is a nested event loop even
>> if the lock is held?
> 
> With "lock" you mean the graph lock here, not the BQL, right?

Oh, I actually meant the BQL. Since your "lock" refers to the graph
lock, that explains my confusion :)

> 
> These generated coroutine wrapper are a bit ugly because they behave
> different when called from a coroutine and when called outside of
> coroutine context:
> 
> * In coroutine context, the caller MUST hold the lock
> * Outside of coroutine context, the caller MUST NOT hold the lock
> 
> The second requirement comes from AIO_WAIT_WHILE(), like you say. If you
> hold the lock and you're not in a coroutine, you simply can't call such
> functions.
> 
> However, as bdrv_graph_co_rdlock() is a coroutine_fn, you won't usually
> hold the lock outside of coroutine context anyway. But it's something to
> be careful with when you have a writer lock.
> 

Best Regards,
Fiona



      reply	other threads:[~2023-05-09 14:21 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-05  9:35 Question about graph locking preconditions regarding qemu_in_main_thread() Fiona Ebner
2023-05-08 10:40 ` Kevin Wolf
2023-05-09 10:26   ` Fiona Ebner
2023-05-09 13:53     ` Kevin Wolf
2023-05-09 14:20       ` Fiona Ebner [this message]

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=b431b9b8-a68d-9b49-8df3-b5e1b424b648@proxmox.com \
    --to=f.ebner@proxmox.com \
    --cc=eesposit@redhat.com \
    --cc=hreitz@redhat.com \
    --cc=kwolf@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    --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 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).