From patchwork Fri Apr 14 23:45:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 83599 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp736393vqo; Fri, 14 Apr 2023 17:08:34 -0700 (PDT) X-Google-Smtp-Source: AKy350YBFJ4C/H2jBt2LfMg9S27E1r4uEI4Mbkj3MY68m75SHf5QuP8ksCka5UjMpmePOmVOLMN3 X-Received: by 2002:a17:902:c94a:b0:1a2:79f0:f059 with SMTP id i10-20020a170902c94a00b001a279f0f059mr5602970pla.28.1681517313941; Fri, 14 Apr 2023 17:08:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681517313; cv=none; d=google.com; s=arc-20160816; b=mL4sKNwhSuTLdHeJQMU8ycuZXZLQ70LY3gzIfcl5j9WynQiOJi4XOh0YnHPM9CxlPp Sm2MfWtW0/9ATCe32OY7Cy0dZkW+vy5Y5+jVRikfusZw52LknTqOfDkHJ78w+LuQmiNw RG7QYHfAkMtcZYN2kYsemXCuLESfh2gjaWodKBv9niQkp2yqn/6G+zEyhU0RP5EqKgKs LVHaW8ELBihrad/6uYKbK754pwPjh3a89JvA2P4pOXw5KC7IyrbAkkiriRI2oTMoBsp6 aN/wTrzDObzkVJ0s4coXEzDqgqW1/SuuEyv7+344TCNUhCcYYC38tpyl/fZNGlT4z1iR M27w== 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id f13-20020a170902ce8d00b001a6b341b278si298247plg.399.2023.04.14.17.08.19; Fri, 14 Apr 2023 17:08: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 S229945AbjDNXwB (ORCPT + 99 others); Fri, 14 Apr 2023 19:52:01 -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 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1763198698699526144?= X-GMAIL-MSGID: =?utf-8?q?1763198698699526144?= 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