From patchwork Fri May 22 16:07:47 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Robert Foley X-Patchwork-Id: 187173 Delivered-To: patch@linaro.org Received: by 2002:a92:5b0a:0:0:0:0:0 with SMTP id p10csp2645902ilb; Fri, 22 May 2020 09:17:47 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwvLDzmeVtB5ig+jG0+ureKCJBCrimsqyznCdBthQdvb7isNvItOnEsxF7fPqRl+wDtvema X-Received: by 2002:a05:6214:7cd:: with SMTP id bb13mr4564436qvb.17.1590164267256; Fri, 22 May 2020 09:17:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1590164267; cv=none; d=google.com; s=arc-20160816; b=MxasZdDJvu7LYSyXtY0NnGzJ7Bfd8rlmzq3apsCm/5r9/yCuWWon8UOw9jc9/5u+tM a5IdQgZKWiaMne0uU8Wgtv0Knxv4XUvKlm0bgPov6Mm5/JIyzfFePcRfLP+PBtrNTIXs ghdoCJ0mCsugXQAHkwIrl+krMmVWxmGyOZHRsOd8cVDz+LBOc+/Wwl/mjMDcZDp3BmrP qC3oGlwBOHwK73c8tbXpi8dFoSMayrGHdIRe1r1anIr7P1xgjTL08gmLKOZaQPQrIHHb qnfIfB6n+wqOKQzCxbN34ps7swrzVoN1WoqTQfKofXu2g5dJQNITPnommwEpYmKiXIbW sIoQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:references:in-reply-to :message-id:date:subject:to:from:dkim-signature; bh=sWktVAUx9ulLHoMCqPkS2j+iHzQ8DGPuikmGe+LrZUk=; b=FQwxDmkkJUmHey5bpy6Da/0EfGR/hKApnHBg5jpJd4LVJGxFURsubsbRBR0Uwr2qcG xkPIqfGs37fLyU9l0Vy4tqc3MWcwaGW56YXL4vVA4TD+gYuy85A6p0s0ccXMaFUJzZcq l3qEAOs7o20IEJSfrOvzbCvIvQAaiRxCmY21Wz12oNYKA/S31U2Eodd6yecvjj/VzEA5 4UoDF20Uvn+PT+36Pfdh19GahzTK42JAoV5lKxEV+VOj6BdFdqYlYVtLX3/a1vwdUvaN FJXhtzs3DLDIf6xpdjhsQXiFcH32krZ8Z7C1z5PcK+FefCm3L0ThcacK0QcvjADeFFoL s6zg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=Cm0akHXB; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id t7si5253511qtn.208.2020.05.22.09.17.47 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 22 May 2020 09:17:47 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=Cm0akHXB; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:49254 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jcAMk-0005FL-Nt for patch@linaro.org; Fri, 22 May 2020 12:17:46 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40424) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jcAKT-00038Q-Gk for qemu-devel@nongnu.org; Fri, 22 May 2020 12:15:26 -0400 Received: from mail-pg1-x541.google.com ([2607:f8b0:4864:20::541]:41122) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jcAKR-0006Eq-2Q for qemu-devel@nongnu.org; Fri, 22 May 2020 12:15:25 -0400 Received: by mail-pg1-x541.google.com with SMTP id r10so5193161pgv.8 for ; Fri, 22 May 2020 09:15:22 -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; bh=sWktVAUx9ulLHoMCqPkS2j+iHzQ8DGPuikmGe+LrZUk=; b=Cm0akHXBJ44Xf4i0soK9E5rV+vLa3l1KWkBctdFf7kBUJ//m1QQ4AXHqDQO1h6uu9j UlRhlrcnfnjlxwkXv9EaKsjDFcLddrVZNOs2e5iXYdJHACrZGOYnWDu7IO9ObTGRlUHx 3f/UCqRYdjKg/DeM8Cz1/rRQvH+aDd/7lrAHb7TrgoeJRUDb4IAAsQfW8pETdZuFmJFc 7B4FiZ/pyLBvCmcclK2NhdtKkEtTAHbje2+3aCCcpHG3DQtfK047Wx4ngfPZS1CR7f+m qPN4D/TfeKGbs7/b1YQPZTNDOm6YgZBz7L+hK+qkxVLy9khFV1hXhwJ/ZF01xk/oRgdp VKTg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=sWktVAUx9ulLHoMCqPkS2j+iHzQ8DGPuikmGe+LrZUk=; b=Ko536QNTtXf3xHaYYO4OT4ABAODEauKRk8P8QQH7NbKWhRV1vWBbJ6aOOxIeHSzNQC tjzagO82+g4C1oQ5zzq9Y1nBykQMFyD8PjNofeF+JDFkWig2xPpIvpqOGL73g8RiD+02 4RS7/EdOtZuNPVYmkTJ7+JZhemd7f5fjToy4ZD3nZJA0QzVxpsTmqhtofmghPTQECoEI rTFa7lhAir/lJd6uaIXZixsR4dKAgtV/Ec4GK84qn7833Ccckzd5/FAqwZiktve6/vQM fW4Gc2vzL0scAnOJAEW2zskv9JYUHFuhgJPmwa7x70EzO/ZGpvjZmuvIwnCI0YvsBc+y 5HHA== X-Gm-Message-State: AOAM530dQ/1eamBKcQveCuV9sPZkH6UbRziNyslu+VcHOfLNAzRYn4O7 cJq9Fu7P66kTaobWEhBdRg+pdjryIiVhWg== X-Received: by 2002:a62:7a0b:: with SMTP id v11mr4662621pfc.111.1590164121017; Fri, 22 May 2020 09:15:21 -0700 (PDT) Received: from Rfoley-MA01.hsd1.ma.comcast.net ([2601:199:4480:60c0:f1d9:5fce:c451:d2e2]) by smtp.gmail.com with ESMTPSA id y75sm7255428pfb.212.2020.05.22.09.15.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 May 2020 09:15:20 -0700 (PDT) From: Robert Foley To: qemu-devel@nongnu.org Subject: [PATCH 11/19] accel/tcg: Fixed tsan warnings related to parallel_cpus Date: Fri, 22 May 2020 12:07:47 -0400 Message-Id: <20200522160755.886-12-robert.foley@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200522160755.886-1-robert.foley@linaro.org> References: <20200522160755.886-1-robert.foley@linaro.org> Received-SPF: pass client-ip=2607:f8b0:4864:20::541; envelope-from=robert.foley@linaro.org; helo=mail-pg1-x541.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: robert.foley@linaro.org, Richard Henderson , cota@braap.org, Paolo Bonzini , peter.puhov@linaro.org, alex.bennee@linaro.org Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Fixed several tsan warnings. e.g. WARNING: ThreadSanitizer: data race (pid=35425) Read of size 1 at 0x557cd83aee28 by thread T7: #0 curr_cflags include/exec/exec-all.h:460:13 (qemu-system-aarch64+0x4b7f27) #1 cpu_exec accel/tcg/cpu-exec.c:730:26 (qemu-system-aarch64+0x4b7f27) #2 tcg_cpu_exec cpus.c:1415:11 (qemu-system-aarch64+0x45b9b6) #3 qemu_tcg_cpu_thread_fn cpus.c:1723:17 (qemu-system-aarch64+0x45b9b6) #4 qemu_thread_start util/qemu-thread-posix.c:519:9 (qemu-system-aarch64+0xd431e0) Previous write of size 1 at 0x557cd83aee28 by thread T6: #0 cpu_exec_step_atomic accel/tcg/cpu-exec.c:254:23 (qemu-system-aarch64+0x4b6caa) #1 qemu_tcg_cpu_thread_fn cpus.c:1741:17 (qemu-system-aarch64+0x45baca) #2 qemu_thread_start util/qemu-thread-posix.c:519:9 (qemu-system-aarch64+0xd431e0) Location is global 'parallel_cpus' of size 1 at 0x557cd83aee28 (qemu-system-aarch64+0x000001fb3e28) Cc: Richard Henderson Cc: Paolo Bonzini Signed-off-by: Robert Foley --- accel/tcg/cpu-exec.c | 4 ++-- cpus.c | 2 +- include/exec/exec-all.h | 2 +- linux-user/syscall.c | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-) -- 2.17.1 Reviewed-by: Emilio G. Cota diff --git a/accel/tcg/cpu-exec.c b/accel/tcg/cpu-exec.c index d95c4848a4..4cbdef1373 100644 --- a/accel/tcg/cpu-exec.c +++ b/accel/tcg/cpu-exec.c @@ -250,7 +250,7 @@ void cpu_exec_step_atomic(CPUState *cpu) } /* Since we got here, we know that parallel_cpus must be true. */ - parallel_cpus = false; + atomic_set(¶llel_cpus, false); cc->cpu_exec_enter(cpu); /* execute the generated code */ trace_exec_tb(tb, pc); @@ -278,7 +278,7 @@ void cpu_exec_step_atomic(CPUState *cpu) * the execution. */ g_assert(cpu_in_exclusive_context(cpu)); - parallel_cpus = true; + atomic_set(¶llel_cpus, true); end_exclusive(); } diff --git a/cpus.c b/cpus.c index af44027549..c5d04486a8 100644 --- a/cpus.c +++ b/cpus.c @@ -1966,7 +1966,7 @@ static void qemu_tcg_init_vcpu(CPUState *cpu) if (qemu_tcg_mttcg_enabled()) { /* create a thread per vCPU with TCG (MTTCG) */ - parallel_cpus = true; + atomic_set(¶llel_cpus, true); snprintf(thread_name, VCPU_THREAD_NAME_SIZE, "CPU %d/TCG", cpu->cpu_index); diff --git a/include/exec/exec-all.h b/include/exec/exec-all.h index 3cf88272df..3f2c0290e1 100644 --- a/include/exec/exec-all.h +++ b/include/exec/exec-all.h @@ -496,7 +496,7 @@ static inline uint32_t tb_cflags(const TranslationBlock *tb) /* current cflags for hashing/comparison */ static inline uint32_t curr_cflags(void) { - return (parallel_cpus ? CF_PARALLEL : 0) + return (atomic_read(¶llel_cpus) ? CF_PARALLEL : 0) | (use_icount ? CF_USE_ICOUNT : 0); } diff --git a/linux-user/syscall.c b/linux-user/syscall.c index 05f03919ff..8e39c09c5d 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -6022,8 +6022,8 @@ static int do_fork(CPUArchState *env, unsigned int flags, abi_ulong newsp, /* If this is our first additional thread, we need to ensure we * generate code for parallel execution and flush old translations. */ - if (!parallel_cpus) { - parallel_cpus = true; + if (!atomic_read(¶llel_cpus)) { + atomic_set(¶llel_cpus, true); tb_flush(cpu); }