Received: by 2002:a05:6500:2018:b0:1fb:9675:f89d with SMTP id t24csp500922lqh; Fri, 31 May 2024 07:51:46 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCX42K+cu1IbVWx25Uw5rAA46PN+gGosXD+TB6cLNNfE6Ih7FhfJkAkW4hYzva+S0AZPH5bZb4HX9WUMkIXqALv02sM51H7uXOgPeLMAJQ== X-Google-Smtp-Source: AGHT+IG91BR6/PVh/SAUGJNSlO8LJfDsHhHWVu6iInqaPluHLmtcPeIMSDmkV+iEH3V4kt0zech7 X-Received: by 2002:a17:907:bd8:b0:a59:aa3a:e6b6 with SMTP id a640c23a62f3a-a682022b91cmr127426866b.18.1717167106284; Fri, 31 May 2024 07:51:46 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717167106; cv=pass; d=google.com; s=arc-20160816; b=TIOYT7Gm3wxDs0/RCE2inqLv4YuwcFgIEksRBwqcXe5PEQJ5KgkA8DvkoW2hnJYeNB nDHyLIPsO2VBxZ7Ei573z6SzX6HnqTTrho6c8HuDl3WbTnhHW9F8k0xRnuh+y9kz8/hT ljFJjKBJEF2VdU9DOxzD+jdThyeJpILo10BzC4/z5RGFRa8GHRWyTJsot6SUpmfpNiZ1 Th952MfXp05QVhQlvZEVuzWzbkDRNMn21MZK+v1ivXLZD/kMXjgVA7YuXCSHDAqOXxnq Kjed7oWpuhL+zk1D6/RhOUjHYwejMS4O5+L9+TNxjV1IHJXSS6+mTO6ulM5y3FtY/u5H OujA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :subject:cc:to:from:date:dkim-signature; bh=0VUfB4+jz0KWgX252WALiY16nprLLul6uAMpMDWs1qw=; fh=NSnYj6tpGinFvTJElM5X+45jOrnS9GbogdcRlOg2Gnw=; b=yvXaajJm4ydNxL19rqfVBdDNATp6gdJSE6lZArYQ0uLUpyr3luZkWyiejLXfirvE6J fb9P9FClQE0uAd/z6RATRum+ZbPAtpQ7WIk7HUnt5eJRkCBpR+jYMdplFgq6nMa/eqnG JlQOKFbcBH37hjUD/0oT10vKFDQWxRBoplxkN3DEc8LFBMpX3ZwQEZbArgktENcrdJRm vevvAzQPvhh4370PJiHdTXOtYHI4De93TsuOZbkdbpi3ZWxhG9oKzt0FqtxBsqB3mBH9 M9iJQlOjEj1WGGv+ya3kX6Ipx8TKUH3mqdlnpvQSAQOw6lRSYsklSmYgOdIvCXYvyOFQ dbjw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=noplJiD1; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-197008-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-197008-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id a640c23a62f3a-a67ea86b8dbsi95336266b.499.2024.05.31.07.51.46 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 31 May 2024 07:51:46 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-197008-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=noplJiD1; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-197008-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-197008-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id D0DF01F283F4 for ; Fri, 31 May 2024 14:51:45 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 70C87745E2; Fri, 31 May 2024 14:50:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="noplJiD1" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7F7BA6F2EB; Fri, 31 May 2024 14:50:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717167029; cv=none; b=lG3Jm3bZ6bi6R4Qm0iiCmZ2ZCdVwSmP/DZxd9XikJ67P9w6h3FmQfg+LEWu50iZCAxlsNJExEzuFlqsa4NpdWAhvz3SRX8ADJzwWjg4RINznhDfg+EaUOx4jX6nOsaQAW3bO1nz5h3jtTDBK5vC7Im8iJYirKbeiQqJicJTuGFs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717167029; c=relaxed/simple; bh=SoFBpNqzbtb+5DiL1b3Xa2w1zfCNY7f9atKzwbTKab0=; h=Date:From:To:Cc:Subject:Message-Id:In-Reply-To:References: Mime-Version:Content-Type; b=mgtLhNLpGBNxB0PdvpSJVn6YhLj5vWiSO0mVibDA0BjTFJUYDN5XMc2AMH4aNMqu5GtEaPk+UoSePUOjmPT8AvjaD6P+8dFU/rQGK9IfwgVRuWct/TAynJ34M6r8eCTOYkpwuCAmdxreu1w0/ZggXqcp5pFZ3acRDHChi5rXDlk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=noplJiD1; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 957B3C116B1; Fri, 31 May 2024 14:50:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1717167029; bh=SoFBpNqzbtb+5DiL1b3Xa2w1zfCNY7f9atKzwbTKab0=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=noplJiD1JNJetlnp2zOzi5qcDqbPSkw74sQoxNmQDAo2MshMOAQqpSJOyJukYUFwu pwQJJq6CtfBr+2nfEO6WfL7DkO9SxDJJRv/jptWw7CLxLEeREj3cZ0CVsls45I9ImK xyu2/Kj/sYtgRi8jlfTebsYG+ZD67Og5DLr5fBRYvfQt1aEw0gq2PSAR1YD5noFp/t Qi63eq1BK8bhuN6L8jX0ES01kBlVLvMPQD6YnPWRq6znArglYSKhk1JYrjoqH1nMmQ pV/ayB5yUs89kLcAwko7vUXIVSZAlGg+ilAWUpFxwuhV7NktlDepEd6vNX989fSoTH yDvcsaNaLV9eA== Date: Fri, 31 May 2024 23:50:23 +0900 From: Masami Hiramatsu (Google) To: Steven Rostedt Cc: linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org, Mark Rutland , Mathieu Desnoyers , Andrew Morton , Alexei Starovoitov , Florent Revest , Martin KaFai Lau , bpf , Sven Schnelle , Alexei Starovoitov , Jiri Olsa , Arnaldo Carvalho de Melo , Daniel Borkmann , Alan Maguire , Peter Zijlstra , Thomas Gleixner , Guo Ren Subject: Re: [PATCH 10/20] function_graph: Have the instances use their own ftrace_ops for filtering Message-Id: <20240531235023.a0b2b207362eba2f8b5c16f7@kernel.org> In-Reply-To: <20240531020346.6c13e2d4@rorschach.local.home> References: <20240525023652.903909489@goodmis.org> <20240525023742.786834257@goodmis.org> <20240530223057.21c2a779@rorschach.local.home> <20240531121241.c586189caad8d31d597f614d@kernel.org> <20240531020346.6c13e2d4@rorschach.local.home> X-Mailer: Sylpheed 3.7.0 (GTK+ 2.24.33; x86_64-pc-linux-gnu) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit On Fri, 31 May 2024 02:03:46 -0400 Steven Rostedt wrote: > On Fri, 31 May 2024 12:12:41 +0900 > Masami Hiramatsu (Google) wrote: > > > On Thu, 30 May 2024 22:30:57 -0400 > > Steven Rostedt wrote: > > > > > On Fri, 24 May 2024 22:37:02 -0400 > > > Steven Rostedt wrote: > > > > > > > From: "Steven Rostedt (VMware)" > > > > > > > > Allow for instances to have their own ftrace_ops part of the fgraph_ops > > > > that makes the funtion_graph tracer filter on the set_ftrace_filter file > > > > of the instance and not the top instance. > > > > > > > > Note that this also requires to update ftrace_graph_func() to call new > > > > function_graph_enter_ops() instead of function_graph_enter() so that > > > > it avoid pushing on shadow stack multiple times on the same function. > > > > > > So I found a major design flaw in this patch. > > > > > > > > > > > Co-developed with Masami Hiramatsu: > > > > Link: https://lore.kernel.org/linux-trace-kernel/171509102088.162236.15758883237657317789.stgit@devnote2 > > > > > > > > Signed-off-by: Steven Rostedt (VMware) > > > > Signed-off-by: Masami Hiramatsu (Google) > > > > Signed-off-by: Steven Rostedt (Google) > > > > --- > > > > > > > diff --git a/arch/x86/kernel/ftrace.c b/arch/x86/kernel/ftrace.c > > > > index 8da0e66ca22d..998558cb8f15 100644 > > > > --- a/arch/x86/kernel/ftrace.c > > > > +++ b/arch/x86/kernel/ftrace.c > > > > @@ -648,9 +648,24 @@ void ftrace_graph_func(unsigned long ip, unsigned long parent_ip, > > > > struct ftrace_ops *op, struct ftrace_regs *fregs) > > > > { > > > > struct pt_regs *regs = &fregs->regs; > > > > - unsigned long *stack = (unsigned long *)kernel_stack_pointer(regs); > > > > + unsigned long *parent = (unsigned long *)kernel_stack_pointer(regs); > > > > + struct fgraph_ops *gops = container_of(op, struct fgraph_ops, ops); > > > > + int bit; > > > > + > > > > + if (unlikely(ftrace_graph_is_dead())) > > > > + return; > > > > + > > > > + if (unlikely(atomic_read(¤t->tracing_graph_pause))) > > > > + return; > > > > > > > > - prepare_ftrace_return(ip, (unsigned long *)stack, 0); > > > > + bit = ftrace_test_recursion_trylock(ip, *parent); > > > > + if (bit < 0) > > > > + return; > > > > + > > > > + if (!function_graph_enter_ops(*parent, ip, 0, parent, gops)) > > > > > > So each registered graph ops has its own ftrace_ops which gets > > > registered with ftrace, so this function does get called in a loop (by > > > the ftrace iterator function). This means that we would need that code > > > to detect the function_graph_enter_ops() getting called multiple times > > > for the same function. This means each fgraph_ops gits its own retstack > > > on the shadow stack. > > > > Ah, that is my concern and the reason why I added bitmap and stack reuse > > code in the ftrace_push_return_trace(). > > > > > > > > I find this a waste of shadow stack resources, and also complicates the > > > code with having to deal with tail calls and all that. > > > > > > BUT! There's good news! I also thought about another way of handling > > > this. I have something working, but requires a bit of rewriting the > > > code. I should have something out in a day or two. > > > > Hmm, I just wonder why you don't reocver my bitmap check and stack > > reusing code. Are there any problem on it? (Too complicated?) > > > > I actually dislike the use of ftrace itself to do the loop. I rather > have fgraph be in control of it. (actually, I agreed with you, looping in ftrace may cause trouble) > > I've come up with a new "subops" assignment, where you can have one > ftrace_ops represent multiple sub ftrace_ops. Basically, each fgraph > ops can register its own ftrace_ops under a single graph_ops > ftrace_ops. The graph_ops will be used to decide what functions call > the callback, and then the callback does the multiplexing. So is it similar to the fprobe/kprobe, use shared signle ftrace_ops, but keep each fgraph has own hash table? > This removes the need to touch the architecture code. It can also be > used by fprobes to handle the attachments to functions for several > different sets of callbacks. > > I'll send out patches soon. OK, I'll wait for that. Thank you! > > -- Steve > -- Masami Hiramatsu (Google)