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: 125523 Delivered-To: patch@linaro.org Received: by 10.46.66.141 with SMTP id h13csp1801555ljf; Tue, 23 Jan 2018 06:51:18 -0800 (PST) X-Google-Smtp-Source: AH8x22710iKgF7gfFTo+hl/HEHSmgdQgR1/EL72CnCTH3BeUY4UX6eLxjRWJRuOION451TorUKWu X-Received: by 10.129.76.72 with SMTP id z69mr2706762ywa.255.1516719078562; Tue, 23 Jan 2018 06:51:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516719078; cv=none; d=google.com; s=arc-20160816; b=ut665d7Mn+J3P5qMJS4ePW8t8zcjtw460DDrFY9RmI2j/21bYuFZRe9032ioC+nlyf Yj0xt3c8yF9Ro+JbwaULxtG7d/ijKKDs5qrLcGtqIJGzs6+6Plfji6dsPpugjE23kPmn 6mApc0uPiH1cp+hiCvWRRHDu9dEpgCvNKtAk4+9YVdfn/g7YOSBm4+vN5MciQ/uNg7wu h+a0Sa/Ev8HqwxxFfioIJ/d92S06Esl1g0eX8pccvpoTLH0YIt1iVPX0s0VQ7m4QdgNl oSxMpaMGRtWLxeWQ+fssclkmBT8PFFJfp11eoBiSQBLuw3sN8qQFHbCfYDdnPRnlW9lQ 0TIg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:to:from:arc-authentication-results; bh=ZKDiuspwHa9P3QEP06oWBubBMnAOYkhSJye8ys9OjGI=; b=TdeBcY1Oo5S49OuyJ2jCdgh5ES9tI+dFEIvBPPeqIs+PrYYfGULqfnirT2vgiP4auT 1/5ENGugiOU6OSt7h+Tbr5UGYW1egWfELUr8q+VJzc/ynJ+lYQvJH9qK60jkV0IfGHDn TFeZP+U9PG4jGWerK2e1tdvFxp7oZ4ty7tblFxpGmGL93Xj1i2Ovin/gVDwGv/MTdY3s FrF8jVCzMISwxAS3VXbIYMBmPrbLva7MDEzvKOZ0iyk/6qfAIxaI27h5QYxtwCMfwne4 xVzxMLLc9K0kBzHWV5ZpDtBI1madgzfObtnBie/XkuEW0YCDBMkCf3+DeIds23CiMIs9 oeNw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id 203si2511672ybc.161.2018.01.23.06.51.18 for (version=TLS1 cipher=AES128-SHA bits=128/128); Tue, 23 Jan 2018 06:51:18 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Authentication-Results: mx.google.com; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org Received: from localhost ([::1]:33599 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1edzuw-0008Qn-06 for patch@linaro.org; Tue, 23 Jan 2018 09:51:18 -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+patch=linaro.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(-) -- 2.14.3 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)