From patchwork Wed Nov 8 14:27:27 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: 163050 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:aa0b:0:b0:403:3b70:6f57 with SMTP id k11csp949850vqo; Wed, 8 Nov 2023 06:28:32 -0800 (PST) X-Google-Smtp-Source: AGHT+IG31IhKtu67Xdlw7nnwL4vGgKZIwpMHXHfLrk4vS+X1gXk4OntFuVy4Z7EBSPK2v9ZGwb5p X-Received: by 2002:a17:902:da85:b0:1cc:5835:9630 with SMTP id j5-20020a170902da8500b001cc58359630mr2206634plx.30.1699453712050; Wed, 08 Nov 2023 06:28:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1699453712; cv=none; d=google.com; s=arc-20160816; b=GBUQKMsANPtdVxTX/QnOsvYtWQ1B8+68Ecnc2MsIHqPUqFbJPuSAj/sl+1anCYkA6C L9bdjoG/hrDyVo7Q8AnBd8u/Glv9+xWwNT1D65kBXw1pDN4TFXqSbAMGleZ8XLTUIeyQ qqhtAmitxQfnNToE4wgHehO7squVfmHje3NEIl0pvVkHbzEaJjdGXgwlIcucs/jn9CfQ 0N81O7cJ4dM5P7c5PKjtX+RHtfVA101K0UFUApqIefaFd84JjPd96D14zG+p2wJw3mMz JHFsQKwGeD+zxcXDNeu1DEllsX2r1dSA4YdQjs1av97lh08oIforJi+OH1BgkmOayk5P V/vg== 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=Ih7foLE9yrXjw3EVDGiI2vJzA3x2/UbIlB5AjZuDwHQ=; fh=SIgps5XdV0XNwjZfT2uAI7g3mrspDldK9Qs8qQAfoa4=; b=mLkK2uVW+5okPkF15jdR7Rd27bzSZCjp7o6oD4S6DjGFKsfV6NUIKbsjfJCLmZyNsB 3ZmF3/XCxEtBiPVzkYGrNEmG3yI97v3zq0eDqkXn03H9xlsbq+rcr0awAyFMe8VkSmXK mN7wLjJPYMg2Zzvsvd25YNlsfH96tV79n8DUYMHnd/qytLqFF6xQ6p8/R6vt9lFJ8pwS 8arIp9uDUd0OqmBXg0moIfnD3VKWLcpn2lSNMN7xjLD6TgduJ+VDElPBWCzUmdhe5pto /asgL4kZQMUWqG/Fl9rfdgMwDNYHorZPkciEsg04twc9a3oQP6HE51wuPyIdzmWvc3tB ryjg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=DohexUuD; 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 u1-20020a170902e80100b001c6223663b3si2437006plg.369.2023.11.08.06.28.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Nov 2023 06:28:32 -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=DohexUuD; 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 C96D081CFF17; Wed, 8 Nov 2023 06:28:23 -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 S1344080AbjKHO2G (ORCPT + 32 others); Wed, 8 Nov 2023 09:28:06 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35514 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1343846AbjKHO1k (ORCPT ); Wed, 8 Nov 2023 09:27:40 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A5F521FF6 for ; Wed, 8 Nov 2023 06:27:32 -0800 (PST) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 30239C433C9; Wed, 8 Nov 2023 14:27:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1699453652; bh=AazvW4/a90V/YIaJshYrFG/FkUTxnxIHHqFsOEqmNJ4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=DohexUuDrJLVtXyYt2QY1NH+ByHMTlsNWR/xtWNi+f16WQzyj7RApB2lZEO0ue2U2 daoiGdIt2mMnqaffz8Z/7DGuSz97i9RrI3ZMvU9lkd2/X4j2SMXSOeYdarSnAv0cKB aagkuyx7DkWqwZTSHrk+Rovl0KtUXVEE4mHkb8X8cqN0YmREE4evEWtqwQicje0lZk os8vM3BFF1CYqQymMTlz8v6rZr7N+Fsbct8M/BnFLudVBepjL/hZsKMg35oF1BiQdx 1Y4UebYZ/HkWVngvSj0T8rMEIQ25qcFyoa0j+cvjgBmP68jS1hoJo/B+UM6NQUV8M5 1f/aApGWx0ctw== 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 16/31] function_graph: Move graph notrace bit to shadow stack global var Date: Wed, 8 Nov 2023 23:27:27 +0900 Message-Id: <169945364658.55307.8169090480122784915.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:23 -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: 1782006375807088476 X-GMAIL-MSGID: 1782006375807088476 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 cbe44998ef77..27b2b52c36cc 100644 --- a/kernel/trace/trace.h +++ b/kernel/trace/trace.h @@ -910,8 +910,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; }