x86 MCE improvements series for 2.6.31 v2
Subsystems (2)
Various new Intel x86 machine check features, including initial support for machine check recovery and new status bits. The actual machine check recovery requires some generic VM changes, which will be posted in a separate series ("POISON series"), however this series is independent and compiles without it.
This is all ready for merging for 2.6.31.
v2: Various bug fixes and a few minor improvements
Now based on the mce3-32bitmerge branch
(git://git.kernel.org/pub/scm/linux/kernel/git/ak/linux-mce-2.6.git mce3-32bitmerge) which is based on the mce3 branch
(git://git.kernel.org/pub/scm/linux/kernel/git/ak/linux-mce-2.6.git mce3) which is a updated version of the x86/mce2 branch in tip
-Andi
PATCH 1/31 x86: MCE: Synchronize core after machine check handling
From: Andi Kleen <[email protected]>
Impact: Spec compliance
The example code in the IA32 SDM recommends to synchronize the CPU after machine check handling. So do that here.
--- arch/x86/kernel/cpu/mcheck/mce.c | 3 +++ 1 files changed, 3 insertions(+), 0 deletions(-)
arch/x86/kernel/cpu/mcheck/mce.c +3 -0
@@ -328,6 +328,8 @@ void machine_check_poll(enum mcp_flags flags, mce_banks_t *b)* Don't clear MCG_STATUS here because it's only defined for * exceptions. */ + +sync_core (); }EXPORT_SYMBOL_GPL (machine_check_poll);
@@ -501,6 +503,7 @@ void do_machine_check(struct pt_regs *regs, long error_code)mce_wrmsrl (MSR_IA32_MCG_STATUS ,0 ); out2:atomic_dec (&mce_entry); +sync_core (); }EXPORT_SYMBOL_GPL (do_machine_check);
Signature · 1 line
1.6.0.2
PATCH 2/31 x86: MCE: Improve mce_get_rip v3
From: Huang Ying <[email protected]>
Assume RIP is valid when either EIPV or RIPV are set. This influences whether the machine check exception handler decides to return or panic.
This fixes a test case in the mce-test suite and is more compliant to the specification.
This currently only makes a difference in a artificial testing scenario with the mce-test test suite.
Also in addition do not force the RIP to be valid with the exact register MSRs.
[AK: combination of patches from Huang Ying and Hidetoshi Seto, with new description by me]
--- arch/x86/kernel/cpu/mcheck/mce.c | 13 +++++++------ 1 files changed, 7 insertions(+), 6 deletions(-)
arch/x86/kernel/cpu/mcheck/mce.c +7 -6
@@ -247,21 +247,22 @@ int mce_available(struct cpuinfo_x86 *c)return cpu_has (c,X86_FEATURE_MCE ) &&cpu_has (c,X86_FEATURE_MCA ); } +/* +* Get the address of the instruction at the time of the machine check +* error. +*/ static inline void mce_get_rip (struct mce *m,struct pt_regs *regs) { -if (regs && (m->mcgstatus &MCG_STATUS_RIPV )) { + +if (regs && (m->mcgstatus & (MCG_STATUS_RIPV |MCG_STATUS_EIPV ))) { m->ip = regs->ip; m->cs = regs->cs; }else { m->ip =0 ; m->cs =0 ; } -if (rip_msr) { -/* Assume the RIP in the MSR is exact. Is this true? */ - m->mcgstatus |=MCG_STATUS_EIPV ; +if (rip_msr) m->ip =mce_rdmsrl (rip_msr); - m->cs =0 ; - } }/*
Signature · 1 line
1.6.0.2
PATCH 3/31 x86: MCE: Fix EIPV behaviour with !PCC
From: Huang Ying <[email protected]>
Impact: Spec compliance
When tolerant == 0, system should go panic instead of send SIGBUS even for a MCE with EPIV && !PCC on user space.
--- arch/x86/kernel/cpu/mcheck/mce.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
arch/x86/kernel/cpu/mcheck/mce.c +1 -1
@@ -485,7 +485,7 @@ void do_machine_check(struct pt_regs *regs, long error_code)* force_sig() takes an awful lot of locks and has a slight * risk of deadlocking. */ -if (user_space) { +if (user_space && tolerant >0 ) {force_sig (SIGBUS , current); }else if (panic_on_oops || tolerant <2 ) { mce_panic("Uncorrected machine check",
Signature · 1 line
1.6.0.2
PATCH 4/31 x86: MCE: Use extended sysattrs for the check_interval attribute.
From: Andi Kleen <[email protected]>
Impact: Cleanup
Instead of using own callbacks use the generic ones provided by the sysdev later.
This finally allows to get rid of the ugly ACCESSOR macros. Should also save some text size.
--- arch/x86/kernel/cpu/mcheck/mce.c | 39 ++++++++++++++----------------------- 1 files changed, 15 insertions(+), 24 deletions(-)
arch/x86/kernel/cpu/mcheck/mce.c +15 -24
@@ -1055,28 +1055,6 @@ DEFINE_PER_CPU(struct sys_device, device_mce);__cpuinitdata void (*threshold_cpu_callback)(unsigned long action,unsigned int cpu); -/* Why are there no generic functions for this? */ -#define ACCESSOR (name, var, start) \ - static ssize_t show_ ## name(struct sys_device *s, \ - struct sysdev_attribute *attr, \ - char *buf) { \ - return sprintf(buf, "%Lx\n", (u64)var); \ - } \ - static ssize_t set_ ## name(struct sys_device *s, \ - struct sysdev_attribute *attr, \ - const char *buf, size_t siz) { \ - char *end; \ - u64 new = simple_strtoull(buf, &end, 0); \ - \ - if (end == buf) \ - return -EINVAL; \ - var = new; \ - start; \ - \ - return end-buf; \ - } \ - static SYSDEV_ATTR(name, 0644, show_ ## name, set_ ## name); -static struct sysdev_attribute *bank_attrs; static ssize_t show_bank(struct sys_device *s, struct sysdev_attribute *attr,
@@ -1127,13 +1105,26 @@ static ssize_t set_trigger(struct sys_device *s, struct sysdev_attribute *attr,return len; } +static ssize_t store_int_with_restart (struct sys_device *s, +struct sysdev_attribute *attr, +const char *buf,size_t size) +{ +ssize_t ret =sysdev_store_int (s, attr, buf, size); +mce_restart (); +return ret; +} + static SYSDEV_ATTR(trigger, 0644, show_trigger, set_trigger); static SYSDEV_INT_ATTR(tolerant, 0644, tolerant); -ACCESSOR(check_interval, check_interval, mce_restart()) +static struct sysdev_ext_attribute attr_check_interval = { +_SYSDEV_ATTR (check_interval,0644 , sysdev_show_int, + store_int_with_restart), + &check_interval +};static struct sysdev_attribute *mce_attr[] = { - &attr_tolerant.attr, &attr_check_interval, &attr_trigger, + &attr_tolerant.attr, &attr_check_interval.attr, &attr_trigger,NULL };
Signature · 1 line
1.6.0.2
PATCH 5/31 x86: MCE: Add machine check exception count in /proc/interrupts
From: Andi Kleen <[email protected]>
Impact: feature, debugging tool
Useful for debugging, but it's also good general policy
to have a counter for all special interrupts there. This makes it easier to diagnose where a CPU is spending its time.
--- arch/x86/include/asm/mce.h | 3 +++ arch/x86/kernel/cpu/mcheck/mce.c | 4 ++++ arch/x86/kernel/irq.c | 10 ++++++++++ 3 files changed, 17 insertions(+), 0 deletions(-)
arch/x86/include/asm/mce.h +3 -0
@@ -89,6 +89,7 @@ struct mce_log {extern int mce_disabled;#include <asm/atomic.h> +#include <linux/percpu.h> void mce_setup (struct mce *m);void mce_log (struct mce *m);
@@ -123,6 +124,8 @@ static inline void mce_amd_feature_init(struct cpuinfo_x86 *c) { }extern int mce_available (struct cpuinfo_x86 *c); +DECLARE_PER_CPU (unsigned, mce_exception_count); +void mce_log_therm_throt_event (__u64 status);extern atomic_t mce_entry;
arch/x86/kernel/cpu/mcheck/mce.c +4 -0
@@ -58,6 +58,8 @@ int mce_disabled;atomic_t mce_entry; +DEFINE_PER_CPU (unsigned, mce_exception_count); +/* * Tolerant levels: * 0: always panic on uncorrected errors, log corrected errors
@@ -362,6 +364,8 @@ void do_machine_check(struct pt_regs *regs, long error_code)atomic_inc (&mce_entry); +__get_cpu_var (mce_exception_count)++; +if (notify_die (DIE_NMI ,"machine check" , regs, error_code,18 ,SIGKILL ) ==NOTIFY_STOP ) goto out2;
arch/x86/kernel/irq.c +10 -0
@@ -12,6 +12,7 @@#include <asm/io_apic.h> #include <asm/irq.h> #include <asm/idle.h> +#include <asm/mce.h> atomic_t irq_err_count;
@@ -96,6 +97,12 @@ static int show_other_interrupts(struct seq_file *p, int prec)seq_printf (p," Threshold APIC interrupts\n" );# endif #endif +#if defined(CONFIG_X86_MCE ) && defined(CONFIG_X86_64 ) +seq_printf (p,"%*s: " , prec,"MCE" ); +for_each_online_cpu (j) +seq_printf (p,"%10u " ,per_cpu (mce_exception_count, j)); +seq_printf (p," Machine check exceptions\n" ); +#endif seq_printf (p,"%*s: %10u\n" , prec,"ERR" ,atomic_read (&irq_err_count));#if defined(CONFIG_X86_IO_APIC )seq_printf (p,"%*s: %10u\n" , prec,"MIS" ,atomic_read (&irq_mis_count));
@@ -163,6 +170,9 @@ u64 arch_irq_stat_cpu(unsigned int cpu) {u64 sum =irq_stats (cpu)->__nmi_count; +#if defined(CONFIG_X86_MCE ) && defined(CONFIG_X86_64 ) + sum +=per_cpu (mce_exception_count, cpu); +#endif #ifdef CONFIG_X86_LOCAL_APIC sum +=irq_stats (cpu)->apic_timer_irqs; sum +=irq_stats (cpu)->irq_spurious_count;
Signature · 1 line
1.6.0.2
PATCH 6/31 x86: Fix panic with interrupts off (needed for MCE)
From: Andi Kleen <[email protected]>
Impact: bug fix, fixes an old regression
For some time each panic() called with interrupts disabled triggered the !irqs_disabled() WARN_ON in smp_call_function(), producing ugly backtraces and confusing users.
This is a common situation with machine checks for example which tend to call panic with interrupts disabled, but will also hit in other situations e.g. panic during early boot. In fact it means that panic cannot be called in many circumstances, which would be bad.
This all started with the new fancy queued smp_call_function, which is then used by the shutdown path to shut down the other CPUs.
On closer examination it turned out that the fancy RCU smp_call_function() does lots of things not suitable in a panic situation anyways, like allocating memory and relying on complex system state.
I originally tried to patch this over by checking for panic there, but it was quite complicated and the original patch was also not very popular. This also didn't fix some of the underlying complexity problems.
The new code in post 2.6.29 tries to patch around this by checking for oops_in_progress, but that is not enough to make this fully safe and I don't think that's a real solution because panic has to be reliable.
So instead use an own vector to reboot. This makes the reboot code extremly straight forward, which is definitely a big plus in a panic situation where it is important to avoid relying on too much kernel state. The new simple code is also safe to be called from interupts off region because it is very very simple.
There can be situations where it is important that panic is reliable. For example on a fatal machine check the panic is needed to get the system up again and running as quickly as possible. So it's important that panic is reliable and all function it calls simple.
This is why I came up with this simple vector scheme. It's very hard to beat in simplicity. Vectors are not particularly precious anymore since all big systems are using per CPU vectors.
Another possibility would have been to use an NMI similar to kdump, but there is still the problem that NMIs don't work reliably on some systems due to BIOS issues. NMIs would have been able to stop CPUs running with interrupts off too. In the sake of universal reliability I opted for using a non NMI vector for now.
I put the reboot vector into the highest priority bucket of the APIC vectors and moved the 64bit UV_BAU message down instead into the next lower priority.
--- arch/x86/include/asm/entry_arch.h | 1 + arch/x86/include/asm/hw_irq.h | 1 + arch/x86/include/asm/irq_vectors.h | 8 +++----- arch/x86/kernel/entry_64.S | 2 ++ arch/x86/kernel/irqinit_32.c | 3 +++ arch/x86/kernel/irqinit_64.c | 3 +++ arch/x86/kernel/smp.c | 28 +++++++++++++++++++++++++++- 7 files changed, 40 insertions(+), 6 deletions(-)
arch/x86/include/asm/entry_arch.h +1 -0
@@ -14,6 +14,7 @@ BUILD_INTERRUPT(reschedule_interrupt,RESCHEDULE_VECTOR) BUILD_INTERRUPT(call_function_interrupt,CALL_FUNCTION_VECTOR) BUILD_INTERRUPT(call_function_single_interrupt,CALL_FUNCTION_SINGLE_VECTOR) BUILD_INTERRUPT(irq_move_cleanup_interrupt,IRQ_MOVE_CLEANUP_VECTOR) +BUILD_INTERRUPT(reboot_interrupt,REBOOT_VECTOR)BUILD_INTERRUPT3 (invalidate_interrupt0,INVALIDATE_TLB_VECTOR_START +0 , smp_invalidate_interrupt)
arch/x86/include/asm/hw_irq.h +1 -0
@@ -44,6 +44,7 @@ extern void invalidate_interrupt6(void);extern void invalidate_interrupt7 (void );extern void irq_move_cleanup_interrupt (void ); +extern void reboot_interrupt (void );extern void threshold_interrupt (void );extern void call_function_interrupt (void );
arch/x86/include/asm/irq_vectors.h +3 -5
@@ -89,11 +89,7 @@#define THRESHOLD_APIC_VECTOR 0xf9 -#ifdef CONFIG_X86_32 -/* 0xf9 : free */ -#else -# define UV_BAU_MESSAGE 0xf8 -#endif +#define REBOOT_VECTOR 0xf8/* f0-f7 used for spreading out TLB flushes: */ #define INVALIDATE_TLB_VECTOR_END 0xf7
@@ -117,6 +113,8 @@*/ #define GENERIC_INTERRUPT_VECTOR 0xed +#define UV_BAU_MESSAGE 0xec +/* * First APIC vector available to drivers: (vectors 0x30-0xee) we * start at 0x31(0x41) to spread out vectors evenly between priority
arch/x86/kernel/entry_64.S +2 -0
@@ -976,6 +976,8 @@ END(\sym) #ifdef CONFIG_SMP apicinterrupt IRQ_MOVE_CLEANUP_VECTOR \ irq_move_cleanup_interrupt smp_irq_move_cleanup_interrupt +apicinterrupt REBOOT_VECTOR \ + reboot_interrupt smp_reboot_interrupt #endif #ifdef CONFIG_X86_UV
arch/x86/kernel/irqinit_32.c +3 -0
@@ -167,6 +167,9 @@ void __init native_init_IRQ(void)/* Low priority IPI to cleanup after moving an irq */ set_intr_gate (IRQ_MOVE_CLEANUP_VECTOR , irq_move_cleanup_interrupt);set_bit (IRQ_MOVE_CLEANUP_VECTOR , used_vectors); + +/* IPI used for rebooting/stopping */ +alloc_intr_gate (REBOOT_VECTOR , reboot_interrupt);#endif #ifdef CONFIG_X86_LOCAL_APIC
arch/x86/kernel/irqinit_64.c +3 -0
@@ -133,6 +133,9 @@ static void __init smp_intr_init(void)/* Low priority IPI to cleanup after moving an irq */ set_intr_gate (IRQ_MOVE_CLEANUP_VECTOR , irq_move_cleanup_interrupt);set_bit (IRQ_MOVE_CLEANUP_VECTOR , used_vectors); + +/* IPI for rebooting/panicing */ +alloc_intr_gate (REBOOT_VECTOR , reboot_interrupt);#endif }
arch/x86/kernel/smp.c +27 -1
@@ -150,14 +150,40 @@ void native_send_call_func_ipi(const struct cpumask *mask)* this function calls the 'stop' function on all other CPUs in the system. */ +asmlinkage void smp_reboot_interrupt(void) +{ +ack_APIC_irq (); +irq_enter (); +stop_this_cpu (NULL ); +irq_exit (); +} +static void native_smp_send_stop (void ) {unsigned long flags; +unsigned long wait;if (reboot_force)return ; -smp_call_function (stop_this_cpu,NULL ,0 ); +/* +* Use an own vector here because smp_call_function +* does lots of things not suitable in a panic situation. +* On most systems we could also use an NMI here, +* but there are a few systems around where NMI +* is problematic so stay with an non NMI for now +* (this implies we cannot stop CPUs spinning with irq off +* currently) +*/ +if (num_online_cpus () >1 ) { + apic->send_IPI_allbutself (REBOOT_VECTOR ); + +/* Don't wait longer than a second */ + wait =USEC_PER_SEC ; +while (num_online_cpus () >1 && wait--) +udelay (1 ); + } +local_irq_save (flags);disable_local_APIC ();local_irq_restore (flags);
Signature · 1 line
1.6.0.2
PATCH 7/31 x86: MCE: Log corrected errors when panicing
From: Andi Kleen <[email protected]>
Impact: bugfix
Normally the machine check handler ignores corrected errors and leaves them to machine_check_poll(). But when panicing mcp won't run, so log all errors.
Note: this can still miss some cases until the "early no way out" patch later is applied too.
--- arch/x86/kernel/cpu/mcheck/mce.c | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-)
arch/x86/kernel/cpu/mcheck/mce.c +2 -2
@@ -398,9 +398,9 @@ void do_machine_check(struct pt_regs *regs, long error_code)/* * Non uncorrected errors are handled by machine_check_poll -* Leave them alone. +* Leave them alone, unless this panics. */ -if ((m.status &MCI_STATUS_UC ) ==0 ) +if ((m.status &MCI_STATUS_UC ) ==0 && !no_way_out)continue ;/*
Signature · 1 line
1.6.0.2
PATCH 8/31 x86: MCE: Remove unused mce_events variable
From: Andi Kleen <[email protected]>
Impact: Cleanup
Remove unused mce_events static variable.
--- arch/x86/kernel/cpu/mcheck/mce.c | 2 -- 1 files changed, 0 insertions(+), 2 deletions(-)
arch/x86/kernel/cpu/mcheck/mce.c +0 -2
@@ -73,7 +73,6 @@ static u64 *bank;static unsigned long notify_user;static int rip_msr;static int mce_bootlog =-1 ; -static atomic_t mce_events;static char trigger[128 ];static char *trigger_argv[2 ] = { trigger,NULL };
@@ -118,7 +117,6 @@ void mce_log(struct mce *mce) {unsigned next, entry; -atomic_inc (&mce_events); mce->finished =0 ;wmb ();for (;;) {
Signature · 1 line
1.6.0.2
PATCH 9/31 x86: MCE: Remove mce_init unused argument
From: Thomas Gleixner <[email protected]>
Impact: Cleanup
Remove unused mce_init argument.
--- arch/x86/kernel/cpu/mcheck/mce.c | 8 ++++---- 1 files changed, 4 insertions(+), 4 deletions(-)
arch/x86/kernel/cpu/mcheck/mce.c +4 -4
@@ -649,7 +649,7 @@ static int mce_cap_init(void)return 0 ; } -static void mce_init (void *dummy) +static void mce_init (void ) {mce_banks_t all_banks;u64 cap;
@@ -782,7 +782,7 @@ void __cpuinit mcheck_init(struct cpuinfo_x86 *c) machine_check_vector = do_machine_check; -mce_init (NULL ); +mce_init ();mce_cpu_features (c);mce_init_timer (); }
@@ -1025,7 +1025,7 @@ static int mce_shutdown(struct sys_device *dev)*/ static int mce_resume (struct sys_device *dev) { -mce_init (NULL ); +mce_init ();mce_cpu_features (¤t_cpu_data);return 0 ;
@@ -1035,7 +1035,7 @@ static void mce_cpu_restart(void *data) {del_timer_sync (&__get_cpu_var (mce_timer));if (mce_available (¤t_cpu_data)) -mce_init (NULL ); +mce_init ();mce_init_timer (); }
Signature · 1 line
1.6.0.2
PATCH 10/31 x86: MCE: Rename and align out2 label
From: Andi Kleen <[email protected]>
Impact: Minor cleanup, no functional changes
There's only a single out path in do_machine_check now, so rename the label from out2 to out. Also align it at the first column.
--- arch/x86/kernel/cpu/mcheck/mce.c | 6 +++--- 1 files changed, 3 insertions(+), 3 deletions(-)
arch/x86/kernel/cpu/mcheck/mce.c +3 -3
@@ -366,9 +366,9 @@ void do_machine_check(struct pt_regs *regs, long error_code)if (notify_die (DIE_NMI ,"machine check" , regs, error_code,18 ,SIGKILL ) ==NOTIFY_STOP ) - goto out2; + goto out;if (!banks) - goto out2; + goto out;mce_setup (&m);
@@ -504,7 +504,7 @@ void do_machine_check(struct pt_regs *regs, long error_code)mce_wrmsrl (MSR_IA32_MC0_STATUS +4 *i,0 ); }mce_wrmsrl (MSR_IA32_MCG_STATUS ,0 ); - out2: +out:atomic_dec (&mce_entry);sync_core (); }
Signature · 1 line
1.6.0.2
PATCH 11/31 x86: MCE: Implement bootstrapping for machine check wakeups
From: Andi Kleen <[email protected]>
machine checks support waking up the mcelog daemon quickly.
The original wake up code for this was pretty ugly, relying on a idle notifier and a special process flag. The reason it did it this way is that the machine check handler is not subject to normal interrupt locking rules so it's not safe to call wake_up(). Instead it set a process flag and then either did the wakeup in the syscall return or in the idle notifier.
This patch adds a new "bootstraping" method as replacement.
The idea is that the handler checks if it's in a state where it is unsafe to call wake_up(). If it's safe it calls it directly. When it's not safe -- that is it interrupted in a critical section with interrupts disables -- it uses a new "self IPI" to trigger an IPI to its own CPU. This can be done safely because IPI triggers are atomic with some care. The IPI is raised
once the interrupts are reenabled and can then safely call wake_up().
When APICs are disabled the event is just queued and will be picked up eventually by the next polling timer. I think that's a reasonable compromise, since it should only happen quite rarely.
Contains fixes from Ying Huang
--- arch/x86/include/asm/hw_irq.h | 1 + arch/x86/include/asm/irq_vectors.h | 5 +++ arch/x86/kernel/cpu/mcheck/mce.c | 52 ++++++++++++++++++++++++++++++++++++ arch/x86/kernel/entry_64.S | 5 +++ arch/x86/kernel/irqinit_64.c | 4 +++ 5 files changed, 67 insertions(+), 0 deletions(-)
arch/x86/include/asm/hw_irq.h +1 -0
@@ -32,6 +32,7 @@ extern void error_interrupt(void);extern void spurious_interrupt (void );extern void thermal_interrupt (void );extern void reschedule_interrupt (void ); +extern void mce_self_interrupt (void );extern void invalidate_interrupt (void );extern void invalidate_interrupt0 (void );
arch/x86/include/asm/irq_vectors.h +5 -0
@@ -116,6 +116,11 @@#define UV_BAU_MESSAGE 0xec/* +* Self IPI vector for machine checks +*/ +#define MCE_SELF_VECTOR 0xeb + +/* * First APIC vector available to drivers: (vectors 0x30-0xee) we * start at 0x31(0x41) to spread out vectors evenly between priority * levels. (0x80 is the syscall vector)
arch/x86/kernel/cpu/mcheck/mce.c +52 -0
76 lines not on this page · raw message
arch/x86/kernel/entry_64.S +5 -0
@@ -1013,6 +1013,11 @@ apicinterrupt THRESHOLD_APIC_VECTOR \ apicinterrupt THERMAL_APIC_VECTOR \ thermal_interrupt smp_thermal_interrupt +#ifdef CONFIG_X86_MCE +apicinterrupt MCE_SELF_VECTOR \ + mce_self_interrupt smp_mce_self_interrupt +#endif + #ifdef CONFIG_SMP apicinterrupt CALL_FUNCTION_SINGLE_VECTOR \ call_function_single_interrupt smp_call_function_single_interrupt
arch/x86/kernel/irqinit_64.c +4 -0
@@ -155,6 +155,10 @@ static void __init apic_intr_init(void)/* IPI vectors for APIC spurious and error interrupts */ alloc_intr_gate (SPURIOUS_APIC_VECTOR , spurious_interrupt);alloc_intr_gate (ERROR_APIC_VECTOR , error_interrupt); + +#ifdef CONFIG_X86_MCE +alloc_intr_gate (MCE_SELF_VECTOR , mce_self_interrupt); +#endif }void __init native_init_IRQ (void )
Signature · 1 line
1.6.0.2
PATCH 12/31 x86: MCE: Remove TSC print heuristic
From: Andi Kleen <[email protected]>
Impact: bug fix, cleanup
Previously mce_panic used a simple heuristic to avoid printing old so far unreported machine check events on a mce panic. This worked by comparing the TSC value at the start of the machine check handler with the event time stamp and only printing newer ones.
This has a couple of issues, in particular on systems where the TSC is not fully synchronized between CPUs it could lose events or print old ones.
It is also problematic with full system synchronization as it is added by the next patch.
Remove the TSC heuristic and instead replace it with a simple heuristic to print corrected errors first and after that uncorrected errors and finally the worst machine check as determined by the machine check handler.
This simplifies the code because there is no need to pass the original TSC value around.
Contains fixes from Ying Huang
--- arch/x86/kernel/cpu/mcheck/mce.c | 32 ++++++++++++++++++-------------- 1 files changed, 18 insertions(+), 14 deletions(-)
arch/x86/kernel/cpu/mcheck/mce.c +18 -14
@@ -152,6 +152,7 @@ void mce_log(struct mce *mce) mcelog.entry[entry].finished =1 ;wmb (); + mce->finished =1 ;set_bit (0 , ¬ify_user); }
@@ -181,23 +182,29 @@ static void print_mce(struct mce *m) "and contact your hardware vendor\n"); } -static void mce_panic (char *msg,struct mce *backup,u64 start) +static void mce_panic (char *msg,struct mce *final) {int i;bust_spinlocks (1 );console_verbose (); +/* First print corrected ones that are still unlogged */ for (i =0 ; i <MCE_LOG_LEN ; i++) { -u64 tsc = mcelog.entry[i].tsc; - -if ((s64)(tsc - start) <0 ) +struct mce *m = &mcelog.entry[i]; +if ((m->status &MCI_STATUS_VAL ) && + !(m->status &MCI_STATUS_UC )) +print_mce (m); + } +/* Now print uncorrected but with the final one last */ +for (i =0 ; i <MCE_LOG_LEN ; i++) { +struct mce *m = &mcelog.entry[i]; +if (!(m->status &MCI_STATUS_VAL ))continue ; -print_mce (&mcelog.entry[i]); -if (backup && mcelog.entry[i].tsc == backup->tsc) - backup =NULL ; +if (!final ||memcmp (m, final,sizeof (struct mce ))) +print_mce (m); } -if (backup) -print_mce (backup); +if (final) +print_mce (final);panic (msg); }
@@ -396,7 +403,6 @@ void do_machine_check(struct pt_regs *regs, long error_code) {struct mce m, panicm;int panicm_found =0 ; -u64 mcestart =0 ;int i;/* * If no_way_out gets set, there is no safe way to recover from this
@@ -428,7 +434,6 @@ void do_machine_check(struct pt_regs *regs, long error_code)if (!(m.mcgstatus &MCG_STATUS_RIPV )) no_way_out =1 ; -rdtscll (mcestart);barrier ();for (i =0 ; i < banks; i++) {
@@ -512,7 +517,7 @@ void do_machine_check(struct pt_regs *regs, long error_code)* has not set tolerant to an insane level, give up and die. */ if (no_way_out && tolerant <3 ) -mce_panic ("Machine check" , &panicm, mcestart); +mce_panic ("Machine check" , &panicm);/* * If the error seems to be unrecoverable, something should be
@@ -540,8 +545,7 @@ void do_machine_check(struct pt_regs *regs, long error_code)if (user_space && tolerant >0 ) {force_sig (SIGBUS , current); }else if (panic_on_oops || tolerant <2 ) { -mce_panic ("Uncorrected machine check" , - &panicm, mcestart); +mce_panic ("Uncorrected machine check" , &panicm); } }
Signature · 1 line
1.6.0.2
PATCH 13/31 x86: MCE: Drop BKL in mce_open
From: Andi Kleen <[email protected]>
Impact: cleanup
BKL is not needed for anything in mce_open because it has an own spinlock. Remove it.
--- arch/x86/kernel/cpu/mcheck/mce.c | 4 ---- 1 files changed, 0 insertions(+), 4 deletions(-)
arch/x86/kernel/cpu/mcheck/mce.c +0 -4
@@ -14,7 +14,6 @@#include <linux/ratelimit.h> #include <linux/kallsyms.h> #include <linux/rcupdate.h> -#include <linux/smp_lock.h> #include <linux/kobject.h> #include <linux/kdebug.h> #include <linux/kernel.h>
@@ -853,12 +852,10 @@ static int open_exclu; /* already open exclusive? */static int mce_open (struct inode *inode,struct file *file) { -lock_kernel ();spin_lock (&mce_state_lock);if (open_exclu || (open_count && (file->f_flags &O_EXCL ))) {spin_unlock (&mce_state_lock); -unlock_kernel ();return -EBUSY ; }
@@ -868,7 +865,6 @@ static int mce_open(struct inode *inode, struct file *file) open_count++;spin_unlock (&mce_state_lock); -unlock_kernel ();return nonseekable_open (inode, file); }
Signature · 1 line
1.6.0.2
PATCH 14/31 x86: MCE: Add table driven machine check grading
From: Andi Kleen <[email protected]>
Impact: Feature
The machine check grading (as in deciding what should be done for a given register value) has to be done multiple times soon and it's also getting more complicated. So it makes sense to consolidate it into a single function. To get smaller and more straight forward and possibly more extensible code I opted towards a new table driven method. The various rules are put into a table
when is then executed by a very simple interpreter.
The grading engine is in a new file mce-severity.c. I also added a private include file mce-internal.h, because mce.h is already a bit too cluttered.
This is dead code right now, but will be used in followon patches.
--- arch/x86/kernel/cpu/mcheck/Makefile | 1 + arch/x86/kernel/cpu/mcheck/mce-internal.h | 10 +++++ arch/x86/kernel/cpu/mcheck/mce-severity.c | 61 +++++++++++++++++++++++++++++ 3 files changed, 72 insertions(+), 0 deletions(-) create mode 100644 arch/x86/kernel/cpu/mcheck/mce-internal.h create mode 100644 arch/x86/kernel/cpu/mcheck/mce-severity.c
arch/x86/kernel/cpu/mcheck/Makefile +1 -0
@@ -1,5 +1,6 @@ obj-y = mce.o therm_throt.o +obj-$(CONFIG_X86_NEW_MCE) += mce-severity.o obj-$(CONFIG_X86_OLD_MCE) += k7.o p4.o p6.o obj-$(CONFIG_X86_ANCIENT_MCE) += winchip.o p5.o obj-$(CONFIG_X86_MCE_P4THERMAL) += mce_intel.o
arch/x86/kernel/cpu/mcheck/mce-internal.h new file +10 -0
@@ -0,0 +1,10 @@ +#include <asm/mce.h> + +enum severity_level { +MCE_NO_SEVERITY , +MCE_SOME_SEVERITY , +MCE_UC_SEVERITY , +MCE_PANIC_SEVERITY , +}; + +int mce_severity (struct mce *a,int tolerant,char **msg);
arch/x86/kernel/cpu/mcheck/mce-severity.c new file +61 -0
61 lines not on this page · raw message
Signature · 1 line
1.6.0.2
PATCH 15/31 x86: MCE: Check early in exception handler if panic is needed
From: Andi Kleen <[email protected]>
Impact: Feature
The exception handler should behave differently if the exception is fatal versus one that can be returned from. In the first case it should never clear any registers because these need to be preserved for logging after the next boot. Otherwise it should clear them on each CPU step by step so that other CPUs sharing the same bank don't see duplicate events. Otherwise we risk reporting events multiple times on any CPUs which have shared machine check banks, which is a common problem on Intel Nehalem which has both SMT (two CPU threads sharing banks) and shared machine check banks in the uncore.
Determine early in a special pass if any event requires a panic. This uses the mce_severity() function added earlier.
This is needed for the next patch.
Also fixes a problem together with an earlier patch that corrected events weren't logged on a fatal MCE.
--- arch/x86/kernel/cpu/mcheck/mce.c | 38 +++++++++++++++++++++++++------------- 1 files changed, 25 insertions(+), 13 deletions(-)
arch/x86/kernel/cpu/mcheck/mce.c +25 -13
@@ -39,6 +39,7 @@#include <asm/ipi.h> #include <asm/hw_irq.h> #include <asm/apic.h> +#include "mce-internal.h" #include "mce.h"
@@ -181,7 +182,7 @@ static void print_mce(struct mce *m) "and contact your hardware vendor\n"); } -static void mce_panic (char *msg,struct mce *final) +static void mce_panic (char *msg,struct mce *final,char *exp) {int i;
@@ -204,6 +205,8 @@ static void mce_panic(char *msg, struct mce *final) }if (final)print_mce (final); +if (exp) +printk (KERN_EMERG "Machine check: %s\n" , exp);panic (msg); }
@@ -391,6 +394,22 @@ void machine_check_poll(enum mcp_flags flags, mce_banks_t *b)EXPORT_SYMBOL_GPL (machine_check_poll);/* +* Do a quick check if any of the events requires a panic. +* This decides if we keep the events around or clear them. +*/ +static int mce_no_way_out (struct mce *m,char **msg) +{ +int i; + +for (i =0 ; i < banks; i++) { + m->status =mce_rdmsrl (MSR_IA32_MC0_STATUS + i*4 ); +if (mce_severity (m, tolerant, msg) >=MCE_PANIC_SEVERITY ) +return 1 ; + } +return 0 ; +} + +/* * The actual machine check handler. This only handles real * exceptions when something got corrupted coming in through int 18. *
@@ -414,6 +433,7 @@ void do_machine_check(struct pt_regs *regs, long error_code)*/ int kill_it =0 ;DECLARE_BITMAP (toclear,MAX_NR_BANKS ); +char *msg ="Unknown" ;atomic_inc (&mce_entry);
@@ -428,10 +448,7 @@ void do_machine_check(struct pt_regs *regs, long error_code)mce_setup (&m); m.mcgstatus =mce_rdmsrl (MSR_IA32_MCG_STATUS ); - -/* if the restart IP is not valid, we're done for */ -if (!(m.mcgstatus &MCG_STATUS_RIPV )) - no_way_out =1 ; + no_way_out =mce_no_way_out (&m, &msg);barrier ();
@@ -463,18 +480,13 @@ void do_machine_check(struct pt_regs *regs, long error_code)__set_bit (i, toclear);if (m.status &MCI_STATUS_EN ) { -/* if PCC was set, there's no way out */ - no_way_out |= !!(m.status &MCI_STATUS_PCC );/* * If this error was uncorrectable and there was * an overflow, we're in trouble. If no overflow, * we might get away with just killing a task. */ -if (m.status &MCI_STATUS_UC ) { -if (tolerant <1 || m.status &MCI_STATUS_OVER ) - no_way_out =1 ; +if (m.status &MCI_STATUS_UC ) kill_it =1 ; - } }else {/* * Machine check event was not enabled. Clear, but
@@ -516,7 +528,7 @@ void do_machine_check(struct pt_regs *regs, long error_code)* has not set tolerant to an insane level, give up and die. */ if (no_way_out && tolerant <3 ) -mce_panic ("Machine check" , &panicm); +mce_panic ("Machine check" , &panicm, msg);/* * If the error seems to be unrecoverable, something should be
@@ -544,7 +556,7 @@ void do_machine_check(struct pt_regs *regs, long error_code)if (user_space && tolerant >0 ) {force_sig (SIGBUS , current); }else if (panic_on_oops || tolerant <2 ) { -mce_panic ("Uncorrected machine check" , &panicm); +mce_panic ("Uncorrected machine check" , &panicm, msg); } }
Signature · 1 line
1.6.0.2
PATCH 16/31 x86: MCE: Implement panic synchronization
From: Andi Kleen <[email protected]>
Impact: bugfix
In some circumstances multiple CPUs can enter mce_panic() in parallel. This gives quite confused output because they will all dump the same machine check buffer.
The other problem is that they would all panic in parallel, but not process each other's shutdown IPIs because interrupts are disabled.
Detect this situation early on in mce_panic(). On the first CPU entering will do the panic, the others will just wait to be killed.
For paranoia reasons in case the other CPU dies during the MCE I added a 5 seconds timeout. If it expires each CPU will panic on its own again,
--- arch/x86/kernel/cpu/mcheck/mce.c | 22 ++++++++++++++++++++++ 1 files changed, 22 insertions(+), 0 deletions(-)
arch/x86/kernel/cpu/mcheck/mce.c +22 -0
@@ -182,10 +182,32 @@ static void print_mce(struct mce *m) "and contact your hardware vendor\n"); } +#define PANIC_TIMEOUT 5/* 5 seconds */ + +static atomic_t mce_paniced; + +/* Panic in progress. Enable interrupts and wait for final IPI */ +static void wait_for_panic (void ) +{ +long timeout =PANIC_TIMEOUT *USEC_PER_SEC ; +preempt_disable (); +local_irq_enable (); +while (timeout-- >0 ) +udelay (1 ); +panic ("Panicing machine check CPU died" ); +} +static void mce_panic (char *msg,struct mce *final,char *exp) {int i; +/* +* Make sure only one CPU runs in machine check panic +*/ +if (atomic_add_return (1 , &mce_paniced) >1 ) +wait_for_panic (); +barrier (); +bust_spinlocks (1 );console_verbose ();/* First print corrected ones that are still unlogged */
Signature · 1 line
1.6.0.2
PATCH 17/31 x86: MCE: Switch x86 machine check handler to Monarch election. v2
From: Andi Kleen <[email protected]>
Impact: feature, fixes long standing problems.
On Intel platforms machine check exceptions are always broadcast to all CPUs. This patch makes the machine check handler synchronize all these machine checks, elect a Monarch to handle the event and collect the worst event from all CPUs and then process it first.
This has some advantages:
- When there is a truly data corrupting error the system panics as quickly as possible. This improves containment of corrupted data and makes sure the corrupted data never hits stable storage.
- The panics are synchronized and do not reenter the panic code on multiple CPUs (which currently does not handle this well).
- All the errors are reported. Currently it often happens that another CPU happens to do the panic first, but reports useless information (empty machine check) because the real error happened on another CPU which came in later.
This is a big advantage on Nehalem where the 8 threads per CPU lead to often the wrong CPU winning the race and dumping useless information on a machine check. The problem also occurs in a less severe form on older CPUs.
- The system can detect when no CPUs detected a machine check and shut down the system. This can happen when one CPU is so badly hung that that it cannot process a machine check anymore or when some external agent wants to stop the system by asserting the machine check pin. This follows Intel hardware recommendations.
- This matches the recommended error model by the CPU designers.
- The events can be output in true severity order
- When a panic happens on another CPU it makes sure to be actually be able to process the stop IPI by enabling interrupts.
The code is extremly careful to handle timeouts while waiting for other CPUs. It can't rely on the normal timing mechanisms (jiffies, ktime_get) because of its asynchronous/lockless nature, so it uses own timeouts using ndelay() and a "SPINUNIT"
The timeout is configurable. By default it waits for upto one second for the other CPUs. This can be also disabled.
Quoted 1 line
From some informal testing AMD systems do not see to broadcast
machine checks, so right now it's always disabled by default on non Intel CPUs or also on very old Intel systems.
Includes fixes from Ying Huang
Fixed a "ecception" in a comment (H.Seto)
Moved global_nwo reset later based on suggestion from H.Seto
v2: Avoid duplicate messages
--- Documentation/x86/x86_64/boot-options.txt | 6 +- Documentation/x86/x86_64/machinecheck | 4 + arch/x86/kernel/cpu/mcheck/mce.c | 360 ++++++++++++++++++++++++++--- 3 files changed, 340 insertions(+), 30 deletions(-)
Documentation/x86/x86_64/boot-options.txt +5 -1
@@ -13,13 +13,17 @@ Machine check in a reboot. On Intel systems it is enabled by default. mce=nobootlog Disable boot machine check logging. - mce=tolerancelevel (number) + mce=tolerancelevel[,monarchtimeout] (number,number) + tolerance levels: 0: always panic on uncorrected errors, log corrected errors 1: panic or SIGBUS on uncorrected errors, log corrected errors 2: SIGBUS or log uncorrected errors, log corrected errors 3: never panic or SIGBUS, log all errors (for testing only) Default is 1 Can be also set using sysfs which is preferable. + monarchtimout: + Sets the time in us to wait for other CPUs on machine checks. 0 + to disable. nomce (for compatibility with i386): same as mce=off
Documentation/x86/x86_64/machinecheck +4 -0
@@ -67,6 +67,10 @@ trigger Program to run when a machine check event is detected. This is an alternative to running mcelog regularly from cron and allows to detect events faster. +monarch_timeout + How long to wait for the other CPUs to machine check too on a + exception. 0 to disable waiting for other CPUs. + Unit: us TBD document entries for AMD threshold interrupt configuration
arch/x86/kernel/cpu/mcheck/mce.c +331 -29
492 lines not on this page · raw message
Signature · 1 line
1.6.0.2
PATCH 18/31 x86: MCE: Store record length into memory struct mce anchor
From: Andi Kleen <[email protected]>
This makes it easier for tools who want to extract the mcelog out of crash images or memory dumps to adapt to changing struct mce size. The length field replaces padding, so it's fully compatible.
--- arch/x86/include/asm/mce.h | 2 +- arch/x86/kernel/cpu/mcheck/mce.c | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-)
arch/x86/include/asm/mce.h +1 -1
@@ -59,7 +59,7 @@ struct mce_log {unsigned len;/* = MCE_LOG_LEN */ unsigned next;unsigned flags; -unsigned pad0; +unsigned recordlen;/* length of struct mce */ struct mce entry[MCE_LOG_LEN ]; };
arch/x86/kernel/cpu/mcheck/mce.c +3 -2
@@ -121,8 +121,9 @@ EXPORT_PER_CPU_SYMBOL_GPL(injectm);*/ static struct mce_log mcelog = { -MCE_LOG_SIGNATURE , -MCE_LOG_LEN , + .signature =MCE_LOG_SIGNATURE , + .len =MCE_LOG_LEN , + .recordlen =sizeof (struct mce ), };void mce_log (struct mce *mce)
Signature · 1 line
1.6.0.2
PATCH 19/31 x86: MCE: Default to panic timeout for machine checks v2
From: Andi Kleen <[email protected]>
Fatal machine checks can be logged to disk after boot, but only if the system did a warm reboot. That's unfortunately difficult with the default panic behaviour, which waits forever and the admin has to press the power button because modern systems usually miss a reset button. This clears the machine checks in the registers and make
it impossible to log them.
This patch changes the default for machine check panic to always reboot after 30s. Then the mce can be successfully logged after reboot.
I believe this will improve machine check experience for any system running the X server.
This is dependent on successfull boot logging of MCEs. This currently only works on Intel systems, on AMD there are quite a lot of systems around which leave junk in the machine check registers after boot, so it's disabled here. These systems will continue to default to endless waiting panic.
v2: Only force panic timeout when it's shorter (H.Seto)
--- arch/x86/kernel/cpu/mcheck/mce.c | 7 +++++++ 1 files changed, 7 insertions(+), 0 deletions(-)
arch/x86/kernel/cpu/mcheck/mce.c +7 -0
@@ -82,6 +82,7 @@ static unsigned long notify_user;static int rip_msr;static int mce_bootlog =-1 ;static int monarch_timeout =-1 ; +static int mce_panic_timeout;static char trigger[128 ];static char *trigger_argv[2 ] = { trigger,NULL };
@@ -203,6 +204,8 @@ static void wait_for_panic(void)local_irq_enable ();while (timeout-- >0 )udelay (1 ); +if (mce_panic_timeout < panic_timeout) + panic_timeout = mce_panic_timeout;panic ("Panicing machine check CPU died" ); }
@@ -240,6 +243,8 @@ static void mce_panic(char *msg, struct mce *final, char *exp)printk (KERN_EMERG "Some CPUs didn't answer in synchronization\n" );if (exp)printk (KERN_EMERG "Machine check: %s\n" , exp); +if (mce_panic_timeout < panic_timeout) + panic_timeout = mce_panic_timeout;panic (msg); }
@@ -1100,6 +1105,8 @@ static void mce_cpu_quirks(struct cpuinfo_x86 *c) }if (monarch_timeout <0 ) monarch_timeout =0 ; +if (mce_bootlog !=0 ) + mce_panic_timeout =30 ; }static void __cpuinit mce_ancient_init (struct cpuinfo_x86 *c)
Signature · 1 line
1.6.0.2
PATCH 20/31 x86: MCE: Improve documentation
From: Andi Kleen <[email protected]>
Document that check_interval set to 0 means no polling. Noticed by Hidetoshi Seto
Also add a reference from boot options to the sysfs tunables
--- Documentation/x86/x86_64/boot-options.txt | 2 ++ Documentation/x86/x86_64/machinecheck | 4 +++- 2 files changed, 5 insertions(+), 1 deletions(-)
Documentation/x86/x86_64/boot-options.txt +2 -0
@@ -5,6 +5,8 @@ only the AMD64 specific ones are listed here. Machine check + Please see Documentation/x86/x86_64/machinecheck for sysfs runtime tunables. + mce=off disable machine check mce=bootlog Enable logging of machine checks left over from booting. Disabled by default on AMD because some BIOS leave bogus ones.
Documentation/x86/x86_64/machinecheck +3 -1
@@ -41,7 +41,9 @@ check_interval the polling interval. When the poller stops finding MCEs, it triggers an exponential backoff (poll less often) on the polling interval. The check_interval variable is both the initial and - maximum polling interval. + maximum polling interval. 0 means no polling for corrected machine + check errors (but some corrected errors might be still reported + in other ways) tolerant Tolerance level. When a machine check exception occurs for a non
Signature · 1 line
1.6.0.2
PATCH 21/31 x86: MCE: Support more than 256 CPUs in struct mce
From: Andi Kleen <[email protected]>
The old struct mce had a limitation to 256 CPUs. But x86 Linux supports more than that now with x2apic. Add a new field extcpu to report the extended number.
--- arch/x86/include/asm/mce.h | 4 ++-- arch/x86/kernel/cpu/mcheck/mce-inject.c | 10 +++++----- arch/x86/kernel/cpu/mcheck/mce.c | 4 ++-- 3 files changed, 9 insertions(+), 9 deletions(-)
arch/x86/include/asm/mce.h +2 -2
@@ -40,9 +40,9 @@ struct mce {__u64 res2;/* dito. */ __u8 cs;/* code segment */ __u8 bank;/* machine check bank */ -__u8 cpu;/* cpu that raised the error */ +__u8 cpu;/* cpu number; obsolete; use extcpu now */ __u8 finished;/* entry is valid */ -__u32 pad; +__u32 extcpu;/* linux cpu number that detected the error */ };/*
arch/x86/kernel/cpu/mcheck/mce-inject.c +5 -5
@@ -23,14 +23,14 @@/* Update fake mce registers on current CPU. */ static void inject_mce (struct mce *m) { -struct mce *i = &per_cpu (injectm, m->cpu); +struct mce *i = &per_cpu (injectm, m->extcpu);/* Make sure noone reads partially written injectm */ i->finished =0 ;mb (); m->finished =0 ;/* First set the fields after finished */ - i->cpu = m->cpu; + i->extcpu = m->extcpu;mb ();/* Now write record in order, finished last (except above) */ memcpy (i, m,sizeof (struct mce ));
@@ -49,7 +49,7 @@ static void raise_mce(unsigned long data) {struct delayed_mce *dm = (struct delayed_mce *)data;struct mce *m = &dm->m; -int cpu = m->cpu; +int cpu = m->extcpu;inject_mce (m);if (m->status &MCI_STATUS_UC ) {
@@ -93,7 +93,7 @@ static ssize_t mce_write(struct file *filp, const char __user *ubuf,if (copy_from_user (&m, ubuf, usize))return -EFAULT ; -if (m.cpu >=NR_CPUS || !cpu_online (m.cpu)) +if (m.extcpu >=NR_CPUS || !cpu_online (m.extcpu))return -EINVAL ; dm =kmalloc (sizeof (struct delayed_mce ),GFP_KERNEL );
@@ -108,7 +108,7 @@ static ssize_t mce_write(struct file *filp, const char __user *ubuf,memcpy (&dm->m, &m,sizeof (struct mce ));setup_timer (&dm->timer, raise_mce, (unsigned long )dm); dm->timer.expires = jiffies +2 ; -add_timer_on (&dm->timer, m.cpu); +add_timer_on (&dm->timer, m.extcpu);return usize; }
arch/x86/kernel/cpu/mcheck/mce.c +2 -2
@@ -108,7 +108,7 @@ static inline int skip_bank_init(int i)void mce_setup (struct mce *m) {memset (m,0 ,sizeof (struct mce )); - m->cpu =smp_processor_id (); + m->cpu = m->extcpu =smp_processor_id ();rdtscll (m->tsc); }
@@ -172,7 +172,7 @@ static void print_mce(struct mce *m)KERN_EMERG "HARDWARE ERROR\n" KERN_EMERG "CPU %d: Machine Check Exception: %16Lx Bank %d: %016Lx\n" , - m->cpu, m->mcgstatus, m->bank, m->status); + m->extcpu, m->mcgstatus, m->bank, m->status);if (m->ip) { printk(KERN_EMERG "RIP%s %02x:<%016Lx> ", !(m->mcgstatus & MCG_STATUS_EIPV) ? " !INEXACT!" : "",
Signature · 1 line
1.6.0.2
PATCH 22/31 x86: MCE: Extend struct mce user interface with more information.
From: Andi Kleen <[email protected]>
Experience has shown that struct mce which is used to pass an machine check to the user space daemon currently a few limitations. Also some data which is useful to print at panic level is also missing.
This patch addresses most of them. The same information is also printed out together with mce panic.
struct mce can be painlessly extended in a compatible way, the mcelog user space code just ignores additional fields with a warning.
- It doesn't provide a wall time timestamp. There have been a few complaints about that. Fix that by adding a 64bit time_t
- It doesn't provide the exact CPU identification. This makes it awkward for mcelog to decode the event correctly, especially when there are variations in the supported MCE codes on different CPU models or when mcelog is running on a different host after a panic. Previously the administrator had to specify the correct CPU when mcelog ran on a different host, but with the more variation in machine checks now it's better to auto detect that.
It's also useful for more detailed analysis of CPU events. Pass CPUID 1.EAX and the cpu vendor (as encoded in processor.h) instead.
- Socket ID and initial APIC ID are useful to report because they allow to identify the failing CPU in some (not all) cases. This is also especially useful for the panic situation.
This addresses one of the complaints from Thomas Gleixner earlier.
- The MCG capabilities MSR needs to be reported for some advanced error processing in mcelog
--- arch/x86/include/asm/mce.h | 10 ++++++++-- arch/x86/kernel/cpu/mcheck/mce.c | 12 ++++++++++++ 2 files changed, 20 insertions(+), 2 deletions(-)
arch/x86/include/asm/mce.h +8 -2
@@ -36,13 +36,19 @@ struct mce {__u64 mcgstatus;__u64 ip;__u64 tsc;/* cpu time stamp counter */ -__u64 res1;/* for future extension */ -__u64 res2;/* dito. */ +__u64 time;/* wall time_t when error was detected */ +__u8 cpuvendor;/* cpu vendor as encoded in system.h */ +__u8 pad1; +__u16 pad2; +__u32 cpuid;/* CPUID 1 EAX */ __u8 cs;/* code segment */ __u8 bank;/* machine check bank */ __u8 cpu;/* cpu number; obsolete; use extcpu now */ __u8 finished;/* entry is valid */ __u32 extcpu;/* linux cpu number that detected the error */ +__u32 socketid;/* CPU socket ID */ +__u32 apicid;/* CPU initial apic ID */ +__u64 mcgcap;/* MCGCAP MSR: machine check capabilities of CPU */ };/*
arch/x86/kernel/cpu/mcheck/mce.c +12 -0
@@ -110,6 +110,15 @@ void mce_setup(struct mce *m)memset (m,0 ,sizeof (struct mce )); m->cpu = m->extcpu =smp_processor_id ();rdtscll (m->tsc); +/* We hope get_seconds stays lockless */ + m->time =get_seconds (); + m->cpuvendor = boot_cpu_data.x86_vendor; + m->cpuid =cpuid_eax (1 ); +#ifdef CONFIG_SMP + m->socketid =cpu_data (m->extcpu).phys_proc_id; +#endif + m->apicid =cpu_data (m->extcpu).initial_apicid; +rdmsrl (MSR_IA32_MCG_CAP , m->mcgcap); } DEFINE_PER_CPU(struct mce, injectm);
@@ -187,6 +196,9 @@ static void print_mce(struct mce *m)if (m->misc)printk ("MISC %llx " , m->misc);printk ("\n" ); +printk (KERN_EMERG "PROCESSOR %u:%x TIME %llu SOCKET %u APIC %x\n" , + m->cpuvendor, m->cpuid, m->time, m->socketid, + m->apicid);printk (KERN_EMERG "This is not a software problem!\n" );printk (KERN_EMERG "Run through mcelog --ascii to decode " "and contact your hardware vendor\n" );
Signature · 1 line
1.6.0.2
PATCH 23/31 x86: MCE: Add MCE poll count to /proc/interrupts
From: Andi Kleen <[email protected]>
Keep a count of the machine check polls (or CMCI events) in /proc/interrupts.
Andi needs this for debugging, but it's also useful in general to see what's going in by the kernel.
--- arch/x86/include/asm/mce.h | 1 + arch/x86/kernel/cpu/mcheck/mce.c | 4 ++++ arch/x86/kernel/irq.c | 4 ++++ 3 files changed, 9 insertions(+), 0 deletions(-)
arch/x86/include/asm/mce.h +1 -0
@@ -131,6 +131,7 @@ static inline void mce_amd_feature_init(struct cpuinfo_x86 *c) { }extern int mce_available (struct cpuinfo_x86 *c);DECLARE_PER_CPU (unsigned, mce_exception_count); +DECLARE_PER_CPU (unsigned, mce_poll_count);void mce_log_therm_throt_event (__u64 status);
arch/x86/kernel/cpu/mcheck/mce.c +4 -0
@@ -374,6 +374,8 @@ static void mce_report_event(struct pt_regs *regs)#endif } +DEFINE_PER_CPU (unsigned, mce_poll_count); +/* * Poll for corrected events or events that happened before reset. * Those are just logged through /dev/mcelog.
@@ -385,6 +387,8 @@ void machine_check_poll(enum mcp_flags flags, mce_banks_t *b)struct mce m;int i; +__get_cpu_var (mce_poll_count)++; +mce_setup (&m); m.mcgstatus =mce_rdmsrl (MSR_IA32_MCG_STATUS );
arch/x86/kernel/irq.c +4 -0
@@ -102,6 +102,10 @@ static int show_other_interrupts(struct seq_file *p, int prec)for_each_online_cpu (j)seq_printf (p,"%10u " ,per_cpu (mce_exception_count, j));seq_printf (p," Machine check exceptions\n" ); +seq_printf (p,"%*s: " , prec,"MCP" ); +for_each_online_cpu (j) +seq_printf (p,"%10u " ,per_cpu (mce_poll_count, j)); +seq_printf (p," Machine check polls\n" );#endif seq_printf (p,"%*s: %10u\n" , prec,"ERR" ,atomic_read (&irq_err_count));#if defined(CONFIG_X86_IO_APIC )
Signature · 1 line
1.6.0.2
PATCH 24/31 x86: MCE: Don't print backtrace on machine checks with DEBUG_BUGVERBOSE
From: Andi Kleen <[email protected]>
CONFIG_DEBUG_BUGVERBOSE prints backtraces on panics, but we don't want that on machine checks because these are not kernel bugs. So disable it here.
--- kernel/panic.c | 3 ++- 1 files changed, 2 insertions(+), 1 deletions(-)
kernel/panic.c +2 -1
@@ -71,7 +71,8 @@ NORET_TYPE void panic(const char * fmt, ...)va_end (args);printk (KERN_EMERG "Kernel panic - not syncing: %s\n" ,buf);#ifdef CONFIG_DEBUG_BUGVERBOSE -dump_stack (); +if (!strstr (fmt,"Machine check" )) +dump_stack ();#endif /*
Signature · 1 line
1.6.0.2
PATCH 25/31 x86: MCE: Implement new status bits v2
From: Andi Kleen <[email protected]>
The x86 architecture recently added some new machine check status bits:
S(ignalled) and AR (Action-Required). Signalled allows to check if a specific event caused an exception or was just logged through CMCI. AR allows the kernel to decide if an event needs immediate action or can be delayed or ignored.
Implement support for these new status bits. mce_severity() uses the new bits to grade the machine check correctly and decide what to do. The exception handler uses AR to decide to kill or not. The S bit is used to separate events between the poll/CMCI handler and the exception handler.
Classical UC always leads to panic. That was true before anyways because the existing CPUs always passed a PCC with it.
Also corrects the rules whether to kill in user or kernel context and how to handle missing RIPV.
The machine check handler largely uses the mce-severity grading engine now instead of making its own decisions. This means the logic is centralized in one place. This is useful because it has to be evaluated multiple times.
v2: Some rule fixes; Add AO events
Fix RIPV, RIPV|EIPV order (Ying Huang)
Fix UCNA with AR=1 message (Ying Huang)
Add comment about panicing in m_c_p.
--- arch/x86/include/asm/mce.h | 10 ++++ arch/x86/kernel/cpu/mcheck/mce-internal.h | 5 ++ arch/x86/kernel/cpu/mcheck/mce-severity.c | 82 ++++++++++++++++++++++++++-- arch/x86/kernel/cpu/mcheck/mce.c | 85 +++++++++++++++-------------- 4 files changed, 137 insertions(+), 45 deletions(-)
arch/x86/include/asm/mce.h +10 -0
@@ -15,6 +15,7 @@#define MCG_CTL_P (1ULL << 8)/* MCG_CAP register available */ #define MCG_EXT_P (1ULL << 9)/* Extended registers available */ #define MCG_CMCI_P (1ULL << 10)/* CMCI supported */ +#define MCG_SER_P (1ULL<<24)/* MCA recovery/new status bits */ #define MCG_STATUS_RIPV (1ULL<<0)/* restart ip valid */ #define MCG_STATUS_EIPV (1ULL<<1)/* ip points to correct instruction */
@@ -27,6 +28,15 @@#define MCI_STATUS_MISCV (1ULL<<59)/* misc error reg. valid */ #define MCI_STATUS_ADDRV (1ULL<<58)/* addr reg. valid */ #define MCI_STATUS_PCC (1ULL<<57)/* processor context corrupt */ +#define MCI_STATUS_S (1ULL<<56)/* Signaled machine check */ +#define MCI_STATUS_AR (1ULL<<55)/* Action required */ + +/* MISC register defines */ +#define MCM_ADDR_SEGOFF 0/* segment offset */ +#define MCM_ADDR_LINEAR 1/* linear address */ +#define MCM_ADDR_PHYS 2/* physical address */ +#define MCM_ADDR_MEM 3/* memory address */ +#define MCM_ADDR_GENERIC 7/* generic */ /* Fields are zero when not available */ struct mce {
arch/x86/kernel/cpu/mcheck/mce-internal.h +5 -0
@@ -2,9 +2,14 @@enum severity_level {MCE_NO_SEVERITY , +MCE_KEEP_SEVERITY ,MCE_SOME_SEVERITY , +MCE_AO_SEVERITY ,MCE_UC_SEVERITY , +MCE_AR_SEVERITY ,MCE_PANIC_SEVERITY , };int mce_severity (struct mce *a,int tolerant,char **msg); + +extern int mce_ser;
arch/x86/kernel/cpu/mcheck/mce-severity.c +78 -4
121 lines not on this page · raw message
arch/x86/kernel/cpu/mcheck/mce.c +44 -41
150 lines not on this page · raw message
Signature · 1 line
1.6.0.2
PATCH 26/31 x86: MCE: Export MCE severities coverage via debugfs
From: Huang Ying <[email protected]>
The MCE severity judgement code is data-driven, so code coverage tools such as gcov can not be used for measuring coverage. Instead a dedicated coverage mechanism is implemented. The kernel keeps track of rules executed and reports them in debugfs.
This is useful for increasing coverage of the mce-test testsuite.
Right now it's unconditionally enabled because it's very little code.
--- arch/x86/kernel/cpu/mcheck/mce-severity.c | 83 +++++++++++++++++++++++++++++ 1 files changed, 83 insertions(+), 0 deletions(-)
arch/x86/kernel/cpu/mcheck/mce-severity.c +83 -0
@@ -10,6 +10,9 @@* Author: Andi Kleen */ #include <linux/kernel.h> +#include <linux/seq_file.h> +#include <linux/init.h> +#include <linux/debugfs.h> #include <asm/mce.h> #include "mce-internal.h"
@@ -37,6 +40,7 @@ static struct severity {unsigned char mcgres;unsigned char ser;unsigned char context; +unsigned char covered;char *msg; } severities[] = {#define KERNEL .context = IN_KERNEL
@@ -126,6 +130,7 @@ int mce_severity(struct mce *a, int tolerant, char **msg)continue ;if (msg) *msg = s->msg; + s->covered =1 ;if (s->sev >=MCE_UC_SEVERITY && ctx ==IN_KERNEL ) {if (panic_on_oops || tolerant <1 )return MCE_PANIC_SEVERITY ;
@@ -133,3 +138,81 @@ int mce_severity(struct mce *a, int tolerant, char **msg)return s->sev; } } + +static void *s_start (struct seq_file *f,loff_t *pos) +{ +if (*pos >=ARRAY_SIZE (severities)) +return NULL ; +return &severities[*pos]; +} + +static void *s_next (struct seq_file *f,void *data,loff_t *pos) +{ +if (++(*pos) >=ARRAY_SIZE (severities)) +return NULL ; +return &severities[*pos]; +} + +static void s_stop (struct seq_file *f,void *data) +{ +} + +static int s_show (struct seq_file *f,void *data) +{ +struct severity *ser = data; +seq_printf (f,"%d\t%s\n" , ser->covered, ser->msg); +return 0 ; +} + +static const struct seq_operations severities_seq_ops = { + .start = s_start, + .next = s_next, + .stop = s_stop, + .show = s_show, +}; + +static int severities_coverage_open (struct inode *inode,struct file *file) +{ +return seq_open (file, &severities_seq_ops); +} + +static ssize_t severities_coverage_write (struct file *file, +const char __user *ubuf, +size_t count,loff_t *ppos) +{ +int i; +for (i =0 ; i <ARRAY_SIZE (severities); i++) + severities[i].covered =0 ; +return count; +} + +static const struct file_operations severities_coverage_fops = { + .open = severities_coverage_open, + .release = seq_release, + .read = seq_read, + .write = severities_coverage_write, +}; + +static int __init severities_debugfs_init (void ) +{ +struct dentry *dmce =NULL , *fseverities_coverage =NULL ; + + dmce =debugfs_create_dir ("mce" ,NULL ); +if (dmce ==NULL ) + goto err_out; + fseverities_coverage =debugfs_create_file ("severities-coverage" , +0444 , dmce,NULL , + &severities_coverage_fops); +if (fseverities_coverage ==NULL ) + goto err_out; + +return 0 ; + +err_out: +if (fseverities_coverage) +debugfs_remove (fseverities_coverage); +if (dmce) +debugfs_remove (dmce); +return -ENOMEM ; +} +late_initcall (severities_debugfs_init);
Signature · 1 line
1.6.0.2
PATCH 27/31 x86: MCE: Print header/footer only once for multiple MCEs
From: Andi Kleen <[email protected]>
When multiple MCEs are printed print the "HARDWARE ERROR" header and "This is not a software error" footer only once. This makes the output much more compact with many CPUs.
--- arch/x86/kernel/cpu/mcheck/mce.c | 27 +++++++++++++++++---------- 1 files changed, 17 insertions(+), 10 deletions(-)
arch/x86/kernel/cpu/mcheck/mce.c +17 -10
@@ -176,11 +176,13 @@ void mce_log(struct mce *mce)set_bit (0 , ¬ify_user); } -static void print_mce (struct mce *m) +static void print_mce (struct mce *m,int *first) { -printk (KERN_EMERG "\n" -KERN_EMERG "HARDWARE ERROR\n" -KERN_EMERG +if (*first) { +printk (KERN_EMERG "\n" KERN_EMERG "HARDWARE ERROR\n" ); + *first =0 ; + } +printk (KERN_EMERG "CPU %d: Machine Check Exception: %16Lx Bank %d: %016Lx\n" , m->extcpu, m->mcgstatus, m->bank, m->status);if (m->ip) {
@@ -200,9 +202,12 @@ static void print_mce(struct mce *m)printk (KERN_EMERG "PROCESSOR %u:%x TIME %llu SOCKET %u APIC %x\n" , m->cpuvendor, m->cpuid, m->time, m->socketid, m->apicid); -printk (KERN_EMERG "This is not a software problem!\n" ); -printk (KERN_EMERG "Run through mcelog --ascii to decode " -"and contact your hardware vendor\n" ); +} + +static void print_mce_tail (void ) +{ +printk (KERN_EMERG "This is not a software problem!\n" +KERN_EMERG "Run through mcelog --ascii to decode and contact your hardware vendor\n" ); }#define PANIC_TIMEOUT 5/* 5 seconds */
@@ -225,6 +230,7 @@ static void wait_for_panic(void)static void mce_panic (char *msg,struct mce *final,char *exp) {int i; +int first =1 ;/* * Make sure only one CPU runs in machine check panic
@@ -240,7 +246,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)struct mce *m = &mcelog.entry[i];if ((m->status &MCI_STATUS_VAL ) && !(m->status &MCI_STATUS_UC )) -print_mce (m); +print_mce (m, &first); }/* Now print uncorrected but with the final one last */ for (i =0 ; i <MCE_LOG_LEN ; i++) {
@@ -248,12 +254,13 @@ static void mce_panic(char *msg, struct mce *final, char *exp)if (!(m->status &MCI_STATUS_VAL ))continue ;if (!final ||memcmp (m, final,sizeof (struct mce ))) -print_mce (m); +print_mce (m, &first); }if (final) -print_mce (final); +print_mce (final, &first);if (cpu_missing)printk (KERN_EMERG "Some CPUs didn't answer in synchronization\n" ); +print_mce_tail ();if (exp)printk (KERN_EMERG "Machine check: %s\n" , exp);if (mce_panic_timeout < panic_timeout)
Signature · 1 line
1.6.0.2
PATCH 28/31 x86: MCE: Make non Monarch panic message "Fatal machine check" too v2
From: Andi Kleen <[email protected]>
... instead of "Machine check". This is for consistency with the Monarch panic message.
Based on a report from Ying Huang.
v2: But add a descriptive postfix so that the test suite can distingush.
--- arch/x86/kernel/cpu/mcheck/mce.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
arch/x86/kernel/cpu/mcheck/mce.c +1 -1
@@ -889,7 +889,7 @@ void do_machine_check(struct pt_regs *regs, long error_code)* support MCE broadcasting or it has been disabled. */ if (no_way_out && tolerant <3 ) -mce_panic ("Machine check" , final, msg); +mce_panic ("Fatal machine check on current CPU" , final, msg);/* * If the error seems to be unrecoverable, something should be
Signature · 1 line
1.6.0.2
PATCH 29/31 x86: MCE: Rename mce_notify_user to mce_notify_irq
From: Andi Kleen <[email protected]>
Impact: cleanup
Rename the mce_notify_user function to mce_notify_irq. The next patch will split the wakeup handling of interrupt context and of process context and it's better to give it a clearer name for this.
Contains a fix from Ying Huang
--- arch/x86/include/asm/mce.h | 2 +- arch/x86/kernel/cpu/mcheck/mce-inject.c | 2 +- arch/x86/kernel/cpu/mcheck/mce.c | 10 +++++----- arch/x86/kernel/cpu/mcheck/mce_intel_64.c | 2 +- arch/x86/kernel/signal.c | 2 +- 5 files changed, 9 insertions(+), 9 deletions(-)
arch/x86/include/asm/mce.h +1 -1
@@ -159,7 +159,7 @@ enum mcp_flags { };extern void machine_check_poll (enum mcp_flags flags,mce_banks_t *b); -extern int mce_notify_user (void ); +extern int mce_notify_irq (void ); DECLARE_PER_CPU(struct mce, injectm);extern struct file_operations mce_chrdev_ops;
arch/x86/kernel/cpu/mcheck/mce-inject.c +1 -1
@@ -65,7 +65,7 @@ static void raise_mce(unsigned long data)memset (&b,0xff ,sizeof (mce_banks_t));printk (KERN_INFO "Starting machine check poll CPU %d\n" , cpu);machine_check_poll (0 , &b); -mce_notify_user (); +mce_notify_irq ();printk (KERN_INFO "Finished machine check poll on CPU %d\n" , cpu); }
arch/x86/kernel/cpu/mcheck/mce.c +5 -5
@@ -346,14 +346,14 @@ asmlinkage void smp_mce_self_interrupt(struct pt_regs *regs)ack_APIC_irq ();exit_idle ();irq_enter (); -mce_notify_user (); +mce_notify_irq ();irq_exit (); }static void mce_report_event (struct pt_regs *regs) {if (regs->flags & (X86_VM_MASK |X86_EFLAGS_IF )) { -mce_notify_user (); +mce_notify_irq ();return ; }
@@ -964,7 +964,7 @@ static void mcheck_timer(unsigned long data)* polling interval, otherwise increase the polling interval. */ n = &__get_cpu_var (next_interval); -if (mce_notify_user ()) { +if (mce_notify_irq ()) { *n =max (*n/2 ,HZ /100 ); }else { *n =min (*n*2 , (int )round_jiffies_relative (check_interval*HZ ));
@@ -986,7 +986,7 @@ static DECLARE_WORK(mce_trigger_work, mce_do_trigger);* Can be called from interrupt context, but not from machine check/NMI * context. */ -int mce_notify_user (void ) +int mce_notify_irq (void ) {/* Not more than two messages every minute */ static DEFINE_RATELIMIT_STATE(ratelimit, 60*HZ, 2);
@@ -1011,7 +1011,7 @@ int mce_notify_user(void) }return 0 ; } -EXPORT_SYMBOL_GPL (mce_notify_user); +EXPORT_SYMBOL_GPL (mce_notify_irq);/* * Initialize Machine Checks for a CPU.
arch/x86/kernel/cpu/mcheck/mce_intel_64.c +1 -1
@@ -78,7 +78,7 @@ static int cmci_supported(int *banks)static void intel_threshold_interrupt (void ) {machine_check_poll (MCP_TIMESTAMP , &__get_cpu_var (mce_banks_owned)); -mce_notify_user (); +mce_notify_irq (); }/*
arch/x86/kernel/signal.c +1 -1
@@ -860,7 +860,7 @@ do_notify_resume(struct pt_regs *regs, void *unused, __u32 thread_info_flags)#ifdef CONFIG_X86_NEW_MCE /* notify userspace of pending MCEs */ if (thread_info_flags & _TIF_MCE_NOTIFY) -mce_notify_user (); +mce_notify_irq ();#endif /* CONFIG_X86_64 && CONFIG_X86_MCE */ /* deal with pending signal delivery */
Signature · 1 line
1.6.0.2
PATCH 30/31 x86: MCE: Define MCE_VECTOR
From: Andi Kleen <[email protected]>
--- arch/x86/include/asm/irq_vectors.h | 1 + 1 files changed, 1 insertions(+), 0 deletions(-)
arch/x86/include/asm/irq_vectors.h +1 -0
@@ -25,6 +25,7 @@*/ #define NMI_VECTOR 0x02 +#define MCE_VECTOR 0x12/* * IDT vectors usable for external interrupt sources start
Signature · 1 line
1.6.0.2
PATCH 31/31 x86: MCE: Support action-optional machine checks v2
From: Andi Kleen <[email protected]>
Newer Intel CPUs support a new class of machine checks called recoverable action optional.
Action Optional means that the CPU detected some form of corruption in the background and tells the OS about using a machine check exception. The OS can then take appropiate action, like killing the process with the corrupted data or logging the event properly to disk.
This is done by the new generic high level memory failure handler added in a earlier patch. The high level handler takes the address with the failed memory and does the appropiate action, like killing the process.
In this version of the patch the high level handler is stubbed out with a weak function to not create a direct dependency on the hwpoison branch.
The high level handler cannot be directly called from the machine check exception though, because it has to run in a defined process context to be able to sleep when taking VM locks (it is not expected to sleep for a long time, just do so in some exceptional cases like lock contention)
Thus the MCE handler has to queue a work item for process context, trigger process context and then call the high level handler from there.
This patch adds two path to process context: through a per thread kernel exit notify_user() callback or through a high priority work item. The first runs when the process exits back to user space, the other when it goes to sleep and there is no higher priority process.
The machine check handler will schedule both, and whoever runs first will grab the event. This is done because quick reaction to this event is critical to avoid a potential more fatal machine check when the corruption is consumed.
There is a simple lock less ring buffer to queue the corrupted addresses between the exception handler and the process context handler. Then in process context it just calls the high level VM code with the corrupted PFNs.
The code adds the required code to extract the failed address from the CPU's machine check registers. It doesn't try to handle all possible cases -- the specification has 6 different ways to specify memory address -- but only the linear address.
Most of the required checking has been already done earlier in the mce_severity rule checking engine. Following the Intel recommendations Action Optional errors are only enabled for known situations (encoded in MCACODs). The errors are ignored otherwise, because they are action optional.
v2: Improve comment, disable preemption while processing ring buffer
(reported by Ying Huang)
--- arch/x86/include/asm/mce.h | 1 + arch/x86/kernel/cpu/mcheck/mce.c | 133 ++++++++++++++++++++++++++++++++++++++ arch/x86/kernel/signal.c | 2 +- 3 files changed, 135 insertions(+), 1 deletions(-)
arch/x86/include/asm/mce.h +1 -0
@@ -160,6 +160,7 @@ enum mcp_flags {extern void machine_check_poll (enum mcp_flags flags,mce_banks_t *b);extern int mce_notify_irq (void ); +extern void mce_notify_process (void ); DECLARE_PER_CPU(struct mce, injectm);extern struct file_operations mce_chrdev_ops;
arch/x86/kernel/cpu/mcheck/mce.c +133 -0
193 lines not on this page · raw message
arch/x86/kernel/signal.c +1 -1
@@ -860,7 +860,7 @@ do_notify_resume(struct pt_regs *regs, void *unused, __u32 thread_info_flags)#ifdef CONFIG_X86_NEW_MCE /* notify userspace of pending MCEs */ if (thread_info_flags & _TIF_MCE_NOTIFY) -mce_notify_irq (); +mce_notify_process ();#endif /* CONFIG_X86_64 && CONFIG_X86_MCE */ /* deal with pending signal delivery */
Signature · 1 line
1.6.0.2
Re: [PATCH 27/31] x86: MCE: Print header/footer only once for multiple MCEs
In reply to Andi KleenQuoted 23 lines · Andi Kleen
From: Andi Kleen <[email protected]>
When multiple MCEs are printed print the "HARDWARE ERROR" header and "This is not a software error" footer only once. This makes the output much more compact with many CPUs.
Signed-off-by Andi Kleen <[email protected]>--- arch/x86/kernel/cpu/mcheck/mce.c | 27 +++++++++++++++++---------- 1 files changed, 17 insertions(+), 10 deletions(-)arch/x86/kernel/cpu/mcheck/mce.c +1
-2@@ -176,11 +176,13 @@ void mce_log(struct mce *mce)set_bit (0 , ¬ify_user); } -static void print_mce (struct mce *m) +static void print_mce (struct mce *m,int *first) { - printk(KERN_EMERG "\n"
arch/x86/kernel/cpu/mcheck/mce.c void mce_log(struct mce *mce) · line 188
Quoted 10 lines
arch/x86/kernel/cpu/mcheck/mce.c +5
-2-KERN_EMERG "HARDWARE ERROR\n" -KERN_EMERG +if (*first) { +printk (KERN_EMERG "\n" KERN_EMERG "HARDWARE ERROR\n" ); + *first =0 ; + } +printk (KERN_EMERG "CPU %d: Machine Check Exception: %16Lx Bank %d: %016Lx\n" , m->extcpu, m->mcgstatus, m->bank, m->status);if (m->ip) {
Why don't you have print_mce_head?
I suppose one possible benefit not to have it and do like this is that we can suppress printing header if there is no log to print.
But on the other hand footer is always printed.
Quoted 6 lines
arch/x86/kernel/cpu/mcheck/mce.c +0
-2@@ -200,9 +202,12 @@ static void print_mce(struct mce *m)printk (KERN_EMERG "PROCESSOR %u:%x TIME %llu SOCKET %u APIC %x\n" , m->cpuvendor, m->cpuid, m->time, m->socketid, m->apicid); -printk (KERN_EMERG "This is not a software problem!\n" ); - printk(KERN_EMERG "Run through mcelog --ascii to decode "
arch/x86/kernel/cpu/mcheck/mce.c static void print_mce(struct mce *m) · line 213
Quoted 10 lines
arch/x86/kernel/cpu/mcheck/mce.c +6
-1- "and contact your hardware vendor\n"); +} + +static void print_mce_tail (void ) +{ +printk (KERN_EMERG "This is not a software problem!\n" +KERN_EMERG "Run through mcelog --ascii to decode and contact your hardware vendor\n" ); }#define PANIC_TIMEOUT 5/* 5 seconds */
And if there is no log, do we still need to run mcelog?
Quoted 23 lines
arch/x86/kernel/cpu/mcheck/mce.c +3
-2@@ -225,6 +230,7 @@ static void wait_for_panic(void)static void mce_panic (char *msg,struct mce *final,char *exp) {int i; +int first =1 ;/* * Make sure only one CPU runs in machine check panic @@ -240,7 +246,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)struct mce *m = &mcelog.entry[i];if ((m->status &MCI_STATUS_VAL ) && !(m->status &MCI_STATUS_UC )) -print_mce (m); +print_mce (m, &first); }/* Now print uncorrected but with the final one last */ for (i =0 ; i <MCE_LOG_LEN ; i++) {@@ -248,12 +254,13 @@ static void mce_panic(char *msg, struct mce *final, char *exp)if (!(m->status &MCI_STATUS_VAL ))continue ;if (!final ||memcmp (m, final,sizeof (struct mce ))) -print_mce (m); +print_mce (m, &first);
arch/x86/kernel/cpu/mcheck/mce.c static void mce_panic(char *msg, struct mce *final, char *exp) · line 266
Quoted 10 lines
arch/x86/kernel/cpu/mcheck/mce.c +2
-1}if (final) -print_mce (final); +print_mce (final, &first);if (cpu_missing)printk (KERN_EMERG "Some CPUs didn't answer in synchronization\n" ); +print_mce_tail ();if (exp)printk (KERN_EMERG "Machine check: %s\n" , exp);if (mce_panic_timeout < panic_timeout)
If mce_panic is only caller of mce_log_tail (and possible mce_log_head), it would be better to use printk directly than having such sub-function.
Thanks,
H.Seto
Re: [PATCH 27/31] x86: MCE: Print header/footer only once for multiple MCEs
Quoted 3 lines · Hidetoshi Seto
I suppose one possible benefit not to have it and do like this is that we can suppress printing header if there is no log to print.
But on the other hand footer is always printed.
If there's a machine check exception there's a hardware error, so that message should be printed.
This can happen for example in the "external agent" case.
Quoted 3 lines
Quoted 1 line
#define
PANIC_TIMEOUT5 /* 5 seconds */And if there is no log, do we still need to run mcelog?
Not manually if it runs correctly, but the kernel doesn't know that in advance. So in case someone picks it up from a console log it might be still needed.
Quoted 21 lines
Quoted 21 lines
arch/x86/kernel/cpu/mcheck/mce.c +3
-3* Make sure only one CPU runs in machine check panic @@ -240,7 +246,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)struct mce *m = &mcelog.entry[i];if ((m->status &MCI_STATUS_VAL ) && !(m->status &MCI_STATUS_UC )) -print_mce (m); +print_mce (m, &first); }/* Now print uncorrected but with the final one last */ for (i =0 ; i <MCE_LOG_LEN ; i++) {@@ -248,12 +254,13 @@ static void mce_panic(char *msg, struct mce *final, char *exp)if (!(m->status &MCI_STATUS_VAL ))continue ;if (!final ||memcmp (m, final,sizeof (struct mce ))) -print_mce (m); +print_mce (m, &first); }if (final) -print_mce (final); +print_mce (final, &first);if (cpu_missing)
Quoted 8 lines
arch/x86/kernel/cpu/mcheck/mce.c static void mce_panic(char *msg, struct mce *final, char *exp) · line 266
Quoted 5 lines
arch/x86/kernel/cpu/mcheck/mce.c +1
-0printk (KERN_EMERG "Some CPUs didn't answer in synchronization\n" ); +print_mce_tail ();if (exp)printk (KERN_EMERG "Machine check: %s\n" , exp);if (mce_panic_timeout < panic_timeout)If
mce_panicis only caller ofmce_log_tail(and possiblemce_log_head), it would be better to use printk directly than having such sub-function.
The coding standard recommends to avoid too long functions, so I split it out.
-Andi
Signature · 1 line
[email protected] -- Speaking for myself only.
Re: [PATCH 19/31] x86: MCE: Default to panic timeout for machine checks v2
In reply to Andi KleenQuoted 22 lines · Andi Kleen
From: Andi Kleen <[email protected]>
Fatal machine checks can be logged to disk after boot, but only if the system did a warm reboot. That's unfortunately difficult with the default panic behaviour, which waits forever and the admin has to press the power button because modern systems usually miss a reset button. This clears the machine checks in the registers and make
it impossible to log them.This patch changes the default for machine check panic to always reboot after 30s. Then the mce can be successfully logged after reboot.
I believe this will improve machine check experience for any system running the X server.
This is dependent on successfull boot logging of MCEs. This currently only works on Intel systems, on AMD there are quite a lot of systems around which leave junk in the machine check registers after boot, so it's disabled here. These systems will continue to default to endless waiting panic.
Quoted 4 lines
v2: Only force panic timeout when it's shorter (H.Seto)
Signed-off-by Andi Kleen <[email protected]>---
I suppose the original intention is overwrite the panic_timeout 0 to 30.
Quoted 10 lines
arch/x86/kernel/cpu/mcheck/mce.c +2
-0@@ -240,6 +243,8 @@ static void mce_panic(char *msg, struct mce *final, char *exp)printk (KERN_EMERG "Some CPUs didn't answer in synchronization\n" );if (exp)printk (KERN_EMERG "Machine check: %s\n" , exp); +if (mce_panic_timeout < panic_timeout) + panic_timeout = mce_panic_timeout;panic (msg); }
arch/x86/kernel/cpu/mcheck/mce.c static void mce_cpu_quirks(struct cpuinfo_x86 *c) · line 1112
Quoted 8 lines
arch/x86/kernel/cpu/mcheck/mce.c +2
-0@@ -1100,6 +1105,8 @@ static void mce_cpu_quirks(struct cpuinfo_x86 *c) }if (monarch_timeout <0 ) monarch_timeout =0 ; +if (mce_bootlog !=0 ) + mce_panic_timeout =30 ; }static void __cpuinit mce_ancient_init (struct cpuinfo_x86 *c)
It seems it doesn't work.
I made a incremental patch for this fix. Please consider applying.
Thanks,
H.Seto
Re: [PATCH 19/31] x86: MCE: Default to panic timeout for machine checks v2
Quoted 1 line · Hidetoshi Seto
I suppose the original intention is overwrite the
panic_timeout0 to 30.
Yes.
Quoted 11 lines
arch/x86/kernel/cpu/mcheck/mce.c static void mce_cpu_quirks(struct cpuinfo_x86 *c) · line 1112
Quoted 9 lines
arch/x86/kernel/cpu/mcheck/mce.c +2
-0@@ -1100,6 +1105,8 @@ static void mce_cpu_quirks(struct cpuinfo_x86 *c) }if (monarch_timeout <0 ) monarch_timeout =0 ; +if (mce_bootlog !=0 ) + mce_panic_timeout =30 ; }static void __cpuinit mce_ancient_init (struct cpuinfo_x86 *c)It seems it doesn't work.
Okay fair point. I applied your earlier review suggestion literally yes that was not correct. I changed it in my patchkit to handle the 0 case too.
-Andi
Signature · 1 line
[email protected] -- Speaking for myself only.
PATCH 1/1 x86: MCE: Fix for mce_panic_timeout
In reply to Andi KleenThis fixes:
- In case of panic_timeout == 0 and mce_bootlog != 0:
System should reboot after mce panic, but it doesn't because current mce code doesn't overwrite small panic_timeout even if it is 0.
- In case of panic_timeout > 0 and mce_bootlog == 0.
System should reboot after panic, but it doesn't on mce panic because current mce code overwrite panic_timeout to 0.
--- arch/x86/kernel/cpu/mcheck/mce.c | 19 ++++++++++++------- 1 files changed, 12 insertions(+), 7 deletions(-)
arch/x86/kernel/cpu/mcheck/mce.c +12 -7
@@ -82,7 +82,7 @@ static unsigned long notify_user;static int rip_msr;static int mce_bootlog =-1 ;static int monarch_timeout =-1 ; -static int mce_panic_timeout; +static int mce_panic_timeout =30 ;static char trigger[128 ];static char *trigger_argv[2 ] = { trigger,NULL };
@@ -196,6 +196,15 @@ static void print_mce(struct mce *m)static atomic_t mce_paniced; +/* Let system panic to reboot for logging the fatal machine check */ +static void mce_set_panic_timeout (void ) +{ +if (!mce_bootlog) +return ; +if (!panic_timeout || mce_panic_timeout < panic_timeout) + panic_timeout = mce_panic_timeout; +} +/* Panic in progress. Enable interrupts and wait for final IPI */ static void wait_for_panic (void ) {
@@ -204,8 +213,7 @@ static void wait_for_panic(void)local_irq_enable ();while (timeout-- >0 )udelay (1 ); -if (mce_panic_timeout < panic_timeout) - panic_timeout = mce_panic_timeout; +mce_set_panic_timeout ();panic ("Panicing machine check CPU died" ); }
@@ -243,8 +251,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)printk (KERN_EMERG "Some CPUs didn't answer in synchronization\n" );if (exp)printk (KERN_EMERG "Machine check: %s\n" , exp); -if (mce_panic_timeout < panic_timeout) - panic_timeout = mce_panic_timeout; +mce_set_panic_timeout ();panic (msg); }
@@ -1109,8 +1116,6 @@ static void mce_cpu_quirks(struct cpuinfo_x86 *c) }if (monarch_timeout <0 ) monarch_timeout =0 ; -if (mce_bootlog !=0 ) - mce_panic_timeout =30 ; }static void __cpuinit mce_ancient_init (struct cpuinfo_x86 *c)
Signature · 1 line
1.6.3
Re: [PATCH] x86: MCE: Fix for mce_panic_timeout
Quoted 1 line · Hidetoshi Seto
This fixes:
Thanks I had already fixed it on my own.
Updated patch appended.
Quoted 4 lines
- In case of
panic_timeout> 0 andmce_bootlog== 0.
System should reboot after panic, but it doesn't on mce panic because current mce code overwritepanic_timeoutto 0.
Nope, with bootlog==0 it should _not_ automatically reboot on panic. Automatic rebooting makes mainly sense with boot logging, otherwise you will likely lose the information. Or at least the kernel cannot know if you lose information or not so it has to err on the safe side.
I changed it now to only override with panic_timeout == 0, as in the user didn't set anything,
that's probably the most sensible semantics anyways.
-Andi
---
x86: MCE: Default to panic timeout for machine checks v3
Fatal machine checks can be logged to disk after boot, but only if the system did a warm reboot. That's unfortunately difficult with the default panic behaviour, which waits forever and the admin has to press the power button because modern systems usually miss a reset button. This clears the machine checks in the registers and make
it impossible to log them.
This patch changes the default for machine check panic to always reboot after 30s. Then the mce can be successfully logged after reboot.
I believe this will improve machine check experience for any system running the X server.
This is dependent on successfull boot logging of MCEs. This currently only works on Intel systems, on AMD there are quite a lot of systems around which leave junk in the machine check registers after boot, so it's disabled here. These systems will continue to default to endless waiting panic.
v2: Only force panic timeout when it's shorter (H.Seto)
v3: Only panic when there is no earlier timeout or it's not zero (based on comment H.Seto)
--- arch/x86/kernel/cpu/mcheck/mce.c | 7 +++++++ 1 file changed, 7 insertions(+)
arch/x86/kernel/cpu/mcheck/mce.c +7 -0
@@ -82,6 +82,7 @@static int rip_msr;static int mce_bootlog =-1 ;static int monarch_timeout =-1 ; +static int mce_panic_timeout;static char trigger[128 ];static char *trigger_argv[2 ] = { trigger,NULL };
@@ -203,6 +204,8 @@local_irq_enable ();while (timeout-- >0 )udelay (1 ); +if (panic_timeout ==0 ) + panic_timeout = mce_panic_timeout;panic ("Panicing machine check CPU died" ); }
@@ -240,6 +243,8 @@printk (KERN_EMERG "Some CPUs didn't answer in synchronization\n" );if (exp)printk (KERN_EMERG "Machine check: %s\n" , exp); +if (panic_timeout ==0 ) + panic_timeout = mce_panic_timeout;panic (msg); }
@@ -1100,6 +1105,8 @@ }if (monarch_timeout <0 ) monarch_timeout =0 ; +if (mce_bootlog !=0 ) + mce_panic_timeout =30 ; }static void __cpuinit mce_ancient_init (struct cpuinfo_x86 *c)
Signature · 1 line
[email protected] -- Speaking for myself only.
Re: [PATCH] x86: MCE: Fix for mce_panic_timeout
Quoted 10 lines · Andi Kleen
Quoted 3 lines · Hidetoshi Seto
- In case of
panic_timeout> 0 andmce_bootlog== 0.
System should reboot after panic, but it doesn't on mce panic because current mce code overwritepanic_timeoutto 0.Nope, with bootlog==0 it should _not_ automatically reboot on panic. Automatic rebooting makes mainly sense with boot logging, otherwise you will likely lose the information. Or at least the kernel cannot know if you lose information or not so it has to err on the safe side.
Users already know they might lose the information about the panic if panic_timeout > 0. It is same on all kind of panic.
Quoted 3 lines
I changed it now to only override with
panic_timeout== 0, as in the user didn't set anything,
that's probably the most sensible semantics anyways.
It's OK with me.
The logic in this patch also seems good.
But...
Quoted 3 lines
v2: Only force panic timeout when it's shorter (H.Seto)
v3: Only panic when there is no earlier timeout or it's not zero (based on comment H.Seto)
"Only panic when ..." ?
I could not cache the meaning of this changelog.
Thanks,
H.Seto
Re: [PATCH] x86: MCE: Fix for mce_panic_timeout
Quoted 6 lines · Hidetoshi Seto
Quoted 5 lines · Andi Kleen
Quoted 3 lines · Hidetoshi Seto
- In case of
panic_timeout> 0 andmce_bootlog== 0.
System should reboot after panic, but it doesn't on mce panic because current mce code overwritepanic_timeoutto 0.
Quoted 8 lines
Quoted 5 lines
Nope, with bootlog==0 it should _not_ automatically reboot on panic. Automatic rebooting makes mainly sense with boot logging, otherwise you will likely lose the information. Or at least the kernel cannot know if you lose information or not so it has to err on the safe side.
Users already know they might lose the information about the panic if
panic_timeout> 0. It is same on all kind of panic.
Yes if they set panic=..., but they don't expect it by default as this patch does.
Quoted 7 lines
Quoted 4 lines
I changed it now to only override with
panic_timeout== 0, as in the user didn't set anything,
that's probably the most sensible semantics anyways.It's OK with me.
The logic in this patch also seems good.
Thanks.
Quoted 9 lines
But...
Quoted 3 lines
v2: Only force panic timeout when it's shorter (H.Seto)
v3: Only panic when there is no earlier timeout or it's not zero (based on comment H.Seto)"Only panic when ..." ?
I could not cache the meaning of this changelog.
"Only automatically panic ..."
Ok fair enough, if I ever redo a repost I'll update that line, but I hope I don't have to touch this trivial patch anymore.
-Andi
Signature · 1 line
[email protected] -- Speaking for myself only.
Re: [PATCH 06/31] x86: Fix panic with interrupts off (needed for MCE)
In reply to Andi KleenQuoted 14 lines · Andi Kleen
arch/x86/include/asm/irq_vectors.h +1
-5@@ -89,11 +89,7 @@#define THRESHOLD_APIC_VECTOR 0xf9 -#ifdef CONFIG_X86_32 -/* 0xf9 : free */ -#else -# define UV_BAU_MESSAGE 0xf8 -#endif +#define REBOOT_VECTOR 0xf8/* f0-f7 used for spreading out TLB flushes: */ #define INVALIDATE_TLB_VECTOR_END 0xf7
arch/x86/include/asm/irq_vectors.h line 120
Quoted 8 lines
arch/x86/include/asm/irq_vectors.h +2
-0@@ -117,6 +113,8 @@*/ #define GENERIC_INTERRUPT_VECTOR 0xed +#define UV_BAU_MESSAGE 0xec +/* * First APIC vector available to drivers: (vectors 0x30-0xee) we * start at 0x31(0x41) to spread out vectors evenly between priority
#ifdef CONFIG_X86_64
#define UV_BAU_MESSAGE 0xec
#endif
Isn't it?
Thanks,
H.Seto
Re: [PATCH 06/31] x86: Fix panic with interrupts off (needed for MCE)
Quoted 5 lines
#ifdef
CONFIG_X86_64
#defineUV_BAU_MESSAGE0xec
#endifIsn't it?
No, it's not, the ifdef is not needed. I see no point at all in adding that ifdef. It would only help if 32bit wanted to add a vector on its own here which is totally unlikely.
-Andi
Signature · 1 line
[email protected] -- Speaking for myself only.
Re: [PATCH 03/31] x86: MCE: Fix EIPV behaviour with !PCC
In reply to Andi KleenQuoted 18 lines · Andi Kleen
From: Huang Ying <[email protected]>
Impact: Spec compliance
When tolerant == 0, system should go panic instead of send SIGBUS even for a MCE with EPIV && !PCC on user space.
Signed-off-by Huang Ying <[email protected]>Signed-off-by Andi Kleen <[email protected]>--- arch/x86/kernel/cpu/mcheck/mce.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)arch/x86/kernel/cpu/mcheck/mce.c +0
-0
arch/x86/kernel/cpu/mcheck/mce.c void do_machine_check(struct pt_regs *regs, long error_code) · line 491
Quoted 8 lines
arch/x86/kernel/cpu/mcheck/mce.c +1
-1@@ -485,7 +485,7 @@ void do_machine_check(struct pt_regs *regs, long error_code)* force_sig() takes an awful lot of locks and has a slight * risk of deadlocking. */ -if (user_space) { +if (user_space && tolerant >0 ) {force_sig (SIGBUS , current); }else if (panic_on_oops || tolerant <2 ) { mce_panic("Uncorrected machine check",
Again, this patch is useless.
if (m.status & MCI_STATUS_EN) {
/* if PCC was set, there's no way out */
no_way_out |= !!(m.status & MCI_STATUS_PCC);
/*
* If this error was uncorrectable and there was
* an overflow, we're in trouble. If no overflow,
* we might get away with just killing a task.
*/
if (m.status & MCI_STATUS_UC) {
if (tolerant < 1 || m.status & MCI_STATUS_OVER)
no_way_out = 1;
kill_it = 1;
}
} else {
:
if (no_way_out && tolerant < 3)
mce_panic("Machine check", &panicm, mcestart);
:
if (kill_it && tolerant < 3) {
:
if (user_space) {
force_sig(SIGBUS, current);
} else if (panic_on_oops || tolerant < 2) {
mce_panic("Uncorrected machine check",
&panicm, mcestart);
}
}We never reach there with tolerant == 0.
And you will remove this code in your 25/31.
Thanks,
H.Seto
Re: [PATCH 03/31] x86: MCE: Fix EIPV behaviour with !PCC
Quoted 1 line
We never reach there with tolerant == 0.
Fair point. Ying do you remember which test case that fixed?
Quoted 2 lines
And you will remove this code in your 25/31.
I usually kept the earlier patches fixing the code before I remove it, just in case someone drops the later code.
-Andi
Signature · 1 line
[email protected] -- Speaking for myself only.
Re: [PATCH 03/31] x86: MCE: Fix EIPV behaviour with !PCC
Quoted 3 lines · Andi Kleen
Quoted 1 line
We never reach there with tolerant == 0.
Fair point. Ying do you remember which test case that fixed?
I think I fixed a "bug" that does not exist. So I think maybe we should drop this patch. Sorry about that.
Best Regards,
Huang Ying
Re: [PATCH 03/31] x86: MCE: Fix EIPV behaviour with !PCC
Quoted 6 lines · Huang Ying
Quoted 3 lines · Andi Kleen
Quoted 1 line
We never reach there with tolerant == 0.
Fair point. Ying do you remember which test case that fixed?
I think I fixed a "bug" that does not exist. So I think maybe we should
Or maybe not anymore.
Quoted 1 line
drop this patch. Sorry about that.
Okay. I dropped it. Thanks everyone.
-Andi
Signature · 1 line
[email protected] -- Speaking for myself only.
Re: [PATCH 02/31] x86: MCE: Improve mce_get_rip v3
In reply to Andi KleenQuoted 3 lines · Andi Kleen
From: Huang Ying <[email protected]>
Assume RIP is valid when either EIPV or RIPV are set.
Bad description.
If RIP means "restart IP" that is valid only if RIPV is set, this sentence doesn't make sense completely.
Followings will be better:
"Assume IP stored on the stack indicates the address of instruction
at the time of the MCE when either EIPV or RIPV are set."
Quoted 2 lines
This influences
whether the machine check exception handler decides to return or panic.
I suppose you are pointing logics in:
mce_get_rip(&m, regs);
:
panicm = m;
:
/*
* If the EIPV bit is set, it means the saved IP is the
* instruction which caused the MCE.
*/
if (m.mcgstatus & MCG_STATUS_EIPV)
user_space = panicm.ip && (panicm.cs & 3);
/*
* If we know that the error was in user space, send a
* SIGBUS. Otherwise, panic if tolerance is low.
*
* force_sig() takes an awful lot of locks and has a slight
* risk of deadlocking.
*/
if (user_space) {
force_sig(SIGBUS, current);
} else if (panic_on_oops || tolerant < 2) {
mce_panic("Uncorrected machine check",
&panicm, mcestart);
}So EIPV without RIPV will be no ip and will result in panic, while expected result is SIGBUS.
Quoted 2 lines
This fixes a test case in the mce-test suite and is more compliant to the specification.
It would be better to describe about the test case that need this fix.
Quoted 5 lines
This currently only makes a difference in a artificial testing scenario with the mce-test test suite.
Also in addition do not force the RIP to be valid with the exact register MSRs.
I think the forced one is EIP:
arch/x86/kernel/cpu/mcheck/mce.c int mce_available(struct cpuinfo_x86 *c) · line 261
Quoted 1 line
arch/x86/kernel/cpu/mcheck/mce.c +0
-1- m->mcgstatus |=MCG_STATUS_EIPV ;
And please note that it keep use CS on stack even if MSR is available.
I made an alternative patch for this, with no functional change. Please consider replacing.
Thanks,
H.Seto
Quoted 42 lines
[AK: combination of patches from Huang Ying and Hidetoshi Seto, with new description by me]
Signed-off-by Huang Ying <[email protected]>Signed-off-by Andi Kleen <[email protected]>Signed-off-by Hidetoshi Seto <[email protected]>--- arch/x86/kernel/cpu/mcheck/mce.c | 13 +++++++------ 1 files changed, 7 insertions(+), 6 deletions(-)arch/x86/kernel/cpu/mcheck/mce.c +7
-6@@ -247,21 +247,22 @@ int mce_available(struct cpuinfo_x86 *c)return cpu_has (c,X86_FEATURE_MCE ) &&cpu_has (c,X86_FEATURE_MCA ); } +/* +* Get the address of the instruction at the time of the machine check +* error. +*/ static inline void mce_get_rip (struct mce *m,struct pt_regs *regs) { -if (regs && (m->mcgstatus &MCG_STATUS_RIPV )) { + +if (regs && (m->mcgstatus & (MCG_STATUS_RIPV |MCG_STATUS_EIPV ))) { m->ip = regs->ip; m->cs = regs->cs; }else { m->ip =0 ; m->cs =0 ; } -if (rip_msr) { -/* Assume the RIP in the MSR is exact. Is this true? */ - m->mcgstatus |=MCG_STATUS_EIPV ; +if (rip_msr) m->ip =mce_rdmsrl (rip_msr); - m->cs =0 ; - } }/*
Re: [PATCH 02/31] x86: MCE: Improve mce_get_rip v3
Quoted 8 lines · Hidetoshi Seto
Quoted 3 lines · Andi Kleen
From: Huang Ying <[email protected]>
Assume RIP is valid when either EIPV or RIPV are set.
Bad description.
If RIP means "restart IP" that is valid only if RIPV is set, this sentence doesn't make sense completely.
No it doesn't mean restart IP, it just means normal instruction pointer like everywhere else.
Quoted 5 lines
Quoted 3 lines
This influences
whether the machine check exception handler decides to return or panic.I suppose you are pointing logics in:
Yes.
Quoted 26 lines
mce_get_rip(&m, regs);
:
panicm = m;
:
/*
* If the EIPV bit is set, it means the saved IP is the
* instruction which caused the MCE.
*/
if (m.mcgstatus & MCG_STATUS_EIPV)
user_space = panicm.ip && (panicm.cs & 3);
/*
* If we know that the error was in user space, send a
* SIGBUS. Otherwise, panic if tolerance is low.
*
* force_sig() takes an awful lot of locks and has a slight
* risk of deadlocking.
*/
if (user_space) {
force_sig(SIGBUS, current);
} else if (panic_on_oops || tolerant < 2) {
mce_panic("Uncorrected machine check",
&panicm, mcestart);
}Quoted 2 lines
So EIPV without RIPV will be no ip and will result in panic, while expected result is SIGBUS.
First this is only for the !MCA recovery case. In the MCA recovery case we have more information and can decide better.
In this case no EIPV means that the kernel isn't sure where the error occurred so it cannot safely decide if it was user space or kernel space and in the tolerant == 2 case has to panic just in case a kernel kill would cause deadlock.
With MCA recovery this whole this is replaced by a new improved mechanism using the high level handler.
Quoted 6 lines
Quoted 3 lines
Also in addition do not force the RIP to be valid with the exact register MSRs.
I think the forced one is EIP:
arch/x86/kernel/cpu/mcheck/mce.c int mce_available(struct cpuinfo_x86 *c) · line 261
Quoted 1 line
arch/x86/kernel/cpu/mcheck/mce.c +0
-1- m->mcgstatus |=MCG_STATUS_EIPV ;
True. Changed.
Quoted 5 lines
And please note that it keep use CS on stack even if MSR is available.
I made an alternative patch for this, with no functional change. Please consider replacing.
No, sorry I got burned too much last time you touched the description of this simple patch. I think my description is simple and to the point and this patch doesn't really deserve anything more.
-Andi
Signature · 1 line
[email protected] -- Speaking for myself only.
PATCH 1/1 x86: MCE: Fix for getting IP/CS at MCE
In reply to Andi KleenAssume IP stored on the stack indicates the address of instruction at the time of the MCE when either EIPV or RIPV are set. This influences whether the machine check exception handler decides to return or panic.
This fixes an EIPV test case in the mce-test suite and is more compliant to the specification.
This currently only makes a difference in a artificial testing scenario with the mce-test test suite.
Also in addition do not overwrite the EIPV with the presence of MSR, and keep in trust the CS value on stack even if MSR is available.
[AK: combination of patches from Huang Ying and Hidetoshi Seto, with
new description by me]
[HS: change misleading function name, add comment and some description
based on "Improve mce_get_rip v3" ]
--- arch/x86/kernel/cpu/mcheck/mce.c | 21 +++++++++++++-------- 1 files changed, 13 insertions(+), 8 deletions(-)
arch/x86/kernel/cpu/mcheck/mce.c +13 -8
@@ -247,21 +247,26 @@ int mce_available(struct cpuinfo_x86 *c)return cpu_has (c,X86_FEATURE_MCE ) &&cpu_has (c,X86_FEATURE_MCA ); } -static inline void mce_get_rip (struct mce *m,struct pt_regs *regs) +/* +* Get the address of the instruction at the time of the machine check +* error. +*/ +static inline void mce_get_ip_at_error (struct mce *m,struct pt_regs *regs) { -if (regs && (m->mcgstatus &MCG_STATUS_RIPV )) { +/* We can trust IP & CS on stack if either RIPV or EIPV is valid */ +if (regs && (m->mcgstatus & (MCG_STATUS_RIPV |MCG_STATUS_EIPV ))) { m->ip = regs->ip; m->cs = regs->cs; }else { m->ip =0 ; m->cs =0 ; } -if (rip_msr) { -/* Assume the RIP in the MSR is exact. Is this true? */ - m->mcgstatus |=MCG_STATUS_EIPV ; +/* +* Use MSR if available. +* Since there is no MSR for CS, keep in trust it on stack. +*/ +if (rip_msr) m->ip =mce_rdmsrl (rip_msr); - m->cs =0 ; - } }/*
@@ -431,7 +436,7 @@ void do_machine_check(struct pt_regs *regs, long error_code)if (m.status &MCI_STATUS_ADDRV ) m.addr =mce_rdmsrl (MSR_IA32_MC0_ADDR + i*4 ); -mce_get_rip (&m, regs); +mce_get_ip_at_error (&m, regs);mce_log (&m);/*
Signature · 1 line
1.6.3