From patchwork Tue Feb 6 15:10:50 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: 197494 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp1608574dyb; Tue, 6 Feb 2024 07:15:23 -0800 (PST) X-Google-Smtp-Source: AGHT+IGxxHhZZlqmYIg8Seb4O1yR0vGHVJMDUxk1Jx6jmazsUiiz8H4mXK0e8TV+4sCodhNrrCBe X-Received: by 2002:a17:906:31c6:b0:a38:801:6770 with SMTP id f6-20020a17090631c600b00a3808016770mr2756239ejf.24.1707232523376; Tue, 06 Feb 2024 07:15:23 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707232523; cv=pass; d=google.com; s=arc-20160816; b=OHusW3XYWhSGjCqD0Kofsl1dn0kDBYw2Mv0FgnbLPyM/1eCUlQH/796nQylYsZaqOc tjF8U902F3o1Br5KyhHoYTqVDcDT2nt0KcsLH0kDnuSQ4+cLQNKa/vaNxj7TIJTfYP6x Kxt9P1PFv8Ek8V5uuzzsWPbt18qq4YO17Zb1t8fB0V1e1dmqwkgeytOHallWm61Ujs0d 6xijhPKkMm44LoH4OgWq/gvNQz+gsYR1CCoAzCransWxLkKUtrNQDKPHyXEJx16mxIg4 M8qtUKMir8YF5hT6XVc4GD8KkG2KUTVIUR5O51cuOZs/Gg0N3XRcAvODr98Yfvcffdja 5Ciw== ARC-Message-Signature: i=2; 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=CgjbyiPfUVr56PkrTBGflIyaHfPHVrAirnWqGZAFJy8=; fh=cFg/BCY0leMmooSxAw6Eo7J7ceKE0gF7bsd5ektg0jQ=; b=P2X6n9xxckryuNX452HY53RmjrsWfm/j5hqZaFFWnr992b3UIMRpHIOQXFwKbKssRD wbsD/5CDPH5YVoWKdO8iqWgjy7U48GHeFvdLez5NTcHZLszW7CqBNP1UsAdp6msw2A8l duauc7juMXDMdbwOA7XUzvwS1P3u86vkD904jDHRHQ64eDI/Q7ySzzd8lnuk+S5bbyV/ /t04h3JkXlZ4kx1hKJciBMqd/PbR7dqGS0ohxOHsh/Skk1LJD6zFmnZWFDTKYseUANuK 3a4yeYhqvprQitBhfmZ6wVKR7vm6iK3ZXPHN0qt7mDnlsnS9dIItMEebAvmkAnQNp5y+ bH0A==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="T/4N5YOC"; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-55196-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-55196-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org X-Forwarded-Encrypted: i=1; AJvYcCWBUvzNofQKveaeLabkWo5Q4qKcIASdJBdf8imq6Mw4IpRYfHmv3fuNcvFE6kKo5T36QbcY+b3FliObSfXhTrzjXpOM1g== Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id t25-20020a1709066bd900b00a384f537a74si143278ejs.860.2024.02.06.07.15.23 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Feb 2024 07:15:23 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-55196-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="T/4N5YOC"; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-55196-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-55196-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 F1A391F22885 for ; Tue, 6 Feb 2024 15:15:22 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D369EA59; Tue, 6 Feb 2024 15:10:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="T/4N5YOC" 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 19951134CFC; Tue, 6 Feb 2024 15:10:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707232256; cv=none; b=R/R9BpCVKrfSv+OzCTjsqCjweRSzldzyRpylR7oQCHExiqvthbwsQzUPT6hvJLhmcBbuWNV0CE8RSAJhqW4D3sgYDjCitBba241Sve1+yZeVGS9uL1Ml9m/cceEIdJnJ0mT1boeW7iUqFgHVdMmA18FP1R4i7sHdVMUJpghGvuo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707232256; c=relaxed/simple; bh=XT8mAO5U8kYBF5nHzre3NP4S7gGsaqfcEiXyQTVrS+w=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=ZTxsAHiVgw/dEPExONl1Qxts0eVsK3ptKWTs9QObO20H6ftGZyHYO2/Wcwfrls9qS5PWg6esTg7za4nOvu33bw6N6GmVCgWH7IIWi2J80buEBbkaw4+FPMuZmvVX7MBSWvA5W8spfrUS7QZdvS3KiErABF9suRw+Yad5RnpDWtU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=T/4N5YOC; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id ABAC7C433C7; Tue, 6 Feb 2024 15:10:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1707232255; bh=XT8mAO5U8kYBF5nHzre3NP4S7gGsaqfcEiXyQTVrS+w=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=T/4N5YOCnRDcLX/JjZRuT1ZrzMUhmlwFugMIeQXUi+cmemubEX/Ty40c0JklpMR9O a9M3+BBrmqjP6scM2QbsIaxkeCHi1p1lQuTgROaAPgE+ld3TN/ZnV+AD7zngU+RegR dv//Y3DkIRvv7zIgigLFMI1YWuJs0WLOgQWw3Hr8U5LmxphN/Dlkne9z2Ae7UMPh4a FMKJQItEN5BEAAnu4cWsNyhgqQvXa64IEXypv0uQI7tAMnHQt8rjR7pRqJz8Rl2Eh7 b1NnkwdKvwvZ+kMz+DbL/+42tOXXsXQMXAnSzL667XKN84o15Gw8AjjJ3PJp/mlyLK z5TeeA2Is6aqg== 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 v7 18/36] function_graph: Move graph notrace bit to shadow stack global var Date: Wed, 7 Feb 2024 00:10:50 +0900 Message-Id: <170723225020.502590.2063430645806603064.stgit@devnote2> X-Mailer: git-send-email 2.34.1 In-Reply-To: <170723204881.502590.11906735097521170661.stgit@devnote2> References: <170723204881.502590.11906735097521170661.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: 1790163050419715895 X-GMAIL-MSGID: 1790163050419715895 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 d8cdcbb4e5a6..029a80a38c23 100644 --- a/kernel/trace/trace.h +++ b/kernel/trace/trace.h @@ -918,8 +918,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; }