diff options
author | Andy Lutomirski <luto@kernel.org> | 2016-04-02 10:01:37 -0400 |
---|---|---|
committer | Ingo Molnar <mingo@kernel.org> | 2016-04-13 05:37:45 -0400 |
commit | fbd704374d111bed16a19261176fa30e2379c87c (patch) | |
tree | 8b1de7476a88eae86f76dc929c37e5a129c94e6c | |
parent | c2ee03b2a94d7ba692cf6206bbe069d5bfcc20ed (diff) |
x86/msr: Carry on after a non-"safe" MSR access fails
This demotes an OOPS and likely panic due to a failed non-"safe" MSR
access to a WARN_ONCE() and, for RDMSR, a return value of zero.
To be clear, this type of failure should *not* happen. This patch
exists to minimize the chance of nasty undebuggable failures
happening when a CONFIG_PARAVIRT=y bug in the non-"safe" MSR helpers
gets fixed.
Tested-by: Boris Ostrovsky <boris.ostrovsky@oracle.com>
Signed-off-by: Andy Lutomirski <luto@kernel.org>
Acked-by: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Arjan van de Ven <arjan@linux.intel.com>
Cc: Borislav Petkov <bp@alien8.de>
Cc: KVM list <kvm@vger.kernel.org>
Cc: Paolo Bonzini <pbonzini@redhat.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: xen-devel <Xen-devel@lists.xen.org>
Link: http://lkml.kernel.org/r/26567b216aae70e795938f4b567eace5a0eb90ba.1459605520.git.luto@kernel.org
Signed-off-by: Ingo Molnar <mingo@kernel.org>
-rw-r--r-- | arch/x86/include/asm/msr.h | 10 | ||||
-rw-r--r-- | arch/x86/mm/extable.c | 27 |
2 files changed, 35 insertions, 2 deletions
diff --git a/arch/x86/include/asm/msr.h b/arch/x86/include/asm/msr.h index 7a79ee2778b3..25f169c6eb95 100644 --- a/arch/x86/include/asm/msr.h +++ b/arch/x86/include/asm/msr.h | |||
@@ -84,7 +84,10 @@ static inline unsigned long long native_read_msr(unsigned int msr) | |||
84 | { | 84 | { |
85 | DECLARE_ARGS(val, low, high); | 85 | DECLARE_ARGS(val, low, high); |
86 | 86 | ||
87 | asm volatile("rdmsr" : EAX_EDX_RET(val, low, high) : "c" (msr)); | 87 | asm volatile("1: rdmsr\n" |
88 | "2:\n" | ||
89 | _ASM_EXTABLE_HANDLE(1b, 2b, ex_handler_rdmsr_unsafe) | ||
90 | : EAX_EDX_RET(val, low, high) : "c" (msr)); | ||
88 | if (msr_tracepoint_active(__tracepoint_read_msr)) | 91 | if (msr_tracepoint_active(__tracepoint_read_msr)) |
89 | do_trace_read_msr(msr, EAX_EDX_VAL(val, low, high), 0); | 92 | do_trace_read_msr(msr, EAX_EDX_VAL(val, low, high), 0); |
90 | return EAX_EDX_VAL(val, low, high); | 93 | return EAX_EDX_VAL(val, low, high); |
@@ -111,7 +114,10 @@ static inline unsigned long long native_read_msr_safe(unsigned int msr, | |||
111 | static inline void native_write_msr(unsigned int msr, | 114 | static inline void native_write_msr(unsigned int msr, |
112 | unsigned low, unsigned high) | 115 | unsigned low, unsigned high) |
113 | { | 116 | { |
114 | asm volatile("wrmsr" : : "c" (msr), "a"(low), "d" (high) : "memory"); | 117 | asm volatile("1: wrmsr\n" |
118 | "2:\n" | ||
119 | _ASM_EXTABLE_HANDLE(1b, 2b, ex_handler_wrmsr_unsafe) | ||
120 | : : "c" (msr), "a"(low), "d" (high) : "memory"); | ||
115 | if (msr_tracepoint_active(__tracepoint_read_msr)) | 121 | if (msr_tracepoint_active(__tracepoint_read_msr)) |
116 | do_trace_write_msr(msr, ((u64)high << 32 | low), 0); | 122 | do_trace_write_msr(msr, ((u64)high << 32 | low), 0); |
117 | } | 123 | } |
diff --git a/arch/x86/mm/extable.c b/arch/x86/mm/extable.c index 061a23758354..fd9eb98c4f58 100644 --- a/arch/x86/mm/extable.c +++ b/arch/x86/mm/extable.c | |||
@@ -43,6 +43,33 @@ bool ex_handler_ext(const struct exception_table_entry *fixup, | |||
43 | } | 43 | } |
44 | EXPORT_SYMBOL(ex_handler_ext); | 44 | EXPORT_SYMBOL(ex_handler_ext); |
45 | 45 | ||
46 | bool ex_handler_rdmsr_unsafe(const struct exception_table_entry *fixup, | ||
47 | struct pt_regs *regs, int trapnr) | ||
48 | { | ||
49 | WARN_ONCE(1, "unchecked MSR access error: RDMSR from 0x%x\n", | ||
50 | (unsigned int)regs->cx); | ||
51 | |||
52 | /* Pretend that the read succeeded and returned 0. */ | ||
53 | regs->ip = ex_fixup_addr(fixup); | ||
54 | regs->ax = 0; | ||
55 | regs->dx = 0; | ||
56 | return true; | ||
57 | } | ||
58 | EXPORT_SYMBOL(ex_handler_rdmsr_unsafe); | ||
59 | |||
60 | bool ex_handler_wrmsr_unsafe(const struct exception_table_entry *fixup, | ||
61 | struct pt_regs *regs, int trapnr) | ||
62 | { | ||
63 | WARN_ONCE(1, "unchecked MSR access error: WRMSR to 0x%x (tried to write 0x%08x%08x)\n", | ||
64 | (unsigned int)regs->cx, | ||
65 | (unsigned int)regs->dx, (unsigned int)regs->ax); | ||
66 | |||
67 | /* Pretend that the write succeeded. */ | ||
68 | regs->ip = ex_fixup_addr(fixup); | ||
69 | return true; | ||
70 | } | ||
71 | EXPORT_SYMBOL(ex_handler_wrmsr_unsafe); | ||
72 | |||
46 | bool ex_has_fault_handler(unsigned long ip) | 73 | bool ex_has_fault_handler(unsigned long ip) |
47 | { | 74 | { |
48 | const struct exception_table_entry *e; | 75 | const struct exception_table_entry *e; |