From patchwork Sun Nov 5 16:09:21 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: 161671 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:8f47:0:b0:403:3b70:6f57 with SMTP id j7csp2197236vqu; Sun, 5 Nov 2023 08:09:51 -0800 (PST) X-Google-Smtp-Source: AGHT+IH6Ld03HMmxzE1HCc0pOJkNSrfTRNPWMUAKVbsirFBL35T+e4s6butc2tu2lOY/R2QME+vp X-Received: by 2002:a05:6358:5e0c:b0:168:e898:fb7d with SMTP id q12-20020a0563585e0c00b00168e898fb7dmr20883810rwn.28.1699200590884; Sun, 05 Nov 2023 08:09:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1699200590; cv=none; d=google.com; s=arc-20160816; b=srGkJzmej866T6ttfyHxswIbovRMs02iTh1UFD3UZgYotKjeW0P+LlG77w3Iqmz5Ua eId6yoSovD2cxPNfidTLfGPWwn1q578ow50Dz2y7QAgI/xKgu8lRHBJNFPhVCPra1YAY 9p8MdpBdtANYI2wf0JhBYrE5xZKGfu6/civDvPLpkWzCiOT8TJ9MYID3RTCT1TsZQxiz CPmGWFCUyCBZJufoMfSMiwO9r3qRmolD2HxNYe3y4h404FXpj5cHTxVAuVW8gNIXcvYI QGzP7rJj/uHiC54gESeEjizsyb6YbFkbpaHkIRS/9p2rOs5m+AuL6TTnybJd9ccMjHHM bziQ== 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=l4+nrejjmjt+quOSeWblSaRKiBZpudQWmKBCVtfL5xM=; fh=SIgps5XdV0XNwjZfT2uAI7g3mrspDldK9Qs8qQAfoa4=; b=OmB9whhbmGD3W6IchyY0oVl/kC8m4FRklGZir0WSzU5Bb9mR4lNrsVDhgWcKEFimYr xTmWWjrQnQOKfLy+roCo9tilABwicUcapjAMS6ntDuU8WYKqVOlIlRxVV6Av4qkDnTeN IorSE8ulnI1Xvw9GH2QOQf34+gZNibmgzf83nTGOdbIG9DufyqaXI9QByM4yEP1oGvei BISVuHPX0ul287NQcx/KxXrUj3IuUqoDNym0tAS9odY7p+HCno3DwdMArpGVKFPw9/Si q+XNqiJW6bU2yIGvXUyUXjXygxNroCuZfzwBuWR0sqHKrbGZ6a9M79XDBnGmhDGe+US8 jo/g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=hzsj6qVn; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 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. [2620:137:e000::3:3]) by mx.google.com with ESMTPS id i186-20020a6387c3000000b005b8817b3cb0si5965250pge.65.2023.11.05.08.09.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 05 Nov 2023 08:09:50 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) client-ip=2620:137:e000::3:3; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=hzsj6qVn; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 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 8BEF38053620; Sun, 5 Nov 2023 08:09:48 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229913AbjKEQJf (ORCPT + 34 others); Sun, 5 Nov 2023 11:09:35 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47566 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229633AbjKEQJa (ORCPT ); Sun, 5 Nov 2023 11:09:30 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 32FBED77 for ; Sun, 5 Nov 2023 08:09:28 -0800 (PST) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E758DC433C7; Sun, 5 Nov 2023 16:09:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1699200567; bh=yEhjs0R0Qef2/83fXa4qLGdcMfbIL29IAkz328qo8AA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hzsj6qVnQRs/v+v15sUROz1C+2AWBJYj5dYYAzCNaDUDke8KQ8Anv4ESb9v0XeTyK dvtK9bMb7OvyK06lzfrQDZuhtFghRP2nct9W7yiSmaSfIBdf8s8JeThxQPqd4LpS2O eQS1zMDhzSy7NPdcaCzAQzBFU/Vd9UT+TwUrAQPjdgeAlJy8vXiqU6u2Ht58qYNMYk +hQkAYZQtaycBwQtr3SwW6g7j18R+e+iWqdFcIgTIY6DLMLUF95M4Vhc419VV8aREF JU9gO5G/mnl4hjWzLIC+efxxmdPaVxqYGTxxLkOsrhLQyxYt3A2rhQV66+THSQJdZZ avnpAvBjktNXg== 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 14/32] function_graph: Move graph notrace bit to shadow stack global var Date: Mon, 6 Nov 2023 01:09:21 +0900 Message-Id: <169920056100.482486.10749804996506200504.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 lipwig.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 (lipwig.vger.email [0.0.0.0]); Sun, 05 Nov 2023 08:09:48 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1781740958457262343 X-GMAIL-MSGID: 1781740958457262343 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) --- 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 8e5943d3d25c..350c889c2f1e 100644 --- a/kernel/trace/trace.h +++ b/kernel/trace/trace.h @@ -911,8 +911,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; }