Re: [PATCH] x86/nmi: Rate limit unknown NMI messages

From: Guilherme Amadio
Date: Sun Dec 10 2023 - 05:39:14 EST


On Fri, Dec 08, 2023 at 05:52:11PM -0800, Namhyung Kim wrote:
> On some AMD machines, unknown NMI messages were printed on the console
> continuously when using perf command with IBS. It was reported that it
> can slow down the kernel. Let's ratelimit the unknown NMI messages.
>
> Cc: Ravi Bangoria <ravi.bangoria@xxxxxxx>
> Cc: Guilherme Amadio <amadio@xxxxxxxxxx>

The rate of messages on the console were proportional to the sampling frequency
when I noticed this happening, so this is a welcome change. Thank you!

Acked-by: Guilherme Amadio <amadio@xxxxxxxxxx>

Best regards,
-Guilherme

> Cc: Stephane Eranian <eranian@xxxxxxxxxx>
> Signed-off-by: Namhyung Kim <namhyung@xxxxxxxxxx>
> ---
> arch/x86/kernel/nmi.c | 6 +++---
> 1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/arch/x86/kernel/nmi.c b/arch/x86/kernel/nmi.c
> index 17e955ab69fe..d23867901186 100644
> --- a/arch/x86/kernel/nmi.c
> +++ b/arch/x86/kernel/nmi.c
> @@ -303,13 +303,13 @@ unknown_nmi_error(unsigned char reason, struct pt_regs *regs)
>
> __this_cpu_add(nmi_stats.unknown, 1);
>
> - pr_emerg("Uhhuh. NMI received for unknown reason %02x on CPU %d.\n",
> - reason, smp_processor_id());
> + pr_emerg_ratelimited("Uhhuh. NMI received for unknown reason %02x on CPU %d.\n",
> + reason, smp_processor_id());
>
> if (unknown_nmi_panic || panic_on_unrecovered_nmi)
> nmi_panic(regs, "NMI: Not continuing");
>
> - pr_emerg("Dazed and confused, but trying to continue\n");
> + pr_emerg_ratelimited("Dazed and confused, but trying to continue\n");
> }
> NOKPROBE_SYMBOL(unknown_nmi_error);
>
> --
> 2.43.0.472.g3155946c3a-goog
>