From nobody Mon Feb 9 17:35:37 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 B794513DBB6 for ; Wed, 27 Nov 2024 19:04:04 +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=1732734246; cv=none; b=fmRx2gPw/5IlDJidzQeDAWhJ4ZjYRChjN5ikP2IuRVHAA6RPb0mHihuOEoRFFM21Slcx/CoG99DpETm0SkHvTKYQB/4JGAE4HzxdasLux3iJATKtKpKnvat8cVj5iuQ0KvMxPGXbaUkM030eOvemcJRJcakp+ALsuNvKsxv+VPs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732734246; c=relaxed/simple; bh=3SqJF/VnlSgG+GODyAWRjTdYXkhTouAgU12k3nHcgX8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=SEqbdR7fwXIPTMatK6Xezye20C6o/RNuj8oiPMqxr95OnFip/tIV/UgWWGFWiiy+CmFVwjPTOTWChBdrQVqRoCLXu64OnAwUSyilXxCA05FJluLUXX1mhAg35bGxApLPYwHMETFU4scatFGB7fxoUwQ6FSR65rpUKMZmkKLnf+0= 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=ajAa6zng; 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="ajAa6zng" 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=ajAa6zngHwcn7K5Aa3M5D9KTC6 VAB7nGe2pyUne/Xv4EIWvecFnKgLWcBZKiF9bpSwKnlTffGJaoZ/n01mLHxEokcdPcwnBG0V10NxN jPcm6sBdKJ9i56VFVyOalcgWe7cPe/Si9MZkZNBD9rWgjAKUiSKnm6gdbw+o8J2GncyHSDYsZF554 d+/yjrKqBbp3NrwuDCkCf9LhTuxwOMId3TNlFMztgIpzG5FBQrFzpMqPlJ4iYNViiBrjmvtl4YLWv OLaVAKRkX6aJYfVH8Y9MVRghUVid/D6OrVEPo70Xyk91CYXJqPvXb4/vCxU7ZQPLNUI6xz/imUdt2 IOTEwGtA==; 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 1tGNKF-00000001Sub-18GV; Wed, 27 Nov 2024 19:03:47 +0000 Received: from dwoodhou by i7.infradead.org with local (Exim 4.98 #2 (Red Hat Linux)) id 1tGNKD-00000000BiA-3OxZ; Wed, 27 Nov 2024 19:03:45 +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 v4 01/20] x86/kexec: Restore GDT on return from preserve_context kexec Date: Wed, 27 Nov 2024 19:00:15 +0000 Message-ID: <20241127190343.44916-2-dwmw2@infradead.org> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241127190343.44916-1-dwmw2@infradead.org> References: <20241127190343.44916-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