Received: by 2002:a89:288:0:b0:1f7:eeee:6653 with SMTP id j8csp549353lqh; Tue, 7 May 2024 07:13:05 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCW9tBbTGQGJUC98g96MzppalDdL/9MrsSgfSIhyxDlDAGF859aW8Tx+ctPhtI0hlhqGFHbkTqLupZAy2yYA/R8xOPwuTpjGAFCjOLJW/Q== X-Google-Smtp-Source: AGHT+IGPQj4Tv1DjxqgElYEXUKwHgvBlVBi0L0TicPo5Pz5H24VmCueuTlVsfU8lQZVTT4BXEFG5 X-Received: by 2002:a17:906:2c43:b0:a58:e2b1:92c2 with SMTP id f3-20020a1709062c4300b00a58e2b192c2mr8484747ejh.57.1715091185753; Tue, 07 May 2024 07:13:05 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715091185; cv=pass; d=google.com; s=arc-20160816; b=pWeVvogYzncXzu0JFYcpI1hZIkk0SuwG4Zbujh+wiGhvUYnm3kiuawnZCZYGysna0o 2P6x7C21QB0gG1pU24g/bIdkhAD0bJxGQ0X8s6sdvXHPIai2k4bYwexjQ16E4j6psA0L GjxvRh+ItD59txahfd94Sl+Vm9X8nLYIIsA3hceN5qzIETN86NugxoT/P+oMnMyFlpmk fRX7PSTe73v+Xhghrs8nIXEl2h9KvtxdJK8YZiLo/u0hjxl91UODEVZ5nFj3Lg/smgMj N5qv9LlC5DrE+dNJXDfsCIo+2oza9W2H/uokQfmPOUh2H+TbP0DyEp1Gf14oNiNrmQ0a CDiQ== ARC-Message-Signature: i=2; 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=PUt41m2lavfKn817J4RF+DZj3NCCUnjWkm3IMW8sOH0=; fh=SIgps5XdV0XNwjZfT2uAI7g3mrspDldK9Qs8qQAfoa4=; b=VhYM2Nq2JtimbsPxB4NN5vqpXGKQwOsevyvISN+YLRZWF8SVcaJO2w8EcfDboa9zOr FQjqez6MPX7ZcjrcHnJIso27AWX8q2GnNjixTqaF/64Z4NV4p8NY5v/DUth/3c9kjZvL yl2b4BJYBE1yVos1rKcpx6RpsNlByYKX7V5QsZRT1j+4DeQHrXFTD0Ur39CaLZ3sFrWI BQB6TzI/p6GsmX9zMEC5FVrE7aQTy7/CQFwAj4CkhX+AnLfY4vsULRthQ9/pN3j2ZnQJ e9JxhuR22RKTREH8ALErKh7gtlRyE9CPsMFXE1p8nECTuFe/ZzU4DVSqEpr9TRAhyQl5 bzSw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=kHXHWexj; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-171521-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-171521-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 gb39-20020a170907962700b00a59cf5de8bcsi2284192ejc.135.2024.05.07.07.13.05 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 May 2024 07:13:05 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-171521-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=kHXHWexj; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-171521-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-171521-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 50F611F21AC4 for ; Tue, 7 May 2024 14:13:05 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C15441635CF; Tue, 7 May 2024 14:11:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="kHXHWexj" 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 D303C15EFAD; Tue, 7 May 2024 14:11:13 +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=1715091073; cv=none; b=pab51C58m/YxspUwYREi1besofz0ynNSfkQONCZPOcvKfSwhwpaCWB5VAEbCh42z5nXrrTOwzcGqAF1mWLRqMmEkGAQ0dZ4zuGSSdnnyHE7GJCo0lhUqrETit9dgaDhVgpevCi91FC9b3GTt2taDtP8JwugjLk4bpO2R/jWiyec= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715091073; c=relaxed/simple; bh=cTwRXrlVJVDu9PadS8nHpaVDLMh0lpLwXs6fmwk+hXY=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=WrTwLokeOZ/zsfSLkiUDBrZBz2kIRzf6ofaQmj4u3z4ioEudxqyL2k+jDszvD6PeOFFl3pi5dP5VSfbXqdr+6tAQPA0vIuY6nyoH33otcd/rPpVee3r/DXQHqBQxs3Q9lP52Zb3wh+Ylp1VCai9SNPIuFGGO/swuRhabrqVruoo= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=kHXHWexj; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id D7D70C2BBFC; Tue, 7 May 2024 14:11:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1715091073; bh=cTwRXrlVJVDu9PadS8nHpaVDLMh0lpLwXs6fmwk+hXY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=kHXHWexjIuD3JXBR/xCSoe/9r1M9O1LYo5MC6wdCvaBNSJdnA9rBC1CjhQQI6IVPN j8XqFXs+mLvZf/uZHX3OZah4LCLRvX6YXywKyuH80hdcznxjXEmXITF8TJySPQdyw8 2VcN7LMnVGVmxaB4kO1totwZaPHQ60pLckI7z3kbJWSVSb8N0sfuS/OEgnhXSnBolB JUu5fvtk+FLIzF/A4gfGSwqUO7qwOPGY/lFVuxHqq50gZogNv2lVcqfA2H+lGwdxke C/cu6Jn9VrYjMnGyqbcrInLscof9d0i5Otrc2Z3F/I59PBvY4RHioHd7wnwKbUA/SQ utnq6+IQwxmWg== 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 v10 16/36] function_graph: Move graph depth stored data to shadow stack global var Date: Tue, 7 May 2024 23:11:07 +0900 Message-Id: <171509106728.162236.2398372644430125344.stgit@devnote2> X-Mailer: git-send-email 2.34.1 In-Reply-To: <171509088006.162236.7227326999861366050.stgit@devnote2> References: <171509088006.162236.7227326999861366050.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 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 c7c7e7c9f700..7ab731b9ebc8 100644 --- a/kernel/trace/trace.h +++ b/kernel/trace/trace.h @@ -899,8 +899,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; @@ -933,7 +963,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 @@ -958,7 +988,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; }