From patchwork Mon Dec 23 02:55:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rik van Riel X-Patchwork-Id: 13918383 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 9F3E7E7718D for ; Mon, 23 Dec 2024 03:01:48 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 18F926B0082; Sun, 22 Dec 2024 22:01:48 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 119726B0083; Sun, 22 Dec 2024 22:01:48 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id ED40D6B0089; Sun, 22 Dec 2024 22:01:47 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id CD8676B0083 for ; Sun, 22 Dec 2024 22:01:47 -0500 (EST) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 7871A121652 for ; Mon, 23 Dec 2024 03:01:47 +0000 (UTC) X-FDA: 82924722426.07.2DFFAE6 Received: from shelob.surriel.com (shelob.surriel.com [96.67.55.147]) by imf12.hostedemail.com (Postfix) with ESMTP id 6CDD240005 for ; Mon, 23 Dec 2024 03:01:29 +0000 (UTC) Authentication-Results: imf12.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf12.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=1734922870; a=rsa-sha256; cv=none; b=azuQRrO3B0DvloQflZ6ZMtF5nNb2+1dlaUKfnjU8wTIQqbnMmuWD5UNE6vSQpX+GYY28hp /D5dwKSObHoZTNINt4V3hpKuR4OWnrFpg61SJH00+n2nhsAArCddepJxDZ88uBvwYtx/Ro XFwfa7tL0GmG33MpzGPaMTgCcqOeHl4= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf12.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=1734922870; 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=XkfGOJSqy4hVcRMB7cZA7dAORYByX/Np69HzIE+fTbc=; b=Il4OErN3oAltItEGiCF/aMfs6AnEB08MyfMe6GQmF8rMkelMyB8Y/tCXU06oyjqRvPDGl0 Kb9OUhOInqhoF0+AIpAKFisXT20MrV3joz0CoHPtygSLHhfK0gwDFdjjgCnXb2Nx2COnN2 fUaCwxN7PjnMPHjX+uJ7fo1f2cU19HI= 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 1tPYdo-000000001Ih-3jUV; Sun, 22 Dec 2024 21:57:56 -0500 From: Rik van Riel To: x86@kernel.org Cc: linux-kernel@vger.kernel.org, kernel-team@meta.com, dave.hansen@linux.intel.com, luto@kernel.org, peterz@infradead.org, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, hpa@zytor.com, akpm@linux-foundation.org, linux-mm@kvack.org, Rik van Riel Subject: [PATCH 03/11] x86/mm: get INVLPGB count max from CPUID Date: Sun, 22 Dec 2024 21:55:09 -0500 Message-ID: <20241223025751.3268975-4-riel@surriel.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20241223025751.3268975-1-riel@surriel.com> References: <20241223025751.3268975-1-riel@surriel.com> MIME-Version: 1.0 X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 6CDD240005 X-Stat-Signature: kriki8tgmxu9n9os6ng5wm6umrujabyz X-Rspam-User: X-HE-Tag: 1734922889-717194 X-HE-Meta: U2FsdGVkX1+xNCEzNCyrB/2gSM4jL/KptWThL0873t1LoqKcIg/bwwK5GqOm9EwAE3pxYnj+ujJ3godoYETCb5jGiT7eUbNd8omIzAYSKtGgdY+1+28QznoeXsEm6Q/bpM0FhOgFicausWOkhyiQ7mOK4Ow6wDJd7eV778nq+L7ZQZVMNPCQgXl7LMnoGWCR1QRR3usxipIgypIue21BN6eoJhcqJN5AsHlHh//3lLRjASYQ1GeoqB7A6krrn0aqyzCYQx1irjorDYHbAhH5heotCxoIKbhcuBxx8edfFIRbx7gyqx617B5FvKQlyk0MiNK6kA1HtpZSoGjoikwEUFBZkH5ZcDExU0N1DaPmDIgqontbdS02J131dwHFtPxCgvo6od2WR0jQcWfZXXJkxHA72vdo9IP/DAwWXwfFZI43EcO50eDhTDMuqQ/yMFzJyugvKucJxqqkNphJhaHEm3oZXMXK2VAmB72nupTTcbbwUoeKIW7tYUD1hH4/VZSCZ6H8gijTLLW5uxhmVnaKSJ4TRTrTMeYXjiHN25GcHSJ5mu8l8x5U/kvLriOQnkXvwdgQLIzYk5NMxZ6/G6K8yVkEd6PKEyUVKQaRqhK68c7aCmg/4NYcdsEzzS0pogseJIMD91j7ql0F8wnUXyXMoS6ez2WXaVOJ/fgG8NC0nRyk9eeODcpZXU0m0nZN3bYFbzACtGKk/zGJmoNJCpB2IzNZ2RqF4tSzU8jetvWpHdsUARtNof17hhB72NrgFXlYwhA+O7ldUOZnTDyD8aBvjrtUe16G8RYX5R5ZbMUpjC4yeq1nA96lZiwcA2oMl3XeDYd7wmrSf9B7sjjSg0lAg6yNYGlFCwSwtmai0dhfbT+1zp8NaVnaylWrdHls8FGNIVn5gzssrS9uW+vl2PL0qkHBZ562jsBw1jvQPKepEfZAJzY1pktEvt3sHG1mks45aDtwpT1XELuMhH3wGZg vqNA+aq7 HmWKg+Q0lrbYJe2ePWEaHGYcb0OOpdoR9Ao5jgU9uCG3pF8wfU/8Nw/ea3ZNeQ5ipyQ9fUJ1TbTM0by1O/71lkwLUHURU/0lyybBQKvZ/aEat5Dk7+2XFujX5LOwkKiOvzuC+IHO5NnpRBjwUgjhqoGFo/elNGkSlrNJaXpm9PVcS9ERcD17mzzDyUmIi5KvzhR3YKr9siSWsTtOtJy2Ivq6wKQNGcXaof3lmbesHLQNzWmchLkp3IDxjMG168iz0XogXgvcLY6cdoN/Zz6PJnUkXoVUsH1F519O0Opq8SKUaU5J5ty53SiqlOXsSBE8VwZqQ 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: The CPU advertises the maximum number of pages that can be shot down with one INVLPGB instruction in the CPUID data. Save that information for later use. Signed-off-by: Rik van Riel --- arch/x86/include/asm/tlbflush.h | 1 + arch/x86/kernel/cpu/amd.c | 8 ++++++++ arch/x86/kernel/setup.c | 4 ++++ 3 files changed, 13 insertions(+) diff --git a/arch/x86/include/asm/tlbflush.h b/arch/x86/include/asm/tlbflush.h index 02fc2aa06e9e..7d1468a3967b 100644 --- a/arch/x86/include/asm/tlbflush.h +++ b/arch/x86/include/asm/tlbflush.h @@ -182,6 +182,7 @@ static inline void cr4_init_shadow(void) extern unsigned long mmu_cr4_features; extern u32 *trampoline_cr4_features; +extern u16 invlpgb_count_max; extern void initialize_tlbstate_and_flush(void); diff --git a/arch/x86/kernel/cpu/amd.c b/arch/x86/kernel/cpu/amd.c index 79d2e17f6582..226b8fc64bfc 100644 --- a/arch/x86/kernel/cpu/amd.c +++ b/arch/x86/kernel/cpu/amd.c @@ -1135,6 +1135,14 @@ static void cpu_detect_tlb_amd(struct cpuinfo_x86 *c) tlb_lli_2m[ENTRIES] = eax & mask; tlb_lli_4m[ENTRIES] = tlb_lli_2m[ENTRIES] >> 1; + + if (c->extended_cpuid_level < 0x80000008) + return; + + cpuid(0x80000008, &eax, &ebx, &ecx, &edx); + + /* Max number of pages INVLPGB can invalidate in one shot */ + invlpgb_count_max = (edx & 0xffff) + 1; } static const struct cpu_dev amd_cpu_dev = { diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c index f1fea506e20f..ef2b49edca25 100644 --- a/arch/x86/kernel/setup.c +++ b/arch/x86/kernel/setup.c @@ -138,6 +138,10 @@ __visible unsigned long mmu_cr4_features __ro_after_init; __visible unsigned long mmu_cr4_features __ro_after_init = X86_CR4_PAE; #endif +#ifdef CONFIG_CPU_SUP_AMD +u16 invlpgb_count_max; +#endif + #ifdef CONFIG_IMA static phys_addr_t ima_kexec_buffer_phys; static size_t ima_kexec_buffer_size;