Received: by 2002:a4a:311b:0:0:0:0:0 with SMTP id k27-v6csp4784600ooa; Tue, 14 Aug 2018 10:30:23 -0700 (PDT) X-Google-Smtp-Source: AA+uWPw9tYSVHhUOS6R0ctQ07iyxp8M4Qx1ineIVy8S/Elj3IBFExV00bnjBKMyf33QcgsZwsJNY X-Received: by 2002:a62:9541:: with SMTP id p62-v6mr24094923pfd.152.1534267823072; Tue, 14 Aug 2018 10:30:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1534267823; cv=none; d=google.com; s=arc-20160816; b=W0gmLkZfNsO9dM+6W9f/45+7zGZvzDnuIXOJgzOJyy37nir95ApsKIGRJH9jzjfUMb DTFPO7jhtyePPTXRKMNFdPs+YYd6h4CP+IUZsw3ssgn2C7E8ZgrDZp+t1KRncmI/gd3w eD7mv0O8CLhpMyPkW8RKZ4zGLlngdMgsH/BWcgiVmL7Xks0yq5+CLoDX7g27PlkBACks 3Vfhcj1vRQ64ZJJTb4rHkNshUxLIdNR27/NTy6aXL/j0/rn6VYwC3TG5OiJlGntDjPzV cnr9HWzk6yjRMQ3ESE0tS4peSlxS6svVJmKuj6DTeAYWVEyWKVbKNjeaBqGVd75+xjtO tbBQ== 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=iu5z41yPMwXIEt4+ax9BraNWLVKVG75+ZTjYbizMty8=; b=Hx9elEKCkyHoWxp99uMqy0wAOjiKHV52PaAlQ6q2Iy2nol7jAY4DCn5tyairoLx67X XBP6zbo2bzeYS0JpD0X5VTH1Rtc7BlK9Kq9UkojL3JLy62Rp9kL0KXT8aWagWx5GSuS9 kIgo4vI3GUXSJ5emBMchz1NJmrlMpEnMkHFDp8ULmbhw4DKJEJTqSzrSsAD2hgfWtkuv ibpjs+BBnJyxeFxLyW+5GjmS08lnbZtRSB6CDhi0oVMfNW1DvjZ1mF8QotKIDF+EtUhO KEn5UPU/gFhr45MR6twfQQcI2Rcc9liu8cOFJRnk+k/aoQvM5rcVmi/CUqBtIGTM8+mo uIqw== 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 e12-v6si19083452pfn.322.2018.08.14.10.29.45; Tue, 14 Aug 2018 10:30:23 -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 S2388593AbeHNUPD (ORCPT + 99 others); Tue, 14 Aug 2018 16:15:03 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:52362 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387702AbeHNUPD (ORCPT ); Tue, 14 Aug 2018 16:15:03 -0400 Received: from localhost (unknown [194.244.16.108]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 2C756CD8; Tue, 14 Aug 2018 17:26:55 +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 Subject: [PATCH 4.18 34/79] cpu/hotplug: Boot HT siblings at least once Date: Tue, 14 Aug 2018 19:16:53 +0200 Message-Id: <20180814171338.110437094@linuxfoundation.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180814171336.799314117@linuxfoundation.org> References: <20180814171336.799314117@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.18-stable review patch. If anyone has any objections, please let me know. ------------------ From: Thomas Gleixner 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. Reported-by: Dave Hansen Signed-off-by: Thomas Gleixner Tested-by: Tony Luck 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 @@ -60,6 +60,7 @@ struct cpuhp_cpu_state { bool rollback; bool single; bool bringup; + bool booted_once; struct hlist_node *node; struct hlist_node *last; enum cpuhp_state cb_state; @@ -342,6 +343,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 + static inline enum cpuhp_state cpuhp_set_state(struct cpuhp_cpu_state *st, enum cpuhp_state target) { @@ -422,6 +457,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; + if (st->target <= CPUHP_AP_ONLINE_IDLE) return 0; @@ -933,29 +978,6 @@ EXPORT_SYMBOL(cpu_down); #define takedown_cpu NULL #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 @@ -970,6 +992,7 @@ void notify_cpu_starting(unsigned int cp int ret; rcu_cpu_starting(cpu); /* Enables RCU usage on this CPU. */ + st->booted_once = true; while (st->state < target) { st->state++; ret = cpuhp_invoke_callback(cpu, st->state, true, NULL, NULL); @@ -2180,5 +2203,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); }