From patchwork Thu Jan 16 02:30:35 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: 13941169 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 9C654C02183 for ; Thu, 16 Jan 2025 02:45:39 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 37B84280003; Wed, 15 Jan 2025 21:45:39 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 32646280001; Wed, 15 Jan 2025 21:45:39 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1EEB1280003; Wed, 15 Jan 2025 21:45:39 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 0123B280001 for ; Wed, 15 Jan 2025 21:45:38 -0500 (EST) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id A98D3AF03A for ; Thu, 16 Jan 2025 02:45:38 +0000 (UTC) X-FDA: 83011774356.28.6DC11CE Received: from shelob.surriel.com (shelob.surriel.com [96.67.55.147]) by imf11.hostedemail.com (Postfix) with ESMTP id 2CA3E4000F for ; Thu, 16 Jan 2025 02:45:37 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf11.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=1736995537; a=rsa-sha256; cv=none; b=UjZww8yFQQMbJaUspCubeRQusXcZrnBzYQFMaS86khFXTgsNyyn/WxhSd1ydjuO0adhPHx Pj0gaA8Iu9Q3SOD8h9aydSnu4SF3MOxEOOp6w8InDTL/zTq/l88BpgKPwrnlx4WHzyFXQ6 V6naOh5qwEqkYNBWt10fA+f8pjgM8M0= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf11.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=1736995537; 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=0o0tFfKjjLyNfvHqePJBQrBq7wmKzWDPuR0QqO5bV3g=; b=Ht0CCpiYkQFt/BGWSFb3vvSBDDOin67PGDMHeRUlHJdb25hFGYJ+hxCinr2G27cuj9nXgg zgRS5vzfZZohUY45raAnMSHwWJ/Yx4uLTWMOnVhbvNIlq+rd6rs/9d/xVmJDtAiq0o3uGE A1t97+/Hc8rM4M7Y3z6TevEN9/9t5rI= 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 1tYFfO-000000003nd-41DF; Wed, 15 Jan 2025 21:31:30 -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 v5 12/12] x86/mm: only invalidate final translations with INVLPGB Date: Wed, 15 Jan 2025 21:30:35 -0500 Message-ID: <20250116023127.1531583-13-riel@surriel.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250116023127.1531583-1-riel@surriel.com> References: <20250116023127.1531583-1-riel@surriel.com> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: 2CA3E4000F X-Stat-Signature: 51xro7ojw95ynw1gr4zhq8qiazbxauyc X-HE-Tag: 1736995537-42331 X-HE-Meta: U2FsdGVkX1/BQfaptHvNzHf3vYIutFyBXNgdryBirm+2b4+CaGYTVlLwvV08vULEN4GJoJPTgGBRqRXsUls93RpH2HIKdV4WlQbCa7ncGAHpLdZtYP7/e5NF73h/VP0jctQJGQ+ZZBVuLWLsoqAdzwrQutFgSPWtWMTeSA6YuVOaNkUvJQFr6xoP813oNfYEI0WD3Gdgdo7BmdgB6dblHxcTg8j1SPc/q5MoaaPq1t1bLekSsaU6ozvxGswS1f4M8vQSR8FcJ8pAxjaV/jW0BjHieRb91USZQaEEDOvd0NSTRt9yK7sxrOF9sSWEkoUxKShLuhGNJ06vE2r6grnJ76wGKDhP5LAzYdVrqeEVENMhVJeZgn/7Q9KaRj4rB+zhv6XDaO7WgghV35ExWfuHaB2OR9DGAmu0JQ5iVl01OCVALJMzd1hSh7jNT9RKp6/s59mQeisIVg6Iy+v8b/OwRwcLmOXnakuTINF8rIBkDKoj2SPBQVzt86bppEDVGa+edLykh8QQNwyHUHGZIguRjJEokqSco47uGMqBHLrE/0IgWnUK/gJEIXbQfPpn12tieD4ZTNVsLQ3LSgtH0BfzlXzj3lzF9zQcl/6yikirmIEnoBapvWY+ZmdpzM9PzRXrEE59K/UT+0SexfbJKhuYyqzfKWdOjOmuQW08f0G/AtX4M2cNht0lqDLHy9hn37wHS2HDd7HLqINI3fVYYWuxcTWVCXBBxDgIjrs2luOdzVJyYc+LGYDrzxKSU0V5P6Wx2EZXyNPmGA9Ztw0nKCtXz9+77PGZ29EL2v/W/PBodGg2UswLtIO5d48tyJYi6l1NHMnvrlTQ2WDRqBcVlcemdPc4rGqzOGzefOTlfmIXH9PTgW6+gqI6UD3F2hWEXkpZp+HbR2maD8PGEul1Ku1Id6XY9u2fMGusisMTja1WpmfN18SQgGZ4KT2fLPk1mq0X2iiG4PzK/cX4VmPYm4C XUw3CiUo Q+xs0Wmi+qhD+Hupx3Br3fDw2iGJBh5NwPBCsnHz7x6KqHdpDSoob9Ag6Y7Gtk84idn39MllwibIRf12K2TcYP3MHmP4wn5WRQal0L11aZ09So23B95IN3wly6SChufuKPac2I4zpxXQ0UHJEAdCNBWB1sJg2EKJseFSpZHubrnamA8leprLQ0/ddEiRKtq++w8YZIxTzPodc1wYdalhLcmzmB8oQ7t6DuR90tw7JCNZZf4uOjDJqZUo6TkyhRbD8eID9W31t4r2uvVvPpQxKanPX79ua8QUCXLAE9f+72on4QuCmMmLl2Fu1TW+gZuX+e2OPaAWMHJtQOv/8zxGpe81xYmQJ/l4FPtOO4PIdPej5xEWFIrmxct7VzcgsESuSzi5YpP34Gr4nAoQ= 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 4dfd09e65fa6..418402535319 100644 --- a/arch/x86/include/asm/invlpgb.h +++ b/arch/x86/include/asm/invlpgb.h @@ -63,9 +63,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 81f847c94321..82fed9fd5ac2 100644 --- a/arch/x86/mm/tlb.c +++ b/arch/x86/mm/tlb.c @@ -538,10 +538,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); } finish_asid_transition(info); @@ -1700,10 +1700,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