Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753947AbbKXJgN (ORCPT ); Tue, 24 Nov 2015 04:36:13 -0500 Received: from terminus.zytor.com ([198.137.202.10]:55438 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753772AbbKXJgK (ORCPT ); Tue, 24 Nov 2015 04:36:10 -0500 Date: Tue, 24 Nov 2015 01:35:16 -0800 From: tip-bot for Andy Lutomirski Message-ID: Cc: dvlasenk@redhat.com, torvalds@linux-foundation.org, mingo@kernel.org, brgerst@gmail.com, hpa@zytor.com, luto@amacapital.net, peterz@infradead.org, bp@alien8.de, linux-kernel@vger.kernel.org, fweisbec@gmail.com, tglx@linutronix.de, luto@kernel.org Reply-To: mingo@kernel.org, hpa@zytor.com, brgerst@gmail.com, torvalds@linux-foundation.org, dvlasenk@redhat.com, linux-kernel@vger.kernel.org, tglx@linutronix.de, luto@kernel.org, fweisbec@gmail.com, luto@amacapital.net, peterz@infradead.org, bp@alien8.de In-Reply-To: <86237e362390dfa6fec12de4d75a238acb0ae787.1447361906.git.luto@kernel.org> References: <86237e362390dfa6fec12de4d75a238acb0ae787.1447361906.git.luto@kernel.org> To: linux-tip-commits@vger.kernel.org Subject: [tip:x86/asm] x86/entry/64: Fix irqflag tracing wrt context tracking Git-Commit-ID: f10750536fa783cafb2653f6fa349d6e62337e42 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 Content-Length: 3501 Lines: 101 Commit-ID: f10750536fa783cafb2653f6fa349d6e62337e42 Gitweb: http://git.kernel.org/tip/f10750536fa783cafb2653f6fa349d6e62337e42 Author: Andy Lutomirski AuthorDate: Thu, 12 Nov 2015 12:59:00 -0800 Committer: Ingo Molnar CommitDate: Tue, 24 Nov 2015 09:55:02 +0100 x86/entry/64: Fix irqflag tracing wrt context tracking Paolo pointed out that enter_from_user_mode could be called while irqflags were traced as though IRQs were on. In principle, this could confuse lockdep. It doesn't cause any problems that I've seen in any configuration, but if I build with CONFIG_DEBUG_LOCKDEP=y, enable a nohz_full CPU, and add code like: if (irqs_disabled()) { spin_lock(&something); spin_unlock(&something); } to the top of enter_from_user_mode, then lockdep will complain without this fix. It seems that lockdep's irqflags sanity checks are too weak to detect this bug without forcing the issue. This patch adds one byte to normal kernels, and it's IMO a bit ugly. I haven't spotted a better way to do this yet, though. The issue is that we can't do TRACE_IRQS_OFF until after SWAPGS (if needed), but we're also supposed to do it before calling C code. An alternative approach would be to call trace_hardirqs_off in enter_from_user_mode. That would be less code and would not bloat normal kernels at all, but it would be harder to see how the code worked. Signed-off-by: Andy Lutomirski Reviewed-by: Thomas Gleixner Cc: Andy Lutomirski Cc: Borislav Petkov Cc: Brian Gerst Cc: Denys Vlasenko Cc: Frederic Weisbecker Cc: H. Peter Anvin Cc: Linus Torvalds Cc: Peter Zijlstra Link: http://lkml.kernel.org/r/86237e362390dfa6fec12de4d75a238acb0ae787.1447361906.git.luto@kernel.org Signed-off-by: Ingo Molnar --- arch/x86/entry/entry_64.S | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/arch/x86/entry/entry_64.S b/arch/x86/entry/entry_64.S index 53616ca..a55697d 100644 --- a/arch/x86/entry/entry_64.S +++ b/arch/x86/entry/entry_64.S @@ -509,6 +509,17 @@ END(irq_entries_start) * tracking that we're in kernel mode. */ SWAPGS + + /* + * We need to tell lockdep that IRQs are off. We can't do this until + * we fix gsbase, and we should do it before enter_from_user_mode + * (which can take locks). Since TRACE_IRQS_OFF idempotent, + * the simplest way to handle it is to just call it twice if + * we enter from user mode. There's no reason to optimize this since + * TRACE_IRQS_OFF is a no-op if lockdep is off. + */ + TRACE_IRQS_OFF + #ifdef CONFIG_CONTEXT_TRACKING call enter_from_user_mode #endif @@ -1049,12 +1060,18 @@ ENTRY(error_entry) SWAPGS .Lerror_entry_from_usermode_after_swapgs: + /* + * We need to tell lockdep that IRQs are off. We can't do this until + * we fix gsbase, and we should do it before enter_from_user_mode + * (which can take locks). + */ + TRACE_IRQS_OFF #ifdef CONFIG_CONTEXT_TRACKING call enter_from_user_mode #endif + ret .Lerror_entry_done: - TRACE_IRQS_OFF ret -- 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/