Received: by 2002:a89:d88:0:b0:1fa:5c73:8e2d with SMTP id eb8csp916887lqb; Fri, 24 May 2024 19:56:41 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVhfwcO7uB950f+XeGOZgNAJwmTSec9jxykma2pNU+NBm82NCKbNWTuUnkBpgWemN5EZlDPDwcXoxtyfv++ffiZ79dSq3tlXfqAdRktXw== X-Google-Smtp-Source: AGHT+IEFS1E5db7YTf65cEBHwnMEg5zBsJeimen+RM5uMhw0xI6SjkZ/wWQ/WD1aAkzHGMmOI8mK X-Received: by 2002:a05:6870:3289:b0:229:f035:f5b2 with SMTP id 586e51a60fabf-24ca11d4610mr4145977fac.17.1716605800860; Fri, 24 May 2024 19:56:40 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1716605800; cv=pass; d=google.com; s=arc-20160816; b=i86VrsjnZuKRglLoLP6Y8iknOyxWe4NXYwXjF7H1pGpUPaWbuPjzN1+9PbBPJT2Mvv +Wz/Yk5H5kqA3UCyRG5N719MQ8cAtYN1KvNOJBNCNoqaL1oyKIqTH6ad221w6cZriHTP DTsF6xBShA8eICB2T452ARH6boWv3rLu7Cpe99l55rIljJzzsXT/uni5VV9lwU+7C3o6 amxkU+AV1k5unVMdDKRTvTq8cO3T3kTKzOC/K3SXF7VNDXNfSQ9VPI67kB8uX3wrE8ls tQ38I0WLlipxWK8K7Y+584ZND/Zz1bvN8lz1cNmavlYzezMl9x3G60EbpaC5dnPzYJy6 KKug== 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=mI3KGhGoI0q21AdjjluA1L5J/Gxn+j9OoUfl9K6t7DU=; fh=YfcaVrAzBpSwi8dOlqHV4K1os6qdULs4cyXFG/DyLfE=; b=kQqWcsEIi81XommFFapc9Al5zgIQ36QiFRM28UugCaNl4lo10kt80o4ZLdXu5DTcdS ltZx17x0Tsc5acf+tg2WcdNYiCJIjaH5tc3XSTUr/1R+TlPblGwWCCv3OFGXPX0wPWd0 U/UMcGrgsylqbx/LWTvdZJJ6AJlsdpuwPHYeFf3zxA6ZAMqkTkO54ItagCBDJL0frlpB 38+c6a1UwnuiYDmlJTm3rXaDmHuazJjJ+zKyXCmymHI5lxRE2ONSGmgdcJnxQ0tvysOl F3L+g8lyAC0oa6wxK2PmWCH/I6V4AW7S/PGN3Zvo15qu90Zh2OZ+7hNQ524kj3hLTS2w S2+A==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-189255-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-189255-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 d2e1a72fcca58-6f8fcfd7cfcsi2396147b3a.215.2024.05.24.19.56.40 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 May 2024 19:56:40 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-189255-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-189255-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-189255-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 42D6BB23205 for ; Sat, 25 May 2024 02:40:36 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A03B112881E; Sat, 25 May 2024 02:36:59 +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 ABF322C69A; Sat, 25 May 2024 02:36:55 +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=1716604615; cv=none; b=ivcHCpjbRG+3tj+XlZ1Qycd/3WCiiHTpD7R5EbJ7TlrsEQce4ArBlP7MtOboyRVIKpJLBi/JF94nwGUzGjoK2OCkiMwV9DNKwLPkDNBKPRKAQKe5dPjG6SsQz7ZVmUxvmGszNNk0rUiZ7VRA2Bb2H1Pe/DkB/e3IELeFRSNWuMY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716604615; c=relaxed/simple; bh=+zjkH0vKAbAdSpqS3wrFl7xOCNvH08ZS6FM6hM562QM=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=ONK2wRKUAUX/VWvNmyFOYL5KefFWrfgHrINHEhPjiJtERD1hRFnpOVdZqS2CpXJ4Yvy62/CejEwed9BB8OXkXhtJcMpTaU1qOvh9TnKCd4w2U4zVfuDS2cKnB/drVj1ESeIaKy1btANXWleV63Qc7P12X3PxOgMbQP42zPVffs0= 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 F3256C4AF68; Sat, 25 May 2024 02:36:54 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.97) (envelope-from ) id 1sAhHz-00000007DOZ-2OeY; Fri, 24 May 2024 22:37:43 -0400 Message-ID: <20240525023743.429477012@goodmis.org> User-Agent: quilt/0.68 Date: Fri, 24 May 2024 22:37:06 -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 14/20] function_graph: Move graph depth stored data to shadow stack global var References: <20240525023652.903909489@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 6f889cc6097e..5398b6889027 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