Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

x86/asm/entry/64: Use shorter MOVs from segment registers

The "movw %ds,%cx" instruction needs a 0x66 prefix, while
"movl %ds,%ecx" does not.

The difference is that latter form (on 64-bit CPUs)
overwrites the entire %ecx, not only its lower half.

But subsequent code doesn't depend on the value of upper
half of %ecx, so we can safely use the shorter instruction.

The new code is also faster than the old one - now we don't
depend on the old value of %ecx, but this code fragment is
not performance-critical so it does not matter much.

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
Cc: Alexei Starovoitov <ast@plumgrid.com>
Cc: Andy Lutomirski <luto@amacapital.net>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Brian Gerst <brgerst@gmail.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Kees Cook <keescook@chromium.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Oleg Nesterov <oleg@redhat.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Will Drewry <wad@chromium.org>
Link: http://lkml.kernel.org/r/1431722346-26585-1-git-send-email-dvlasenk@redhat.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>

authored by

Denys Vlasenko and committed by
Ingo Molnar
adeb5537 e839004b

+4 -4
+4 -4
arch/x86/kernel/entry_64.S
··· 1190 1190 /*CFI_REL_OFFSET ds,DS*/ 1191 1191 CFI_REL_OFFSET r11,8 1192 1192 CFI_REL_OFFSET rcx,0 1193 - movw %ds,%cx 1193 + movl %ds,%ecx 1194 1194 cmpw %cx,0x10(%rsp) 1195 1195 CFI_REMEMBER_STATE 1196 1196 jne 1f 1197 - movw %es,%cx 1197 + movl %es,%ecx 1198 1198 cmpw %cx,0x18(%rsp) 1199 1199 jne 1f 1200 - movw %fs,%cx 1200 + movl %fs,%ecx 1201 1201 cmpw %cx,0x20(%rsp) 1202 1202 jne 1f 1203 - movw %gs,%cx 1203 + movl %gs,%ecx 1204 1204 cmpw %cx,0x28(%rsp) 1205 1205 jne 1f 1206 1206 /* All segments match their saved values => Category 2 (Bad IRET). */