mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "tip-bot2 for David Woodhouse" <tip-bot2@linutronix.de>
To: linux-tip-commits@vger.kernel.org
Cc: David Woodhouse <dwmw@amazon.co.uk>,
	Ingo Molnar <mingo@kernel.org>, Andy Lutomirski <luto@kernel.org>,
	Brian Gerst <brgerst@gmail.com>, "H. Peter Anvin" <hpa@zytor.com>,
	Kees Cook <keescook@chromium.org>,
	Ard Biesheuvel <ardb@kernel.org>,
	Linus Torvalds <torvalds@linux-foundation.org>,
	x86@kernel.org, linux-kernel@vger.kernel.org
Subject: [tip: x86/boot] x86/kexec: Add relocate_kernel() debugging support: Load a GDT
Date: Thu, 13 Mar 2025 10:42:16 -0000	[thread overview]
Message-ID: <174186253602.14745.9025061893846353110.tip-bot2@tip-bot2> (raw)
In-Reply-To: <20250312144257.2348250-2-dwmw2@infradead.org>

The following commit has been merged into the x86/boot branch of tip:

Commit-ID:     afb305d6831b930571b5413cec239289ef164b55
Gitweb:        https://git.kernel.org/tip/afb305d6831b930571b5413cec239289ef164b55
Author:        David Woodhouse <dwmw@amazon.co.uk>
AuthorDate:    Wed, 12 Mar 2025 14:34:13 
Committer:     Ingo Molnar <mingo@kernel.org>
CommitterDate: Thu, 13 Mar 2025 11:23:31 +01:00

x86/kexec: Add relocate_kernel() debugging support: Load a GDT

There are some failure modes which lead to triple-faults in the
relocate_kernel() function, which is fairly much undebuggable
for normal mortals.

Adding a GDT in the relocate_kernel() environment is step 1 towards
being able to catch faults and do something more useful.

Signed-off-by: David Woodhouse <dwmw@amazon.co.uk>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Brian Gerst <brgerst@gmail.com>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Kees Cook <keescook@chromium.org>
Cc: Ard Biesheuvel <ardb@kernel.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Link: https://lore.kernel.org/r/20250312144257.2348250-2-dwmw2@infradead.org
---
 arch/x86/kernel/relocate_kernel_64.S | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)

diff --git a/arch/x86/kernel/relocate_kernel_64.S b/arch/x86/kernel/relocate_kernel_64.S
index b44d886..ac05897 100644
--- a/arch/x86/kernel/relocate_kernel_64.S
+++ b/arch/x86/kernel/relocate_kernel_64.S
@@ -40,6 +40,16 @@ SYM_DATA(kexec_pa_table_page, .quad 0)
 SYM_DATA(kexec_pa_swap_page, .quad 0)
 SYM_DATA_LOCAL(pa_backup_pages_map, .quad 0)
 
+	.balign 16
+SYM_DATA_START_LOCAL(kexec_debug_gdt)
+	.word   kexec_debug_gdt_end - kexec_debug_gdt - 1
+	.long   0
+	.word   0
+	.quad   0x00cf9a000000ffff      /* __KERNEL32_CS */
+	.quad   0x00af9a000000ffff      /* __KERNEL_CS */
+	.quad   0x00cf92000000ffff      /* __KERNEL_DS */
+SYM_DATA_END_LABEL(kexec_debug_gdt, SYM_L_LOCAL, kexec_debug_gdt_end)
+
 	.section .text..relocate_kernel,"ax";
 	.code64
 SYM_CODE_START_NOALIGN(relocate_kernel)
@@ -116,6 +126,19 @@ SYM_CODE_START_LOCAL_NOALIGN(identity_mapped)
 	/* store the start address on the stack */
 	pushq   %rdx
 
+	/* Create a GDTR (16 bits limit, 64 bits addr) on stack */
+	leaq	kexec_debug_gdt(%rip), %rax
+	pushq	%rax
+	pushw	(%rax)
+
+	/* Load the GDT, put the stack back */
+	lgdt	(%rsp)
+	addq	$10, %rsp
+
+	/* Test that we can load segments */
+	movq	%ds, %rax
+	movq	%rax, %ds
+
 	/*
 	 * Clear X86_CR4_CET (if it was set) such that we can clear CR0_WP
 	 * below.

  reply	other threads:[~2025-03-13 10:42 UTC|newest]

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-03-12 14:34 [PATCH v7 0/8] x86/kexec: Add exception handling for relocate_kernel David Woodhouse
2025-03-12 14:34 ` [PATCH v7 1/8] x86/kexec: Debugging support: load a GDT David Woodhouse
2025-03-13 10:42   ` tip-bot2 for David Woodhouse [this message]
2025-03-14 10:16   ` [tip: x86/boot] x86/kexec: Add relocate_kernel() debugging support: Load " tip-bot2 for David Woodhouse
2025-03-12 14:34 ` [PATCH v7 2/8] x86/kexec: Debugging support: Load an IDT and basic exception entry points David Woodhouse
2025-03-13 10:42   ` [tip: x86/boot] x86/kexec: Add relocate_kernel() debugging " tip-bot2 for David Woodhouse
2025-03-12 14:34 ` [PATCH v7 3/8] x86/kexec: Debugging support: Dump registers on exception David Woodhouse
2025-03-13 10:42   ` [tip: x86/boot] x86/kexec: Add relocate_kernel() debugging " tip-bot2 for David Woodhouse
2025-03-12 14:34 ` [PATCH v7 4/8] x86/kexec: Add 8250 serial port output David Woodhouse
2025-03-13 10:35   ` Ingo Molnar
2025-03-12 14:34 ` [PATCH v7 5/8] x86/kexec: Add 8250 MMIO " David Woodhouse
2025-03-12 14:34 ` [PATCH v7 6/8] x86/kexec: Invalidate GDT/IDT from relocate_kernel() instead of earlier David Woodhouse
2025-03-12 14:34 ` [PATCH v7 7/8] [DO NOT MERGE] x86/kexec: Add int3 in kexec path for testing David Woodhouse
2025-03-13 10:44   ` Ingo Molnar
2025-03-13 11:06     ` David Woodhouse
2025-03-13 17:06       ` Ingo Molnar
2025-03-13 18:38         ` David Woodhouse
2025-03-12 14:34 ` [PATCH v7 8/8] [DO NOT MERGE] x86/kexec: Add CFI type information to relocate_kernel() David Woodhouse
2025-03-14 16:07   ` Josh Poimboeuf
2025-03-14 17:23     ` David Woodhouse
2025-03-14 17:52       ` Josh Poimboeuf
2025-03-14 18:29         ` David Woodhouse
2025-03-17 12:40         ` David Woodhouse
2025-03-18  0:17           ` Josh Poimboeuf
2025-03-18  0:24             ` Josh Poimboeuf
2025-03-18 15:56               ` David Woodhouse
2025-03-18 17:14                 ` Josh Poimboeuf
2025-03-18 21:06                   ` David Woodhouse
2025-03-18 22:41                     ` Josh Poimboeuf
2025-03-19 13:04                       ` David Woodhouse
2025-03-19 15:47                         ` Josh Poimboeuf
2025-03-22 11:38                           ` David Woodhouse
2025-03-13 10:46 ` [PATCH v7 0/8] x86/kexec: Add exception handling for relocate_kernel Ingo Molnar
2025-03-13 10:54   ` Ingo Molnar
2025-03-13 19:58     ` David Woodhouse
2025-03-14  9:25       ` David Woodhouse
2025-03-14 10:21         ` Ingo Molnar
2025-03-14 10:37           ` David Woodhouse

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=174186253602.14745.9025061893846353110.tip-bot2@tip-bot2 \
    --to=tip-bot2@linutronix.de \
    --cc=ardb@kernel.org \
    --cc=brgerst@gmail.com \
    --cc=dwmw@amazon.co.uk \
    --cc=hpa@zytor.com \
    --cc=keescook@chromium.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-tip-commits@vger.kernel.org \
    --cc=luto@kernel.org \
    --cc=mingo@kernel.org \
    --cc=torvalds@linux-foundation.org \
    --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®