lkml.org 
[lkml]   [2022]   [May]   [12]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
Date
From
SubjectRe: [PATCH 1/2] x86/crash: Disable virt in core NMI crash handler to avoid double list_add
On Thu, May 12, 2022, Thomas Gleixner wrote:
> Sean,
>
> On Wed, May 11 2022 at 23:43, Sean Christopherson wrote:
> > @@ -840,6 +858,20 @@ void nmi_shootdown_cpus(nmi_shootdown_cb callback)
> > unsigned long msecs;
> > local_irq_disable();
> >
> > + /*
> > + * Invoking multiple callbacks is not currently supported, registering
> > + * the NMI handler twice will cause a list_add() double add BUG().
> > + * The exception is the "nop" handler in the emergency reboot path,
> > + * which can run after e.g. kdump's shootdown. Do nothing if the crash
> > + * handler has already run, i.e. has already prepared other CPUs, the
> > + * reboot path doesn't have any work of its to do, it just needs to
> > + * ensure all CPUs have prepared for reboot.
>
> This is confusing at best. The double list add is just one part of the
> problem, which would be trivial enough to fix.
>
> The real point is that after the first shoot down all other CPUs are
> stuck in crash_nmi_callback() and won't respond to the second NMI.

Well that's embarrasingly obvious in hindsight.

>
> So trying to run this twice is completely pointless and guaranteed to
> run into the timeout.
>
> > + */
> > + if (shootdown_callback) {
> > + WARN_ON_ONCE(callback != nmi_shootdown_nop);
> > + return;
>
> Instead of playing games with the callback pointer, I prefer to make
> this all explicit. Delta patch below.

Much better. If you're planning on doing fixup, can you also include a comment
tweak about why the callback is left set? If not, I'll do it in v2. A bit
overkill, but it's another thing that for me was obvious only once I realized "why".

Thanks!

diff --git a/arch/x86/kernel/reboot.c b/arch/x86/kernel/reboot.c
index 4e3a839ae146..808d3e75fb2d 100644
--- a/arch/x86/kernel/reboot.c
+++ b/arch/x86/kernel/reboot.c
@@ -896,7 +896,11 @@ void nmi_shootdown_cpus(nmi_shootdown_cb callback)
msecs--;
}

- /* Leave the nmi callback set */
+ /*
+ * Leave the nmi callback set, shootdown is a one-time thing. Clearing
+ * the callback could result in a NULL pointer dereference if a CPU
+ * (finally) responds after the timeout expires.
+ */
}

static inline void nmi_shootdown_cpus_on_restart(void)
\
 
 \ /
  Last update: 2022-05-12 16:15    [W:3.351 / U:0.052 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site