From patchwork Thu Jan 16 02:30:34 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: 13941165 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 E9380C02180 for ; Thu, 16 Jan 2025 02:33:05 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id EE2756B009A; Wed, 15 Jan 2025 21:32:58 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id E4383280001; Wed, 15 Jan 2025 21:32:58 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C6EDB6B009C; Wed, 15 Jan 2025 21:32:58 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id A1E926B009A for ; Wed, 15 Jan 2025 21:32:58 -0500 (EST) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 6439AAEF31 for ; Thu, 16 Jan 2025 02:32:58 +0000 (UTC) X-FDA: 83011742436.16.5D85BDF Received: from shelob.surriel.com (shelob.surriel.com [96.67.55.147]) by imf13.hostedemail.com (Postfix) with ESMTP id D996E20006 for ; Thu, 16 Jan 2025 02:32:56 +0000 (UTC) Authentication-Results: imf13.hostedemail.com; dkim=none; spf=pass (imf13.hostedemail.com: domain of riel@shelob.surriel.com designates 96.67.55.147 as permitted sender) smtp.mailfrom=riel@shelob.surriel.com; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1736994776; 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=sMKZVRVMqWB/k/G/H8VJSeqcX/A9uaqo7sZv8mUxtLQkqem6C5MJLpk2CFiWf0yX1JH0J3 r0v6AyCE9ainIUaJ0SiwCnGD3oiaopLmnsBElDYz9tzPRvLakngswRS8kr0r9rqOUf6kwM CfnivNMGe3hasK9vsJU91wTpCr6SUVo= ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=none; spf=pass (imf13.hostedemail.com: domain of riel@shelob.surriel.com designates 96.67.55.147 as permitted sender) smtp.mailfrom=riel@shelob.surriel.com; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1736994776; a=rsa-sha256; cv=none; b=0WzVLvUUQ3rCkg3l4itcahexZtU5itTouCnifpFsPQj3Fh9unMUWgl7ZdfJwuae2lofG2A dwM4q4Ndm2zTjwrKdGplZD9i67s34vDDlVzGHMnQa+yOsqJREcX01p2qz0al30wb1qXr7O +sWFO0LutHw6PKffVAmDO2h3oev8uAw= 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-3vhs; 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 11/12] x86/mm: enable AMD translation cache extensions Date: Wed, 15 Jan 2025 21:30:34 -0500 Message-ID: <20250116023127.1531583-12-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-Rspamd-Queue-Id: D996E20006 X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: mu3d8eyqj54iqkoo9yqhse5xzisgxfee X-HE-Tag: 1736994776-612478 X-HE-Meta: U2FsdGVkX1+37AvbB4696q+72UGiNRNmWUg+a/IeXUmMRO4KRmku3vq6W7IChdrPHld0pmh1ac0q39My5zufX5KzDlduJse8E+3flUVlWIZZnZ7GSR6R/VCeajfvvioGFIYWUi4ItfVTais0P3l5rWUbAsBnDg2hf1e3ExxfpBd2Ox4L4P8Pl7nwOpONpq001adafkMj+tJoB52Y3yQ5spGjxTpC2g8zJkRWbB8U+LaL6ulZDLmKJFdwCGnXMPYK8yMw22S01osqRigRuAb77YB01oa9qfVdKB78fRlhWC+HsYmM5hFzM/Tzh/a5za3ZWbxEQcaX6hhDaXoJz0emkJSNCYlp6w2I0D3SFFxOW46NY0UnltjV2BgWZGkd0l961DFu6AUIYutsATBGFS9foh37/K11k0e5R4bSi83A+Xk5ojc12TFYckGq3xPaDNEbNksIVZzs4CnaB5YwtG58JQVqWZcvCU8naoTpjqo6wlr/WnPsa+yzP49QX6TZ0v0bo514RQxUSUTUVzI1+bCCILL1itfGl814oJZvivJ6iQDNGyIdmVliThdETQY1Y5SULPG0ZIBsn26gHIj5vyfoz/3uVb32fi/ZixWxdirNrPH1wxfxDOOf3dtj50GydDSzBnW6N41MfCVpa/hrn04dIrCupfU+9WJMVLu2zUPvpMj06wGPS/3ZqKv2OP3w8VVZTX0D0Lp3s2oGmFbyqywMQRr1cm9NDvblUplgblSkEi+JrwjxYAwdOu3gdyWmY4rw/9594E3VIhOxvc+1DiQ0hEz4I8nD9Fbx6zTjpa9kCuKMGuaQo6AI6uir9HgBsSPqgVKE+yGQTa4mDfwKIIfQUOVPUd1oRe5IkvsnFk3qetRP+PdrnVlhAjumg4K2/MtRHk5Q7DA/qgI07wi7zkPrhzI4hCW7EjjHQf6DELzIWQpzTVhBNNj+MG5OgHvZ2Ish4mUxoSU6IOykYsXcWGI ae+TCMdz NY1r6qw6c5FrHXiwLOfg/vxPMvHamwXVQ5yYMMIj+Zo9lEc4FBY7xhMfl2CV4rg5qje7r3N4LddDBZIO+WgSs/bZigJRRo/TrqlcNqezkh2MEmPMbq0LRZRQquw3lyZ7ib6eSwig3qIcU9UUHqw3cp0P7RRq8NAS38FSwIgTI34ARqeEjtZfht/Rv5WEv3dWDVIf2ogElxP4cnsW1fUHWjmTedaLB2WGyt8gflTooZHwjHjLH/Wqn47ILUNzjSi+q0bWjvgKaQrZ5EsFBCJNotHrR8Fbo5L3cu/zJNOhgPJYBbtItMV2SlyWkX63+5SiYvl4GiPTqV91rASLTKCZOKEsEG4tdyBJJQefKsVswFq1pB3v1Y531yi8ZRI5ZD0fn2/S62BimkC/F7c7asxtsKzc7kn78JOzEIikU77QXapz81bE= 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) /*