Received: by 2002:a4a:311b:0:0:0:0:0 with SMTP id k27-v6csp4802985ooa; Tue, 14 Aug 2018 10:45:47 -0700 (PDT) X-Google-Smtp-Source: AA+uWPy9I6EWxoRjNLCuiDrkIfxE0rRyNulpyuJhO70Xfm1rqeKRNZE4WmtGW9WzW2ByOhr4H3fY X-Received: by 2002:a17:902:8a97:: with SMTP id p23-v6mr21298838plo.21.1534268747225; Tue, 14 Aug 2018 10:45:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1534268747; cv=none; d=google.com; s=arc-20160816; b=lSYDtcCz8IeBazZD1P2QbodIMJEP6+w6C1s08KIKPgmqu3vdLevEPmSCUw2VR+PcqR 8VdmBgg2PwZ1WwZMiU05Ul78grpciAaTT5DZbEALIi0zdTrfjsKdQgG48Y8kh52LgJIH 61cS2IViJJocasG8XB6zEx+0nl0fwraQde1pRzYQ7KLZzxpscyRy/owDqHOdh5YLZPq9 cI0xp4nLFi5pbRgKNliC8dXtdhVX0+ABOIoY9CglUW861JozD5zRij+pP2ARD1CuoGC+ f5J3+VvBISDoILFVXoR5Xmj4dw6ur8yZwNPdt0mrrPqcO4hFKizxTCbX6Fz89GBNFpiX bjUg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=zhEd4wScYlC9s4tTL3J8h353AkFywj2z0RHNxAOOB3c=; b=ws6SsmE0Ar26lAlaETyAxH4dr5QlJVg6YTd53Rt0pjiHbx/OiX/9crhyTw9iGNpNYm aq9fsqUxlKVm6Sfg5VM4CUcmBKTCeNAyK/eWc+PVdQEYu3MxppMoCSmAOAhIMNPUnPCJ qL4wWPZte4MruzTx5gkuCgYDoIKkCSyIp0akIH7zPj+Th+78eychDg4iy2afJTrKmROF mx1T+sW3pIlBzvulOMpz8wph92lBMqwHXq8GmaWLPhPFrY/Yhi5iJMzthXrKv/Kd8JEe J/LR2dWtL3kelVhNHkicWvp7YyrsZDPcVOlxZkwclncdO7w9J4IRK32jxRwoZ1Fr/MMh TMyA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a61-v6si17328476plc.80.2018.08.14.10.45.32; Tue, 14 Aug 2018 10:45:47 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390766AbeHNUcr (ORCPT + 99 others); Tue, 14 Aug 2018 16:32:47 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:60058 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728642AbeHNUcr (ORCPT ); Tue, 14 Aug 2018 16:32:47 -0400 Received: from localhost (unknown [194.244.16.108]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 9D000C8D; Tue, 14 Aug 2018 17:44:34 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Dave Hansen , Thomas Gleixner , Tony Luck , David Woodhouse Subject: [PATCH 4.9 056/107] cpu/hotplug: Boot HT siblings at least once Date: Tue, 14 Aug 2018 19:17:19 +0200 Message-Id: <20180814171524.517633215@linuxfoundation.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180814171520.883143803@linuxfoundation.org> References: <20180814171520.883143803@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.9-stable review patch. If anyone has any objections, please let me know. ------------------ From: Thomas Gleixner commit 0cc3cd21657be04cb0559fe8063f2130493f92cf upstream Due to the way Machine Check Exceptions work on X86 hyperthreads it's required to boot up _all_ logical cores at least once in order to set the CR4.MCE bit. So instead of ignoring the sibling threads right away, let them boot up once so they can configure themselves. After they came out of the initial boot stage check whether its a "secondary" sibling and cancel the operation which puts the CPU back into offline state. [dwmw2: Backport to 4.9] Reported-by: Dave Hansen Signed-off-by: Thomas Gleixner Tested-by: Tony Luck Signed-off-by: David Woodhouse Signed-off-by: Greg Kroah-Hartman --- kernel/cpu.c | 72 +++++++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 48 insertions(+), 24 deletions(-) --- a/kernel/cpu.c +++ b/kernel/cpu.c @@ -54,6 +54,7 @@ struct cpuhp_cpu_state { bool rollback; bool single; bool bringup; + bool booted_once; struct hlist_node *node; enum cpuhp_state cb_state; int result; @@ -355,6 +356,40 @@ void cpu_hotplug_enable(void) EXPORT_SYMBOL_GPL(cpu_hotplug_enable); #endif /* CONFIG_HOTPLUG_CPU */ +#ifdef CONFIG_HOTPLUG_SMT +enum cpuhp_smt_control cpu_smt_control __read_mostly = CPU_SMT_ENABLED; + +static int __init smt_cmdline_disable(char *str) +{ + cpu_smt_control = CPU_SMT_DISABLED; + if (str && !strcmp(str, "force")) { + pr_info("SMT: Force disabled\n"); + cpu_smt_control = CPU_SMT_FORCE_DISABLED; + } + return 0; +} +early_param("nosmt", smt_cmdline_disable); + +static inline bool cpu_smt_allowed(unsigned int cpu) +{ + if (cpu_smt_control == CPU_SMT_ENABLED) + return true; + + if (topology_is_primary_thread(cpu)) + return true; + + /* + * On x86 it's required to boot all logical CPUs at least once so + * that the init code can get a chance to set CR4.MCE on each + * CPU. Otherwise, a broadacasted MCE observing CR4.MCE=0b on any + * core will shutdown the machine. + */ + return !per_cpu(cpuhp_state, cpu).booted_once; +} +#else +static inline bool cpu_smt_allowed(unsigned int cpu) { return true; } +#endif + /* Need to know about CPUs going up/down? */ int register_cpu_notifier(struct notifier_block *nb) { @@ -431,6 +466,16 @@ static int bringup_wait_for_ap(unsigned stop_machine_unpark(cpu); kthread_unpark(st->thread); + /* + * SMT soft disabling on X86 requires to bring the CPU out of the + * BIOS 'wait for SIPI' state in order to set the CR4.MCE bit. The + * CPU marked itself as booted_once in cpu_notify_starting() so the + * cpu_smt_allowed() check will now return false if this is not the + * primary sibling. + */ + if (!cpu_smt_allowed(cpu)) + return -ECANCELED; + /* Should we go further up ? */ if (st->target > CPUHP_AP_ONLINE_IDLE) { __cpuhp_kick_ap_work(st); @@ -978,29 +1023,6 @@ int cpu_down(unsigned int cpu) EXPORT_SYMBOL(cpu_down); #endif /*CONFIG_HOTPLUG_CPU*/ -#ifdef CONFIG_HOTPLUG_SMT -enum cpuhp_smt_control cpu_smt_control __read_mostly = CPU_SMT_ENABLED; - -static int __init smt_cmdline_disable(char *str) -{ - cpu_smt_control = CPU_SMT_DISABLED; - if (str && !strcmp(str, "force")) { - pr_info("SMT: Force disabled\n"); - cpu_smt_control = CPU_SMT_FORCE_DISABLED; - } - return 0; -} -early_param("nosmt", smt_cmdline_disable); - -static inline bool cpu_smt_allowed(unsigned int cpu) -{ - return cpu_smt_control == CPU_SMT_ENABLED || - topology_is_primary_thread(cpu); -} -#else -static inline bool cpu_smt_allowed(unsigned int cpu) { return true; } -#endif - /** * notify_cpu_starting(cpu) - Invoke the callbacks on the starting CPU * @cpu: cpu that just started @@ -1014,6 +1036,7 @@ void notify_cpu_starting(unsigned int cp enum cpuhp_state target = min((int)st->target, CPUHP_AP_ONLINE); rcu_cpu_starting(cpu); /* Enables RCU usage on this CPU. */ + st->booted_once = true; while (st->state < target) { st->state++; cpuhp_invoke_callback(cpu, st->state, true, NULL); @@ -2114,5 +2137,6 @@ void __init boot_cpu_init(void) */ void __init boot_cpu_hotplug_init(void) { - per_cpu_ptr(&cpuhp_state, smp_processor_id())->state = CPUHP_ONLINE; + this_cpu_write(cpuhp_state.booted_once, true); + this_cpu_write(cpuhp_state.state, CPUHP_ONLINE); }