Received: by 2002:ab2:7903:0:b0:1fb:b500:807b with SMTP id a3csp285649lqj; Sat, 1 Jun 2024 20:43:26 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUeAOg8p+qnguU08Yyy5L1mw0gacNCMSmQVZuDyEbL4SSPNVfvoGuyeubnhOdN34r7y84Kb1BlNy08+vq33mA/3t2QXDCnvyAYyNOWAJQ== X-Google-Smtp-Source: AGHT+IGRurF3jPpYY9SHZSbGAqVvGUk8fTBpatLXHSjHny08gtw5/W5y8PT+qdSvcveP9PcVhSyo X-Received: by 2002:a17:902:ea12:b0:1f4:bcef:e968 with SMTP id d9443c01a7336-1f63708da4fmr80312195ad.53.1717299806669; Sat, 01 Jun 2024 20:43:26 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717299806; cv=pass; d=google.com; s=arc-20160816; b=iiJWsteFoK0aNjuhQCJFxvuR4mfr2IcYR4GpC39C7VSSxhSAX2+Z0vNZoAFxBQAkbt foxXrriwCKeySzk84p6I9MofNxAf4VrCGQ2WyTbGoum5smrkjhsgmwAm4iD4gIOxLTCq qi4lgzM7I7zKEMCA2MjTEyAfdYY6908CtFhP0Zd93rhXaJtKXAm/4jP1/NR+hvkS7+AF yhqeg+RLSy+xuzaMqD9cOvRSlDrICy62Y6c7fwYzDmpakYmBSj5XOezmK6vMreykJLrj SZHiQOdiJAXmHpdlJ0hNjNfnnwfYnWe8B7S1KYLR/mFdUADFspbBrfO04ZKTViDyb6+j 7dCw== 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=BYI39cMG6yW0r7YlBrASGrtG1E3jPCIpqZj6OSCwpSI+qtv+erNJbxwtTdMLuUnc9l ZJYKClO04niHa/DuHrl0caKw72P0HQFpWX6wvC/VTVe69XBKESy3O56ICWRweEuYNh3b 0D+zecEqCefAeYbgZRuYqyQ3DTC/qJF/XaxJj78EMAGQoSDDcOACuSWdzTXQXVqHU9Fo aFb3DdiS+Qn/MmSy1cAkdH5WFLeaNJ7q06gMEl1xgao4PpMn05xFfegbjrmyOPqbcf5R EGlV6UUCy4OLrqItefkWdzCk2Uv2cA02fN/u5x9JU8CQQHG92nHjjABLI1II6RxjBzcg bceQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-198100-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-198100-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id d9443c01a7336-1f6323eb727si28596155ad.345.2024.06.01.20.43.26 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 01 Jun 2024 20:43:26 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-198100-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-198100-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-198100-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 73C6D282E6D for ; Sun, 2 Jun 2024 03:41:24 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 616EC64CCC; Sun, 2 Jun 2024 03:37:31 +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 1D1AF38DCD; Sun, 2 Jun 2024 03:37:26 +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=1717299447; cv=none; b=qGWeyd7Z71vVDAH6wRe0ge5+f6QNKh9iR5bgkfoLO3UJ+IMDScTfc7h7By4hRUJHmgSsc67h5Hx2rMWsMHr01H506X2u53d3r9ZhUlUE56BXEt3iQtvfChCaXxWZ7/xWCdD3kbvcfSQTiqNj0fbcGLE0MT7yMZ0ULKB/UoUaVw8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717299447; c=relaxed/simple; bh=JE93PlBa3kdyQhPv7TKP6/ed9Zy0l5p2+IbasxlOd1M=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=f17LdDU3wNX7HFOZb6i9BTh7A7fdsIaUd0cZQgFell0UkufDzK/6AmvpoCwmQqBmOnuFH8Kxuxk+P30s41bZUwuG/Dh8rllZei7+QtPc72Mm2XN+K7JHueJoqjFGiAuAKGpW6URvt7Nom6NvaicBQ+5KGGD4YDBL+0uSg1b2YYc= 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 BDD41C4AF5F; Sun, 2 Jun 2024 03:37:26 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.97) (envelope-from ) id 1sDc3F-000000094RQ-4Arj; Sat, 01 Jun 2024 23:38:33 -0400 Message-ID: <20240602033833.854784427@goodmis.org> User-Agent: quilt/0.68 Date: Sat, 01 Jun 2024 23:38:01 -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 v2 17/27] function_graph: Move graph depth stored data to shadow stack global var References: <20240602033744.563858532@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