Skip to content

Commit ca1b669

Browse files
committed
Merge tag 'ras_updates_for_v5.10' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip
Pull RAS updates from Borislav Petkov: - Extend the recovery from MCE in kernel space also to processes which encounter an MCE in kernel space but while copying from user memory by sending them a SIGBUS on return to user space and umapping the faulty memory, by Tony Luck and Youquan Song. - memcpy_mcsafe() rework by splitting the functionality into copy_mc_to_user() and copy_mc_to_kernel(). This, as a result, enables support for new hardware which can recover from a machine check encountered during a fast string copy and makes that the default and lets the older hardware which does not support that advance recovery, opt in to use the old, fragile, slow variant, by Dan Williams. - New AMD hw enablement, by Yazen Ghannam and Akshay Gupta. - Do not use MSR-tracing accessors in #MC context and flag any fault while accessing MCA architectural MSRs as an architectural violation with the hope that such hw/fw misdesigns are caught early during the hw eval phase and they don't make it into production. - Misc fixes, improvements and cleanups, as always. * tag 'ras_updates_for_v5.10' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: x86/mce: Allow for copy_mc_fragile symbol checksum to be generated x86/mce: Decode a kernel instruction to determine if it is copying from user x86/mce: Recover from poison found while copying from user space x86/mce: Avoid tail copy when machine check terminated a copy from user x86/mce: Add _ASM_EXTABLE_CPY for copy user access x86/mce: Provide method to find out the type of an exception handler x86/mce: Pass pointer to saved pt_regs to severity calculation routines x86/copy_mc: Introduce copy_mc_enhanced_fast_string() x86, powerpc: Rename memcpy_mcsafe() to copy_mc_to_{user, kernel}() x86/mce: Drop AMD-specific "DEFERRED" case from Intel severity rule list x86/mce: Add Skylake quirk for patrol scrub reported errors RAS/CEC: Convert to DEFINE_SHOW_ATTRIBUTE() x86/mce: Annotate mce_rd/wrmsrl() with noinstr x86/mce/dev-mcelog: Do not update kflags on AMD systems x86/mce: Stop mce_reign() from re-computing severity for every CPU x86/mce: Make mce_rdmsrl() panic on an inaccessible MSR x86/mce: Increase maximum number of banks to 64 x86/mce: Delay clearing IA32_MCG_STATUS to the end of do_machine_check() x86/MCE/AMD, EDAC/mce_amd: Remove struct smca_hwid.xec_bitmap RAS/CEC: Fix cec_init() prototype
2 parents a9a4b7d + b3149ff commit ca1b669

52 files changed

Lines changed: 866 additions & 697 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

arch/powerpc/Kconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ config PPC
135135
select ARCH_HAS_STRICT_KERNEL_RWX if (PPC32 && !HIBERNATION)
136136
select ARCH_HAS_TICK_BROADCAST if GENERIC_CLOCKEVENTS_BROADCAST
137137
select ARCH_HAS_UACCESS_FLUSHCACHE
138-
select ARCH_HAS_UACCESS_MCSAFE if PPC64
138+
select ARCH_HAS_COPY_MC if PPC64
139139
select ARCH_HAS_UBSAN_SANITIZE_ALL
140140
select ARCH_HAVE_NMI_SAFE_CMPXCHG
141141
select ARCH_KEEP_MEMBLOCK

arch/powerpc/include/asm/string.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,7 @@ void *__memmove(void *to, const void *from, __kernel_size_t n);
5353
#ifndef CONFIG_KASAN
5454
#define __HAVE_ARCH_MEMSET32
5555
#define __HAVE_ARCH_MEMSET64
56-
#define __HAVE_ARCH_MEMCPY_MCSAFE
5756

58-
extern int memcpy_mcsafe(void *dst, const void *src, __kernel_size_t sz);
5957
extern void *__memset16(uint16_t *, uint16_t v, __kernel_size_t);
6058
extern void *__memset32(uint32_t *, uint32_t v, __kernel_size_t);
6159
extern void *__memset64(uint64_t *, uint64_t v, __kernel_size_t);

arch/powerpc/include/asm/uaccess.h

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -435,6 +435,32 @@ do { \
435435
extern unsigned long __copy_tofrom_user(void __user *to,
436436
const void __user *from, unsigned long size);
437437

438+
#ifdef CONFIG_ARCH_HAS_COPY_MC
439+
unsigned long __must_check
440+
copy_mc_generic(void *to, const void *from, unsigned long size);
441+
442+
static inline unsigned long __must_check
443+
copy_mc_to_kernel(void *to, const void *from, unsigned long size)
444+
{
445+
return copy_mc_generic(to, from, size);
446+
}
447+
#define copy_mc_to_kernel copy_mc_to_kernel
448+
449+
static inline unsigned long __must_check
450+
copy_mc_to_user(void __user *to, const void *from, unsigned long n)
451+
{
452+
if (likely(check_copy_size(from, n, true))) {
453+
if (access_ok(to, n)) {
454+
allow_write_to_user(to, n);
455+
n = copy_mc_generic((void *)to, from, n);
456+
prevent_write_to_user(to, n);
457+
}
458+
}
459+
460+
return n;
461+
}
462+
#endif
463+
438464
#ifdef __powerpc64__
439465
static inline unsigned long
440466
raw_copy_in_user(void __user *to, const void __user *from, unsigned long n)
@@ -523,20 +549,6 @@ raw_copy_to_user(void __user *to, const void *from, unsigned long n)
523549
return ret;
524550
}
525551

526-
static __always_inline unsigned long __must_check
527-
copy_to_user_mcsafe(void __user *to, const void *from, unsigned long n)
528-
{
529-
if (likely(check_copy_size(from, n, true))) {
530-
if (access_ok(to, n)) {
531-
allow_write_to_user(to, n);
532-
n = memcpy_mcsafe((void *)to, from, n);
533-
prevent_write_to_user(to, n);
534-
}
535-
}
536-
537-
return n;
538-
}
539-
540552
unsigned long __arch_clear_user(void __user *addr, unsigned long size);
541553

542554
static inline unsigned long clear_user(void __user *addr, unsigned long size)

arch/powerpc/lib/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ obj-$(CONFIG_PPC_BOOK3S_64) += copyuser_power7.o copypage_power7.o \
3939
memcpy_power7.o
4040

4141
obj64-y += copypage_64.o copyuser_64.o mem_64.o hweight_64.o \
42-
memcpy_64.o memcpy_mcsafe_64.o
42+
memcpy_64.o copy_mc_64.o
4343

4444
ifndef CONFIG_PPC_QUEUED_SPINLOCKS
4545
obj64-$(CONFIG_SMP) += locks.o
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ err3; stb r0,0(r3)
5050
blr
5151

5252

53-
_GLOBAL(memcpy_mcsafe)
53+
_GLOBAL(copy_mc_generic)
5454
mr r7,r5
5555
cmpldi r5,16
5656
blt .Lshort_copy
@@ -239,4 +239,4 @@ err1; stb r0,0(r3)
239239
15: li r3,0
240240
blr
241241

242-
EXPORT_SYMBOL_GPL(memcpy_mcsafe);
242+
EXPORT_SYMBOL_GPL(copy_mc_generic);

arch/x86/Kconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ config X86
7575
select ARCH_HAS_PTE_DEVMAP if X86_64
7676
select ARCH_HAS_PTE_SPECIAL
7777
select ARCH_HAS_UACCESS_FLUSHCACHE if X86_64
78-
select ARCH_HAS_UACCESS_MCSAFE if X86_64 && X86_MCE
78+
select ARCH_HAS_COPY_MC if X86_64
7979
select ARCH_HAS_SET_MEMORY
8080
select ARCH_HAS_SET_DIRECT_MAP
8181
select ARCH_HAS_STRICT_KERNEL_RWX

arch/x86/Kconfig.debug

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ config EARLY_PRINTK_USB_XDBC
6262
You should normally say N here, unless you want to debug early
6363
crashes or need a very simple printk logging facility.
6464

65-
config MCSAFE_TEST
65+
config COPY_MC_TEST
6666
def_bool n
6767

6868
config EFI_PGT_DUMP

arch/x86/include/asm/asm-prototypes.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include <asm/string.h>
66
#include <asm/page.h>
77
#include <asm/checksum.h>
8+
#include <asm/mce.h>
89

910
#include <asm-generic/asm-prototypes.h>
1011

arch/x86/include/asm/asm.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,9 @@
135135
# define _ASM_EXTABLE_UA(from, to) \
136136
_ASM_EXTABLE_HANDLE(from, to, ex_handler_uaccess)
137137

138+
# define _ASM_EXTABLE_CPY(from, to) \
139+
_ASM_EXTABLE_HANDLE(from, to, ex_handler_copy)
140+
138141
# define _ASM_EXTABLE_FAULT(from, to) \
139142
_ASM_EXTABLE_HANDLE(from, to, ex_handler_fault)
140143

@@ -160,6 +163,9 @@
160163
# define _ASM_EXTABLE_UA(from, to) \
161164
_ASM_EXTABLE_HANDLE(from, to, ex_handler_uaccess)
162165

166+
# define _ASM_EXTABLE_CPY(from, to) \
167+
_ASM_EXTABLE_HANDLE(from, to, ex_handler_copy)
168+
163169
# define _ASM_EXTABLE_FAULT(from, to) \
164170
_ASM_EXTABLE_HANDLE(from, to, ex_handler_fault)
165171

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
/* SPDX-License-Identifier: GPL-2.0 */
2+
#ifndef _COPY_MC_TEST_H_
3+
#define _COPY_MC_TEST_H_
4+
5+
#ifndef __ASSEMBLY__
6+
#ifdef CONFIG_COPY_MC_TEST
7+
extern unsigned long copy_mc_test_src;
8+
extern unsigned long copy_mc_test_dst;
9+
10+
static inline void copy_mc_inject_src(void *addr)
11+
{
12+
if (addr)
13+
copy_mc_test_src = (unsigned long) addr;
14+
else
15+
copy_mc_test_src = ~0UL;
16+
}
17+
18+
static inline void copy_mc_inject_dst(void *addr)
19+
{
20+
if (addr)
21+
copy_mc_test_dst = (unsigned long) addr;
22+
else
23+
copy_mc_test_dst = ~0UL;
24+
}
25+
#else /* CONFIG_COPY_MC_TEST */
26+
static inline void copy_mc_inject_src(void *addr)
27+
{
28+
}
29+
30+
static inline void copy_mc_inject_dst(void *addr)
31+
{
32+
}
33+
#endif /* CONFIG_COPY_MC_TEST */
34+
35+
#else /* __ASSEMBLY__ */
36+
#include <asm/export.h>
37+
38+
#ifdef CONFIG_COPY_MC_TEST
39+
.macro COPY_MC_TEST_CTL
40+
.pushsection .data
41+
.align 8
42+
.globl copy_mc_test_src
43+
copy_mc_test_src:
44+
.quad 0
45+
EXPORT_SYMBOL_GPL(copy_mc_test_src)
46+
.globl copy_mc_test_dst
47+
copy_mc_test_dst:
48+
.quad 0
49+
EXPORT_SYMBOL_GPL(copy_mc_test_dst)
50+
.popsection
51+
.endm
52+
53+
.macro COPY_MC_TEST_SRC reg count target
54+
leaq \count(\reg), %r9
55+
cmp copy_mc_test_src, %r9
56+
ja \target
57+
.endm
58+
59+
.macro COPY_MC_TEST_DST reg count target
60+
leaq \count(\reg), %r9
61+
cmp copy_mc_test_dst, %r9
62+
ja \target
63+
.endm
64+
#else
65+
.macro COPY_MC_TEST_CTL
66+
.endm
67+
68+
.macro COPY_MC_TEST_SRC reg count target
69+
.endm
70+
71+
.macro COPY_MC_TEST_DST reg count target
72+
.endm
73+
#endif /* CONFIG_COPY_MC_TEST */
74+
#endif /* __ASSEMBLY__ */
75+
#endif /* _COPY_MC_TEST_H_ */

0 commit comments

Comments
 (0)