Received: by 2002:a05:7412:e794:b0:fa:551:50a7 with SMTP id o20csp2196948rdd; Fri, 12 Jan 2024 02:17:16 -0800 (PST) X-Google-Smtp-Source: AGHT+IERb87iWedwYhQTpjj9FqKHO8vkhhZLqxpI8xo59trnxSQ+SW2/ekma9JUa9UJpafWfywoL X-Received: by 2002:a19:9112:0:b0:50e:b46f:4383 with SMTP id t18-20020a199112000000b0050eb46f4383mr500877lfd.133.1705054636553; Fri, 12 Jan 2024 02:17:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1705054636; cv=none; d=google.com; s=arc-20160816; b=FWUfFB95Ft/aQWTsXnjouUC4jLRBXuvOf3xLd0UdCi66AW+iOWxabcYMHSDQ1Co95p XfJSXfxquzfY5sX2aciDs/jiu6Ck+GKaQCDOklxseumcSfrXZbyL8a+mig9lj+LYgwjc lXu6PjpcjoFjM3PVTqw2rPkvLkyZgeuyuIkEeKSUS2l/n7Fc28nyBm2WI9nhQImqHaC2 yt79FcLoCYiGHar06p5qlneokS7ajcd0Ldrf5zSHYyPNsJ8s/BwyrDkAkDDng//w5ksb zpJGk485ojO0UZf+VKou826kkuKMQJX566z+ELVef3Lw5lnaJz8stNHJ4DJ6VIB5rM83 kT5w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:user-agent:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=9CuribqGRXZVBw1pJiF7m/l1J/GRDApfXdZ+8ZAOymc=; fh=SIgps5XdV0XNwjZfT2uAI7g3mrspDldK9Qs8qQAfoa4=; b=tsj+NfFxdfDZSo0w/oCelvVoFzWKMbVqQWK5G7xoynS/gWXfMd68JiVn1O78qi3/Xc cqJ45kTXjjqsAk3c6jDsk3Kvj4Cjkn4cbE7F6rqjB8r6kCM3OZAHp/jN4bYLhGYKrwTq VFshK444/gUi5jchf3J6qEJF1MN8PY502og2kpEgayEweJlaJFJxp0L+bZjwLMw3EsrS kpo46QA8im8UETCtLb+DlxHBI8tQL4oOKvZZUPUj7s4zvbLVYzknlofNVEtyNwyl6TgQ U8K/7gc1pYWzqZS3YvT3iOuN2fSg6kvgg0cI+dMxdPZ9zFQ4/2LzPgVSn3QCgMuSUD/6 0uPw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="RUGP/VGO"; spf=pass (google.com: domain of linux-kernel+bounces-24565-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-24565-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id i7-20020a17090639c700b00a2b21ff1092si1230518eje.602.2024.01.12.02.17.16 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Jan 2024 02:17:16 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-24565-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="RUGP/VGO"; spf=pass (google.com: domain of linux-kernel+bounces-24565-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-24565-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=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 am.mirrors.kernel.org (Postfix) with ESMTPS id 4C36D1F21F68 for ; Fri, 12 Jan 2024 10:17:16 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 604D6627E2; Fri, 12 Jan 2024 10:14:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="RUGP/VGO" 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 8BF6560B90; Fri, 12 Jan 2024 10:14:18 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4B9BFC433C7; Fri, 12 Jan 2024 10:14:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1705054458; bh=L5NcxvFVVjpzi2aQTxHsnjnq0+vQBf6ABI8Dmfni5sw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=RUGP/VGOfU+aRircD59KTYoEsKC6ms4z2hImcLDQnsNzwFO8qD8DfR6u9TfTYJnlh g/6jJU5EXuqPm7CuSQegKC+aZBRSLpGbdYcmea/5Tv0Pr1TchKrbCtFKMCME+zMef5 pbaxpdwA8/m6+oomEgUH0kL6Y++aizjsX8Bn2mopHUhChgr5ajtqo7pV2GOOQp/403 5r/6HUoxoz3id100YdW+f45wTX+jM1GBRHisajgQiSREbq0OTs+z21umD3feR2f635 B9pIVGGQoA6WeavLByo4dUaZVEK62mOXqQh4w2DqZD2tK2enthw70/jR7uu64jCVz9 iW5GxDajiCxeQ== 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 v6 17/36] function_graph: Move graph depth stored data to shadow stack global var Date: Fri, 12 Jan 2024 19:14:11 +0900 Message-Id: <170505445179.459169.14013960772012231130.stgit@devnote2> X-Mailer: git-send-email 2.34.1 In-Reply-To: <170505424954.459169.10630626365737237288.stgit@devnote2> References: <170505424954.459169.10630626365737237288.stgit@devnote2> User-Agent: StGit/0.19 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" Content-Transfer-Encoding: 8bit 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_recursion.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, - /* - * 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 883d5c64f43f..1a467b5437b3 100644 --- a/kernel/trace/trace.h +++ b/kernel/trace/trace.h @@ -897,8 +897,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; @@ -931,7 +961,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 @@ -956,7 +986,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; }