mirror of
https://github.com/hardkernel/linux.git
synced 2026-06-05 10:31:46 +09:00
x86/boot/compressed: Move startup32_check_sev_cbit() into .text
commit b5d854cd4b upstream.
Move startup32_check_sev_cbit() into the .text section and turn it into
an ordinary function using the ordinary 32-bit calling convention,
instead of saving/restoring the registers that are known to be live at
the only call site. This improves maintainability, and makes it possible
to move this function out of head_64.S and into a separate compilation
unit that is specific to memory encryption.
Note that this requires the call site to be moved before the mixed mode
check, as %eax will be live otherwise.
Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Borislav Petkov <bp@suse.de>
Link: https://lore.kernel.org/r/20221122161017.2426828-14-ardb@kernel.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
committed by
Greg Kroah-Hartman
parent
801873f175
commit
e840ae3dc2
@@ -251,6 +251,11 @@ SYM_FUNC_START(startup_32)
|
|||||||
movl $__BOOT_TSS, %eax
|
movl $__BOOT_TSS, %eax
|
||||||
ltr %ax
|
ltr %ax
|
||||||
|
|
||||||
|
#ifdef CONFIG_AMD_MEM_ENCRYPT
|
||||||
|
/* Check if the C-bit position is correct when SEV is active */
|
||||||
|
call startup32_check_sev_cbit
|
||||||
|
#endif
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Setup for the jump to 64bit mode
|
* Setup for the jump to 64bit mode
|
||||||
*
|
*
|
||||||
@@ -268,8 +273,6 @@ SYM_FUNC_START(startup_32)
|
|||||||
leal rva(startup_64_mixed_mode)(%ebp), %eax
|
leal rva(startup_64_mixed_mode)(%ebp), %eax
|
||||||
1:
|
1:
|
||||||
#endif
|
#endif
|
||||||
/* Check if the C-bit position is correct when SEV is active */
|
|
||||||
call startup32_check_sev_cbit
|
|
||||||
|
|
||||||
pushl $__KERNEL_CS
|
pushl $__KERNEL_CS
|
||||||
pushl %eax
|
pushl %eax
|
||||||
@@ -740,16 +743,17 @@ SYM_DATA_END_LABEL(boot_idt, SYM_L_GLOBAL, boot_idt_end)
|
|||||||
* succeed. An incorrect C-bit position will map all memory unencrypted, so that
|
* succeed. An incorrect C-bit position will map all memory unencrypted, so that
|
||||||
* the compare will use the encrypted random data and fail.
|
* the compare will use the encrypted random data and fail.
|
||||||
*/
|
*/
|
||||||
__HEAD
|
|
||||||
SYM_FUNC_START(startup32_check_sev_cbit)
|
|
||||||
#ifdef CONFIG_AMD_MEM_ENCRYPT
|
#ifdef CONFIG_AMD_MEM_ENCRYPT
|
||||||
pushl %eax
|
.text
|
||||||
|
SYM_FUNC_START(startup32_check_sev_cbit)
|
||||||
pushl %ebx
|
pushl %ebx
|
||||||
pushl %ecx
|
pushl %ebp
|
||||||
pushl %edx
|
|
||||||
|
call 0f
|
||||||
|
0: popl %ebp
|
||||||
|
|
||||||
/* Check for non-zero sev_status */
|
/* Check for non-zero sev_status */
|
||||||
movl rva(sev_status)(%ebp), %eax
|
movl (sev_status - 0b)(%ebp), %eax
|
||||||
testl %eax, %eax
|
testl %eax, %eax
|
||||||
jz 4f
|
jz 4f
|
||||||
|
|
||||||
@@ -764,17 +768,18 @@ SYM_FUNC_START(startup32_check_sev_cbit)
|
|||||||
jnc 2b
|
jnc 2b
|
||||||
|
|
||||||
/* Store to memory and keep it in the registers */
|
/* Store to memory and keep it in the registers */
|
||||||
movl %eax, rva(sev_check_data)(%ebp)
|
leal (sev_check_data - 0b)(%ebp), %ebp
|
||||||
movl %ebx, rva(sev_check_data+4)(%ebp)
|
movl %eax, 0(%ebp)
|
||||||
|
movl %ebx, 4(%ebp)
|
||||||
|
|
||||||
/* Enable paging to see if encryption is active */
|
/* Enable paging to see if encryption is active */
|
||||||
movl %cr0, %edx /* Backup %cr0 in %edx */
|
movl %cr0, %edx /* Backup %cr0 in %edx */
|
||||||
movl $(X86_CR0_PG | X86_CR0_PE), %ecx /* Enable Paging and Protected mode */
|
movl $(X86_CR0_PG | X86_CR0_PE), %ecx /* Enable Paging and Protected mode */
|
||||||
movl %ecx, %cr0
|
movl %ecx, %cr0
|
||||||
|
|
||||||
cmpl %eax, rva(sev_check_data)(%ebp)
|
cmpl %eax, 0(%ebp)
|
||||||
jne 3f
|
jne 3f
|
||||||
cmpl %ebx, rva(sev_check_data+4)(%ebp)
|
cmpl %ebx, 4(%ebp)
|
||||||
jne 3f
|
jne 3f
|
||||||
|
|
||||||
movl %edx, %cr0 /* Restore previous %cr0 */
|
movl %edx, %cr0 /* Restore previous %cr0 */
|
||||||
@@ -786,13 +791,11 @@ SYM_FUNC_START(startup32_check_sev_cbit)
|
|||||||
jmp 3b
|
jmp 3b
|
||||||
|
|
||||||
4:
|
4:
|
||||||
popl %edx
|
popl %ebp
|
||||||
popl %ecx
|
|
||||||
popl %ebx
|
popl %ebx
|
||||||
popl %eax
|
|
||||||
#endif
|
|
||||||
RET
|
RET
|
||||||
SYM_FUNC_END(startup32_check_sev_cbit)
|
SYM_FUNC_END(startup32_check_sev_cbit)
|
||||||
|
#endif
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Stack and heap for uncompression
|
* Stack and heap for uncompression
|
||||||
|
|||||||
Reference in New Issue
Block a user