Received: by 2002:a05:7412:419a:b0:f3:1519:9f41 with SMTP id i26csp3068978rdh; Mon, 27 Nov 2023 06:02:13 -0800 (PST) X-Google-Smtp-Source: AGHT+IGbcmSWa3iAd3WKhX/YiOAG7YG15GeJUaC++EYGYtW92AwrUkZYxgEyXyoYseK51rQ5h+wp X-Received: by 2002:a25:ccd7:0:b0:da0:37a6:7899 with SMTP id l206-20020a25ccd7000000b00da037a67899mr11177901ybf.7.1701093733304; Mon, 27 Nov 2023 06:02:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701093733; cv=none; d=google.com; s=arc-20160816; b=AhLGh9XL6BnJDYAx+i/4mnuWqL+KnUwQnHgu4mIEOovnra9T3DjxNJFqxk4hCEUzn1 bUM9C0M9OQg0kP7NrNqrnHHx/SL6vBdD6SyodZDyD7jt7nu0p0xe8U/aG1BfwIkYvowW zCT/bof+8LeAN92umqJsBDJ5Pz5XKOOEbCr3SrwhnqVkNyYcOXldVTMzC/QD45DaCwwY wffT5ljLUx1aZmVd/A7crY1DouVvglPQowHALzJ2wyP61SHXb4zOsNtn7Gtox5rOjDfV 0hqSHzAz2cPRmj31wl/7r9ibag1dzZSYq5Ob19JrMn/RJ0SfwDc4bzOSoLVutJShxa76 TKPQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=+FnSZ6xmFSrA3ZDQwJUZ+ljtz5vSSwvDSDyWa3YxNUE=; fh=SIgps5XdV0XNwjZfT2uAI7g3mrspDldK9Qs8qQAfoa4=; b=KEfZIg6qkvXnA+PQVQlvHEsGw/zaqwn5nGzaRuEr54hiL4Z2YeVrvUOx9CVP2hABUy FdZ5pwv9RhUM2K3q3Ni0CpP6Boe6wtPbW/CePlr71Y2CjhmhnDKpJa2z/bzAS1AtuYKs f3edG3A1Z2nIcH1BRjOV7cboT7zQk4FN+qTQQ4y3dzsZb09XWmWkMIQ/BtzBGzTiuw+B KI6+ZFYb4Ig1OIVfnFVC5df2h5jKdeAKxfOvAYwN587F4DAblPlgyFBWBm1qVLfH1l1q wnyHO1l47gBobSUz5zzX+hQ0lesZZPmLVic9na9M7XRlLtwWNeLnu6NTDKV+XlY6nx2i ioIQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Tbr0qLbw; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from pete.vger.email (pete.vger.email. [23.128.96.36]) by mx.google.com with ESMTPS id c8-20020a253508000000b00da0acf744eesi6092800yba.148.2023.11.27.06.02.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Nov 2023 06:02:13 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) client-ip=23.128.96.36; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Tbr0qLbw; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by pete.vger.email (Postfix) with ESMTP id DA5C3801D550; Mon, 27 Nov 2023 06:02:05 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233282AbjK0OBD (ORCPT + 99 others); Mon, 27 Nov 2023 09:01:03 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33514 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233536AbjK0N6w (ORCPT ); Mon, 27 Nov 2023 08:58:52 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5A66310D7 for ; Mon, 27 Nov 2023 05:56:06 -0800 (PST) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4514FC433D9; Mon, 27 Nov 2023 13:56:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1701093366; bh=zcbx8h1RkttbOn5vskAZ1U6GGz5oeChBoNAtPCt+YfY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Tbr0qLbw2Dtp6Qp5u9/1YEu4ixBJ8hhAXRamT5CoUPQoMD2IECrQPP/a10htZE6T5 hI7iStWbPTYDnUjnWznW0mz0JekcIKJnEPYZUT7t9xmi8XynyxKJrVXkQexO5PTVKU ZGM7ZhPyiwMYG1cRpbPCCPz9pcXfqKXkrA95iuk2UJBitgWSLuFj561pCGjAzs3ZXR /NAzNXQgiJAjYEH0EvPBCQxRPpvge/grEFA57Uvx369o0cPBVXl9KGlahZt3p7MIvg Wcd+Y8ETvXdZIBqsNkAJgEzLGKBye9Suq2Dh4eDb6y7QdWfAsna4nzLEXXkv2vmDcF HhiFWAw8N14cg== 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 v3 15/33] function_graph: Move graph depth stored data to shadow stack global var Date: Mon, 27 Nov 2023 22:55:59 +0900 Message-Id: <170109335913.343914.13373917760465141817.stgit@devnote2> X-Mailer: git-send-email 2.34.1 In-Reply-To: <170109317214.343914.4784420430328654397.stgit@devnote2> References: <170109317214.343914.4784420430328654397.stgit@devnote2> User-Agent: StGit/0.19 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on pete.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (pete.vger.email [0.0.0.0]); Mon, 27 Nov 2023 06:02:06 -0800 (PST) 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 60d38709ab91..cbe44998ef77 100644 --- a/kernel/trace/trace.h +++ b/kernel/trace/trace.h @@ -891,8 +891,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; @@ -925,7 +955,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 @@ -950,7 +980,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; }