Skip to content

Commit 03dda95

Browse files
ardbiesheuvelbp3tk0v
authored andcommitted
x86/decompressor: Merge trampoline cleanup with switching code
Now that the trampoline setup code and the actual invocation of it are all done from the C routine, the trampoline cleanup can be merged into it as well, instead of returning to asm just to call another C function. Signed-off-by: Ard Biesheuvel <ardb@kernel.org> Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de> Acked-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com> Link: https://lore.kernel.org/r/20230807162720.545787-16-ardb@kernel.org
1 parent cb83cec commit 03dda95

File tree

2 files changed

+8
-24
lines changed

2 files changed

+8
-24
lines changed

arch/x86/boot/compressed/head_64.S

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -430,20 +430,14 @@ SYM_CODE_START(startup_64)
430430
* a trampoline in 32-bit addressable memory if the current number does
431431
* not match the desired number.
432432
*
433-
* Pass the boot_params pointer as the first argument.
433+
* Pass the boot_params pointer as the first argument. The second
434+
* argument is the relocated address of the page table to use instead
435+
* of the page table in trampoline memory (if required).
434436
*/
435437
movq %r15, %rdi
438+
leaq rva(top_pgtable)(%rbx), %rsi
436439
call configure_5level_paging
437440

438-
/*
439-
* cleanup_trampoline() would restore trampoline memory.
440-
*
441-
* RDI is address of the page table to use instead of page table
442-
* in trampoline memory (if required).
443-
*/
444-
leaq rva(top_pgtable)(%rbx), %rdi
445-
call cleanup_trampoline
446-
447441
/* Zero EFLAGS */
448442
pushq $0
449443
popfq

arch/x86/boot/compressed/pgtable_64.c

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ static unsigned long find_trampoline_placement(void)
101101
return bios_start - TRAMPOLINE_32BIT_SIZE;
102102
}
103103

104-
asmlinkage void configure_5level_paging(struct boot_params *bp)
104+
asmlinkage void configure_5level_paging(struct boot_params *bp, void *pgtable)
105105
{
106106
void (*toggle_la57)(void *cr3);
107107
bool l5_required = false;
@@ -191,22 +191,12 @@ asmlinkage void configure_5level_paging(struct boot_params *bp)
191191
}
192192

193193
toggle_la57(trampoline_32bit);
194-
}
195-
196-
void cleanup_trampoline(void *pgtable)
197-
{
198-
void *trampoline_pgtable;
199-
200-
trampoline_pgtable = trampoline_32bit;
201194

202195
/*
203-
* Move the top level page table out of trampoline memory,
204-
* if it's there.
196+
* Move the top level page table out of trampoline memory.
205197
*/
206-
if ((void *)__native_read_cr3() == trampoline_pgtable) {
207-
memcpy(pgtable, trampoline_pgtable, PAGE_SIZE);
208-
native_write_cr3((unsigned long)pgtable);
209-
}
198+
memcpy(pgtable, trampoline_32bit, PAGE_SIZE);
199+
native_write_cr3((unsigned long)pgtable);
210200

211201
/* Restore trampoline memory */
212202
memcpy(trampoline_32bit, trampoline_save, TRAMPOLINE_32BIT_SIZE);

0 commit comments

Comments
 (0)