[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 02/13] linux-user: wrap fork() in a start/end exclusi
From: |
Laurent Vivier |
Subject: |
[Qemu-devel] [PULL 02/13] linux-user: wrap fork() in a start/end exclusive section |
Date: |
Tue, 23 Jan 2018 15:47:56 +0100 |
From: Peter Maydell <address@hidden>
When we do a fork() in usermode emulation, we need to be in
a start/end exclusive section, so that we can ensure that no
other thread is in an RCU section. Otherwise you can get this
deadlock:
- fork thread: has mmap_lock, waits for rcu_sync_lock
(because rcu_init_lock() is registered as a pthread_atfork() hook)
- RCU thread: has rcu_sync_lock, waits for rcu_read_(un)lock
- another CPU thread: in RCU critical section, waits for mmap_lock
This can show up if you have a heavily multithreaded guest program
that does a fork().
Signed-off-by: Peter Maydell <address@hidden>
Reported-by: Stuart Monteith <address@hidden>
Message-Id: <address@hidden>
Signed-off-by: Laurent Vivier <address@hidden>
---
linux-user/main.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/linux-user/main.c b/linux-user/main.c
index e8406917e3..2140465709 100644
--- a/linux-user/main.c
+++ b/linux-user/main.c
@@ -127,6 +127,7 @@ int cpu_get_pic_interrupt(CPUX86State *env)
/* Make sure everything is in a consistent state for calling fork(). */
void fork_start(void)
{
+ start_exclusive();
mmap_fork_start();
qemu_mutex_lock(&tb_ctx.tb_lock);
cpu_list_lock();
@@ -147,9 +148,13 @@ void fork_end(int child)
qemu_mutex_init(&tb_ctx.tb_lock);
qemu_init_cpu_list();
gdbserver_fork(thread_cpu);
+ /* qemu_init_cpu_list() takes care of reinitializing the
+ * exclusive state, so we don't need to end_exclusive() here.
+ */
} else {
qemu_mutex_unlock(&tb_ctx.tb_lock);
cpu_list_unlock();
+ end_exclusive();
}
}
--
2.14.3
- [Qemu-devel] [PULL 01/13] linux-user: Fix locking order in fork_start(), (continued)
- [Qemu-devel] [PULL 01/13] linux-user: Fix locking order in fork_start(), Laurent Vivier, 2018/01/23
- [Qemu-devel] [PULL 05/13] linux-user: Translate flags argument to dup3 syscall, Laurent Vivier, 2018/01/23
- [Qemu-devel] [PULL 03/13] linux-user: Fix length calculations in host_to_target_cmsg(), Laurent Vivier, 2018/01/23
- [Qemu-devel] [PULL 08/13] linux-user: Add AT_SECURE auxval, Laurent Vivier, 2018/01/23
- [Qemu-devel] [PULL 09/13] linux-user: Add getcpu() support, Laurent Vivier, 2018/01/23
- [Qemu-devel] [PULL 10/13] linux-user: remove nmi.c and fw-path-provider.c, Laurent Vivier, 2018/01/23
- [Qemu-devel] [PULL 13/13] linux-user: implement renameat2, Laurent Vivier, 2018/01/23
- [Qemu-devel] [PULL 02/13] linux-user: wrap fork() in a start/end exclusive section,
Laurent Vivier <=
- [Qemu-devel] [PULL 04/13] linux-user: Don't use CMSG_ALIGN(sizeof struct cmsghdr), Laurent Vivier, 2018/01/23
- [Qemu-devel] [PULL 07/13] linux-user: Fix sched_get/setaffinity conversion, Laurent Vivier, 2018/01/23
- [Qemu-devel] [PULL 11/13] linux-user: Propagate siginfo_t through to handle_cpu_signal(), Laurent Vivier, 2018/01/23
- [Qemu-devel] [PULL 12/13] page_unprotect(): handle calls to pages that are PAGE_WRITE, Laurent Vivier, 2018/01/23
- [Qemu-devel] [PULL 06/13] linux-user/mmap.c: Avoid choosing NULL as start address, Laurent Vivier, 2018/01/23
- Re: [Qemu-devel] [PULL 00/13] Linux user for 2.12 patches, Peter Maydell, 2018/01/25