From nobody Thu Dec 18 09:42:57 2025 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) (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 2C82F21D5B0 for ; Thu, 5 Dec 2024 15:34:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=90.155.50.34 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733412844; cv=none; b=FS10MZVeGcDcozEsbxVltLxtcxoqwpAPBPGFHQIXndJkS0ClD9oXU1ptB3b+dSb10QSNRzLz1a0tHozjki2m+jVlWxfjHxZgLOA8t9WvoSJvb3PxADvfgctZmLFiJmVw8VhlFhQrjr19eEYWEVbEDfLIjhqe7+gbAe+YtKSMqO4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733412844; c=relaxed/simple; bh=O010R88AY/wt73wwUsqV/NXUDUXuMTU64ql55cjPV2I=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=KmbMA4dYsZf9eNr3I0eUW5vL1Ydi/V8Xo+do/FEaHPoPgUReVoahOtZT2kKFXUBG3r4WKKMvdtj8v3LQdcb/74+2C4DcfAUnuNkgXG7ul87OrhQVKhvNq4X65wgrG8lEAySifEjLHeojjlu6yPWKPNrulkrk9GijlTtJQKpX+BM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org; spf=none smtp.mailfrom=casper.srs.infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=vpca3ChZ; arc=none smtp.client-ip=90.155.50.34 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=casper.srs.infradead.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="vpca3ChZ" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; 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=Igzw2FpuOdN8JV32gGNo6ufcDNCSrfphToQqI27Lv94=; b=vpca3ChZR+H66rMA0ICD+i7ijP w3f6NykSVeRBT8TWVQqWazQ72keUJG9AkYU2r+XFkSD2mWmvFTezdDdkvEnofdvYAdVY6lAiYTwYa gsUOYDs/QMEPxcCfjeKEGeu0PySykhINaxjlL6B29HXHqT+xVhh5qwFPL5dMgY9IQ1qk0InG1igup lbDchYKI3mGYck5TVmtjeAWrEpZzlRfae5iYg7SF/qC+9xjfJo41D9gO8LhWloYN5QCBZcKge6CnE qZYmlD0hNft9oHI77w2V06FN6hZh7iJPNOFQU7I4YDsTRvpD2bsRmib6o/kT0t8ULTbjEbok8My5v fpzs2jXw==; Received: from [2001:8b0:10b:1::ebe] (helo=i7.infradead.org) by casper.infradead.org with esmtpsa (Exim 4.98 #2 (Red Hat Linux)) id 1tJDrM-0000000DDoy-0k9n; Thu, 05 Dec 2024 15:33:45 +0000 Received: from dwoodhou by i7.infradead.org with local (Exim 4.98 #2 (Red Hat Linux)) id 1tJDrN-0000000DyL8-0x1L; Thu, 05 Dec 2024 15:33: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: [PATCH v5 01/20] x86/kexec: Restore GDT on return from preserve_context kexec Date: Thu, 5 Dec 2024 15:05:07 +0000 Message-ID: <20241205153343.3275139-2-dwmw2@infradead.org> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241205153343.3275139-1-dwmw2@infradead.org> References: <20241205153343.3275139-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 casper.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 base-commit: d0ceea662d459726487030237689835fcc0483e5 --=20 2.47.0