Commit e90c7853 authored by Peter Zijlstra's avatar Peter Zijlstra Committed by Ingo Molnar

x86/nmi: Push duration printk() to irq context

Calling printk() from NMI context is bad (TM), so move it to IRQ
context.

In doing so we slightly change (probably wreck) the debugfs
nmi_longest_ns thingy, in that it doesn't update to reflect the
longest, nor does writing to it reset the count.
Signed-off-by: default avatarPeter Zijlstra <peterz@infradead.org>
Cc: Don Zickus <dzickus@redhat.com>
Cc: Dave Hansen <dave.hansen@linux.intel.com>
Link: http://lkml.kernel.org/n/tip-rdw0au56a5ymis1u8p48c12d@git.kernel.orgSigned-off-by: default avatarIngo Molnar <mingo@kernel.org>
parent 6a02ad66
#ifndef _ASM_X86_NMI_H #ifndef _ASM_X86_NMI_H
#define _ASM_X86_NMI_H #define _ASM_X86_NMI_H
#include <linux/irq_work.h>
#include <linux/pm.h> #include <linux/pm.h>
#include <asm/irq.h> #include <asm/irq.h>
#include <asm/io.h> #include <asm/io.h>
...@@ -38,6 +39,8 @@ typedef int (*nmi_handler_t)(unsigned int, struct pt_regs *); ...@@ -38,6 +39,8 @@ typedef int (*nmi_handler_t)(unsigned int, struct pt_regs *);
struct nmiaction { struct nmiaction {
struct list_head list; struct list_head list;
nmi_handler_t handler; nmi_handler_t handler;
u64 max_duration;
struct irq_work irq_work;
unsigned long flags; unsigned long flags;
const char *name; const char *name;
}; };
......
...@@ -87,6 +87,7 @@ __setup("unknown_nmi_panic", setup_unknown_nmi_panic); ...@@ -87,6 +87,7 @@ __setup("unknown_nmi_panic", setup_unknown_nmi_panic);
#define nmi_to_desc(type) (&nmi_desc[type]) #define nmi_to_desc(type) (&nmi_desc[type])
static u64 nmi_longest_ns = 1 * NSEC_PER_MSEC; static u64 nmi_longest_ns = 1 * NSEC_PER_MSEC;
static int __init nmi_warning_debugfs(void) static int __init nmi_warning_debugfs(void)
{ {
debugfs_create_u64("nmi_longest_ns", 0644, debugfs_create_u64("nmi_longest_ns", 0644,
...@@ -95,6 +96,20 @@ static int __init nmi_warning_debugfs(void) ...@@ -95,6 +96,20 @@ static int __init nmi_warning_debugfs(void)
} }
fs_initcall(nmi_warning_debugfs); fs_initcall(nmi_warning_debugfs);
static void nmi_max_handler(struct irq_work *w)
{
struct nmiaction *a = container_of(w, struct nmiaction, irq_work);
int remainder_ns, decimal_msecs;
u64 whole_msecs = ACCESS_ONCE(a->max_duration);
remainder_ns = do_div(whole_msecs, (1000 * 1000));
decimal_msecs = remainder_ns / 1000;
printk_ratelimited(KERN_INFO
"INFO: NMI handler (%ps) took too long to run: %lld.%03d msecs\n",
a->handler, whole_msecs, decimal_msecs);
}
static int __kprobes nmi_handle(unsigned int type, struct pt_regs *regs, bool b2b) static int __kprobes nmi_handle(unsigned int type, struct pt_regs *regs, bool b2b)
{ {
struct nmi_desc *desc = nmi_to_desc(type); struct nmi_desc *desc = nmi_to_desc(type);
...@@ -110,26 +125,20 @@ static int __kprobes nmi_handle(unsigned int type, struct pt_regs *regs, bool b2 ...@@ -110,26 +125,20 @@ static int __kprobes nmi_handle(unsigned int type, struct pt_regs *regs, bool b2
* to handle those situations. * to handle those situations.
*/ */
list_for_each_entry_rcu(a, &desc->head, list) { list_for_each_entry_rcu(a, &desc->head, list) {
u64 before, delta, whole_msecs; int thishandled;
int remainder_ns, decimal_msecs, thishandled; u64 delta;
before = sched_clock(); delta = sched_clock();
thishandled = a->handler(type, regs); thishandled = a->handler(type, regs);
handled += thishandled; handled += thishandled;
delta = sched_clock() - before; delta = sched_clock() - delta;
trace_nmi_handler(a->handler, (int)delta, thishandled); trace_nmi_handler(a->handler, (int)delta, thishandled);
if (delta < nmi_longest_ns) if (delta < nmi_longest_ns || delta < a->max_duration)
continue; continue;
nmi_longest_ns = delta; a->max_duration = delta;
whole_msecs = delta; irq_work_queue(&a->irq_work);
remainder_ns = do_div(whole_msecs, (1000 * 1000));
decimal_msecs = remainder_ns / 1000;
printk_ratelimited(KERN_INFO
"INFO: NMI handler (%ps) took too long to run: "
"%lld.%03d msecs\n", a->handler, whole_msecs,
decimal_msecs);
} }
rcu_read_unlock(); rcu_read_unlock();
...@@ -146,6 +155,8 @@ int __register_nmi_handler(unsigned int type, struct nmiaction *action) ...@@ -146,6 +155,8 @@ int __register_nmi_handler(unsigned int type, struct nmiaction *action)
if (!action->handler) if (!action->handler)
return -EINVAL; return -EINVAL;
init_irq_work(&action->irq_work, nmi_max_handler);
spin_lock_irqsave(&desc->lock, flags); spin_lock_irqsave(&desc->lock, flags);
/* /*
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment