Return-Path: Received: from mail.linutronix.de (146.0.238.70:993) by crypto-ml.lab.linutronix.de with IMAP4-SSL for ; 30 Jun 2018 16:38:51 -0000 Received: from mx2.suse.de ([195.135.220.15] helo=mx1.suse.de) by Galois.linutronix.de with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1fZItb-0004ki-9D for speck@linutronix.de; Sat, 30 Jun 2018 18:38:50 +0200 Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 56B30ACEC for ; Sat, 30 Jun 2018 16:38:39 +0000 (UTC) Date: Sat, 30 Jun 2018 18:38:34 +0200 From: Borislav Petkov Subject: [MODERATED] Re: [patch 2/2] cpu/hotplug: Boot HT siblings at least once Message-ID: <20180630163834.GB18970@zn.tnic> References: <20180629140546.075961202@linutronix.de> <20180629140611.033996006@linutronix.de> MIME-Version: 1.0 In-Reply-To: <20180629140611.033996006@linutronix.de> Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable To: speck@linutronix.de List-ID: On Fri, Jun 29, 2018 at 04:05:48PM +0200, speck for Thomas Gleixner wrote: > From: Thomas Gleixner > Subject: cpu/hotplug: Boot HT siblings at least once >=20 > 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. >=20 > So instead of ignoring the sibling threads right away, let them boot up > once so they can configure themself. After they came out of the initial themselves. > boot stage check whether its a "secondary" sibling and cancel the operation > which puts the CPU back into offline state. >=20 > Reported-by: Dave Hansen > Signed-off-by: Thomas Gleixner > --- > kernel/cpu.c | 69 ++++++++++++++++++++++++++++++++++++++----------------= ----- > 1 file changed, 45 insertions(+), 24 deletions(-) >=20 > --- 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; Might wanna turn all those bools into a bitfield at some point, as a cleanup. > struct hlist_node *node; > struct hlist_node *last; > enum cpuhp_state cb_state; > @@ -342,6 +343,37 @@ void cpu_hotplug_enable(void) > EXPORT_SYMBOL_GPL(cpu_hotplug_enable); > #endif /* CONFIG_HOTPLUG_CPU */ > =20 > +#ifdef CONFIG_HOTPLUG_SMT > +enum cpuhp_smt_control cpu_smt_control __read_mostly =3D CPU_SMT_ENABLED; > + > +static int __init smt_cmdline_disable(char *str) > +{ > + cpu_smt_control =3D CPU_SMT_DISABLED; > + if (str && !strcmp(str, "force")) { > + pr_info("SMT: Force disabled\n"); > + cpu_smt_control =3D 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 =3D=3D CPU_SMT_ENABLED) > + return true; <---- newline here. > + if (topology_is_primary_thread(cpu)) > + return true; <---- newline here. It looks better with newlines spacing them out. :) > + /* > + * X86 requires that the sibling threads are at least booted up > + * once to set the CR4.MCE bit so Machine Check Exceptions can be Let's rewrite that: "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=3D0b= on any core will shutdown the machine." > + * handled and do not end up raising the CPU Internal Error line. > + */ > + 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) > { ... > @@ -970,6 +989,7 @@ void notify_cpu_starting(unsigned int cp > int ret; > =20 > rcu_cpu_starting(cpu); /* Enables RCU usage on this CPU. */ > + st->booted_once =3D true; > while (st->state < target) { > st->state++; > ret =3D cpuhp_invoke_callback(cpu, st->state, true, NULL, NULL); > @@ -2180,5 +2200,6 @@ void __init boot_cpu_init(void) > */ > void __init boot_cpu_state_init(void) > { > - per_cpu_ptr(&cpuhp_state, smp_processor_id())->state =3D CPUHP_ONLINE; > + this_cpu_write(cpuhp_state.booted_once, true); I guess it doesn't matter if set ->booted_once on the BSP too - it is a primary thread, I'd strongly hope. But it is better this way as we don't have to special-case it. --=20 Regards/Gruss, Boris. SUSE Linux GmbH, GF: Felix Imend=C3=B6rffer, Jane Smithard, Graham Norton, HR= B 21284 (AG N=C3=BCrnberg) --=20