Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp2335742rwd; Fri, 16 Jun 2023 02:31:26 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4XRJvFR4gCeV+5EZOKHhXbRM8YYB8nXDLsUF39wYeDUru3M+PdAFXLNi8AKZ30/0IJ+vdp X-Received: by 2002:a05:622a:14cc:b0:3f9:a6ad:e734 with SMTP id u12-20020a05622a14cc00b003f9a6ade734mr2068006qtx.3.1686907886321; Fri, 16 Jun 2023 02:31:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686907886; cv=none; d=google.com; s=arc-20160816; b=e7woOzlxzD3RBVe2MuJQ13niWTdCUsiBUNwMFMMnwwZ1m4fI05H8GavojPWY0+2SyY W4YX+onKIBBNFB5ehk0C+HbE40Oug2FcDVhtnf4AZOnQkX6jnFkqXzeeCVetqw64tFXS iSL4+RZeHnOoH79xd3zHW5aMdXpvohe9LB03Z7QsOqRp1qaZKYCgTzwLHTiZnFUN9RLk iqzNMs8Kp+YHQY82EQZR6NMb1THel7nJqj+ury4ENPX3rfppslDcHv5YHUrPkzKB3mG0 LVdTfauocqBIA3zj1a6pAf30zMhwpHyG37qSJnm030Uv7LUuoYeD1q5PlUyKLdbYe5Xh OgcQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:robot-unsubscribe :robot-id:message-id:mime-version:references:in-reply-to:cc:subject :to:reply-to:sender:from:dkim-signature:dkim-signature:date; bh=VC7zbcZySykoT8FxNRT4RBTp99pGWn+5WJTuuVp1xW4=; b=0n9EcI+Su8TSBbwwiA4YYPyGSghzO9Hbt0KPgduK4tKZNiPcWyVvdolGYU+9Yg0w01 FFUj1xwiMOJJufXCa+Z4SnN1hWbUxlbB6qoStoBnVWm3kF73G7lgkmWS6pJ2ZDl5vPOM 1r/yjo5Zj2q92rxmx2oBUORK2ywfs9bpzn9DmE4hxi+fLiMivuNJ3i2FnMpJ0ztX+WeO lXqv8APqNfvUAQtk6D4A86F/lrWRn033fH8mh8aaPz4CccnHHS3Rud9srdly7bS8jYb4 I++6RWn1fjgOhkL0zbJmDnGtx+/QYsISgysWvUXIK6nyAAPtIbmQ+GkVkYo3Sq2pxEPv ANFg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=dMzXHxho; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b27-20020a63931b000000b005304a8af2adsi15048769pge.392.2023.06.16.02.31.07; Fri, 16 Jun 2023 02:31:26 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=dMzXHxho; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344134AbjFPJ0S (ORCPT + 99 others); Fri, 16 Jun 2023 05:26:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41396 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344164AbjFPJY4 (ORCPT ); Fri, 16 Jun 2023 05:24:56 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0F82B268B; Fri, 16 Jun 2023 02:24:54 -0700 (PDT) Date: Fri, 16 Jun 2023 09:24:51 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1686907491; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=VC7zbcZySykoT8FxNRT4RBTp99pGWn+5WJTuuVp1xW4=; b=dMzXHxho552ShUgaJ5QNFjgT3QryEY+plTwrC7/IMUIUHHgZAE1lp1dF/fWbYL23+wJX5w AJn7y+Kt4yvi84l7Uy35fnHe5wKDeUoXnPGhcGQA5qjLu9HI4IG1b7M6bolw3bqGQrxCx3 hgoK5e0i8bnm8NQzxRPRKsFaFkftC0rJUrDcaEOAu1UmZLfXzZJSL0uTwWd8kb+wq+h5GY AvftTbMvpefZ/HrMTrlTkESbFPBFnsMmxm3e5oxl0kK0nUVyBtcWNjIPztwXzyANDj3jZE tC1VNMBXZaWtZ5Xf4+YsgdD1hONhy0Q4TLVDqodrl/mcNL7/VD++2Nr/4eNImA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1686907491; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=VC7zbcZySykoT8FxNRT4RBTp99pGWn+5WJTuuVp1xW4=; b=bGCyFfYNsiyt7GK6W1U/YVOTlHLvdF4bpkfBqE2qQHByzbwhX/0CUs3Gpm+6XWnaKXb2Zs 5X6TpA8W9zKxESBg== From: "tip-bot2 for Thomas Gleixner" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: x86/boot] x86/cpu: Switch to arch_cpu_finalize_init() Cc: Thomas Gleixner , "Borislav Petkov (AMD)" , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20230613224545.019583869@linutronix.de> References: <20230613224545.019583869@linutronix.de> MIME-Version: 1.0 Message-ID: <168690749101.404.11854299371702867449.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The following commit has been merged into the x86/boot branch of tip: Commit-ID: 7c7077a72674402654f3291354720cd73cdf649e Gitweb: https://git.kernel.org/tip/7c7077a72674402654f3291354720cd73cdf649e Author: Thomas Gleixner AuthorDate: Wed, 14 Jun 2023 01:39:24 +02:00 Committer: Thomas Gleixner CommitterDate: Fri, 16 Jun 2023 10:15:59 +02:00 x86/cpu: Switch to arch_cpu_finalize_init() check_bugs() is a dumping ground for finalizing the CPU bringup. Only parts of it has to do with actual CPU bugs. Split it apart into arch_cpu_finalize_init() and cpu_select_mitigations(). Fixup the bogus 32bit comments while at it. No functional change. Signed-off-by: Thomas Gleixner Reviewed-by: Borislav Petkov (AMD) Link: https://lore.kernel.org/r/20230613224545.019583869@linutronix.de --- arch/x86/Kconfig | 1 +- arch/x86/include/asm/bugs.h | 2 +- arch/x86/kernel/cpu/bugs.c | 51 +---------------------------------- arch/x86/kernel/cpu/common.c | 53 +++++++++++++++++++++++++++++++++++- arch/x86/kernel/cpu/cpu.h | 1 +- 5 files changed, 56 insertions(+), 52 deletions(-) diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig index 53bab12..e8ebafa 100644 --- a/arch/x86/Kconfig +++ b/arch/x86/Kconfig @@ -71,6 +71,7 @@ config X86 select ARCH_HAS_ACPI_TABLE_UPGRADE if ACPI select ARCH_HAS_CACHE_LINE_SIZE select ARCH_HAS_CPU_CACHE_INVALIDATE_MEMREGION + select ARCH_HAS_CPU_FINALIZE_INIT select ARCH_HAS_CURRENT_STACK_POINTER select ARCH_HAS_DEBUG_VIRTUAL select ARCH_HAS_DEBUG_VM_PGTABLE if !X86_PAE diff --git a/arch/x86/include/asm/bugs.h b/arch/x86/include/asm/bugs.h index 92ae283..f25ca2d 100644 --- a/arch/x86/include/asm/bugs.h +++ b/arch/x86/include/asm/bugs.h @@ -4,8 +4,6 @@ #include -extern void check_bugs(void); - #if defined(CONFIG_CPU_SUP_INTEL) && defined(CONFIG_X86_32) int ppro_with_ram_bug(void); #else diff --git a/arch/x86/kernel/cpu/bugs.c b/arch/x86/kernel/cpu/bugs.c index 182af64..9e2a918 100644 --- a/arch/x86/kernel/cpu/bugs.c +++ b/arch/x86/kernel/cpu/bugs.c @@ -9,7 +9,6 @@ * - Andrew D. Balsa (code cleanup). */ #include -#include #include #include #include @@ -27,8 +26,6 @@ #include #include #include -#include -#include #include #include #include @@ -125,21 +122,8 @@ DEFINE_STATIC_KEY_FALSE(switch_mm_cond_l1d_flush); DEFINE_STATIC_KEY_FALSE(mmio_stale_data_clear); EXPORT_SYMBOL_GPL(mmio_stale_data_clear); -void __init check_bugs(void) +void __init cpu_select_mitigations(void) { - identify_boot_cpu(); - - /* - * identify_boot_cpu() initialized SMT support information, let the - * core code know. - */ - cpu_smt_check_topology(); - - if (!IS_ENABLED(CONFIG_SMP)) { - pr_info("CPU: "); - print_cpu_info(&boot_cpu_data); - } - /* * Read the SPEC_CTRL MSR to account for reserved bits which may * have unknown values. AMD64_LS_CFG MSR is cached in the early AMD @@ -176,39 +160,6 @@ void __init check_bugs(void) md_clear_select_mitigation(); srbds_select_mitigation(); l1d_flush_select_mitigation(); - - arch_smt_update(); - -#ifdef CONFIG_X86_32 - /* - * Check whether we are able to run this kernel safely on SMP. - * - * - i386 is no longer supported. - * - In order to run on anything without a TSC, we need to be - * compiled for a i486. - */ - if (boot_cpu_data.x86 < 4) - panic("Kernel requires i486+ for 'invlpg' and other features"); - - init_utsname()->machine[1] = - '0' + (boot_cpu_data.x86 > 6 ? 6 : boot_cpu_data.x86); - alternative_instructions(); - - fpu__init_check_bugs(); -#else /* CONFIG_X86_64 */ - alternative_instructions(); - - /* - * Make sure the first 2MB area is not mapped by huge pages - * There are typically fixed size MTRRs in there and overlapping - * MTRRs into large pages causes slow downs. - * - * Right now we don't do that with gbpages because there seems - * very little benefit for that case. - */ - if (!direct_gbpages) - set_memory_4k((unsigned long)__va(0), 1); -#endif } /* diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c index 80710a6..18612e5 100644 --- a/arch/x86/kernel/cpu/common.c +++ b/arch/x86/kernel/cpu/common.c @@ -19,11 +19,14 @@ #include #include #include +#include #include #include #include #include +#include +#include #include #include #include @@ -59,6 +62,7 @@ #include #include #include +#include #include #include #include @@ -2362,3 +2366,52 @@ void arch_smt_update(void) /* Check whether IPI broadcasting can be enabled */ apic_smt_update(); } + +void __init arch_cpu_finalize_init(void) +{ + identify_boot_cpu(); + + /* + * identify_boot_cpu() initialized SMT support information, let the + * core code know. + */ + cpu_smt_check_topology(); + + if (!IS_ENABLED(CONFIG_SMP)) { + pr_info("CPU: "); + print_cpu_info(&boot_cpu_data); + } + + cpu_select_mitigations(); + + arch_smt_update(); + + if (IS_ENABLED(CONFIG_X86_32)) { + /* + * Check whether this is a real i386 which is not longer + * supported and fixup the utsname. + */ + if (boot_cpu_data.x86 < 4) + panic("Kernel requires i486+ for 'invlpg' and other features"); + + init_utsname()->machine[1] = + '0' + (boot_cpu_data.x86 > 6 ? 6 : boot_cpu_data.x86); + } + + alternative_instructions(); + + if (IS_ENABLED(CONFIG_X86_64)) { + /* + * Make sure the first 2MB area is not mapped by huge pages + * There are typically fixed size MTRRs in there and overlapping + * MTRRs into large pages causes slow downs. + * + * Right now we don't do that with gbpages because there seems + * very little benefit for that case. + */ + if (!direct_gbpages) + set_memory_4k((unsigned long)__va(0), 1); + } else { + fpu__init_check_bugs(); + } +} diff --git a/arch/x86/kernel/cpu/cpu.h b/arch/x86/kernel/cpu/cpu.h index f97b0fe..1c44630 100644 --- a/arch/x86/kernel/cpu/cpu.h +++ b/arch/x86/kernel/cpu/cpu.h @@ -79,6 +79,7 @@ extern void detect_ht(struct cpuinfo_x86 *c); extern void check_null_seg_clears_base(struct cpuinfo_x86 *c); unsigned int aperfmperf_get_khz(int cpu); +void cpu_select_mitigations(void); extern void x86_spec_ctrl_setup_ap(void); extern void update_srbds_msr(void);