From: Kevin Wolf <kwolf@redhat.com>
To: qemu-block@nongnu.org
Cc: kwolf@redhat.com, hreitz@redhat.com, stefanha@redhat.com,
f.ebner@proxmox.com, qemu-devel@nongnu.org
Subject: [PATCH 8/8] graph-lock: Honour read locks even in the main thread
Date: Wed, 10 May 2023 22:36:01 +0200 [thread overview]
Message-ID: <20230510203601.418015-9-kwolf@redhat.com> (raw)
In-Reply-To: <20230510203601.418015-1-kwolf@redhat.com>
There are some conditions under which we don't actually need to do
anything for taking a reader lock: Writing the graph is only possible
from the main context while holding the BQL. So if a reader is running
in the main context under 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).
These conditions are exactly what bdrv_graph_rdlock_main_loop() asserts.
They are not fulfilled in bdrv_graph_co_rdlock(), which always runs in a
coroutine.
This deletes the shortcuts in bdrv_graph_co_rdlock() that skip taking
the reader lock in the main thread.
Reported-by: Fiona Ebner <f.ebner@proxmox.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
block/graph-lock.c | 10 ----------
1 file changed, 10 deletions(-)
diff --git a/block/graph-lock.c b/block/graph-lock.c
index 377884c3a9..9c42bd9799 100644
--- a/block/graph-lock.c
+++ b/block/graph-lock.c
@@ -162,11 +162,6 @@ void coroutine_fn bdrv_graph_co_rdlock(void)
BdrvGraphRWlock *bdrv_graph;
bdrv_graph = qemu_get_current_aio_context()->bdrv_graph;
- /* Do not lock if in main thread */
- if (qemu_in_main_thread()) {
- return;
- }
-
for (;;) {
qatomic_set(&bdrv_graph->reader_count,
bdrv_graph->reader_count + 1);
@@ -230,11 +225,6 @@ void coroutine_fn bdrv_graph_co_rdunlock(void)
BdrvGraphRWlock *bdrv_graph;
bdrv_graph = qemu_get_current_aio_context()->bdrv_graph;
- /* Do not lock if in main thread */
- if (qemu_in_main_thread()) {
- return;
- }
-
qatomic_store_release(&bdrv_graph->reader_count,
bdrv_graph->reader_count - 1);
/* make sure writer sees reader_count before we check has_writer */
--
2.40.1
next prev parent reply other threads:[~2023-05-10 20:38 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-05-10 20:35 [PATCH 0/8] block: Honour graph read lock even in the main thread Kevin Wolf
2023-05-10 20:35 ` [PATCH 1/8] block: Call .bdrv_co_create(_opts) unlocked Kevin Wolf
2023-05-12 16:12 ` Eric Blake
2023-05-15 16:19 ` Kevin Wolf
2023-05-15 21:08 ` Eric Blake
2023-05-10 20:35 ` [PATCH 2/8] block/export: Fix null pointer dereference in error path Kevin Wolf
2023-05-12 15:31 ` Peter Maydell
2023-05-12 16:16 ` Eric Blake
2023-05-12 18:46 ` Eric Blake
2023-05-10 20:35 ` [PATCH 3/8] qcow2: Unlock the graph in qcow2_do_open() where necessary Kevin Wolf
2023-05-12 16:19 ` Eric Blake
2023-05-10 20:35 ` [PATCH 4/8] qemu-img: Take graph lock more selectively Kevin Wolf
2023-05-12 16:20 ` Eric Blake
2023-05-10 20:35 ` [PATCH 5/8] test-bdrv-drain: " Kevin Wolf
2023-05-12 16:26 ` Eric Blake
2023-05-10 20:35 ` [PATCH 6/8] test-bdrv-drain: Call bdrv_co_unref() in coroutine context Kevin Wolf
2023-05-12 16:27 ` Eric Blake
2023-05-10 20:36 ` [PATCH 7/8] blockjob: Adhere to rate limit even when reentered early Kevin Wolf
2023-05-12 16:35 ` Eric Blake
2023-05-10 20:36 ` Kevin Wolf [this message]
2023-05-12 16:37 ` [PATCH 8/8] graph-lock: Honour read locks even in the main thread Eric Blake
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=20230510203601.418015-9-kwolf@redhat.com \
--to=kwolf@redhat.com \
--cc=f.ebner@proxmox.com \
--cc=hreitz@redhat.com \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=stefanha@redhat.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).