public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Ard Biesheuvel <ardb@kernel.org>
To: linux-efi@vger.kernel.org
Cc: linux-kernel@vger.kernel.org, Ard Biesheuvel <ardb@kernel.org>,
	Evgeniy Baskov <baskov@ispras.ru>, Borislav Petkov <bp@alien8.de>,
	Andy Lutomirski <luto@kernel.org>,
	Dave Hansen <dave.hansen@linux.intel.com>,
	Ingo Molnar <mingo@redhat.com>,
	Peter Zijlstra <peterz@infradead.org>,
	Thomas Gleixner <tglx@linutronix.de>,
	Alexey Khoroshilov <khoroshilov@ispras.ru>,
	Peter Jones <pjones@redhat.com>,
	Gerd Hoffmann <kraxel@redhat.com>, Dave Young <dyoung@redhat.com>,
	Mario Limonciello <mario.limonciello@amd.com>,
	Kees Cook <keescook@chromium.org>,
	Tom Lendacky <thomas.lendacky@amd.com>,
	"Kirill A . Shutemov" <kirill.shutemov@linux.intel.com>,
	Linus Torvalds <torvalds@linux-foundation.org>,
	Joerg Roedel <jroedel@suse.de>
Subject: [PATCH v7 02/22] x86/head_64: Store boot_params pointer in callee save register
Date: Fri, 28 Jul 2023 11:08:56 +0200	[thread overview]
Message-ID: <20230728090916.1538550-3-ardb@kernel.org> (raw)
In-Reply-To: <20230728090916.1538550-1-ardb@kernel.org>

Instead of pushing/popping %RSI to/from the stack every time a function
is called from startup_64(), store it in a callee preserved register
and grab it from there when its value is actually needed.

Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
---
 arch/x86/kernel/head_64.S | 23 +++++---------------
 1 file changed, 5 insertions(+), 18 deletions(-)

diff --git a/arch/x86/kernel/head_64.S b/arch/x86/kernel/head_64.S
index c5b9289837dcbad2..dbc80fe098f86860 100644
--- a/arch/x86/kernel/head_64.S
+++ b/arch/x86/kernel/head_64.S
@@ -62,6 +62,7 @@ SYM_CODE_START_NOALIGN(startup_64)
 	 * compiled to run at we first fixup the physical addresses in our page
 	 * tables and then reload them.
 	 */
+	mov	%rsi, %r15		/* Preserve boot_params pointer */
 
 	/* Set up the stack for verify_cpu() */
 	leaq	(__end_init_task - PTREGS_SIZE)(%rip), %rsp
@@ -75,9 +76,7 @@ SYM_CODE_START_NOALIGN(startup_64)
 	shrq	$32,  %rdx
 	wrmsr
 
-	pushq	%rsi
 	call	startup_64_setup_env
-	popq	%rsi
 
 	/* Now switch to __KERNEL_CS so IRET works reliably */
 	pushq	$__KERNEL_CS
@@ -95,10 +94,8 @@ SYM_CODE_START_NOALIGN(startup_64)
 	 * which needs to be done before any CPUID instructions are executed in
 	 * subsequent code.
 	 */
-	movq	%rsi, %rdi
-	pushq	%rsi
+	movq	%r15, %rdi		/* Pass boot_params pointer */
 	call	sme_enable
-	popq	%rsi
 #endif
 
 	/* Sanitize CPU configuration */
@@ -111,9 +108,7 @@ SYM_CODE_START_NOALIGN(startup_64)
 	 * programmed into CR3.
 	 */
 	leaq	_text(%rip), %rdi
-	pushq	%rsi
 	call	__startup_64
-	popq	%rsi
 
 	/* Form the CR3 value being sure to include the CR3 modifier */
 	addq	$(early_top_pgt - __START_KERNEL_map), %rax
@@ -127,8 +122,6 @@ SYM_CODE_START(secondary_startup_64)
 	 * At this point the CPU runs in 64bit mode CS.L = 1 CS.D = 0,
 	 * and someone has loaded a mapped page table.
 	 *
-	 * %rsi holds a physical pointer to real_mode_data.
-	 *
 	 * We come here either from startup_64 (using physical addresses)
 	 * or from trampoline.S (using virtual addresses).
 	 *
@@ -153,6 +146,8 @@ SYM_INNER_LABEL(secondary_startup_64_no_verify, SYM_L_GLOBAL)
 	UNWIND_HINT_END_OF_STACK
 	ANNOTATE_NOENDBR
 
+	xorq	%r15, %r15		/* Clear boot_params pointer */
+
 	/*
 	 * Retrieve the modifier (SME encryption mask if SME is active) to be
 	 * added to the initial pgdir entry that will be programmed into CR3.
@@ -199,13 +194,9 @@ SYM_INNER_LABEL(secondary_startup_64_no_verify, SYM_L_GLOBAL)
 	 * hypervisor could lie about the C-bit position to perform a ROP
 	 * attack on the guest by writing to the unencrypted stack and wait for
 	 * the next RET instruction.
-	 * %rsi carries pointer to realmode data and is callee-clobbered. Save
-	 * and restore it.
 	 */
-	pushq	%rsi
 	movq	%rax, %rdi
 	call	sev_verify_cbit
-	popq	%rsi
 
 	/*
 	 * Switch to new page-table
@@ -365,9 +356,7 @@ SYM_INNER_LABEL(secondary_startup_64_no_verify, SYM_L_GLOBAL)
 	wrmsr
 
 	/* Setup and Load IDT */
-	pushq	%rsi
 	call	early_setup_idt
-	popq	%rsi
 
 	/* Check if nx is implemented */
 	movl	$0x80000001, %eax
@@ -403,9 +392,7 @@ SYM_INNER_LABEL(secondary_startup_64_no_verify, SYM_L_GLOBAL)
 	pushq $0
 	popfq
 
-	/* rsi is pointer to real mode structure with interesting info.
-	   pass it to C */
-	movq	%rsi, %rdi
+	movq	%r15, %rdi		/* Pass boot_params pointer */
 
 .Ljump_to_C_code:
 	/*
-- 
2.39.2


  parent reply	other threads:[~2023-07-28  9:14 UTC|newest]

Thread overview: 41+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-07-28  9:08 [PATCH v7 00/22] efi/x86: Avoid bare metal decompressor during EFI boot Ard Biesheuvel
2023-07-28  9:08 ` [PATCH v7 01/22] x86/decompressor: Don't rely on upper 32 bits of GPRs being preserved Ard Biesheuvel
2023-07-31 10:07   ` Borislav Petkov
2023-07-31 10:09     ` Ard Biesheuvel
2023-07-31 11:01       ` Borislav Petkov
2023-07-28  9:08 ` Ard Biesheuvel [this message]
2023-08-01 11:28   ` [PATCH v7 02/22] x86/head_64: Store boot_params pointer in callee save register Borislav Petkov
2023-07-28  9:08 ` [PATCH v7 03/22] x86/efistub: Branch straight to kernel entry point from C code Ard Biesheuvel
2023-07-28  9:08 ` [PATCH v7 04/22] x86/efistub: Simplify and clean up handover entry code Ard Biesheuvel
2023-07-28  9:08 ` [PATCH v7 05/22] x86/decompressor: Avoid magic offsets for EFI handover entrypoint Ard Biesheuvel
2023-07-28  9:09 ` [PATCH v7 06/22] x86/efistub: Clear BSS in EFI handover protocol entrypoint Ard Biesheuvel
2023-07-28  9:09 ` [PATCH v7 07/22] x86/decompressor: Use proper sequence to take the address of the GOT Ard Biesheuvel
2023-07-28  9:09 ` [PATCH v7 08/22] x86/decompressor: Store boot_params pointer in callee save register Ard Biesheuvel
2023-07-28  9:09 ` [PATCH v7 09/22] x86/decompressor: Call trampoline as a normal function Ard Biesheuvel
2023-07-28  9:09 ` [PATCH v7 10/22] x86/decompressor: Use standard calling convention for trampoline Ard Biesheuvel
2023-07-31 11:28   ` Borislav Petkov
2023-07-31 11:35     ` Ard Biesheuvel
2023-07-28  9:09 ` [PATCH v7 11/22] x86/decompressor: Avoid the need for a stack in the 32-bit trampoline Ard Biesheuvel
2023-08-01 10:30   ` Borislav Petkov
2023-07-28  9:09 ` [PATCH v7 12/22] x86/decompressor: Call trampoline directly from C code Ard Biesheuvel
2023-08-01 11:45   ` Borislav Petkov
2023-08-01 11:48     ` Ard Biesheuvel
2023-08-01 11:51       ` Borislav Petkov
2023-07-28  9:09 ` [PATCH v7 13/22] x86/decompressor: Only call the trampoline when changing paging levels Ard Biesheuvel
2023-07-28  9:09 ` [PATCH v7 14/22] x86/decompressor: Merge trampoline cleanup with switching code Ard Biesheuvel
2023-08-01 12:08   ` Borislav Petkov
2023-08-01 12:11     ` Ard Biesheuvel
2023-08-01 12:40       ` Borislav Petkov
2023-08-01 12:46         ` Ard Biesheuvel
2023-08-01 13:04           ` Borislav Petkov
2023-07-28  9:09 ` [PATCH v7 15/22] x86/efistub: Perform 4/5 level paging switch from the stub Ard Biesheuvel
2023-07-28  9:09 ` [PATCH v7 16/22] x86/efistub: Prefer EFI memory attributes protocol over DXE services Ard Biesheuvel
2023-07-28  9:09 ` [PATCH v7 17/22] decompress: Use 8 byte alignment Ard Biesheuvel
2023-07-28  9:09 ` [PATCH v7 18/22] x86/decompressor: Move global symbol references to C code Ard Biesheuvel
2023-07-28  9:09 ` [PATCH v7 19/22] x86/decompressor: Factor out kernel decompression and relocation Ard Biesheuvel
2023-07-28  9:09 ` [PATCH v7 20/22] efi/libstub: Add limit argument to efi_random_alloc() Ard Biesheuvel
2023-07-28  9:09 ` [PATCH v7 21/22] x86/efistub: Perform SNP feature test while running in the firmware Ard Biesheuvel
2023-07-28  9:09 ` [PATCH v7 22/22] x86/efistub: Avoid legacy decompressor when doing EFI boot Ard Biesheuvel
2023-08-02 10:26   ` Borislav Petkov
2023-08-02 10:47     ` Ard Biesheuvel
2023-08-02 15:55       ` Borislav Petkov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230728090916.1538550-3-ardb@kernel.org \
    --to=ardb@kernel.org \
    --cc=baskov@ispras.ru \
    --cc=bp@alien8.de \
    --cc=dave.hansen@linux.intel.com \
    --cc=dyoung@redhat.com \
    --cc=jroedel@suse.de \
    --cc=keescook@chromium.org \
    --cc=khoroshilov@ispras.ru \
    --cc=kirill.shutemov@linux.intel.com \
    --cc=kraxel@redhat.com \
    --cc=linux-efi@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=luto@kernel.org \
    --cc=mario.limonciello@amd.com \
    --cc=mingo@redhat.com \
    --cc=peterz@infradead.org \
    --cc=pjones@redhat.com \
    --cc=tglx@linutronix.de \
    --cc=thomas.lendacky@amd.com \
    --cc=torvalds@linux-foundation.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox