Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754754AbbG0UeW (ORCPT ); Mon, 27 Jul 2015 16:34:22 -0400 Received: from mx1.redhat.com ([209.132.183.28]:55152 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754296AbbG0UeU (ORCPT ); Mon, 27 Jul 2015 16:34:20 -0400 From: Denys Vlasenko To: Ingo Molnar Cc: Denys Vlasenko , Linus Torvalds , "Krzysztof A. Sobiecki" , Steven Rostedt , Borislav Petkov , "H. Peter Anvin" , Andy Lutomirski , Oleg Nesterov , Frederic Weisbecker , Alexei Starovoitov , Will Drewry , Kees Cook , x86@kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 5/5] x86/asm/entry/32: Simplify FLAGS_NT clearing in SYSENTER32 code. Date: Mon, 27 Jul 2015 22:33:48 +0200 Message-Id: <1438029228-20560-5-git-send-email-dvlasenk@redhat.com> In-Reply-To: <1438029228-20560-1-git-send-email-dvlasenk@redhat.com> References: <1438029228-20560-1-git-send-email-dvlasenk@redhat.com> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2760 Lines: 86 "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 CC: Ingo Molnar CC: Linus Torvalds CC: Krzysztof A. Sobiecki CC: Steven Rostedt CC: Borislav Petkov CC: "H. Peter Anvin" CC: Andy Lutomirski CC: Oleg Nesterov CC: Frederic Weisbecker CC: Alexei Starovoitov CC: Will Drewry CC: Kees Cook CC: x86@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 majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/