mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Baskov Evgeniy <baskov@ispras.ru>
To: Ard Biesheuvel <ardb@kernel.org>
Cc: Baskov Evgeniy <baskov@ispras.ru>, Borislav Petkov <bp@alien8.de>,
	Dave Hansen <dave.hansen@linux.intel.com>,
	Ingo Molnar <mingo@redhat.com>, Jonathan Corbet <corbet@lwn.net>,
	Thomas Gleixner <tglx@linutronix.de>,
	x86@kernel.org, linux-doc@vger.kernel.org,
	linux-efi@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH RFC 2/5] efi/x86_64: set page table if provided by libstub
Date: Wed, 10 Nov 2021 13:46:10 +0300	[thread overview]
Message-ID: <20211110104613.23881-3-baskov@ispras.ru> (raw)
In-Reply-To: <20211110104613.23881-1-baskov@ispras.ru>

It is desired to be able to switch pages tables before jumping
to potentially relocated code while booting via UEFI.
The easiest way to achieve that is to do it in assembly
immediately after returning from efi_main().

Add mechanism to switch page table to one provided by libstub.

Signed-off-by: Baskov Evgeniy <baskov@ispras.ru>
---
 arch/x86/boot/compressed/head_64.S | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/arch/x86/boot/compressed/head_64.S b/arch/x86/boot/compressed/head_64.S
index 572c535cf45b..1e467fdefd9d 100644
--- a/arch/x86/boot/compressed/head_64.S
+++ b/arch/x86/boot/compressed/head_64.S
@@ -540,6 +540,17 @@ SYM_FUNC_START_ALIAS(efi_stub_entry)
 	movq	%rdx, %rbx			/* save boot_params pointer */
 	call	efi_main
 	movq	%rbx,%rsi
+
+	/*
+	 * Switch page table to the one constructed by libstub if provided
+	 * It is required to be done here because stack is not mapped
+	 * in new page table.
+	 */
+	movq	efi_temp_pgtable(%rip), %rbx
+	testq	%rbx, %rbx
+	jz	1f
+	movq	%rbx, %cr3
+1:
 	leaq	rva(startup_64)(%rax), %rax
 	jmp	*%rax
 SYM_FUNC_END(efi64_stub_entry)
@@ -736,6 +747,7 @@ SYM_DATA_END_LABEL(boot32_idt, SYM_L_GLOBAL, boot32_idt_end)
 
 #ifdef CONFIG_EFI_STUB
 SYM_DATA(image_offset, .long 0)
+SYM_DATA(efi_temp_pgtable, .quad 0)
 #endif
 #ifdef CONFIG_EFI_MIXED
 SYM_DATA_LOCAL(efi32_boot_args, .long 0, 0, 0)
-- 
2.33.1


  parent reply	other threads:[~2021-11-10 10:57 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-10 10:46 [PATCH RFC 0/5] Handle UEFI NX-restricted page tables Baskov Evgeniy
2021-11-10 10:46 ` [PATCH RFC 1/5] efi/x86: Disable paging when booting via efistub Baskov Evgeniy
2021-11-10 10:46 ` Baskov Evgeniy [this message]
2021-11-10 10:46 ` [PATCH RFC 3/5] libstub: build temporary page table without NX-bit Baskov Evgeniy
2021-11-10 10:46 ` [PATCH RFC 4/5] efi: Add option for handling efi memory protection Baskov Evgeniy
2021-11-10 10:46 ` [PATCH RFC 5/5] Docs: document notemppt option Baskov Evgeniy
2021-11-10 11:11 ` [PATCH RFC 0/5] Handle UEFI NX-restricted page tables Ard Biesheuvel
2021-11-25  7:36   ` baskov
2021-12-16 17:30     ` Ard Biesheuvel

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=20211110104613.23881-3-baskov@ispras.ru \
    --to=baskov@ispras.ru \
    --cc=ardb@kernel.org \
    --cc=bp@alien8.de \
    --cc=corbet@lwn.net \
    --cc=dave.hansen@linux.intel.com \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-efi@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=tglx@linutronix.de \
    --cc=x86@kernel.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

all inboxes | Powered by JetHome®