Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge branch 'x86-urgent-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip

Pull misc x86 fixes from Ingo Molnar:

- make CR4 handling irq-safe, which bug vmware guests ran into

- don't crash on early IRQs in Xen guests

- don't crash secondary CPU bringup if #UD assisted WARN()ings are
triggered

- make X86_BUG_FXSAVE_LEAK optional on newer AMD CPUs that have the fix

- fix AMD Fam17h microcode loading

- fix broadcom_postcore_init() if ACPI is disabled

- fix resume regression in __restore_processor_context()

- fix Sparse warnings

- fix a GCC-8 warning

* 'x86-urgent-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip:
x86/vdso: Change time() prototype to match __vdso_time()
x86: Fix Sparse warnings about non-static functions
x86/power: Fix some ordering bugs in __restore_processor_context()
x86/PCI: Make broadcom_postcore_init() check acpi_disabled
x86/microcode/AMD: Add support for fam17h microcode loading
x86/cpufeatures: Make X86_BUG_FXSAVE_LEAK detectable in CPUID on AMD
x86/idt: Load idt early in start_secondary
x86/xen: Support early interrupts in xen pv guests
x86/tlb: Disable interrupts when changing CR4
x86/tlb: Refactor CR4 setting and shadow write

+107 -44
+1 -1
arch/x86/entry/vdso/vclock_gettime.c
··· 324 324 *t = result; 325 325 return result; 326 326 } 327 - int time(time_t *t) 327 + time_t time(time_t *t) 328 328 __attribute__((weak, alias("__vdso_time")));
+1
arch/x86/include/asm/cpufeatures.h
··· 266 266 /* AMD-defined CPU features, CPUID level 0x80000008 (EBX), word 13 */ 267 267 #define X86_FEATURE_CLZERO (13*32+ 0) /* CLZERO instruction */ 268 268 #define X86_FEATURE_IRPERF (13*32+ 1) /* Instructions Retired Count */ 269 + #define X86_FEATURE_XSAVEERPTR (13*32+ 2) /* Always save/restore FP error pointers */ 269 270 270 271 /* Thermal and Power Management Leaf, CPUID level 0x00000006 (EAX), word 14 */ 271 272 #define X86_FEATURE_DTHERM (14*32+ 0) /* Digital Thermal Sensor */
+12
arch/x86/include/asm/segment.h
··· 236 236 */ 237 237 #define EARLY_IDT_HANDLER_SIZE 9 238 238 239 + /* 240 + * xen_early_idt_handler_array is for Xen pv guests: for each entry in 241 + * early_idt_handler_array it contains a prequel in the form of 242 + * pop %rcx; pop %r11; jmp early_idt_handler_array[i]; summing up to 243 + * max 8 bytes. 244 + */ 245 + #define XEN_EARLY_IDT_HANDLER_SIZE 8 246 + 239 247 #ifndef __ASSEMBLY__ 240 248 241 249 extern const char early_idt_handler_array[NUM_EXCEPTION_VECTORS][EARLY_IDT_HANDLER_SIZE]; 242 250 extern void early_ignore_irq(void); 251 + 252 + #if defined(CONFIG_X86_64) && defined(CONFIG_XEN_PV) 253 + extern const char xen_early_idt_handler_array[NUM_EXCEPTION_VECTORS][XEN_EARLY_IDT_HANDLER_SIZE]; 254 + #endif 243 255 244 256 /* 245 257 * Load a segment. Fall back on loading the zero segment if something goes
+19 -16
arch/x86/include/asm/tlbflush.h
··· 173 173 this_cpu_write(cpu_tlbstate.cr4, __read_cr4()); 174 174 } 175 175 176 + static inline void __cr4_set(unsigned long cr4) 177 + { 178 + lockdep_assert_irqs_disabled(); 179 + this_cpu_write(cpu_tlbstate.cr4, cr4); 180 + __write_cr4(cr4); 181 + } 182 + 176 183 /* Set in this cpu's CR4. */ 177 184 static inline void cr4_set_bits(unsigned long mask) 178 185 { 179 - unsigned long cr4; 186 + unsigned long cr4, flags; 180 187 188 + local_irq_save(flags); 181 189 cr4 = this_cpu_read(cpu_tlbstate.cr4); 182 - if ((cr4 | mask) != cr4) { 183 - cr4 |= mask; 184 - this_cpu_write(cpu_tlbstate.cr4, cr4); 185 - __write_cr4(cr4); 186 - } 190 + if ((cr4 | mask) != cr4) 191 + __cr4_set(cr4 | mask); 192 + local_irq_restore(flags); 187 193 } 188 194 189 195 /* Clear in this cpu's CR4. */ 190 196 static inline void cr4_clear_bits(unsigned long mask) 191 197 { 192 - unsigned long cr4; 198 + unsigned long cr4, flags; 193 199 200 + local_irq_save(flags); 194 201 cr4 = this_cpu_read(cpu_tlbstate.cr4); 195 - if ((cr4 & ~mask) != cr4) { 196 - cr4 &= ~mask; 197 - this_cpu_write(cpu_tlbstate.cr4, cr4); 198 - __write_cr4(cr4); 199 - } 202 + if ((cr4 & ~mask) != cr4) 203 + __cr4_set(cr4 & ~mask); 204 + local_irq_restore(flags); 200 205 } 201 206 202 - static inline void cr4_toggle_bits(unsigned long mask) 207 + static inline void cr4_toggle_bits_irqsoff(unsigned long mask) 203 208 { 204 209 unsigned long cr4; 205 210 206 211 cr4 = this_cpu_read(cpu_tlbstate.cr4); 207 - cr4 ^= mask; 208 - this_cpu_write(cpu_tlbstate.cr4, cr4); 209 - __write_cr4(cr4); 212 + __cr4_set(cr4 ^ mask); 210 213 } 211 214 212 215 /* Read the CR4 shadow. */
+2 -2
arch/x86/kernel/apic/vector.c
··· 542 542 } 543 543 544 544 #ifdef CONFIG_GENERIC_IRQ_DEBUGFS 545 - void x86_vector_debug_show(struct seq_file *m, struct irq_domain *d, 546 - struct irq_data *irqd, int ind) 545 + static void x86_vector_debug_show(struct seq_file *m, struct irq_domain *d, 546 + struct irq_data *irqd, int ind) 547 547 { 548 548 unsigned int cpu, vector, prev_cpu, prev_vector; 549 549 struct apic_chip_data *apicd;
+5 -2
arch/x86/kernel/cpu/amd.c
··· 804 804 case 0x17: init_amd_zn(c); break; 805 805 } 806 806 807 - /* Enable workaround for FXSAVE leak */ 808 - if (c->x86 >= 6) 807 + /* 808 + * Enable workaround for FXSAVE leak on CPUs 809 + * without a XSaveErPtr feature 810 + */ 811 + if ((c->x86 >= 6) && (!cpu_has(c, X86_FEATURE_XSAVEERPTR))) 809 812 set_cpu_bug(c, X86_BUG_FXSAVE_LEAK); 810 813 811 814 cpu_detect_cache_sizes(c);
+4
arch/x86/kernel/cpu/microcode/amd.c
··· 470 470 #define F14H_MPB_MAX_SIZE 1824 471 471 #define F15H_MPB_MAX_SIZE 4096 472 472 #define F16H_MPB_MAX_SIZE 3458 473 + #define F17H_MPB_MAX_SIZE 3200 473 474 474 475 switch (family) { 475 476 case 0x14: ··· 481 480 break; 482 481 case 0x16: 483 482 max_size = F16H_MPB_MAX_SIZE; 483 + break; 484 + case 0x17: 485 + max_size = F17H_MPB_MAX_SIZE; 484 486 break; 485 487 default: 486 488 max_size = F1XH_MPB_MAX_SIZE;
+1 -1
arch/x86/kernel/process.c
··· 299 299 } 300 300 301 301 if ((tifp ^ tifn) & _TIF_NOTSC) 302 - cr4_toggle_bits(X86_CR4_TSD); 302 + cr4_toggle_bits_irqsoff(X86_CR4_TSD); 303 303 304 304 if ((tifp ^ tifn) & _TIF_NOCPUID) 305 305 set_cpuid_faulting(!!(tifn & _TIF_NOCPUID));
+1 -1
arch/x86/kernel/smpboot.c
··· 237 237 load_cr3(swapper_pg_dir); 238 238 __flush_tlb_all(); 239 239 #endif 240 - 240 + load_current_idt(); 241 241 cpu_init(); 242 242 x86_cpuinit.early_percpu_clock_init(); 243 243 preempt_disable();
+3 -1
arch/x86/mm/extable.c
··· 1 1 #include <linux/extable.h> 2 2 #include <linux/uaccess.h> 3 3 #include <linux/sched/debug.h> 4 + #include <xen/xen.h> 4 5 5 6 #include <asm/fpu/internal.h> 6 7 #include <asm/traps.h> ··· 213 212 * Old CPUs leave the high bits of CS on the stack 214 213 * undefined. I'm not sure which CPUs do this, but at least 215 214 * the 486 DX works this way. 215 + * Xen pv domains are not using the default __KERNEL_CS. 216 216 */ 217 - if (regs->cs != __KERNEL_CS) 217 + if (!xen_pv_domain() && regs->cs != __KERNEL_CS) 218 218 goto fail; 219 219 220 220 /*
+1 -1
arch/x86/pci/broadcom_bus.c
··· 97 97 * We should get host bridge information from ACPI unless the BIOS 98 98 * doesn't support it. 99 99 */ 100 - if (acpi_os_get_root_pointer()) 100 + if (!acpi_disabled && acpi_os_get_root_pointer()) 101 101 return 0; 102 102 #endif 103 103
+2 -2
arch/x86/platform/uv/uv_nmi.c
··· 905 905 /* 906 906 * UV NMI handler 907 907 */ 908 - int uv_handle_nmi(unsigned int reason, struct pt_regs *regs) 908 + static int uv_handle_nmi(unsigned int reason, struct pt_regs *regs) 909 909 { 910 910 struct uv_hub_nmi_s *hub_nmi = uv_hub_nmi; 911 911 int cpu = smp_processor_id(); ··· 1013 1013 } 1014 1014 1015 1015 /* Setup HUB NMI info */ 1016 - void __init uv_nmi_setup_common(bool hubbed) 1016 + static void __init uv_nmi_setup_common(bool hubbed) 1017 1017 { 1018 1018 int size = sizeof(void *) * (1 << NODES_SHIFT); 1019 1019 int cpu;
+17 -4
arch/x86/power/cpu.c
··· 226 226 load_idt((const struct desc_ptr *)&ctxt->idt_limit); 227 227 #endif 228 228 229 + #ifdef CONFIG_X86_64 229 230 /* 230 - * segment registers 231 + * We need GSBASE restored before percpu access can work. 232 + * percpu access can happen in exception handlers or in complicated 233 + * helpers like load_gs_index(). 234 + */ 235 + wrmsrl(MSR_GS_BASE, ctxt->gs_base); 236 + #endif 237 + 238 + fix_processor_context(); 239 + 240 + /* 241 + * Restore segment registers. This happens after restoring the GDT 242 + * and LDT, which happen in fix_processor_context(). 231 243 */ 232 244 #ifdef CONFIG_X86_32 233 245 loadsegment(es, ctxt->es); ··· 260 248 load_gs_index(ctxt->gs); 261 249 asm volatile ("movw %0, %%ss" :: "r" (ctxt->ss)); 262 250 251 + /* 252 + * Restore FSBASE and user GSBASE after reloading the respective 253 + * segment selectors. 254 + */ 263 255 wrmsrl(MSR_FS_BASE, ctxt->fs_base); 264 - wrmsrl(MSR_GS_BASE, ctxt->gs_base); 265 256 wrmsrl(MSR_KERNEL_GS_BASE, ctxt->gs_kernel_base); 266 257 #endif 267 - 268 - fix_processor_context(); 269 258 270 259 do_fpu_end(); 271 260 tsc_verify_tsc_adjust(true);
+24 -13
arch/x86/xen/enlighten_pv.c
··· 622 622 { simd_coprocessor_error, xen_simd_coprocessor_error, false }, 623 623 }; 624 624 625 - static bool get_trap_addr(void **addr, unsigned int ist) 625 + static bool __ref get_trap_addr(void **addr, unsigned int ist) 626 626 { 627 627 unsigned int nr; 628 628 bool ist_okay = false; ··· 642 642 ist_okay = entry->ist_okay; 643 643 break; 644 644 } 645 + } 646 + 647 + if (nr == ARRAY_SIZE(trap_array) && 648 + *addr >= (void *)early_idt_handler_array[0] && 649 + *addr < (void *)early_idt_handler_array[NUM_EXCEPTION_VECTORS]) { 650 + nr = (*addr - (void *)early_idt_handler_array[0]) / 651 + EARLY_IDT_HANDLER_SIZE; 652 + *addr = (void *)xen_early_idt_handler_array[nr]; 645 653 } 646 654 647 655 if (WARN_ON(ist != 0 && !ist_okay)) ··· 1270 1262 xen_setup_gdt(0); 1271 1263 1272 1264 xen_init_irq_ops(); 1265 + 1266 + /* Let's presume PV guests always boot on vCPU with id 0. */ 1267 + per_cpu(xen_vcpu_id, 0) = 0; 1268 + 1269 + /* 1270 + * Setup xen_vcpu early because idt_setup_early_handler needs it for 1271 + * local_irq_disable(), irqs_disabled(). 1272 + * 1273 + * Don't do the full vcpu_info placement stuff until we have 1274 + * the cpu_possible_mask and a non-dummy shared_info. 1275 + */ 1276 + xen_vcpu_info_reset(0); 1277 + 1278 + idt_setup_early_handler(); 1279 + 1273 1280 xen_init_capabilities(); 1274 1281 1275 1282 #ifdef CONFIG_X86_LOCAL_APIC ··· 1318 1295 */ 1319 1296 acpi_numa = -1; 1320 1297 #endif 1321 - /* Let's presume PV guests always boot on vCPU with id 0. */ 1322 - per_cpu(xen_vcpu_id, 0) = 0; 1323 - 1324 - /* 1325 - * Setup xen_vcpu early because start_kernel needs it for 1326 - * local_irq_disable(), irqs_disabled(). 1327 - * 1328 - * Don't do the full vcpu_info placement stuff until we have 1329 - * the cpu_possible_mask and a non-dummy shared_info. 1330 - */ 1331 - xen_vcpu_info_reset(0); 1332 - 1333 1298 WARN_ON(xen_cpuhp_setup(xen_cpu_up_prepare_pv, xen_cpu_dead_pv)); 1334 1299 1335 1300 local_irq_disable();
+14
arch/x86/xen/xen-asm_64.S
··· 15 15 16 16 #include <xen/interface/xen.h> 17 17 18 + #include <linux/init.h> 18 19 #include <linux/linkage.h> 19 20 20 21 .macro xen_pv_trap name ··· 54 53 xen_pv_trap entry_INT80_compat 55 54 #endif 56 55 xen_pv_trap hypervisor_callback 56 + 57 + __INIT 58 + ENTRY(xen_early_idt_handler_array) 59 + i = 0 60 + .rept NUM_EXCEPTION_VECTORS 61 + pop %rcx 62 + pop %r11 63 + jmp early_idt_handler_array + i*EARLY_IDT_HANDLER_SIZE 64 + i = i + 1 65 + .fill xen_early_idt_handler_array + i*XEN_EARLY_IDT_HANDLER_SIZE - ., 1, 0xcc 66 + .endr 67 + END(xen_early_idt_handler_array) 68 + __FINIT 57 69 58 70 hypercall_iret = hypercall_page + __HYPERVISOR_iret * 32 59 71 /*