mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Borislav Petkov <bp@amd64.org>
To: <acme@infradead.org>, <fweisbec@gmail.com>, <mingo@elte.hu>,
	<peterz@infradead.org>, <rostedt@goodmis.org>
Cc: <linux-kernel@vger.kernel.org>,
	Borislav Petkov <borislav.petkov@amd.com>
Subject: [PATCH 03/20] x86, mce: Add persistent MCE event
Date: Thu,  4 Nov 2010 16:36:39 +0100	[thread overview]
Message-ID: <1288885016-18295-4-git-send-email-bp@amd64.org> (raw)
In-Reply-To: <1288885016-18295-1-git-send-email-bp@amd64.org>

From: Borislav Petkov <borislav.petkov@amd.com>

Add the necessary glue to enable the mce_record tracepoint on boot
turning it into a persistent event. This exports the MCE buffer
read-only to a userspace daemon which will hook into it through debugfs
when booting is finished.

Signed-off-by: Borislav Petkov <borislav.petkov@amd.com>
---
 arch/x86/include/asm/mce.h       |    8 ++++
 arch/x86/kernel/cpu/mcheck/mce.c |   84 ++++++++++++++++++++++++++++++++++++++
 2 files changed, 92 insertions(+), 0 deletions(-)

diff --git a/arch/x86/include/asm/mce.h b/arch/x86/include/asm/mce.h
index c62c13c..c248038 100644
--- a/arch/x86/include/asm/mce.h
+++ b/arch/x86/include/asm/mce.h
@@ -91,6 +91,14 @@ struct mce_log {
 	struct mce entry[MCE_LOG_LEN];
 };
 
+/*
+ * a per-cpu descriptor of the persistent MCE tracepoint
+ */
+struct mce_tp_desc {
+	struct perf_event *event;
+	struct dentry *debugfs_entry;
+};
+
 #define MCE_OVERFLOW 0		/* bit 0 in flags means overflow */
 
 #define MCE_LOG_SIGNATURE	"MACHINECHECK"
diff --git a/arch/x86/kernel/cpu/mcheck/mce.c b/arch/x86/kernel/cpu/mcheck/mce.c
index ed41562..5ce3e72 100644
--- a/arch/x86/kernel/cpu/mcheck/mce.c
+++ b/arch/x86/kernel/cpu/mcheck/mce.c
@@ -95,8 +95,11 @@ static char			*mce_helper_argv[2] = { mce_helper, NULL };
 
 static DECLARE_WAIT_QUEUE_HEAD(mce_wait);
 static DEFINE_PER_CPU(struct mce, mces_seen);
+static DEFINE_PER_CPU(struct mce_tp_desc, mce_event);
 static int			cpu_missing;
 
+
+
 /*
  * CPU/chipset specific EDAC code can register a notifier call here to print
  * MCE errors in a human-readable form.
@@ -2052,6 +2055,86 @@ static void __cpuinit mce_reenable_cpu(void *h)
 	}
 }
 
+struct perf_event_attr pattr = {
+	.type		= PERF_TYPE_TRACEPOINT,
+	.size		= sizeof(pattr),
+	.sample_type	= PERF_SAMPLE_RAW,
+};
+
+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, mce_get_debugfs_dir(),
+				   event, &perf_pers_fops);
+}
+
+static int mce_enable_perf_event_on_cpu(int cpu)
+{
+	struct mce_tp_desc *d = &per_cpu(mce_event, cpu);
+	int err = 0;
+
+	err = perf_enable_persistent_event(&d->event, &pattr, cpu, 128);
+	if (err) {
+		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);
+	perf_disable_persistent_event(d->event, cpu);
+	debugfs_remove(d->debugfs_entry);
+}
+
+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 = ULLONG_MAX;
+
+	for_each_online_cpu(cpu)
+		if (mce_enable_perf_event_on_cpu(cpu))
+			goto unwind;
+
+	goto unlock;
+
+unwind:
+	for (--cpu; cpu >= 0; cpu--)
+		mce_disable_perf_event_on_cpu(cpu);
+
+unlock:
+	put_online_cpus();
+
+	return err;
+}
+
+/*
+ * This has to run after event_trace_init()
+ */
+device_initcall(mcheck_init_persistent_event);
+
+
 /* 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)
@@ -2065,6 +2148,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:
-- 
1.7.3.1


  parent reply	other threads:[~2010-11-04 15:38 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-11-04 15:36 [RFC PATCH 00/20] RAS daemon v3 Borislav Petkov
2010-11-04 15:36 ` [PATCH 01/20] perf: Start the massive restructuring Borislav Petkov
2010-11-04 15:36 ` [PATCH 02/20] perf: Add persistent event facilities Borislav Petkov
2010-11-04 15:36 ` Borislav Petkov [this message]
2010-11-10 21:15   ` [PATCH 03/20] x86, mce: Add persistent MCE event Ben Gamari
2010-11-10 22:21     ` Ingo Molnar
2010-11-11  6:17       ` Borislav Petkov
2010-11-11  8:58         ` Ingo Molnar
2010-11-11 13:34           ` Borislav Petkov
2010-11-11 15:38             ` Peter Zijlstra
2010-11-11 15:55               ` Borislav Petkov
2010-11-11 17:30                 ` Ingo Molnar
2010-11-04 15:36 ` [PATCH 04/20] perf: Move trace-event-parse out of perf/util directory Borislav Petkov
2010-11-04 15:36 ` [PATCH 05/20] perf: Update the lib parse-events to the latest code Borislav Petkov
2010-11-04 15:36 ` [PATCH 06/20] perf: Move trace stuff into tools/lib/trace Borislav Petkov
2010-11-04 15:36 ` [PATCH 07/20] perf: Export debugfs utilities Borislav Petkov
2010-11-04 15:36 ` [PATCH 08/20] perf: Export cpumap Borislav Petkov
2010-11-04 15:36 ` [PATCH 09/20] perf: Carve out mmap helpers for general use Borislav Petkov
2010-11-04 15:36 ` [PATCH 10/20] perf: Export util.ch into library Borislav Petkov
2010-11-04 15:36 ` [PATCH 11/20] perf: Move rbtree to library Borislav Petkov
2010-11-04 15:36 ` [PATCH 12/20] perf: Export generic kernel utils " Borislav Petkov
2010-11-04 15:36 ` [PATCH 13/20] perf: Export compiler.h to the generic library Borislav Petkov
2010-11-04 15:36 ` [PATCH 14/20] perf: Export color.ch and config.ch Borislav Petkov
2010-11-04 15:36 ` [PATCH 15/20] perf: Export strlist.ch Borislav Petkov
2010-11-04 15:36 ` [PATCH 16/20] perf: Export map.ch and symbol.ch Borislav Petkov
2010-11-04 15:36 ` [PATCH 17/20] perf: Export trace parsing utils Borislav Petkov
2010-11-04 15:36 ` [PATCH 18/20] Move string.c to the library Borislav Petkov
2010-11-04 15:36 ` [PATCH 19/20] perf, trace: Export event parsing helpers Borislav Petkov
2010-11-04 15:36 ` [PATCH 20/20] ras: Add RAS daemon Borislav Petkov
2010-11-05 12:02 ` [RFC PATCH 00/20] RAS daemon v3 Mauro Carvalho Chehab
2010-11-05 13:46   ` Borislav Petkov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1288885016-18295-4-git-send-email-bp@amd64.org \
    --to=bp@amd64.org \
    --cc=acme@infradead.org \
    --cc=borislav.petkov@amd.com \
    --cc=fweisbec@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    --cc=peterz@infradead.org \
    --cc=rostedt@goodmis.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome