From patchwork Thu Jan 23 04:23:30 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: 13947939 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 6C2C1C02182 for ; Thu, 23 Jan 2025 04:29:59 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 031CF280006; Wed, 22 Jan 2025 23:29:59 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id F2391280004; Wed, 22 Jan 2025 23:29:58 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DEC37280006; Wed, 22 Jan 2025 23:29:58 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id C0CF6280004 for ; Wed, 22 Jan 2025 23:29:58 -0500 (EST) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 4F4C0A0B92 for ; Thu, 23 Jan 2025 04:29:58 +0000 (UTC) X-FDA: 83037438876.17.AF684F0 Received: from shelob.surriel.com (shelob.surriel.com [96.67.55.147]) by imf10.hostedemail.com (Postfix) with ESMTP id C8072C0008 for ; Thu, 23 Jan 2025 04:29:56 +0000 (UTC) Authentication-Results: imf10.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf10.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=1737606596; a=rsa-sha256; cv=none; b=MEEvVM5gwICZw0g9ZFb3Ej4jEYeA46wne5+Q2HofgXLzYyzxtAU/IaYc9AkJ6ROQctEM7E eTix/DtU9v7assBkFo6RuzRWJNy/mWefyO+Uc0EZD1j2vqKq/b4e9t6wRJYiIdyohDLXZt Utb+oRA9BfD35pSu2n1lWtFaZi9hKmA= ARC-Authentication-Results: i=1; imf10.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf10.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=1737606596; 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=E11YoPwP2rmb054DCbWgK0xc/jXlKCd3xTPcG1+CCjs=; b=vIBd8cSqwltQcZj8bqfoQjCZ1hzvTdxRsi1g52tKNIFOA4FzhtGI+cfgF1vPT4HJjCANKu b48dN9rJqrddQbuN8xR8GU92HK7ut7x9RSzid+EX76dsqEl+K9pSipiABvLN82HNq7lL1y UBY7BQQK0XlLsUkJsBKOlponTLmH2JI= 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-3TDy; 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 11/12] x86/mm: enable AMD translation cache extensions Date: Wed, 22 Jan 2025 23:23:30 -0500 Message-ID: <20250123042447.2259648-12-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: C8072C0008 X-Stat-Signature: yss8owikf4ocern91i111or48m8roq37 X-Rspam-User: X-HE-Tag: 1737606596-842885 X-HE-Meta: U2FsdGVkX18EUgnnuS1I0ySPhcKJqYE2pmYaD6yHkZqnKKXC5gPPgoI/LGbRk+YPFDqwUiSXgXc4HViiYKb7mR3Q/rXeAcmCHhAxrN4Ljr5RQxDj+AIGrorZFXQXpA+Az6MK8CwjxiHWfCV6SHxwlPHqERiRni45rIhAOZr/TVLE0QS8shQOGuf0GFdpvYFSp1RqPFGuxbYn3bZ2ONUsDk4cAe4KvcYrdYzb8sWAJrjE9EWkIaGxwrPb/AdEC2/uOiRjXkV5K29V7VYDM8kf1QbZe/YQGIZby01zlJgxA+//1Mcp/u4Tj7CWQN/c0djosMdDuhiYYLvemLnEqdCh8PcumfOva8XdKB8ByhCcUvnlECPnaQO01biZZWuS0UMzO8Rhof9fFKjZyGyeE0uELRAKPA6/ai0vwE4DgYltIiUuX+CH7bHpfTSBDxQeBS861rOY48soIbU+AHMX3UQTXi8bMPktjlR9T365rZadzhLDSviZbVVk0QFqh2e3WrLBRBP0XTvaN0p8meKTJ/+hB7MQSH7jGBHab5eS7KnLTZ1i4GkUz4+0c38scDr2JhBi9TfrwxRTrQVjl7cl24K50N+ASdLyIezJrnNbrnjjmMtrCQJZhJW6kty7MMvMPZ/LVKDzELLT5xQdDIfcVgy9HSQaZsq/MmHYeBgsBr934SqG8k7l5fy1ja7U9xZXCgf8K4ErUaMRBwgFoytD314/4XzURHiLG2uDrPT80CWhvuFujuKZyTueV7eIENXbNkwhc9sDXMOQlcoHWV6mj6qy1hSXbwV1L3BatzPRx+bTMr5Ge1NWPFcJj8NwukLCfMhMAifdW71BLF+wSjUeVb/BaYQGwSImqqHgqUedIHvyYckttCOqnIRvx0m5NryDcenfpxqnQWxLD5zGqNHK6JKG2D9ZJ8WHZjckgDlX6uaDbztZcuzFieFUDGjqm811ZB9CZ2cwo7MrUAUpqXJAHUO r2gCeS5z h+0bN/ugPsLrKuP/5m+vgPnZujQGf+y/K28hoPh2os8UtSPNjfB4Bluu+Bz1tA8w92DmhznTj8ehfms7wDsF3IBAVRPSxGIHKrYI9Ficwj74CTEPmbEq5SMYb7GxdKlAU8fEsVyJz2apXpVkvKR1C28vCWT069RkhFQP/2kH3e3GCbuBa3VOlgJgT2rwlYmuDhes2b1neOBD8no7a+Bno/CHgfuoirqBlkNEVs12xhjrp5nmaf8njah/G8ELXFGqcZanRVFyxXcmve1RDeDADRaef20gm7GKHX3C/9e7MAczkIccC2gbIcVQ8NuDLFyHADs3zRus2IAgP03vlpLbgr4brwOUNDhMyZw0JIPs0aw4tC437cu4WZGm1sDilSP4oZL0T 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: With AMD TCE (translation cache extensions) only the intermediate mappings that cover the address range zapped by INVLPG / INVLPGB get invalidated, rather than all intermediate mappings getting zapped at every TLB invalidation. This can help reduce the TLB miss rate, by keeping more intermediate mappings in the cache. From the AMD manual: Translation Cache Extension (TCE) Bit. Bit 15, read/write. Setting this bit to 1 changes how the INVLPG, INVLPGB, and INVPCID instructions operate on TLB entries. When this bit is 0, these instructions remove the target PTE from the TLB as well as all upper-level table entries that are cached in the TLB, whether or not they are associated with the target PTE. When this bit is set, these instructions will remove the target PTE and only those upper-level entries that lead to the target PTE in the page table hierarchy, leaving unrelated upper-level entries intact. Signed-off-by: Rik van Riel --- arch/x86/include/asm/msr-index.h | 2 ++ arch/x86/kernel/cpu/amd.c | 4 ++++ tools/arch/x86/include/asm/msr-index.h | 2 ++ 3 files changed, 8 insertions(+) diff --git a/arch/x86/include/asm/msr-index.h b/arch/x86/include/asm/msr-index.h index 3ae84c3b8e6d..dc1c1057f26e 100644 --- a/arch/x86/include/asm/msr-index.h +++ b/arch/x86/include/asm/msr-index.h @@ -25,6 +25,7 @@ #define _EFER_SVME 12 /* Enable virtualization */ #define _EFER_LMSLE 13 /* Long Mode Segment Limit Enable */ #define _EFER_FFXSR 14 /* Enable Fast FXSAVE/FXRSTOR */ +#define _EFER_TCE 15 /* Enable Translation Cache Extensions */ #define _EFER_AUTOIBRS 21 /* Enable Automatic IBRS */ #define EFER_SCE (1<<_EFER_SCE) @@ -34,6 +35,7 @@ #define EFER_SVME (1<<_EFER_SVME) #define EFER_LMSLE (1<<_EFER_LMSLE) #define EFER_FFXSR (1<<_EFER_FFXSR) +#define EFER_TCE (1<<_EFER_TCE) #define EFER_AUTOIBRS (1<<_EFER_AUTOIBRS) /* diff --git a/arch/x86/kernel/cpu/amd.c b/arch/x86/kernel/cpu/amd.c index bcf73775b4f8..21076252a491 100644 --- a/arch/x86/kernel/cpu/amd.c +++ b/arch/x86/kernel/cpu/amd.c @@ -1071,6 +1071,10 @@ static void init_amd(struct cpuinfo_x86 *c) /* AMD CPUs don't need fencing after x2APIC/TSC_DEADLINE MSR writes. */ clear_cpu_cap(c, X86_FEATURE_APIC_MSRS_FENCE); + + /* Enable Translation Cache Extension */ + if (cpu_feature_enabled(X86_FEATURE_TCE)) + msr_set_bit(MSR_EFER, _EFER_TCE); } #ifdef CONFIG_X86_32 diff --git a/tools/arch/x86/include/asm/msr-index.h b/tools/arch/x86/include/asm/msr-index.h index 3ae84c3b8e6d..dc1c1057f26e 100644 --- a/tools/arch/x86/include/asm/msr-index.h +++ b/tools/arch/x86/include/asm/msr-index.h @@ -25,6 +25,7 @@ #define _EFER_SVME 12 /* Enable virtualization */ #define _EFER_LMSLE 13 /* Long Mode Segment Limit Enable */ #define _EFER_FFXSR 14 /* Enable Fast FXSAVE/FXRSTOR */ +#define _EFER_TCE 15 /* Enable Translation Cache Extensions */ #define _EFER_AUTOIBRS 21 /* Enable Automatic IBRS */ #define EFER_SCE (1<<_EFER_SCE) @@ -34,6 +35,7 @@ #define EFER_SVME (1<<_EFER_SVME) #define EFER_LMSLE (1<<_EFER_LMSLE) #define EFER_FFXSR (1<<_EFER_FFXSR) +#define EFER_TCE (1<<_EFER_TCE) #define EFER_AUTOIBRS (1<<_EFER_AUTOIBRS) /*