From patchwork Fri Jan 12 10:14:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Masami Hiramatsu (Google)" X-Patchwork-Id: 187678 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2614:b0:101:6a76:bbe3 with SMTP id mm20csp77512dyc; Fri, 12 Jan 2024 02:17:41 -0800 (PST) X-Google-Smtp-Source: AGHT+IEiFGkxBClQAUf8P1f8GiwaZgxP+aBvZd1+v/YWPv9HTMX+cUbTftV99YiCRxNe2B5D1TZi X-Received: by 2002:a17:907:1608:b0:a2c:e148:e2d7 with SMTP id cw8-20020a170907160800b00a2ce148e2d7mr157705ejd.2.1705054661416; Fri, 12 Jan 2024 02:17:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1705054661; cv=none; d=google.com; s=arc-20160816; b=oAyITJqoRNAxrfB7jptZUrQZweTOaApdaiN/eoL5kN0uakcsc17aPItj77+C652ZZK NP82df8hEXTujIHESPvImM6aEuRkrFj0JniD7wZucnWvEfnRo2TT0J5UtNNH5jd3W9Ds 7A7DPIoOrPFZ9wKsHPG8jErm40Shi6nx4Br3i16EgKQRvDvdb6qzzUXL6rWk0NGHGHTq degcQ0hLXUpECdn/8L2dBc7A8uAR3DCrfeEsP+faeOByzw63/708Wtf/E1gOGxr19g1k sxc4hVNfs/NRxhNdOxVL36M87UlaoJEICOoGVaelMZLwswLBpSYVJ82L3ukUdQ+ZR7Vw Pc5A== ARC-Message-Signature: i=1; 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=ocz7aahkU1q+mzRbwwD6DbRc+cK1SxI84ZYWCER1RQI=; fh=SIgps5XdV0XNwjZfT2uAI7g3mrspDldK9Qs8qQAfoa4=; b=aM45A6DhRcihF/1T8AO8GrdeephXy8QQonkbToEbOJ1SvD8iSjn5fMLHdA7wdv419o wwgqqyPGryg0g3w7clzHdgvFNCm6fLh2U6ZZq2Z+uYZjbhv56Pxf55nofJBiCexBbQ7c bSqQI1HexKdaoXOKy1zme45BJ/5WXaAQAyXjydIzeHpXHYtEwk7igMzl9X82+8cj9BSq OHU6dkiCp8yt0b/rinVqDs3LEqL5MbvFGIxA0bQMC5IPHHF8VfxmcSnbfPY1XqIWDSO4 GKBI4o2yc9T73fiKux0kuSLLTcihiCubLqRPcvf9x96LsxansfgQzDl9cTwdLo/g+i/m Uaow== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=fTopnriY; spf=pass (google.com: domain of linux-kernel+bounces-24566-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-24566-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id ks3-20020a170906f84300b00a26b9a288bfsi1295052ejb.370.2024.01.12.02.17.41 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Jan 2024 02:17:41 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-24566-ouuuleilei=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=fTopnriY; spf=pass (google.com: domain of linux-kernel+bounces-24566-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-24566-ouuuleilei=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 0E9291F23479 for ; Fri, 12 Jan 2024 10:17:41 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 03D07627FC; Fri, 12 Jan 2024 10:14:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="fTopnriY" 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 605115EE98; Fri, 12 Jan 2024 10:14:29 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 15094C433C7; Fri, 12 Jan 2024 10:14:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1705054469; bh=QNjMxMJQNC5kAkv3s4bCawBXsRiU8SwHk0osgr4U2eM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=fTopnriYzv+U5ebJAQmvl+MBX+tx4BJqyLju5NGK05KETD2TdyPCPS7lgJ1n7r95V MkbZtkiqziaf6s4mA2rldnuAdBG/j9KbVvpkFulyiGmCdH2kMCo+dEYpULgUlUl7+z haFuM1G8nbqmDIfQClB8y2soCKflYk7I0ma8gbl1DE+vTH9Oxft56YLtmpbN5eMfY+ ItAZ3WLfo6TdZksty/xGKlXBLIZt+vKXl/CiHfCpVQtkoYoJaId90kej0q7p2tDVPp hp0wn9Jge9AQYR2BX7gfPbNkXzykVr/wOoYSVEsZtzS3TnBsAJodIs2047OvAs5BhB Szgip2VEuEMwg== 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 v6 18/36] function_graph: Move graph notrace bit to shadow stack global var Date: Fri, 12 Jan 2024 19:14:23 +0900 Message-Id: <170505446356.459169.7646049202447015855.stgit@devnote2> X-Mailer: git-send-email 2.34.1 In-Reply-To: <170505424954.459169.10630626365737237288.stgit@devnote2> References: <170505424954.459169.10630626365737237288.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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1787879396361731230 X-GMAIL-MSGID: 1787879396361731230 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 1a467b5437b3..1dfa031c2812 100644 --- a/kernel/trace/trace.h +++ b/kernel/trace/trace.h @@ -916,8 +916,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; }