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

x86/boot/32: Defer resyncing initial_page_table until per-cpu is set up

The x86 smpboot trampoline expects initial_page_table to have the
GDT mapped. If the GDT ends up in a virtually mapped per-cpu page,
then it won't be in the page tables at all until perc-pu areas are
set up. The result will be a triple fault the first time that the
CPU attempts to access the GDT after LGDT loads the perc-pu GDT.

This appears to be an old bug, but somehow the GDT fixmap rework
is triggering it. This seems to have something to do with the
memory layout.

Signed-off-by: Andy Lutomirski <luto@kernel.org>
Cc: Ard Biesheuvel <ard.biesheuvel@linaro.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: Matt Fleming <matt@codeblueprint.co.uk>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Garnier <thgarnie@google.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: linux-efi@vger.kernel.org
Link: http://lkml.kernel.org/r/a553264a5972c6a86f9b5caac237470a0c74a720.1490218061.git.luto@kernel.org
Signed-off-by: Ingo Molnar <mingo@kernel.org>

authored by

Andy Lutomirski and committed by
Ingo Molnar
23b2a4dd 3fa1cabb

+21 -15
-15
arch/x86/kernel/setup.c
··· 1226 1226 1227 1227 kasan_init(); 1228 1228 1229 - #ifdef CONFIG_X86_32 1230 - /* sync back kernel address range */ 1231 - clone_pgd_range(initial_page_table + KERNEL_PGD_BOUNDARY, 1232 - swapper_pg_dir + KERNEL_PGD_BOUNDARY, 1233 - KERNEL_PGD_PTRS); 1234 - 1235 - /* 1236 - * sync back low identity map too. It is used for example 1237 - * in the 32-bit EFI stub. 1238 - */ 1239 - clone_pgd_range(initial_page_table, 1240 - swapper_pg_dir + KERNEL_PGD_BOUNDARY, 1241 - min(KERNEL_PGD_PTRS, KERNEL_PGD_BOUNDARY)); 1242 - #endif 1243 - 1244 1229 tboot_probe(); 1245 1230 1246 1231 map_vsyscall();
+21
arch/x86/kernel/setup_percpu.c
··· 288 288 289 289 /* Setup cpu initialized, callin, callout masks */ 290 290 setup_cpu_local_masks(); 291 + 292 + #ifdef CONFIG_X86_32 293 + /* 294 + * Sync back kernel address range. We want to make sure that 295 + * all kernel mappings, including percpu mappings, are available 296 + * in the smpboot asm. We can't reliably pick up percpu 297 + * mappings using vmalloc_fault(), because exception dispatch 298 + * needs percpu data. 299 + */ 300 + clone_pgd_range(initial_page_table + KERNEL_PGD_BOUNDARY, 301 + swapper_pg_dir + KERNEL_PGD_BOUNDARY, 302 + KERNEL_PGD_PTRS); 303 + 304 + /* 305 + * sync back low identity map too. It is used for example 306 + * in the 32-bit EFI stub. 307 + */ 308 + clone_pgd_range(initial_page_table, 309 + swapper_pg_dir + KERNEL_PGD_BOUNDARY, 310 + min(KERNEL_PGD_PTRS, KERNEL_PGD_BOUNDARY)); 311 + #endif 291 312 }