From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755403AbdDFEP3 (ORCPT ); Thu, 6 Apr 2017 00:15:29 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:54051 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751251AbdDFEPW (ORCPT ); Thu, 6 Apr 2017 00:15:22 -0400 Date: Wed, 5 Apr 2017 21:15:15 -0700 From: "Paul E. McKenney" To: Steven Rostedt Cc: LKML Subject: Re: [BUG] stack tracing causes: kernel/module.c:271 module_assert_mutex_or_preempt Reply-To: paulmck@linux.vnet.ibm.com References: <20170405093207.404f8deb@gandalf.local.home> <20170405162515.GF1600@linux.vnet.ibm.com> <20170405124539.730a2365@gandalf.local.home> <20170405175925.GG1600@linux.vnet.ibm.com> <20170405221224.0d265a3d@gandalf.local.home> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20170405221224.0d265a3d@gandalf.local.home> User-Agent: Mutt/1.5.21 (2010-09-15) X-TM-AS-GCONF: 00 x-cbid: 17040604-0008-0000-0000-000001E8032D X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00006887; HX=3.00000240; KW=3.00000007; PH=3.00000004; SC=3.00000208; SDB=6.00843740; UDB=6.00415756; IPR=6.00621914; BA=6.00005271; NDR=6.00000001; ZLA=6.00000005; ZF=6.00000009; ZB=6.00000000; ZP=6.00000000; ZH=6.00000000; ZU=6.00000002; MB=3.00014930; XFM=3.00000013; UTC=2017-04-06 04:15:18 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17040604-0009-0000-0000-0000346A7E1E Message-Id: <20170406041515.GX1600@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:,, definitions=2017-04-06_01:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=2 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1702020001 definitions=main-1704060035 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Apr 05, 2017 at 10:12:24PM -0400, Steven Rostedt wrote: > On Wed, 5 Apr 2017 10:59:25 -0700 > "Paul E. McKenney" wrote: > > > > > Could you please let me know if tracing happens in NMI handlers? > > > > If so, a bit of additional code will be needed. > > > > > > > > Thanx, Paul > > > > > > > > PS. Which reminds me, any short-term uses of RCU_TASKS? This represents > > > > 3 of my 16 test scenarios, which is getting hard to justify for > > > > something that isn't used. Especially given that I will need to > > > > add more scenarios for parallel-callbacks SRCU... > > > > > > The RCU_TASK implementation is next on my todo list. Yes, there's going > > > to be plenty of users very soon. Not for 4.12 but definitely for 4.13. > > > > > > Sorry for the delay in implementing that :-/ > > > > OK, I will wait a few months before checking again... > > > > Actually, I took a quick look at what needs to be done, and I think it > is *really* easy, and may be available in 4.12! Here's the current > patch. Cool!!! > I can probably do a patch to allow optimized kprobes on PREEMPT kernels > as well. > > -- Steve > > diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c > index 8efd9fe..28e3019 100644 > --- a/kernel/trace/ftrace.c > +++ b/kernel/trace/ftrace.c > @@ -2808,18 +2808,28 @@ static int ftrace_shutdown(struct ftrace_ops *ops, int command) > * callers are done before leaving this function. > * The same goes for freeing the per_cpu data of the per_cpu > * ops. > - * > - * Again, normal synchronize_sched() is not good enough. > - * We need to do a hard force of sched synchronization. > - * This is because we use preempt_disable() to do RCU, but > - * the function tracers can be called where RCU is not watching > - * (like before user_exit()). We can not rely on the RCU > - * infrastructure to do the synchronization, thus we must do it > - * ourselves. > */ > if (ops->flags & (FTRACE_OPS_FL_DYNAMIC | FTRACE_OPS_FL_PER_CPU)) { > + /* > + * We need to do a hard force of sched synchronization. > + * This is because we use preempt_disable() to do RCU, but > + * the function tracers can be called where RCU is not watching > + * (like before user_exit()). We can not rely on the RCU > + * infrastructure to do the synchronization, thus we must do it > + * ourselves. > + */ > schedule_on_each_cpu(ftrace_sync); Great header comment on ftrace_sync(): "Yes, function tracing is rude." And schedule_on_each_cpu() looks like a great workqueue gatling gun! ;-) > +#ifdef CONFIG_PREEMPT > + /* > + * When the kernel is preeptive, tasks can be preempted > + * while on a ftrace trampoline. Just scheduling a task on > + * a CPU is not good enough to flush them. Calling > + * synchronize_rcu_tasks() will wait for those tasks to > + * execute and either schedule voluntarily or enter user space. > + */ > + synchronize_rcu_tasks(); > +#endif How about this to save a line? if (IS_ENABLED(CONFIG_PREEMPT)) synchronize_rcu_tasks(); One thing that might speed this up a bit (or might not) would be to doe the schedule_on_each_cpu() from a delayed workqueue. That way, if any of the activity from schedule_on_each_cpu() involved a voluntary context switch (from a cond_resched() or some such), then synchronize_rcu_tasks() would get the benefit of that context switch. You would need a flush_work() to wait for that delayed workqueue as well, of course. Not sure whether it is worth it, but figured I should pass it along. > arch_ftrace_trampoline_free(ops); > > if (ops->flags & FTRACE_OPS_FL_PER_CPU) > @@ -5366,22 +5376,6 @@ void __weak arch_ftrace_update_trampoline(struct ftrace_ops *ops) > > static void ftrace_update_trampoline(struct ftrace_ops *ops) > { > - > -/* > - * Currently there's no safe way to free a trampoline when the kernel > - * is configured with PREEMPT. That is because a task could be preempted > - * when it jumped to the trampoline, it may be preempted for a long time > - * depending on the system load, and currently there's no way to know > - * when it will be off the trampoline. If the trampoline is freed > - * too early, when the task runs again, it will be executing on freed > - * memory and crash. > - */ > -#ifdef CONFIG_PREEMPT > - /* Currently, only non dynamic ops can have a trampoline */ > - if (ops->flags & FTRACE_OPS_FL_DYNAMIC) > - return; > -#endif > - > arch_ftrace_update_trampoline(ops); > } Agreed, straightforward patch! Thanx, Paul