From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754057AbbLKF1I (ORCPT ); Fri, 11 Dec 2015 00:27:08 -0500 Received: from e38.co.us.ibm.com ([32.97.110.159]:32893 "EHLO e38.co.us.ibm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750976AbbLKF0t (ORCPT ); Fri, 11 Dec 2015 00:26:49 -0500 X-IBM-Helo: d03dlp03.boulder.ibm.com X-IBM-MailFrom: paulmck@linux.vnet.ibm.com X-IBM-RcptTo: linux-kernel@vger.kernel.org Date: Thu, 10 Dec 2015 21:26:47 -0800 From: "Paul E. McKenney" To: Ani Sinha Cc: Rik van Riel , Randy Dunlap , Richard Weinberger , "linux-kernel@vger.kernel.org" , Ivan Delalande , fruggeri Subject: Re: new warning on sysrq kernel crash trigger Message-ID: <20151211052647.GL28602@linux.vnet.ibm.com> Reply-To: paulmck@linux.vnet.ibm.com References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.21 (2010-09-15) X-TM-AS-MML: disable X-Content-Scanned: Fidelis XPS MAILER x-cbid: 15121105-0029-0000-0000-00000EC4DC6A Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Dec 10, 2015 at 03:57:09PM -0800, Ani Sinha wrote: > Hi guys > > I am noticing a new warning in linux 3.18 which we did not see before > in linux 3.4 : > > bash-4.1# echo c > /proc/sysrq-trigger > [ 978.807185] BUG: sleeping function called from invalid context at > ../arch/x86/mm/fault.c:1187 > [ 978.909816] in_atomic(): 0, irqs_disabled(): 0, pid: 4706, name: bash > [ 978.987358] Preemption disabled at:[] printk+0x48/0x4a > > > I have bisected this to the following change : > > commit 984d74a72076a12b400339973e8c98fd2fcd90e5 > Author: Rik van Riel > Date: Fri Jun 6 14:38:13 2014 -0700 > > sysrq: rcu-ify __handle_sysrq > > > the rcu_read_lock() in handle_sysrq() bumps up > current->rcu_read_lock_nesting. Hence, in __do_page_fault() when it > calls might_sleep() in x86/mm/fault.c line 1191, > preempt_count_equals(0) returns false and hence the warning is > printed. > > One way to handle this would be to do something like this: > > diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c > index eef44d9..d4dbe22 100644 > --- a/arch/x86/mm/fault.c > +++ b/arch/x86/mm/fault.c > @@ -1132,7 +1132,7 @@ __do_page_fault(struct pt_regs *regs, unsigned > long error_code, > * If we're in an interrupt, have no user context or are running > * in a region with pagefaults disabled then we must not take the fault > */ > - if (unlikely(faulthandler_disabled() || !mm)) { > + if (unlikely(faulthandler_disabled() || rcu_preempt_depth() || !mm)) { This works if CONFIG_PREEMPT=y, but if CONFIG_PREEMPT=n, then rcu_preempt_depth() unconditionally returns zero. And if CONFIG_PREEMPT_COUNT=y && CONFIG_PREEMPT=n, you would still see the might_sleep() splat. Maybe use SRCU instead of RCU for this purpose? Thanx, Paul > bad_area_nosemaphore(regs, error_code, address); > return; > } > > I am wondering if this would be the right approach. I have tested that > this patch does indeed suppress the warning. If you guys agree, I will > send a patch. It's true that this is a trivial issue since we are > intentionally crashing the kernel but in our case, this additional > complaint from the kernel is confusing our test scripts and they are > generating false positives. >