]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/commitdiff
x86/nmi: Remove irq_work from the long duration NMI handler
authorChangbin Du <changbin.du@gmail.com>
Sat, 11 Jan 2020 12:54:27 +0000 (20:54 +0800)
committerKleber Sacilotto de Souza <kleber.souza@canonical.com>
Tue, 7 Apr 2020 08:50:47 +0000 (10:50 +0200)
BugLink: https://bugs.launchpad.net/bugs/1867837
[ Upstream commit 248ed51048c40d36728e70914e38bffd7821da57 ]

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 <changbin.du@gmail.com>
Signed-off-by: Borislav Petkov <bp@suse.de>
Acked-by: Thomas Gleixner <tglx@linutronix.de>
Link: https://lkml.kernel.org/r/20200111125427.15662-1-changbin.du@gmail.com
Signed-off-by: Sasha Levin <sashal@kernel.org>
Signed-off-by: Kamal Mostafa <kamal@canonical.com>
Signed-off-by: Khalid Elmously <khalid.elmously@canonical.com>
arch/x86/include/asm/nmi.h
arch/x86/kernel/nmi.c

index 75ded1d13d98d6cde6f01ab8602587145e010707..9d5d949e662e14bcb90934f1ba312123a2b10bd1 100644 (file)
@@ -41,7 +41,6 @@ struct nmiaction {
        struct list_head        list;
        nmi_handler_t           handler;
        u64                     max_duration;
-       struct irq_work         irq_work;
        unsigned long           flags;
        const char              *name;
 };
index 086cf1d1d71d820e13baca26091d6104abea9eb9..0f8b9b900b0e7e0a86eca925f2bf2aec58171677 100644 (file)
@@ -102,18 +102,22 @@ static int __init nmi_warning_debugfs(void)
 }
 fs_initcall(nmi_warning_debugfs);
 
-static void nmi_max_handler(struct irq_work *w)
+static void nmi_check_duration(struct nmiaction *action, u64 duration)
 {
-       struct nmiaction *a = container_of(w, struct nmiaction, irq_work);
+       u64 whole_msecs = READ_ONCE(action->max_duration);
        int remainder_ns, decimal_msecs;
-       u64 whole_msecs = READ_ONCE(a->max_duration);
+
+       if (duration < nmi_longest_ns || duration < action->max_duration)
+               return;
+
+       action->max_duration = 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);
+               action->handler, whole_msecs, decimal_msecs);
 }
 
 static int nmi_handle(unsigned int type, struct pt_regs *regs)
@@ -140,11 +144,7 @@ static int nmi_handle(unsigned int type, struct pt_regs *regs)
                delta = sched_clock() - delta;
                trace_nmi_handler(a->handler, (int)delta, thishandled);
 
-               if (delta < nmi_longest_ns || delta < a->max_duration)
-                       continue;
-
-               a->max_duration = delta;
-               irq_work_queue(&a->irq_work);
+               nmi_check_duration(a, delta);
        }
 
        rcu_read_unlock();
@@ -162,8 +162,6 @@ int __register_nmi_handler(unsigned int type, struct nmiaction *action)
        if (!action->handler)
                return -EINVAL;
 
-       init_irq_work(&action->irq_work, nmi_max_handler);
-
        raw_spin_lock_irqsave(&desc->lock, flags);
 
        /*