From patchwork Sun Nov 5 16:09:09 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: 161670 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:8f47:0:b0:403:3b70:6f57 with SMTP id j7csp2197232vqu; Sun, 5 Nov 2023 08:09:50 -0800 (PST) X-Google-Smtp-Source: AGHT+IEVhKdTMQ4OdSHr/+xU5nUMXFpdRCeHnQoXPPitqZUT+ZfZX76dzCM6uSu2VYLufMXKZrOv X-Received: by 2002:a05:6e02:1526:b0:357:f72d:ad1d with SMTP id i6-20020a056e02152600b00357f72dad1dmr33397055ilu.30.1699200590016; Sun, 05 Nov 2023 08:09:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1699200589; cv=none; d=google.com; s=arc-20160816; b=dgjlZYA5Vy38wTVoOGAxFTo9hR7almHS+yZG0qBYIFuvi/acyTuyjFoYxwF5anFQn3 FxLZQpNWp7SWgWaBD4e1PIt+lTot49zkaR7VF1UGWTEa5JJAOvyPb6Tta1Y25YkNzMp+ MyYtQC4gHU5hThT0oHXRTR/h5dPTPgOe/u9A4Dfsu0GB1OY0YsR1pz94/YvjGWtWbx2q vYeomzJ3LXJmJRy/iqzF6shsJVfClU6/8hyMQ2Tqkl+DRQcrglG+pnetyVSsn8tqXfau YJmWMgYqC0O8H/q+bedAh9KVR1czvDVsewYhfViN2tx7FCuV8+dj3zNyIw+Kr2vR3r7f Q6Gw== 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=kVEWPFRz5/+fGUs7XIJwNAZNJkae3qIxVCEwhsGv+nA=; fh=SIgps5XdV0XNwjZfT2uAI7g3mrspDldK9Qs8qQAfoa4=; b=KHCAgVArpNP0XmdsCznIlz0+XYSLYP+2PH03afcwE9Cj56AG21MbcrdIFbvlFpwiRf dYkYfW/mDEJu9ndLLisAMTT+PdgWZwr1JQ1SqdQ+BvXT71l411uqyuT8YG6d38HYApBq LOXCppJFltsMlkdQa4gCygTGP9UZyTja1Wx3jrM0rFJEFztOsRUdl70g1PyPcRv0zvrD tNyF1ZLLFz9h7Lt3hYfCI+Q09mYUjJI7xr47hqjY8ZIM53NRUXrcfMDrjyXjz/5Fkxtx j1ZenmiBHgPDH2VPxql583mUrC545F7Lnt7Y2PEDzZeSugTCWzfOuRnIvGTcWGxy4rP+ GVkQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=r4Nkok4i; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 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 agentk.vger.email (agentk.vger.email. [2620:137:e000::3:2]) by mx.google.com with ESMTPS id h185-20020a636cc2000000b005b96cdc0681si6084772pgc.381.2023.11.05.08.09.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 05 Nov 2023 08:09:49 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) client-ip=2620:137:e000::3:2; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=r4Nkok4i; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 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 agentk.vger.email (Postfix) with ESMTP id 6D8238057D8D; Sun, 5 Nov 2023 08:09:47 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229695AbjKEQJ1 (ORCPT + 34 others); Sun, 5 Nov 2023 11:09:27 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47400 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229894AbjKEQJT (ORCPT ); Sun, 5 Nov 2023 11:09:19 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C0B611BC for ; Sun, 5 Nov 2023 08:09:15 -0800 (PST) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A1A18C433C7; Sun, 5 Nov 2023 16:09:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1699200555; bh=76F6UbhxbZaSAsPQvjDLsi8NvSTD+j0mXXNs1M+k06E=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=r4Nkok4i0G5ndXr3QBzG86wJTNKlWrVaghBQMvUb0dp30EwQRXBgtv66TMHYP8KtW LX9+guJ59ZjiSQkoCFG7Tn8Ffrk4zRYsclIVNR8stwjQtDe79vVRm8xfblry6JgYYH dluu+Pt7wi7C1EsRIygc57ZWFVNqxAIkQZQ+2sOi/y2RtIbgiG6OzFCopHzYaMkcoM oNAgyFF+S0JdMMPz8nsbLSiF8DrJ9yriXUvAn/3NMM1nvNYnRz8i1+fbgh7wItgf9C zE+cU776CFUM4yeDN+GKOsutVAbi/0UhLTiQmUJ7Je4xCBm1DTRF+XkeGOrqPnFpvx aylPTjxWt5I5w== 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 13/32] function_graph: Move graph depth stored data to shadow stack global var Date: Mon, 6 Nov 2023 01:09:09 +0900 Message-Id: <169920054871.482486.6029981940887989219.stgit@devnote2> X-Mailer: git-send-email 2.34.1 In-Reply-To: <169920038849.482486.15796387219966662967.stgit@devnote2> References: <169920038849.482486.15796387219966662967.stgit@devnote2> User-Agent: StGit/0.19 MIME-Version: 1.0 X-Spam-Status: No, score=-1.8 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 agentk.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 (agentk.vger.email [0.0.0.0]); Sun, 05 Nov 2023 08:09:47 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1781740957701326974 X-GMAIL-MSGID: 1781740957701326974 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 219520621091..8e5943d3d25c 100644 --- a/kernel/trace/trace.h +++ b/kernel/trace/trace.h @@ -892,8 +892,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; @@ -926,7 +956,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 @@ -951,7 +981,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; }