From nobody Tue Feb 10 06:25:06 2026 Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) (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 CB3641DFE3C for ; Fri, 22 Nov 2024 22:47:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=90.155.92.199 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732315675; cv=none; b=pje/MrAUwtY4sRxP251M6Nv8coImQBw/nL3nwvGHC0qDAeyglwIdmpGwQCE3wiHN2zGQD4xC1fSOhGG/gTDyYGupxF5NYfEqJR+Ixlo2fpecPsK6DnB01Xk2AoAC7oOKBsEkd8iRwGqTt//Z5SHVzNStLCV6wfOIRqZahIIfDok= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732315675; c=relaxed/simple; bh=78bUkO/aNPFK2xJZsagiCKKRakQWzU9ImoWzrpNtIjE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=MQzuk+gnip5mB7l0hzf3JmRGx/wHAQ+3/soloiv+6ifdtSfWDaK4XGfcIvKkjngTyMrSARGr2C0/i8WZwPim1ryv2kt4oyS7vxMCEwUm0P97BN9GjjBkSzcIV9cLuutqb370XecrFjWTM0XqPQ3Ngam7a4p8uIdC/66FYk0Rv/Y= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org; spf=none smtp.mailfrom=desiato.srs.infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=rF3QGRXP; arc=none smtp.client-ip=90.155.92.199 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=desiato.srs.infradead.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="rF3QGRXP" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; 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=PM8M+JIu8uZjpEQfel8bzCRRPJYH7fSk33eUzo/nnU0=; b=rF3QGRXPlEJmi4zzK2yeUu9q6o +MQhF7dc6fsRF6mRBksfr6ZvhnvFHLqOWro4HxxT9Hktex8e2Gln1L/BAKF3gBBgvhqyPCF8NdkZD rTi5X/0XG2g//sjIrvTY4H4+ma2j9wmoDBw7Kgvlfz1NXdneyys8+DIntjjw5n50wU83wapX1neYI CVvTFerkxoO86GxLLykO44W5BSwliMZWG8BijcOvUijggdAdJcpYRJI7cie73Meo0VV5f35wwwFh7 HjpwpSnPNO3TYvLqI1aQ34kgOF/xAqYvlDGif8EullkmJtpGzcR44F/Jt9spM5/p7NS9qaJZWGGr7 q7fa0QIQ==; Received: from [2001:8b0:10b:1::ebe] (helo=i7.infradead.org) by desiato.infradead.org with esmtpsa (Exim 4.98 #2 (Red Hat Linux)) id 1tEcQv-00000000maL-3C75; Fri, 22 Nov 2024 22:47:36 +0000 Received: from dwoodhou by i7.infradead.org with local (Exim 4.98 #2 (Red Hat Linux)) id 1tEcQp-00000000iid-1guO; Fri, 22 Nov 2024 22:47:19 +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 Subject: [RFC PATCH v2 13/16] x86/kexec: Debugging support: load a GDT Date: Fri, 22 Nov 2024 22:38:22 +0000 Message-ID: <20241122224715.171751-14-dwmw2@infradead.org> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241122224715.171751-1-dwmw2@infradead.org> References: <20241122224715.171751-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 desiato.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 51dc55ac4395..5c174829f794 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 DEBUG +SYM_DATA_START_LOCAL(reloc_kernel_gdt) + .balign 16 + .word reloc_kernel_gdt_end - reloc_kernel_gdt - 1 + .long 0 + .word 0 + .quad 0x00cf9a000000ffff /* __KERNEL32_CS */ + .quad 0x00af9a000000ffff /* __KERNEL_CS */ + .quad 0x00cf92000000ffff /* __KERNEL_DS */ +SYM_DATA_END_LABEL(reloc_kernel_gdt, SYM_L_LOCAL, reloc_kernel_gdt_end) +#endif /* 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 DEBUG + /* Create a GDTR (16 bits limit, 64 bits addr) on stack */ + leaq reloc_kernel_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 /* DEBUG */ + /* * Clear X86_CR4_CET (if it was set) such that we can clear CR0_WP * below. --=20 2.47.0