From nobody Tue Feb 10 04:03:24 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 6F9E3192B73 for ; Mon, 25 Nov 2024 10:08:35 +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=1732529317; cv=none; b=bgOQ+vf8GVY0IR6HU9hIt6Ldw73vIrPLwtDn3lA+ZKlhoMQ1kDXeTVzNu7La8y3d6jo/Bd6wsNv8l270qw5ZBJhjTxLMbmCjn/+6pSAiPbddwiy17PkGkHvZmzoaEjq9+/jkBUz0NUboZDyDMHOoVJ3/3m6POiEwKbK2fMoiGzE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732529317; c=relaxed/simple; bh=3SqJF/VnlSgG+GODyAWRjTdYXkhTouAgU12k3nHcgX8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=E9+2Tm5dMy5LunBRF2DJfvGyfd4fn5Yx3kroELB40JnFyX8W/nLZi1k/C2PNNLwFt21sfKWQjr0QdRoLWhB3Hi5PjCFP88cSsXDCqRl3EDMiWHBJQMDnW/pK/HDJk1Vxvl0+gd0amT1fczlsVLOSI1F9RkrQGrJeK6tz+qcWX0Y= 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=Im9cJDoS; 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="Im9cJDoS" 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=wV5Ch2f/rekMRnAGWDqppVh4gVRb99fHt2UOyp/e2N0=; b=Im9cJDoSRMUh2cOkBNituBJjIz hkh+D2YYGPBdDdwR/Vs1tm3wMyf0aMrG7DC0Cm++fJKze0fMJb3DfUoq4ylGB2AKNf3+pKnc14EOC G4BIruhc8OJZc5/xygtSe5tboxN/07u+1PTu0eF0EdoNcLNz3yyCQcxHxEWQxjtgjvH29jwl2hghY UCl6oUcXXBVizDjbqRg3jrmEAnugytFB6SMqR0erfp04qRqBWzQ4JMB+zUmhZ381iixNvRxx3W82S zo7wJMxyldl3Q8YxF3bszy7Z1j/ot2MmRrO2aLn4QhfCMKk/4U3v/uGn4g9sttzJji5bTOkR2if/I dm+dWT1w==; 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 1tFW11-000000014f5-03Am; 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-000000000kt-1HYE; 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 02/20] x86/kexec: Restore GDT on return from preserve_context kexec Date: Mon, 25 Nov 2024 09:54:32 +0000 Message-ID: <20241125100815.2512-3-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 desiato.infradead.org. See http://www.infradead.org/rpr.html Content-Type: text/plain; charset="utf-8" From: David Woodhouse The restore_processor_state() function explicitly states that "the asm code that gets us here will have restored a usable GDT". That wasn't true in the case of returning from a preserve_context kexec. Make it so. Without this, the kernel was depending on the called function to reload a GDT which is appropriate for the kernel before returning. Test program: #include #include #include #include #include #include #include #include int main (void) { struct kexec_segment segment =3D {}; unsigned char purgatory[] =3D { 0x66, 0xba, 0xf8, 0x03, // mov $0x3f8, %dx 0xb0, 0x42, // mov $0x42, %al 0xee, // outb %al, (%dx) 0xc3, // ret }; int ret; segment.buf =3D &purgatory; segment.bufsz =3D sizeof(purgatory); segment.mem =3D (void *)0x400000; segment.memsz =3D 0x1000; ret =3D syscall(__NR_kexec_load, 0x400000, 1, &segment, KEXEC_PRESERVE_CON= TEXT); if (ret) { perror("kexec_load"); exit(1); } ret =3D syscall(__NR_reboot, LINUX_REBOOT_MAGIC1, LINUX_REBOOT_MAGIC2, LIN= UX_REBOOT_CMD_KEXEC); if (ret) { perror("kexec reboot"); exit(1); } printf("Success\n"); return 0; } Signed-off-by: David Woodhouse Cc: stable@vger.kernel.org --- arch/x86/kernel/relocate_kernel_64.S | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/arch/x86/kernel/relocate_kernel_64.S b/arch/x86/kernel/relocat= e_kernel_64.S index e9e88c342f75..1236f25fc8d1 100644 --- a/arch/x86/kernel/relocate_kernel_64.S +++ b/arch/x86/kernel/relocate_kernel_64.S @@ -242,6 +242,13 @@ SYM_CODE_START_LOCAL_NOALIGN(virtual_mapped) movq CR0(%r8), %r8 movq %rax, %cr3 movq %r8, %cr0 + +#ifdef CONFIG_KEXEC_JUMP + /* Saved in save_processor_state. */ + movq $saved_context, %rax + lgdt saved_context_gdt_desc(%rax) +#endif + movq %rbp, %rax =20 popf --=20 2.47.0