Skip to content

Commit 4440977

Browse files
kirylIngo Molnar
authored andcommitted
x86/boot/compressed/64: Introduce paging_prepare()
Rename l5_paging_required() to paging_prepare() and change the interface of the function. This is a preparation for the next patch, which would make the function also allocate memory for the 32-bit trampoline. The function now returns a 128-bit structure. RAX would return trampoline memory address (zero for now) and RDX would indicate if we need to enable 5-level paging. Signed-off-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com> [ Typo fixes and general clarification. ] Cc: Andy Lutomirski <luto@amacapital.net> Cc: Borislav Petkov <bp@suse.de> Cc: Cyrill Gorcunov <gorcunov@openvz.org> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Matthew Wilcox <willy@infradead.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: linux-mm@kvack.org Link: http://lkml.kernel.org/r/20180209142228.21231-3-kirill.shutemov@linux.intel.com Signed-off-by: Ingo Molnar <mingo@kernel.org>
1 parent 7cc4eb1 commit 4440977

File tree

2 files changed

+31
-35
lines changed

2 files changed

+31
-35
lines changed

arch/x86/boot/compressed/head_64.S

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -304,33 +304,35 @@ ENTRY(startup_64)
304304
/* Set up the stack */
305305
leaq boot_stack_end(%rbx), %rsp
306306

307-
#ifdef CONFIG_X86_5LEVEL
308-
/*
309-
* Check if we need to enable 5-level paging.
310-
* RSI holds real mode data and need to be preserved across
311-
* a function call.
312-
*/
313-
pushq %rsi
314-
call l5_paging_required
315-
popq %rsi
316-
317-
/* If l5_paging_required() returned zero, we're done here. */
318-
cmpq $0, %rax
319-
je lvl5
320-
321307
/*
322308
* At this point we are in long mode with 4-level paging enabled,
323309
* but we want to enable 5-level paging.
324310
*
325311
* The problem is that we cannot do it directly. Setting LA57 in
326312
* long mode would trigger #GP. So we need to switch off long mode
327313
* first.
314+
*/
315+
316+
/*
317+
* paging_prepare() sets up the trampoline and checks if we need to
318+
* enable 5-level paging.
328319
*
329-
* NOTE: This is not going to work if bootloader put us above 4G
330-
* limit.
320+
* Address of the trampoline is returned in RAX.
321+
* Non zero RDX on return means we need to enable 5-level paging.
331322
*
332-
* The first step is go into compatibility mode.
323+
* RSI holds real mode data and needs to be preserved across
324+
* this function call.
333325
*/
326+
pushq %rsi
327+
call paging_prepare
328+
popq %rsi
329+
330+
/* Save the trampoline address in RCX */
331+
movq %rax, %rcx
332+
333+
/* Check if we need to enable 5-level paging */
334+
cmpq $0, %rdx
335+
jz lvl5
334336

335337
/* Clear additional page table */
336338
leaq lvl5_pgtable(%rbx), %rdi
@@ -352,7 +354,6 @@ ENTRY(startup_64)
352354
pushq %rax
353355
lretq
354356
lvl5:
355-
#endif
356357

357358
/* Zero EFLAGS */
358359
pushq $0
@@ -490,7 +491,6 @@ relocated:
490491
jmp *%rax
491492

492493
.code32
493-
#ifdef CONFIG_X86_5LEVEL
494494
compatible_mode:
495495
/* Setup data and stack segments */
496496
movl $__KERNEL_DS, %eax
@@ -526,7 +526,6 @@ compatible_mode:
526526
movl %eax, %cr0
527527

528528
lret
529-
#endif
530529

531530
no_longmode:
532531
/* This isn't an x86-64 CPU so hang */
@@ -585,7 +584,5 @@ boot_stack_end:
585584
.balign 4096
586585
pgtable:
587586
.fill BOOT_PGT_SIZE, 1, 0
588-
#ifdef CONFIG_X86_5LEVEL
589587
lvl5_pgtable:
590588
.fill PAGE_SIZE, 1, 0
591-
#endif

arch/x86/boot/compressed/pgtable_64.c

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,19 @@
99
*/
1010
unsigned long __force_order;
1111

12-
int l5_paging_required(void)
13-
{
14-
/* Check if leaf 7 is supported. */
15-
16-
if (native_cpuid_eax(0) < 7)
17-
return 0;
12+
struct paging_config {
13+
unsigned long trampoline_start;
14+
unsigned long l5_required;
15+
};
1816

19-
/* Check if la57 is supported. */
20-
if (!(native_cpuid_ecx(7) & (1 << (X86_FEATURE_LA57 & 31))))
21-
return 0;
17+
struct paging_config paging_prepare(void)
18+
{
19+
struct paging_config paging_config = {};
2220

23-
/* Check if 5-level paging has already been enabled. */
24-
if (native_read_cr4() & X86_CR4_LA57)
25-
return 0;
21+
/* Check if LA57 is desired and supported */
22+
if (IS_ENABLED(CONFIG_X86_5LEVEL) && native_cpuid_eax(0) >= 7 &&
23+
(native_cpuid_ecx(7) & (1 << (X86_FEATURE_LA57 & 31))))
24+
paging_config.l5_required = 1;
2625

27-
return 1;
26+
return paging_config;
2827
}

0 commit comments

Comments
 (0)