Skip to content

Commit ea32444

Browse files
committed
x86/mce: Restore MCA polling interval halving
RongQing reported that the MCA polling interval doesn't halve when an error gets logged. It was traced down to the commit in Fixes:, because: mce_timer_fn() |-> mce_poll_banks() |-> machine_check_poll() |-> mce_log() which will queue the work and return. Now, back in mce_timer_fn(): /* * Alert userspace if needed. If we logged an MCE, reduce the polling * interval, otherwise increase the polling interval. */ if (mce_notify_irq()) <--- here we haven't ran the notifier chain yet so mce_need_notify is not set yet so this won't hit and we won't halve the interval iv. Now the notifier chain runs. mce_early_notifier() sets the bit, does mce_notify_irq(), that clears the bit and then the notifier chain a little later logs the error. So this is a silly timing issue. But, that's all unnecessary. All it needs to happen here is, the "should we notify of a logged MCE" mce_notify_irq() asks, should be simply a question to the mce gen pool: "Are you empty?" And that then turns into a simple yes or no answer and it all JustWorks(tm). So do that and also distribute the functionality where it belongs: - Print that MCE events have been logged in mce_log() - Trigger the mcelog tool specific work in the first notifier As a result, mce_notify_irq() can go now. Fixes: 011d826 ("RAS: Add a Corrected Errors Collector") Reported-by: Li RongQing <lirongqing@baidu.com> Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de> Reviewed-by: Qiuxu Zhuo <qiuxu.zhuo@intel.com> Tested-by: Qiuxu Zhuo <qiuxu.zhuo@intel.com> Link: https://lore.kernel.org/r/20260112082747.2842-1-lirongqing@baidu.com
1 parent 5d69190 commit ea32444

1 file changed

Lines changed: 5 additions & 28 deletions

File tree

arch/x86/kernel/cpu/mce/core.c

Lines changed: 5 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,6 @@ struct mca_config mca_cfg __read_mostly = {
9090
};
9191

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

9594
/*
9695
* MCA banks polled by the period polling timer for corrected events.
@@ -152,8 +151,10 @@ EXPORT_PER_CPU_SYMBOL_GPL(injectm);
152151

153152
void mce_log(struct mce_hw_err *err)
154153
{
155-
if (mce_gen_pool_add(err))
154+
if (mce_gen_pool_add(err)) {
155+
pr_info(HW_ERR "Machine check events logged\n");
156156
irq_work_queue(&mce_irq_work);
157+
}
157158
}
158159
EXPORT_SYMBOL_GPL(mce_log);
159160

@@ -585,28 +586,6 @@ bool mce_is_correctable(struct mce *m)
585586
}
586587
EXPORT_SYMBOL_GPL(mce_is_correctable);
587588

588-
/*
589-
* Notify the user(s) about new machine check events.
590-
* Can be called from interrupt context, but not from machine check/NMI
591-
* context.
592-
*/
593-
static bool mce_notify_irq(void)
594-
{
595-
/* Not more than two messages every minute */
596-
static DEFINE_RATELIMIT_STATE(ratelimit, 60*HZ, 2);
597-
598-
if (test_and_clear_bit(0, &mce_need_notify)) {
599-
mce_work_trigger();
600-
601-
if (__ratelimit(&ratelimit))
602-
pr_info(HW_ERR "Machine check events logged\n");
603-
604-
return true;
605-
}
606-
607-
return false;
608-
}
609-
610589
static int mce_early_notifier(struct notifier_block *nb, unsigned long val,
611590
void *data)
612591
{
@@ -618,9 +597,7 @@ static int mce_early_notifier(struct notifier_block *nb, unsigned long val,
618597
/* Emit the trace record: */
619598
trace_mce_record(err);
620599

621-
set_bit(0, &mce_need_notify);
622-
623-
mce_notify_irq();
600+
mce_work_trigger();
624601

625602
return NOTIFY_DONE;
626603
}
@@ -1804,7 +1781,7 @@ static void mce_timer_fn(struct timer_list *t)
18041781
* Alert userspace if needed. If we logged an MCE, reduce the polling
18051782
* interval, otherwise increase the polling interval.
18061783
*/
1807-
if (mce_notify_irq())
1784+
if (!mce_gen_pool_empty())
18081785
iv = max(iv / 2, (unsigned long) HZ/100);
18091786
else
18101787
iv = min(iv * 2, round_jiffies_relative(check_interval * HZ));

0 commit comments

Comments
 (0)