Received: by 2002:a05:6500:1b41:b0:1fb:d597:ff75 with SMTP id cz1csp155971lqb; Tue, 4 Jun 2024 07:48:06 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVYl8v+c/CPfKevQhW2soo9R1n7HMiSZkKy2vayfP/W+UOFWw9BFwQ5LqSkdx6lvk/zdv3gPbifD55BrJES6jdEmJ3G3y7hi750AnCLKQ== X-Google-Smtp-Source: AGHT+IET4fWzkdOtXbCXQn0bTmBmq7Y4/16wL3A00HhGPWL1YMzkGAfcStP4NZrL4kwbC8kR6Vnz X-Received: by 2002:a05:6a20:258c:b0:1b2:b60a:a41b with SMTP id adf61e73a8af0-1b2b60aa550mr6243637.29.1717512486129; Tue, 04 Jun 2024 07:48:06 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717512486; cv=pass; d=google.com; s=arc-20160816; b=s4lPpULBkL2DLnSH8jfgA3Qm8FGRmmoiqOKZmmgWh7Ih6yMO5SdpX4MdoO9K34WWh9 rwV3uNcHwY/rDRWk/CF3ceGMWBwLxA4P5E4B1lXYYaSQ2aDyiaG70/tCMCv2CjMxwGUL FSxDDFyl12Qd66I5tLYp5hUk0IQSr4L41bYmXFBlMyVc/qTaffraXbB5+9o7jm46pHBX SbCwKQVeC0InAmwCZ2u/nzzl5YLrq6eXlvM1/c60XPoddnTNowDKjsBALx3hi+8MatJq uzB8cSRGFX1RlGVvUROPGfK3yFZVzJd0BddFMnqmj5bnT3n8uV4rTlublg0eYMR1MW8B iVdQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :references:subject:cc:to:from:date:user-agent:message-id; bh=zHP4QZiqyzR5IXzWPjs6FduVordAf56m8PydUZFv6B8=; fh=/wy5e/q+z2qlOMkv0QH/u80KV4ZXPtz68q6c1OyjqGY=; b=o9pKMGPlzeyzCr+6U695FcwuiLXGxagSgancPXwANCD2WSVrlDUrvN/pgyGm8plQUy FLqFed72+h3k6gmiIhkLpxMHmIEcwTDEmtHln8JuETd+o/+PN2/Q6Bijkx3yyV/IM5yh i2BwarUnp9C5c6HKe7iOtUhfKmN6zVtgO7xOZL9oXF96deMV4wZVk03lTZkH/wCsraN3 wFsvcIxXL21MCXkJUj0aHkBadOR/KsDsDM28A+BgtuPC6xi1qdemansGXkp6MBOvfSBA oXAwxTDQuGpWNjDaTsTzRWpjzhohLD050WmObj92Zb4UEAIxAAckak9i4kKyb8rREuDZ EdJA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-200878-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-200878-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id d2e1a72fcca58-7024913c831si1693374b3a.175.2024.06.04.07.48.05 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Jun 2024 07:48:06 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-200878-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-200878-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-200878-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 7488B2837C2 for ; Tue, 4 Jun 2024 14:47:12 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B138F14B97A; Tue, 4 Jun 2024 14:42:21 +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 7F63D149C53; Tue, 4 Jun 2024 14:42:17 +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=1717512137; cv=none; b=dBxTiaOD4/8r2qWMdwTG1MDjlPnEJNDFblklV7+EDKNvwF7X+F+2mY4UAOb2wLg6ohKT/VhL37fXfF6AWnvhx+36yBHYt5DrocFKLF5r9XF4mDKrGNIiEySk+f1uvCYSpilfxZ+YH3F5DWjfwa35lKnkdv9Ucx5xGcTonkgjSwY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717512137; c=relaxed/simple; bh=VOkBqN9ssCbZLRIMRmxIeUPZHCFegRpzd3sUILCk0QY=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=UObFSXCot2IOd60yQIomsrzPnhmPd+e3A3ZwZWQ97Af00PHe6G+RkdP7bBinn4O9ZC9x00k2+GFx1sDkiCF9xZeiuhWGbL66cUzDNj6qb+XJZo5+jXHAXActklMl83cJ5EnsWkPcawUBfxs5Bydc+On6xIaJzRaBdudcAAKWDrY= 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 68E95C32786; Tue, 4 Jun 2024 14:42:17 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.97) (envelope-from ) id 1sEVMe-00000000Z1W-3ZuE; Tue, 04 Jun 2024 10:42:16 -0400 Message-ID: <20240604144216.712787030@goodmis.org> User-Agent: quilt/0.68 Date: Tue, 04 Jun 2024 10:41:20 -0400 From: Steven Rostedt To: linux-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: [for-next][PATCH 17/27] function_graph: Move graph depth stored data to shadow stack global var References: <20240604144103.293353991@goodmis.org> 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=UTF-8 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. Link: https://lore.kernel.org/linux-trace-kernel/171509106728.162236.2398372644430125344.stgit@devnote2 Link: https://lore.kernel.org/linux-trace-kernel/20240603190823.634870264@goodmis.org Cc: Mark Rutland Cc: Mathieu Desnoyers Cc: Andrew Morton Cc: Alexei Starovoitov Cc: Florent Revest Cc: Martin KaFai Lau Cc: bpf Cc: Sven Schnelle Cc: Alexei Starovoitov Cc: Jiri Olsa Cc: Arnaldo Carvalho de Melo Cc: Daniel Borkmann Cc: Alan Maguire Cc: Peter Zijlstra Cc: Thomas Gleixner Cc: Guo Ren Reviewed-by: Masami Hiramatsu (Google) Signed-off-by: Steven Rostedt (VMware) Signed-off-by: Masami Hiramatsu (Google) Signed-off-by: Steven Rostedt (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_recursion.h index 02e6afc6d7fe..fdfb6f66718a 100644 --- a/include/linux/trace_recursion.h +++ b/include/linux/trace_recursion.h @@ -44,25 +44,6 @@ enum { */ TRACE_IRQ_BIT, - /* - * 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 &= ~(1<<(bit)); } while (0) #define trace_recursion_test(bit) ((current)->trace_recursion & (1<<(bit))) -#define trace_recursion_depth() \ - (((current)->trace_recursion >> TRACE_GRAPH_DEPTH_START_BIT) & 3) -#define trace_recursion_set_depth(depth) \ - do { \ - current->trace_recursion &= \ - ~(3 << TRACE_GRAPH_DEPTH_START_BIT); \ - current->trace_recursion |= \ - ((depth) & 3) << TRACE_GRAPH_DEPTH_START_BIT; \ - } while (0) - #define TRACE_CONTEXT_BITS 4 #define TRACE_FTRACE_START TRACE_FTRACE_BIT diff --git a/kernel/trace/trace.h b/kernel/trace/trace.h index 73919129e57c..82d879dc63ff 100644 --- a/kernel/trace/trace.h +++ b/kernel/trace/trace.h @@ -900,8 +900,38 @@ extern void free_fgraph_ops(struct trace_array *tr); enum { TRACE_GRAPH_FL = 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, }; +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 depth) +{ + *task_var &= ~(3 << TRACE_GRAPH_DEPTH_START_BIT); + *task_var |= (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; @@ -934,7 +964,7 @@ ftrace_graph_addr(unsigned long *task_var, struct ftrace_graph_ent *trace) * when the depth is zero. */ *task_var |= TRACE_GRAPH_FL; - trace_recursion_set_depth(trace->depth); + ftrace_graph_set_depth(task_var, trace->depth); /* * If no irqs are to be traced, but a set_graph_function @@ -959,7 +989,7 @@ ftrace_graph_addr_finish(struct fgraph_ops *gops, struct ftrace_graph_ret *trace unsigned long *task_var = fgraph_get_task_var(gops); if ((*task_var & TRACE_GRAPH_FL) && - trace->depth == trace_recursion_depth()) + trace->depth == ftrace_graph_depth(task_var)) *task_var &= ~TRACE_GRAPH_FL; } -- 2.43.0