From nobody Mon Feb 9 19:38:00 2026 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5E622192B69 for ; Mon, 25 Nov 2024 10:08:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=90.155.50.34 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732529317; cv=none; b=W0HJNkuhdBdFc05wCzwkszzwiGvzfCdHVIV25+1HlfWDGzqG9/ZYStdXNWeMFVv8pwqK4qyUqREC6aFcdz3FWFhRukm3YCa11Nz2lsAzCUOGYafa5nD27rOfvRGKZbkmY/hvtzDpgKMHXZ/fn1qaUDYUvvwsGIwXBiD5Dt5CIC4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732529317; c=relaxed/simple; bh=623G9e0jeZ2RMFMd1YHMdaz5Es5e+KKYpgx8j02dSxU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=KJiSy+V+LdQqYREloNW8qG0gubXOy8nkcrHcEG0hk5tfEQrrtxxq2zA/wP7mH2hA2doJL+cbyBBBKGOeraAc1r2F7NHOyDOMopXk3E07aKz7yHjfKjVt79SEuem/bYn6pyWmC5ussiSRkHVntN/IPcafwLv8VkdnKAIp/itBCss= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org; spf=none smtp.mailfrom=casper.srs.infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=sxl6QURa; arc=none smtp.client-ip=90.155.50.34 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=casper.srs.infradead.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="sxl6QURa" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Sender:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description; bh=J05THXe+YRacmOzA8KfGrmyEonAyJGQ1gSBRrJydwjs=; b=sxl6QURaNSNHXgV2EZa/YhJBp2 ELnUr+nDBcu0tCux8+OEQzLOob8oKO9lp7hG8zgwb9RwEYnceSLvE+wqwXZBmgv9NY5dAT63Ogl2+ qRsKWXSUH/OoRNiquun7QJSILVsC5qcDqyw/S5VGAiWoHsEH1rs6tvLSOU3zNaq9MkozTcIpOZ9st xumVFD1zBEu+vR9HHmtJeY3Y5ZYeg9jo+gAipKOLjl7AzOyopmUuOuJabVOtZ3wzsGrVI1gcrkqao /qwweKruA6tTlR8OKg3tghUkQazjhenvys2J2Ff628uQnHKWblKl/FtHcmie69XtLikgMC9PUfkyM UNj8eV5g==; Received: from [2001:8b0:10b:1::ebe] (helo=i7.infradead.org) by casper.infradead.org with esmtpsa (Exim 4.98 #2 (Red Hat Linux)) id 1tFW10-0000000BirA-1LQq; Mon, 25 Nov 2024 10:08:23 +0000 Received: from dwoodhou by i7.infradead.org with local (Exim 4.98 #2 (Red Hat Linux)) id 1tFW0z-000000000le-3mDi; Mon, 25 Nov 2024 10:08:21 +0000 From: David Woodhouse To: kexec@lists.infradead.org Cc: Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , David Woodhouse , "Kirill A. Shutemov" , Kai Huang , Nikolay Borisov , linux-kernel@vger.kernel.org, Simon Horman , Dave Young , Peter Zijlstra , jpoimboe@kernel.org, bsz@amazon.de Subject: [RFC PATCH v3 16/20] x86/kexec: Debugging support: load a GDT Date: Mon, 25 Nov 2024 09:54:46 +0000 Message-ID: <20241125100815.2512-17-dwmw2@infradead.org> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241125100815.2512-1-dwmw2@infradead.org> References: <20241125100815.2512-1-dwmw2@infradead.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: David Woodhouse X-SRS-Rewrite: SMTP reverse-path rewritten from by casper.infradead.org. See http://www.infradead.org/rpr.html Content-Type: text/plain; charset="utf-8" From: David Woodhouse 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 --- arch/x86/kernel/relocate_kernel_64.S | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/arch/x86/kernel/relocate_kernel_64.S b/arch/x86/kernel/relocat= e_kernel_64.S index b24198eb1fe9..6c6bfdccfe6a 100644 --- a/arch/x86/kernel/relocate_kernel_64.S +++ b/arch/x86/kernel/relocate_kernel_64.S @@ -39,6 +39,18 @@ 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) =20 +#ifdef CONFIG_KEXEC_DEBUG + .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) +#endif /* CONFIG_KEXEC_DEBUG */ + .section .text.relocate_kernel,"ax"; .code64 SYM_CODE_START_NOALIGN(relocate_kernel) @@ -112,6 +124,21 @@ SYM_CODE_START_LOCAL_NOALIGN(identity_mapped) /* store the start address on the stack */ pushq %rdx =20 +#ifdef CONFIG_KEXEC_DEBUG + /* 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 +#endif /* CONFIG_KEXEC_DEBUG */ + /* * Clear X86_CR4_CET (if it was set) such that we can clear CR0_WP * below. --=20 2.47.0