Skip to content

Commit a4e31f5

Browse files
geofftMichael Tokarev
authored andcommitted
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: [email protected] Signed-off-by: Geoffrey Thomas <[email protected]> Fixes: c093364 "fd-trans: Fix race condition on reallocation of the translation table." Resolves: https://gitlab.com/qemu-project/qemu/-/issues/2846 Buglink: astral-sh/uv#6105 Reviewed-by: Richard Henderson <[email protected]> Signed-off-by: Richard Henderson <[email protected]> Message-ID: <[email protected]> (cherry picked from commit e4e839b2eeea5745c48ce47144c7842eb7cd455f) Signed-off-by: Michael Tokarev <[email protected]>
1 parent 1759558 commit a4e31f5

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

linux-user/fd-trans.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,16 @@ static inline void fd_trans_init(void)
3636
qemu_mutex_init(&target_fd_trans_lock);
3737
}
3838

39+
static inline void fd_trans_prefork(void)
40+
{
41+
qemu_mutex_lock(&target_fd_trans_lock);
42+
}
43+
44+
static inline void fd_trans_postfork(void)
45+
{
46+
qemu_mutex_unlock(&target_fd_trans_lock);
47+
}
48+
3949
static inline TargetFdDataFunc fd_trans_target_to_host_data(int fd)
4050
{
4151
if (fd < 0) {

linux-user/main.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,12 +149,14 @@ void fork_start(void)
149149
cpu_list_lock();
150150
qemu_plugin_user_prefork_lock();
151151
gdbserver_fork_start();
152+
fd_trans_prefork();
152153
}
153154

154155
void fork_end(pid_t pid)
155156
{
156157
bool child = pid == 0;
157158

159+
fd_trans_postfork();
158160
qemu_plugin_user_postfork(child);
159161
mmap_fork_end(child);
160162
if (child) {

0 commit comments

Comments
 (0)