x86_64: support poll() on /dev/mcelog (try #3) (resend)
PATCH 1/1 x86_64: support poll() on /dev/mcelog (try #3) (resend)
From: Tim Hockin <[email protected]>
Background:
/dev/mcelog is typically polled manually. This is less than optimal for situations where accurate accounting of MCEs is important. Calling poll() on /dev/mcelog does not work.
Description:
This patch adds support for poll() to /dev/mcelog. This results in immediate wakeup of user apps whenever the poller finds MCEs. Because the exception handler can not take any locks, it can not call the wakeup itself. Instead, it uses a thread_info flag (TIF_MCE_NOTIFY) which is caught at the next return from interrupt or exit from idle, calling the mce_user_notify() routine. This patch also disables the "fake panic" path of the mce_panic(), because it results in printk()s in the exception handler and crashy systems.
This patch also does some small cleanup for essentially unused variables, and moves the user notification into the body of the poller, so it is only called once per poll, rather than once per CPU.
Result:
Applications can now poll() on /dev/mcelog. When an error is logged (whether through the poller or through an exception) the applications are woken up promptly. This should not affect any previous behaviors. If no MCEs are being logged, there is no overhead.
Alternatives:
I considered simply supporting poll() through the poller and not using TIF_MCE_NOTIFY at all. However, the time between an uncorrectable error happening and the user application being notified is *the*most* critical window for us. Many uncorrectable errors can be logged to the network if given a chance.
I also considered doing the MCE poll directly from the idle notifier, but decided that was overkill.
Testing:
I used an error-injecting DIMM to create lots of correctable DRAM errors and verified that my user app is woken up in sync with the polling interval. I also used the northbridge to inject uncorrectable ECC errors, and verified (printk() to the rescue) that the notify routine is called and the user app does wake up. I built with PREEMPT on and off, and verified that my machine survives MCEs.
Patch:
This patch is against 2.6.21.
---
This is the third version version of this patch. The TIF_* approach was suggested by Mike Waychison and Andi did not yell at me when I suggested it. Hooking the idle notifier was born of an Andrew Morton suggestion and, no surprise, seems to work well.
arch/x86_64/kernel/entry.S +3 -3
@@ -282,7 +282,7 @@ sysret_careful: sysret_signal: TRACE_IRQS_ON sti - testl $(_TIF_SIGPENDING|_TIF_NOTIFY_RESUME|_TIF_SINGLESTEP),%edx + testl $(_TIF_SIGPENDING|_TIF_NOTIFY_RESUME|_TIF_SINGLESTEP|_TIF_MCE_NOTIFY),%edx jz 1f /* Really a signal */
@@ -375,7 +375,7 @@ int_very_careful: jmp int_restore_rest int_signal: - testl $(_TIF_NOTIFY_RESUME|_TIF_SIGPENDING|_TIF_SINGLESTEP),%edx + testl $(_TIF_NOTIFY_RESUME|_TIF_SIGPENDING|_TIF_SINGLESTEP|_TIF_MCE_NOTIFY),%edx jz 1f movq %rsp,%rdi # &ptregs -> arg1 xorl %esi,%esi # oldset -> arg2
@@ -599,7 +599,7 @@ retint_careful: jmp retint_check retint_signal: - testl $(_TIF_SIGPENDING|_TIF_NOTIFY_RESUME|_TIF_SINGLESTEP),%edx + testl $(_TIF_SIGPENDING|_TIF_NOTIFY_RESUME|_TIF_SINGLESTEP|_TIF_MCE_NOTIFY),%edx jz retint_swapgs TRACE_IRQS_ON sti
arch/x86_64/kernel/mce.c +67 -37
201 lines not on this page · raw message
arch/x86_64/kernel/signal.c +5 -0
@@ -27,6 +27,7 @@#include <asm/i387.h> #include <asm/proto.h> #include <asm/ia32_unistd.h> +#include <asm/mce.h> /* #define DEBUG_SIG 1 */
@@ -473,6 +474,10 @@ do_notify_resume(struct pt_regs *regs, vclear_thread_flag (TIF_SINGLESTEP ); } +/* notify userspace of pending MCEs */ +if (thread_info_flags & _TIF_MCE_NOTIFY) +mce_notify_user (); +/* deal with pending signal delivery */ if (thread_info_flags & (_TIF_SIGPENDING|_TIF_RESTORE_SIGMASK))do_signal (regs);
include/asm-x86_64/mce.h +2 -0
@@ -105,6 +105,8 @@ extern atomic_t mce_entry;extern void do_machine_check (struct pt_regs *,long ); +extern int mce_notify_user (void ); +#endif #endif
include/asm-x86_64/thread_info.h +2 -0
@@ -115,6 +115,7 @@ static inline struct thread_info *stack_#define TIF_SYSCALL_AUDIT 7/* syscall auditing active */ #define TIF_SECCOMP 8/* secure computing */ #define TIF_RESTORE_SIGMASK 9/* restore signal mask in do_signal */ +#define TIF_MCE_NOTIFY 10/* notify userspace of an MCE */ /* 16 free */ #define TIF_IA32 17/* 32bit process */ #define TIF_FORK 18/* ret_from_fork */
@@ -133,6 +134,7 @@ static inline struct thread_info *stack_#define _TIF_SYSCALL_AUDIT (1<<TIF_SYSCALL_AUDIT)#define _TIF_SECCOMP (1<<TIF_SECCOMP)#define _TIF_RESTORE_SIGMASK (1<<TIF_RESTORE_SIGMASK) +#define _TIF_MCE_NOTIFY (1<<TIF_MCE_NOTIFY)#define _TIF_IA32 (1<<TIF_IA32)#define _TIF_FORK (1<<TIF_FORK)#define _TIF_ABI_PENDING (1<<TIF_ABI_PENDING)