From patchwork Mon Nov 27 13:56:11 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: 170160 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:ce62:0:b0:403:3b70:6f57 with SMTP id o2csp3134776vqx; Mon, 27 Nov 2023 06:02:48 -0800 (PST) X-Google-Smtp-Source: AGHT+IFihKQBExjQDd7u2XQTuhsTevH7ilE7yGR+CeDLbZAH0Xu2Uz5Hsltu36HzVCG5kkFQd8R5 X-Received: by 2002:a0d:cc13:0:b0:5cc:355e:5e93 with SMTP id o19-20020a0dcc13000000b005cc355e5e93mr12131187ywd.22.1701093768255; Mon, 27 Nov 2023 06:02:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701093768; cv=none; d=google.com; s=arc-20160816; b=nm/uSDMOmySbDHluZrGfiUHuZY0CIDfq1JMoK2dSK4vgBzbfdDvIgkMBqxxjKC7CtE e3bVrh88b9qerThzzRPQOzW8nf+JnIvY+wbS+sBA8rJKzmIwgANyvMgvbWBtrwrhgbD6 +d+fsdBytoCg5TdyElWRqQaI1svQkDg1gZv0i8niLcSqOlwSTu6Ska76DlyJW7NteqA5 6eT9e49dhq9qmMvnrS+0QOec2AH59Be2tK5g9X1RfhEcO152qrZmvkcsUlCs9GsP4oJB h/sRDziduHcZzpCzTOiL+e2cmoX22RKkTJ6oL4+MrCAlqwUGw7tGH5JYwd6Snx/kQF2z 05Vw== 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=Sqau8jjxI7eVfJDYoYUHkatHawFmyaTdEE/ez6xeVDAWdD9wItkT3hyURKfy39rvsM l98D9k3x7BDo9XrEBEXZt9YqmvXLFEGA36gDnoltPB3eFVvADuWQCsBnojKT0EbPrjCo xovO9WirAPYlBL0pdEb1Rj6SP86Oxd15EnuI61bJW4itlCNUrBnvMbVCthEwTkggU9QR Wr3KCFqBSieLscciHX7usZNYSuv53Jx5beBLh/4e04+1ltrX9r6fDIFbMAm0hKnKsJpy tJMoyhG3V08ec4MmG+larGarm77geP6qG3PPBulFG/znBzEexmCixZPnAVFn8x0NjdoH YSPQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=ntekJ5o1; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 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 snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id o18-20020a817e12000000b005839b8c52d0si5646369ywn.484.2023.11.27.06.02.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Nov 2023 06:02:48 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=ntekJ5o1; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 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 snail.vger.email (Postfix) with ESMTP id 965B0806B54A; Mon, 27 Nov 2023 06:01:30 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233423AbjK0OBH (ORCPT + 99 others); Mon, 27 Nov 2023 09:01:07 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38894 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233569AbjK0N64 (ORCPT ); Mon, 27 Nov 2023 08:58:56 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1E6A01988 for ; Mon, 27 Nov 2023 05:56:19 -0800 (PST) Received: by smtp.kernel.org (Postfix) with ESMTPSA id EEEF8C433D9; Mon, 27 Nov 2023 13:56:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1701093378; bh=AazvW4/a90V/YIaJshYrFG/FkUTxnxIHHqFsOEqmNJ4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ntekJ5o1Kg3FOTwvmE8wk2UcJ8STdTR6o0/0mRObGaDja1IUR/mN09HwhSyCHrQ7Y tKDmmGDJGr3zPJdSqeHibckLzET5C27oB5k+1YgcrC5+hE5J6/QcYdWcXJ/rv6+cO1 vysHWZ5eJ3w9reVI7N0wUSGA28Qmmy6WT/bnKGhqP3rXf2TPbUs/al9MBVY/ErwtzI thRFEEBt8L8GxozyFzO4kpX/M35wAnUyjZfElwVMGGBylfW/3B/bQ/B1WFvrdCZFQN M4hXsZWM3++MEYDBmzfDFSVdxLzWaVSRZ23A13EzcBvZiO1h8CbGpb+uMZAH9tMmXb wSu39Vjd0DFnQ== 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 v3 16/33] function_graph: Move graph notrace bit to shadow stack global var Date: Mon, 27 Nov 2023 22:56:11 +0900 Message-Id: <170109337141.343914.17947410912543913151.stgit@devnote2> X-Mailer: git-send-email 2.34.1 In-Reply-To: <170109317214.343914.4784420430328654397.stgit@devnote2> References: <170109317214.343914.4784420430328654397.stgit@devnote2> User-Agent: StGit/0.19 MIME-Version: 1.0 X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net 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 (snail.vger.email [0.0.0.0]); Mon, 27 Nov 2023 06:01:30 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1783726099174905728 X-GMAIL-MSGID: 1783726099174905728 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; }