From nobody Wed Feb 5 17:06:27 2025 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 06A7A1D6DD4 for ; Wed, 15 Jan 2025 19:14:45 +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=1736968487; cv=none; b=KCy8c9HPJSFMBC8HrmlQPDayFeRvI1Rz1CQJLVFFEEa9VOUnO9vR2057H25NL01kdw0/xzI8wpEj57NEPRWClitmSdnJrv8xUlq0EJuXp6J6nmpJx10gftR9TpJIaI6yrrtY8CXbxdOOlzCE24RI/0P3tKKFLNqwPv3foeQub9w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736968487; c=relaxed/simple; bh=3gv0x7Zem4Zmes+1DaHZKUreg4e5P9Bw/NMYo6CRLis=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=WTTHpq3Sio2UyJbTmUAn7/ZHyHmemK1YSEDobRpQ82FKSQPPe865Qqoh1MF3AIy9ffYuJ0wUwOwfyZIDiCVtcpYNOcTtGS/S/4c0YgtjZCiDdEl1ZMAu0J0un9DaV0O1s2w/NwxrSE7StGqB/lc7PK+FgEl6N8MYA9YP22J/I38= 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=CmJydDU/; 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="CmJydDU/" 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=gSlCkcjgZBWAkesEhGWssA+8sh3qmIYNjsyEtgrDo9o=; b=CmJydDU/dAvjj4CnxjPLH6YzMp xL7tbn0ps9im7A6cSChwUu7TxpcKV0+MpI4IDFG868u6Mp00Ci1pPnFj5E4xWxaRnzp9Vy6kTJykI KWDB0XphijgmIpsYjCOZnA7j75hLVXzWlP37SefhuHRFM2hdEa7z8EFjVjYpQUQP3CgjIhYQo8ieP 00mwG9JQJyLXAp5LFTESxbaMo21zpkMi5O5hVivkOy9QwQIO6m2z1RlJfJgIiXV6vsVvVdfy39AGQ Hx3kIsIk2X40EJzhRF96dxqQCBDrAODLkAIe1Tc0wXNVeinWMWTR/uQkq0l0YVpW33Ghst0qneIqJ 0QrbJaUQ==; 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 1tY8qS-0000000AvMc-07ML; Wed, 15 Jan 2025 19:14:29 +0000 Received: from dwoodhou by i7.infradead.org with local (Exim 4.98 #2 (Red Hat Linux)) id 1tY8qO-00000002Uvx-3ogr; Wed, 15 Jan 2025 19:14:24 +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: [PATCH v6 2/7] x86/kexec: Debugging support: load a GDT Date: Wed, 15 Jan 2025 19:09:31 +0000 Message-ID: <20250115191423.587774-3-dwmw2@infradead.org> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20250115191423.587774-1-dwmw2@infradead.org> References: <20250115191423.587774-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 af2cd06ff318..c62f03808f18 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) @@ -115,6 +127,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