From patchwork Fri Dec 8 10:27:29 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: 175743 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp5363353vqy; Fri, 8 Dec 2023 02:28:31 -0800 (PST) X-Google-Smtp-Source: AGHT+IGkDMlZHQceX+7oco/BLIQUId2NWnFFwH0soaEYmEKeVgMWisBHbaJc45mz5VcZ5gjdp5Sl X-Received: by 2002:a17:90b:23c3:b0:286:f625:d42d with SMTP id md3-20020a17090b23c300b00286f625d42dmr920609pjb.21.1702031310761; Fri, 08 Dec 2023 02:28:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702031310; cv=none; d=google.com; s=arc-20160816; b=x5eBzo6qdXJI7t9vEkm6l5Y0PzrZblDe2bJelJLqd5C9v5kLqCWT9hGoB4qfxcJgMG aCnea7/6YzdJ3KKYAnsPECwJCs7+Ih8U+nFWn5CsGJv5GG7MO+Wo42/n0QQ3vg8xXgrY yIh9kfuFtPgJldwfsM6uE5y9XNQ+BK2UX1SbWa+Q9SzG3Kfl3jk2sYFWo+gLA506AJof zLoA2r2Q/cB78207FuW7svQ5H0v2OkP159oiXJMmrzmSeO9iK2r63MQOyaBL/59RH968 VTdFJ2etN4/CbCQvKJj1p1YX/HAOvneTlOCIOiJyQbKQDnTw+r99+V/2ZbKDnS/Vkdae TneA== 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=OYBJw1NfeATJxeGscVzw9H+t8LsucyyBedZ6vHChRco=; fh=SIgps5XdV0XNwjZfT2uAI7g3mrspDldK9Qs8qQAfoa4=; b=i4r6tEMs0zVyBFACu8ekrRSlKLezBNfRvVZ8LnQTY7/QzS13tBgmSmPsnteV4S+aFJ gtL6DAO58t7hZQPR3nogm8svMPA3d0BMIB+QAS+cb68vX4BndQAoXWQhAoJcsp8KLZ5O VGQHOWTkn+bPxSw3Hv/8sZo4EqfMZxjMNYEG3HfUuUtUzu2VkmUMHg3eKzYDvZ/iJ7CD 3hp2D2aUDzqdAuALxYd1B/NsBfpAenmed1/6NJvTpNGQ3MMm+P1lXPdkhI9C5OAH4Ixh zF5qrGs5SVEGJld9yMK7IS+LFtMhntbHQ85a7l9EgnngbCcic3WmXc4IxMY2uIBq+964 UgOw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=jdCIWqT+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 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 pete.vger.email (pete.vger.email. [2620:137:e000::3:6]) by mx.google.com with ESMTPS id h13-20020a17090ac38d00b0027d04b581dcsi2745700pjt.72.2023.12.08.02.28.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Dec 2023 02:28:30 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) client-ip=2620:137:e000::3:6; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=jdCIWqT+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 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 69F3382C4008; Fri, 8 Dec 2023 02:28:25 -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 S1573514AbjLHK2H (ORCPT + 99 others); Fri, 8 Dec 2023 05:28:07 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60906 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1573683AbjLHK1n (ORCPT ); Fri, 8 Dec 2023 05:27:43 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 02F4819BB for ; Fri, 8 Dec 2023 02:27:36 -0800 (PST) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C06C3C433C8; Fri, 8 Dec 2023 10:27:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1702031255; bh=x44g32Pd9O3zsRrhngWEUNn/+TG68nwVi1AhDspvG5g=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jdCIWqT+IlDbMobTp0pglIWjDIs9sbMpmSUFclPYuQhTBQLfXiWyU5S+MxQyU1kaw 9s7BxlgrH7oiR+At2KTIUfz7lsQecdDiJwHYpiEptbTa01+ely2ZmE1bEVVVwQO7ES KYxKI5zPUY7GI57pUopaLJqGnvwZ3zu8qNoP9uQla78LB52sFAv/6KQxX2kry/MzHW 6arZJpdUIHVqIJ4VID2228+Qyt5G/3rdOwFJi6Mit5Qr8mHvwVA+VL7/gigY7vqfdv QvvM2GpBanMvGmxx7dypN00qSjF2Vm2n6l/aqP+CXJB4Rcbs8qBfMzd8M/UW344Enr zpDDKL+FAnCwg== 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 v4 16/33] function_graph: Move graph notrace bit to shadow stack global var Date: Fri, 8 Dec 2023 19:27:29 +0900 Message-Id: <170203124882.579004.5300962282313539942.stgit@devnote2> X-Mailer: git-send-email 2.34.1 In-Reply-To: <170203105427.579004.8033550792660734570.stgit@devnote2> References: <170203105427.579004.8033550792660734570.stgit@devnote2> User-Agent: StGit/0.19 MIME-Version: 1.0 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]); Fri, 08 Dec 2023 02:28:25 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1784709183385686835 X-GMAIL-MSGID: 1784709183385686835 From: Steven Rostedt (VMware) The use of the task->trace_recursion for the logic used for the function graph no-trace 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) --- Changes in v2: - Make description lines shorter than 76 chars. --- include/linux/trace_recursion.h | 7 ------- kernel/trace/trace.h | 9 +++++++++ kernel/trace/trace_functions_graph.c | 10 ++++++---- 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/include/linux/trace_recursion.h b/include/linux/trace_recursion.h index 00e792bf148d..cc11b0e9d220 100644 --- a/include/linux/trace_recursion.h +++ b/include/linux/trace_recursion.h @@ -44,13 +44,6 @@ enum { */ TRACE_IRQ_BIT, - /* - * To implement set_graph_notrace, if this bit is set, we ignore - * function graph tracing of called functions, until the return - * function is called to clear it. - */ - TRACE_GRAPH_NOTRACE_BIT, - /* Used to prevent recursion recording from recursing. */ TRACE_RECORD_RECURSION_BIT, }; diff --git a/kernel/trace/trace.h b/kernel/trace/trace.h index e3f452eda0e3..fac29f08d5d8 100644 --- a/kernel/trace/trace.h +++ b/kernel/trace/trace.h @@ -915,8 +915,17 @@ enum { 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 + * function is called to clear it. + */ + TRACE_GRAPH_NOTRACE_BIT, }; +#define TRACE_GRAPH_NOTRACE (1 << TRACE_GRAPH_NOTRACE_BIT) + static inline unsigned long ftrace_graph_depth(unsigned long *task_var) { return (*task_var >> TRACE_GRAPH_DEPTH_START_BIT) & 3; diff --git a/kernel/trace/trace_functions_graph.c b/kernel/trace/trace_functions_graph.c index 66cce73e94f8..13d0387ac6a6 100644 --- a/kernel/trace/trace_functions_graph.c +++ b/kernel/trace/trace_functions_graph.c @@ -130,6 +130,7 @@ static inline int ftrace_graph_ignore_irqs(void) int trace_graph_entry(struct ftrace_graph_ent *trace, struct fgraph_ops *gops) { + unsigned long *task_var = fgraph_get_task_var(gops); struct trace_array *tr = gops->private; struct trace_array_cpu *data; unsigned long flags; @@ -138,7 +139,7 @@ int trace_graph_entry(struct ftrace_graph_ent *trace, int ret; int cpu; - if (trace_recursion_test(TRACE_GRAPH_NOTRACE_BIT)) + if (*task_var & TRACE_GRAPH_NOTRACE) return 0; /* @@ -149,7 +150,7 @@ int trace_graph_entry(struct ftrace_graph_ent *trace, * returning from the function. */ if (ftrace_graph_notrace_addr(trace->func)) { - trace_recursion_set(TRACE_GRAPH_NOTRACE_BIT); + *task_var |= TRACE_GRAPH_NOTRACE_BIT; /* * Need to return 1 to have the return called * that will clear the NOTRACE bit. @@ -240,6 +241,7 @@ void __trace_graph_return(struct trace_array *tr, void trace_graph_return(struct ftrace_graph_ret *trace, struct fgraph_ops *gops) { + unsigned long *task_var = fgraph_get_task_var(gops); struct trace_array *tr = gops->private; struct trace_array_cpu *data; unsigned long flags; @@ -249,8 +251,8 @@ void trace_graph_return(struct ftrace_graph_ret *trace, ftrace_graph_addr_finish(gops, trace); - if (trace_recursion_test(TRACE_GRAPH_NOTRACE_BIT)) { - trace_recursion_clear(TRACE_GRAPH_NOTRACE_BIT); + if (*task_var & TRACE_GRAPH_NOTRACE) { + *task_var &= ~TRACE_GRAPH_NOTRACE; return; }