Skip to content

Commit c653667

Browse files
committed
Merge tag 'x86_core_for_v5.13' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip
Pull x86 updates from Borislav Petkov: - Turn the stack canary into a normal __percpu variable on 32-bit which gets rid of the LAZY_GS stuff and a lot of code. - Add an insn_decode() API which all users of the instruction decoder should preferrably use. Its goal is to keep the details of the instruction decoder away from its users and simplify and streamline how one decodes insns in the kernel. Convert its users to it. - kprobes improvements and fixes - Set the maximum DIE per package variable on Hygon - Rip out the dynamic NOP selection and simplify all the machinery around selecting NOPs. Use the simplified NOPs in objtool now too. - Add Xeon Sapphire Rapids to list of CPUs that support PPIN - Simplify the retpolines by folding the entire thing into an alternative now that objtool can handle alternatives with stack ops. Then, have objtool rewrite the call to the retpoline with the alternative which then will get patched at boot time. - Document Intel uarch per models in intel-family.h - Make Sub-NUMA Clustering topology the default and Cluster-on-Die the exception on Intel. * tag 'x86_core_for_v5.13' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: (53 commits) x86, sched: Treat Intel SNC topology as default, COD as exception x86/cpu: Comment Skylake server stepping too x86/cpu: Resort and comment Intel models objtool/x86: Rewrite retpoline thunk calls objtool: Skip magical retpoline .altinstr_replacement objtool: Cache instruction relocs objtool: Keep track of retpoline call sites objtool: Add elf_create_undef_symbol() objtool: Extract elf_symbol_add() objtool: Extract elf_strtab_concat() objtool: Create reloc sections implicitly objtool: Add elf_create_reloc() helper objtool: Rework the elf_rebuild_reloc_section() logic objtool: Fix static_call list generation objtool: Handle per arch retpoline naming objtool: Correctly handle retpoline thunk calls x86/retpoline: Simplify retpolines x86/alternatives: Optimize optimize_nops() x86: Add insn_decode_kernel() x86/kprobes: Move 'inline' to the beginning of the kprobe_is_ss() declaration ...
2 parents e7c6e40 + 2c88d45 commit c653667

Some content is hidden

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

78 files changed

+1918
-1432
lines changed

arch/x86/Kconfig

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -361,10 +361,6 @@ config X86_64_SMP
361361
def_bool y
362362
depends on X86_64 && SMP
363363

364-
config X86_32_LAZY_GS
365-
def_bool y
366-
depends on X86_32 && !STACKPROTECTOR
367-
368364
config ARCH_SUPPORTS_UPROBES
369365
def_bool y
370366

@@ -387,7 +383,8 @@ config CC_HAS_SANE_STACKPROTECTOR
387383
default $(success,$(srctree)/scripts/gcc-x86_32-has-stack-protector.sh $(CC))
388384
help
389385
We have to make sure stack protector is unconditionally disabled if
390-
the compiler produces broken code.
386+
the compiler produces broken code or if it does not let us control
387+
the segment on 32-bit kernels.
391388

392389
menu "Processor type and features"
393390

arch/x86/Makefile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,14 @@ ifeq ($(CONFIG_X86_32),y)
8080

8181
# temporary until string.h is fixed
8282
KBUILD_CFLAGS += -ffreestanding
83+
84+
ifeq ($(CONFIG_STACKPROTECTOR),y)
85+
ifeq ($(CONFIG_SMP),y)
86+
KBUILD_CFLAGS += -mstack-protector-guard-reg=fs -mstack-protector-guard-symbol=__stack_chk_guard
87+
else
88+
KBUILD_CFLAGS += -mstack-protector-guard=global
89+
endif
90+
endif
8391
else
8492
BITS := 64
8593
UTS_MACHINE := x86_64

arch/x86/boot/compressed/sev-es.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -78,16 +78,15 @@ static inline void sev_es_wr_ghcb_msr(u64 val)
7878
static enum es_result vc_decode_insn(struct es_em_ctxt *ctxt)
7979
{
8080
char buffer[MAX_INSN_SIZE];
81-
enum es_result ret;
81+
int ret;
8282

8383
memcpy(buffer, (unsigned char *)ctxt->regs->ip, MAX_INSN_SIZE);
8484

85-
insn_init(&ctxt->insn, buffer, MAX_INSN_SIZE, 1);
86-
insn_get_length(&ctxt->insn);
85+
ret = insn_decode(&ctxt->insn, buffer, MAX_INSN_SIZE, INSN_MODE_64);
86+
if (ret < 0)
87+
return ES_DECODE_FAILED;
8788

88-
ret = ctxt->insn.immediate.got ? ES_OK : ES_DECODE_FAILED;
89-
90-
return ret;
89+
return ES_OK;
9190
}
9291

9392
static enum es_result vc_write_mem(struct es_em_ctxt *ctxt,

arch/x86/entry/entry_32.S

Lines changed: 4 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
* 1C(%esp) - %ds
2121
* 20(%esp) - %es
2222
* 24(%esp) - %fs
23-
* 28(%esp) - %gs saved iff !CONFIG_X86_32_LAZY_GS
23+
* 28(%esp) - unused -- was %gs on old stackprotector kernels
2424
* 2C(%esp) - orig_eax
2525
* 30(%esp) - %eip
2626
* 34(%esp) - %cs
@@ -53,83 +53,6 @@
5353

5454
#define PTI_SWITCH_MASK (1 << PAGE_SHIFT)
5555

56-
/*
57-
* User gs save/restore
58-
*
59-
* %gs is used for userland TLS and kernel only uses it for stack
60-
* canary which is required to be at %gs:20 by gcc. Read the comment
61-
* at the top of stackprotector.h for more info.
62-
*
63-
* Local labels 98 and 99 are used.
64-
*/
65-
#ifdef CONFIG_X86_32_LAZY_GS
66-
67-
/* unfortunately push/pop can't be no-op */
68-
.macro PUSH_GS
69-
pushl $0
70-
.endm
71-
.macro POP_GS pop=0
72-
addl $(4 + \pop), %esp
73-
.endm
74-
.macro POP_GS_EX
75-
.endm
76-
77-
/* all the rest are no-op */
78-
.macro PTGS_TO_GS
79-
.endm
80-
.macro PTGS_TO_GS_EX
81-
.endm
82-
.macro GS_TO_REG reg
83-
.endm
84-
.macro REG_TO_PTGS reg
85-
.endm
86-
.macro SET_KERNEL_GS reg
87-
.endm
88-
89-
#else /* CONFIG_X86_32_LAZY_GS */
90-
91-
.macro PUSH_GS
92-
pushl %gs
93-
.endm
94-
95-
.macro POP_GS pop=0
96-
98: popl %gs
97-
.if \pop <> 0
98-
add $\pop, %esp
99-
.endif
100-
.endm
101-
.macro POP_GS_EX
102-
.pushsection .fixup, "ax"
103-
99: movl $0, (%esp)
104-
jmp 98b
105-
.popsection
106-
_ASM_EXTABLE(98b, 99b)
107-
.endm
108-
109-
.macro PTGS_TO_GS
110-
98: mov PT_GS(%esp), %gs
111-
.endm
112-
.macro PTGS_TO_GS_EX
113-
.pushsection .fixup, "ax"
114-
99: movl $0, PT_GS(%esp)
115-
jmp 98b
116-
.popsection
117-
_ASM_EXTABLE(98b, 99b)
118-
.endm
119-
120-
.macro GS_TO_REG reg
121-
movl %gs, \reg
122-
.endm
123-
.macro REG_TO_PTGS reg
124-
movl \reg, PT_GS(%esp)
125-
.endm
126-
.macro SET_KERNEL_GS reg
127-
movl $(__KERNEL_STACK_CANARY), \reg
128-
movl \reg, %gs
129-
.endm
130-
131-
#endif /* CONFIG_X86_32_LAZY_GS */
132-
13356
/* Unconditionally switch to user cr3 */
13457
.macro SWITCH_TO_USER_CR3 scratch_reg:req
13558
ALTERNATIVE "jmp .Lend_\@", "", X86_FEATURE_PTI
@@ -282,7 +205,7 @@
282205
.macro SAVE_ALL pt_regs_ax=%eax switch_stacks=0 skip_gs=0 unwind_espfix=0
283206
cld
284207
.if \skip_gs == 0
285-
PUSH_GS
208+
pushl $0
286209
.endif
287210
pushl %fs
288211

@@ -307,9 +230,6 @@
307230
movl $(__USER_DS), %edx
308231
movl %edx, %ds
309232
movl %edx, %es
310-
.if \skip_gs == 0
311-
SET_KERNEL_GS %edx
312-
.endif
313233
/* Switch to kernel stack if necessary */
314234
.if \switch_stacks > 0
315235
SWITCH_TO_KERNEL_STACK
@@ -348,7 +268,7 @@
348268
1: popl %ds
349269
2: popl %es
350270
3: popl %fs
351-
POP_GS \pop
271+
addl $(4 + \pop), %esp /* pop the unused "gs" slot */
352272
IRET_FRAME
353273
.pushsection .fixup, "ax"
354274
4: movl $0, (%esp)
@@ -361,7 +281,6 @@
361281
_ASM_EXTABLE(1b, 4b)
362282
_ASM_EXTABLE(2b, 5b)
363283
_ASM_EXTABLE(3b, 6b)
364-
POP_GS_EX
365284
.endm
366285

367286
.macro RESTORE_ALL_NMI cr3_reg:req pop=0
@@ -779,7 +698,7 @@ SYM_CODE_START(__switch_to_asm)
779698

780699
#ifdef CONFIG_STACKPROTECTOR
781700
movl TASK_stack_canary(%edx), %ebx
782-
movl %ebx, PER_CPU_VAR(stack_canary)+stack_canary_offset
701+
movl %ebx, PER_CPU_VAR(__stack_chk_guard)
783702
#endif
784703

785704
#ifdef CONFIG_RETPOLINE
@@ -976,7 +895,6 @@ SYM_FUNC_START(entry_SYSENTER_32)
976895
movl PT_EIP(%esp), %edx /* pt_regs->ip */
977896
movl PT_OLDESP(%esp), %ecx /* pt_regs->sp */
978897
1: mov PT_FS(%esp), %fs
979-
PTGS_TO_GS
980898

981899
popl %ebx /* pt_regs->bx */
982900
addl $2*4, %esp /* skip pt_regs->cx and pt_regs->dx */
@@ -1012,7 +930,6 @@ SYM_FUNC_START(entry_SYSENTER_32)
1012930
jmp 1b
1013931
.popsection
1014932
_ASM_EXTABLE(1b, 2b)
1015-
PTGS_TO_GS_EX
1016933

1017934
.Lsysenter_fix_flags:
1018935
pushl $X86_EFLAGS_FIXED
@@ -1154,11 +1071,7 @@ SYM_CODE_START_LOCAL_NOALIGN(handle_exception)
11541071
SAVE_ALL switch_stacks=1 skip_gs=1 unwind_espfix=1
11551072
ENCODE_FRAME_POINTER
11561073

1157-
/* fixup %gs */
1158-
GS_TO_REG %ecx
11591074
movl PT_GS(%esp), %edi # get the function address
1160-
REG_TO_PTGS %ecx
1161-
SET_KERNEL_GS %ecx
11621075

11631076
/* fixup orig %eax */
11641077
movl PT_ORIG_EAX(%esp), %edx # get the error code

arch/x86/events/intel/ds.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1353,14 +1353,13 @@ static int intel_pmu_pebs_fixup_ip(struct pt_regs *regs)
13531353
is_64bit = kernel_ip(to) || any_64bit_mode(regs);
13541354
#endif
13551355
insn_init(&insn, kaddr, size, is_64bit);
1356-
insn_get_length(&insn);
1356+
13571357
/*
1358-
* Make sure there was not a problem decoding the
1359-
* instruction and getting the length. This is
1360-
* doubly important because we have an infinite
1361-
* loop if insn.length=0.
1358+
* Make sure there was not a problem decoding the instruction.
1359+
* This is doubly important because we have an infinite loop if
1360+
* insn.length=0.
13621361
*/
1363-
if (!insn.length)
1362+
if (insn_get_length(&insn))
13641363
break;
13651364

13661365
to += insn.length;

arch/x86/events/intel/lbr.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1224,8 +1224,7 @@ static int branch_type(unsigned long from, unsigned long to, int abort)
12241224
is64 = kernel_ip((unsigned long)addr) || any_64bit_mode(current_pt_regs());
12251225
#endif
12261226
insn_init(&insn, addr, bytes_read, is64);
1227-
insn_get_opcode(&insn);
1228-
if (!insn.opcode.got)
1227+
if (insn_get_opcode(&insn))
12291228
return X86_BR_ABORT;
12301229

12311230
switch (insn.opcode.bytes[0]) {
@@ -1262,8 +1261,7 @@ static int branch_type(unsigned long from, unsigned long to, int abort)
12621261
ret = X86_BR_INT;
12631262
break;
12641263
case 0xe8: /* call near rel */
1265-
insn_get_immediate(&insn);
1266-
if (insn.immediate1.value == 0) {
1264+
if (insn_get_immediate(&insn) || insn.immediate1.value == 0) {
12671265
/* zero length call */
12681266
ret = X86_BR_ZERO_CALL;
12691267
break;
@@ -1279,7 +1277,9 @@ static int branch_type(unsigned long from, unsigned long to, int abort)
12791277
ret = X86_BR_JMP;
12801278
break;
12811279
case 0xff: /* call near absolute, call far absolute ind */
1282-
insn_get_modrm(&insn);
1280+
if (insn_get_modrm(&insn))
1281+
return X86_BR_ABORT;
1282+
12831283
ext = (insn.modrm.bytes[0] >> 3) & 0x7;
12841284
switch (ext) {
12851285
case 2: /* near ind call */

arch/x86/include/asm/alternative.h

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ struct alt_instr {
6565
u16 cpuid; /* cpuid bit set for replacement */
6666
u8 instrlen; /* length of original instruction */
6767
u8 replacementlen; /* length of new instruction */
68-
u8 padlen; /* length of build-time padding */
6968
} __packed;
7069

7170
/*
@@ -104,7 +103,6 @@ static inline int alternatives_text_reserved(void *start, void *end)
104103

105104
#define alt_end_marker "663"
106105
#define alt_slen "662b-661b"
107-
#define alt_pad_len alt_end_marker"b-662b"
108106
#define alt_total_slen alt_end_marker"b-661b"
109107
#define alt_rlen(num) e_replacement(num)"f-"b_replacement(num)"f"
110108

@@ -151,8 +149,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
151149
" .long " b_replacement(num)"f - .\n" /* new instruction */ \
152150
" .word " __stringify(feature) "\n" /* feature bit */ \
153151
" .byte " alt_total_slen "\n" /* source len */ \
154-
" .byte " alt_rlen(num) "\n" /* replacement len */ \
155-
" .byte " alt_pad_len "\n" /* pad len */
152+
" .byte " alt_rlen(num) "\n" /* replacement len */
156153

157154
#define ALTINSTR_REPLACEMENT(newinstr, num) /* replacement */ \
158155
"# ALT: replacement " #num "\n" \
@@ -224,9 +221,6 @@ static inline int alternatives_text_reserved(void *start, void *end)
224221
* Peculiarities:
225222
* No memory clobber here.
226223
* Argument numbers start with 1.
227-
* Best is to use constraints that are fixed size (like (%1) ... "r")
228-
* If you use variable sized constraints like "m" or "g" in the
229-
* replacement make sure to pad to the worst case length.
230224
* Leaving an unused argument 0 to keep API compatibility.
231225
*/
232226
#define alternative_input(oldinstr, newinstr, feature, input...) \
@@ -315,13 +309,12 @@ static inline int alternatives_text_reserved(void *start, void *end)
315309
* enough information for the alternatives patching code to patch an
316310
* instruction. See apply_alternatives().
317311
*/
318-
.macro altinstruction_entry orig alt feature orig_len alt_len pad_len
312+
.macro altinstruction_entry orig alt feature orig_len alt_len
319313
.long \orig - .
320314
.long \alt - .
321315
.word \feature
322316
.byte \orig_len
323317
.byte \alt_len
324-
.byte \pad_len
325318
.endm
326319

327320
/*
@@ -338,7 +331,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
338331
142:
339332

340333
.pushsection .altinstructions,"a"
341-
altinstruction_entry 140b,143f,\feature,142b-140b,144f-143f,142b-141b
334+
altinstruction_entry 140b,143f,\feature,142b-140b,144f-143f
342335
.popsection
343336

344337
.pushsection .altinstr_replacement,"ax"
@@ -375,8 +368,8 @@ static inline int alternatives_text_reserved(void *start, void *end)
375368
142:
376369

377370
.pushsection .altinstructions,"a"
378-
altinstruction_entry 140b,143f,\feature1,142b-140b,144f-143f,142b-141b
379-
altinstruction_entry 140b,144f,\feature2,142b-140b,145f-144f,142b-141b
371+
altinstruction_entry 140b,143f,\feature1,142b-140b,144f-143f
372+
altinstruction_entry 140b,144f,\feature2,142b-140b,145f-144f
380373
.popsection
381374

382375
.pushsection .altinstr_replacement,"ax"

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

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,19 @@ extern void cmpxchg8b_emu(void);
1919

2020
#ifdef CONFIG_RETPOLINE
2121

22-
#define DECL_INDIRECT_THUNK(reg) \
22+
#undef GEN
23+
#define GEN(reg) \
2324
extern asmlinkage void __x86_indirect_thunk_ ## reg (void);
24-
25-
#define DECL_RETPOLINE(reg) \
26-
extern asmlinkage void __x86_retpoline_ ## reg (void);
25+
#include <asm/GEN-for-each-reg.h>
2726

2827
#undef GEN
29-
#define GEN(reg) DECL_INDIRECT_THUNK(reg)
28+
#define GEN(reg) \
29+
extern asmlinkage void __x86_indirect_alt_call_ ## reg (void);
3030
#include <asm/GEN-for-each-reg.h>
3131

3232
#undef GEN
33-
#define GEN(reg) DECL_RETPOLINE(reg)
33+
#define GEN(reg) \
34+
extern asmlinkage void __x86_indirect_alt_jmp_ ## reg (void);
3435
#include <asm/GEN-for-each-reg.h>
3536

3637
#endif /* CONFIG_RETPOLINE */

arch/x86/include/asm/cpufeatures.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@
8484

8585
/* CPU types for specific tunings: */
8686
#define X86_FEATURE_K8 ( 3*32+ 4) /* "" Opteron, Athlon64 */
87-
#define X86_FEATURE_K7 ( 3*32+ 5) /* "" Athlon */
87+
/* FREE, was #define X86_FEATURE_K7 ( 3*32+ 5) "" Athlon */
8888
#define X86_FEATURE_P3 ( 3*32+ 6) /* "" P3 */
8989
#define X86_FEATURE_P4 ( 3*32+ 7) /* "" P4 */
9090
#define X86_FEATURE_CONSTANT_TSC ( 3*32+ 8) /* TSC ticks at a constant rate */

arch/x86/include/asm/inat.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*
77
* Written by Masami Hiramatsu <[email protected]>
88
*/
9-
#include <asm/inat_types.h>
9+
#include <asm/inat_types.h> /* __ignore_sync_check__ */
1010

1111
/*
1212
* Internal bits. Don't use bitmasks directly, because these bits are

0 commit comments

Comments
 (0)