Skip to content

Commit efb9666

Browse files
committed
Merge tag 'x86-urgent-2020-07-19' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip into master
Pull x86 fixes from Thomas Gleixner: "A pile of fixes for x86: - Fix the I/O bitmap invalidation on XEN PV, which was overlooked in the recent ioperm/iopl rework. This caused the TSS and XEN's I/O bitmap to get out of sync. - Use the proper vectors for HYPERV. - Make disabling of stack protector for the entry code work with GCC builds which enable stack protector by default. Removing the option is not sufficient, it needs an explicit -fno-stack-protector to shut it off. - Mark check_user_regs() noinstr as it is called from noinstr code. The missing annotation causes it to be placed in the text section which makes it instrumentable. - Add the missing interrupt disable in exc_alignment_check() - Fixup a XEN_PV build dependency in the 32bit entry code - A few fixes to make the Clang integrated assembler happy - Move EFI stub build to the right place for out of tree builds - Make prepare_exit_to_usermode() static. It's not longer called from ASM code" * tag 'x86-urgent-2020-07-19' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: x86/boot: Don't add the EFI stub to targets x86/entry: Actually disable stack protector x86/ioperm: Fix io bitmap invalidation on Xen PV x86: math-emu: Fix up 'cmp' insn for clang ias x86/entry: Fix vectors to IDTENTRY_SYSVEC for CONFIG_HYPERV x86/entry: Add compatibility with IAS x86/entry/common: Make prepare_exit_to_usermode() static x86/entry: Mark check_user_regs() noinstr x86/traps: Disable interrupts in exc_aligment_check() x86/entry/32: Fix XEN_PV build dependency
2 parents 66e4b63 + da05b14 commit efb9666

File tree

12 files changed

+66
-37
lines changed

12 files changed

+66
-37
lines changed

arch/x86/boot/compressed/Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,8 @@ endif
9090

9191
vmlinux-objs-$(CONFIG_ACPI) += $(obj)/acpi.o
9292

93-
vmlinux-objs-$(CONFIG_EFI_STUB) += $(objtree)/drivers/firmware/efi/libstub/lib.a
9493
vmlinux-objs-$(CONFIG_EFI_MIXED) += $(obj)/efi_thunk_$(BITS).o
94+
efi-obj-$(CONFIG_EFI_STUB) = $(objtree)/drivers/firmware/efi/libstub/lib.a
9595

9696
# The compressed kernel is built with -fPIC/-fPIE so that a boot loader
9797
# can place it anywhere in memory and it will still run. However, since
@@ -115,7 +115,7 @@ endef
115115
quiet_cmd_check-and-link-vmlinux = LD $@
116116
cmd_check-and-link-vmlinux = $(cmd_check_data_rel); $(cmd_ld)
117117

118-
$(obj)/vmlinux: $(vmlinux-objs-y) FORCE
118+
$(obj)/vmlinux: $(vmlinux-objs-y) $(efi-obj-y) FORCE
119119
$(call if_changed,check-and-link-vmlinux)
120120

121121
OBJCOPYFLAGS_vmlinux.bin := -R .comment -S

arch/x86/entry/Makefile

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,20 @@ KASAN_SANITIZE := n
77
UBSAN_SANITIZE := n
88
KCOV_INSTRUMENT := n
99

10-
CFLAGS_REMOVE_common.o = $(CC_FLAGS_FTRACE) -fstack-protector -fstack-protector-strong
11-
CFLAGS_REMOVE_syscall_32.o = $(CC_FLAGS_FTRACE) -fstack-protector -fstack-protector-strong
12-
CFLAGS_REMOVE_syscall_64.o = $(CC_FLAGS_FTRACE) -fstack-protector -fstack-protector-strong
10+
CFLAGS_REMOVE_common.o = $(CC_FLAGS_FTRACE)
11+
CFLAGS_REMOVE_syscall_64.o = $(CC_FLAGS_FTRACE)
12+
CFLAGS_REMOVE_syscall_32.o = $(CC_FLAGS_FTRACE)
13+
CFLAGS_REMOVE_syscall_x32.o = $(CC_FLAGS_FTRACE)
14+
15+
CFLAGS_common.o += -fno-stack-protector
16+
CFLAGS_syscall_64.o += -fno-stack-protector
17+
CFLAGS_syscall_32.o += -fno-stack-protector
18+
CFLAGS_syscall_x32.o += -fno-stack-protector
1319

1420
CFLAGS_syscall_64.o += $(call cc-option,-Wno-override-init,)
1521
CFLAGS_syscall_32.o += $(call cc-option,-Wno-override-init,)
22+
CFLAGS_syscall_x32.o += $(call cc-option,-Wno-override-init,)
23+
1624
obj-y := entry_$(BITS).o thunk_$(BITS).o syscall_$(BITS).o
1725
obj-y += common.o
1826

arch/x86/entry/common.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
#include <trace/events/syscalls.h>
4747

4848
/* Check that the stack and regs on entry from user mode are sane. */
49-
static void check_user_regs(struct pt_regs *regs)
49+
static noinstr void check_user_regs(struct pt_regs *regs)
5050
{
5151
if (IS_ENABLED(CONFIG_DEBUG_ENTRY)) {
5252
/*
@@ -294,7 +294,7 @@ static void __prepare_exit_to_usermode(struct pt_regs *regs)
294294
#endif
295295
}
296296

297-
__visible noinstr void prepare_exit_to_usermode(struct pt_regs *regs)
297+
static noinstr void prepare_exit_to_usermode(struct pt_regs *regs)
298298
{
299299
instrumentation_begin();
300300
__prepare_exit_to_usermode(regs);

arch/x86/include/asm/idtentry.h

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -469,33 +469,31 @@ __visible noinstr void func(struct pt_regs *regs, \
469469
.align 8
470470
SYM_CODE_START(irq_entries_start)
471471
vector=FIRST_EXTERNAL_VECTOR
472-
pos = .
473472
.rept (FIRST_SYSTEM_VECTOR - FIRST_EXTERNAL_VECTOR)
474473
UNWIND_HINT_IRET_REGS
474+
0 :
475475
.byte 0x6a, vector
476476
jmp asm_common_interrupt
477477
nop
478478
/* Ensure that the above is 8 bytes max */
479-
. = pos + 8
480-
pos=pos+8
481-
vector=vector+1
479+
. = 0b + 8
480+
vector = vector+1
482481
.endr
483482
SYM_CODE_END(irq_entries_start)
484483

485484
#ifdef CONFIG_X86_LOCAL_APIC
486485
.align 8
487486
SYM_CODE_START(spurious_entries_start)
488487
vector=FIRST_SYSTEM_VECTOR
489-
pos = .
490488
.rept (NR_VECTORS - FIRST_SYSTEM_VECTOR)
491489
UNWIND_HINT_IRET_REGS
490+
0 :
492491
.byte 0x6a, vector
493492
jmp asm_spurious_interrupt
494493
nop
495494
/* Ensure that the above is 8 bytes max */
496-
. = pos + 8
497-
pos=pos+8
498-
vector=vector+1
495+
. = 0b + 8
496+
vector = vector+1
499497
.endr
500498
SYM_CODE_END(spurious_entries_start)
501499
#endif
@@ -553,7 +551,7 @@ DECLARE_IDTENTRY_RAW(X86_TRAP_MC, exc_machine_check);
553551

554552
/* NMI */
555553
DECLARE_IDTENTRY_NMI(X86_TRAP_NMI, exc_nmi);
556-
#ifdef CONFIG_XEN_PV
554+
#if defined(CONFIG_XEN_PV) && defined(CONFIG_X86_64)
557555
DECLARE_IDTENTRY_RAW(X86_TRAP_NMI, xenpv_exc_nmi);
558556
#endif
559557

@@ -563,7 +561,7 @@ DECLARE_IDTENTRY_DEBUG(X86_TRAP_DB, exc_debug);
563561
#else
564562
DECLARE_IDTENTRY_RAW(X86_TRAP_DB, exc_debug);
565563
#endif
566-
#ifdef CONFIG_XEN_PV
564+
#if defined(CONFIG_XEN_PV) && defined(CONFIG_X86_64)
567565
DECLARE_IDTENTRY_RAW(X86_TRAP_DB, xenpv_exc_debug);
568566
#endif
569567

@@ -626,8 +624,8 @@ DECLARE_IDTENTRY_SYSVEC(POSTED_INTR_NESTED_VECTOR, sysvec_kvm_posted_intr_nested
626624

627625
#if IS_ENABLED(CONFIG_HYPERV)
628626
DECLARE_IDTENTRY_SYSVEC(HYPERVISOR_CALLBACK_VECTOR, sysvec_hyperv_callback);
629-
DECLARE_IDTENTRY_SYSVEC(HYPERVISOR_REENLIGHTENMENT_VECTOR, sysvec_hyperv_reenlightenment);
630-
DECLARE_IDTENTRY_SYSVEC(HYPERVISOR_STIMER0_VECTOR, sysvec_hyperv_stimer0);
627+
DECLARE_IDTENTRY_SYSVEC(HYPERV_REENLIGHTENMENT_VECTOR, sysvec_hyperv_reenlightenment);
628+
DECLARE_IDTENTRY_SYSVEC(HYPERV_STIMER0_VECTOR, sysvec_hyperv_stimer0);
631629
#endif
632630

633631
#if IS_ENABLED(CONFIG_ACRN_GUEST)

arch/x86/include/asm/io_bitmap.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,28 @@ struct task_struct;
1919
void io_bitmap_share(struct task_struct *tsk);
2020
void io_bitmap_exit(struct task_struct *tsk);
2121

22+
static inline void native_tss_invalidate_io_bitmap(void)
23+
{
24+
/*
25+
* Invalidate the I/O bitmap by moving io_bitmap_base outside the
26+
* TSS limit so any subsequent I/O access from user space will
27+
* trigger a #GP.
28+
*
29+
* This is correct even when VMEXIT rewrites the TSS limit
30+
* to 0x67 as the only requirement is that the base points
31+
* outside the limit.
32+
*/
33+
this_cpu_write(cpu_tss_rw.x86_tss.io_bitmap_base,
34+
IO_BITMAP_OFFSET_INVALID);
35+
}
36+
2237
void native_tss_update_io_bitmap(void);
2338

2439
#ifdef CONFIG_PARAVIRT_XXL
2540
#include <asm/paravirt.h>
2641
#else
2742
#define tss_update_io_bitmap native_tss_update_io_bitmap
43+
#define tss_invalidate_io_bitmap native_tss_invalidate_io_bitmap
2844
#endif
2945

3046
#else

arch/x86/include/asm/paravirt.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,11 @@ static inline void write_idt_entry(gate_desc *dt, int entry, const gate_desc *g)
302302
}
303303

304304
#ifdef CONFIG_X86_IOPL_IOPERM
305+
static inline void tss_invalidate_io_bitmap(void)
306+
{
307+
PVOP_VCALL0(cpu.invalidate_io_bitmap);
308+
}
309+
305310
static inline void tss_update_io_bitmap(void)
306311
{
307312
PVOP_VCALL0(cpu.update_io_bitmap);

arch/x86/include/asm/paravirt_types.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ struct pv_cpu_ops {
141141
void (*load_sp0)(unsigned long sp0);
142142

143143
#ifdef CONFIG_X86_IOPL_IOPERM
144+
void (*invalidate_io_bitmap)(void);
144145
void (*update_io_bitmap)(void);
145146
#endif
146147

arch/x86/kernel/paravirt.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,8 @@ struct paravirt_patch_template pv_ops = {
324324
.cpu.swapgs = native_swapgs,
325325

326326
#ifdef CONFIG_X86_IOPL_IOPERM
327-
.cpu.update_io_bitmap = native_tss_update_io_bitmap,
327+
.cpu.invalidate_io_bitmap = native_tss_invalidate_io_bitmap,
328+
.cpu.update_io_bitmap = native_tss_update_io_bitmap,
328329
#endif
329330

330331
.cpu.start_context_switch = paravirt_nop,

arch/x86/kernel/process.c

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -322,20 +322,6 @@ void arch_setup_new_exec(void)
322322
}
323323

324324
#ifdef CONFIG_X86_IOPL_IOPERM
325-
static inline void tss_invalidate_io_bitmap(struct tss_struct *tss)
326-
{
327-
/*
328-
* Invalidate the I/O bitmap by moving io_bitmap_base outside the
329-
* TSS limit so any subsequent I/O access from user space will
330-
* trigger a #GP.
331-
*
332-
* This is correct even when VMEXIT rewrites the TSS limit
333-
* to 0x67 as the only requirement is that the base points
334-
* outside the limit.
335-
*/
336-
tss->x86_tss.io_bitmap_base = IO_BITMAP_OFFSET_INVALID;
337-
}
338-
339325
static inline void switch_to_bitmap(unsigned long tifp)
340326
{
341327
/*
@@ -346,7 +332,7 @@ static inline void switch_to_bitmap(unsigned long tifp)
346332
* user mode.
347333
*/
348334
if (tifp & _TIF_IO_BITMAP)
349-
tss_invalidate_io_bitmap(this_cpu_ptr(&cpu_tss_rw));
335+
tss_invalidate_io_bitmap();
350336
}
351337

352338
static void tss_copy_io_bitmap(struct tss_struct *tss, struct io_bitmap *iobm)
@@ -380,7 +366,7 @@ void native_tss_update_io_bitmap(void)
380366
u16 *base = &tss->x86_tss.io_bitmap_base;
381367

382368
if (!test_thread_flag(TIF_IO_BITMAP)) {
383-
tss_invalidate_io_bitmap(tss);
369+
native_tss_invalidate_io_bitmap();
384370
return;
385371
}
386372

arch/x86/kernel/traps.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,8 @@ DEFINE_IDTENTRY_ERRORCODE(exc_alignment_check)
303303

304304
do_trap(X86_TRAP_AC, SIGBUS, "alignment check", regs,
305305
error_code, BUS_ADRALN, NULL);
306+
307+
local_irq_disable();
306308
}
307309

308310
#ifdef CONFIG_VMAP_STACK

arch/x86/math-emu/wm_sqrt.S

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ sqrt_stage_2_finish:
209209

210210
#ifdef PARANOID
211211
/* It should be possible to get here only if the arg is ffff....ffff */
212-
cmp $0xffffffff,FPU_fsqrt_arg_1
212+
cmpl $0xffffffff,FPU_fsqrt_arg_1
213213
jnz sqrt_stage_2_error
214214
#endif /* PARANOID */
215215

arch/x86/xen/enlighten_pv.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -870,6 +870,17 @@ static void xen_load_sp0(unsigned long sp0)
870870
}
871871

872872
#ifdef CONFIG_X86_IOPL_IOPERM
873+
static void xen_invalidate_io_bitmap(void)
874+
{
875+
struct physdev_set_iobitmap iobitmap = {
876+
.bitmap = 0,
877+
.nr_ports = 0,
878+
};
879+
880+
native_tss_invalidate_io_bitmap();
881+
HYPERVISOR_physdev_op(PHYSDEVOP_set_iobitmap, &iobitmap);
882+
}
883+
873884
static void xen_update_io_bitmap(void)
874885
{
875886
struct physdev_set_iobitmap iobitmap;
@@ -1099,6 +1110,7 @@ static const struct pv_cpu_ops xen_cpu_ops __initconst = {
10991110
.load_sp0 = xen_load_sp0,
11001111

11011112
#ifdef CONFIG_X86_IOPL_IOPERM
1113+
.invalidate_io_bitmap = xen_invalidate_io_bitmap,
11021114
.update_io_bitmap = xen_update_io_bitmap,
11031115
#endif
11041116
.io_delay = xen_io_delay,

0 commit comments

Comments
 (0)