summary refs log tree commit diff stats
path: root/linux-user/fd-trans.h
diff options
context:
space:
mode:
authorGeoffrey Thomas <geofft@ldpreload.com>2025-03-14 08:47:42 -0400
committerRichard Henderson <richard.henderson@linaro.org>2025-07-10 13:49:03 -0600
commite4e839b2eeea5745c48ce47144c7842eb7cd455f (patch)
tree625dcbd28f8e2d2bd4d6e657069f0386be9fbdad /linux-user/fd-trans.h
parent91748d50c7ef4addcc9302160a4b8b3c63d5d024 (diff)
downloadfocaccia-qemu-e4e839b2eeea5745c48ce47144c7842eb7cd455f.tar.gz
focaccia-qemu-e4e839b2eeea5745c48ce47144c7842eb7cd455f.zip
linux-user: Hold the fd-trans lock across fork
If another thread is holding target_fd_trans_lock during a fork,
then the lock becomes permanently locked in the child and the
emulator deadlocks at the next interaction with the fd-trans table.
As with other locks, acquire the lock in fork_start() and release
it in fork_end().

Cc: qemu-stable@nongnu.org
Signed-off-by: Geoffrey Thomas <geofft@ldpreload.com>
Fixes: c093364f4d91 "fd-trans: Fix race condition on reallocation of the translation table."
Resolves: https://gitlab.com/qemu-project/qemu/-/issues/2846
Buglink: https://github.com/astral-sh/uv/issues/6105
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
Message-ID: <20250314124742.4965-1-geofft@ldpreload.com>
Diffstat (limited to 'linux-user/fd-trans.h')
-rw-r--r--linux-user/fd-trans.h10
1 files changed, 10 insertions, 0 deletions
diff --git a/linux-user/fd-trans.h b/linux-user/fd-trans.h
index 910faaf237..e14f96059c 100644
--- a/linux-user/fd-trans.h
+++ b/linux-user/fd-trans.h
@@ -36,6 +36,16 @@ static inline void fd_trans_init(void)
     qemu_mutex_init(&target_fd_trans_lock);
 }
 
+static inline void fd_trans_prefork(void)
+{
+    qemu_mutex_lock(&target_fd_trans_lock);
+}
+
+static inline void fd_trans_postfork(void)
+{
+    qemu_mutex_unlock(&target_fd_trans_lock);
+}
+
 static inline TargetFdDataFunc fd_trans_target_to_host_data(int fd)
 {
     if (fd < 0) {