Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp752960ybv; Wed, 5 Feb 2020 13:59:09 -0800 (PST) X-Google-Smtp-Source: APXvYqxFvzmSCiM5+cTiTdQVrm1cVMaL63zMZZHKey626MEpQTvY9VK6QBuUU86K5GxBEzhkeA7s X-Received: by 2002:a05:6830:1304:: with SMTP id p4mr22445172otq.327.1580939949361; Wed, 05 Feb 2020 13:59:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1580939949; cv=none; d=google.com; s=arc-20160816; b=tuFzL494KFsHW8tKeZHpk3rxytcz6Jl8XsUFryc4bFXWppUaSC9aoPO8I+IKAzMWpi kuLVbmwkIhPj4nlIYUTPBX8nrr1hxObJgxsJBbf8XWGomSmXc5OW02FzCwIdcq0MaUO4 eUk71jLm37FPS+i0mvf0DNqvKc4b2ixmLb1pKDVzx4cHmPrq4P5zQEBkquBRIxVyUgum R7IaCeQhOYn0xsST+RyrMcKTW6H+cvakTPOZAdX0iB44oB+9MvcwhT7wVx/3VOxGtMFq +J7bOmsKbfyMR2pnJN94sL1KoOf648mQtsqlnvQkFT6Q6ukuVBZ3rmKV8Qlpb0cBHw0J hi+w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=GZiszdRhEoXDklowAhrMMrF/LCE5Ul6eKPbb4HvqS4w=; b=F7UnA1C9XoETDOJOL3UHKrpOK8ty76ZLZj1tQJ9J7VR9E/cNgjDxOjNB9URYCNL0ln 0ffcCSbOxX/MYzd2RdhaAyJqdjUdlJ/4Zng6Uv252PWFabnXLM8toLCdNYrAHvUyHrXd ARJ1JIffhEmvvo+k6/1DtmUgopvWelqQQm7fp4nDJtJUtU5oAxr63LM5nF2GuHE97LhI dpsHixNVQ6vRinnwl7ygEUIR3XbNzpd4WuzO17bjehwf9Iw3+ihhEru89Gc8RmMzKr9L QGa6jJyH2WSueyDgcdhlfy0HS3hhLVjSyJ1ZjmUJPLAJJPhR0poRfAR9fNcNnL25q+rW 731g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@joelfernandes.org header.s=google header.b=BfgtY2l3; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z14si528422oth.15.2020.02.05.13.58.57; Wed, 05 Feb 2020 13:59:09 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@joelfernandes.org header.s=google header.b=BfgtY2l3; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727443AbgBEV6E (ORCPT + 99 others); Wed, 5 Feb 2020 16:58:04 -0500 Received: from mail-pj1-f68.google.com ([209.85.216.68]:52031 "EHLO mail-pj1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727106AbgBEV6C (ORCPT ); Wed, 5 Feb 2020 16:58:02 -0500 Received: by mail-pj1-f68.google.com with SMTP id fa20so1551848pjb.1 for ; Wed, 05 Feb 2020 13:58:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=joelfernandes.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=GZiszdRhEoXDklowAhrMMrF/LCE5Ul6eKPbb4HvqS4w=; b=BfgtY2l3umi7jAcYAQkg0xPmgX1OhRn09atiKDbbeZ66YUiA39WaRMI0IYWXIR78lH camocExRGLndJzc7CcnzUHTuiZsTZGalRcwYsKd161M1EvmA9q3xNSK01OzMDVRNYtOl TX4dEOq/PIsoUdTqRGSWus5SFSKGc+Pir9A0Y= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=GZiszdRhEoXDklowAhrMMrF/LCE5Ul6eKPbb4HvqS4w=; b=MsDsZelhQOcARljErtulWZBPkoXY5XaeJZ1Lge7eRca2lKL30dq5Vz0mVCbbO45KNY fG2yd56O2VLerODYI+LSW/BixlyAElG4gtHOrf9tlI5h6S7xG0mrrA+c2Obdy22eNLPv dSD7VvaaiAuZqxTWP+0205bIAAAL8NQ6+k2FLQ/G+6mbEd9xhopHiihimJUAYJBJDCsE 5niUIlBVYAbQPKGybMwCEHhEKwYJnUODySd6WeCxjR4fK1KLHajEHHJR1q/j5HSFxa7i w/7ddtbMJ3tnjh4oURj5YtEY9yBL3tz7FvgGr9hSBllZ3HK3S0G4xLDy+Eo0SlO/4NNR 3PpQ== X-Gm-Message-State: APjAAAUdUtuKZ7xxa8cIAWIT19ngDczePylJy01K7erFyUTCC5N44Tnm X4uOlzHyG7qDUOaAUB0npQXHZw== X-Received: by 2002:a17:902:bf49:: with SMTP id u9mr64670pls.199.1580939881455; Wed, 05 Feb 2020 13:58:01 -0800 (PST) Received: from localhost ([2620:15c:6:12:9c46:e0da:efbf:69cc]) by smtp.gmail.com with ESMTPSA id d2sm717301pjv.18.2020.02.05.13.58.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Feb 2020 13:58:00 -0800 (PST) Date: Wed, 5 Feb 2020 16:57:59 -0500 From: Joel Fernandes To: Steven Rostedt Cc: LKML , "Paul E. McKenney" , Amol Grover , Ingo Molnar , linux-kernel-mentees@lists.linuxfoundation.org, Madhuparna Bhowmik Subject: Re: [PATCH] ftrace: Protect ftrace_graph_hash with ftrace_sync Message-ID: <20200205215759.GK142103@google.com> References: <20200205094156.717b36c9@oasis.local.home> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200205094156.717b36c9@oasis.local.home> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Feb 05, 2020 at 09:41:56AM -0500, Steven Rostedt wrote: > > From: "Steven Rostedt (VMware)" > > As function_graph tracer can run when RCU is not "watching", it can not be > protected by synchronize_rcu() it requires running a task on each CPU before > it can be freed. Calling schedule_on_each_cpu(ftrace_sync) needs to be used. > > Link: https://lore.kernel.org/r/20200205131110.GT2935@paulmck-ThinkPad-P72 > > Cc: stable@vger.kernel.org > Fixes: b9b0c831bed26 ("ftrace: Convert graph filter to use hash tables") > Reported-by: "Paul E. McKenney" > Signed-off-by: Steven Rostedt (VMware) Reviewed-by: Joel Fernandes (Google) thanks, - Joel > --- > kernel/trace/ftrace.c | 11 +++++++++-- > kernel/trace/trace.h | 2 ++ > 2 files changed, 11 insertions(+), 2 deletions(-) > > diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c > index 481ede3eac13..3f7ee102868a 100644 > --- a/kernel/trace/ftrace.c > +++ b/kernel/trace/ftrace.c > @@ -5867,8 +5867,15 @@ ftrace_graph_release(struct inode *inode, struct file *file) > > mutex_unlock(&graph_lock); > > - /* Wait till all users are no longer using the old hash */ > - synchronize_rcu(); > + /* > + * 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); > > free_ftrace_hash(old_hash); > } > diff --git a/kernel/trace/trace.h b/kernel/trace/trace.h > index 8c52f5de9384..3c75d29bd861 100644 > --- a/kernel/trace/trace.h > +++ b/kernel/trace/trace.h > @@ -979,6 +979,7 @@ static inline int ftrace_graph_addr(struct ftrace_graph_ent *trace) > * Have to open code "rcu_dereference_sched()" because the > * function graph tracer can be called when RCU is not > * "watching". > + * Protected with schedule_on_each_cpu(ftrace_sync) > */ > hash = rcu_dereference_protected(ftrace_graph_hash, !preemptible()); > > @@ -1031,6 +1032,7 @@ static inline int ftrace_graph_notrace_addr(unsigned long addr) > * Have to open code "rcu_dereference_sched()" because the > * function graph tracer can be called when RCU is not > * "watching". > + * Protected with schedule_on_each_cpu(ftrace_sync) > */ > notrace_hash = rcu_dereference_protected(ftrace_graph_notrace_hash, > !preemptible()); > -- > 2.20.1 >