From patchwork Tue Jan 23 14:47:56 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Vivier X-Patchwork-Id: 125524 Delivered-To: patch@linaro.org Received: by 10.46.66.141 with SMTP id h13csp1801798ljf; Tue, 23 Jan 2018 06:51:52 -0800 (PST) X-Google-Smtp-Source: AH8x226tk19TLaC/Zkfo1odQId8udjyheg1BkMxwGYvlJxCJ6/+5jb90EM8+zgXRSkDX2lieRWbG X-Received: by 10.37.186.72 with SMTP id z8mr2604882ybj.33.1516719112625; Tue, 23 Jan 2018 06:51:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516719112; cv=none; d=google.com; s=arc-20160816; b=huLQiivHhR/g3sWt2A3yH2mQExIztCJbxpSyRMaxwesC4FWz3e6k6H/gqMjvtLeWk9 kfSI3icr7QGkHN4d/VpjLMuHoqcFs0fCmNZSw2K4D5jvbN4B3W6jP7qoYAKhMDsHmMJf LiR9QHteWqAGUTFT43skSClZYhivBiw+1ngxOchOw/4h+h+Uo6vh3XbZdO8OquF0SSqr 5IQyphM/eY8g1aw5j3Bcac3peO58tdAj8wrkdR8R1L1z0VYu2fX9P9R8OcfH5+U4hI0Q gDo6nW/dlr/a3mCJ196EWeIqRtsRGeR/9lYuTkiCxgfx5d6Fsf1GuU6NL3V83Nwhdmwh 34LQ== 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:references:in-reply-to :message-id:date:to:from:arc-authentication-results; bh=M1dFrUV9+hwf+jEX7Drr6mwEeAnbaiKoScVdDOeNGHQ=; b=b3Oy7EUsi9w129wh8X8flFEDOa4G9JgOlmVPDbqhpHMU0XB5vV8t8ffo3TEApRMROq KG/+U3wPSDzPMSak4fYH0bIbuj0dtYXGE2Ns0CHv246JkMq2xmETnSEKrU8PBGMdy26m ZCwvSFl7YruxWgi704jgVNH6QHjPFyv01uGN7OhOGoh2sliTYtrRvZwSxoMzm0X158DN Iyig0Q9Zw7Uz3w49n8o1KnJ06jhMV9NCEklcBjIqZBuNAnLXhmAAWFEhxqM3WfULid/T JVeBgsyUlD1okwM+wdLl8Tum6M3tG+grywmNm97zibZBaScGtOtPgQ+Xs0GODonxmxrJ nuoA== 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 i4si2447336ybb.503.2018.01.23.06.51.52 for (version=TLS1 cipher=AES128-SHA bits=128/128); Tue, 23 Jan 2018 06:51:52 -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]:33615 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1edzvT-0001S1-VT for patch@linaro.org; Tue, 23 Jan 2018 09:51:52 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43409) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1edzs1-00075R-4U for qemu-devel@nongnu.org; Tue, 23 Jan 2018 09:48:23 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1edzrw-0002Jr-VL for qemu-devel@nongnu.org; Tue, 23 Jan 2018 09:48:17 -0500 Received: from mout.kundenserver.de ([217.72.192.73]:53116) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1edzrw-0002IY-LT for qemu-devel@nongnu.org; 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 0MHYCK-1ef5nS2WRI-003PY2; Tue, 23 Jan 2018 15:48:10 +0100 From: Laurent Vivier To: qemu-devel@nongnu.org Date: Tue, 23 Jan 2018 15:47:56 +0100 Message-Id: <20180123144807.5618-3-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> X-Provags-ID: V03:K0:Hz2/MRvBgvoNyWuDIH5Xyajag+PMslGb0SGwzc1G8jcCnYDJZgq e6aox1QvGtxaak3TB4gQwm/nUM+EE2IxaqLAr0xXN75pyKspJXmq9i98CTz8yOJsfPWOAxT 5bYDEm2fObX7g7ysJ1C4IFDz2rphsC9WP0HcsDsnUs3HyUsQt0kGTbryR+qBqFJ7yF9vRub Y/p63Yu3GCJslwF1D0FwA== X-UI-Out-Filterresults: notjunk:1; V01:K0:DsM+9peBhFc=:VjfyhFiya1Hn/REWjKHe8a tKYSF2V83oDfEF0Fj73gKjriZcgqDv6fpVHnqpmc8AF6Vp4H3xTN/xsflGuZCjFCoPUWRRAOF VccZO7KVPL7FmB3ZjwS7TjFSMu0skJ/cNT3TpiptIdIfnJzFAv3Oe10ixGnF0Uyu5qoCWeiPp oVxb6VjnMkeiW+IEmXHb/B091rUJFllaaO4wx57mrJ+NyFlWuFc58rgFuYPmZIexBSqGpOWTr Tii4hTDa/a/T9hKgiigrezFITI8NnRWRaxQ6xykKbAhN7TOCKK/5DRwrldhu0w4qUWXLuxVGN nDp8FL7vc9fxAer+kvgh7FBmDyhU/eOwCLgFFA3COyH4VBnHYSAED1MwHWlX6S2PSbKpPQ6E+ Gch+2xpmx6eYxQWT3dK7ptqRP566XCw/tD9BcHsLARb81n/E4NZPOnOqzJpm2AEMIlQ4VlYlj DpyfOY74H6ynbyAGyAU4S9vGqI6FJozzlFxuHAGlHIGZS8Sw2ggHuPhVDsNcnvMUNnN3o8+SM +CSlsLmVZsROjtIM4Rl+qrq3XCd6V99pppsStw29Wiw0jID4Zmk9W8cKX0RKMoOQ5PEu9zi/i Il9O7VxszRJsXxttKBdtLeYWsds8WSsepe6WVp2wM5qptAdHyJ+G/uQw6Xo+NCK5FRGA1dyeL y87PKUJ860zrEY1ID2/qW17P3o6K8IkCzKwC7UqoSjBeNKwMgoEGvsOEjODxfYoGhkubi0CRH CPBjdtHA/ArrORfV0sjcg7OiqtPRIqhBjIlGAg== X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 217.72.192.73 Subject: [Qemu-devel] [PULL 02/13] linux-user: wrap fork() in a start/end exclusive section 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 , Laurent Vivier Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Peter Maydell 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 Reported-by: Stuart Monteith Message-Id: <1512650481-1723-1-git-send-email-peter.maydell@linaro.org> Signed-off-by: Laurent Vivier --- linux-user/main.c | 5 +++++ 1 file changed, 5 insertions(+) -- 2.14.3 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(); } }