From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756998AbbGGKwd (ORCPT ); Tue, 7 Jul 2015 06:52:33 -0400 Received: from terminus.zytor.com ([198.137.202.10]:59965 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756974AbbGGKw1 (ORCPT ); Tue, 7 Jul 2015 06:52:27 -0400 Date: Tue, 7 Jul 2015 03:51:29 -0700 From: tip-bot for Andy Lutomirski Message-ID: Cc: luto@amacapital.net, linux-kernel@vger.kernel.org, brgerst@gmail.com, peterz@infradead.org, mingo@kernel.org, vda.linux@googlemail.com, luto@kernel.org, hpa@zytor.com, dvlasenk@redhat.com, riel@redhat.com, torvalds@linux-foundation.org, bp@alien8.de, tglx@linutronix.de, keescook@chromium.org, oleg@redhat.com, fweisbec@gmail.com Reply-To: luto@amacapital.net, brgerst@gmail.com, linux-kernel@vger.kernel.org, peterz@infradead.org, mingo@kernel.org, vda.linux@googlemail.com, luto@kernel.org, hpa@zytor.com, dvlasenk@redhat.com, riel@redhat.com, torvalds@linux-foundation.org, bp@alien8.de, tglx@linutronix.de, oleg@redhat.com, keescook@chromium.org, fweisbec@gmail.com In-Reply-To: <853b42420066ec3fb856779cdc223a6dcb5d355b.1435952415.git.luto@kernel.org> References: <853b42420066ec3fb856779cdc223a6dcb5d355b.1435952415.git.luto@kernel.org> To: linux-tip-commits@vger.kernel.org Subject: [tip:x86/asm] x86/entry: Add enter_from_user_mode() and use it in syscalls Git-Commit-ID: feed36cde0a10adb957445a37e48f957f30b2273 X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8 Content-Disposition: inline Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Commit-ID: feed36cde0a10adb957445a37e48f957f30b2273 Gitweb: http://git.kernel.org/tip/feed36cde0a10adb957445a37e48f957f30b2273 Author: Andy Lutomirski AuthorDate: Fri, 3 Jul 2015 12:44:25 -0700 Committer: Ingo Molnar CommitDate: Tue, 7 Jul 2015 10:59:06 +0200 x86/entry: Add enter_from_user_mode() and use it in syscalls Changing the x86 context tracking hooks is dangerous because there are no good checks that we track our context correctly. Add a helper to check that we're actually in CONTEXT_USER when we enter from user mode and wire it up for syscall entries. Subsequent patches will wire this up for all non-NMI entries as well. NMIs are their own special beast and cannot currently switch overall context tracking state. Instead, they have their own special RCU hooks. This is a tiny speedup if !CONFIG_CONTEXT_TRACKING (removes a branch) and a tiny slowdown if CONFIG_CONTEXT_TRACING (adds a layer of indirection). Eventually, we should fix up the core context tracking code to supply a function that does what we want (and can be much simpler than user_exit), which will enable us to get rid of the extra call. Signed-off-by: Andy Lutomirski Cc: Andy Lutomirski Cc: Borislav Petkov Cc: Brian Gerst Cc: Denys Vlasenko Cc: Denys Vlasenko Cc: Frederic Weisbecker Cc: H. Peter Anvin Cc: Kees Cook Cc: Linus Torvalds Cc: Oleg Nesterov Cc: Peter Zijlstra Cc: Rik van Riel Cc: Thomas Gleixner Cc: paulmck@linux.vnet.ibm.com Link: http://lkml.kernel.org/r/853b42420066ec3fb856779cdc223a6dcb5d355b.1435952415.git.luto@kernel.org Signed-off-by: Ingo Molnar --- arch/x86/entry/common.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/arch/x86/entry/common.c b/arch/x86/entry/common.c index 917d0c3..9a327ee 100644 --- a/arch/x86/entry/common.c +++ b/arch/x86/entry/common.c @@ -28,6 +28,15 @@ #define CREATE_TRACE_POINTS #include +#ifdef CONFIG_CONTEXT_TRACKING +/* Called on entry from user mode with IRQs off. */ +__visible void enter_from_user_mode(void) +{ + CT_WARN_ON(ct_state() != CONTEXT_USER); + user_exit(); +} +#endif + static void do_audit_syscall_entry(struct pt_regs *regs, u32 arch) { #ifdef CONFIG_X86_64 @@ -65,14 +74,16 @@ unsigned long syscall_trace_enter_phase1(struct pt_regs *regs, u32 arch) work = ACCESS_ONCE(current_thread_info()->flags) & _TIF_WORK_SYSCALL_ENTRY; +#ifdef CONFIG_CONTEXT_TRACKING /* * If TIF_NOHZ is set, we are required to call user_exit() before * doing anything that could touch RCU. */ if (work & _TIF_NOHZ) { - user_exit(); + enter_from_user_mode(); work &= ~_TIF_NOHZ; } +#endif #ifdef CONFIG_SECCOMP /*