From nobody Wed Dec 17 21:28:16 2025 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (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 1BDEC1FCD0E; Fri, 6 Dec 2024 10:16:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733480202; cv=none; b=NFc+W7CvFz3PNBiCCi7D6g476FOLdXBReni3iD3Xw3rYICyIq06KXgRklKXlYQbG4o4qlMhP8uJT2/zGYEPNPEFzgktejh5Ky4p3PwveBybxB+UxciCiRwGEFmo4KQh3ZVkaXIUUlbTnKxffiRVRpVKgkvS6Xlo9fyDs/BYN/Nk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733480202; c=relaxed/simple; bh=K+zGqI9q21uTonb7URHR/nkqCUTjh2uYwUvs/im7Yts=; h=Date:From:To:Subject:Cc:In-Reply-To:References:MIME-Version: Message-ID:Content-Type; b=sOhZ0r64pHTtsItYA6jKxy0eDac7s9ObNEmgB+vFlG3lHWAQo7CtxEA4CUEshlx28Fhfi2B5Mz+D+ioR9teoMOMVDaIzayQC/Ri+yK7U+Y0VEBiV8m0EyAR3w/qYjYRC6jqDMKYvmKVR6Q9p6Q3oskfApvMuNJhHOzoSOUaYbPg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=Ftax5Gq6; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=/glm0KeH; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="Ftax5Gq6"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="/glm0KeH" Date: Fri, 06 Dec 2024 10:16:38 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1733480199; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Ys0FZid5GFWslTVF5iEhFlxma/b+XlUurBJ3vxqSlIM=; b=Ftax5Gq6y1mEjVnUc43XRVvLxgcLlPiKM/ap0vA+y0QZyvFLVQ3x0YhXVUB0qZTZ7LqEEK EL0fNvhxY84VJWqlBONndjxZcRY0h4RCkBA6eAERw8fCXO5dYE7p9lpg01nYQY469vW2on 4oFgFnFO1uY+OAD1U8V+AyEDRvMUmGa7oQ93i/AHUDB94nZxMJWJlDQ0098nkoxg5sguGU P+JsCJgsRWq8ABD9T9xKDLAYjTF7fsl7F393vNWf5pZ0MTiZ54rIddP0lSW+ETsft8x6we KKG+NazUl13q8Fx8bUHwmcYPtaPUaJPse+xwbg4tpoYb6Uq6qbvFhZnPux9GIA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1733480199; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Ys0FZid5GFWslTVF5iEhFlxma/b+XlUurBJ3vxqSlIM=; b=/glm0KeHikOkzyg6ONCnt/Mwod8DajvRUQZn07BWcQAfQhA3m+k92jrFkRJrApd40qwb5Q TLyTyxaaSB/SPMCg== From: "tip-bot2 for David Woodhouse" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: x86/urgent] x86/kexec: Restore GDT on return from ::preserve_context kexec Cc: David Woodhouse , Ingo Molnar , stable@vger.kernel.org, x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20241205153343.3275139-2-dwmw2@infradead.org> References: <20241205153343.3275139-2-dwmw2@infradead.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-ID: <173348019869.412.5731556015025742288.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Precedence: bulk Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable The following commit has been merged into the x86/urgent branch of tip: Commit-ID: 07fa619f2a40c221ea27747a3323cabc59ab25eb Gitweb: https://git.kernel.org/tip/07fa619f2a40c221ea27747a3323cabc5= 9ab25eb Author: David Woodhouse AuthorDate: Thu, 05 Dec 2024 15:05:07=20 Committer: Ingo Molnar CommitterDate: Fri, 06 Dec 2024 10:35:49 +01:00 x86/kexec: Restore GDT on return from ::preserve_context kexec 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 Signed-off-by: Ingo Molnar Cc: stable@vger.kernel.org Link: https://lore.kernel.org/r/20241205153343.3275139-2-dwmw2@infradead.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 e9e88c3..1236f25 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