From patchwork Mon Jan 20 02:40:19 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: 13944703 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 87083C02188 for ; Mon, 20 Jan 2025 02:42:39 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DC5656B0089; Sun, 19 Jan 2025 21:42:30 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id AAFEA6B0088; Sun, 19 Jan 2025 21:42:30 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5CBD1280003; Sun, 19 Jan 2025 21:42:30 -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 005196B0095 for ; Sun, 19 Jan 2025 21:42:29 -0500 (EST) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 92EFF42A49 for ; Mon, 20 Jan 2025 02:42:29 +0000 (UTC) X-FDA: 83026281618.15.0303CBF Received: from shelob.surriel.com (shelob.surriel.com [96.67.55.147]) by imf30.hostedemail.com (Postfix) with ESMTP id 185E38000F for ; Mon, 20 Jan 2025 02:42:27 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf30.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=1737340948; 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=nLl4K9219osqvP9pDmLmSTTjqwTvZM45V9fFhQoPFv9L5eXCX3oCbq1o1XnHMCSrc/F11w Oy/TSZX2g2ktlrtuKB2nIdKRg7PyOKFDlNeDg79kDU0BscYyD/QjWR0eNhmWXNBI6ajhqj zAYlHGgGayP9ENGx0eYhBKHwTXEdQFY= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf30.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=1737340948; a=rsa-sha256; cv=none; b=79bBq1jjSlH6VnbMwfskoJmCtwaTa1WiEABEVXCH9nLZdQaJ+Ai+njrGMTOIcmluqEahDW 1JVq46gDWA6hA9uDA9F4nwqn1wL6JDJxQEk9LdpRQ211hR1JJ/LqFJM95DOibvw0KRYHkT bz7oA1oWda3Jgar72OIyZPP8tLYhaXA= 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 1tZhis-000000002w5-1cIp; Sun, 19 Jan 2025 21:41:06 -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 v6 11/12] x86/mm: enable AMD translation cache extensions Date: Sun, 19 Jan 2025 21:40:19 -0500 Message-ID: <20250120024104.1924753-12-riel@surriel.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250120024104.1924753-1-riel@surriel.com> References: <20250120024104.1924753-1-riel@surriel.com> MIME-Version: 1.0 X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 185E38000F X-Stat-Signature: u6e7qsc8h11htpwnjjf81qoxq448uxf8 X-Rspam-User: X-HE-Tag: 1737340947-186215 X-HE-Meta: U2FsdGVkX187jFRJ9ckXC3Nd9J0cy27MNoHtBf+AMXEXCXu0ItU59FJu907fAwAjf7rpUbxMzXxxZkoJGw5ilLLYgG1u23yQg7w/En9SoB9X3R16n/Y0a6l2Y50xvz/2XWMoY+K+vl0dvU05Od8Npb/JNjONcKCl7nIxJdC/rCzrDsoXFssPZbjxnbfMerfMrPZ/xizbDGBQsPSqx+2lA5g+J8j8ywlzvOLK3Oj8ijRKAapekprvhuPNavVb9L/uCO3kLGYBn6xN3AsEG52j0RGdL5tTXP72zXy04OLer0hf4W2vbMgUlJqK0PDXO+swgIEFeFv5aQuAQSEod8tAN3CvmIgfovQthsqOx1n4kLhGJ1QF+r32Nc7IH9FodiGUhY4Fcy5hKXWwux1OshM4Wc8A8YQPASjmmajOVJn0DDA61KVTZEHwm479xsU9jK/EBMcKx8GEF8b/fjG8pGcgR9e8IMSIaFq5EUsHnzEEOeVyaXPgLbxjUbid4mEd1ZavThaC3cpr4nohriUKAqvMm9WdlXWNy3z34IX/EPJFXsn9nQx3ewnkho4B9k6JurJS/I8iiq5jolCm5yM0myQ7CMO3iFT0aKPayyjwhoDmlw2guBeQ99Pc7oELszAEGYT4GX4/WYLZ1s1ZQUIVl0d5DW8S9uz0SEGiC2aqIWdmRgTGXWiOlWqKaiVU+tWly6k6+H9E2lM0i89nbhDymVVLHAMKsJBFBqTPjfPkDfqp23dNFQ1wbWRADhckwwfFkdM0/rsrmoRkIv5EAqZ/Gu20RBcUSsM7mtnQi8BVORSa0N2Xjx7NCXrr8foKerd61a9+HFK3b9bZTz+LHZ46EgiKGv3TWQE5pdgyQlq5TzF4dD+bBNbFeLglTdR61pKAiYbuh7EWGfNu7xb2+blp1xToYEzvCko1HGZt5F18hy6SpLL2XFW38H3sS46SOCCB3EiAnn90DrXvz4X7UTEPwWd cfwWS5rb zyTfOuGim0ns6diSMzXekiWWSeTXdjITzKvOsX7UDcbMaX381l0Qeub9rZX2pjcVhNexAhRksUkwXCG8LOvdM5bAt2Vp75xMnLcEpdobr8UVoi9RWVLm55qFRNFXN9nBMg0bpzZuwgpl8yBiO0fL6SXmkEF+unYsYd6IawBZFm5ZyWCJnoi/ENe+tsGU7F9B6GEhcG2kyKfhR+W9VfRPHOqB1OTOyZTEnDch2Wei94yPraF6x7mOAO/egvewkQsL2jw/C8r8o/FEBAi6QePYsLj9rGVBlgYxuyonZhna9Au/sH5gTdb6nZjzP/jiWBcGVB7NzSxGiw3mAcuMe8nGcaoZ7zsDo+PZyN5ipWKqtJa+6HE325NOqOFChc6rihlGk72Ho 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) /*