From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751764AbbBDGB5 (ORCPT ); Wed, 4 Feb 2015 01:01:57 -0500 Received: from terminus.zytor.com ([198.137.202.10]:34342 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751203AbbBDGBz (ORCPT ); Wed, 4 Feb 2015 01:01:55 -0500 Date: Tue, 3 Feb 2015 22:01:42 -0800 From: tip-bot for Andy Lutomirski Message-ID: Cc: luto@amacapital.net, mingo@kernel.org, linux-kernel@vger.kernel.org, hpa@zytor.com, tglx@linutronix.de, sasha.levin@oracle.com Reply-To: hpa@zytor.com, tglx@linutronix.de, sasha.levin@oracle.com, mingo@kernel.org, luto@amacapital.net, linux-kernel@vger.kernel.org In-Reply-To: <261ebee6aee55a4724746d0d7024697013c40a08.1422709102.git.luto@amacapital.net> References: <261ebee6aee55a4724746d0d7024697013c40a08.1422709102.git.luto@amacapital.net> To: linux-tip-commits@vger.kernel.org Subject: [tip:x86/asm] x86, traps: Fix ist_enter from userspace Git-Commit-ID: b926e6f61a26036ee9eabe6761483954d481ad25 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: b926e6f61a26036ee9eabe6761483954d481ad25 Gitweb: http://git.kernel.org/tip/b926e6f61a26036ee9eabe6761483954d481ad25 Author: Andy Lutomirski AuthorDate: Sat, 31 Jan 2015 04:53:53 -0800 Committer: Andy Lutomirski CommitDate: Sun, 1 Feb 2015 04:02:53 -0800 x86, traps: Fix ist_enter from userspace context_tracking_user_exit() has no effect if in_interrupt() returns true, so ist_enter() didn't work. Fix it by calling exception_enter(), and thus context_tracking_user_exit(), before incrementing the preempt count. This also adds an assertion that will catch the problem reliably if CONFIG_PROVE_RCU=y to help prevent the bug from being reintroduced. Link: http://lkml.kernel.org/r/261ebee6aee55a4724746d0d7024697013c40a08.1422709102.git.luto@amacapital.net Fixes: 959274753857 x86, traps: Track entry into and exit from IST context Reported-and-tested-by: Sasha Levin Signed-off-by: Andy Lutomirski --- arch/x86/kernel/traps.c | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c index 7176f84..c74f2f5 100644 --- a/arch/x86/kernel/traps.c +++ b/arch/x86/kernel/traps.c @@ -110,15 +110,11 @@ static inline void preempt_conditional_cli(struct pt_regs *regs) enum ctx_state ist_enter(struct pt_regs *regs) { - /* - * We are atomic because we're on the IST stack (or we're on x86_32, - * in which case we still shouldn't schedule. - */ - preempt_count_add(HARDIRQ_OFFSET); + enum ctx_state prev_state; if (user_mode_vm(regs)) { /* Other than that, we're just an exception. */ - return exception_enter(); + prev_state = exception_enter(); } else { /* * We might have interrupted pretty much anything. In @@ -127,12 +123,27 @@ enum ctx_state ist_enter(struct pt_regs *regs) * but we need to notify RCU. */ rcu_nmi_enter(); - return IN_KERNEL; /* the value is irrelevant. */ + prev_state = IN_KERNEL; /* the value is irrelevant. */ } + + /* + * We are atomic because we're on the IST stack (or we're on x86_32, + * in which case we still shouldn't schedule). + * + * This must be after exception_enter(), because exception_enter() + * won't do anything if in_interrupt() returns true. + */ + preempt_count_add(HARDIRQ_OFFSET); + + /* This code is a bit fragile. Test it. */ + rcu_lockdep_assert(rcu_is_watching(), "ist_enter didn't work"); + + return prev_state; } void ist_exit(struct pt_regs *regs, enum ctx_state prev_state) { + /* Must be before exception_exit. */ preempt_count_sub(HARDIRQ_OFFSET); if (user_mode_vm(regs))