Received: by 2002:ab2:7903:0:b0:1fb:b500:807b with SMTP id a3csp1173256lqj; Mon, 3 Jun 2024 12:25:24 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUCPrJlLMWDh+UCdcpl78Q7Ez2sU1OmPf+9qbVW/wP2PI8kCQw442BR7iaBQq9NWZhCjCzHLH16o0SeQjAk95irzHEIXFPslPdWgwlb8w== X-Google-Smtp-Source: AGHT+IFP2ItYiyfrEd4n26jxkay43LO1RkIfzUUelk76+atrqpDlriCX9nPxbZgc1nHogZNHCZw7 X-Received: by 2002:a05:6870:82a9:b0:24f:eebc:64f1 with SMTP id 586e51a60fabf-2508c118a9bmr11035323fac.40.1717442723857; Mon, 03 Jun 2024 12:25:23 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717442723; cv=pass; d=google.com; s=arc-20160816; b=ebRd6naqs2vbmF14kgnsSGTq+22G7gQkjph4FAm8euGNsZL/0bd4TTVSTUI7r2nEiJ qgLL4LoFK/BZh1pG0imMq1EDzbkFYp4jmJmjswFr5yCEsSOtDDTJwx2vcMx4secwMcfo LY7uFOSRMhpB9tRX+b0sCC56JwGxFouhApbj+oG794thYH3RxNQLsPGrWbjfHxLA5HZq Zh+DjTvIbuiQTqpFaQj0QQrmH1gfZBHlMbIVR11rntXzJc2n6WOrc5lqBumVtwboBJbL GOSkYleszvrQHlUok588HdmGtJlDAcAkd1p1T0B/BleC+SYhFgVdNlgCKR4lxpVCJx43 U6aw== 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=zSSklb4IT71gHyzVTWF4Oyb/zcoMWe54KEv/nUEGm2s=; fh=YfcaVrAzBpSwi8dOlqHV4K1os6qdULs4cyXFG/DyLfE=; b=i45EP2/4+UcOmjYw8QeTXBYl4UTTPgJmFPiZ/2LXNmR9XGvJmdlvGfJCRwFHQD/+OE fLWZavzNIcSlXx5RufLg2kX/oE8/f/3/2jN3QxluhVhVZfQAuF3TTUg4IkkrPAClDbSv 7i5tWFh8V1q6f1+0vryxril3wkiifDgZz4RMGJfISzFEnDK/thc9/lpg9ncRDmX5qLga oSOmyP1Aq3+Rb2rkRdZUHTlSbaIF4jzXmFOL39LKE9osk/1940rsLAW3zqjyirmZXBUC JFMSxab68pf1rJs7bwb7fiub3+fX467yz7Zjr7e81f9N+84FbFJ+EgjKGS+J5vF7zf6w nuQw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-199613-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-199613-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id 41be03b00d2f7-6c3554345b9si635268a12.228.2024.06.03.12.25.23 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Jun 2024 12:25:23 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-199613-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-199613-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-199613-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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 1E1C2B2167C for ; Mon, 3 Jun 2024 19:11:36 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3633113F442; Mon, 3 Jun 2024 19:07:17 +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 6610213CA81; Mon, 3 Jun 2024 19:07:13 +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=1717441633; cv=none; b=NHJjo6KJK1dvY7zmuIdUoBDV+iBJT6bXOlFYOZrBso0qeuqn6yu3YA+KWvNnGCyaiK+s8wWExuI9mbifPNHosSixaMuzCzDYOWWv6YnjP/Tld9tm6mPPioGmzMYrV0DwxqxNFp/ybCEG99p24SgksTj/o/ufTcN9uCZSD9sbS9Y= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717441633; c=relaxed/simple; bh=JE93PlBa3kdyQhPv7TKP6/ed9Zy0l5p2+IbasxlOd1M=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=DKWkfbWk3cf+eRj0YWeqjZR/Bg96FhTKhkND7yu8LbpiCA2enBx+DyPyN8mwsCyIEsQkxQQ4PXP+a/xqx7RlONAyS7D8Mg3nrA+NHdSXEmAoJDEj154feMgJuIQKH4kF60lOSSA+RxHrK0dJy+RZNKE8dNH58RULCPSPbTckYMY= 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 C5100C4DE09; Mon, 3 Jun 2024 19:07:12 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.97) (envelope-from ) id 1sED2d-00000009TuR-3G9G; Mon, 03 Jun 2024 15:08:23 -0400 Message-ID: <20240603190823.634870264@goodmis.org> User-Agent: quilt/0.68 Date: Mon, 03 Jun 2024 15:07:21 -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: [PATCH v3 17/27] function_graph: Move graph depth stored data to shadow stack global var References: <20240603190704.663840775@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 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