From nobody Fri Apr 19 01:36:22 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 1549729796334525.7000501525624; Sat, 9 Feb 2019 08:29:56 -0800 (PST) Received: from localhost ([127.0.0.1]:47253 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gsVVm-0004rW-RQ for importer@patchew.org; Sat, 09 Feb 2019 11:29:50 -0500 Received: from eggs.gnu.org ([209.51.188.92]:42001) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gsVTw-0003h9-CB for qemu-devel@nongnu.org; Sat, 09 Feb 2019 11:27:56 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gsVTu-0000kW-F2 for qemu-devel@nongnu.org; Sat, 09 Feb 2019 11:27:56 -0500 Received: from out2-smtp.messagingengine.com ([66.111.4.26]:35455) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gsVTs-0000id-Gv for qemu-devel@nongnu.org; Sat, 09 Feb 2019 11:27:52 -0500 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id BC1A220F24; Sat, 9 Feb 2019 11:27:51 -0500 (EST) Received: from mailfrontend2 ([10.202.2.163]) by compute4.internal (MEProxy); Sat, 09 Feb 2019 11:27:51 -0500 Received: from localhost (flamenco.cs.columbia.edu [128.59.20.216]) by mail.messagingengine.com (Postfix) with ESMTPA id 578041030F; Sat, 9 Feb 2019 11:27:51 -0500 (EST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=braap.org; h= from:to:cc:subject:date:message-id:in-reply-to:references; s= mesmtp; bh=ZheWVnulEu+/z8msQwCPTZomvKwPvgBz1JZXMJFHQt0=; b=t1TTq vyZSNEJsaIYxzj+6dM2c9LtDoyLz9pfZdv3WNBJJwCZoBtQGPy8E0hwjNgd/udhR yUxl4ESwxMJtrAIk0C90QY2tSoFaQsOkDE7FFdNIfcOxESAdCvB9S7ImsuEEbTux 7rgGHuaHVklyzru5Lkm2QOeAZgWtyK/GNHVB90= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:date:from:in-reply-to:message-id :references:subject:to:x-me-proxy:x-me-proxy:x-me-sender :x-me-sender:x-sasl-enc; s=fm2; bh=ZheWVnulEu+/z8msQwCPTZomvKwPv gBz1JZXMJFHQt0=; b=tNHs8vwGhogc13NDhQuDxITvUMCd94oV1sMTcPcQAfTXR pLnhaRFW7wnc+H6UZ4Jb0VAE/jIpQDqzE1ya4lBUVvX4pyxYVg0/tnEiysGbmooU N3JVv3Hv/2XL92OKDZzhewiE1uuu7HXeDzDd8ntuhext5+lqu7JVa/lYhBqj4V5P 2UW8oxIdU/rWzvLGRD2gQrug8y1BlwQeEzpON/DSOdwCoxj3dS3wUozg/j2J9U3e h4KFgXoU0a5234zfRvisRI8eGLpSD7Jin/1Kv2sfN/4UFwtlmSCNN/f40yBHIeVq QzFaFXHJs2aR48acJT9Gwf+qqUbYG1gDF94ZErLdA== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedtledrleeggdeklecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfhuthenuceurghilhhouhhtmecufedt tdenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujfgurhephffvufffkffojg hfsedttdertdertddtnecuhfhrohhmpedfgfhmihhlihhoucfirdcuvehothgrfdcuoegt ohhtrgessghrrggrphdrohhrgheqnecukfhppeduvdekrdehledrvddtrddvudeinecurf grrhgrmhepmhgrihhlfhhrohhmpegtohhtrgessghrrggrphdrohhrghenucevlhhushht vghrufhiiigvpedt X-ME-Proxy: From: "Emilio G. Cota" To: qemu-devel@nongnu.org Date: Sat, 9 Feb 2019 11:27:44 -0500 Message-Id: <20190209162745.12668-2-cota@braap.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190209162745.12668-1-cota@braap.org> References: <20190209162745.12668-1-cota@braap.org> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 66.111.4.26 Subject: [Qemu-devel] [PATCH 1/2] exec-all: document that tlb_fill can trigger a TLB resize 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: Max Filippov , Richard Henderson , =?UTF-8?q?Alex=20Benn=C3=A9e?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Emilio G. Cota Reviewed-by: Alex Benn=C3=A9e --- include/exec/exec-all.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/include/exec/exec-all.h b/include/exec/exec-all.h index aa7b81aaf0..97b90cb0db 100644 --- a/include/exec/exec-all.h +++ b/include/exec/exec-all.h @@ -475,6 +475,11 @@ static inline void assert_no_pages_locked(void) struct MemoryRegionSection *iotlb_to_section(CPUState *cpu, hwaddr index, MemTxAttrs attr= s); =20 +/* + * Note: tlb_fill() can trigger a resize of the TLB. This means that all o= f the + * caller's prior references to the TLB table (e.g. CPUTLBEntry pointers) = must + * be discarded and looked up again (e.g. via tlb_entry()). + */ void tlb_fill(CPUState *cpu, target_ulong addr, int size, MMUAccessType access_type, int mmu_idx, uintptr_t retaddr); =20 --=20 2.17.1 From nobody Fri Apr 19 01:36:22 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 1549729797306100.22914977882965; Sat, 9 Feb 2019 08:29:57 -0800 (PST) Received: from localhost ([127.0.0.1]:47256 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gsVVn-0004rd-Ak for importer@patchew.org; Sat, 09 Feb 2019 11:29:51 -0500 Received: from eggs.gnu.org ([209.51.188.92]:41999) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gsVTw-0003h8-Bq for qemu-devel@nongnu.org; Sat, 09 Feb 2019 11:27:57 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gsVTu-0000kN-ER for qemu-devel@nongnu.org; Sat, 09 Feb 2019 11:27:56 -0500 Received: from out2-smtp.messagingengine.com ([66.111.4.26]:41523) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gsVTs-0000ij-GE for qemu-devel@nongnu.org; Sat, 09 Feb 2019 11:27:52 -0500 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id DF75F213FC; Sat, 9 Feb 2019 11:27:51 -0500 (EST) Received: from mailfrontend2 ([10.202.2.163]) by compute4.internal (MEProxy); Sat, 09 Feb 2019 11:27:51 -0500 Received: from localhost (flamenco.cs.columbia.edu [128.59.20.216]) by mail.messagingengine.com (Postfix) with ESMTPA id 8E10610311; Sat, 9 Feb 2019 11:27:51 -0500 (EST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=braap.org; h= from:to:cc:subject:date:message-id:in-reply-to:references; s= mesmtp; bh=6SgLy/Xg8Dk22X4RKJruyKq2tseQv5cvuFy1zo4OfuM=; b=FQ/5Z Qt77X0H7q5yx/CRutAbPpdfpw2Js3xIAFMiX5g+Mz6B9Z2Pehv3dksq3nHzLXkK7 K6V1jADCQqA7tR7ipnL2eWUTkVP8CyS4MukRWjCALFrwMCZGu6W6BW7IhKBd0TjF 9MMoNz2jI991AeZUA8nf0tW5yprXAA8t859Q3Q= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:date:from:in-reply-to:message-id :references:subject:to:x-me-proxy:x-me-proxy:x-me-sender :x-me-sender:x-sasl-enc; s=fm2; bh=6SgLy/Xg8Dk22X4RKJruyKq2tseQv 5cvuFy1zo4OfuM=; b=EGf7Kg/ElWI4uZDE1RFu9M5teEJTXxOb2G3UHsXjYolxo RtpHUKvnmZzOwrgIehyffiILMT0pAublh/aLDTdS3I5booOGfZ5FWOO3xNcKli3b oQpgd/suSFIYUpxxWBtPA6VsesP1KwyyW5nGQMrdieyNItCb806RyZMJZ6mcXTXh T4htqHArqrLuhgIs2KnBPkrRcjjkscAFBM576EDNA7n9ecYf7bA8YOnrQWgdleJI j1ba2M4KFNkvdVyVlKOaPakc4ntFiq537kuQJr0wQm2N6m2BTJ57t4PM3olJr+ui 1oZ7wJ8PAsfhk61AtnzZ7WPdb/qLmj9ymiNg5Effg== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedtledrleeggdeklecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfhuthenuceurghilhhouhhtmecufedt tdenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujfgurhephffvufffkffojg hfsedttdertdertddtnecuhfhrohhmpedfgfhmihhlihhoucfirdcuvehothgrfdcuoegt ohhtrgessghrrggrphdrohhrgheqnecukfhppeduvdekrdehledrvddtrddvudeinecurf grrhgrmhepmhgrihhlfhhrohhmpegtohhtrgessghrrggrphdrohhrghenucevlhhushht vghrufhiiigvpedt X-ME-Proxy: From: "Emilio G. Cota" To: qemu-devel@nongnu.org Date: Sat, 9 Feb 2019 11:27:45 -0500 Message-Id: <20190209162745.12668-3-cota@braap.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190209162745.12668-1-cota@braap.org> References: <20190209162745.12668-1-cota@braap.org> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 66.111.4.26 Subject: [Qemu-devel] [PATCH 2/2] cputlb: update TLB entry/index after tlb_fill 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: Max Filippov , Richard Henderson , =?UTF-8?q?Alex=20Benn=C3=A9e?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" We are failing to take into account that tlb_fill() can cause a TLB resize, which renders prior TLB entry pointers/indices stale. Fix it by re-doing the TLB entry lookups immediately after tlb_fill. Fixes: 86e1eff8bc ("tcg: introduce dynamic TLB sizing", 2019-01-28) Reported-by: Max Filippov Tested-by: Max Filippov Signed-off-by: Emilio G. Cota --- accel/tcg/softmmu_template.h | 8 ++++++++ accel/tcg/cputlb.c | 4 ++++ 2 files changed, 12 insertions(+) diff --git a/accel/tcg/softmmu_template.h b/accel/tcg/softmmu_template.h index 1fdd262ea4..e970a8b378 100644 --- a/accel/tcg/softmmu_template.h +++ b/accel/tcg/softmmu_template.h @@ -129,6 +129,8 @@ WORD_TYPE helper_le_ld_name(CPUArchState *env, target_u= long addr, if (!VICTIM_TLB_HIT(ADDR_READ, addr)) { tlb_fill(ENV_GET_CPU(env), addr, DATA_SIZE, READ_ACCESS_TYPE, mmu_idx, retaddr); + index =3D tlb_index(env, mmu_idx, addr); + entry =3D tlb_entry(env, mmu_idx, addr); } tlb_addr =3D entry->ADDR_READ; } @@ -198,6 +200,8 @@ WORD_TYPE helper_be_ld_name(CPUArchState *env, target_u= long addr, if (!VICTIM_TLB_HIT(ADDR_READ, addr)) { tlb_fill(ENV_GET_CPU(env), addr, DATA_SIZE, READ_ACCESS_TYPE, mmu_idx, retaddr); + index =3D tlb_index(env, mmu_idx, addr); + entry =3D tlb_entry(env, mmu_idx, addr); } tlb_addr =3D entry->ADDR_READ; } @@ -294,6 +298,8 @@ void helper_le_st_name(CPUArchState *env, target_ulong = addr, DATA_TYPE val, if (!VICTIM_TLB_HIT(addr_write, addr)) { tlb_fill(ENV_GET_CPU(env), addr, DATA_SIZE, MMU_DATA_STORE, mmu_idx, retaddr); + index =3D tlb_index(env, mmu_idx, addr); + entry =3D tlb_entry(env, mmu_idx, addr); } tlb_addr =3D tlb_addr_write(entry) & ~TLB_INVALID_MASK; } @@ -372,6 +378,8 @@ void helper_be_st_name(CPUArchState *env, target_ulong = addr, DATA_TYPE val, if (!VICTIM_TLB_HIT(addr_write, addr)) { tlb_fill(ENV_GET_CPU(env), addr, DATA_SIZE, MMU_DATA_STORE, mmu_idx, retaddr); + index =3D tlb_index(env, mmu_idx, addr); + entry =3D tlb_entry(env, mmu_idx, addr); } tlb_addr =3D tlb_addr_write(entry) & ~TLB_INVALID_MASK; } diff --git a/accel/tcg/cputlb.c b/accel/tcg/cputlb.c index f580e4dd7e..88cc8389e9 100644 --- a/accel/tcg/cputlb.c +++ b/accel/tcg/cputlb.c @@ -1045,6 +1045,8 @@ tb_page_addr_t get_page_addr_code(CPUArchState *env, = target_ulong addr) if (unlikely(!tlb_hit(entry->addr_code, addr))) { if (!VICTIM_TLB_HIT(addr_code, addr)) { tlb_fill(ENV_GET_CPU(env), addr, 0, MMU_INST_FETCH, mmu_idx, 0= ); + index =3D tlb_index(env, mmu_idx, addr); + entry =3D tlb_entry(env, mmu_idx, addr); } assert(tlb_hit(entry->addr_code, addr)); } @@ -1125,6 +1127,8 @@ static void *atomic_mmu_lookup(CPUArchState *env, tar= get_ulong addr, if (!VICTIM_TLB_HIT(addr_write, addr)) { tlb_fill(ENV_GET_CPU(env), addr, 1 << s_bits, MMU_DATA_STORE, mmu_idx, retaddr); + index =3D tlb_index(env, mmu_idx, addr); + tlbe =3D tlb_entry(env, mmu_idx, addr); } tlb_addr =3D tlb_addr_write(tlbe) & ~TLB_INVALID_MASK; } --=20 2.17.1