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

x86/xen/gdt: Use X86_FEATURE_XENPV instead of globals for the GDT fixup

Xen imposes special requirements on the GDT. Rather than using a
global variable for the pgprot, just use an explicit special case
for Xen -- this makes it clearer what's going on. It also debloats
64-bit kernels very slightly.

Signed-off-by: Andy Lutomirski <luto@kernel.org>
Cc: Boris Ostrovsky <boris.ostrovsky@oracle.com>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Brian Gerst <brgerst@gmail.com>
Cc: Denys Vlasenko <dvlasenk@redhat.com>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Josh Poimboeuf <jpoimboe@redhat.com>
Cc: Juergen Gross <jgross@suse.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Garnier <thgarnie@google.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Link: http://lkml.kernel.org/r/e9ea96abbfd6a8c87753849171bb5987ecfeb523.1490218061.git.luto@kernel.org
Signed-off-by: Ingo Molnar <mingo@kernel.org>

authored by

Andy Lutomirski and committed by
Ingo Molnar
b23adb7d 59c58ceb

+18 -16
-1
arch/x86/include/asm/desc.h
··· 39 39 extern gate_desc idt_table[]; 40 40 extern const struct desc_ptr debug_idt_descr; 41 41 extern gate_desc debug_idt_table[]; 42 - extern pgprot_t pg_fixmap_gdt_flags; 43 42 44 43 struct gdt_page { 45 44 struct desc_struct gdt[GDT_ENTRIES];
+18 -12
arch/x86/kernel/cpu/common.c
··· 448 448 load_stack_canary_segment(); 449 449 } 450 450 451 - /* 452 - * On 64-bit the GDT remapping is read-only. 453 - * A global is used for Xen to change the default when required. 454 - */ 455 - #ifdef CONFIG_X86_64 456 - pgprot_t pg_fixmap_gdt_flags = PAGE_KERNEL_RO; 457 - #else 458 - pgprot_t pg_fixmap_gdt_flags = PAGE_KERNEL; 459 - #endif 460 - 461 451 /* Setup the fixmap mapping only once per-processor */ 462 452 static inline void setup_fixmap_gdt(int cpu) 463 453 { 464 - __set_fixmap(get_cpu_gdt_ro_index(cpu), get_cpu_gdt_paddr(cpu), 465 - pg_fixmap_gdt_flags); 454 + #ifdef CONFIG_X86_64 455 + /* On 64-bit systems, we use a read-only fixmap GDT. */ 456 + pgprot_t prot = PAGE_KERNEL_RO; 457 + #else 458 + /* 459 + * On native 32-bit systems, the GDT cannot be read-only because 460 + * our double fault handler uses a task gate, and entering through 461 + * a task gate needs to change an available TSS to busy. If the GDT 462 + * is read-only, that will triple fault. 463 + * 464 + * On Xen PV, the GDT must be read-only because the hypervisor requires 465 + * it. 466 + */ 467 + pgprot_t prot = boot_cpu_has(X86_FEATURE_XENPV) ? 468 + PAGE_KERNEL_RO : PAGE_KERNEL; 469 + #endif 470 + 471 + __set_fixmap(get_cpu_gdt_ro_index(cpu), get_cpu_gdt_paddr(cpu), prot); 466 472 } 467 473 468 474 /* Load the original GDT from the per-cpu structure */
-3
arch/x86/xen/enlighten.c
··· 1545 1545 */ 1546 1546 xen_initial_gdt = &per_cpu(gdt_page, 0); 1547 1547 1548 - /* GDT can only be remapped RO */ 1549 - pg_fixmap_gdt_flags = PAGE_KERNEL_RO; 1550 - 1551 1548 xen_smp_init(); 1552 1549 1553 1550 #ifdef CONFIG_ACPI_NUMA