From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755289AbdERTvK (ORCPT ); Thu, 18 May 2017 15:51:10 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:59055 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1754906AbdERTu6 (ORCPT ); Thu, 18 May 2017 15:50:58 -0400 Date: Thu, 18 May 2017 12:50:54 -0700 From: "Paul E. McKenney" To: Steven Rostedt Cc: LKML , Ingo Molnar , Thomas Gleixner Subject: Re: [PATCH v2] tracing: Make sure RCU is watching before calling a stack trace Reply-To: paulmck@linux.vnet.ibm.com References: <20170518093809.13428efa@gandalf.local.home> <20170518154711.GR3956@linux.vnet.ibm.com> <20170518123914.689a2b02@gandalf.local.home> <20170518184528.GV3956@linux.vnet.ibm.com> <20170518153026.053b2c82@gandalf.local.home> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20170518153026.053b2c82@gandalf.local.home> User-Agent: Mutt/1.5.21 (2010-09-15) X-TM-AS-GCONF: 00 x-cbid: 17051819-0024-0000-0000-000002737ACE X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00007081; HX=3.00000241; KW=3.00000007; PH=3.00000004; SC=3.00000212; SDB=6.00862333; UDB=6.00427803; IPR=6.00642002; BA=6.00005358; NDR=6.00000001; ZLA=6.00000005; ZF=6.00000009; ZB=6.00000000; ZP=6.00000000; ZH=6.00000000; ZU=6.00000002; MB=3.00015503; XFM=3.00000015; UTC=2017-05-18 19:50:55 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17051819-0025-0000-0000-0000440C6E1C Message-Id: <20170518195054.GY3956@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:,, definitions=2017-05-18_04:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=0 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1703280000 definitions=main-1705180134 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, May 18, 2017 at 03:30:26PM -0400, Steven Rostedt wrote: > On Thu, 18 May 2017 11:45:28 -0700 > "Paul E. McKenney" wrote: > > > On Thu, May 18, 2017 at 12:39:14PM -0400, Steven Rostedt wrote: > > > On Thu, 18 May 2017 08:47:11 -0700 > > > "Paul E. McKenney" wrote: > > > > > > > On Thu, May 18, 2017 at 09:38:09AM -0400, Steven Rostedt wrote: > > > > > > > > > > From: "Steven Rostedt (VMware)" > > > > > > > > > > As stack tracing now requires "rcu watching", force RCU to be watching when > > > > > recording a stack trace. > > > > > > > > > > Link: http://lkml.kernel.org/r/20170512172449.879684501@goodmis.org > > > > > > > > > > Cc: "Paul E. McKenney" > > > > > Signed-off-by: Steven Rostedt (VMware) > > > > > --- > > > > > > > > > > Changes since v1: > > > > > > > > > > My testing discovered that the stack trace can be called with > > > > > interrupts enabled, which is a no no to have when calling > > > > > rcu_irq_enter(). When interrupts are enabled, as with being in an > > > > > NMI, RCU will also be watching. > > > > > > > > > > kernel/trace/trace.c | 26 +++++++++++++++++++++++++- > > > > > 1 file changed, 25 insertions(+), 1 deletion(-) > > > > > > > > > > diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c > > > > > index fcc9a2d..34a98ba 100644 > > > > > --- a/kernel/trace/trace.c > > > > > +++ b/kernel/trace/trace.c > > > > > @@ -2568,7 +2568,31 @@ static inline void ftrace_trace_stack(struct trace_array *tr, > > > > > void __trace_stack(struct trace_array *tr, unsigned long flags, int skip, > > > > > int pc) > > > > > { > > > > > - __ftrace_trace_stack(tr->trace_buffer.buffer, flags, skip, pc, NULL); > > > > > + struct ring_buffer *buffer = tr->trace_buffer.buffer; > > > > > + > > > > > + /* > > > > > + * When an NMI triggers, RCU is enabled via rcu_nmi_enter() > > > > > + * Also, RCU is always enabled when interrupts are. > > > > > + */ > > > > > + if (!irqs_disabled() || in_nmi()) { > > > > > > > > You lost me on this one. RCU might not be watching if irqs are > > > > enabled, for example, in the idle loop. What am I missing here? > > > > > > > > > > Hmm, no, maybe I'm missing something :-/ > > > > > > OK, so if we trace in the idle loop, rcu may not be watching, so I may > > > need to byte the bullet and use the rcu_irq_enter_irqon() instead :-( > > > > If rcu_is_watching() returns false, yes. Of course, if rcu_is_watching() > > returns true, you are golden. > > > > Hmm, so I can just replace the entire if with: > > if (rcu_is_watching()) > > because it should be watching in NMI context, correct? Yes, and that would be even better! ;-) However, this assumes that there is no possibility of this being called during the time that in_nmi() returns true but RCU is not aware of the NMI. (Yes, we did go through this a bit earlier, just my usual paranoia showing...) Thanx, Paul