[PATCH 6/6] x86-mce: ensure the MCP timer is not already set in the mce_timer_fn.

From: Havard Skinnemoen
Date: Wed Jul 09 2014 - 13:11:20 EST


From: Ewout van Bekkum <ewout@xxxxxxxxxx>

The machine check poll timer function, mce_timer_fn(), did not check
whether the MCP timer had already been set in case the function was
preempted by an interrupt. A CMCI interrupt could preempt this function
and enable the MCP timer through mce_timer_kick(). The race condition
was resolved by disabling interrupts during the mce_timer_fn() function
and by verifying the timer isn't already set before starting the timer.

Signed-off-by: Ewout van Bekkum <ewout@xxxxxxxxxx>
Signed-off-by: Havard Skinnemoen <hskinnemoen@xxxxxxxxxx>
---
arch/x86/kernel/cpu/mcheck/mce.c | 11 +++++++++--
1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/arch/x86/kernel/cpu/mcheck/mce.c b/arch/x86/kernel/cpu/mcheck/mce.c
index 1587b18..c5e40cb 100644
--- a/arch/x86/kernel/cpu/mcheck/mce.c
+++ b/arch/x86/kernel/cpu/mcheck/mce.c
@@ -1310,10 +1310,13 @@ static void mce_timer_fn(unsigned long data)
{
struct timer_list *t = &__get_cpu_var(mce_timer);
unsigned long iv;
+ unsigned long flags;
int notify;

WARN_ON(smp_processor_id() != data);

+ /* Ensure a CMCI interrupt can't preempt this. */
+ local_irq_save(flags);
if (mce_available(__this_cpu_ptr(&cpu_info))) {
machine_check_poll(MCP_TIMESTAMP,
&__get_cpu_var(mce_poll_banks));
@@ -1334,11 +1337,15 @@ static void mce_timer_fn(unsigned long data)
iv = mce_adjust_timer(iv);
}
__this_cpu_write(mce_next_interval, iv);
- /* Might have become 0 after CMCI storm subsided */
- if (iv) {
+
+ /* Ensure the timer isn't already set and the interval has not become
+ * 0 after a CMCMI storm has subsided.
+ */
+ if (!timer_pending(t) && iv) {
t->expires = jiffies + iv;
add_timer_on(t, smp_processor_id());
}
+ local_irq_restore(flags);
}

/*
--
2.0.0.526.g5318336

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/