From patchwork Fri Sep 30 21:31:01 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 77180 Delivered-To: patch@linaro.org Received: by 10.140.106.72 with SMTP id d66csp513120qgf; Fri, 30 Sep 2016 14:34:08 -0700 (PDT) X-Received: by 10.200.42.130 with SMTP id b2mr9128348qta.106.1475271248268; Fri, 30 Sep 2016 14:34:08 -0700 (PDT) Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id o188si13416805qke.147.2016.09.30.14.34.08 for (version=TLS1 cipher=AES128-SHA bits=128/128); Fri, 30 Sep 2016 14:34:08 -0700 (PDT) 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; dkim=fail header.i=@linaro.org; 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 dis=NONE) header.from=linaro.org Received: from localhost ([::1]:47033 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bq5RX-0008BI-PA for patch@linaro.org; Fri, 30 Sep 2016 17:34:07 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49716) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bq5Ox-0006TA-Ia for qemu-devel@nongnu.org; Fri, 30 Sep 2016 17:31:28 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bq5Ow-0006Z8-Kl for qemu-devel@nongnu.org; Fri, 30 Sep 2016 17:31:27 -0400 Received: from mail-wm0-x22a.google.com ([2a00:1450:400c:c09::22a]:37305) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bq5Ow-0006Yj-Da for qemu-devel@nongnu.org; Fri, 30 Sep 2016 17:31:26 -0400 Received: by mail-wm0-x22a.google.com with SMTP id b80so66257761wme.0 for ; Fri, 30 Sep 2016 14:31:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=7arOCA7/GqiG6IUvlchgJaciEceJQ2KSG0e5CPUeZZ8=; b=Gh1OW7p12+TIHa7IdYeJdGTIbnxEoSLntZYEfSdmirGklTkOCcLQkNgRVA+wzTjR+p O3iNarqHoVHX720tyAQ735XkX1TLG3tGS2YDfTC1M0Sm+POtAZaLS7ZMrrT6tsbUye0f TvoX+H94uUDdSDZ7MpD3kQDdVvSHjMqf/tPl0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=7arOCA7/GqiG6IUvlchgJaciEceJQ2KSG0e5CPUeZZ8=; b=g607P/qQwNUtjzMHE036BS3aJvtxSGGAitSXDJkxmRnNiPlO/90VmZpurAqfmloj3s IoWT4gd2MnhTna04puSfXaPi9zdgtiwbepXfzZNWSyJ29KOM+Mx7xI9qOGQ2nRuXP6tI ge/WC4Lg6/+RF1iihCRUjnFjLxqjNqJv4rXIrpTc0rRhgJgydNjEF2YZ98zblNzLj8a0 /Z/zkbyC5HmjY5jbCWlymtuvGl6NVzpvXm+HcwTR8Ic/rYr+RWV17uJ3f/o4QyB8ldAf d+wMD3Cuv7n72LEKDtZLYL5By08W5N5GHn7hAhTSAWTVwKWIvx1fAOhI2gkp23CE2Le3 6RYw== X-Gm-Message-State: AA6/9Rn/Q7dYyoougqZPd2fsmZD5Jo/+DYgN5cbzgJWZB+bhI4dBbGn2R9xLjn1MnpjX/EAz X-Received: by 10.194.102.165 with SMTP id fp5mr2162849wjb.134.1475271085688; Fri, 30 Sep 2016 14:31:25 -0700 (PDT) Received: from zen.linaro.local ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id i11sm5994594wma.21.2016.09.30.14.31.20 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 30 Sep 2016 14:31:23 -0700 (PDT) Received: from zen.linaroharston (localhost [127.0.0.1]) by zen.linaro.local (Postfix) with ESMTP id 2E93D3E04AE; Fri, 30 Sep 2016 22:31:18 +0100 (BST) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org, pbonzini@redhat.com Date: Fri, 30 Sep 2016 22:31:01 +0100 Message-Id: <20160930213106.20186-11-alex.bennee@linaro.org> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20160930213106.20186-1-alex.bennee@linaro.org> References: <20160930213106.20186-1-alex.bennee@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2a00:1450:400c:c09::22a Subject: [Qemu-devel] [PATCH v3 10/15] linux-user/syscall: extend lock around cpu-list 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: mttcg@listserver.greensocs.com, peter.maydell@linaro.org, claudio.fontana@huawei.com, nikunj@linux.vnet.ibm.com, jan.kiszka@siemens.com, Riku Voipio , mark.burton@greensocs.com, a.rigo@virtualopensystems.com, cota@braap.org, serge.fdrv@gmail.com, bobby.prani@gmail.com, rth@twiddle.net, =?UTF-8?q?Alex=20Benn=C3=A9e?= , fred.konrad@greensocs.com Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" There is a potential race if several threads exit at once. To serialise the exits extend the lock above the initial checking of the CPU list. Signed-off-by: Alex Bennée --- linux-user/syscall.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) -- 2.9.3 diff --git a/linux-user/syscall.c b/linux-user/syscall.c index 0815f30..fa559be 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -7476,13 +7476,16 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1, break; } + cpu_list_lock(); + if (CPU_NEXT(first_cpu)) { TaskState *ts; - cpu_list_lock(); /* Remove the CPU from the list. */ QTAILQ_REMOVE(&cpus, cpu, node); + cpu_list_unlock(); + ts = cpu->opaque; if (ts->child_tidptr) { put_user_u32(0, ts->child_tidptr); @@ -7495,6 +7498,8 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1, rcu_unregister_thread(); pthread_exit(NULL); } + + cpu_list_unlock(); #ifdef TARGET_GPROF _mcleanup(); #endif