mce: prevent concurrent polling of MCE events
Subsystems (3)
PATCH v2 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. This can be improved further in the future if Intel implements a way to determine which package a certain CPU belongs to.
--- arch/x86/kernel/cpu/mce/core.c | 2 + arch/x86/kernel/cpu/mce/intel.c | 47 +++++++++++++++++++++++++++++++------ arch/x86/kernel/cpu/mce/internal.h | 4 +++ 3 files changed, 46 insertions(+), 7 deletions(-)
arch/x86/kernel/cpu/mce/core.c +2 -0
@@ -1618,7 +1618,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 =intel_cmci_poll_lock ();machine_check_poll (0 ,this_cpu_ptr (&mce_poll_banks)); +intel_cmci_poll_unlock (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);
Tony Luck
maintainerQuoted 3 lines · Aristeu Rozanski
This patch fixes this by introducing synchronization during polling only for the affected microarchitectures. This can be improved further in the future if Intel implements a way to determine which package a certain CPU belongs to.
It is already possible to associate a CPU with a package. The problem here is knowing which CPUs are sharing which banks.
arch/x86/kernel/cpu/mce/core.c static void mce_timer_fn(struct timer_li · line 1621
Quoted 7 lines
arch/x86/kernel/cpu/mce/core.c +1
-0@@ -1618,7 +1618,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 =intel_cmci_poll_lock ();
Is mce_timer_fn() used on AMD? I think it is (mcheck_cpu_init() calls __mcheck_cpu_setup_timer() apparently unconditionally). So this code is OK if CONFIG_X86_MCE_INTEL=n because that's an empty stub. But with both CONFIG_X86_MCE_INTEL=y and CONFIG_X86_MCE_AMD=y you'll call this function on AMD systems.
Or is this OK because this will always return false on AMD?
-Tony
Quoted 2 lines · Tony Luck
It is already possible to associate a CPU with a package. The problem here is knowing which CPUs are sharing which banks.
Then this patch can be improved to have one lock per package instead one for the entire system. How do I know which package the current CPU belongs?
Quoted 7 lines
Is
mce_timer_fn()used on AMD? I think it is (mcheck_cpu_init()calls__mcheck_cpu_setup_timer()apparently unconditionally). So this code is OK ifCONFIG_X86_MCE_INTEL=nbecause that's an empty stub. But with bothCONFIG_X86_MCE_INTEL=yandCONFIG_X86_MCE_AMD=yyou'll call this function on AMD systems.Or is this OK because this will always return false on AMD?
That was my intention. I could use a static to only call cmci_supported_hw() once (that in fact could be useful for users of cmci_supported() that actually just want cmci_supported_hw() but I didn't want to mix it with this change) if you prefer:
+bool intel_cmci_poll_lock(void)
{
static bool supported = cmci_supported_hw();
if (!supported)
return false;
spin_lock(&cmci_poll_lock);
return true;
}Still a call and comparison for everyone (although it's likely intel_cmci_poll_{,un}lock() will be inlined). You prefer this or have a different idea?
Thanks
Signature · 1 line
Aristeu
Luck, Tony
maintainerQuoted 3 lines
Then this patch can be improved to have one lock per package instead one for the entire system. How do I know which package the current CPU belongs?
topology_physical_package_id(cpu);
But it seems like that adds a lot of work to find out how many packages there are and initialize a spin lock for each one. Just to reduce what is likely to be quite low contention on a lock in a rare code path.
Quoted 6 lines
Or is this OK because this will always return false on AMD?
That was my intention. I could use a static to only call
cmci_supported_hw()once (that in fact could be useful for users ofcmci_supported()that actually just wantcmci_supported_hw()but I didn't want to mix it with this change) if you prefer:
Maybe the function just needs a better name. Calling something with an "intel_cmci_" prefix from generic code is what's causing me to step back.
What if the code read:
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);
As an intermediate functions. With core.c declaring:
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 false;
return intel_cmci_poll_unlock();
}That would be in-lined and almost all disappear for CONFIG_X86_MCE_INTEL=n
-Tony
Quoted 5 lines · Tony
topology_physical_package_id(cpu);But it seems like that adds a lot of work to find out how many packages there are and initialize a spin lock for each one. Just to reduce what is likely to be quite low contention on a lock in a rare code path.
OK, I'll update the description then.
Quoted 29 lines
Quoted 6 lines
Or is this OK because this will always return false on AMD?
That was my intention. I could use a static to only call
cmci_supported_hw()once (that in fact could be useful for users ofcmci_supported()that actually just wantcmci_supported_hw()but I didn't want to mix it with this change) if you prefer:Maybe the function just needs a better name. Calling something with an "
intel_cmci_" prefix from generic code is what's causing me to step back.What if the code read:
if (mce_available(this_cpu_ptr(&cpu_info))) {(quoted diff) +2
-0+ bool locked = serialize_mc_bank_access(); machine_check_poll(0, this_cpu_ptr(&mce_poll_banks)); + unserialize_mc_bank_access(locked);As an intermediate functions. With
core.cdeclaring: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)
Quoted 8 lines
{ if (!locked || boot_cpu_data.x86_vendor != X86_VENDOR_INTEL) return false; return intel_cmci_poll_unlock(); }That would be in-lined and almost all disappear for
CONFIG_X86_MCE_INTEL=n
Ah, I see. Makes sense. I'll update and send it tomorrow.
Signature · 1 line
Aristeu