From patchwork Tue Feb 6 19:14:47 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Michael Roth X-Patchwork-Id: 127086 Delivered-To: patch@linaro.org Received: by 10.46.124.24 with SMTP id x24csp3211166ljc; Tue, 6 Feb 2018 11:27:37 -0800 (PST) X-Google-Smtp-Source: AH8x2279NsqTPOiJGpJTnHuLLOg3+up+jyrhw2zvq9M0VcKRBa7TT/PMFexe6jia0AQ/e69TsHE5 X-Received: by 10.129.93.139 with SMTP id r133mr2288546ywb.422.1517945257193; Tue, 06 Feb 2018 11:27:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1517945257; cv=none; d=google.com; s=arc-20160816; b=VDa7Xnzjz4AyQwgCF36Qqe794M7FXCCfxwmVaoqAGkjTrx1J5T+sIiqAGrj1e8jeXJ p+/p2Wkd8LZFmyr0amab45f7RkXnjBisi4Hxt1PwurqpQ4QM5LQrUAijFs37iDMOTlSR KTD9e2MgaVogmczXoXG/u6LauCFEK3R/JvtIrRI+QUttheNMng9k0x5b8ps3tIlEBjef aPJ4Vou/+lPsE2uNHBNszNnuc1Mnkz60pLq7M6UuB7ECbdP8CRGw5eY7dmFBslWIACkj FJk36izCtqzTwJyh0LCVzzvmi0SGSjPi/ayQS6mAwllEgYoFeNzQE743IAUYV7379CNL XLGg== 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:message-id:mime-version:references :in-reply-to:date:to:from:arc-authentication-results; bh=9HM2mPDzhMEYjyQjnstE2IOmudbuV7imB29JjnM9NUw=; b=qFYwArwAuiq+b1+4idf5XQ/sjck/XWTC+4K/uTRfoqLxHGLPB+k4r+B4QwMZQLNvc/ 4gIWp1WwTiV0COEiwwt2p4M+47LMVPeNd9/c8MTVRxeXoXHkPZseqUAPU0vkaLjCq4o+ lxw13S9efhPwPCrp3Ny+WOjSh96HEitip1BlGo1vYE9b4UT9MakfdTAxYTaq7BKzjIBt enN4qo2eb2heD+gx0sQM9FInDI1kEpZBm745txYIUxNsBuITwd77CPHPQvCWW1kBg28b tCEQWwjDZclOdHYgeYGTcv449v2K2qpRX6P1HH7D/qfh8P4AvDc0DHDW7/GfQyZmkNu7 tLaQ== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id f14si1944613ybk.825.2018.02.06.11.27.37 for (version=TLS1 cipher=AES128-SHA bits=128/128); Tue, 06 Feb 2018 11:27:37 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Received: from localhost ([::1]:53399 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ej8u0-0007NG-Iw for patch@linaro.org; Tue, 06 Feb 2018 14:27:36 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43885) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ej8ii-0005Eo-AP for qemu-devel@nongnu.org; Tue, 06 Feb 2018 14:16:00 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ej8if-0007xb-Ks for qemu-devel@nongnu.org; Tue, 06 Feb 2018 14:15:56 -0500 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:60746 helo=mx0a-001b2d01.pphosted.com) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ej8if-0007x0-F6 for qemu-devel@nongnu.org; Tue, 06 Feb 2018 14:15:53 -0500 Received: from pps.filterd (m0098414.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w16JEJcV056297 for ; Tue, 6 Feb 2018 14:15:53 -0500 Received: from e15.ny.us.ibm.com (e15.ny.us.ibm.com [129.33.205.205]) by mx0b-001b2d01.pphosted.com with ESMTP id 2fygjbwcmx-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Tue, 06 Feb 2018 14:15:52 -0500 Received: from localhost by e15.ny.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 6 Feb 2018 14:15:52 -0500 Received: from b01cxnp22033.gho.pok.ibm.com (9.57.198.23) by e15.ny.us.ibm.com (146.89.104.202) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Tue, 6 Feb 2018 14:15:49 -0500 Received: from b01ledav006.gho.pok.ibm.com (b01ledav006.gho.pok.ibm.com [9.57.199.111]) by b01cxnp22033.gho.pok.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id w16JFnGC40960148; Tue, 6 Feb 2018 19:15:49 GMT Received: from b01ledav006.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id D9027AC041; Tue, 6 Feb 2018 14:17:09 -0500 (EST) Received: from localhost (unknown [9.80.97.150]) by b01ledav006.gho.pok.ibm.com (Postfix) with ESMTP id 98880AC03F; Tue, 6 Feb 2018 14:17:09 -0500 (EST) From: Michael Roth To: qemu-devel@nongnu.org Date: Tue, 6 Feb 2018 13:14:47 -0600 X-Mailer: git-send-email 2.11.0 In-Reply-To: <20180206191515.25830-1-mdroth@linux.vnet.ibm.com> References: <20180206191515.25830-1-mdroth@linux.vnet.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 x-cbid: 18020619-0036-0000-0000-000002BA0AC7 X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00008485; HX=3.00000241; KW=3.00000007; PH=3.00000004; SC=3.00000248; SDB=6.00985885; UDB=6.00500282; IPR=6.00765253; BA=6.00005813; NDR=6.00000001; ZLA=6.00000005; ZF=6.00000009; ZB=6.00000000; ZP=6.00000000; ZH=6.00000000; ZU=6.00000002; MB=3.00019407; XFM=3.00000015; UTC=2018-02-06 19:15:51 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 18020619-0037-0000-0000-0000433F814A Message-Id: <20180206191515.25830-27-mdroth@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2018-02-06_09:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=1 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 impostorscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1709140000 definitions=main-1802060241 X-MIME-Autoconverted: from 8bit to quoted-printable by mx0b-001b2d01.pphosted.com id w16JEJcV056297 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] [fuzzy] X-Received-From: 148.163.158.5 Subject: [Qemu-devel] [PATCH 26/54] 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, christian.ehrhardt@canonical.com, 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 (cherry picked from commit 024949caf32805f4cc3e7d363a80084b47aac1f6) Signed-off-by: Michael Roth --- linux-user/main.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) -- 2.11.0 diff --git a/linux-user/main.c b/linux-user/main.c index 6286661bd3..146ee3e4ba 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); mmap_fork_start(); + qemu_mutex_lock(&tb_ctx.tb_lock); + cpu_list_lock(); } void fork_end(int child)