From patchwork Fri Oct 7 16:57:40 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 77351 Delivered-To: patch@linaro.org Received: by 10.140.97.247 with SMTP id m110csp364205qge; Fri, 7 Oct 2016 10:22:57 -0700 (PDT) X-Received: by 10.55.136.133 with SMTP id k127mr19945213qkd.57.1475860977425; Fri, 07 Oct 2016 10:22:57 -0700 (PDT) Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id u37si3953089qte.19.2016.10.07.10.22.57 for (version=TLS1 cipher=AES128-SHA bits=128/128); Fri, 07 Oct 2016 10:22:57 -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; 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]:37456 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bsYrI-0006wE-Ub for patch@linaro.org; Fri, 07 Oct 2016 13:22:56 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34356) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bsYTi-00046y-MB for qemu-devel@nongnu.org; Fri, 07 Oct 2016 12:58:35 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bsYTh-00089L-Nj for qemu-devel@nongnu.org; Fri, 07 Oct 2016 12:58:34 -0400 Received: from mx1.redhat.com ([209.132.183.28]:39768) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bsYTh-000893-He for qemu-devel@nongnu.org; Fri, 07 Oct 2016 12:58:33 -0400 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E650A3B72D; Fri, 7 Oct 2016 16:58:32 +0000 (UTC) Received: from donizetti.redhat.com (ovpn-112-69.ams2.redhat.com [10.36.112.69]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u97Gw4ti022714; Fri, 7 Oct 2016 12:58:31 -0400 From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Fri, 7 Oct 2016 18:57:40 +0200 Message-Id: <1475859483-32234-17-git-send-email-pbonzini@redhat.com> In-Reply-To: <1475859483-32234-1-git-send-email-pbonzini@redhat.com> References: <1475859483-32234-1-git-send-email-pbonzini@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Fri, 07 Oct 2016 16:58:32 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 16/39] 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: =?UTF-8?q?Alex=20Benn=C3=A9e?= Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Alex Bennée 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 Message-Id: <20160930213106.20186-9-alex.bennee@linaro.org> Signed-off-by: Paolo Bonzini --- cpu-exec.c | 8 ++++---- qom/cpu.c | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) -- 2.7.4 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,