From patchwork Tue Jan 23 14:47:55 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Laurent Vivier X-Patchwork-Id: 864838 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3zQrm703Tjz9t3C for ; Wed, 24 Jan 2018 01:49:09 +1100 (AEDT) Received: from localhost ([::1]:33591 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1edzso-00076K-HT for incoming@patchwork.ozlabs.org; Tue, 23 Jan 2018 09:49:06 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43407) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1edzs1-00075Q-17 for qemu-devel@nongnu.org; Tue, 23 Jan 2018 09:48:18 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1edzrw-0002JX-QB for qemu-devel@nongnu.org; Tue, 23 Jan 2018 09:48:17 -0500 Received: from mout.kundenserver.de ([212.227.17.10]:49182) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1edzrw-0002IP-FU; Tue, 23 Jan 2018 09:48:12 -0500 Received: from localhost.localdomain ([78.238.229.36]) by mrelayeu.kundenserver.de (mreue102 [212.227.15.183]) with ESMTPSA (Nemesis) id 0MTQ1P-1eBdm90eRz-00SKIL; Tue, 23 Jan 2018 15:48:10 +0100 From: Laurent Vivier To: qemu-devel@nongnu.org Date: Tue, 23 Jan 2018 15:47:55 +0100 Message-Id: <20180123144807.5618-2-laurent@vivier.eu> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180123144807.5618-1-laurent@vivier.eu> References: <20180123144807.5618-1-laurent@vivier.eu> MIME-Version: 1.0 X-Provags-ID: V03:K0:wpCLzc9kLopZja2236XSDOZA9oiwgErHQNL9RNucOX1917WaDhN PBQEihMpH+WaXXhUkkqtmmEcBeS6ujkCkF2UREvwc5LEXmdsIx9ORTqmiWahJ4dCSXrrmiq ULj1+tUyFNFUoIWwHw06SBzZJLYAaa4dWN6TyVnxA9CZu5sKnbrbhu+yfypUS+g2JxOSM3J mM1vIVl3Ul2t4zCqPlgZA== X-UI-Out-Filterresults: notjunk:1; V01:K0:iJmDBE7uI6k=:57PvMpElEg6j/ECXYcRBLm rZn9y+9ICQ3xDUUlziSLNL+5ssDFNsgMirlmhO5wYVTc8Vd77/3Z22CLy+RgxTIRoU1bMJZ15 g4wFcfapBQ/QHAfa6cQ0DfAdD/UlURRocYmwQVyNIQOuYuY6SFYeeKNiloaNyCBg4UmIVXUlb BYfD8UOUiLgsUsx7K3M7Bq8plV34qYkE06ehiLH+VeCvpG8+HLzCy3PsSJb7a/7v4dwZJ1k8s mwNX0l6kGVWx4Me7QjxegGj3Uu7tpadEEfRr2fXjSF1buuZXxOARzEOljqKZKpmAzRPJsXz0/ F/VyFgaVe/qp1OdnyDaNzYgodGNxSCCJPT5ptwhL7zU9scPZ4HdmRcyAhXyP+3FwGIShOGCNL dv8iW923JiXY5Ih2rRJBeyFLFfB6Zi5qVVVaGYoDchNCZJ7dqJlzpHARDwXJa9k1nKRczAUxh v/z3nk7C8kcKLUcSE+kZzTYhUtyRpbkYQKmZnxZe4FczgR1Q+FouRR+fUrGVpU1z6olX6ZRBg p+RMX0Zbcm9Sls2kAto2dzUcsReGORR49Z37SuDF+w5CcohbP7SrOEyjAFAJcRUAIDDeeryZd FIYiN0wIwirHe1zyXncuSCLTUl9Dns7v5dTkSkpgEuphCkM82vkgxnzbjPg9SPQ6yAm/kKdE6 JWlusiBHxUGC3PErj206XlrueJPcrueIQMrynO7LXbmdRfn5ERt0oCgTurnDoqMdE1V9DYJCk knaeFupM7gXFR3ZTaSJHtRtSm41IgnPQp3D+sVHLxdRpjzVzgcOLhIVz3Ho= X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 212.227.17.10 Subject: [Qemu-devel] [PULL 01/13] linux-user: Fix locking order in fork_start() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , qemu-stable@nongnu.org, Laurent Vivier Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Peter Maydell 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 Cc: qemu-stable@nongnu.org Reviewed-by: Paolo Bonzini Reviewed-by: Alex Bennée Message-Id: <1512397331-15238-1-git-send-email-peter.maydell@linaro.org> Signed-off-by: Laurent Vivier --- 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 450eb3ce65..e8406917e3 100644 --- a/linux-user/main.c +++ b/linux-user/main.c @@ -127,9 +127,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); mmap_fork_start(); + qemu_mutex_lock(&tb_ctx.tb_lock); + cpu_list_lock(); } void fork_end(int child)