Skip to content

Commit 918a7a0

Browse files
ardbiesheuvelbp3tk0v
authored andcommitted
x86/decompressor: Use standard calling convention for trampoline
Update the trampoline code so its arguments are passed via RDI and RSI, which matches the ordinary SysV calling convention for x86_64. This will allow this code to be called directly from C. Signed-off-by: Ard Biesheuvel <[email protected]> Signed-off-by: Borislav Petkov (AMD) <[email protected]> Acked-by: Kirill A. Shutemov <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent e8972a7 commit 918a7a0

File tree

2 files changed

+14
-15
lines changed

2 files changed

+14
-15
lines changed

arch/x86/boot/compressed/head_64.S

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -444,9 +444,9 @@ SYM_CODE_START(startup_64)
444444
movq %r15, %rdi
445445
call paging_prepare
446446

447-
/* Save the trampoline address in RCX */
448-
movq %rax, %rcx
449-
447+
/* Pass the trampoline address and boolean flag as args #1 and #2 */
448+
movq %rax, %rdi
449+
movq %rdx, %rsi
450450
leaq TRAMPOLINE_32BIT_CODE_OFFSET(%rax), %rax
451451
call *%rax
452452

@@ -531,11 +531,14 @@ SYM_FUNC_START_LOCAL_NOALIGN(.Lrelocated)
531531
SYM_FUNC_END(.Lrelocated)
532532

533533
/*
534-
* This is the 32-bit trampoline that will be copied over to low memory.
534+
* This is the 32-bit trampoline that will be copied over to low memory. It
535+
* will be called using the ordinary 64-bit calling convention from code
536+
* running in 64-bit mode.
535537
*
536538
* Return address is at the top of the stack (might be above 4G).
537-
* ECX contains the base address of the trampoline memory.
538-
* Non zero RDX means trampoline needs to enable 5-level paging.
539+
* The first argument (EDI) contains the 32-bit addressable base of the
540+
* trampoline memory. A non-zero second argument (ESI) means that the
541+
* trampoline needs to enable 5-level paging.
539542
*/
540543
SYM_CODE_START(trampoline_32bit_src)
541544
/*
@@ -582,7 +585,7 @@ SYM_CODE_START(trampoline_32bit_src)
582585
movl %eax, %cr0
583586

584587
/* Check what paging mode we want to be in after the trampoline */
585-
testl %edx, %edx
588+
testl %esi, %esi
586589
jz 1f
587590

588591
/* We want 5-level paging: don't touch CR3 if it already points to 5-level page tables */
@@ -597,21 +600,17 @@ SYM_CODE_START(trampoline_32bit_src)
597600
jz 3f
598601
2:
599602
/* Point CR3 to the trampoline's new top level page table */
600-
leal TRAMPOLINE_32BIT_PGTABLE_OFFSET(%ecx), %eax
603+
leal TRAMPOLINE_32BIT_PGTABLE_OFFSET(%edi), %eax
601604
movl %eax, %cr3
602605
3:
603606
/* Set EFER.LME=1 as a precaution in case hypervsior pulls the rug */
604-
pushl %ecx
605-
pushl %edx
606607
movl $MSR_EFER, %ecx
607608
rdmsr
608609
btsl $_EFER_LME, %eax
609610
/* Avoid writing EFER if no change was made (for TDX guest) */
610611
jc 1f
611612
wrmsr
612-
1: popl %edx
613-
popl %ecx
614-
613+
1:
615614
#ifdef CONFIG_X86_MCE
616615
/*
617616
* Preserve CR4.MCE if the kernel will enable #MC support.
@@ -628,7 +627,7 @@ SYM_CODE_START(trampoline_32bit_src)
628627

629628
/* Enable PAE and LA57 (if required) paging modes */
630629
orl $X86_CR4_PAE, %eax
631-
testl %edx, %edx
630+
testl %esi, %esi
632631
jz 1f
633632
orl $X86_CR4_LA57, %eax
634633
1:

arch/x86/boot/compressed/pgtable.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
extern unsigned long *trampoline_32bit;
1616

17-
extern void trampoline_32bit_src(void *return_ptr);
17+
extern void trampoline_32bit_src(void *trampoline, bool enable_5lvl);
1818

1919
#endif /* __ASSEMBLER__ */
2020
#endif /* BOOT_COMPRESSED_PAGETABLE_H */

0 commit comments

Comments
 (0)