Received: by 2002:a05:6358:53a8:b0:117:f937:c515 with SMTP id z40csp1221640rwe; Fri, 14 Apr 2023 16:54:34 -0700 (PDT) X-Google-Smtp-Source: AKy350axQ/EGsJSDqVoOnKz3iHuxTOz6IAs/iVqtSuB5CO+EOgpWXBBoIIaMBLELfoVqaW57MrXR X-Received: by 2002:a05:6a20:279d:b0:d9:bf06:cd85 with SMTP id s29-20020a056a20279d00b000d9bf06cd85mr7084484pzf.25.1681516473793; Fri, 14 Apr 2023 16:54:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681516473; cv=none; d=google.com; s=arc-20160816; b=sHHNtQkzrsYE3HAnEETyTG6iljcNirirGACv4RuibwTxcu5dBhoYf+gfDdRRfhD1pB n7ubY+ZzZCXOiNi9YFf2XkoW410uLO/2vRudNQ//q5uAik6+mVHXDC1xyOCXdYXFy71v miylcBna1MB9Uo2lRTMqKOzMRt8r0isa5i0yCf3DJ0ABTlS9EA4KnOqqkyVhUYsrpHIl ggkX1AY6FW8TU2rQwZnYTvOt5RhK+D3Gr3jT9A32yvzvGE2DX2oBOBwuMh63+F0Y59w1 AYYZeHUT4Ngnzc3kqIREFHyAMMSUDAEtzDEGbryKDE//pnVA5Ixhw5cT2pJD9TtmP8fu 5cDg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:date:mime-version:references:subject:cc:to:from :dkim-signature:dkim-signature:message-id; bh=6cGHgynMBCaHRwYTrISGgGUY8IfBttwd4gSW6/8ncwo=; b=AqIof15ytnn/ru4LSla16YwuP54A861Svf18Ea/MtSk2w9IA4qiiUdPGZWtgDpEb33 m3iCS/hhreAWpjNJsQPZCiiS3ptv9WTtrmSh17xhIlBtxBfgnsKIMQ7UCQMNxYWgvaGN OMd4OCWPme1iBbqoomNYKAR8YyJg/a7ToeWYpEmA+OnH38mShNsPsLQ9AqNfc27ibY93 JTM0Vom01TqPJGvMbufl/WVSgF+iQX2vRsXckgv8hNiOuAsnB/s2nWS8qpBqUtYgWlfB O6OzboQWHqp21o4fxadKqE1PPOfC9RnrwlWvzD+08N913kgg5mFLTHvx+s5Ml30h7YyY aHfA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=Y6MvVoIR; dkim=neutral (no key) header.i=@linutronix.de header.b=62z6QxHl; 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 w80-20020a627b53000000b006351cdc5e2fsi5536269pfc.292.2023.04.14.16.54.19; Fri, 14 Apr 2023 16:54:33 -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=Y6MvVoIR; dkim=neutral (no key) header.i=@linutronix.de header.b=62z6QxHl; 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 S230240AbjDNXwA (ORCPT + 99 others); Fri, 14 Apr 2023 19:52:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35544 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230219AbjDNXv6 (ORCPT ); Fri, 14 Apr 2023 19:51:58 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F11B959ED; Fri, 14 Apr 2023 16:51:27 -0700 (PDT) Message-ID: <20230414232311.441918776@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1681515912; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: references:references; bh=6cGHgynMBCaHRwYTrISGgGUY8IfBttwd4gSW6/8ncwo=; b=Y6MvVoIRD+b308pDJWowuLkJP8xTk8BgVllbAchtET5SCLxH3pPaTbpOYvBSvJgt29AjQn ezcDEAwpvw4go5HJCn0jDdZCGPT9MLW24qpZKb8kz2KJNNnr6JcyXOPyaUGlM/ANv9N+fq tuEJRuRxzNty3GrkhGsgHYpRhP/0DX3AEiMTFdAHD/hkrve/Z/OGirQHyoZehUi+ZLj2of nh0+zW/XB9E47Zv4MWfj7UgDu31M48dyxxMexXPIhf0Fh2Xfz56PypK/Z4RNZ1QuLpDfkl MzM4X40h1quxb59BK38sroOGy3J6fRyyYS1Nn/XWNH7x+1QZ0XFumeRWVGSB2A== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1681515912; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: references:references; bh=6cGHgynMBCaHRwYTrISGgGUY8IfBttwd4gSW6/8ncwo=; b=62z6QxHlYDjrTs4WKqbuHCfVc8G+x+AUIAn0i55mZeGFgkDCFd3an/Sr2oboSn6ZUcOcEh Lf1/KZWBw97ffRDQ== From: Thomas Gleixner To: LKML Cc: x86@kernel.org, David Woodhouse , Andrew Cooper , Brian Gerst , "Arjan van de Veen" , Paolo Bonzini , Paul McKenney , Tom Lendacky , Sean Christopherson , Oleksandr Natalenko , Paul Menzel , "Guilherme G. Piccoli" , Piotr Gorski , David Woodhouse , Usama Arif , Juergen Gross , Boris Ostrovsky , xen-devel@lists.xenproject.org, Russell King , Arnd Bergmann , linux-arm-kernel@lists.infradead.org, Catalin Marinas , Will Deacon , Guo Ren , linux-csky@vger.kernel.org, Thomas Bogendoerfer , linux-mips@vger.kernel.org, "James E.J. Bottomley" , Helge Deller , linux-parisc@vger.kernel.org, Paul Walmsley , Palmer Dabbelt , linux-riscv@lists.infradead.org, Mark Rutland , Sabin Rapan Subject: [patch 36/37] x86/smpboot/64: Implement arch_cpuhp_init_parallel_bringup() and enable it References: <20230414225551.858160935@linutronix.de> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Date: Sat, 15 Apr 2023 01:45:12 +0200 (CEST) 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 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 Implement the validation function which tells the core code whether parallel bringup is possible: 1) Valid CPUID leaf for APIC ID retrieval. For non x2APIC systmms leaf 0x1 is sufficient, otherwise leaf 0xb or 0x1f must be available. 2) Prevent parallel bringup on encrypted guests as this requires a different handling of the CPUID leaf retrieval via a call into the trusted firmware module. This is what the #VC trap handler does later on, which is not available during the very early startup. Originally-by: David Woodhouse Signed-off-by: Thomas Gleixner --- arch/x86/Kconfig | 3 +- arch/x86/kernel/cpu/common.c | 6 ----- arch/x86/kernel/smpboot.c | 49 +++++++++++++++++++++++++++++++++++++++++-- 3 files changed, 50 insertions(+), 8 deletions(-) --- a/arch/x86/Kconfig +++ b/arch/x86/Kconfig @@ -272,8 +272,9 @@ config X86 select HAVE_UNSTABLE_SCHED_CLOCK select HAVE_USER_RETURN_NOTIFIER select HAVE_GENERIC_VDSO + select HOTPLUG_PARALLEL if SMP && X86_64 select HOTPLUG_SMT if SMP - select HOTPLUG_SPLIT_STARTUP if SMP + select HOTPLUG_SPLIT_STARTUP if SMP && X86_32 select IRQ_FORCED_THREADING select NEED_PER_CPU_EMBED_FIRST_CHUNK select NEED_PER_CPU_PAGE_FIRST_CHUNK --- a/arch/x86/kernel/cpu/common.c +++ b/arch/x86/kernel/cpu/common.c @@ -2127,11 +2127,7 @@ static inline void setup_getcpu(int cpu) } #ifdef CONFIG_X86_64 -static inline void ucode_cpu_init(int cpu) -{ - if (cpu) - load_ucode_ap(); -} +static inline void ucode_cpu_init(int cpu) { } static inline void tss_setup_ist(struct tss_struct *tss) { --- a/arch/x86/kernel/smpboot.c +++ b/arch/x86/kernel/smpboot.c @@ -58,6 +58,7 @@ #include #include #include +#include #include #include @@ -75,7 +76,7 @@ #include #include #include -#include +#include #include #include #include @@ -128,7 +129,6 @@ int arch_update_cpu_topology(void) return retval; } - static unsigned int smpboot_warm_reset_vector_count; static inline void smpboot_setup_warm_reset_vector(unsigned long start_eip) @@ -247,6 +247,8 @@ static void notrace start_secondary(void #endif cpu_init_exception_handling(); + load_ucode_ap(); + /* * Sync point with the hotplug core. Sets the sync state to ALIVE * and waits for the control CPU to release it. @@ -1251,6 +1253,49 @@ void __init smp_prepare_cpus_common(void set_cpu_sibling_map(0); } +#ifdef CONFIG_X86_64 +/* Establish whether parallel bringup can be supported. */ +bool __init arch_cpuhp_init_parallel_bringup(void) +{ + unsigned int ctrl; + + if (boot_cpu_data.cpuid_level < 0x01) { + pr_info("Parallel CPU startup disabled due to lack of CPUID\n"); + return false; + } + + /* Encrypted guests require special CPUID handling. */ + if (cc_platform_has(CC_ATTR_GUEST_STATE_ENCRYPT)) { + pr_info("Parallel CPU startup disabled due to guest state encryption\n"); + return false; + } + + switch (topology_extended_leaf) { + case 0x0b: + ctrl = STARTUP_APICID_CPUID_0B; + break; + case 0x1f: + ctrl = STARTUP_APICID_CPUID_1F; + break; + case 0x00: + /* For !x2APIC mode 8 bits from leaf 0x01 are sufficient. */ + if (!x2apic_mode) { + ctrl = STARTUP_APICID_CPUID_01; + break; + } + fallthrough; + default: + pr_info("Parallel CPU startup disabled. Unsupported topology leaf %u\n", + topology_extended_leaf); + return false; + } + + pr_debug("Parallel CPU startup enabled: 0x%08x\n", ctrl); + smpboot_control = ctrl; + return true; +} +#endif + /* * Prepare for SMP bootup. * @max_cpus: configured maximum number of CPUs, It is a legacy parameter