From patchwork Fri Sep 30 21:31:04 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: 77190 Delivered-To: patch@linaro.org Received: by 10.140.106.72 with SMTP id d66csp518980qgf; Fri, 30 Sep 2016 14:50:17 -0700 (PDT) X-Received: by 10.55.23.90 with SMTP id i87mr9145785qkh.226.1475272217541; Fri, 30 Sep 2016 14:50:17 -0700 (PDT) Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id d133si13462180qkg.226.2016.09.30.14.50.17 for (version=TLS1 cipher=AES128-SHA bits=128/128); Fri, 30 Sep 2016 14:50:17 -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]:47132 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bq5hB-0006UR-5C for patch@linaro.org; Fri, 30 Sep 2016 17:50:17 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49784) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bq5P3-0006Zv-EV for qemu-devel@nongnu.org; Fri, 30 Sep 2016 17:31:36 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bq5Oz-0006ab-7o for qemu-devel@nongnu.org; Fri, 30 Sep 2016 17:31:32 -0400 Received: from mail-wm0-x233.google.com ([2a00:1450:400c:c09::233]:36230) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bq5Oz-0006aR-1x for qemu-devel@nongnu.org; Fri, 30 Sep 2016 17:31:29 -0400 Received: by mail-wm0-x233.google.com with SMTP id k125so48664003wma.1 for ; Fri, 30 Sep 2016 14:31:28 -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=+StYBd8lAUEPsoZtSHA9BL9MMapBK8mBNRTm/kwYMbU=; b=OLNc0RPLV86DXq1SwcL0XFcpdRstGItuno81IifBbemWtUxPwVZbm5qRoSDtYSvNau d42jCGxlZMmT6h65rmRUgkhe13P7QO94NYP7XRUmGog4AsNZvNhtEidZwuHKvgh9i35e iyvBlgtIweg3uLUFVCagdRky+zxVjhgPM/pTY= 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=+StYBd8lAUEPsoZtSHA9BL9MMapBK8mBNRTm/kwYMbU=; b=Dm++i1tm0FWuImXoA2GU1TCnMPIXBTxggly8VTNqTkulpnetH9Ir62Tugo7OEO+GOK 7hz5pbPGfCCETt+0bNxqBy43YH8rDWe4IAwiw7SLsdEXPjld3oy7p9sswtoKAWqDjUY+ lbQgWFpLsupTzqMPDJiSjCmkzWYIAtQyENRaogvF4pro+is1YGkc3cduMiSW5SyWLmjr RBTcS26oNyWlCItR0ZkqWW70KY1I1YgJgrqhE7cRuXmQ9vedQyhSiWy17/R6WvY7utFN SMnAmPDnyA0PpKHrM9HnXevdBdG6+OpaQASVAIULn/J5evnzdc1nIgjBz5pNjzBd1gIb Ofeg== X-Gm-Message-State: AA6/9Rmw0uoX3UcfatummHOLOwTg/IOFdeitwiUwQy5ZFd5nmRZ68xsJ4qwRlEMsgIlYVZSD X-Received: by 10.28.31.76 with SMTP id f73mr5433592wmf.90.1475271088418; Fri, 30 Sep 2016 14:31:28 -0700 (PDT) Received: from zen.linaro.local ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id o196sm5103213wmg.8.2016.09.30.14.31.21 (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 634AC3E055D; 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:04 +0100 Message-Id: <20160930213106.20186-14-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::233 Subject: [Qemu-devel] [PATCH v3 13/15] tcg: ensure cpu_tb_exec/tb_gen_code use atomic_read/write 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" To meet C11 semantics for shared data access we need to use relaxed atomic accesses. While the completion of data writes w.r.t reads is ensured by QHT's explicit barriers when a newly generated TB is inserted ThreadSanitizer will still complain. By using the relaxed accesses the same code gets generated but instrumentation does not have to worry about a potentially undefined interaction between plain loads/stores. Signed-off-by: Alex Bennée --- cpu-exec.c | 6 +++--- translate-all.c | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) -- 2.9.3 diff --git a/cpu-exec.c b/cpu-exec.c index e114fcd..99c906b 100644 --- a/cpu-exec.c +++ b/cpu-exec.c @@ -140,7 +140,7 @@ static inline tcg_target_ulong cpu_tb_exec(CPUState *cpu, TranslationBlock *itb) uintptr_t ret; TranslationBlock *last_tb; int tb_exit; - uint8_t *tb_ptr = itb->tc_ptr; + uint8_t *tb_ptr = atomic_read(&itb->tc_ptr); qemu_log_mask_and_addr(CPU_LOG_EXEC, itb->pc, "Trace %p [" TARGET_FMT_lx "] %s\n", @@ -291,8 +291,8 @@ static inline TranslationBlock *tb_find(CPUState *cpu, is executed. */ cpu_get_tb_cpu_state(env, &pc, &cs_base, &flags); tb = atomic_rcu_read(&cpu->tb_jmp_cache[tb_jmp_cache_hash_func(pc)]); - if (unlikely(!tb || tb->pc != pc || tb->cs_base != cs_base || - tb->flags != flags)) { + if (unlikely(!tb || atomic_read(&tb->pc) != pc || atomic_read(&tb->cs_base) != cs_base || + atomic_read(&tb->flags) != flags)) { tb = tb_htable_lookup(cpu, pc, cs_base, flags); if (!tb) { diff --git a/translate-all.c b/translate-all.c index 8ca393c..0f13d4d 100644 --- a/translate-all.c +++ b/translate-all.c @@ -1198,10 +1198,10 @@ TranslationBlock *tb_gen_code(CPUState *cpu, } gen_code_buf = tcg_ctx.code_gen_ptr; - tb->tc_ptr = gen_code_buf; - tb->cs_base = cs_base; - tb->flags = flags; - tb->cflags = cflags; + atomic_set(&tb->tc_ptr, gen_code_buf); + atomic_set(&tb->cs_base, cs_base); + atomic_set(&tb->flags, flags); + atomic_set(&tb->cflags, cflags); #ifdef CONFIG_PROFILER tcg_ctx.tb_count1++; /* includes aborted translations because of