Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1516240

Re: [PATCH 21/25] x86/mcheck: Split threshold_cpu_callback into two callbacks

From Borislav Petkov <bp@alien8.de>
Newsgroups linux.kernel
Subject Re: [PATCH 21/25] x86/mcheck: Split threshold_cpu_callback into two callbacks
Date 2016-11-07 16:10 +0100
Message-ID <sATIB-4Mo-11@gated-at.bofh.it> (permalink)
References <szrEO-5cN-13@gated-at.bofh.it> <szrEQ-5cN-69@gated-at.bofh.it> <sAS9Q-3GK-9@gated-at.bofh.it> <sAS9Q-3GK-23@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


On Mon, Nov 07, 2016 at 02:25:01PM +0100, Sebastian Andrzej Siewior wrote:
> This moves it 1:1 (well, more or less). Wouldn't you prefer doing it as
> separate patch/change?

Ontop of all of yours so that you don't have to redo yours?

> CONFIG_X86_MCE_AMD is where the callback is implemented. Wouldn't that
> be broken now?

Yeah, fixed.

Thanks.

---
Index: b/arch/x86/include/asm/mce.h
===================================================================
--- a/arch/x86/include/asm/mce.h	2016-11-07 14:06:40.246518729 +0100
+++ b/arch/x86/include/asm/mce.h	2016-11-07 15:52:38.786620194 +0100
@@ -292,9 +292,7 @@ void do_machine_check(struct pt_regs *,
 /*
  * Threshold handler
  */
-
 extern void (*mce_threshold_vector)(void);
-extern void (*threshold_cpu_callback)(unsigned long action, unsigned int cpu);
 
 /* Deferred error interrupt handler */
 extern void (*deferred_error_int_vector)(void);
@@ -372,6 +370,12 @@ struct smca_bank {
 extern struct smca_bank smca_banks[MAX_NR_BANKS];
 
 extern const char *smca_get_long_name(enum smca_bank_types t);
+extern int mce_threshold_create_device(unsigned int cpu);
+extern int mce_threshold_remove_device(unsigned int cpu);
+#else
+
+static inline int mce_threshold_create_device(unsigned int cpu) { return 0; };
+static inline int mce_threshold_remove_device(unsigned int cpu) { return 0; };
 #endif
 
 #endif /* _ASM_X86_MCE_H */
Index: b/arch/x86/kernel/cpu/mcheck/mce.c
===================================================================
--- a/arch/x86/kernel/cpu/mcheck/mce.c	2016-11-07 14:06:40.246518729 +0100
+++ b/arch/x86/kernel/cpu/mcheck/mce.c	2016-11-07 14:17:06.186528717 +0100
@@ -2291,8 +2291,6 @@ static struct bus_type mce_subsys = {
 
 DEFINE_PER_CPU(struct device *, mce_device);
 
-void (*threshold_cpu_callback)(unsigned long action, unsigned int cpu);
-
 static inline struct mce_bank *attr_to_bank(struct device_attribute *attr)
 {
 	return container_of(attr, struct mce_bank, attr);
@@ -2548,13 +2546,17 @@ mce_cpu_callback(struct notifier_block *
 
 	switch (action & ~CPU_TASKS_FROZEN) {
 	case CPU_ONLINE:
+
 		mce_device_create(cpu);
-		if (threshold_cpu_callback)
-			threshold_cpu_callback(action, cpu);
+
+		if (mce_threshold_create_device(cpu)) {
+			mce_device_remove(cpu);
+			return NOTIFY_BAD;
+		}
+
 		break;
 	case CPU_DEAD:
-		if (threshold_cpu_callback)
-			threshold_cpu_callback(action, cpu);
+		mce_threshold_remove_device(cpu);
 		mce_device_remove(cpu);
 		mce_intel_hcpu_update(cpu);
 
Index: b/arch/x86/kernel/cpu/mcheck/mce_amd.c
===================================================================
--- a/arch/x86/kernel/cpu/mcheck/mce_amd.c	2016-11-07 14:06:40.246518729 +0100
+++ b/arch/x86/kernel/cpu/mcheck/mce_amd.c	2016-11-07 14:18:10.506529743 +0100
@@ -55,6 +55,8 @@
 /* Threshold LVT offset is at MSR0xC0000410[15:12] */
 #define SMCA_THR_LVT_OFF	0xF000
 
+static bool thresholding_en;
+
 static const char * const th_names[] = {
 	"load_store",
 	"insn_fetch",
@@ -1097,10 +1099,13 @@ free_out:
 	per_cpu(threshold_banks, cpu)[bank] = NULL;
 }
 
-static void threshold_remove_device(unsigned int cpu)
+int mce_threshold_remove_device(unsigned int cpu)
 {
 	unsigned int bank;
 
+	if (!thresholding_en)
+		return 0;
+
 	for (bank = 0; bank < mca_cfg.banks; ++bank) {
 		if (!(per_cpu(bank_map, cpu) & (1 << bank)))
 			continue;
@@ -1108,15 +1113,19 @@ static void threshold_remove_device(unsi
 	}
 	kfree(per_cpu(threshold_banks, cpu));
 	per_cpu(threshold_banks, cpu) = NULL;
+	return 0;
 }
 
 /* create dir/files for all valid threshold banks */
-static int threshold_create_device(unsigned int cpu)
+int mce_threshold_create_device(unsigned int cpu)
 {
 	unsigned int bank;
 	struct threshold_bank **bp;
 	int err = 0;
 
+	if (!thresholding_en)
+		return 0;
+
 	bp = per_cpu(threshold_banks, cpu);
 	if (bp)
 		return 0;
@@ -1136,40 +1145,23 @@ static int threshold_create_device(unsig
 	}
 	return err;
 err:
-	threshold_remove_device(cpu);
+	mce_threshold_remove_device(cpu);
 	return err;
 }
 
-/* get notified when a cpu comes on/off */
-static void
-amd_64_threshold_cpu_callback(unsigned long action, unsigned int cpu)
-{
-	switch (action) {
-	case CPU_ONLINE:
-	case CPU_ONLINE_FROZEN:
-		threshold_create_device(cpu);
-		break;
-	case CPU_DEAD:
-	case CPU_DEAD_FROZEN:
-		threshold_remove_device(cpu);
-		break;
-	default:
-		break;
-	}
-}
-
 static __init int threshold_init_device(void)
 {
 	unsigned lcpu = 0;
 
 	/* to hit CPUs online before the notifier is up */
 	for_each_online_cpu(lcpu) {
-		int err = threshold_create_device(lcpu);
+		int err = mce_threshold_create_device(lcpu);
 
 		if (err)
 			return err;
 	}
-	threshold_cpu_callback = amd_64_threshold_cpu_callback;
+
+	thresholding_en = true;
 
 	return 0;
 }

-- 
Regards/Gruss,
    Boris.

Good mailing practices for 400: avoid top-posting and trim the reply.

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

cpu hotplug: convert more drivers (batch #4) Sebastian Andrzej Siewior <bigeasy@linutronix.de> - 2016-11-03 16:00 +0100
  [PATCH 04/25] lib/percpu_counter: Convert to hotplug state machine Sebastian Andrzej Siewior <bigeasy@linutronix.de> - 2016-11-03 16:00 +0100
    [tip:smp/hotplug] lib/percpu_counter: Convert to hotplug state  machine tip-bot for Sebastian Andrzej Siewior <tipbot@zytor.com> - 2016-11-10 00:00 +0100
  [PATCH 10/25] s390/smp: Make cpu notifier symetric Sebastian Andrzej Siewior <bigeasy@linutronix.de> - 2016-11-03 16:00 +0100
    Re: [PATCH 10/25] s390/smp: Make cpu notifier symetric Heiko Carstens <heiko.carstens@de.ibm.com> - 2016-11-04 15:30 +0100
      [PATCH 10/25 v2] s390/smp: Make cpu notifier symetric Sebastian Andrzej Siewior <bigeasy@linutronix.de> - 2016-11-04 15:50 +0100
        [tip:smp/hotplug] s390/smp: Make cpu notifier symetric tip-bot for Thomas Gleixner <tipbot@zytor.com> - 2016-11-10 00:00 +0100
  [PATCH 11/25] s390/smp: Convert to hotplug state machine Sebastian Andrzej Siewior <bigeasy@linutronix.de> - 2016-11-03 16:00 +0100
    Re: [PATCH 11/25] s390/smp: Convert to hotplug state machine Heiko Carstens <heiko.carstens@de.ibm.com> - 2016-11-04 15:40 +0100
      [PATCH 11/25 v2] s390/smp: Convert to hotplug state machine Sebastian Andrzej Siewior <bigeasy@linutronix.de> - 2016-11-04 15:50 +0100
        [tip:smp/hotplug] s390/smp: Convert to hotplug state machine tip-bot for Sebastian Andrzej Siewior <tipbot@zytor.com> - 2016-11-10 00:00 +0100
  [PATCH 25/25] x86/mcheck: Move CPU_DEAD to hotplug state machine Sebastian Andrzej Siewior <bigeasy@linutronix.de> - 2016-11-03 16:00 +0100
  [PATCH 14/25] ia64/err-inject: Convert to hotplug state machine Sebastian Andrzej Siewior <bigeasy@linutronix.de> - 2016-11-03 16:00 +0100
    [tip:smp/hotplug] ia64/err-inject: Convert to hotplug state machine tip-bot for Sebastian Andrzej Siewior <tipbot@zytor.com> - 2016-11-10 00:00 +0100
  [PATCH 05/25] lib/radix-tree: Convert to hotplug state machine Sebastian Andrzej Siewior <bigeasy@linutronix.de> - 2016-11-03 16:00 +0100
    [tip:smp/hotplug] lib/radix-tree: Convert to hotplug state machine tip-bot for Sebastian Andrzej Siewior <tipbot@zytor.com> - 2016-11-10 00:00 +0100
  [PATCH 23/25] x86/mcheck: Make CPU_DOWN_PREPARE the counter part of CPU_STARTING Sebastian Andrzej Siewior <bigeasy@linutronix.de> - 2016-11-03 16:00 +0100
  [PATCH 02/25] kernel/printk: Convert to hotplug state machine Sebastian Andrzej Siewior <bigeasy@linutronix.de> - 2016-11-03 16:00 +0100
    [tip:smp/hotplug] kernel/printk: Convert to hotplug state machine tip-bot for Sebastian Andrzej Siewior <tipbot@zytor.com> - 2016-11-10 00:00 +0100
  [PATCH 06/25] mm/page_alloc: Convert to hotplug state machine Sebastian Andrzej Siewior <bigeasy@linutronix.de> - 2016-11-03 16:00 +0100
    [tip:smp/hotplug] mm/page_alloc: Convert to hotplug state machine tip-bot for Sebastian Andrzej Siewior <tipbot@zytor.com> - 2016-11-10 00:00 +0100
  [PATCH 18/25] x86/mcheck: Move threshold_create_device() Sebastian Andrzej Siewior <bigeasy@linutronix.de> - 2016-11-03 16:00 +0100
    Re: [PATCH 18/25] x86/mcheck: Move threshold_create_device() Borislav Petkov <bp@alien8.de> - 2016-11-07 11:40 +0100
  [PATCH 09/25] net/flowcache: Convert to hotplug state machine Sebastian Andrzej Siewior <bigeasy@linutronix.de> - 2016-11-03 16:00 +0100
    [tip:smp/hotplug] net/flowcache: Convert to hotplug state machine tip-bot for Sebastian Andrzej Siewior <tipbot@zytor.com> - 2016-11-10 00:00 +0100
  [PATCH 21/25] x86/mcheck: Split threshold_cpu_callback into two callbacks Sebastian Andrzej Siewior <bigeasy@linutronix.de> - 2016-11-03 16:00 +0100
    Re: [PATCH 21/25] x86/mcheck: Split threshold_cpu_callback into two  callbacks Borislav Petkov <bp@alien8.de> - 2016-11-07 14:30 +0100
      Re: [PATCH 21/25] x86/mcheck: Split threshold_cpu_callback into two  callbacks Sebastian Andrzej Siewior <bigeasy@linutronix.de> - 2016-11-07 14:30 +0100
        Re: [PATCH 21/25] x86/mcheck: Split threshold_cpu_callback into two  callbacks Borislav Petkov <bp@alien8.de> - 2016-11-07 16:10 +0100
          Re: [PATCH 21/25] x86/mcheck: Split threshold_cpu_callback into two  callbacks Sebastian Andrzej Siewior <bigeasy@linutronix.de> - 2016-11-07 16:20 +0100
          Re: [PATCH 21/25] x86/mcheck: Split threshold_cpu_callback into two  callbacks Sebastian Andrzej Siewior <bigeasy@linutronix.de> - 2016-11-07 18:30 +0100
            Re: [PATCH 21/25] x86/mcheck: Split threshold_cpu_callback into two  callbacks Borislav Petkov <bp@alien8.de> - 2016-11-07 19:20 +0100
  [PATCH 08/25] net/dev: Convert to hotplug state machine Sebastian Andrzej Siewior <bigeasy@linutronix.de> - 2016-11-03 16:00 +0100
    [tip:smp/hotplug] net/dev: Convert to hotplug state machine tip-bot for Sebastian Andrzej Siewior <tipbot@zytor.com> - 2016-11-10 00:00 +0100
  [PATCH 17/25] ia64/topology: Convert to hotplug state machine Sebastian Andrzej Siewior <bigeasy@linutronix.de> - 2016-11-03 16:00 +0100
    [PATCH 17/25 v2] ia64/topology: Convert to hotplug state machine Sebastian Andrzej Siewior <bigeasy@linutronix.de> - 2016-11-03 18:40 +0100
      [tip:smp/hotplug] ia64/topology: Convert to hotplug state machine tip-bot for Sebastian Andrzej Siewior <tipbot@zytor.com> - 2016-11-10 00:10 +0100

csiph-web