Skip to content

Commit 248ed51

Browse files
changbindusuryasaimadhu
authored andcommitted
x86/nmi: Remove irq_work from the long duration NMI handler
First, printk() is NMI-context safe now since the safe printk() has been implemented and it already has an irq_work to make NMI-context safe. Second, this NMI irq_work actually does not work if a NMI handler causes panic by watchdog timeout. It has no chance to run in such case, while the safe printk() will flush its per-cpu buffers before panicking. While at it, repurpose the irq_work callback into a function which concentrates the NMI duration checking and makes the code easier to follow. [ bp: Massage. ] Signed-off-by: Changbin Du <[email protected]> Signed-off-by: Borislav Petkov <[email protected]> Acked-by: Thomas Gleixner <[email protected]> Link: https://lkml.kernel.org/r/[email protected]
1 parent 3620976 commit 248ed51

File tree

2 files changed

+9
-12
lines changed

2 files changed

+9
-12
lines changed

arch/x86/include/asm/nmi.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ struct nmiaction {
4141
struct list_head list;
4242
nmi_handler_t handler;
4343
u64 max_duration;
44-
struct irq_work irq_work;
4544
unsigned long flags;
4645
const char *name;
4746
};

arch/x86/kernel/nmi.c

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -104,18 +104,22 @@ static int __init nmi_warning_debugfs(void)
104104
}
105105
fs_initcall(nmi_warning_debugfs);
106106

107-
static void nmi_max_handler(struct irq_work *w)
107+
static void nmi_check_duration(struct nmiaction *action, u64 duration)
108108
{
109-
struct nmiaction *a = container_of(w, struct nmiaction, irq_work);
109+
u64 whole_msecs = READ_ONCE(action->max_duration);
110110
int remainder_ns, decimal_msecs;
111-
u64 whole_msecs = READ_ONCE(a->max_duration);
111+
112+
if (duration < nmi_longest_ns || duration < action->max_duration)
113+
return;
114+
115+
action->max_duration = duration;
112116

113117
remainder_ns = do_div(whole_msecs, (1000 * 1000));
114118
decimal_msecs = remainder_ns / 1000;
115119

116120
printk_ratelimited(KERN_INFO
117121
"INFO: NMI handler (%ps) took too long to run: %lld.%03d msecs\n",
118-
a->handler, whole_msecs, decimal_msecs);
122+
action->handler, whole_msecs, decimal_msecs);
119123
}
120124

121125
static int nmi_handle(unsigned int type, struct pt_regs *regs)
@@ -142,11 +146,7 @@ static int nmi_handle(unsigned int type, struct pt_regs *regs)
142146
delta = sched_clock() - delta;
143147
trace_nmi_handler(a->handler, (int)delta, thishandled);
144148

145-
if (delta < nmi_longest_ns || delta < a->max_duration)
146-
continue;
147-
148-
a->max_duration = delta;
149-
irq_work_queue(&a->irq_work);
149+
nmi_check_duration(a, delta);
150150
}
151151

152152
rcu_read_unlock();
@@ -164,8 +164,6 @@ int __register_nmi_handler(unsigned int type, struct nmiaction *action)
164164
if (!action->handler)
165165
return -EINVAL;
166166

167-
init_irq_work(&action->irq_work, nmi_max_handler);
168-
169167
raw_spin_lock_irqsave(&desc->lock, flags);
170168

171169
/*

0 commit comments

Comments
 (0)