mce: prevent concurrent polling of MCE events
Subsystems (3)
PATCH v3 1/1 mce: prevent concurrent polling of MCE events
On Intel microarchitectures that support CMCI but have it disabled (BIOS, kernel option or CMCI storm code) the kernel will resort to polling for MCEs. In these microarchitectures the IMC registers are shared by all CPUs in the same package and despite the fact that the polling is set up in the kernel to prevent all CPUs to poll at the same time, it's still possible they'll overlap and report the same MCE multiple times.
This patch fixes this by introducing synchronization during polling only for the affected microarchitectures.
v3: add {,un}serialize_mc_bank_access() as intermediate functions as requested by Tony Luck
--- arch/x86/kernel/cpu/mce/core.c | 18 ++++++++++++++ arch/x86/kernel/cpu/mce/intel.c | 47 +++++++++++++++++++++++++++++++------ arch/x86/kernel/cpu/mce/internal.h | 4 +++ 3 files changed, 62 insertions(+), 7 deletions(-)
arch/x86/kernel/cpu/mce/core.c +18 -0
@@ -1578,6 +1578,22 @@ return 0; }#endif +static bool serialize_mc_bank_access (void ) +{ +if (boot_cpu_data.x86_vendor !=X86_VENDOR_INTEL ) +return false; + +return intel_cmci_poll_lock (); +} + +static void unserialize_mc_bank_access (bool locked) +{ +if (!locked || boot_cpu_data.x86_vendor !=X86_VENDOR_INTEL ) +return ; + +intel_cmci_poll_unlock (locked); +} +/* * Periodic polling timer for "silent" machine check errors. If the * poller finds an MCE, poll 2x faster. When the poller finds no more
@@ -1618,7 +1634,9 @@ static void mce_timer_fn(struct timer_li iv =__this_cpu_read (mce_next_interval);if (mce_available (this_cpu_ptr (&cpu_info))) { +bool locked =serialize_mc_bank_access ();machine_check_poll (0 ,this_cpu_ptr (&mce_poll_banks)); +unserialize_mc_bank_access (locked);if (mce_intel_cmci_poll ()) { iv =mce_adjust_timer (iv);
arch/x86/kernel/cpu/mce/intel.c +40 -7
66 lines not on this page · raw message
arch/x86/kernel/cpu/mce/internal.h +4 -0
@@ -49,6 +49,8 @@ void intel_init_cmci(void);void intel_init_lmce (void );void intel_clear_lmce (void );bool intel_filter_mce (struct mce *m); +bool intel_cmci_poll_lock (void ); +void intel_cmci_poll_unlock (bool locked);#else # define cmci_intel_adjust_timer mce_adjust_timer_defaultstatic inline bool mce_intel_cmci_poll (void ) {return false; }
@@ -58,6 +60,8 @@ static inline void intel_init_cmci(void)static inline void intel_init_lmce (void ) { }static inline void intel_clear_lmce (void ) { }static inline bool intel_filter_mce (struct mce *m) {return false; } +static inline bool intel_cmci_poll_lock (void ) {return false; } +static inline void intel_cmci_poll_unlock (bool locked) { }#endif void mce_timer_kick (unsigned long interval);
arch/x86/kernel/cpu/mce/intel.c ((m->status & 0xa0000000ffffffff) == 0x8 · line 554
Quoted 7 lines · Aristeu Rozanski
arch/x86/kernel/cpu/mce/intel.c +7
-0+void intel_cmci_poll_unlock (bool locked) +{ +if (!locked) +return ; + +spin_unlock (&cmci_poll_lock); +}
This doesn't need an argument any more. The unserialize_mc_bank_access() will only call it for the locked case.
But otherwise:
-Tony
Quoted 11 lines · Tony Luck
arch/x86/kernel/cpu/mce/intel.c ((m->status & 0xa0000000ffffffff) == 0x8 · line 554
Quoted 7 lines · Aristeu Rozanski
arch/x86/kernel/cpu/mce/intel.c +7
-0+void intel_cmci_poll_unlock (bool locked) +{ +if (!locked) +return ; + +spin_unlock (&cmci_poll_lock); +}This doesn't need an argument any more. The
unserialize_mc_bank_access()will only call it for the locked case.
And remove checking processor's vendor on unserialize_mc_bank_access() as well.
Signature · 1 line
Aristeu
PATCH v4 1/1 mce: prevent concurrent polling of MCE events
In reply to Tony LuckOn Intel microarchitectures that support CMCI but have it disabled (BIOS, kernel option or CMCI storm code) the kernel will resort to polling for MCEs. In these microarchitectures the IMC registers are shared by all CPUs in the same package and despite the fact that the polling is set up in the kernel to prevent all CPUs to poll at the same time, it's still possible they'll overlap and report the same MCE multiple times.
This patch fixes this by introducing synchronization during polling only for the affected microarchitectures.
v4: get rid of unneeded variable on intel_cmci_poll_unlock() and simplify unserialize_mc_bank_access()
v3: add {,un}serialize_mc_bank_access() as intermediate functions as requested by Tony Luck
--- arch/x86/kernel/cpu/mce/core.c | 18 +++++++++++++++ arch/x86/kernel/cpu/mce/intel.c | 44 +++++++++++++++++++++++++++++++------ arch/x86/kernel/cpu/mce/internal.h | 4 +++ 3 files changed, 59 insertions(+), 7 deletions(-)
arch/x86/kernel/cpu/mce/core.c +18 -0
@@ -1578,6 +1578,22 @@ return 0; }#endif +static bool serialize_mc_bank_access (void ) +{ +if (boot_cpu_data.x86_vendor !=X86_VENDOR_INTEL ) +return false; + +return intel_cmci_poll_lock (); +} + +static void unserialize_mc_bank_access (bool locked) +{ +if (!locked) +return ; + +intel_cmci_poll_unlock (); +} +/* * Periodic polling timer for "silent" machine check errors. If the * poller finds an MCE, poll 2x faster. When the poller finds no more
@@ -1618,7 +1634,9 @@ static void mce_timer_fn(struct timer_li iv =__this_cpu_read (mce_next_interval);if (mce_available (this_cpu_ptr (&cpu_info))) { +bool locked =serialize_mc_bank_access ();machine_check_poll (0 ,this_cpu_ptr (&mce_poll_banks)); +unserialize_mc_bank_access (locked);if (mce_intel_cmci_poll ()) { iv =mce_adjust_timer (iv);
arch/x86/kernel/cpu/mce/intel.c +37 -7
63 lines not on this page · raw message
arch/x86/kernel/cpu/mce/internal.h +4 -0
@@ -49,6 +49,8 @@ void intel_init_cmci(void);void intel_init_lmce (void );void intel_clear_lmce (void );bool intel_filter_mce (struct mce *m); +bool intel_cmci_poll_lock (void ); +void intel_cmci_poll_unlock (void );#else # define cmci_intel_adjust_timer mce_adjust_timer_defaultstatic inline bool mce_intel_cmci_poll (void ) {return false; }
@@ -58,6 +60,8 @@ static inline void intel_init_cmci(void)static inline void intel_init_lmce (void ) { }static inline void intel_clear_lmce (void ) { }static inline bool intel_filter_mce (struct mce *m) {return false; } +static inline bool intel_cmci_poll_lock (void ) {return false; } +static inline void intel_cmci_poll_unlock (void ) { }#endif void mce_timer_kick (unsigned long interval);
Quoted 1 line
v4: get rid of unneeded variable on
intel_cmci_poll_unlock()and simplifyunserialize_mc_bank_access()
My:
applies to this version too.
-Tony