From: Christian Schoenebeck <qemu_oss@crudebyte.com>
To: qemu-devel@nongnu.org, Peter Maydell <peter.maydell@linaro.org>
Cc: Greg Kurz <groug@kaod.org>
Subject: [PULL 1/9] 9pfs: fix concurrent v9fs_reclaim_fd() calls
Date: Mon, 05 May 2025 11:50:51 +0200 [thread overview]
Message-ID: <61da38db70affd925226ce1e8a61d761c20d045b.1746438650.git.qemu_oss@crudebyte.com> (raw)
In-Reply-To: <cover.1746438650.git.qemu_oss@crudebyte.com>
Even though this function is serialized to be always called from main
thread, v9fs_reclaim_fd() is dispatching the coroutine to a worker thread
in between via its v9fs_co_*() calls, hence leading to the situation where
v9fs_reclaim_fd() is effectively executed multiple times simultaniously,
which renders its LRU algorithm useless and causes high latency.
Fix this by adding a simple boolean variable to ensure this function is
only called once at a time. No synchronization needed for this boolean
variable as this function is only entered and returned on main thread.
Fixes: 7a46274529c ('hw/9pfs: Add file descriptor reclaim support')
Signed-off-by: Christian Schoenebeck <qemu_oss@crudebyte.com>
Reviewed-by: Greg Kurz <groug@kaod.org>
Message-Id: <5c622067efd66dd4ee5eca740dcf263f41db20b2.1741339452.git.qemu_oss@crudebyte.com>
---
hw/9pfs/9p.c | 10 ++++++++++
hw/9pfs/9p.h | 1 +
2 files changed, 11 insertions(+)
diff --git a/hw/9pfs/9p.c b/hw/9pfs/9p.c
index 7cad2bce62..4f9c2dde9c 100644
--- a/hw/9pfs/9p.c
+++ b/hw/9pfs/9p.c
@@ -435,6 +435,12 @@ void coroutine_fn v9fs_reclaim_fd(V9fsPDU *pdu)
GHashTableIter iter;
gpointer fid;
+ /* prevent multiple coroutines running this function simultaniously */
+ if (s->reclaiming) {
+ return;
+ }
+ s->reclaiming = true;
+
g_hash_table_iter_init(&iter, s->fids);
QSLIST_HEAD(, V9fsFidState) reclaim_list =
@@ -510,6 +516,8 @@ void coroutine_fn v9fs_reclaim_fd(V9fsPDU *pdu)
*/
put_fid(pdu, f);
}
+
+ s->reclaiming = false;
}
/*
@@ -4324,6 +4332,8 @@ int v9fs_device_realize_common(V9fsState *s, const V9fsTransport *t,
s->ctx.fst = &fse->fst;
fsdev_throttle_init(s->ctx.fst);
+ s->reclaiming = false;
+
rc = 0;
out:
if (rc) {
diff --git a/hw/9pfs/9p.h b/hw/9pfs/9p.h
index 5e041e1f60..259ad32ed1 100644
--- a/hw/9pfs/9p.h
+++ b/hw/9pfs/9p.h
@@ -362,6 +362,7 @@ struct V9fsState {
uint64_t qp_ndevices; /* Amount of entries in qpd_table. */
uint16_t qp_affix_next;
uint64_t qp_fullpath_next;
+ bool reclaiming;
};
/* 9p2000.L open flags */
--
2.30.2
next prev parent reply other threads:[~2025-05-05 9:54 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-05-05 9:50 [PULL 0/9] 9p queue 2025-05-05 Christian Schoenebeck
2025-05-05 9:50 ` [PULL 7/9] tests/9p: add 'Tsetattr' request to test client Christian Schoenebeck
2025-07-10 13:30 ` Peter Maydell
2025-07-10 14:11 ` Christian Schoenebeck
2025-07-10 14:17 ` Peter Maydell
2025-05-05 9:50 ` [PULL 2/9] 9pfs: fix FD leak and reduce latency of v9fs_reclaim_fd() Christian Schoenebeck
2025-05-05 9:50 ` [PULL 4/9] 9pfs: Don't use file descriptors in core code Christian Schoenebeck
2025-05-05 9:50 ` [PULL 5/9] 9pfs: Introduce ftruncate file op Christian Schoenebeck
2025-05-05 9:50 ` [PULL 9/9] 9pfs: fix 'total_open_fd' decrementation Christian Schoenebeck
2025-05-05 9:50 ` [PULL 6/9] 9pfs: Introduce futimens file op Christian Schoenebeck
2025-05-05 9:50 ` [PULL 8/9] tests/9p: Test `Tsetattr` can truncate unlinked file Christian Schoenebeck
2025-05-05 9:50 ` Christian Schoenebeck [this message]
2025-05-05 9:50 ` [PULL 3/9] 9pfs: local : Introduce local_fid_fd() helper Christian Schoenebeck
2025-05-06 13:58 ` [PULL 0/9] 9p queue 2025-05-05 Stefan Hajnoczi
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=61da38db70affd925226ce1e8a61d761c20d045b.1746438650.git.qemu_oss@crudebyte.com \
--to=qemu_oss@crudebyte.com \
--cc=groug@kaod.org \
--cc=peter.maydell@linaro.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 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).