From nobody Sun May 5 09:16:57 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; dkim=fail spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1498849829133517.3061750025531; Fri, 30 Jun 2017 12:10:29 -0700 (PDT) Received: from localhost ([::1]:45666 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dR1J9-00075A-8J for importer@patchew.org; Fri, 30 Jun 2017 15:10:23 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48371) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dR1Hz-0006Ur-MC for qemu-devel@nongnu.org; Fri, 30 Jun 2017 15:09:12 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dR1Hx-00035F-Fl for qemu-devel@nongnu.org; Fri, 30 Jun 2017 15:09:11 -0400 Received: from mail-qk0-x241.google.com ([2607:f8b0:400d:c09::241]:36121) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dR1Hx-00034w-Al for qemu-devel@nongnu.org; Fri, 30 Jun 2017 15:09:09 -0400 Received: by mail-qk0-x241.google.com with SMTP id v143so3780372qkb.3 for ; Fri, 30 Jun 2017 12:09:09 -0700 (PDT) Received: from bigtime.twiddle.net.com (97-113-165-157.tukw.qwest.net. [97.113.165.157]) by smtp.gmail.com with ESMTPSA id g25sm7454446qte.57.2017.06.30.12.09.07 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 30 Jun 2017 12:09:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=uoVVAQhJ4tcFDqf2RUoSvYwRfgB4kOTOCrg+KOCwYk4=; b=chhUdFEVzK1D+PcbwzfEemAQ7v2oc2RHVUIP+VYTigYOH4mz418XZKUW3Kzuq6WyzO 2s1qE/4K6lrw+f/VfzqZgMjavuQuvoTFiez7lr6Xx0uC9+l4PXsVbDvGI2juAxCWd3sj LnRFxUwem/XS6fuEyW+60k29DKhBPg0qyZXABuSpZKQ/N0i3CUzpTfRU6MbNw0Gd7UC+ FPclGfUC1lKPHGEIcxnn/YIdg3vc/fFkWtUhGG4Q8Al0zL3LkpooahAQP+kr5EAceZTI r5AhRDSEGqoTf0OmMPqN1hMWOnlOecqGXx1qYIMcjV5CDOl4/T9uXB8AK8S2dfZq30ML TqCw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=uoVVAQhJ4tcFDqf2RUoSvYwRfgB4kOTOCrg+KOCwYk4=; b=JeIjhtykeDOsr+MyEhGnaF0XyqZLNIlXnJfDhmsIZ0YSWVw9MEJUpzSv25WbGTwEQU NaMoJgos8fIqYUiQ+UC9EjaHL5xgGbVgSz5145FUH0v6psNDL1MiN54Xw/vfA/2bau2b 7pNaYSvj9/OFCted+WFuFIO4ASc79pA10gQH4h5qj/JEDS3L4gTGLShcMcr5D40HktjE xhNZ9qpsZbDch5U3AtPVOdfGqY0FCwJC6VpPVBTnK5QxgBd2qGP+Ael7GyZCjFrjIa+s 8Y/R6a+14/GWcy0fDnhzyBpHoPEXXnZUJjBeorFuaPML0qowWrz+y0C50QYna9vxk1y1 kHJA== X-Gm-Message-State: AKS2vOyeRG5vJsC0Xj8wPERSIvKXO1YLx5ooAhQXiaG6cH0eLGQLmKGJ IAoBOJfabX1ovPU3Xc8= X-Received: by 10.55.160.12 with SMTP id j12mr26324222qke.87.1498849748649; Fri, 30 Jun 2017 12:09:08 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Fri, 30 Jun 2017 12:09:01 -0700 Message-Id: <20170630190903.9886-2-rth@twiddle.net> X-Mailer: git-send-email 2.9.4 In-Reply-To: <20170630190903.9886-1-rth@twiddle.net> References: <20170630190903.9886-1-rth@twiddle.net> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400d:c09::241 Subject: [Qemu-devel] [PULL 1/3] gen-icount: add missing inline to gen_tb_end 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: peter.maydell@linaro.org, "Emilio G. Cota" Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: "Emilio G. Cota" Reviewed-by: Richard Henderson Signed-off-by: Emilio G. Cota Message-Id: <1497639397-19453-2-git-send-email-cota@braap.org> Signed-off-by: Richard Henderson --- include/exec/gen-icount.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/exec/gen-icount.h b/include/exec/gen-icount.h index 62d462e..547c979 100644 --- a/include/exec/gen-icount.h +++ b/include/exec/gen-icount.h @@ -44,7 +44,7 @@ static inline void gen_tb_start(TranslationBlock *tb) tcg_temp_free_i32(count); } =20 -static void gen_tb_end(TranslationBlock *tb, int num_insns) +static inline void gen_tb_end(TranslationBlock *tb, int num_insns) { if (tb->cflags & CF_USE_ICOUNT) { /* Update the num_insn immediate parameter now that we know --=20 2.9.4 From nobody Sun May 5 09:16:57 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; dkim=fail spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1498849929372207.25264579145346; Fri, 30 Jun 2017 12:12:09 -0700 (PDT) Received: from localhost ([::1]:45670 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dR1Kj-0008BX-WA for importer@patchew.org; Fri, 30 Jun 2017 15:12:02 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48374) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dR1Hz-0006Us-QT for qemu-devel@nongnu.org; Fri, 30 Jun 2017 15:09:12 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dR1Hy-00036j-Md for qemu-devel@nongnu.org; Fri, 30 Jun 2017 15:09:11 -0400 Received: from mail-qk0-x243.google.com ([2607:f8b0:400d:c09::243]:36122) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dR1Hy-000363-Ho for qemu-devel@nongnu.org; Fri, 30 Jun 2017 15:09:10 -0400 Received: by mail-qk0-x243.google.com with SMTP id v143so3780410qkb.3 for ; Fri, 30 Jun 2017 12:09:10 -0700 (PDT) Received: from bigtime.twiddle.net.com (97-113-165-157.tukw.qwest.net. [97.113.165.157]) by smtp.gmail.com with ESMTPSA id g25sm7454446qte.57.2017.06.30.12.09.08 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 30 Jun 2017 12:09:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=PEWrs6e9wYb6WEv532mkYkOBWejEE2rqWcZ8vozKvKk=; b=qbBRlVaO+2RJBeqb4A/FcQqASdMGFvu720QGR0xbf5gKYyhKLmU3dEZhbfBeOGaKNj ZZvEdt096H4y8i2vI6QXODFaPCa6FuDj+udIHXz1Ai1pGAp8TVo0/9uHKE9e3TQMrgxD T3+MrSY43M4kr1B5tA06ICNVTYf0Bj3DGK2EKZ0qm5qWGcONYu15LOTTKPohQXSl9j2O o197r52ACBvd6fOCcpfCWj6mNWYNZiY7xEG+kbJN/1ZhnEQjVmfGHd9uW9t7jPLBi+ZJ N+z15ZS24f/7MCJJ15vxzGXvE46Lgy/JVAuAcZhswUN12Cpo/74be5e5G5RsBzoSvIzr h33A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=PEWrs6e9wYb6WEv532mkYkOBWejEE2rqWcZ8vozKvKk=; b=GhbANBfau+qrOFlfzzPHtQSESPQgTv1uRDdoh4i+Cu7G45nDxrvA6jFPdv7nLyOGEU YmQ325xUYPwtoHFXu+xIBj6u78xvFx5H8n1wFBvfK8/PryJnp2am+SnZ8wyOHbnih037 fGQPvzjZZ05m0o+jF1568Qw/yOl2O6yVFtZ3/ZvmHzeBqelc2CJ7ETjlCtcXcXD5ziOB ye0zAJj1VmBqG5n6GSYYUXlUmyqWxCLK08A3iJf5fRAmG+j9gsmHXYRsaSg0pfis8Dv4 xRimcCjoQGRLLzTGpBNFvRQH/2JhaIkMFU+5P4U+zZnUPeQZRlF28AHuniSA0GTFKuOi 8yFA== X-Gm-Message-State: AKS2vOziH2gR+W3MWgUc/svoMWg3+Mi/AhPTzcK5uuNsD3HKVNAPTT15 dYvQYHJ5vWz7xzRLwTo= X-Received: by 10.55.198.156 with SMTP id s28mr27692941qkl.222.1498849749849; Fri, 30 Jun 2017 12:09:09 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Fri, 30 Jun 2017 12:09:02 -0700 Message-Id: <20170630190903.9886-3-rth@twiddle.net> X-Mailer: git-send-email 2.9.4 In-Reply-To: <20170630190903.9886-1-rth@twiddle.net> References: <20170630190903.9886-1-rth@twiddle.net> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400d:c09::243 Subject: [Qemu-devel] [PULL 2/3] gen-icount: use tcg_ctx.tcg_env instead of cpu_env 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: peter.maydell@linaro.org, "Emilio G. Cota" Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: "Emilio G. Cota" We are relying on cpu_env being defined as a global, yet most targets (i.e. all but arm/a64) have it defined as a local variable. Luckily all of them use the same "cpu_env" name, but really compilation shouldn't break if the name of that local variable changed. Fix it by using tcg_ctx.tcg_env, which all targets set in their translate_init function. This change also helps paving the way for the upcoming "translation loop common to all targets" work. Reviewed-by: Richard Henderson Signed-off-by: Emilio G. Cota Message-Id: <1497639397-19453-3-git-send-email-cota@braap.org> Signed-off-by: Richard Henderson --- include/exec/gen-icount.h | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/include/exec/gen-icount.h b/include/exec/gen-icount.h index 547c979..9b3cb14 100644 --- a/include/exec/gen-icount.h +++ b/include/exec/gen-icount.h @@ -19,7 +19,7 @@ static inline void gen_tb_start(TranslationBlock *tb) count =3D tcg_temp_new_i32(); } =20 - tcg_gen_ld_i32(count, cpu_env, + tcg_gen_ld_i32(count, tcg_ctx.tcg_env, -ENV_OFFSET + offsetof(CPUState, icount_decr.u32)); =20 if (tb->cflags & CF_USE_ICOUNT) { @@ -37,7 +37,7 @@ static inline void gen_tb_start(TranslationBlock *tb) tcg_gen_brcondi_i32(TCG_COND_LT, count, 0, exitreq_label); =20 if (tb->cflags & CF_USE_ICOUNT) { - tcg_gen_st16_i32(count, cpu_env, + tcg_gen_st16_i32(count, tcg_ctx.tcg_env, -ENV_OFFSET + offsetof(CPUState, icount_decr.u16.= low)); } =20 @@ -62,14 +62,16 @@ static inline void gen_tb_end(TranslationBlock *tb, int= num_insns) static inline void gen_io_start(void) { TCGv_i32 tmp =3D tcg_const_i32(1); - tcg_gen_st_i32(tmp, cpu_env, -ENV_OFFSET + offsetof(CPUState, can_do_i= o)); + tcg_gen_st_i32(tmp, tcg_ctx.tcg_env, + -ENV_OFFSET + offsetof(CPUState, can_do_io)); tcg_temp_free_i32(tmp); } =20 static inline void gen_io_end(void) { TCGv_i32 tmp =3D tcg_const_i32(0); - tcg_gen_st_i32(tmp, cpu_env, -ENV_OFFSET + offsetof(CPUState, can_do_i= o)); + tcg_gen_st_i32(tmp, tcg_ctx.tcg_env, + -ENV_OFFSET + offsetof(CPUState, can_do_io)); tcg_temp_free_i32(tmp); } =20 --=20 2.9.4 From nobody Sun May 5 09:16:57 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; dkim=fail spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1498849928362800.9931655950011; Fri, 30 Jun 2017 12:12:08 -0700 (PDT) Received: from localhost ([::1]:45671 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dR1Kl-0008CS-EX for importer@patchew.org; Fri, 30 Jun 2017 15:12:03 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48393) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dR1I1-0006V5-A9 for qemu-devel@nongnu.org; Fri, 30 Jun 2017 15:09:14 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dR1I0-00037u-1r for qemu-devel@nongnu.org; Fri, 30 Jun 2017 15:09:13 -0400 Received: from mail-qt0-x241.google.com ([2607:f8b0:400d:c0d::241]:34442) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dR1Hz-00037c-TL for qemu-devel@nongnu.org; Fri, 30 Jun 2017 15:09:11 -0400 Received: by mail-qt0-x241.google.com with SMTP id m54so13667206qtb.1 for ; Fri, 30 Jun 2017 12:09:11 -0700 (PDT) Received: from bigtime.twiddle.net.com (97-113-165-157.tukw.qwest.net. [97.113.165.157]) by smtp.gmail.com with ESMTPSA id g25sm7454446qte.57.2017.06.30.12.09.09 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 30 Jun 2017 12:09:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=TGxHqc7KHzZuIHV7PHdsZu9127opeu4xewpN0oRmX6k=; b=LWT2r/Xzvrdm/HmmpormyWN9h9N7mWp3xlvaKzEokP8XfWJWd03KRAo+KbqEqL9Nvx 33JoQk7kI/TcEgFj4iB6qg9Y8aEnF/Bdn7724ugSRU0buRTQDAOdWeem8qnb97TBJVpI mmBk1thHn0rJNpumjknFE+o2fWh+HxJLTzUx7D7qbP18MR4B9fkDnYIgNfbdkMRYVZZf uDVHTkCXjU47gmCM9LGAHjBELcTujCqh/5KL1uyorJ/NLcTgD6nXZY/zQx36sDrr0pB1 IL36fZg1a2lWhQKMhgzGhClQbIO8StyUrDJ18GWaFoVU0ppIk5m92knZPeM8WNj+DyVA I1AA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=TGxHqc7KHzZuIHV7PHdsZu9127opeu4xewpN0oRmX6k=; b=Kx8Qlk9dnThicQdeQo8aPtWmcGK+WEJWbSQVsv8x43YJIBHdIc8BtGpCOXL1aX6w6H KXYph4b2LqBGNHkPIqeS5ZeHeeV5G60fU/aToK0Jdx+YwJ0lqY2BRhOjqJ9mkzMpFxvr jKnBNN7PSWY6mLGHQusqnvWEPU6hnPLagKoeiTeJegO9DkmvVM2kRXZj0H6695+KPbut nOGLj/8WYJe9ZP+mnsb3z2bfifaGp9KoKjjxxoDNfSq75xIZM16JHFO4b/XR72TQG+rf J8k1v8NpkMdkMvMsBbOVxatVYSR4rB9svfRzhQ/2ewAzPXFOD8iXBpRcawgOEjoH/Keh YGRA== X-Gm-Message-State: AKS2vOxhogj7hoRovU+29L94L+engem1MzOOLDTN89Mbk2lYUK3hS49V MmY8ytdriERpfc9XfKs= X-Received: by 10.237.63.119 with SMTP id q52mr27785793qtf.49.1498849751125; Fri, 30 Jun 2017 12:09:11 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Fri, 30 Jun 2017 12:09:03 -0700 Message-Id: <20170630190903.9886-4-rth@twiddle.net> X-Mailer: git-send-email 2.9.4 In-Reply-To: <20170630190903.9886-1-rth@twiddle.net> References: <20170630190903.9886-1-rth@twiddle.net> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400d:c0d::241 Subject: [Qemu-devel] [PULL 3/3] tcg: consistently access cpu->tb_jmp_cache atomically 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: peter.maydell@linaro.org, "Emilio G. Cota" Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: "Emilio G. Cota" Some code paths can lead to atomic accesses racing with memset() on cpu->tb_jmp_cache, which can result in torn reads/writes and is undefined behaviour in C11. These torn accesses are unlikely to show up as bugs, but from code inspection they seem possible. For example, tb_phys_invalidate does: /* remove the TB from the hash list */ h =3D tb_jmp_cache_hash_func(tb->pc); CPU_FOREACH(cpu) { if (atomic_read(&cpu->tb_jmp_cache[h]) =3D=3D tb) { atomic_set(&cpu->tb_jmp_cache[h], NULL); } } Here atomic_set might race with a concurrent memset (such as the ones scheduled via "unsafe" async work, e.g. tlb_flush_page) and therefore we might end up with a torn pointer (or who knows what, because we are under undefined behaviour). This patch converts parallel accesses to cpu->tb_jmp_cache to use atomic primitives, thereby bringing these accesses back to defined behaviour. The price to pay is to potentially execute more instructions when clearing cpu->tb_jmp_cache, but given how infrequently they happen and the small size of the cache, the performance impact I have measured is within noise range when booting debian-arm. Note that under "safe async" work (e.g. do_tb_flush) we could use memset because no other vcpus are running. However I'm keeping these accesses atomic as well to keep things simple and to avoid confusing analysis tools such as ThreadSanitizer. Reviewed-by: Paolo Bonzini Reviewed-by: Richard Henderson Signed-off-by: Emilio G. Cota Message-Id: <1497486973-25845-1-git-send-email-cota@braap.org> Signed-off-by: Richard Henderson --- include/qom/cpu.h | 11 ++++++++++- accel/tcg/cputlb.c | 4 ++-- accel/tcg/translate-all.c | 26 ++++++++++++-------------- qom/cpu.c | 5 +---- 4 files changed, 25 insertions(+), 21 deletions(-) diff --git a/include/qom/cpu.h b/include/qom/cpu.h index 89ddb68..2fe7cff 100644 --- a/include/qom/cpu.h +++ b/include/qom/cpu.h @@ -346,7 +346,7 @@ struct CPUState { =20 void *env_ptr; /* CPUArchState */ =20 - /* Writes protected by tb_lock, reads not thread-safe */ + /* Accessed in parallel; all accesses must be atomic */ struct TranslationBlock *tb_jmp_cache[TB_JMP_CACHE_SIZE]; =20 struct GDBRegisterState *gdb_regs; @@ -422,6 +422,15 @@ extern struct CPUTailQ cpus; =20 extern __thread CPUState *current_cpu; =20 +static inline void cpu_tb_jmp_cache_clear(CPUState *cpu) +{ + unsigned int i; + + for (i =3D 0; i < TB_JMP_CACHE_SIZE; i++) { + atomic_set(&cpu->tb_jmp_cache[i], NULL); + } +} + /** * qemu_tcg_mttcg_enabled: * Check whether we are running MultiThread TCG or not. diff --git a/accel/tcg/cputlb.c b/accel/tcg/cputlb.c index 1900936..85635ae 100644 --- a/accel/tcg/cputlb.c +++ b/accel/tcg/cputlb.c @@ -118,7 +118,7 @@ static void tlb_flush_nocheck(CPUState *cpu) =20 memset(env->tlb_table, -1, sizeof(env->tlb_table)); memset(env->tlb_v_table, -1, sizeof(env->tlb_v_table)); - memset(cpu->tb_jmp_cache, 0, sizeof(cpu->tb_jmp_cache)); + cpu_tb_jmp_cache_clear(cpu); =20 env->vtlb_index =3D 0; env->tlb_flush_addr =3D -1; @@ -183,7 +183,7 @@ static void tlb_flush_by_mmuidx_async_work(CPUState *cp= u, run_on_cpu_data data) } } =20 - memset(cpu->tb_jmp_cache, 0, sizeof(cpu->tb_jmp_cache)); + cpu_tb_jmp_cache_clear(cpu); =20 tlb_debug("done\n"); =20 diff --git a/accel/tcg/translate-all.c b/accel/tcg/translate-all.c index f6ad46b..93fb923 100644 --- a/accel/tcg/translate-all.c +++ b/accel/tcg/translate-all.c @@ -928,11 +928,7 @@ static void do_tb_flush(CPUState *cpu, run_on_cpu_data= tb_flush_count) } =20 CPU_FOREACH(cpu) { - int i; - - for (i =3D 0; i < TB_JMP_CACHE_SIZE; ++i) { - atomic_set(&cpu->tb_jmp_cache[i], NULL); - } + cpu_tb_jmp_cache_clear(cpu); } =20 tcg_ctx.tb_ctx.nb_tbs =3D 0; @@ -1813,19 +1809,21 @@ void cpu_io_recompile(CPUState *cpu, uintptr_t reta= ddr) cpu_loop_exit_noexc(cpu); } =20 -void tb_flush_jmp_cache(CPUState *cpu, target_ulong addr) +static void tb_jmp_cache_clear_page(CPUState *cpu, target_ulong page_addr) { - unsigned int i; + unsigned int i, i0 =3D tb_jmp_cache_hash_page(page_addr); =20 + for (i =3D 0; i < TB_JMP_PAGE_SIZE; i++) { + atomic_set(&cpu->tb_jmp_cache[i0 + i], NULL); + } +} + +void tb_flush_jmp_cache(CPUState *cpu, target_ulong addr) +{ /* Discard jump cache entries for any tb which might potentially overlap the flushed page. */ - i =3D tb_jmp_cache_hash_page(addr - TARGET_PAGE_SIZE); - memset(&cpu->tb_jmp_cache[i], 0, - TB_JMP_PAGE_SIZE * sizeof(TranslationBlock *)); - - i =3D tb_jmp_cache_hash_page(addr); - memset(&cpu->tb_jmp_cache[i], 0, - TB_JMP_PAGE_SIZE * sizeof(TranslationBlock *)); + tb_jmp_cache_clear_page(cpu, addr - TARGET_PAGE_SIZE); + tb_jmp_cache_clear_page(cpu, addr); } =20 static void print_qht_statistics(FILE *f, fprintf_function cpu_fprintf, diff --git a/qom/cpu.c b/qom/cpu.c index 5069876..585419b 100644 --- a/qom/cpu.c +++ b/qom/cpu.c @@ -274,7 +274,6 @@ void cpu_reset(CPUState *cpu) static void cpu_common_reset(CPUState *cpu) { CPUClass *cc =3D CPU_GET_CLASS(cpu); - int i; =20 if (qemu_loglevel_mask(CPU_LOG_RESET)) { qemu_log("CPU Reset (CPU %d)\n", cpu->cpu_index); @@ -292,9 +291,7 @@ static void cpu_common_reset(CPUState *cpu) cpu->crash_occurred =3D false; =20 if (tcg_enabled()) { - for (i =3D 0; i < TB_JMP_CACHE_SIZE; ++i) { - atomic_set(&cpu->tb_jmp_cache[i], NULL); - } + cpu_tb_jmp_cache_clear(cpu); =20 #ifdef CONFIG_SOFTMMU tlb_flush(cpu, 0); --=20 2.9.4