From nobody Wed Dec 17 13:51:45 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 564B1C4167B for ; Mon, 27 Nov 2023 14:01:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233338AbjK0OBG (ORCPT ); Mon, 27 Nov 2023 09:01:06 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33514 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233536AbjK0N6w (ORCPT ); Mon, 27 Nov 2023 08:58:52 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5A66310D7 for ; Mon, 27 Nov 2023 05:56:06 -0800 (PST) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4514FC433D9; Mon, 27 Nov 2023 13:56:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1701093366; bh=zcbx8h1RkttbOn5vskAZ1U6GGz5oeChBoNAtPCt+YfY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Tbr0qLbw2Dtp6Qp5u9/1YEu4ixBJ8hhAXRamT5CoUPQoMD2IECrQPP/a10htZE6T5 hI7iStWbPTYDnUjnWznW0mz0JekcIKJnEPYZUT7t9xmi8XynyxKJrVXkQexO5PTVKU ZGM7ZhPyiwMYG1cRpbPCCPz9pcXfqKXkrA95iuk2UJBitgWSLuFj561pCGjAzs3ZXR /NAzNXQgiJAjYEH0EvPBCQxRPpvge/grEFA57Uvx369o0cPBVXl9KGlahZt3p7MIvg Wcd+Y8ETvXdZIBqsNkAJgEzLGKBye9Suq2Dh4eDb6y7QdWfAsna4nzLEXXkv2vmDcF HhiFWAw8N14cg== From: "Masami Hiramatsu (Google)" To: Alexei Starovoitov , Steven Rostedt , Florent Revest Cc: linux-trace-kernel@vger.kernel.org, LKML , Martin KaFai Lau , bpf , Sven Schnelle , Alexei Starovoitov , Jiri Olsa , Arnaldo Carvalho de Melo , Daniel Borkmann , Alan Maguire , Mark Rutland , Peter Zijlstra , Thomas Gleixner , Guo Ren Subject: [PATCH v3 15/33] function_graph: Move graph depth stored data to shadow stack global var Date: Mon, 27 Nov 2023 22:55:59 +0900 Message-Id: <170109335913.343914.13373917760465141817.stgit@devnote2> X-Mailer: git-send-email 2.34.1 In-Reply-To: <170109317214.343914.4784420430328654397.stgit@devnote2> References: <170109317214.343914.4784420430328654397.stgit@devnote2> User-Agent: StGit/0.19 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Steven Rostedt (VMware) The use of the task->trace_recursion for the logic used for the function graph depth was a bit of an abuse of that variable. Now that there exists global vars that are per stack for registered graph traces, use that instead. Signed-off-by: Steven Rostedt (VMware) Signed-off-by: Masami Hiramatsu (Google) --- include/linux/trace_recursion.h | 29 ----------------------------- kernel/trace/trace.h | 34 ++++++++++++++++++++++++++++++++-- 2 files changed, 32 insertions(+), 31 deletions(-) diff --git a/include/linux/trace_recursion.h b/include/linux/trace_recursio= n.h index 2efd5ec46d7f..00e792bf148d 100644 --- a/include/linux/trace_recursion.h +++ b/include/linux/trace_recursion.h @@ -44,25 +44,6 @@ enum { */ TRACE_IRQ_BIT, =20 - /* - * In the very unlikely case that an interrupt came in - * at a start of graph tracing, and we want to trace - * the function in that interrupt, the depth can be greater - * than zero, because of the preempted start of a previous - * trace. In an even more unlikely case, depth could be 2 - * if a softirq interrupted the start of graph tracing, - * followed by an interrupt preempting a start of graph - * tracing in the softirq, and depth can even be 3 - * if an NMI came in at the start of an interrupt function - * that preempted a softirq start of a function that - * preempted normal context!!!! Luckily, it can't be - * greater than 3, so the next two bits are a mask - * of what the depth is when we set TRACE_GRAPH_FL - */ - - TRACE_GRAPH_DEPTH_START_BIT, - TRACE_GRAPH_DEPTH_END_BIT, - /* * To implement set_graph_notrace, if this bit is set, we ignore * function graph tracing of called functions, until the return @@ -78,16 +59,6 @@ enum { #define trace_recursion_clear(bit) do { (current)->trace_recursion &=3D ~(= 1<<(bit)); } while (0) #define trace_recursion_test(bit) ((current)->trace_recursion & (1<<(bit))) =20 -#define trace_recursion_depth() \ - (((current)->trace_recursion >> TRACE_GRAPH_DEPTH_START_BIT) & 3) -#define trace_recursion_set_depth(depth) \ - do { \ - current->trace_recursion &=3D \ - ~(3 << TRACE_GRAPH_DEPTH_START_BIT); \ - current->trace_recursion |=3D \ - ((depth) & 3) << TRACE_GRAPH_DEPTH_START_BIT; \ - } while (0) - #define TRACE_CONTEXT_BITS 4 =20 #define TRACE_FTRACE_START TRACE_FTRACE_BIT diff --git a/kernel/trace/trace.h b/kernel/trace/trace.h index 60d38709ab91..cbe44998ef77 100644 --- a/kernel/trace/trace.h +++ b/kernel/trace/trace.h @@ -891,8 +891,38 @@ extern void free_fgraph_ops(struct trace_array *tr); =20 enum { TRACE_GRAPH_FL =3D 1, + + /* + * In the very unlikely case that an interrupt came in + * at a start of graph tracing, and we want to trace + * the function in that interrupt, the depth can be greater + * than zero, because of the preempted start of a previous + * trace. In an even more unlikely case, depth could be 2 + * if a softirq interrupted the start of graph tracing, + * followed by an interrupt preempting a start of graph + * tracing in the softirq, and depth can even be 3 + * if an NMI came in at the start of an interrupt function + * that preempted a softirq start of a function that + * preempted normal context!!!! Luckily, it can't be + * greater than 3, so the next two bits are a mask + * of what the depth is when we set TRACE_GRAPH_FL + */ + + TRACE_GRAPH_DEPTH_START_BIT, + TRACE_GRAPH_DEPTH_END_BIT, }; =20 +static inline unsigned long ftrace_graph_depth(unsigned long *task_var) +{ + return (*task_var >> TRACE_GRAPH_DEPTH_START_BIT) & 3; +} + +static inline void ftrace_graph_set_depth(unsigned long *task_var, int dep= th) +{ + *task_var &=3D ~(3 << TRACE_GRAPH_DEPTH_START_BIT); + *task_var |=3D (depth & 3) << TRACE_GRAPH_DEPTH_START_BIT; +} + #ifdef CONFIG_DYNAMIC_FTRACE extern struct ftrace_hash __rcu *ftrace_graph_hash; extern struct ftrace_hash __rcu *ftrace_graph_notrace_hash; @@ -925,7 +955,7 @@ ftrace_graph_addr(unsigned long *task_var, struct ftrac= e_graph_ent *trace) * when the depth is zero. */ *task_var |=3D TRACE_GRAPH_FL; - trace_recursion_set_depth(trace->depth); + ftrace_graph_set_depth(task_var, trace->depth); =20 /* * If no irqs are to be traced, but a set_graph_function @@ -950,7 +980,7 @@ ftrace_graph_addr_finish(struct fgraph_ops *gops, struc= t ftrace_graph_ret *trace unsigned long *task_var =3D fgraph_get_task_var(gops); =20 if ((*task_var & TRACE_GRAPH_FL) && - trace->depth =3D=3D trace_recursion_depth()) + trace->depth =3D=3D ftrace_graph_depth(task_var)) *task_var &=3D ~TRACE_GRAPH_FL; }