x86/switch_to/64: Rewrite FS/GS switching yet again to fix AMD CPUs
authorAndy Lutomirski <luto@kernel.org>
Tue, 1 Aug 2017 14:11:37 +0000 (07:11 -0700)
committerIngo Molnar <mingo@kernel.org>
Thu, 10 Aug 2017 15:15:13 +0000 (17:15 +0200)
commite137a4d8f4dd2e277e355495b6b2cb241a8693c3
tree87139e3e55f9006fa1fbb402bc538a70451ccd5b
parent23d98c204386a98d9ef9f9e744f41443ece4929f
x86/switch_to/64: Rewrite FS/GS switching yet again to fix AMD CPUs

Switching FS and GS is a mess, and the current code is still subtly
wrong: it assumes that "Loading a nonzero value into FS sets the
index and base", which is false on AMD CPUs if the value being
loaded is 1, 2, or 3.

(The current code came from commit 3e2b68d752c9 ("x86/asm,
sched/x86: Rewrite the FS and GS context switch code"), which made
it better but didn't fully fix it.)

Rewrite it to be much simpler and more obviously correct.  This
should fix it fully on AMD CPUs and shouldn't adversely affect
performance.

Signed-off-by: Andy Lutomirski <luto@kernel.org>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Borislav Petkov <bpetkov@suse.de>
Cc: Brian Gerst <brgerst@gmail.com>
Cc: Chang Seok <chang.seok.bae@intel.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>
Cc: stable@vger.kernel.org
Signed-off-by: Ingo Molnar <mingo@kernel.org>
arch/x86/kernel/process_64.c