From patchwork Wed Nov 8 14:27:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Masami Hiramatsu (Google)" X-Patchwork-Id: 163046 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:aa0b:0:b0:403:3b70:6f57 with SMTP id k11csp949621vqo; Wed, 8 Nov 2023 06:28:08 -0800 (PST) X-Google-Smtp-Source: AGHT+IHz4PgpHIL39Gh/H5tqs9qoZY9eiJQPipWCgE6WL3t2lRA3WSX9arrqJ1K52Bi+ZfrXKB7e X-Received: by 2002:a05:6a21:8187:b0:182:2282:fd7a with SMTP id pd7-20020a056a21818700b001822282fd7amr1852325pzb.19.1699453688199; Wed, 08 Nov 2023 06:28:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1699453688; cv=none; d=google.com; s=arc-20160816; b=m11pnKNs9F52OeHkB7Bb14X9B+Or7cGxYVzsDCXBpj/OpUHzsQq/17XPeTJSmALC3X So+VlvLlvh1nFVxJKEf2zRAnQ46SitAFa3DBQFymRN/l+lLBmiLyxt8t5kN0djzO8pbP GnePxaHoEJL7UIBMFPL7FXVeHoWV/rD1HYvMBApxqh8QI0tm18pM/cAhIhy+wFz2Oeus 2cSHQWwJA7MHV6fEbD0QpucOmNLtgcwpHq4I+fjdMYk2SoxXgL/722NwDd5xumWEjkPo Eb7q22Lk58F6cZlIi2/KM94vadU0EXK3MZ2uyamaDpJmbFT8ap1QloCyCuG1/9tHENGe jnGQ== 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=kZg4BV/RFkC7mE9efAGLH4SUkhFKJ9ujaygbdxYe2fP0Qux+sonoQnE+to/thiyknP 8ChHzZhvZ8kZbksBVzdZaseWHQaEE1uDe18aTnygvmQ+YYD0kxDhU2mh2LEqsmsbcyK/ IMmmHj0Q7Scq+oijUERi/kMzM4BUsaWKFoFKpZDbw7+A3zc2Lo3Pd22QVk7PDq4XWOzn NiSK6gZN3I6MC6w/hdkitE4EzUUT9TEMpePnLhdKK4FGuA7CbIoRMT4Ns8EcizLN9ezJ B/xxnsFnOn7r2tmDMgmHbRaiqO8nw2YcZxh75CU/OSSICJqorvqkLjNXhAVeRUoNcWUq /vmw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=IMDiNy7m; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 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 lipwig.vger.email (lipwig.vger.email. [23.128.96.33]) by mx.google.com with ESMTPS id h1-20020a170902748100b001bb8a57d518si2383317pll.379.2023.11.08.06.28.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Nov 2023 06:28:08 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) client-ip=23.128.96.33; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=IMDiNy7m; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 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 lipwig.vger.email (Postfix) with ESMTP id 2316E8053608; Wed, 8 Nov 2023 06:28:03 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344605AbjKHO14 (ORCPT + 32 others); Wed, 8 Nov 2023 09:27:56 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46002 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231262AbjKHO1Z (ORCPT ); Wed, 8 Nov 2023 09:27:25 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 83524213E for ; Wed, 8 Nov 2023 06:27:21 -0800 (PST) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B8043C433C7; Wed, 8 Nov 2023 14:27:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1699453641; bh=zcbx8h1RkttbOn5vskAZ1U6GGz5oeChBoNAtPCt+YfY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=IMDiNy7mdXQI5gVVD/r73RXXWpdK9sk717vOxz0SIZbQKOMYkb+d/gg1ZAQeWVQ2I LmtrLrMyo/0bpfGX4OeCCj6cEEAggZg0njpuswCD1nu77kACMD2AF7ebaiMk4BO1WD zab2dpvg6JfVqxcrTg8ALIGCWcvrfipIBQzs8EXS/q4cVYT0laJGp2ljkACGzC239Z 2KcffQCHcnay0hYxxBpUI8wgkuglZ0gjUebVx2b0tXfs5rUZTUl6nwxhI9O4z4Qppf ADStmb+8Exxsq/nNkDuN+J1uFhmhEadFL2Cga8RVzZiBb/qYje4+06SGG2Te3hdOSo Ne71oyUhldOww== 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: [RFC PATCH v2 15/31] function_graph: Move graph depth stored data to shadow stack global var Date: Wed, 8 Nov 2023 23:27:15 +0900 Message-Id: <169945363502.55307.4733872462347686914.stgit@devnote2> X-Mailer: git-send-email 2.34.1 In-Reply-To: <169945345785.55307.5003201137843449313.stgit@devnote2> References: <169945345785.55307.5003201137843449313.stgit@devnote2> User-Agent: StGit/0.19 MIME-Version: 1.0 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 (lipwig.vger.email [0.0.0.0]); Wed, 08 Nov 2023 06:28:03 -0800 (PST) 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 lipwig.vger.email X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1782006350353902834 X-GMAIL-MSGID: 1782006350353902834 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; }