public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH RESEND -tip v2 1/7] x86_32/segment: Always return correctly zero-extended values from savesegment_*()
@ 2026-04-28 16:03 Uros Bizjak
  2026-04-28 16:03 ` [PATCH RESEND -tip v2 2/7] x86/insn-eval: Fix signedness bug in segment selector handling Uros Bizjak
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: Uros Bizjak @ 2026-04-28 16:03 UTC (permalink / raw)
  To: x86, linux-kernel
  Cc: Uros Bizjak, Thomas Gleixner, Ingo Molnar, Borislav Petkov,
	Dave Hansen, H. Peter Anvin

On 32-bit x86, reading segment registers into a 32-bit type can expose
undefined upper bits on older processors (e.g. Intel Quark X1000,
Pentium, and earlier), where bits 31:16 are not defined.

Introduce __seg_return_t as an intermediate type for __savesegment_*():
u16 on CONFIG_X86_32 and unsigned long otherwise.

As a result, __savesegment_*() now returns correctly zero-extended
value in all cases, avoiding propagation of undefined high bits on
32-bit systems while preserving existing behavior on 64-bit.

Signed-off-by: Uros Bizjak <ubizjak@gmail.com>
Cc: Thomas Gleixner <tglx@kernel.org>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Dave Hansen <dave.hansen@linux.intel.com>
Cc: "H. Peter Anvin" <hpa@zytor.com>
---
 arch/x86/include/asm/segment.h | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/arch/x86/include/asm/segment.h b/arch/x86/include/asm/segment.h
index dbd90fede5e7..070ed87063e0 100644
--- a/arch/x86/include/asm/segment.h
+++ b/arch/x86/include/asm/segment.h
@@ -341,13 +341,23 @@ static inline void __loadsegment_fs(u16 value)
 
 #define loadsegment(seg, val) __loadsegment_##seg(val)
 
+#ifdef CONFIG_X86_32
+/*
+ * Bits 31:16 are undefined for Intel Quark X1000 processors,
+ * Pentium, and earlier processors.
+ */
+typedef u16 __seg_return_t;
+#else
+typedef unsigned long __seg_return_t;
+#endif
+
 /*
  * Save a segment register away:
  */
 #define SAVE_SEGMENT(seg)				\
 static inline unsigned long __savesegment_##seg(void)	\
 {							\
-	unsigned long v;				\
+	__seg_return_t v;				\
 	asm volatile("movl %%" #seg ",%k0" : "=r" (v));	\
 	return v;					\
 }
-- 
2.53.0


^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2026-04-28 16:05 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-04-28 16:03 [PATCH RESEND -tip v2 1/7] x86_32/segment: Always return correctly zero-extended values from savesegment_*() Uros Bizjak
2026-04-28 16:03 ` [PATCH RESEND -tip v2 2/7] x86/insn-eval: Fix signedness bug in segment selector handling Uros Bizjak
2026-04-28 16:03 ` [PATCH RESEND -tip v2 3/7] x86/ptrace: Use savesegment() in get_segment_reg() instead of inline asm Uros Bizjak
2026-04-28 16:03 ` [PATCH RESEND -tip v2 4/7] x86/ptrace: Use unsigned short for segment values in get_segment_reg() Uros Bizjak
2026-04-28 16:03 ` [PATCH RESEND -tip v2 5/7] x86/kexec: store segment registers directly to memory in crash_setup_regs() Uros Bizjak
2026-04-28 16:03 ` [PATCH RESEND -tip v2 6/7] x86/segment: Introduce savesegment_mem16() helper to write segment selectors to memory Uros Bizjak
2026-04-28 16:03 ` [PATCH RESEND -tip v2 7/7] x86/process: Use savesegment_mem16() when saving segment selectors Uros Bizjak

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox