Skip to contentSkip to conversation

RAS daemon: kernel part

PATCH In review Borislav Petkov 7 participants 33 messages May 2, 2011 – May 5, 2011

Subsystems (5)
lore
Share & tools
lore
#0 lore raw

cover RAS daemon: kernel part

From: Borislav Petkov <[email protected]>

Hi,

as previously discussed, here's the first part of the RAS daemon code in smaller, broken-out, digestible pieces. No functionality change from the last time, only commit message fixups, clarifications and comment adjustments.

Concerning risk, I don't see any since patch 4/4 leaves the persistent event disabled for now - sort of like a chicken bit - and can only be enabled if explicitly stated so on the kernel command line.

Please review,
thanks.

#1 lore raw

PATCH 1/4 perf: Start the restructuring

From: Borislav Petkov <[email protected]>

mv kernel/perf_event.c -> kernel/events/core.c. From there, all further sensible splitting can happen. The idea is that due to perf_event.c becoming pretty sizable and with the advent of the marriage with ftrace, splitting functionality into its logical parts should help speeding up the unification and managing the complexity of the subsystem.

---
 kernel/Makefile                        |    5 +++--
 kernel/events/Makefile                 |    5 +++++
 kernel/{perf_event.c => events/core.c} |    0
 3 files changed, 8 insertions(+), 2 deletions(-)
 create mode 100644 kernel/events/Makefile
 rename kernel/{perf_event.c => events/core.c} (100%)
kernel/Makefile +3 -2
index 85cbfb3..7981530 100644
@@ -21,7 +21,6 @@ CFLAGS_REMOVE_mutex-debug.o = -pg
 CFLAGS_REMOVE_rtmutex-debug.o = -pg
 CFLAGS_REMOVE_cgroup-debug.o = -pg
 CFLAGS_REMOVE_sched_clock.o = -pg
-CFLAGS_REMOVE_perf_event.o = -pg
 CFLAGS_REMOVE_irq_work.o = -pg
 endif
 
@@ -103,7 +102,9 @@ obj-$(CONFIG_RING_BUFFER) += trace/
 obj-$(CONFIG_TRACEPOINTS) += trace/
 obj-$(CONFIG_SMP) += sched_cpupri.o
 obj-$(CONFIG_IRQ_WORK) += irq_work.o
-obj-$(CONFIG_PERF_EVENTS) += perf_event.o
+
+obj-$(CONFIG_PERF_EVENTS) += events/
+
 obj-$(CONFIG_HAVE_HW_BREAKPOINT) += hw_breakpoint.o
 obj-$(CONFIG_USER_RETURN_NOTIFIER) += user-return-notifier.o
 obj-$(CONFIG_PADATA) += padata.o
kernel/events/Makefile new file +5 -0
new file mode 100644
index 0000000..26c00e4
@@ -0,0 +1,5 @@
+ifdef CONFIG_FUNCTION_TRACER
+CFLAGS_REMOVE_core.o = -pg
+endif
+
+obj-y += core.o
kernel/events/core.c renamed from kernel/perf_event.c +0 -0
similarity index 100%
rename from kernel/perf_event.c
rename to kernel/events/core.c
Signature · 1 line
1.7.4.rc2
#2 lore raw

PATCH 2/4 perf: Add persistent event facilities

In reply to Borislav Petkov

From: Borislav Petkov <[email protected]>

Add a barebones implementation for registering persistent events with perf. For that, we don't destroy the buffers when they're unmapped; also, we map them read-only so that multiple agents can access them.

---
 include/linux/perf_event.h |   22 +++++++++++++++-
 kernel/events/Makefile     |    2 +-
 kernel/events/core.c       |   29 ++++++++++++++++++---
 kernel/events/persistent.c |   59 ++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 105 insertions(+), 7 deletions(-)
 create mode 100644 kernel/events/persistent.c
include/linux/perf_event.h +21 -1
index 9eec53d..18f2a68 100644
@@ -216,8 +216,9 @@ struct perf_event_attr {
 				precise_ip     :  2, /* skid constraint       */
 				mmap_data      :  1, /* non-exec mmap data    */
 				sample_id_all  :  1, /* sample_type all events */
+				persistent     :  1, /* event always on */
 
-				__reserved_1   : 45;
+				__reserved_1   : 44;
 
 	union {
 		__u32		wakeup_events;	  /* wakeup every n events */
@@ -1158,6 +1159,15 @@ extern void perf_swevent_put_recursion_context(int rctx);
 extern void perf_event_enable(struct perf_event *event);
 extern void perf_event_disable(struct perf_event *event);
 extern void perf_event_task_tick(void);
+extern struct perf_buffer *
+perf_buffer_alloc(int nr_pages, long watermark, int cpu, int flags);
+extern void perf_buffer_put(struct perf_buffer *buffer);
+extern struct perf_event *
+perf_enable_persistent_event(struct perf_event_attr *attr,
+			     int cpu, unsigned bufsz);
+extern void perf_disable_persistent_event(struct perf_event *event, int cpu);
+extern int perf_persistent_open(struct inode *inode, struct file *file);
+extern const struct file_operations perf_pers_fops;
 #else
 static inline void
 perf_event_task_sched_in(struct task_struct *task)			{ }
@@ -1192,6 +1202,16 @@ static inline void perf_swevent_put_recursion_context(int rctx)		{ }
 static inline void perf_event_enable(struct perf_event *event)		{ }
 static inline void perf_event_disable(struct perf_event *event)		{ }
 static inline void perf_event_task_tick(void)				{ }
+static inline struct perf_buffer *
+perf_buffer_alloc(int nr_pages, long watermark, int cpu, int flags)	{ return NULL; }
+static inline void perf_buffer_put(struct perf_buffer *buffer)		{}
+static inline struct perf_event *
+perf_enable_persistent_event(struct perf_event_attr *attr, int cpu,
+			     unsigned bufsz)				{ return -EINVAL; }
+static inline void
+perf_disable_persistent_event(struct perf_event *event, int cpu)	{}
+static inline int
+perf_persistent_open(struct inode *inode, struct file *file)		{ return -1; }
 #endif
 
 #define perf_output_put(handle, x) \
kernel/events/Makefile +1 -1
index 26c00e4..e2d4d8e 100644
@@ -2,4 +2,4 @@ ifdef CONFIG_FUNCTION_TRACER
 CFLAGS_REMOVE_core.o = -pg
 endif
 
-obj-y += core.o
+obj-y += core.o persistent.o
kernel/events/core.c +24 -5
index 440bc48..2d8b1af 100644
@@ -2898,7 +2898,7 @@ static void free_event_rcu(struct rcu_head *head)
 	kfree(event);
 }
 
-static void perf_buffer_put(struct perf_buffer *buffer);
+void perf_buffer_put(struct perf_buffer *buffer);
 
 static void free_event(struct perf_event *event)
 {
@@ -3458,7 +3458,7 @@ static void *perf_mmap_alloc_page(int cpu)
 	return page_address(page);
 }
 
-static struct perf_buffer *
+struct perf_buffer *
 perf_buffer_alloc(int nr_pages, long watermark, int cpu, int flags)
 {
 	struct perf_buffer *buffer;
@@ -3575,7 +3575,7 @@ static void perf_buffer_free(struct perf_buffer *buffer)
 	schedule_work(&buffer->work);
 }
 
-static struct perf_buffer *
+struct perf_buffer *
 perf_buffer_alloc(int nr_pages, long watermark, int cpu, int flags)
 {
 	struct perf_buffer *buffer;
@@ -3676,7 +3676,7 @@ static struct perf_buffer *perf_buffer_get(struct perf_event *event)
 	return buffer;
 }
 
-static void perf_buffer_put(struct perf_buffer *buffer)
+void perf_buffer_put(struct perf_buffer *buffer)
 {
 	if (!atomic_dec_and_test(&buffer->refcount))
 		return;
@@ -3695,6 +3695,11 @@ static void perf_mmap_close(struct vm_area_struct *vma)
 {
 	struct perf_event *event = vma->vm_file->private_data;
 
+	if (event->attr.persistent) {
+		atomic_dec(&event->mmap_count);
+		return;
+	}
+
 	if (atomic_dec_and_mutex_lock(&event->mmap_count, &event->mmap_mutex)) {
 		unsigned long size = perf_data_size(event->buffer);
 		struct user_struct *user = event->mmap_user;
@@ -3737,7 +3742,7 @@ static int perf_mmap(struct file *file, struct vm_area_struct *vma)
 	if (event->cpu == -1 && event->attr.inherit)
 		return -EINVAL;
 
-	if (!(vma->vm_flags & VM_SHARED))
+	if (!(vma->vm_flags & VM_SHARED) && !event->attr.persistent)
 		return -EINVAL;
 
 	vma_size = vma->vm_end - vma->vm_start;
@@ -3846,6 +3851,16 @@ static const struct file_operations perf_fops = {
 	.fasync			= perf_fasync,
 };
 
+const struct file_operations perf_pers_fops = {
+	.llseek		= no_llseek,
+	.open		= perf_persistent_open,
+	.poll		= perf_poll,
+	.unlocked_ioctl	= perf_ioctl,
+	.compat_ioctl	= perf_ioctl,
+	.mmap		= perf_mmap,
+	.fasync		= perf_fasync,
+};
+
 /*
  * Perf event wakeup
  *
@@ -6756,6 +6771,10 @@ __perf_event_exit_task(struct perf_event *child_event,
 		raw_spin_unlock_irq(&child_ctx->lock);
 	}
 
+	/* do not remove persistent events on task exit */
+	if (child_event->attr.persistent)
+		return;
+
 	perf_remove_from_context(child_event);
 
 	/*
kernel/events/persistent.c new file +59 -0

59 lines not on this page · raw message

Signature · 1 line
1.7.4.rc2
#3 lore raw

Re: [PATCH 2/4] perf: Add persistent event facilities

Quoted 6 lines · Borislav Petkov

From: Borislav Petkov <[email protected]>

Add a barebones implementation for registering persistent events with perf. For that, we don't destroy the buffers when they're unmapped; also, we map them read-only so that multiple agents can access them.

Quoted 8 lines
---
 include/linux/perf_event.h |   22 +++++++++++++++-
 kernel/events/Makefile     |    2 +-
 kernel/events/core.c       |   29 ++++++++++++++++++---
 kernel/events/persistent.c |   59 ++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 105 insertions(+), 7 deletions(-)
 create mode 100644 kernel/events/persistent.c

I really like this new kernel/events/ subdirectory you created - we could move the other perf_events.c facilities there as well, and maybe split up the file a bit, it's 7.5 KLOC now which is a bit excessive.

We should probably do that before adding kernel/events/persistent.c - wanna do those changes? Initial commit should be a mostly-rename thing:
kernel/perf_events.c could move into kernel/events/core.c or so - and then we could split the core up some more, into various facilities.

[ kernel/hw_breakpoint.c could possibly move into kernel/events/hw_breakpoint.c
file as well - if Frederic acks it. ]

Thanks,

Ingo

#4 lore raw

Re: [PATCH 2/4] perf: Add persistent event facilities

Quoted 7 lines · Ingo Molnar
Quoted 6 lines
 include/linux/perf_event.h |   22 +++++++++++++++-
 kernel/events/Makefile     |    2 +-
 kernel/events/core.c       |   29 ++++++++++++++++++---
 kernel/events/persistent.c |   59 ++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 105 insertions(+), 7 deletions(-)
 create mode 100644 kernel/events/persistent.c
Quoted 8 lines

I really like this new kernel/events/ subdirectory you created - we could move the other perf_events.c facilities there as well, and maybe split up the file a bit, it's 7.5 KLOC now which is a bit excessive.

We should probably do that before adding kernel/events/persistent.c - wanna do those changes? Initial commit should be a mostly-rename thing:
kernel/perf_events.c could move into kernel/events/core.c or so - and then we could split the core up some more, into various facilities.

Looks like you have a time machine and after reading my feedback you have have sneaked this exact change into patch 1/4! :-)

( The alternative interpretation is that i should start reading series at the
beginning - not in the most interesting looking (largest) places where i would stupidly ask for changes you've put into 1/4 already. )

Thanks,

Ingo

#5 lore raw

Re: [PATCH 2/4] perf: Add persistent event facilities

In reply to Ingo Molnar
Quoted 1 line · Ingo Molnar

I really like this new kernel/events/ subdirectory you created -

Yeah, this was your suggestion a couple of months ago, I just picked it up.

Quoted 3 lines

we could move the other perf_events.c facilities there as well, and maybe split up the file a bit, it's 7.5 KLOC now which is a bit excessive.

Right, so I left perf_event.c as a whole on purpose (only renamed) because it makes more sense IMHO for someone who actually wrote it to split it in logical parts (^hint hint^). I mean, I could do it too but it'll take me much more time :).

Quoted 7 lines

We should probably do that before adding kernel/events/persistent.c - wanna do those changes? Initial commit should be a mostly-rename thing:
kernel/perf_events.c could move into kernel/events/core.c or so - and then we could split the core up some more, into various facilities.

[ kernel/hw_breakpoint.c could possibly move into kernel/events/hw_breakpoint.c
file as well - if Frederic acks it. ]

Yeah, no problem.

Thanks for the review, btw.

Signature · 8 lines
Regards/Gruss,
Boris.

Advanced Micro Devices GmbH
Einsteinring 24, 85609 Dornach
General Managers: Alberto Bozzo, Andrew Bowd
Registration: Dornach, Gemeinde Aschheim, Landkreis Muenchen
Registergericht Muenchen, HRB Nr. 43632
#6 lore raw

Re: [PATCH 2/4] perf: Add persistent event facilities

Quoted 7 lines · Borislav Petkov
Quoted 2 lines

we could move the other perf_events.c facilities there as well, and maybe split up the file a bit, it's 7.5 KLOC now which is a bit excessive.

Right, so I left perf_event.c as a whole on purpose (only renamed) because it makes more sense IMHO for someone who actually wrote it to split it in logical parts (^hint hint^). I mean, I could do it too but it'll take me much more time :).

Well you are now writing new events code as well so spending that time might be a good investment in terms of getting persistent.c right as well.

Could you send a Git pull request against perf/core that does the obvious file movement and renaming? We can do that first step straight away and get the ball rolling.

Thanks,

Ingo

#7 lore raw

[GIT PULL] Rename perf_event.c

Quoted 3 lines · Ingo Molnar

Could you send a Git pull request against perf/core that does the obvious file movement and renaming? We can do that first step straight away and get the ball rolling.

Sure, here we go:

The following changes since commit ac0a3260f37b8616da8d33488ec94b94e6ae5b31:

Merge branch 'tip/perf/core' of git://git.kernel.org/pub/scm/linux/kernel/git/rostedt/linux-2.6-trace into perf/core (2011-05-01 19:11:42 +0200)

are available in the git repository at:

git://git.kernel.org/pub/scm/linux/kernel/git/bp/bp.git perf-event-rename

Borislav Petkov (1):
perf: Start the restructuring

 kernel/Makefile                        |    5 +++--
 kernel/events/Makefile                 |    5 +++++
 kernel/{perf_event.c => events/core.c} |    0
 3 files changed, 8 insertions(+), 2 deletions(-)
 create mode 100644 kernel/events/Makefile
 rename kernel/{perf_event.c => events/core.c} (100%)
Signature · 8 lines
Regards/Gruss,
Boris.

Advanced Micro Devices GmbH
Einsteinring 24, 85609 Dornach
General Managers: Alberto Bozzo, Andrew Bowd
Registration: Dornach, Gemeinde Aschheim, Landkreis Muenchen
Registergericht Muenchen, HRB Nr. 43632
#8 lore raw

Re: [PATCH 2/4] perf: Add persistent event facilities

In reply to Ingo Molnar
Quoted 2 lines · Ingo Molnar

[ kernel/hw_breakpoint.c could possibly move into kernel/events/hw_breakpoint.c
file as well - if Frederic acks it. ]

Makes sense yeah.

Thanks.

Quoted 4 lines

Thanks,

Ingo

#9 lore raw

Re: [PATCH 2/4] perf: Add persistent event facilities

Quoted 5 lines · Frederic Weisbecker
Quoted 2 lines · Ingo Molnar

[ kernel/hw_breakpoint.c could possibly move into kernel/events/hw_breakpoint.c
file as well - if Frederic acks it. ]

Makes sense yeah.

Ok, looks trivial enough. Ingo, let me know if I should add it to the pull request from earlier.

--

Quoted 1 line

From 48dbb6dc86ca5d1b2224937d774c7ba98bc3a485 Mon Sep 17 00:00:00 2001

From: Borislav Petkov <[email protected]>
Date: Tue, 3 May 2011 15:26:43 +0200
Subject: [PATCH] hw breakpoints: Move to kernel/events/

As part of the events sybsystem unification, relocate hw_breakpoint.c into its new destination.

Cc Frederic Weisbecker <[email protected]>
---
 kernel/Makefile                     |    1 -
 kernel/events/Makefile              |    3 ++-
 kernel/{ => events}/hw_breakpoint.c |    0
 3 files changed, 2 insertions(+), 2 deletions(-)
 rename kernel/{ => events}/hw_breakpoint.c (100%)
kernel/Makefile +0 -1
index 7981530..e9cf191 100644
@@ -105,7 +105,6 @@ obj-$(CONFIG_IRQ_WORK) += irq_work.o
 
 obj-$(CONFIG_PERF_EVENTS) += events/
 
-obj-$(CONFIG_HAVE_HW_BREAKPOINT) += hw_breakpoint.o
 obj-$(CONFIG_USER_RETURN_NOTIFIER) += user-return-notifier.o
 obj-$(CONFIG_PADATA) += padata.o
 obj-$(CONFIG_CRASH_DUMP) += crash_dump.o
kernel/events/Makefile +2 -1
index 26c00e4..1ce23d3 100644
@@ -2,4 +2,5 @@ ifdef CONFIG_FUNCTION_TRACER
 CFLAGS_REMOVE_core.o = -pg
 endif
 
-obj-y += core.o
+obj-y := core.o
+obj-$(CONFIG_HAVE_HW_BREAKPOINT) += hw_breakpoint.o
kernel/events/hw_breakpoint.c renamed from kernel/hw_breakpoint.c +0 -0
similarity index 100%
rename from kernel/hw_breakpoint.c
rename to kernel/events/hw_breakpoint.c
Signature · 12 lines
1.7.4.rc2


-- 
Regards/Gruss,
Boris.

Advanced Micro Devices GmbH
Einsteinring 24, 85609 Dornach
General Managers: Alberto Bozzo, Andrew Bowd
Registration: Dornach, Gemeinde Aschheim, Landkreis Muenchen
Registergericht Muenchen, HRB Nr. 43632
#10 lore raw

Re: [PATCH 2/4] perf: Add persistent event facilities

Quoted 9 lines · Borislav Petkov
Quoted 5 lines · Frederic Weisbecker
Quoted 2 lines · Ingo Molnar

[ kernel/hw_breakpoint.c could possibly move into kernel/events/hw_breakpoint.c
file as well - if Frederic acks it. ]

Makes sense yeah.

Ok, looks trivial enough. Ingo, let me know if I should add it to the pull request from earlier.

I slapped it into a new branch along with the previous patch:

git://git.kernel.org/pub/scm/linux/kernel/git/bp/bp.git perf-event-rename-2

Thanks.

Signature · 8 lines
Regards/Gruss,
Boris.

Advanced Micro Devices GmbH
Einsteinring 24, 85609 Dornach
General Managers: Alberto Bozzo, Andrew Bowd
Registration: Dornach, Gemeinde Aschheim, Landkreis Muenchen
Registergericht Muenchen, HRB Nr. 43632
#11 lore raw

PATCH 3/4 x86, mce: Add persistent MCE event

In reply to Borislav Petkov

From: Borislav Petkov <[email protected]>

Add the necessary glue to enable the mce_record tracepoint on boot, turning it into a persistent event. This exports the MCE buffer through a debugfs per-CPU file which a userspace daemon can read and then process the received error data further.

---
 arch/x86/include/asm/mce.h       |    8 +++
 arch/x86/kernel/cpu/mcheck/mce.c |   89 ++++++++++++++++++++++++++++++++++++++
 2 files changed, 97 insertions(+), 0 deletions(-)
arch/x86/include/asm/mce.h +8 -0
index eb16e94..40cc9bc 100644
@@ -115,6 +115,14 @@ struct mce_log {
 
 #ifdef __KERNEL__
 
+/*
+ * a per-CPU descriptor of the persistent MCE tracepoint
+ */
+struct mce_tp_desc {
+	struct perf_event *event;
+	struct dentry *debugfs_entry;
+};
+
 extern struct atomic_notifier_head x86_mce_decoder_chain;
 
 #include <linux/percpu.h>
arch/x86/kernel/cpu/mcheck/mce.c +89 -0

119 lines not on this page · raw message

Signature · 1 line
1.7.4.rc2
#12 lore raw

Re: [PATCH 3/4] x86, mce: Add persistent MCE event

Quoted 74 lines · Borislav Petkov
arch/x86/kernel/cpu/mcheck/mce.c +74 -0
+static struct perf_event_attr pattr = {
+	.type		= PERF_TYPE_TRACEPOINT,
+	.size		= sizeof(pattr),
+	.sample_type	= PERF_SAMPLE_RAW,
+	.persistent	= 1,
+};
+
+static struct dentry *mce_add_event_debugfs(struct perf_event *event, int cpu)
+{
+	char buf[14];
+
+	sprintf(buf, "mce_record%d", cpu);
+
+	return debugfs_create_file(buf, S_IRUGO | S_IWUSR,
+				   mce_get_debugfs_dir(),
+				   event, &perf_pers_fops);
+}
+
+#define MCE_BUF_PAGES	4
+
+static int mce_enable_perf_event_on_cpu(int cpu)
+{
+	struct mce_tp_desc *d = &per_cpu(mce_event, cpu);
+	int err = -EINVAL;
+
+	d->event = perf_enable_persistent_event(&pattr, cpu, MCE_BUF_PAGES);
+	if (IS_ERR(d->event)) {
+		printk(KERN_ERR "MCE: Error enabling event on cpu %d\n", cpu);
+		goto ret;
+	}
+
+	d->debugfs_entry = mce_add_event_debugfs(d->event, cpu);
+	if (!d->debugfs_entry) {
+		printk(KERN_ERR "MCE: Error adding event debugfs entry on cpu %d\n", cpu);
+		goto disable;
+	}
+
+	return 0;
+
+disable:
+	perf_disable_persistent_event(d->event, cpu);
+
+ret:
+	return err;
+}
+
+static void mce_disable_perf_event_on_cpu(int cpu)
+{
+	struct mce_tp_desc *d = &per_cpu(mce_event, cpu);
+	debugfs_remove(d->debugfs_entry);
+	perf_disable_persistent_event(d->event, cpu);
+}
+
+static __init int mcheck_init_persistent_event(void)
+{
+	int cpu, err = 0;
+
+	get_online_cpus();
+
+	pattr.config = event_mce_record.event.type;
+	pattr.sample_period = 1;
+	pattr.wakeup_events = 1;
+
+	for_each_online_cpu(cpu)
+		if (mce_enable_perf_event_on_cpu(cpu))
+			goto err_unwind;
+
+	goto unlock;
+
+err_unwind:
+	err = -EINVAL;
+	for (--cpu; cpu >= 0; cpu--)
+		mce_disable_perf_event_on_cpu(cpu);
+

arch/x86/kernel/cpu/mcheck/mce.c static void __cpuinit mce_reenable_cpu(void *h) · line 2142

Quoted 10 lines
arch/x86/kernel/cpu/mcheck/mce.c +10 -0
+unlock:
+	put_online_cpus();
+
+	return err;
+}
+
+/*
+ * This has to run after event_trace_init()
+ */
+device_initcall(mcheck_init_persistent_event);

Looks quite generic - shouldnt this bit be generalized a bit more into kernel/events/? When other places (and other platforms) want to add a persistent event they would thus have your new facility available as well.

Except this bit:

Quoted 20 lines

/* Get notified when a cpu comes on/off. Be hotplug friendly. */ static int __cpuinit
mce_cpu_callback(struct notifier_block *nfb, unsigned long action, void *hcpu)

arch/x86/kernel/cpu/mcheck/mce.c +2 -0
@@ -2068,6 +2154,7 @@ mce_cpu_callback(struct notifier_block *nfb, unsigned long action, void *hcpu)
 		mce_create_device(cpu);
 		if (threshold_cpu_callback)
 			threshold_cpu_callback(action, cpu);
+		mce_enable_perf_event_on_cpu(cpu);
 		break;
 	case CPU_DEAD:
 	case CPU_DEAD_FROZEN:
@@ -2077,6 +2164,7 @@ mce_cpu_callback(struct notifier_block *nfb, unsigned long action, void *hcpu)
 		break;
 	case CPU_DOWN_PREPARE:
 	case CPU_DOWN_PREPARE_FROZEN:
+		mce_disable_perf_event_on_cpu(cpu);
 		del_timer_sync(t);
 		smp_call_function_single(cpu, mce_disable_cpu, &action, 1);
 		break;

arch/x86/kernel/cpu/mcheck/mce.c mce_cpu_callback(struct notifier_block *nfb, unsigned long action, void *hcpu) · line 2182

Quoted 7 lines
arch/x86/kernel/cpu/mcheck/mce.c +1 -0
@@ -2088,6 +2176,7 @@ mce_cpu_callback(struct notifier_block *nfb, unsigned long action, void *hcpu)
 			add_timer_on(t, cpu);
 		}
 		smp_call_function_single(cpu, mce_reenable_cpu, &action, 1);
+		mce_enable_perf_event_on_cpu(cpu);
 		break;
 	case CPU_POST_DEAD:
 		/* intentionally ignoring frozen here */

which looks a bit x86 specific.

Thanks,

Ingo

#13 lore raw

Re: [PATCH 3/4] x86, mce: Add persistent MCE event

Quoted 83 lines · Ingo Molnar
Quoted 80 lines · Borislav Petkov
arch/x86/kernel/cpu/mcheck/mce.c +80 -0
+static struct perf_event_attr pattr = {
+	.type		= PERF_TYPE_TRACEPOINT,
+	.size		= sizeof(pattr),
+	.sample_type	= PERF_SAMPLE_RAW,
+	.persistent	= 1,
+};
+
+static struct dentry *mce_add_event_debugfs(struct perf_event *event, int cpu)
+{
+	char buf[14];
+
+	sprintf(buf, "mce_record%d", cpu);
+
+	return debugfs_create_file(buf, S_IRUGO | S_IWUSR,
+				   mce_get_debugfs_dir(),
+				   event, &perf_pers_fops);
+}
+
+#define MCE_BUF_PAGES	4
+
+static int mce_enable_perf_event_on_cpu(int cpu)
+{
+	struct mce_tp_desc *d = &per_cpu(mce_event, cpu);
+	int err = -EINVAL;
+
+	d->event = perf_enable_persistent_event(&pattr, cpu, MCE_BUF_PAGES);
+	if (IS_ERR(d->event)) {
+		printk(KERN_ERR "MCE: Error enabling event on cpu %d\n", cpu);
+		goto ret;
+	}
+
+	d->debugfs_entry = mce_add_event_debugfs(d->event, cpu);
+	if (!d->debugfs_entry) {
+		printk(KERN_ERR "MCE: Error adding event debugfs entry on cpu %d\n", cpu);
+		goto disable;
+	}
+
+	return 0;
+
+disable:
+	perf_disable_persistent_event(d->event, cpu);
+
+ret:
+	return err;
+}
+
+static void mce_disable_perf_event_on_cpu(int cpu)
+{
+	struct mce_tp_desc *d = &per_cpu(mce_event, cpu);
+	debugfs_remove(d->debugfs_entry);
+	perf_disable_persistent_event(d->event, cpu);
+}
+
+static __init int mcheck_init_persistent_event(void)
+{
+	int cpu, err = 0;
+
+	get_online_cpus();
+
+	pattr.config = event_mce_record.event.type;
+	pattr.sample_period = 1;
+	pattr.wakeup_events = 1;
+
+	for_each_online_cpu(cpu)
+		if (mce_enable_perf_event_on_cpu(cpu))
+			goto err_unwind;
+
+	goto unlock;
+
+err_unwind:
+	err = -EINVAL;
+	for (--cpu; cpu >= 0; cpu--)
+		mce_disable_perf_event_on_cpu(cpu);
+
+unlock:
+	put_online_cpus();
+
+	return err;
+}
+
Quoted 8 lines

arch/x86/kernel/cpu/mcheck/mce.c static void __cpuinit mce_reenable_cpu(void *h) · line 2142

Quoted 4 lines
arch/x86/kernel/cpu/mcheck/mce.c +4 -0
+/*
+ * This has to run after event_trace_init()
+ */
+device_initcall(mcheck_init_persistent_event);

Looks quite generic - shouldnt this bit be generalized a bit more into kernel/events/? When other places (and other platforms) want to add a persistent event they would thus have your new facility available as well.

Right, so the position of those seemed kinda arbitrary to me too due to their partial genericity (that's not a real word :)).

But, the difference between persistent events and "normal" perf events is that we export the former through debugfs, thus bypassing sys_perf_event_open syscall and make them a rather different beast.

I'm guessing that when we move those to /sysfs, this mechanism will have to change too so it might make sense to move that functionality to persistent.c. Let me see what I can do.

Quoted 24 lines

Except this bit:

Quoted 21 lines

/* Get notified when a cpu comes on/off. Be hotplug friendly. */ static int __cpuinit
mce_cpu_callback(struct notifier_block *nfb, unsigned long action, void *hcpu)

arch/x86/kernel/cpu/mcheck/mce.c +2 -0
@@ -2068,6 +2154,7 @@ mce_cpu_callback(struct notifier_block *nfb, unsigned long action, void *hcpu)
 		mce_create_device(cpu);
 		if (threshold_cpu_callback)
 			threshold_cpu_callback(action, cpu);
+		mce_enable_perf_event_on_cpu(cpu);
 		break;
 	case CPU_DEAD:
 	case CPU_DEAD_FROZEN:
@@ -2077,6 +2164,7 @@ mce_cpu_callback(struct notifier_block *nfb, unsigned long action, void *hcpu)
 		break;
 	case CPU_DOWN_PREPARE:
 	case CPU_DOWN_PREPARE_FROZEN:
+		mce_disable_perf_event_on_cpu(cpu);
 		del_timer_sync(t);
 		smp_call_function_single(cpu, mce_disable_cpu, &action, 1);
 		break;
@@ -2088,6 +2176,7 @@ mce_cpu_callback(struct notifier_block *nfb, unsigned long action, void *hcpu)
 			add_timer_on(t, cpu);
Quoted 8 lines

arch/x86/kernel/cpu/mcheck/mce.c mce_cpu_callback(struct notifier_block *nfb, unsigned long action, void *hcpu) · line 2182

Quoted 6 lines
arch/x86/kernel/cpu/mcheck/mce.c +1 -0
 		}
 		smp_call_function_single(cpu, mce_reenable_cpu, &action, 1);
+		mce_enable_perf_event_on_cpu(cpu);
 		break;
 	case CPU_POST_DEAD:
 		/* intentionally ignoring frozen here */

which looks a bit x86 specific.

Yep.

Thanks.

Signature · 8 lines
Regards/Gruss,
Boris.

Advanced Micro Devices GmbH
Einsteinring 24, 85609 Dornach
General Managers: Alberto Bozzo, Andrew Bowd
Registration: Dornach, Gemeinde Aschheim, Landkreis Muenchen
Registergericht Muenchen, HRB Nr. 43632
#14 lore raw

Re: [PATCH 3/4] x86, mce: Add persistent MCE event

Quoted 3 lines · Borislav Petkov

I'm guessing that when we move those to /sysfs, this mechanism will have to change too so it might make sense to move that functionality to persistent.c. Let me see what I can do.

Yes, we really do not want to increase the debugfs mess. This looks like an implementational detail but from a tooling POV it's quite essential.

As a starting point check out Peter's patch from November 2010:

[RFC][PATCH 8/8] perf: Sysfs events

https://lkml.org/lkml/2010/11/17/489

That patch should still apply cleanly to the latest tree.

In the end we want all events (including regular hw events) to be easily available via sysfs enumeration. The goal is that ideally when you type 'perf list' it should only access /sys.

Thanks,

Ingo

#15 lore raw

Re: [PATCH 3/4] x86, mce: Add persistent MCE event

In reply to Borislav Petkov
Quoted 2 lines · Borislav Petkov
Quoted 1 line · Ingo Molnar

* Borislav Petkov <[email protected]> wrote:

[]

Quoted 5 lines
Quoted 5 lines

arch/x86/kernel/cpu/mcheck/mce.c static void __cpuinit mce_reenable_cpu(void *h) · line 2070

Quoted 5 lines
arch/x86/kernel/cpu/mcheck/mce.c +5 -0
+static struct dentry *mce_add_event_debugfs(struct perf_event *event, int cpu)
+{
+	char buf[14];
+
+	sprintf(buf, "mce_record%d", cpu);

trivia:

buf[14] doesn't fit 10k+ cpus.
Isn't that an unnecessary future/current problem? Maybe something bigger?
char buf[sizeof("mce_record") + sizeof(int) * 3]

#16 lore raw

Re: [PATCH 3/4] x86, mce: Add persistent MCE event

Quoted 12 lines · Joe Perches
Quoted 2 lines · Borislav Petkov
Quoted 1 line · Ingo Molnar

* Borislav Petkov <[email protected]> wrote:

[]

Quoted 5 lines
Quoted 5 lines

arch/x86/kernel/cpu/mcheck/mce.c static void __cpuinit mce_reenable_cpu(void *h) · line 2070

Quoted 5 lines
arch/x86/kernel/cpu/mcheck/mce.c +5 -0
+static struct dentry *mce_add_event_debugfs(struct perf_event *event, int cpu)
+{
+	char buf[14];
+
+	sprintf(buf, "mce_record%d", cpu);

trivia:

Quoted 1 line

buf[14] doesn't fit 10k+ cpus.

I'll fix that when someone comes up with a x86 system that supports 10k+ CPUs with a single system image :).

Signature · 8 lines
Regards/Gruss,
Boris.

Advanced Micro Devices GmbH
Einsteinring 24, 85609 Dornach
General Managers: Alberto Bozzo, Andrew Bowd
Registration: Dornach, Gemeinde Aschheim, Landkreis Muenchen
Registergericht Muenchen, HRB Nr. 43632
#17 lore raw

Re: [PATCH 3/4] x86, mce: Add persistent MCE event

Quoted 12 lines · Borislav Petkov
Quoted 11 lines · Joe Perches
Quoted 2 lines · Borislav Petkov
Quoted 1 line · Ingo Molnar

* Borislav Petkov <[email protected]> wrote:

[]

Quoted 5 lines
Quoted 5 lines

arch/x86/kernel/cpu/mcheck/mce.c static void __cpuinit mce_reenable_cpu(void *h) · line 2070

Quoted 5 lines
arch/x86/kernel/cpu/mcheck/mce.c +5 -0
+static struct dentry *mce_add_event_debugfs(struct perf_event *event, int cpu)
+{
+	char buf[14];
+
+	sprintf(buf, "mce_record%d", cpu);

trivia:
buf[14] doesn't fit 10k+ cpus.

Quoted 2 lines

I'll fix that when someone comes up with a x86 system that supports 10k+ CPUs with a single system image :).

Your choice.

I think leaving trivially fixable known defects around isn't good engineering, but maybe that's just me.

#18 lore raw

Re: [PATCH 3/4] x86, mce: Add persistent MCE event

In reply to Borislav Petkov
Quoted 8 lines · Borislav Petkov
Quoted 7 lines · Joe Perches
Quoted 2 lines · Borislav Petkov
Quoted 1 line · Ingo Molnar

* Borislav Petkov <[email protected]> wrote:

[]

Quoted 3 lines
Quoted 3 lines

arch/x86/kernel/cpu/mcheck/mce.c static void __cpuinit mce_reenable_cpu(void *h) · line 2068

Quoted 3 lines
arch/x86/kernel/cpu/mcheck/mce.c +3 -0
+static struct dentry *mce_add_event_debugfs(struct perf_event *event, int cpu)
+{
+	char buf[14];

There should be no harm in upping that number to 32. (I've seen much worse on stacks).

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+
+	sprintf(buf, "mce_record%d", cpu);

At least change this to:

		snprintf(buf, 14, ....)
Quoted 8 lines
Quoted 4 lines

trivia:

buf[14] doesn't fit 10k+ cpus.

I'll fix that when someone comes up with a x86 system that supports 10k+ CPUs with a single system image :).

Best to fix it now, to save the trouble of finding this bug for those that are maintaining this code long after we have retired or are dead ;)

-- Steve

#19 lore raw

Re: [PATCH 3/4] x86, mce: Add persistent MCE event

Quoted 13 lines · Steven Rostedt
Quoted 8 lines · Borislav Petkov
Quoted 7 lines · Joe Perches
Quoted 2 lines · Borislav Petkov
Quoted 1 line · Ingo Molnar

* Borislav Petkov <[email protected]> wrote:

[]

Quoted 3 lines
Quoted 3 lines

arch/x86/kernel/cpu/mcheck/mce.c static void __cpuinit mce_reenable_cpu(void *h) · line 2068

Quoted 3 lines
arch/x86/kernel/cpu/mcheck/mce.c +3 -0
+static struct dentry *mce_add_event_debugfs(struct perf_event *event, int cpu)
+{
+	char buf[14];

There should be no harm in upping that number to 32. (I've seen much worse on stacks).

Quoted 6 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+
+	sprintf(buf, "mce_record%d", cpu);

At least change this to:

		snprintf(buf, 14, ....)

Yep, this is the only sane suggestion I've got, thanks.

Other than that, we shouldn't be concentrating too much on this since we're moving to /sysfs anyway and there we have the per-CPU hierarchy with /sys/devices/system/cpu/cpu%d...

Quoted 6 lines
Quoted 3 lines

I'll fix that when someone comes up with a x86 system that supports 10k+ CPUs with a single system image :).

Best to fix it now, to save the trouble of finding this bug for those that are maintaining this code long after we have retired or are dead ;)

Nah, I'll leave it in so that they can have a blast from the past and can boast on the slashdot of the future or on ((LWN++)..)++ that they've fixed the oldest bug in Linux when booting it on quantum x86 computers and tried running their RAS daemon :-).

Signature · 8 lines
Regards/Gruss,
Boris.

Advanced Micro Devices GmbH
Einsteinring 24, 85609 Dornach
General Managers: Alberto Bozzo, Andrew Bowd
Registration: Dornach, Gemeinde Aschheim, Landkreis Muenchen
Registergericht Muenchen, HRB Nr. 43632
#20 lore raw

PATCH 4/4 x86, mce: Have MCE persistent event off by default for now

In reply to Borislav Petkov

From: Borislav Petkov <[email protected]>

This is new functionality and it affects all of x86 so we want to be very conservative about it and have it off by default for now, in case something goes awry. You can always enable it by supplying "ras" on the kernel command line.

Also, depending on whether it is enabled or not, we emit the tracepoint from a different place in the code to pick up additional decoded info.

---
 Documentation/kernel-parameters.txt |    2 ++
 arch/x86/include/asm/mce.h          |    1 +
 arch/x86/kernel/cpu/mcheck/mce.c    |   32 ++++++++++++++++++++++++++++++--
 drivers/edac/mce_amd.c              |    5 +++++
 4 files changed, 38 insertions(+), 2 deletions(-)
Documentation/kernel-parameters.txt +2 -0
index cc85a92..f09438a 100644
@@ -2165,6 +2165,8 @@ bytes respectively. Such letter suffixes can also be entirely omitted.
 	ramdisk_size=	[RAM] Sizes of RAM disks in kilobytes
 			See Documentation/blockdev/ramdisk.txt.
 
+	ras		[X86] Enable RAS daemon supporting functionality.
+
 	rcupdate.blimit=	[KNL,BOOT]
 			Set maximum number of finished RCU callbacks to process
 			in one batch.
arch/x86/include/asm/mce.h +1 -0
index 40cc9bc..649d47a 100644
@@ -131,6 +131,7 @@ extern struct atomic_notifier_head x86_mce_decoder_chain;
 
 extern int mce_disabled;
 extern int mce_p5_enabled;
+extern int ras;
 
 #ifdef CONFIG_X86_MCE
 int mcheck_init(void);
arch/x86/kernel/cpu/mcheck/mce.c +30 -2
index 9589ebf..3fb22cb 100644
@@ -59,6 +59,8 @@ static DEFINE_MUTEX(mce_read_mutex);
 #define CREATE_TRACE_POINTS
 #include <trace/events/mce.h>
 
+EXPORT_TRACEPOINT_SYMBOL_GPL(mce_record);
+
 int mce_disabled __read_mostly;
 
 #define MISC_MCELOG_MINOR	227
@@ -86,6 +88,7 @@ static int			mce_dont_log_ce		__read_mostly;
 int				mce_cmci_disabled	__read_mostly;
 int				mce_ignore_ce		__read_mostly;
 int				mce_ser			__read_mostly;
+int				ras			__read_mostly;
 
 struct mce_bank                *mce_banks		__read_mostly;
 
@@ -105,6 +108,7 @@ static int			cpu_missing;
  */
 ATOMIC_NOTIFIER_HEAD(x86_mce_decoder_chain);
 EXPORT_SYMBOL_GPL(x86_mce_decoder_chain);
+EXPORT_SYMBOL_GPL(ras);
 
 static int default_decode_mce(struct notifier_block *nb, unsigned long val,
 			       void *data)
@@ -163,8 +167,9 @@ void mce_log(struct mce *mce)
 {
 	unsigned next, entry;
 
-	/* Emit the trace record: */
-	trace_mce_record(mce);
+	if (!ras)
+		/* Emit the trace record: */
+		trace_mce_record(mce);
 
 	mce->finished = 0;
 	wmb();
@@ -1721,6 +1726,19 @@ static int __init mcheck_enable(char *str)
 }
 __setup("mce", mcheck_enable);
 
+static int __init ras_enable(char *str)
+{
+	/*
+	 * We enable the persistent event only if "ras" is supplied on the
+	 * command line.
+	 */
+	ras = 1;
+
+	return 0;
+}
+
+__setup("ras", ras_enable);
+
 int __init mcheck_init(void)
 {
 	atomic_notifier_chain_register(&x86_mce_decoder_chain, &mce_dec_nb);
@@ -2081,6 +2099,9 @@ static int mce_enable_perf_event_on_cpu(int cpu)
 	struct mce_tp_desc *d = &per_cpu(mce_event, cpu);
 	int err = -EINVAL;
 
+	if (!ras)
+		return 0;
+
 	d->event = perf_enable_persistent_event(&pattr, cpu, MCE_BUF_PAGES);
 	if (IS_ERR(d->event)) {
 		printk(KERN_ERR "MCE: Error enabling event on cpu %d\n", cpu);
@@ -2105,6 +2126,10 @@ ret:
 static void mce_disable_perf_event_on_cpu(int cpu)
 {
 	struct mce_tp_desc *d = &per_cpu(mce_event, cpu);
+
+	if (!ras)
+		return;
+
 	debugfs_remove(d->debugfs_entry);
 	perf_disable_persistent_event(d->event, cpu);
 }
@@ -2113,6 +2138,9 @@ static __init int mcheck_init_persistent_event(void)
 {
 	int cpu, err = 0;
 
+	if (!ras)
+		return -EBUSY;
+
 	get_online_cpus();
 
 	pattr.config = event_mce_record.event.type;
drivers/edac/mce_amd.c +5 -0
index 795cfbc..e329335 100644
@@ -1,5 +1,7 @@
 #include <linux/module.h>
 #include <linux/slab.h>
+#include <asm/mce.h>
+#include <trace/events/mce.h>
 
 #include "mce_amd.h"
 
@@ -829,6 +831,9 @@ int amd_decode_mce(struct notifier_block *nb, unsigned long val, void *data)
 
 	amd_decode_err_code(m->status & 0xffff);
 
+	if (ras)
+		trace_mce_record(m);
+
 	return NOTIFY_STOP;
 }
 EXPORT_SYMBOL_GPL(amd_decode_mce);
Signature · 1 line
1.7.4.rc2
#21 lore raw

Re: [PATCH 4/4] x86, mce: Have MCE persistent event off by default for now

Quoted 10 lines · Borislav Petkov

From: Borislav Petkov <[email protected]>

This is new functionality and it affects all of x86 so we want to be very conservative about it and have it off by default for now, in case something goes awry. You can always enable it by supplying "ras" on the kernel command line.

Also, depending on whether it is enabled or not, we emit the tracepoint from a different place in the code to pick up additional decoded info.

Quoted 7 lines
---
 Documentation/kernel-parameters.txt |    2 ++
 arch/x86/include/asm/mce.h          |    1 +
 arch/x86/kernel/cpu/mcheck/mce.c    |   32 ++++++++++++++++++++++++++++++--
 drivers/edac/mce_amd.c              |    5 +++++
 4 files changed, 38 insertions(+), 2 deletions(-)

the boot flag is fine - but please keep it enabled by default if MCE support is enabled in the .config, we do not chicken out when it comes to testing new code! :-)

Thanks,

Ingo

#22 lore raw

Re: [PATCH 4/4] x86, mce: Have MCE persistent event off by default for now

Quoted 21 lines · Ingo Molnar
Quoted 10 lines · Borislav Petkov

From: Borislav Petkov <[email protected]>

This is new functionality and it affects all of x86 so we want to be very conservative about it and have it off by default for now, in case something goes awry. You can always enable it by supplying "ras" on the kernel command line.

Also, depending on whether it is enabled or not, we emit the tracepoint from a different place in the code to pick up additional decoded info.

Quoted 7 lines
---
 Documentation/kernel-parameters.txt |    2 ++
 arch/x86/include/asm/mce.h          |    1 +
 arch/x86/kernel/cpu/mcheck/mce.c    |   32 ++++++++++++++++++++++++++++++--
 drivers/edac/mce_amd.c              |    5 +++++
 4 files changed, 38 insertions(+), 2 deletions(-)
Quoted 3 lines

the boot flag is fine - but please keep it enabled by default if MCE support is enabled in the .config, we do not chicken out when it comes to testing new code! :-)

Ok, the problem I see with it is that people without a RAS daemon running will have the mechanism collecting MCEs in the background, using up resources (4 pages per CPU is the buffer) and not doing anything (in the best case that is, when we're not broken otherwise).

Do we want to have that on all x86 turned on by default? Or maybe invert the flag semantics so that people can disable it on boot?

Thanks.

Signature · 8 lines
Regards/Gruss,
Boris.

Advanced Micro Devices GmbH
Einsteinring 24, 85609 Dornach
General Managers: Alberto Bozzo, Andrew Bowd
Registration: Dornach, Gemeinde Aschheim, Landkreis Muenchen
Registergericht Muenchen, HRB Nr. 43632
#23 lore raw

Re: [PATCH 4/4] x86, mce: Have MCE persistent event off by default for now

Quoted 22 lines · Borislav Petkov
Quoted 21 lines · Ingo Molnar
Quoted 17 lines · Borislav Petkov

From: Borislav Petkov <[email protected]>

This is new functionality and it affects all of x86 so we want to be very conservative about it and have it off by default for now, in case something goes awry. You can always enable it by supplying "ras" on the kernel command line.

Also, depending on whether it is enabled or not, we emit the tracepoint from a different place in the code to pick up additional decoded info.

---
 Documentation/kernel-parameters.txt |    2 ++
 arch/x86/include/asm/mce.h          |    1 +
 arch/x86/kernel/cpu/mcheck/mce.c    |   32 ++++++++++++++++++++++++++++++--
 drivers/edac/mce_amd.c              |    5 +++++
 4 files changed, 38 insertions(+), 2 deletions(-)
Quoted 8 lines
Quoted 3 lines

the boot flag is fine - but please keep it enabled by default if MCE support is enabled in the .config, we do not chicken out when it comes to testing new code! :-)

Ok, the problem I see with it is that people without a RAS daemon running will have the mechanism collecting MCEs in the background, using up resources (4 pages per CPU is the buffer) and not doing anything (in the best case that is, when we're not broken otherwise).

Well, i'd put it behind a new Kconfig option which is default enabled if MCE support is enabled. That way people can still disable it both in the .config and on the boot command line as well.

Quoted 2 lines

Do we want to have that on all x86 turned on by default? Or maybe invert the flag semantics so that people can disable it on boot?

Boot flagsshould have feature=on/off kind of obvious semantics.

Thanks,

Ingo

maintainer
#24 lore raw

RE: [PATCH 4/4] x86, mce: Have MCE persistent event off by default for now

In reply to Borislav Petkov
Quoted 4 lines

Ok, the problem I see with it is that people without a RAS daemon running will have the mechanism collecting MCEs in the background, using up resources (4 pages per CPU is the buffer) and not doing anything (in the best case that is, when we're not broken otherwise).

Can the kernel detect whether anyone is listening to the persistent MCE event? If so, then the kernel could printk() something to let the user with no RAS daemon (or a dead daemon) that stuff is happening that they might like to know about.

Probably make some sense to delay such a message (so that in the boot case we give the daemon a chance to get started before complaining that it hasn't shown up for work).

-Tony

#25 lore raw

Re: [PATCH 4/4] x86, mce: Have MCE persistent event off by default for now

Quoted 10 lines · Tony
Quoted 4 lines

Ok, the problem I see with it is that people without a RAS daemon running will have the mechanism collecting MCEs in the background, using up resources (4 pages per CPU is the buffer) and not doing anything (in the best case that is, when we're not broken otherwise).

Can the kernel detect whether anyone is listening to the persistent MCE event? If so, then the kernel could printk() something to let the user with no RAS daemon (or a dead daemon) that stuff is happening that they might like to know about.

Right, so I have a primitive way to do that when you enable ras over the command line, i.e. boot with "ras=on." But that doesn't help in cases where the daemon dies for some reason.

Maybe the decoding path should look at whether the event descriptor is still mmapped or whether the event is enabled; let me think about it a bit longer, good point btw!

Quoted 3 lines

Probably make some sense to delay such a message (so that in the boot case we give the daemon a chance to get started before complaining that it hasn't shown up for work).

Yep, that and also I need to address the case for catching earlybird MCEs, when perf hasn't been initialized yet. I'm thinking we could reuse the mcelog buffer and feed those into the RAS daemon after init. Something like that.

Thanks.

Signature · 8 lines
Regards/Gruss,
Boris.

Advanced Micro Devices GmbH
Einsteinring 24, 85609 Dornach
General Managers: Alberto Bozzo, Andrew Bowd
Registration: Dornach, Gemeinde Aschheim, Landkreis Muenchen
Registergericht Muenchen, HRB Nr. 43632
#26 lore raw

Re: [PATCH 4/4] x86, mce: Have MCE persistent event off by default for now

Quoted 7 lines · Borislav Petkov
Quoted 3 lines

Probably make some sense to delay such a message (so that in the boot case we give the daemon a chance to get started before complaining that it hasn't shown up for work).

Yep, that and also I need to address the case for catching earlybird MCEs, when perf hasn't been initialized yet. I'm thinking we could reuse the mcelog buffer and feed those into the RAS daemon after init. Something like that.

I'd suggest that to solve that problem we initialize events earlier and allow something like a small static buffer backed event which does not need any dynamic memory so it can be enabled early on and can receive events, at the same time the MCE hw bits are enabled.

That event can get a larger buffer once the system is more fully up - without losing whatever events it is already holding.

Thanks,

Ingo

#27 lore raw

Re: [PATCH 4/4] x86, mce: Have MCE persistent event off by default for now

In reply to Luck, Tony
Quoted 11 lines · Luck, Tony
Quoted 4 lines

Ok, the problem I see with it is that people without a RAS daemon running will have the mechanism collecting MCEs in the background, using up resources (4 pages per CPU is the buffer) and not doing anything (in the best case that is, when we're not broken otherwise).

Can the kernel detect whether anyone is listening to the persistent MCE event? If so, then the kernel could printk() something to let the user with no RAS daemon (or a dead daemon) that stuff is happening that they might like to know about.

Quoted 3 lines

Probably make some sense to delay such a message (so that in the boot case we give the daemon a chance to get started before complaining that it hasn't shown up for work).

Yes, i definitely think a gateway to printk would be useful, so that the system can log MCE events the syslog way as well. This probably makes sense for persistent events in general, not just MCE events.

Btw., as a sidenote, the much more interesting direction is the reverse
direction: we want a gateway of printk into the RAS daemon as well - in form of a special 'printk events' that contain:

- the log level of the kernel when the message was generated
- the log level of the message
- the printk timestamp
- plus the printk message itself, as a free-form string

This would allow RAS functionality to dispatch off printk events immediately and transparently, without having to separately worry about how to talk to syslogd/klogd how to get its logs ...

printk itself could become a persistent event. (Transparently and without breaking compatible syslogd/klogd functionality.)

This would also allow the RAS daemon to log printk messages around suspicious MCE events, in a time-serialized way via a single event channel - so post mortem can be done using a single facility.

There's ongoing work to timestamp perf events with GTOD timestamps - that way global log analysis becomes possible as well.

Thanks,

Ingo

maintainer
#28 lore raw

RE: [PATCH 4/4] x86, mce: Have MCE persistent event off by default for now

Quoted 3 lines

Yes, i definitely think a gateway to printk would be useful, so that the system can log MCE events the syslog way as well. This probably makes sense for persistent events in general, not just MCE events.

s/as well/instead/ ??? If the persistent event mechanism is correctly feeding data to a mart daemon, I don't think we need any printk() chatter. It is only if this is not working that we'd want to see some console logging.

I agree that this isn't just a property of the MCE persistent event - other persistent events would very likely want a way to shout for help if the events are piling up with no listener.

Quoted 2 lines

printk itself could become a persistent event. (Transparently and without breaking compatible syslogd/klogd functionality.)

Someone from Google was very skeptical of printk() remaining stable from release to release ... a big issue when you have some heavy duty infrastructure trying to parse and consume these messages. We should really consider such stuff a user visible ABI, and thus not subject to random breakage - which is a radical departure from our current attitude to printk().

-Tony

#29 lore raw

Re: [PATCH 4/4] x86, mce: Have MCE persistent event off by default for now

Em Wed, May 04, 2011 at 02:40:37PM -0700, Luck, Tony escreveu:

Quoted 12 lines
Quoted 3 lines

Yes, i definitely think a gateway to printk would be useful, so that the system can log MCE events the syslog way as well. This probably makes sense for persistent events in general, not just MCE events.

s/as well/instead/ ??? If the persistent event mechanism is correctly feeding data to a mart daemon, I don't think we need any printk() chatter. It is only if this is not working that we'd want to see some console logging.

I agree that this isn't just a property of the MCE persistent event - other persistent events would very likely want a way to shout for help if the events are piling up with no listener.

Quoted 8 lines
Quoted 2 lines

printk itself could become a persistent event. (Transparently and without breaking compatible syslogd/klogd functionality.)

Someone from Google was very skeptical of printk() remaining stable from release to release ... a big issue when you have some heavy duty infrastructure trying to parse and consume these messages. We should really consider such stuff a user visible ABI, and thus not subject to random breakage - which is a radical departure from our current attitude to printk().

what is the problem with adding free form additional info to whatever turns into heavenly for ever unchanged dogma? :-)

- Arnaldo

#30 lore raw

Re: [PATCH 4/4] x86, mce: Have MCE persistent event off by default for now

In reply to Luck, Tony
Quoted 7 lines · Luck, Tony
Quoted 3 lines

Yes, i definitely think a gateway to printk would be useful, so that the system can log MCE events the syslog way as well. This probably makes sense for persistent events in general, not just MCE events.

s/as well/instead/ ??? If the persistent event mechanism is correctly feeding data to a mart daemon, I don't think we need any printk() chatter. It is only if this is not working that we'd want to see some console logging.

That could certainly be the default incarnation of it, but flexibly allowing all the variations does not look particularly bothersome either.

I have no problem with only offering the sanest variations though.

Quoted 3 lines

I agree that this isn't just a property of the MCE persistent event - other persistent events would very likely want a way to shout for help if the events are piling up with no listener.

Yeah. Basically a fallback mechanism and would also inform users about the availability of a nice RAS daemon out there.

Quoted 5 lines
Quoted 2 lines

printk itself could become a persistent event. (Transparently and without breaking compatible syslogd/klogd functionality.)

Someone from Google was very skeptical of printk() remaining stable from release to release ... [...]

Yeah, the printk messages themselves are not ABI nor will they ever be - although spurious changes are rare so they might provide a bridge to structured events.

printk events are a compatibility wrapper to allow RAS functionality to have easy and unified access to all system events that matter. The structure of printk events is obviously the log level plus a free-form ASCII string, something like:

1- the printk timestamp
2- the log level of the kernel when the message was generated 3- the log level of the message
4- the printk message itself, as a free-form string

Quoted 4 lines

[...] a big issue when you have some heavy duty infrastructure trying to parse and consume these messages. We should really consider such stuff a user visible ABI, and thus not subject to random breakage - which is a radical departure from our current attitude to printk().

Indeed, turning printk into an ABI clearly wont fly upstream although i'd expect upstream to *care more* about good printk messages if the RAS daemon starts making good use of it. Any printk message that turns out to be useful can be turned into an ABI by defining a proper structured event out of it, via TRACE_EVENT() et al.

This does not mean that it's not *useful* to allow the streaming of all print evnts to the RAS daemon. They are available, they get generated and they clearly look useful to me, and it will be useful when a sysadmin looks at the RAS log to figure out an incident.

Consider an example of two logs, one with just pure RAS events, the other with printk lines (and user-space events, see my patch a couple of months ago that allows event injection for critical user-space events as well) embedded:

The MCE-only log:

Subsystem | Time | event
------------------------------------------------------------------

 [MCE]         May 5 05:23:56   correctable MCE event on memory bank X
 [MCE]         May 5 06:19:59   correctable MCE event on memory bank X

Versus a broader, unified log (all events come via the perf event mmap ring-buffer, ordered properly and delivered quickly and transparently):

Subsystem | Time | event
------------------------------------------------------------------

 [MCE]         May 5 05:23:56   correctable MCE event on memory bank X
 [printk]      May 5 06:19:53   thermal trip triggered
 [MCE]         May 5 06:19:59   correctable MCE event on memory bank X
 [fault]       May 5 06:20:00   delivered SIGSEGV to task 'httpd' 
 [httpd]       May 5 06:20:00   unexpected restart
 [printk]      May 5 06:20:01   EXT4-fs (9345): group descriptors corrupted!

As a sysadmin i might misinterpret the first one as a low and still acceptable rate of correctable MCE errors: roughly one event per hour.

I'd take the second log *much* more seriously and would prioritize this incident as it likely indicates bad (overheating?) hardware and user-visible crashes and possible uncorrected data corruption.

Note that we made use of printk events, fault events and user-space injected events as well, in addition to the primary MCE events.

And yes, some of the printk events, if they are relied on frequently and programmatically, will be turned into proper events - and this process is helped by printk events.

As i understood it, being useful in such a way is one of the main goals of the new RAS daemon.

Thanks,

Ingo

#31 lore raw

Re: [PATCH 4/4] x86, mce: Have MCE persistent event off by default for now

Quoted 6 lines · Ingo Molnar

printk events are a compatibility wrapper to allow RAS functionality to have easy and unified access to all system events that matter. The structure of printk events is obviously the log level plus a free-form ASCII string, something like:

1- the printk timestamp

Yeah, we want here the timestamp when the event happened.

Quoted 9 lines

2- the log level of the kernel when the message was generated 3- the log level of the message
4- the printk message itself, as a free-form string

Quoted 4 lines

[...] a big issue when you have some heavy duty infrastructure trying to parse and consume these messages. We should really consider such stuff a user visible ABI, and thus not subject to random breakage - which is a radical departure from our current attitude to printk().

Quoted 5 lines

Indeed, turning printk into an ABI clearly wont fly upstream although i'd expect upstream to *care more* about good printk messages if the RAS daemon starts making good use of it. Any printk message that turns out to be useful can be turned into an ABI by defining a proper structured event out of it, via TRACE_EVENT() et al.

Actually let's have the RAS printk's as TRACE_EVENT's from the start
- it's not like we're going to convert every printk call into a RAS printk event. We only want relevant ones from traps.c, maybe some power management events, fs, maybe some critical security stuff, etc.

Quoted 11 lines

This does not mean that it's not *useful* to allow the streaming of all print evnts to the RAS daemon. They are available, they get generated and they clearly look useful to me, and it will be useful when a sysadmin looks at the RAS log to figure out an incident.

Consider an example of two logs, one with just pure RAS events, the other with printk lines (and user-space events, see my patch a couple of months ago that allows event injection for critical user-space events as well) embedded:

The MCE-only log:

Quoted 7 lines

Subsystem | Time | event
------------------------------------------------------------------

 [MCE]         May 5 05:23:56   correctable MCE event on memory bank X
 [MCE]         May 5 06:19:59   correctable MCE event on memory bank X

Versus a broader, unified log (all events come via the perf event mmap ring-buffer, ordered properly and delivered quickly and transparently):

Yes, especially since we can get it out to userspace even faster than printk :).

Quoted 8 lines

Subsystem | Time | event
------------------------------------------------------------------

 [MCE]         May 5 05:23:56   correctable MCE event on memory bank X
 [printk]      May 5 06:19:53   thermal trip triggered
 [MCE]         May 5 06:19:59   correctable MCE event on memory bank X
 [fault]       May 5 06:20:00   delivered SIGSEGV to task 'httpd' 
 [httpd]       May 5 06:20:00   unexpected restart
 [printk]      May 5 06:20:01   EXT4-fs (9345): group descriptors corrupted!

^^ I wouldn't even call it "printk" since this is obviously [fs]. The printk event should have a field that says from which subsys the printk comes from and thus make it so integrated that it is even invisible :).

And

Quoted 1 line

[printk] May 5 06:19:53 thermal trip triggered

could be

Quoted 1 line

[pm] May 5 06:19:53 thermal trip triggered

for power management.

Quoted 10 lines

As a sysadmin i might misinterpret the first one as a low and still acceptable rate of correctable MCE errors: roughly one event per hour.

I'd take the second log *much* more seriously and would prioritize this incident as it likely indicates bad (overheating?) hardware and user-visible crashes and possible uncorrected data corruption.

Note that we made use of printk events, fault events and user-space injected events as well, in addition to the primary MCE events.

Quoted 6 lines

And yes, some of the printk events, if they are relied on frequently and programmatically, will be turned into proper events - and this process is helped by printk events.

As i understood it, being useful in such a way is one of the main goals of the new RAS daemon.

Yep, this is absolutely what we want to do - we want to have RAS events not only coupled with hardware events but actually collect all _relevant_ events into a common RAS log that is very lightweight and doesn't rely on printk. It can, _however_, be turned into printk's (and it should) if no daemon is running. And yes, we can have special tags like "[[..]]" or whatever to be able to grep it out even from dmesg.

Cool,
thanks.

Signature · 8 lines
Regards/Gruss,
Boris.

Advanced Micro Devices GmbH
Einsteinring 24, 85609 Dornach
General Managers: Alberto Bozzo, Andrew Bowd
Registration: Dornach, Gemeinde Aschheim, Landkreis Muenchen
Registergericht Muenchen, HRB Nr. 43632
#32 lore raw

Re: [PATCH 4/4] x86, mce: Have MCE persistent event off by default for now

Quoted 25 lines · Borislav Petkov
Quoted 6 lines · Ingo Molnar

printk events are a compatibility wrapper to allow RAS functionality to have easy and unified access to all system events that matter. The structure of printk events is obviously the log level plus a free-form ASCII string, something like:

1- the printk timestamp

Yeah, we want here the timestamp when the event happened.

Quoted 9 lines

2- the log level of the kernel when the message was generated 3- the log level of the message
4- the printk message itself, as a free-form string

Quoted 4 lines

[...] a big issue when you have some heavy duty infrastructure trying to parse and consume these messages. We should really consider such stuff a user visible ABI, and thus not subject to random breakage - which is a radical departure from our current attitude to printk().

Quoted 5 lines

Indeed, turning printk into an ABI clearly wont fly upstream although i'd expect upstream to *care more* about good printk messages if the RAS daemon starts making good use of it. Any printk message that turns out to be useful can be turned into an ABI by defining a proper structured event out of it, via TRACE_EVENT() et al.

Quoted 3 lines

Actually let's have the RAS printk's as TRACE_EVENT's from the start
- it's not like we're going to convert every printk call into a RAS printk event. [...]

Fully agreed that printk should be a TRACE_EVENT() from the get go.

What i meant was that it also gives an opportunity for the introduction of new TRACE_EVENT()s: if RAS tooling sees problems with some important printk changing its format all the time then such problems can be addressed by 'upgrading' that printk event to a TRACE_EVENT().

Quoted 2 lines

[...] We only want relevant ones from traps.c, maybe some power management events, fs, maybe some critical security stuff, etc.

Yeah. And what that 'critical stuff' is will probably be found out gradually. In the meanwhile we'll have printk events as a starting point.

The printk event is also useful for a practical reason: if you add it right now you can test the RAS daemon and provoke a steady stream of events easily by catching (and generating) printk events.

( We also want event injection to work, to be able to simulate real MCE
events. )

Thanks,

Ingo