Received: by 2002:a05:6500:2018:b0:1fb:9675:f89d with SMTP id t24csp180623lqh; Thu, 30 May 2024 19:31:44 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCV8uuYMyurRQPiZiXtBV6XTdUMpmd1ee7m0Q1BgzDg0AHN7IoRAa7d/CxRRVBhgn+Vbrw2Oz1tmJW3OOw1tNqxYITvTAfJZk7gS2FKEQQ== X-Google-Smtp-Source: AGHT+IG1MofKEIl6YT2O+vmmxOHVIcMb1n9tCdHXH/1Y09v0plTB8Z/AOLC5cQLb103ghYb2V8Ng X-Received: by 2002:a05:620a:47c1:b0:792:cbf6:87b7 with SMTP id af79cd13be357-794f5ec696dmr44462885a.75.1717122703735; Thu, 30 May 2024 19:31:43 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717122703; cv=pass; d=google.com; s=arc-20160816; b=s2C2o5m1rhREzEZ2TDNV7pl67pO1F9e8+rvvxCqErVI1En477l93d5zfttlI9p0rf6 s7AtaAWmnZZt9f1FsNE4wS7JMOl2dyZ8YL5ID5932u9qVNpjialpQ2Ewq0P5wJlW+lV8 +bZQtYYooUDiS5TliTErRBrVAiD69w6FLG4CS6iat8SMT0F5d/aqa9IrtCmq1EvDfdJa IxXJjTP3qAyC45yyvEfsmg7pUpigG+wjhligj5GOwx/rTVNlMkUHnpPIUK6HlCQlAEs1 jOY27UA9YhCT1mjuK2T9sgUuAOAovn4jMwbpuNecXoyADN9QfKFFHgFHlmqCi8BDgmz9 OMfw== 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; bh=kFolHc0fpaAzE6DNCRqFV7biyxVmJAOJ7eong2L0/B0=; fh=YfcaVrAzBpSwi8dOlqHV4K1os6qdULs4cyXFG/DyLfE=; b=Hw3zOO3t1c/cmJfYvaGnD6HmoCYqgT2yzSX6GtGWVbHoGFOfCL3VSunTxxyvwvLuqc rYLYeBGH578cIJE/ZI+3YpF8kfY/67MbtLPbZRZa3fsEBkkWMcHXluv3Mis8U0NzK96N G1qIfYi0XT/LAfdZxTqABSZDyNKrKqukytw9/9XT6udXRSPzUvsaKW1lqysyR/FWvWHI r3VKJ7kLrB+isNGD2qwbgJ+8Zgwm2m2Lf/9bfsNf6zboQzsUVfYy8rC6AnjGAmhJKO3j 8jflJApTolp18kVhUyJeByW64XILEXrt3dfo22jiHw11H0yJR+jsKO+TYrae1A5faeOv AawQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-196188-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-196188-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id af79cd13be357-794f32a5943si95716685a.639.2024.05.30.19.31.43 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 May 2024 19:31:43 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-196188-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-196188-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-196188-linux.lists.archive=gmail.com@vger.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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 738231C236F6 for ; Fri, 31 May 2024 02:31:43 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3077278B50; Fri, 31 May 2024 02:31:35 +0000 (UTC) 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 A27C31F16B; Fri, 31 May 2024 02:31:34 +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=1717122694; cv=none; b=NA0gvCyw8u/h7ZeIqX2pm+CwIGDmoWJu1Km9j3QKoAoJl9vJsW6bRb27GnffrtpmPE2t4xsy0D4pnu0ZtmUiIg/FUYRQA4J0BtzLKPHHLPs9VN9HD1nIXrA0iVBS2nYHo+5s0ia9UVkAQL2v4f4BVtqlNNkMpaBEAO0OruUJPG8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717122694; c=relaxed/simple; bh=HPgvz7znQ7uYXknf46QLwPRcWIpnDASNDkawI13u898=; h=Date:From:To:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=kMopkFWhzElwKUOogGLEjMrW4bPAaPJs34A1ZNLBzUTImr03eBzNMWCQdVHStI84T6YV1+TTjlrHt3Elci5D1+AeJR3cEiZcrZCFW9QvAZFVLJIhC6rfLQ2GNFK0LIjY4QRgYQv6KSq5HLLUiwJhJ4Hnncgr9dAGPrBOgPuYlPk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id E0248C2BBFC; Fri, 31 May 2024 02:31:29 +0000 (UTC) Date: Thu, 30 May 2024 22:30:57 -0400 From: Steven Rostedt To: linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org Cc: Masami Hiramatsu , 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: <20240530223057.21c2a779@rorschach.local.home> In-Reply-To: <20240525023742.786834257@goodmis.org> References: <20240525023652.903909489@goodmis.org> <20240525023742.786834257@goodmis.org> X-Mailer: Claws Mail 3.17.8 (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, 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. 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. -- Steve > + *parent = (unsigned long)&return_to_handler; > + > + ftrace_test_recursion_unlock(bit); > } > #endif >