[qemu-xen master] linux-user: Fix locking order in fork_start()

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

[qemu-xen master] linux-user: Fix locking order in fork_start()

commit 9327a8e2d639370960c1dc3e11ff5d9c2b26174c
Author:     Peter Maydell <[hidden email]>
AuthorDate: Mon Dec 4 14:22:11 2017 +0000
Commit:     Michael Roth <[hidden email]>
CommitDate: Mon Jan 29 08:27:35 2018 -0600

    linux-user: Fix locking order in fork_start()
    Our locking order is that the tb lock should be taken
    inside the mmap_lock, but fork_start() grabs locks the
    other way around. This means that if a heavily multithreaded
    guest process (such as Java) calls fork() it can deadlock,
    with the thread that called fork() stuck in fork_start()
    with the tb lock and waiting for the mmap lock, but some
    other thread in tb_find() with the mmap lock and waiting
    for the tb lock. The cpu_list_lock() should also always be
    taken last, not first.
    Fix this by making fork_start() grab the locks in the
    right order. The order in which we drop locks doesn't
    matter, so we leave fork_end() the way it is.
    Signed-off-by: Peter Maydell <[hidden email]>
    Cc: [hidden email]
    Reviewed-by: Paolo Bonzini <[hidden email]>
    Reviewed-by: Alex Bennée <[hidden email]>
    Message-Id: <[hidden email]>
    Signed-off-by: Laurent Vivier <[hidden email]>
    (cherry picked from commit 024949caf32805f4cc3e7d363a80084b47aac1f6)
    Signed-off-by: Michael Roth <[hidden email]>
 linux-user/main.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/linux-user/main.c b/linux-user/main.c
index 6286661..146ee3e 100644
--- a/linux-user/main.c
+++ b/linux-user/main.c
@@ -128,9 +128,9 @@ int cpu_get_pic_interrupt(CPUX86State *env)
 /* Make sure everything is in a consistent state for calling fork().  */
 void fork_start(void)
-    cpu_list_lock();
-    qemu_mutex_lock(&tb_ctx.tb_lock);
+    qemu_mutex_lock(&tb_ctx.tb_lock);
+    cpu_list_lock();
 void fork_end(int child)
generated by git-patchbot for /home/xen/git/qemu-xen.git#master

Xen-changelog mailing list
[hidden email]