From patchwork Fri Sep 30 21:30:59 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: 77182 Delivered-To: patch@linaro.org Received: by 10.140.106.72 with SMTP id d66csp514692qgf; Fri, 30 Sep 2016 14:38:24 -0700 (PDT) X-Received: by 10.200.43.169 with SMTP id m38mr9152984qtm.31.1475271504193; Fri, 30 Sep 2016 14:38:24 -0700 (PDT) Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id k41si13480287qta.5.2016.09.30.14.38.24 for (version=TLS1 cipher=AES128-SHA bits=128/128); Fri, 30 Sep 2016 14:38:24 -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]:47057 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bq5Vf-0003KK-Na for patch@linaro.org; Fri, 30 Sep 2016 17:38:23 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49696) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bq5Ow-0006SZ-I9 for qemu-devel@nongnu.org; Fri, 30 Sep 2016 17:31:27 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bq5Ov-0006YD-7i for qemu-devel@nongnu.org; Fri, 30 Sep 2016 17:31:26 -0400 Received: from mail-wm0-x22d.google.com ([2a00:1450:400c:c09::22d]:37296) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bq5Ov-0006Xm-1v for qemu-devel@nongnu.org; Fri, 30 Sep 2016 17:31:25 -0400 Received: by mail-wm0-x22d.google.com with SMTP id b80so66257065wme.0 for ; Fri, 30 Sep 2016 14:31:24 -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=S+/uB7CUxnut9O7Osslsule6s+bgHs3r7Lc2cJFDK7c=; b=e5Cpt4AuKek38+wRw6GZYUuzrpp2om8WdiKjIpSIUyUc6jGgx1mro48Q1MoxdYFbAR EyCzOrS/emwi1nRQPdGO2Dcf+dGltparK8JfzoN0zZOWGUwZx13040wk5jxJKREmVV8a TEKcWniIzEkNrc5i+AGxuha42SYpsbhfnGLpE= 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=S+/uB7CUxnut9O7Osslsule6s+bgHs3r7Lc2cJFDK7c=; b=inA9Fpocol6pg/yv50IQQS5hRV4+Ge0WyLl6f/BlJh/SlWIOZVkt1K8WlpG5naW1Bd pp4/XqlDIiFyUQEvy74RKWGbbblw+SUHSjdX38X9GSnh9mk9bPWI6nLJfLvBWnX4Xk/9 SYKgzBtiqAS/1FsadJlcctTgSQMHMmE9cuyEk2GfRxS6xeW6CltMB+MEDwhXLM6wicgq DUAypTAPQAgF4qSnbjXI1gShE6O5el4orYwX8rmb5Z3N7wH7G99lsVE4JJ40EbFQxn5a rU5P+ceagACZK1UFpRgVSswZhYOeai3KkDexJg0l4fHK7r1EtjdQlsOV/Pgavs8MOEHt NihA== X-Gm-Message-State: AA6/9Rm6NNYqqzinprLwroyr/b74KqianXSiLgcMTpv9mZMyDbwLMSv9h0iPuGGjKccsP3qV X-Received: by 10.28.184.199 with SMTP id i190mr5432760wmf.43.1475271084386; Fri, 30 Sep 2016 14:31:24 -0700 (PDT) Received: from zen.linaro.local ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id y4sm6003699wmy.22.2016.09.30.14.31.19 (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 0C3193E043F; 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:30:59 +0100 Message-Id: <20160930213106.20186-9-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::22d Subject: [Qemu-devel] [PATCH v3 08/15] cpu: atomically modify cpu->exit_request 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, Peter Crosthwaite , jan.kiszka@siemens.com, 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" ThreadSanitizer picks up potential races although we already use barriers to ensure things are in the correct order when processing exit requests. For true C11 defined behaviour across threads we need to use relaxed atomic_set/atomic_read semantics to reassure tsan. Signed-off-by: Alex Bennée --- cpu-exec.c | 8 ++++---- qom/cpu.c | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) -- 2.9.3 diff --git a/cpu-exec.c b/cpu-exec.c index 8823d23..e114fcd 100644 --- a/cpu-exec.c +++ b/cpu-exec.c @@ -192,7 +192,7 @@ static inline tcg_target_ulong cpu_tb_exec(CPUState *cpu, TranslationBlock *itb) /* We were asked to stop executing TBs (probably a pending * interrupt. We've now stopped, so clear the flag. */ - cpu->tcg_exit_req = 0; + atomic_set(&cpu->tcg_exit_req, 0); } return ret; } @@ -490,8 +490,8 @@ static inline void cpu_handle_interrupt(CPUState *cpu, *last_tb = NULL; } } - if (unlikely(cpu->exit_request || replay_has_interrupt())) { - cpu->exit_request = 0; + if (unlikely(atomic_read(&cpu->exit_request) || replay_has_interrupt())) { + atomic_set(&cpu->exit_request, 0); cpu->exception_index = EXCP_INTERRUPT; cpu_loop_exit(cpu); } @@ -503,7 +503,7 @@ static inline void cpu_loop_exec_tb(CPUState *cpu, TranslationBlock *tb, { uintptr_t ret; - if (unlikely(cpu->exit_request)) { + if (unlikely(atomic_read(&cpu->exit_request))) { return; } diff --git a/qom/cpu.c b/qom/cpu.c index ef905da..e765bc0 100644 --- a/qom/cpu.c +++ b/qom/cpu.c @@ -120,10 +120,10 @@ void cpu_reset_interrupt(CPUState *cpu, int mask) void cpu_exit(CPUState *cpu) { - cpu->exit_request = 1; + atomic_set(&cpu->exit_request, 1); /* Ensure cpu_exec will see the exit request after TCG has exited. */ smp_wmb(); - cpu->tcg_exit_req = 1; + atomic_set(&cpu->tcg_exit_req, 1); } int cpu_write_elf32_qemunote(WriteCoreDumpFunction f, CPUState *cpu,