Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 385eca8f authored by Andy Lutomirski's avatar Andy Lutomirski Committed by Ingo Molnar
Browse files

x86/asm/32: Make pt_regs's segment registers be 16 bits



Many 32-bit x86 CPUs do 16-bit writes when storing segment registers to
memory.  This can cause the high word of regs->[cdefgs]s to
occasionally contain garbage.

Rather than making the entry code more complicated to fix up the
garbage, just change pt_regs to reflect reality.

Signed-off-by: default avatarAndy Lutomirski <luto@kernel.org>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Borislav Petkov <bpetkov@suse.de>
Cc: Brian Gerst <brgerst@gmail.com>
Cc: Denys Vlasenko <dvlasenk@redhat.com>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Josh Poimboeuf <jpoimboe@redhat.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: default avatarIngo Molnar <mingo@kernel.org>
parent 21ec3bf6
Loading
Loading
Loading
Loading
+26 −6
Original line number Original line Diff line number Diff line
@@ -9,6 +9,20 @@
#ifdef __i386__
#ifdef __i386__


struct pt_regs {
struct pt_regs {
	/*
	 * NB: 32-bit x86 CPUs are inconsistent as what happens in the
	 * following cases (where %seg represents a segment register):
	 *
	 * - pushl %seg: some do a 16-bit write and leave the high
	 *   bits alone
	 * - movl %seg, [mem]: some do a 16-bit write despite the movl
	 * - IDT entry: some (e.g. 486) will leave the high bits of CS
	 *   and (if applicable) SS undefined.
	 *
	 * Fortunately, x86-32 doesn't read the high bits on POP or IRET,
	 * so we can just treat all of the segment registers as 16-bit
	 * values.
	 */
	unsigned long bx;
	unsigned long bx;
	unsigned long cx;
	unsigned long cx;
	unsigned long dx;
	unsigned long dx;
@@ -16,16 +30,22 @@ struct pt_regs {
	unsigned long di;
	unsigned long di;
	unsigned long bp;
	unsigned long bp;
	unsigned long ax;
	unsigned long ax;
	unsigned long ds;
	unsigned short ds;
	unsigned long es;
	unsigned short __dsh;
	unsigned long fs;
	unsigned short es;
	unsigned long gs;
	unsigned short __esh;
	unsigned short fs;
	unsigned short __fsh;
	unsigned short gs;
	unsigned short __gsh;
	unsigned long orig_ax;
	unsigned long orig_ax;
	unsigned long ip;
	unsigned long ip;
	unsigned long cs;
	unsigned short cs;
	unsigned short __csh;
	unsigned long flags;
	unsigned long flags;
	unsigned long sp;
	unsigned long sp;
	unsigned long ss;
	unsigned short ss;
	unsigned short __ssh;
};
};


#else /* __i386__ */
#else /* __i386__ */