Re: [PATCH] x86/mce: Fix timer interval adjustment after logging a MCE event

Luck, Tony
2026-01-14T00:30:15Z

On Tue, Jan 13, 2026 at 11:41:52PM +0100, Borislav Petkov wrote:
> On Tue, Jan 13, 2026 at 10:31:58PM +0100, Borislav Petkov wrote:
> > Ufff, how silly and overengineered we've made it. I need to think about
> > a cleaner solution tomorrow...
>
> One idea I just thought of:
>
> those two steps:
>
> 1. setting mce_need_notify, and
>
> 2. testing and clearing it
>
> are basically logically a one query: do we have logged errors, or, IOW, is the
> gen pool not empty?
>
> IOW, this below.
>
> That'll get rid of that gunk of when should we test and when set and will
> JustWork(tm) for what we want it to do.
>
> But let's see how it all really works tomorrow...
>
> diff --git a/arch/x86/kernel/cpu/mce/core.c b/arch/x86/kernel/cpu/mce/core.c
> index 34440021e8cf..c378d4d450b6 100644
> --- a/arch/x86/kernel/cpu/mce/core.c
> +++ b/arch/x86/kernel/cpu/mce/core.c
> @@ -595,7 +595,7 @@ static bool mce_notify_irq(void)
> /* Not more than two messages every minute */
> static DEFINE_RATELIMIT_STATE(ratelimit, 60*HZ, 2);
>
> - if (test_and_clear_bit(0, &mce_need_notify)) {
> + if (!mce_gen_pool_empty()) {
> mce_work_trigger();
>
> if (__ratelimit(&ratelimit))
> @@ -618,10 +618,6 @@ static int mce_early_notifier(struct notifier_block *nb, unsigned long val,
> /* Emit the trace record: */
> trace_mce_record(err);
>
> - set_bit(0, &mce_need_notify);
> -
> - mce_notify_irq();
> -
> return NOTIFY_DONE;
> }
>

Seems to work (though you've deleted all the places where mce_need_notify
is used, so you can also delete the declaration.

@@ -90,7 +90,6 @@ struct mca_config mca_cfg __read_mostly = {
};

static DEFINE_PER_CPU(struct mce_hw_err, hw_errs_seen);
-static unsigned long mce_need_notify;

/*
* MCA banks polled by the period polling timer for corrected events.

I see time delta between logs reducing while I'm injecting errors.

When I pause injection for several minutes, and then restart I see the
interval went back up again.

-Tony