From patchwork Mon Sep 19 15:51:37 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: 76557 Delivered-To: patch@linaro.org Received: by 10.140.106.72 with SMTP id d66csp1030518qgf; Mon, 19 Sep 2016 08:55:28 -0700 (PDT) X-Received: by 10.55.54.15 with SMTP id d15mr29319250qka.262.1474300528838; Mon, 19 Sep 2016 08:55:28 -0700 (PDT) Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id x12si20313002qtb.66.2016.09.19.08.55.28 for (version=TLS1 cipher=AES128-SHA bits=128/128); Mon, 19 Sep 2016 08:55:28 -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]:56345 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bm0um-0006LH-Ay for patch@linaro.org; Mon, 19 Sep 2016 11:55:28 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52969) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bm0sR-0005AH-4Z for qemu-devel@nongnu.org; Mon, 19 Sep 2016 11:53:04 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bm0sN-0005AG-RR for qemu-devel@nongnu.org; Mon, 19 Sep 2016 11:53:03 -0400 Received: from mail-wm0-f45.google.com ([74.125.82.45]:36128) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bm0sN-0005A3-Ln for qemu-devel@nongnu.org; Mon, 19 Sep 2016 11:52:59 -0400 Received: by mail-wm0-f45.google.com with SMTP id w84so83470852wmg.1 for ; Mon, 19 Sep 2016 08:52:59 -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=FsQFnQweLCMJBMNE+/N29Evw7kMSj/Q4dCKWVfjR5hg=; b=hMnn6vey+FwO9cWRj681s6SdFIWkhTfbuSZHN4BlIv0c9ObIPjmNgj5KbM+aC9Ccb7 O4jPBxwXMcr27hJoCRx+n/d49E0zeAEawzcQ84Cwer5ljRb56gHTzz/md1y5L8mq6aS9 uzKZZ8Ipz23tCykJc6VGvEZWYI1CwXS/Y5n3Q= 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=FsQFnQweLCMJBMNE+/N29Evw7kMSj/Q4dCKWVfjR5hg=; b=cmMgMqvgmv6tNmRiFwPIWpXWDLPogC7dmxmmIYddtmCVYu8NMVTdvkcGjXg3fWQidI yxCE643cQXhTvm0V+qlzrGpCnyk3Fh2YmeUDJBYIbP1JI4wjMxn7Y5XBnin184H9SZgO 9Uzn8/jig8lRcLMtJKhxA6NZMk46dTqRVIHQpSydYgtV7ubMl5c5xhCgZb7mtaEu8Xy5 oIle2JuAygafmcJcuyCR7+xkjtAJTlJV5qOGdOiykCOxJWj1aOHTlqyfcDdguWQ0hw/v R5Qze0qHEOAcYcG2lR/KA57gbrvFTgMIDpzrTF5H00IT14kxGnP4/VCx/tm5cC/NTa5f MzrA== X-Gm-Message-State: AE9vXwMrITmALhAx90wJu34boRKlqaLtDkT6ScS1B9/7/uJLaOWTugfWEqkil0M8HoPaEteJ X-Received: by 10.28.87.212 with SMTP id l203mr9512254wmb.71.1474300318890; Mon, 19 Sep 2016 08:51:58 -0700 (PDT) Received: from zen.linaro.local ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id a1sm23741521wju.41.2016.09.19.08.51.55 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 19 Sep 2016 08:51:56 -0700 (PDT) Received: from zen.linaroharston (localhost [127.0.0.1]) by zen.linaro.local (Postfix) with ESMTP id AAD613E0646; Mon, 19 Sep 2016 16:51:53 +0100 (BST) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org, pbonzini@redhat.com, cota@braap.org, stefanha@redhat.com, kwolf@redhat.com Date: Mon, 19 Sep 2016 16:51:37 +0100 Message-Id: <20160919155139.28371-7-alex.bennee@linaro.org> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20160919155139.28371-1-alex.bennee@linaro.org> References: <20160919155139.28371-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] [fuzzy] X-Received-From: 74.125.82.45 Subject: [Qemu-devel] [RFC 6/8] 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, 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 now we just use the relaxed atomic_set/atomic_read semantics to reassure tsan that we can't tear the value. 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 9f4bd0b..113d8dc 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; } @@ -497,8 +497,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); } @@ -510,7 +510,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 2553247..47b1597 100644 --- a/qom/cpu.c +++ b/qom/cpu.c @@ -119,10 +119,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,