From patchwork Thu Jan 23 04:23:31 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rik van Riel X-Patchwork-Id: 13947943 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 381CDC0218C for ; Thu, 23 Jan 2025 04:30:58 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8BFC528000C; Wed, 22 Jan 2025 23:30:57 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 893F428000A; Wed, 22 Jan 2025 23:30:57 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6C2BA28000C; Wed, 22 Jan 2025 23:30:57 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 371A728000A for ; Wed, 22 Jan 2025 23:30:57 -0500 (EST) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id EA5F6A0B87 for ; Thu, 23 Jan 2025 04:30:56 +0000 (UTC) X-FDA: 83037441312.27.20D0422 Received: from shelob.surriel.com (shelob.surriel.com [96.67.55.147]) by imf15.hostedemail.com (Postfix) with ESMTP id 5D7E5A0004 for ; Thu, 23 Jan 2025 04:30:55 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf15.hostedemail.com: domain of riel@shelob.surriel.com designates 96.67.55.147 as permitted sender) smtp.mailfrom=riel@shelob.surriel.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1737606655; a=rsa-sha256; cv=none; b=P7tOiy6Yr1mlAjw4Ojp5vZ5jhOo9zAzG4mpalUM5EbKZgqvh/dRmmuVmSSxlO+0AQtMFjn vLNr8IlrbUG9ogk+zp0bmPXBFhr4TVeUna4zFX16lilwc614WQeWhG3drpM31tE2IcvwpH RfIq2CZ8TvXZbO96BEegoJPu8G3hwFk= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf15.hostedemail.com: domain of riel@shelob.surriel.com designates 96.67.55.147 as permitted sender) smtp.mailfrom=riel@shelob.surriel.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1737606655; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=8C+WD7u9Zqwod1lV9jBGsHtY3wt4lu8RpE4zXut7lR8=; b=lsk8RPRZwK6J9hyCrzpbPgzNBRhRi8TolKQe8HPltD4mMA7Ly/qt8qWXMtWTE0pKOrd5bR YP3a/w4kqIsv2z9z+rnZIyg7o0ZbnOVCPhYZmXPVcfujGkNFmrTBlQn4wooYTJU6rCaW1J FSwUCQ2Nt5+STMmvt8AggU8ezBoav0A= Received: from fangorn.home.surriel.com ([10.0.13.7]) by shelob.surriel.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.97.1) (envelope-from ) id 1taols-000000005uH-3Yx9; Wed, 22 Jan 2025 23:24:48 -0500 From: Rik van Riel To: x86@kernel.org Cc: linux-kernel@vger.kernel.org, bp@alien8.de, peterz@infradead.org, dave.hansen@linux.intel.com, zhengqi.arch@bytedance.com, nadav.amit@gmail.com, thomas.lendacky@amd.com, kernel-team@meta.com, linux-mm@kvack.org, akpm@linux-foundation.org, jannh@google.com, mhklinux@outlook.com, andrew.cooper3@citrix.com, Rik van Riel Subject: [PATCH v7 12/12] x86/mm: only invalidate final translations with INVLPGB Date: Wed, 22 Jan 2025 23:23:31 -0500 Message-ID: <20250123042447.2259648-13-riel@surriel.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250123042447.2259648-1-riel@surriel.com> References: <20250123042447.2259648-1-riel@surriel.com> MIME-Version: 1.0 X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 5D7E5A0004 X-Stat-Signature: 5hcqcgrzfj8hbhzagn35431o43fu3o41 X-Rspam-User: X-HE-Tag: 1737606655-168029 X-HE-Meta: U2FsdGVkX19B57ZBNWv91BMEukSadfuQ0lPrTCoDI6/3DvNO4F2y6gFKKobJTZgIrLRoANk/MNe0AV7FX6xkymLPxeAZOiVFqe6RWavExnSuTE8HEg/GEu/evritg5dWaQVoGROMmV9qgnYIf/Zqz9lb2vgZ7xRMBMZDYk0oHyH78UyUgzNam+bgqyTWs8ZScWHSFues0KHq+uStQ6+y0QEoMtF2jNITtCMG81JcjfDaXcn+P4KqpY5T2wo/hOD5jNyrDMIu0iikPlx4YPsLgKZPx69RBcS+crRNTROFErJLZhZ/mMtyjJpKjZEm7dvAcC5vgiQ98DBCX7+PPcpUtZV3KGhsEj4GuRLIKgpTHDTR1vYgQq8UOm5dhAOBxS0XA0jCNrTWTAB7etHldqg2h0hljKf3P0tFIGZPdKWajUZxpetXAwbouUN8pvazjjTG2hackYzE+NwJ+yVbyL2TT1jf2/5UeDgj9g6B4eU8K5Gs43A+vBkV6JVnA/y8RczYVrsnvjjesAkub1aWVovCeG3vp24qDTTzU4vuyA4q4LdvO0xXJaTiiLn8L84Z23tNspxU4H83TrE86Vt7l6teMF5c2hNM1bCM0TotffWvMunajYVsUN+oFF35o405OuNIMRvIyqCfAhFyvC7kYvBIS2k8Vd7NeE7cGLOHNfpkYpAm1B83RDsTQ69dCZoJlryhijPNR/8aHHL23jxYPkc/fJ576rOwluxTu82ZkbyT3aMESnAlFnW6SMJMYd2KmjZLxNH6ZsbV1Kqmp3rJYLXIc3V4a6utzLVVWUZPHi5TqHY5KWS81VilT25Jb37Wp55p0NewyCZKe3RNync79/UU3qCSYsgpN+IWfNc/sxvrRT8aAnQJt7zKgB5N6zAwFJiqq3rwlwpK92NlWKkRKQw6GtRFIfoOM/qdmubYRqx0aHzsYbYLK7i1vs9KbfAMckLKya3pgUX0eOBSZmdLYrP KjsiJqeA 2W6Jr/BREfR3XwYSZMK1F6igFPNaff7tr1zZyJKozN4KX5c8ZAa9kWHerBFtKJrGzwNt2pvXdOvgGHUxuIvvHfvjiPSn9iY7Vs9gn+ZNK1REoG0qZJWJsosYUuHFzmYs4znyLdZb7JbTIJTwclIjGyRwnKSWblo0/4Gim5HHZp05RjbNqR0DzkTe0zoQSajzVZZb2g8ExNTv5MirYh6Z5dpmvjW4rXyrlyt5jCKOYx1Ak7taoEq32GVYM0iamVFQiSEvi/v3w+27mxv2PJhemvqXYShNIuB7kS1yPUg1bRxf2D5zPHJCNChmHH7sWmujffsY+wFBMzJo8hHAEPJ5Y5SRonU/iay8jRfRfuhfSATqKyBhZbGlmnVLgYJR7uhgbQ+D1ES99YznSEV0= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Use the INVLPGB_FINAL_ONLY flag when invalidating mappings with INVPLGB. This way only leaf mappings get removed from the TLB, leaving intermediate translations cached. On the (rare) occasions where we free page tables we do a full flush, ensuring intermediate translations get flushed from the TLB. Signed-off-by: Rik van Riel --- arch/x86/include/asm/invlpgb.h | 10 ++++++++-- arch/x86/mm/tlb.c | 8 ++++---- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/arch/x86/include/asm/invlpgb.h b/arch/x86/include/asm/invlpgb.h index a1d5dedd5217..5fba41671a6d 100644 --- a/arch/x86/include/asm/invlpgb.h +++ b/arch/x86/include/asm/invlpgb.h @@ -67,9 +67,15 @@ static inline void invlpgb_flush_user(unsigned long pcid, static inline void invlpgb_flush_user_nr_nosync(unsigned long pcid, unsigned long addr, u16 nr, - bool pmd_stride) + bool pmd_stride, + bool freed_tables) { - __invlpgb(0, pcid, addr, nr - 1, pmd_stride, INVLPGB_PCID | INVLPGB_VA); + unsigned long flags = INVLPGB_PCID | INVLPGB_VA; + + if (!freed_tables) + flags |= INVLPGB_FINAL_ONLY; + + __invlpgb(0, pcid, addr, nr - 1, pmd_stride, flags); } /* Flush all mappings for a given PCID, not including globals. */ diff --git a/arch/x86/mm/tlb.c b/arch/x86/mm/tlb.c index 9fee2aff8153..682da8d0d1c9 100644 --- a/arch/x86/mm/tlb.c +++ b/arch/x86/mm/tlb.c @@ -518,10 +518,10 @@ static void broadcast_tlb_flush(struct flush_tlb_info *info) nr = min(maxnr, (info->end - addr) >> info->stride_shift); nr = max(nr, 1); - invlpgb_flush_user_nr_nosync(kern_pcid(asid), addr, nr, pmd); + invlpgb_flush_user_nr_nosync(kern_pcid(asid), addr, nr, pmd, info->freed_tables); /* Do any CPUs supporting INVLPGB need PTI? */ if (static_cpu_has(X86_FEATURE_PTI)) - invlpgb_flush_user_nr_nosync(user_pcid(asid), addr, nr, pmd); + invlpgb_flush_user_nr_nosync(user_pcid(asid), addr, nr, pmd, info->freed_tables); addr += nr << info->stride_shift; } while (addr < info->end); @@ -1683,10 +1683,10 @@ void arch_tlbbatch_add_pending(struct arch_tlbflush_unmap_batch *batch, batch->used_invlpgb = true; migrate_disable(); } - invlpgb_flush_user_nr_nosync(kern_pcid(asid), uaddr, 1, false); + invlpgb_flush_user_nr_nosync(kern_pcid(asid), uaddr, 1, false, false); /* Do any CPUs supporting INVLPGB need PTI? */ if (static_cpu_has(X86_FEATURE_PTI)) - invlpgb_flush_user_nr_nosync(user_pcid(asid), uaddr, 1, false); + invlpgb_flush_user_nr_nosync(user_pcid(asid), uaddr, 1, false, false); /* * Some CPUs might still be using a local ASID for this