From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S965890AbcKJRsG (ORCPT ); Thu, 10 Nov 2016 12:48:06 -0500 Received: from Galois.linutronix.de ([146.0.238.70]:34004 "EHLO Galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S965687AbcKJRq3 (ORCPT ); Thu, 10 Nov 2016 12:46:29 -0500 From: Sebastian Andrzej Siewior To: linux-kernel@vger.kernel.org Cc: tglx@linutronix.de, rt@linutronix.de, Sebastian Andrzej Siewior , Tony Luck , Borislav Petkov , linux-edac@vger.kernel.org, x86@kernel.org Subject: [PATCH 6/7] x86/mcheck: Move CPU_ONLINE and CPU_DOWN_PREPARE to hotplug state machine Date: Thu, 10 Nov 2016 18:44:46 +0100 Message-Id: <20161110174447.11848-7-bigeasy@linutronix.de> X-Mailer: git-send-email 2.10.2 In-Reply-To: <20161110174447.11848-1-bigeasy@linutronix.de> References: <20161110091809.vxyf3yiuxtjy3vqv@pd.tnic> <20161110174447.11848-1-bigeasy@linutronix.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The CPU_ONLINE and CPU_DOWN_PREPARE look fully symmetrical and could be move to the hotplug state machine. On a failure during registration we have the tear down callback invoked (mce_cpu_pre_down()) so there should be no timer around and so no need to n= eed keep notifier installed (this was the reason according to the comment why t= he notifier was registered despite of errors). Cc: Tony Luck Cc: Borislav Petkov Cc: linux-edac@vger.kernel.org Cc: x86@kernel.org Signed-off-by: Sebastian Andrzej Siewior --- arch/x86/kernel/cpu/mcheck/mce.c | 78 +++++++++++++++++++-----------------= ---- 1 file changed, 36 insertions(+), 42 deletions(-) diff --git a/arch/x86/kernel/cpu/mcheck/mce.c b/arch/x86/kernel/cpu/mcheck/= mce.c index 3da6fd94fa2e..444177cafb65 100644 --- a/arch/x86/kernel/cpu/mcheck/mce.c +++ b/arch/x86/kernel/cpu/mcheck/mce.c @@ -2506,21 +2506,8 @@ static int mce_cpu_callback(struct notifier_block *nfb, unsigned long action, void *h= cpu) { unsigned int cpu =3D (unsigned long)hcpu; - struct timer_list *t =3D &per_cpu(mce_timer, cpu); =20 switch (action & ~CPU_TASKS_FROZEN) { - case CPU_ONLINE: - case CPU_DOWN_FAILED: - - mce_device_create(cpu); - - if (mce_threshold_create_device(cpu)) { - mce_device_remove(cpu); - return NOTIFY_BAD; - } - mce_reenable_cpu(); - mce_start_timer(cpu, t); - break; case CPU_DEAD: mce_intel_hcpu_update(cpu); =20 @@ -2529,17 +2516,41 @@ mce_cpu_callback(struct notifier_block *nfb, unsign= ed long action, void *hcpu) cmci_rediscover(); break; case CPU_DOWN_PREPARE: - mce_disable_cpu(); - del_timer_sync(t); =20 - mce_threshold_remove_device(cpu); - mce_device_remove(cpu); break; } =20 return NOTIFY_OK; } =20 +static int mce_cpu_online(unsigned int cpu) +{ + struct timer_list *t =3D &per_cpu(mce_timer, cpu); + int ret; + + mce_device_create(cpu); + + ret =3D mce_threshold_create_device(cpu); + if (ret) { + mce_device_remove(cpu); + return ret; + } + mce_reenable_cpu(); + mce_start_timer(cpu, t); + return 0; +} + +static int mce_cpu_pre_down(unsigned int cpu) +{ + struct timer_list *t =3D &per_cpu(mce_timer, cpu); + + mce_disable_cpu(); + del_timer_sync(t); + mce_threshold_remove_device(cpu); + mce_device_remove(cpu); + return 0; +} + static struct notifier_block mce_cpu_notifier =3D { .notifier_call =3D mce_cpu_callback, }; @@ -2564,8 +2575,8 @@ static __init void mce_init_banks(void) =20 static __init int mcheck_init_device(void) { + enum cpuhp_state hp_online; int err; - int i =3D 0; =20 if (!mce_available(&boot_cpu_data)) { err =3D -EIO; @@ -2583,21 +2594,13 @@ static __init int mcheck_init_device(void) if (err) goto err_out_mem; =20 - cpu_notifier_register_begin(); - for_each_online_cpu(i) { - err =3D mce_device_create(i); - if (err) { - /* - * Register notifier anyway (and do not unreg it) so - * that we don't leave undeleted timers, see notifier - * callback above. - */ - __register_hotcpu_notifier(&mce_cpu_notifier); - cpu_notifier_register_done(); - goto err_device_create; - } - } + err =3D cpuhp_setup_state(CPUHP_AP_ONLINE_DYN, "x86/mce:online", + mce_cpu_online, mce_cpu_pre_down); + if (err < 0) + goto err_out_mem; + hp_online =3D err; =20 + cpu_notifier_register_begin(); __register_hotcpu_notifier(&mce_cpu_notifier); cpu_notifier_register_done(); =20 @@ -2612,16 +2615,7 @@ static __init int mcheck_init_device(void) =20 err_register: unregister_syscore_ops(&mce_syscore_ops); - -err_device_create: - /* - * We didn't keep track of which devices were created above, but - * even if we had, the set of online cpus might have changed. - * Play safe and remove for every possible cpu, since - * mce_device_remove() will do the right thing. - */ - for_each_possible_cpu(i) - mce_device_remove(i); + cpuhp_remove_state(hp_online); =20 err_out_mem: free_cpumask_var(mce_device_initialized); --=20 2.10.2