From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751436AbdJSXz7 (ORCPT ); Thu, 19 Oct 2017 19:55:59 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:39650 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1750939AbdJSXz5 (ORCPT ); Thu, 19 Oct 2017 19:55:57 -0400 Date: Thu, 19 Oct 2017 16:55:54 -0700 From: "Paul E. McKenney" To: Masami Hiramatsu Cc: Ingo Molnar , Steven Rostedt , linux-kernel@vger.kernel.org, Peter Zijlstra , Ananth N Mavinakayanahalli , Thomas Gleixner , "H . Peter Anvin" , "Naveen N . Rao" Subject: Re: [PATCH -tip v4] kprobes: Use synchronize_rcu_tasks() for optprobe with CONFIG_PREEMPT Reply-To: paulmck@linux.vnet.ibm.com References: <150845657959.5443.17274153381374966647.stgit@devbox> <150845661962.5443.17724352636247312231.stgit@devbox> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <150845661962.5443.17724352636247312231.stgit@devbox> User-Agent: Mutt/1.5.21 (2010-09-15) X-TM-AS-GCONF: 00 x-cbid: 17101923-0044-0000-0000-000003A254C2 X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00007920; HX=3.00000241; KW=3.00000007; PH=3.00000004; SC=3.00000238; SDB=6.00933598; UDB=6.00470253; IPR=6.00713886; BA=6.00005651; NDR=6.00000001; ZLA=6.00000005; ZF=6.00000009; ZB=6.00000000; ZP=6.00000000; ZH=6.00000000; ZU=6.00000002; MB=3.00017614; XFM=3.00000015; UTC=2017-10-19 23:55:55 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17101923-0045-0000-0000-000007D15D03 Message-Id: <20171019235554.GE3521@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:,, definitions=2017-10-19_12:,, 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-1707230000 definitions=main-1710190326 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Oct 20, 2017 at 08:43:39AM +0900, Masami Hiramatsu wrote: > We want to wait for all potentially preempted kprobes trampoline > execution to have completed. This guarantees that any freed > trampoline memory is not in use by any task in the system anymore. > synchronize_rcu_tasks() gives such a guarantee, so use it. > Also, this guarantees to wait for all potentially preempted tasks > on the instructions which will be replaced with a jump. > > Since this becomes a problem only when CONFIG_PREEMPT=y, enable > CONFIG_TASKS_RCU=y for synchronize_rcu_tasks() in that case. > > Signed-off-by: Masami Hiramatsu ;-) Acked-by: Paul E. McKenney > --- > arch/Kconfig | 2 +- > kernel/kprobes.c | 14 ++++++++------ > 2 files changed, 9 insertions(+), 7 deletions(-) > > diff --git a/arch/Kconfig b/arch/Kconfig > index d789a89cb32c..7e67191a4961 100644 > --- a/arch/Kconfig > +++ b/arch/Kconfig > @@ -90,7 +90,7 @@ config STATIC_KEYS_SELFTEST > config OPTPROBES > def_bool y > depends on KPROBES && HAVE_OPTPROBES > - depends on !PREEMPT > + select TASKS_RCU if PREEMPT > > config KPROBES_ON_FTRACE > def_bool y > diff --git a/kernel/kprobes.c b/kernel/kprobes.c > index 15fba7fe57c8..a8fc1492b308 100644 > --- a/kernel/kprobes.c > +++ b/kernel/kprobes.c > @@ -573,13 +573,15 @@ static void kprobe_optimizer(struct work_struct *work) > do_unoptimize_kprobes(); > > /* > - * Step 2: Wait for quiesence period to ensure all running interrupts > - * are done. Because optprobe may modify multiple instructions > - * there is a chance that Nth instruction is interrupted. In that > - * case, running interrupt can return to 2nd-Nth byte of jump > - * instruction. This wait is for avoiding it. > + * Step 2: Wait for quiesence period to ensure all potentially > + * preempted tasks to have normally scheduled. Because optprobe > + * may modify multiple instructions, there is a chance that Nth > + * instruction is preempted. In that case, such tasks can return > + * to 2nd-Nth byte of jump instruction. This wait is for avoiding it. > + * Note that on non-preemptive kernel, this is transparently converted > + * to synchronoze_sched() to wait for all interrupts to have completed. > */ > - synchronize_sched(); > + synchronize_rcu_tasks(); > > /* Step 3: Optimize kprobes after quiesence period */ > do_optimize_kprobes(); >