x86 fixes
Subsystems (6)
Linus,
Please pull the latest x86-urgent-for-linus git tree from:
git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git x86-urgent-for-linus
# HEAD: 1f161f67a272cc4f29f27934dd3f74cb657eb5c4 x86/microcode: Do the family check first
A landry list of fixes:
- fix reboot breakage on some PCID-enabled system
- fix crashes/hangs on some PCID-enabled systems
- fix microcode loading on certain older CPUs
- various unwinder fixes
- extend an APIC quirk to more hardware systems and disable APIC related warning on virtualized systems
- various Hyper-V fixes
- a macro definition robustness fix
- remove jprobes IRQ disabling
- various mem-encryption fixes
Thanks,
Ingo
------------------>
Andy Lutomirski (2):
x86/mm/64: Fix reboot interaction with CR4.PCIDE x86/mm: Flush more aggressively in lazy TLB mode
Borislav Petkov (1):
x86/microcode: Do the family check first
Josh Poimboeuf (5):
kprobes/x86: Set up frame pointer in kprobe trampoline x86/unwind: Fix dereference of untrusted pointer x86/unwind: Use MSB for frame pointer encoding on 32-bit x86/unwind: Align stack pointer in unwinder dump x86/unwind: Disable unwinder warnings on 32-bit
Len Brown (1):
x86/apic: Update TSC_DEADLINE quirk with additional SKX stepping
Marcelo Henrique Cerri (1):
x86/hyperv: Fix hypercalls with extended CPU ranges for TLB flushing
Masami Hiramatsu (1):
kprobes/x86: Remove IRQ disabling from jprobe handlers
Mathias Krause (1):
x86/alternatives: Fix alt_max_short macro to really be a max()
Paolo Bonzini (1):
x86/apic: Silence "FW_BUG TSC_DEADLINE disabled due to Errata" on hypervisors
Tom Lendacky (1):
x86/mm: Disable various instrumentations of mm/mem_encrypt.c and mm/tlb.c
Vitaly Kuznetsov (2):
x86/hyperv: Clear vCPU banks between calls to avoid flushing unneeded vCPUs x86/hyperv: Don't use percpu areas for pcpu_flush/pcpu_flush_ex structures
arch/x86/entry/entry_32.S | 4 +- arch/x86/hyperv/hv_init.c | 5 ++ arch/x86/hyperv/mmu.c | 57 +++++++++--- arch/x86/include/asm/alternative-asm.h | 4 +- arch/x86/include/asm/alternative.h | 6 +- arch/x86/include/asm/mmu_context.h | 8 +- arch/x86/include/asm/mshyperv.h | 1 + arch/x86/include/asm/tlbflush.h | 24 ++++++ arch/x86/kernel/apic/apic.c | 15 +++- arch/x86/kernel/cpu/microcode/core.c | 27 ++++-- arch/x86/kernel/kprobes/common.h | 13 ++- arch/x86/kernel/kprobes/core.c | 2 - arch/x86/kernel/reboot.c | 4 + arch/x86/kernel/unwind_frame.c | 38 +++++++- arch/x86/mm/Makefile | 11 ++- arch/x86/mm/tlb.c | 153 ++++++++++++++++++++++++--------- 16 files changed, 284 insertions(+), 88 deletions(-)
arch/x86/entry/entry_32.S +2 -2
@@ -176,7 +176,7 @@ /* * This is a sneaky trick to help the unwinder find pt_regs on the stack. The * frame pointer is replaced with an encoded pointer to pt_regs. The encoding - * is just setting the LSB, which makes it an invalid stack address and is also + * is just clearing the MSB, which makes it an invalid stack address and is also * a signal to the unwinder that it's a pt_regs pointer in disguise. * * NOTE: This macro must be used *after* SAVE_ALL because it corrupts the
@@ -185,7 +185,7 @@ .macro ENCODE_FRAME_POINTER #ifdef CONFIG_FRAME_POINTER mov %esp, %ebp - orl $0x1, %ebp + andl $0x7fffffff, %ebp #endif .endm
arch/x86/hyperv/hv_init.c +5 -0
@@ -85,6 +85,8 @@ EXPORT_SYMBOL_GPL(hyperv_cs);u32 *hv_vp_index;EXPORT_SYMBOL_GPL (hv_vp_index); +u32 hv_max_vp_index; +static int hv_cpu_init (unsigned int cpu) {u64 msr_vp_index;
@@ -93,6 +95,9 @@ static int hv_cpu_init(unsigned int cpu) hv_vp_index[smp_processor_id ()] = msr_vp_index; +if (msr_vp_index > hv_max_vp_index) + hv_max_vp_index = msr_vp_index; +return 0 ; }
arch/x86/hyperv/mmu.c +43 -14
120 lines not on this page · raw message
arch/x86/include/asm/alternative-asm.h +3 -1
@@ -62,8 +62,10 @@#define new_len2 145f-144f/* -* max without conditionals. Idea adapted from: +* gas compatible max based on the idea from: * http://graphics.stanford.edu/~seander/bithacks.html#IntegerMinOrMax +* +* The additional "-" is needed because gas uses a "true" value of -1. */ #define alt_max_short (a, b) ((a) ^ (((a) ^ (b)) & -(-((a) < (b)))))
arch/x86/include/asm/alternative.h +3 -3
@@ -103,12 +103,12 @@ static inline int alternatives_text_reserved(void *start, void *end) alt_end_marker":\n" /* -* max without conditionals. Idea adapted from: +* gas compatible max based on the idea from: * http://graphics.stanford.edu/~seander/bithacks.html#IntegerMinOrMax * -* The additional "-" is needed because gas works with s32s. +* The additional "-" is needed because gas uses a "true" value of -1. */ -#define alt_max_short (a, b) "((" a ") ^ (((" a ") ^ (" b ")) & -(-((" a ") - (" b ")))))" +#define alt_max_short (a, b) "((" a ") ^ (((" a ") ^ (" b ")) & -(-((" a ") < (" b ")))))"/* * Pad the second replacement alternative with additional NOPs if it is
arch/x86/include/asm/mmu_context.h +1 -7
@@ -126,13 +126,7 @@ static inline void switch_ldt(struct mm_struct *prev, struct mm_struct *next)DEBUG_LOCKS_WARN_ON (preemptible ()); } -static inline void enter_lazy_tlb (struct mm_struct *mm,struct task_struct *tsk) -{ -int cpu =smp_processor_id (); - -if (cpumask_test_cpu (cpu,mm_cpumask (mm))) -cpumask_clear_cpu (cpu,mm_cpumask (mm)); -} +void enter_lazy_tlb (struct mm_struct *mm,struct task_struct *tsk);static inline int init_new_context (struct task_struct *tsk,struct mm_struct *mm)
arch/x86/include/asm/mshyperv.h +1 -0
@@ -289,6 +289,7 @@ static inline u64 hv_do_rep_hypercall(u16 code, u16 rep_count, u16 varhead_size,* to this information. */ extern u32 *hv_vp_index; +extern u32 hv_max_vp_index;/** * hv_cpu_number_to_vp_number() - Map CPU to VP.
arch/x86/include/asm/tlbflush.h +24 -0
@@ -83,6 +83,13 @@ static inline u64 inc_mm_tlb_gen(struct mm_struct *mm)#endif /* +* If tlb_use_lazy_mode is true, then we try to avoid switching CR3 to point +* to init_mm when we switch to a kernel thread (e.g. the idle thread). If +* it's false, then we immediately switch CR3 when entering a kernel thread. +*/ +DECLARE_STATIC_KEY_TRUE (tlb_use_lazy_mode); + +/* * 6 because 6 should be plenty and struct tlb_state will fit in * two cache lines. */
@@ -105,6 +112,23 @@ struct tlb_state {u16 next_asid;/* +* We can be in one of several states: +* +* - Actively using an mm. Our CPU's bit will be set in +* mm_cpumask(loaded_mm) and is_lazy == false; +* +* - Not using a real mm. loaded_mm == &init_mm. Our CPU's bit +* will not be set in mm_cpumask(&init_mm) and is_lazy == false. +* +* - Lazily using a real mm. loaded_mm != &init_mm, our bit +* is set in mm_cpumask(loaded_mm), but is_lazy == true. +* We're heuristically guessing that the CR3 load we +* skipped more than makes up for the overhead added by +* lazy mode. +*/ +bool is_lazy; + +/* * Access to this CR4 shadow and to H/W CR4 is protected by * disabling interrupts when modifying either one. */
arch/x86/kernel/apic/apic.c +13 -2
@@ -573,11 +573,21 @@ static u32 bdx_deadline_rev(void)return ~0U ; } +static u32 skx_deadline_rev (void ) +{ +switch (boot_cpu_data.x86_mask) { +case 0x03 :return 0x01000136 ; +case 0x04 :return 0x02000014 ; + } + +return ~0U ; +} +static const struct x86_cpu_id deadline_match[] = {DEADLINE_MODEL_MATCH_FUNC (INTEL_FAM6_HASWELL_X , hsx_deadline_rev),DEADLINE_MODEL_MATCH_REV (INTEL_FAM6_BROADWELL_X ,0x0b000020 ),DEADLINE_MODEL_MATCH_FUNC (INTEL_FAM6_BROADWELL_XEON_D , bdx_deadline_rev), -DEADLINE_MODEL_MATCH_REV (INTEL_FAM6_SKYLAKE_X ,0x02000014 ), +DEADLINE_MODEL_MATCH_FUNC (INTEL_FAM6_SKYLAKE_X , skx_deadline_rev),DEADLINE_MODEL_MATCH_REV (INTEL_FAM6_HASWELL_CORE ,0x22 ),DEADLINE_MODEL_MATCH_REV (INTEL_FAM6_HASWELL_ULT ,0x20 ),
@@ -600,7 +610,8 @@ static void apic_check_deadline_errata(void)const struct x86_cpu_id *m;u32 rev; -if (!boot_cpu_has (X86_FEATURE_TSC_DEADLINE_TIMER )) +if (!boot_cpu_has (X86_FEATURE_TSC_DEADLINE_TIMER ) || +boot_cpu_has (X86_FEATURE_HYPERVISOR ))return ; m =x86_match_cpu (deadline_match);
arch/x86/kernel/cpu/microcode/core.c +18 -9
@@ -122,9 +122,6 @@ static bool __init check_loader_disabled_bsp(void)bool *res = &dis_ucode_ldr;#endif -if (!have_cpuid_p ()) -return *res; -/* * CPUID(1).ECX[31]: reserved for hypervisor use. This is still not * completely accurate as xen pv guests don't see that CPUID bit set but
@@ -166,24 +163,36 @@ bool get_builtin_firmware(struct cpio_data *cd, const char *name)void __init load_ucode_bsp (void ) {unsigned int cpuid_1_eax; +bool intel = true; -if (check_loader_disabled_bsp ()) +if (!have_cpuid_p ())return ; cpuid_1_eax =native_cpuid_eax (1 );switch (x86_cpuid_vendor ()) {case X86_VENDOR_INTEL : -if (x86_family (cpuid_1_eax) >=6 ) -load_ucode_intel_bsp (); +if (x86_family (cpuid_1_eax) <6 ) +return ;break ; +case X86_VENDOR_AMD : -if (x86_family (cpuid_1_eax) >=0x10 ) -load_ucode_amd_bsp (cpuid_1_eax); +if (x86_family (cpuid_1_eax) <0x10 ) +return ; + intel = false;break ; +default : -break ; +return ; } + +if (check_loader_disabled_bsp ()) +return ; + +if (intel) +load_ucode_intel_bsp (); +else +load_ucode_amd_bsp (cpuid_1_eax); }static bool check_loader_disabled_ap (void )
arch/x86/kernel/kprobes/common.h +11 -2
@@ -3,6 +3,15 @@/* Kprobes and Optprobes common header */ +#include <asm/asm.h> + +#ifdef CONFIG_FRAME_POINTER +# define SAVE_RBP_STRING " push %" _ASM_BP "\n" \ + " mov %" _ASM_SP ", %" _ASM_BP "\n" +#else +# define SAVE_RBP_STRING " push %" _ASM_BP "\n" +#endif +#ifdef CONFIG_X86_64 #define SAVE_REGS_STRING \/* Skip cs, ip, orig_ax. */ \
@@ -17,7 +26,7 @@" pushq %r10\n" \" pushq %r11\n" \" pushq %rbx\n" \ -" pushq %rbp\n" \ +SAVE_RBP_STRING \" pushq %r12\n" \" pushq %r13\n" \" pushq %r14\n" \
@@ -48,7 +57,7 @@" pushl %es\n" \" pushl %ds\n" \" pushl %eax\n" \ -" pushl %ebp\n" \ +SAVE_RBP_STRING \" pushl %edi\n" \" pushl %esi\n" \" pushl %edx\n" \
arch/x86/kernel/kprobes/core.c +0 -2
@@ -1080,8 +1080,6 @@ int setjmp_pre_handler(struct kprobe *p, struct pt_regs *regs)* raw stack chunk with redzones: */ __memcpy (kcb->jprobes_stack, (kprobe_opcode_t *)addr,MIN_STACK_SIZE (addr)); - regs->flags &= ~X86_EFLAGS_IF ; -trace_hardirqs_off (); regs->ip = (unsigned long )(jp->entry);/*
arch/x86/kernel/reboot.c +4 -0
@@ -105,6 +105,10 @@ void __noreturn machine_real_restart(unsigned int type)load_cr3 (initial_page_table);#else write_cr3 (real_mode_header->trampoline_pgd); + +/* Exiting long mode will fail if CR4.PCIDE is set. */ +if (static_cpu_has (X86_FEATURE_PCID )) +cr4_clear_bits (X86_CR4_PCIDE );#endif /* Jump to the identity-mapped low memory code */
arch/x86/kernel/unwind_frame.c +36 -2
@@ -44,7 +44,8 @@ static void unwind_dump(struct unwind_state *state) state->stack_info.type, state->stack_info.next_sp, state->stack_mask, state->graph_idx); -for (sp = state->orig_sp; sp; sp =PTR_ALIGN (stack_info.next_sp,sizeof (long ))) { +for (sp =PTR_ALIGN (state->orig_sp,sizeof (long )); sp; + sp =PTR_ALIGN (stack_info.next_sp,sizeof (long ))) {if (get_stack_info (sp, state->task, &stack_info, &visit_mask))break ;
@@ -174,6 +175,7 @@ static bool is_last_task_frame(struct unwind_state *state)* This determines if the frame pointer actually contains an encoded pointer to * pt_regs on the stack. See ENCODE_FRAME_POINTER. */ +#ifdef CONFIG_X86_64 static struct pt_regs *decode_frame_pointer (unsigned long *bp) {unsigned long regs = (unsigned long )bp;
@@ -183,6 +185,23 @@ static struct pt_regs *decode_frame_pointer(unsigned long *bp) return (struct pt_regs *)(regs & ~0x1); } +#else +static struct pt_regs *decode_frame_pointer (unsigned long *bp) +{ +unsigned long regs = (unsigned long )bp; + +if (regs &0x80000000 ) +return NULL ; + +return (struct pt_regs *)(regs |0x80000000 ); +} +#endif + +#ifdef CONFIG_X86_32 +#define KERNEL_REGS_SIZE (sizeof(struct pt_regs) - 2*sizeof(long)) +#else +#define KERNEL_REGS_SIZE (sizeof(struct pt_regs)) +#endif static bool update_stack_state (struct unwind_state *state,unsigned long *next_bp)
@@ -202,7 +221,7 @@ static bool update_stack_state(struct unwind_state *state, regs =decode_frame_pointer (next_bp);if (regs) { frame = (unsigned long *)regs; - len =regs_size (regs); + len =KERNEL_REGS_SIZE ; state->got_irq = true; }else { frame = next_bp;
@@ -226,6 +245,14 @@ static bool update_stack_state(struct unwind_state *state, frame < prev_frame_end)return false; +/* +* On 32-bit with user mode regs, make sure the last two regs are safe +* to access: +*/ +if (IS_ENABLED (CONFIG_X86_32 ) && regs &&user_mode (regs) && + !on_stack (info, frame, len +2 *sizeof (long ))) +return false; +/* Move state to the next frame: */ if (regs) { state->regs = regs;
@@ -328,6 +355,13 @@ bool unwind_next_frame(struct unwind_state *state) state->regs->sp < (unsigned long)task_pt_regs(state->task)) goto the_end; +/* +* There are some known frame pointer issues on 32-bit. Disable +* unwinder warnings on 32-bit until it gets objtool support. +*/ +if (IS_ENABLED (CONFIG_X86_32 )) + goto the_end; +if (state->regs) { printk_deferred_once(KERN_WARNING "WARNING: kernel stack regs at %p in %s:%d has bad 'bp' value %p\n",
arch/x86/mm/Makefile +9 -2
@@ -1,5 +1,12 @@ -# Kernel does not boot with instrumentation of tlb.c. -KCOV_INSTRUMENT_tlb.o := n +# Kernel does not boot with instrumentation of tlb.c and mem_encrypt.c +KCOV_INSTRUMENT_tlb.o := n +KCOV_INSTRUMENT_mem_encrypt.o := n + +KASAN_SANITIZE_mem_encrypt.o := n + +ifdef CONFIG_FUNCTION_TRACER +CFLAGS_REMOVE_mem_encrypt.o = -pg +endif obj-y := init.o init_$(BITS).o fault.o ioremap.o extable.o pageattr.o mmap.o \ pat.o pgtable.o physaddr.o setup_nx.o tlb.o
arch/x86/mm/tlb.c +111 -42
204 lines not on this page · raw message