"sysenter_fix_flags" detour does not need to be convoluted anymore, straigten it up. However, we still use this:
jnz 2f jmp sysenter_jumps_here 2: ... instead of this: jz sysenter_jumps_here ... because "cold" conditional forward branch is predicted not taken by most CPUs - exactly what we want. Latter version would get it wrong. Reinstate "why we use SYSRETL instead of SYSEXIT" comment. Signed-off-by: Denys Vlasenko <dvlas...@redhat.com> CC: Ingo Molnar <mi...@kernel.org> CC: Linus Torvalds <torva...@linux-foundation.org> CC: Krzysztof A. Sobiecki <sob...@gmail.com> CC: Steven Rostedt <rost...@goodmis.org> CC: Borislav Petkov <b...@alien8.de> CC: "H. Peter Anvin" <h...@zytor.com> CC: Andy Lutomirski <l...@amacapital.net> CC: Oleg Nesterov <o...@redhat.com> CC: Frederic Weisbecker <fweis...@gmail.com> CC: Alexei Starovoitov <a...@plumgrid.com> CC: Will Drewry <w...@chromium.org> CC: Kees Cook <keesc...@chromium.org> CC: x...@kernel.org CC: linux-kernel@vger.kernel.org --- arch/x86/entry/entry_64_compat.S | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/arch/x86/entry/entry_64_compat.S b/arch/x86/entry/entry_64_compat.S index 73b56a5..bd3664f 100644 --- a/arch/x86/entry/entry_64_compat.S +++ b/arch/x86/entry/entry_64_compat.S @@ -98,20 +98,28 @@ ENTRY(entry_SYSENTER_compat) ASM_CLAC /* - * Sysenter doesn't filter flags, so we need to clear NT - * ourselves. To save a few cycles, we can check whether - * NT was set instead of doing an unconditional popfq. + * Sysenter doesn't filter flags, so we need to clear NT ourselves. */ testl $X86_EFLAGS_NT, EFLAGS(%rsp) - jnz sysenter_fix_flags -sysenter_flags_fixed: + jnz 2f jmp sysenter_jumps_here - -sysenter_fix_flags: +2: pushq $(X86_EFLAGS_IF|X86_EFLAGS_FIXED) popfq - jmp sysenter_flags_fixed - + jmp sysenter_jumps_here + /* + * SYSEXIT insn is not obviously safe for 64-bit kernels -- + * an NMI between STI and SYSEXIT has poorly specified behavior, + * and NMI followed by an IRQ with usergs is fatal. + * So we just pretend we're using SYSEXIT but we really use + * SYSRETL instead. (Yes, SYSRETL works even on Intel CPUs.) + * We do that by reusing the entire SYSCALL code path: + * the jump above takes us there. + * + * The difference of SYSENTER 32-bit ABI versus SYSCALL + * is that SYSENTER ABI does not promise to preserve EDX and EBP, + * SYSCALL does. + */ ENDPROC(entry_SYSENTER_compat) /* -- 1.8.1.4 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/