Received: by 2002:ab2:69cc:0:b0:1f4:be93:e15a with SMTP id n12csp1416353lqp; Mon, 15 Apr 2024 06:10:07 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVGJ5arO33lOxZE6nu8avwH5zuq9cCBSLiC/r7a23MlY2iY/OmPcFtoAjPJ4XCNpIe3Tjn5Wea0L07DxYFzfc+5UUOtzA+TsIlHhoW4mw== X-Google-Smtp-Source: AGHT+IFw5OKbO5ut7bkUjMDNIIeqsg2oCSFNBjLVAREGiKdN8sf1TNPHfCs4GIDIohe8Q3QoYuFV X-Received: by 2002:ac8:7d86:0:b0:436:8ca3:2b3c with SMTP id c6-20020ac87d86000000b004368ca32b3cmr12049031qtd.18.1713186606812; Mon, 15 Apr 2024 06:10:06 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713186606; cv=pass; d=google.com; s=arc-20160816; b=UijjrRk2gFtx+60lLuVs5mHAGMNDMX8q/ZHvIU55SfLYvleoyNZhkbNUY1aCD8fkW9 xf7uGmfUXXKYpdIxx0si8eEeWwGdF6P0QGvEU9Iph02mkgVbvjGMEWECvziUgr02GG6g x6KCMDZuZqosERfNxqXX44sWpCUBbKBd/oRU9A6CBnTKn6krxtPrLRI5fTTgUAI8ZXky mQ1rGj8lP+DYjAYGQU5aSx7nFh54xZmnX14CZQDIBvVvM4qR7JjrsN9fcSlcJQ9ueO+w LCy/yZ7AVux1GI+RxqgCdfTevC0Nul05aN+StrDy83pVKk0+6u38dwPgJOjf+LUz0Vsu nDsw== 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=EMrnNQzyKO3udbk8jdeNivR0XkdPgyT0kDN7nC0zXEM=; fh=SIgps5XdV0XNwjZfT2uAI7g3mrspDldK9Qs8qQAfoa4=; b=PdvJnEBPri52N5X3p+vAvW2WH3dlqMzW2spWZPvGkgtA3rvWFkC3dhvfPwjALRLsmV NTSeLB71mnZxpGyH4Fr0TXraZR7uMLtn2jF2SqyfDo0DOU1KVQRFzcW8s4ie9h6X4fzk EACJdtKgs9f0xHDzm4d0HyrGb+6P7H7ssF0zrhpuKCvLewioLRAA9vQHdGwm1oyOmzzu tJ6R9/kL01nhQc+UR4YqR73ctxlbX8zt62ALmOVQFl/yKneZG63ztxKmaRGY1xfOhnUD 54RoKjf8pTfnG9uHIMPNkpfWrg6KWhCkzF3TGep+xLVJJqAP45Cu8EvKfVr4eZk+pI8x EUlg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=DCYRHe6u; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-145178-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-145178-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id i6-20020ac85e46000000b004346ffa8ee1si10675037qtx.122.2024.04.15.06.10.06 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Apr 2024 06:10:06 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-145178-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=DCYRHe6u; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-145178-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-145178-linux.lists.archive=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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 888361C22387 for ; Mon, 15 Apr 2024 13:09:33 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1257E13A248; Mon, 15 Apr 2024 12:52:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="DCYRHe6u" 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 2733F73174; Mon, 15 Apr 2024 12:52:13 +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=1713185533; cv=none; b=t4Pziw9wOVfEvfXlWw3E4VXOeKW6LIDGMk/JP7Q7VUY85uBMumaVGComUr8jB1i3vQithv9gcr6NuAULRoQb/ZvGch2QXTbEBAYnfXbwd3nXEA87Ss+G+laH6OIOGADry58CkZ5KeI4TOmik21HLMLRdszprlaSE8yF5KjLGROQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713185533; c=relaxed/simple; bh=OMLO4V7EVUvQEW3fkooPL+MnS6qs8p/iD4poivn/7fk=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=Xg2GpunpI4dDCBzmZq/V8eBRtz5Ba6c/Wfa7jiGAMGHg2iWDXX0diRYD3NB/wx1MliZ9dXgj3jBKqchnTj4/dLtBOdZQD2Swr0El9ZNSb97CyzaIeIMUMS+Ha+BNvuu+TOPmNjmwZXxU7D+itkLx2/aJJqZVOzhmiJoSU5KCJzg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=DCYRHe6u; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6C8D8C113CC; Mon, 15 Apr 2024 12:52:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1713185533; bh=OMLO4V7EVUvQEW3fkooPL+MnS6qs8p/iD4poivn/7fk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=DCYRHe6upp/CcXMD3oVYYiDbQA2fHh3sPW0s05XRhode15nz410BxLtPb4HFAOMX/ cQCl/5mx+jo+JQtdGqTKSRrnXc+y8a4yZlnHaF7ACVTEW6hDrfcxsnhzzTHt86yIXy g1y3yzu+BOwVOMY+EI0tZGwX0ceHbhrhrhGJD2Am7Xe9Z0lG9/jPbw114EAgZWzPRQ fXJwxREibWkM7XDi6BP9wE4UPC/4QluLzVF0SM/VkIbY3h5WUAieQjmQx0aJeu+PbZ qncbjMa4O3R9ERHaaxrmFXn3I6gKSNGdm79SFsfuR8Zsm/YaKF/rJAiRpHUb+dcJNQ a0qWP34dfLbkA== 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 v9 16/36] function_graph: Move graph depth stored data to shadow stack global var Date: Mon, 15 Apr 2024 21:52:07 +0900 Message-Id: <171318552698.254850.9979168950308797013.stgit@devnote2> X-Mailer: git-send-email 2.34.1 In-Reply-To: <171318533841.254850.15841395205784342850.stgit@devnote2> References: <171318533841.254850.15841395205784342850.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 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit From: Steven Rostedt (VMware) The use of the task->trace_recursion for the logic used for the function graph depth 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 | 29 ----------------------------- kernel/trace/trace.h | 34 ++++++++++++++++++++++++++++++++-- 2 files changed, 32 insertions(+), 31 deletions(-) diff --git a/include/linux/trace_recursion.h b/include/linux/trace_recursion.h index 2efd5ec46d7f..00e792bf148d 100644 --- a/include/linux/trace_recursion.h +++ b/include/linux/trace_recursion.h @@ -44,25 +44,6 @@ enum { */ TRACE_IRQ_BIT, - /* - * In the very unlikely case that an interrupt came in - * at a start of graph tracing, and we want to trace - * the function in that interrupt, the depth can be greater - * than zero, because of the preempted start of a previous - * trace. In an even more unlikely case, depth could be 2 - * if a softirq interrupted the start of graph tracing, - * followed by an interrupt preempting a start of graph - * tracing in the softirq, and depth can even be 3 - * if an NMI came in at the start of an interrupt function - * that preempted a softirq start of a function that - * preempted normal context!!!! Luckily, it can't be - * greater than 3, so the next two bits are a mask - * of what the depth is when we set TRACE_GRAPH_FL - */ - - 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 @@ -78,16 +59,6 @@ enum { #define trace_recursion_clear(bit) do { (current)->trace_recursion &= ~(1<<(bit)); } while (0) #define trace_recursion_test(bit) ((current)->trace_recursion & (1<<(bit))) -#define trace_recursion_depth() \ - (((current)->trace_recursion >> TRACE_GRAPH_DEPTH_START_BIT) & 3) -#define trace_recursion_set_depth(depth) \ - do { \ - current->trace_recursion &= \ - ~(3 << TRACE_GRAPH_DEPTH_START_BIT); \ - current->trace_recursion |= \ - ((depth) & 3) << TRACE_GRAPH_DEPTH_START_BIT; \ - } while (0) - #define TRACE_CONTEXT_BITS 4 #define TRACE_FTRACE_START TRACE_FTRACE_BIT diff --git a/kernel/trace/trace.h b/kernel/trace/trace.h index c7c7e7c9f700..7ab731b9ebc8 100644 --- a/kernel/trace/trace.h +++ b/kernel/trace/trace.h @@ -899,8 +899,38 @@ extern void free_fgraph_ops(struct trace_array *tr); enum { TRACE_GRAPH_FL = 1, + + /* + * In the very unlikely case that an interrupt came in + * at a start of graph tracing, and we want to trace + * the function in that interrupt, the depth can be greater + * than zero, because of the preempted start of a previous + * trace. In an even more unlikely case, depth could be 2 + * if a softirq interrupted the start of graph tracing, + * followed by an interrupt preempting a start of graph + * tracing in the softirq, and depth can even be 3 + * if an NMI came in at the start of an interrupt function + * that preempted a softirq start of a function that + * preempted normal context!!!! Luckily, it can't be + * greater than 3, so the next two bits are a mask + * of what the depth is when we set TRACE_GRAPH_FL + */ + + TRACE_GRAPH_DEPTH_START_BIT, + TRACE_GRAPH_DEPTH_END_BIT, }; +static inline unsigned long ftrace_graph_depth(unsigned long *task_var) +{ + return (*task_var >> TRACE_GRAPH_DEPTH_START_BIT) & 3; +} + +static inline void ftrace_graph_set_depth(unsigned long *task_var, int depth) +{ + *task_var &= ~(3 << TRACE_GRAPH_DEPTH_START_BIT); + *task_var |= (depth & 3) << TRACE_GRAPH_DEPTH_START_BIT; +} + #ifdef CONFIG_DYNAMIC_FTRACE extern struct ftrace_hash __rcu *ftrace_graph_hash; extern struct ftrace_hash __rcu *ftrace_graph_notrace_hash; @@ -933,7 +963,7 @@ ftrace_graph_addr(unsigned long *task_var, struct ftrace_graph_ent *trace) * when the depth is zero. */ *task_var |= TRACE_GRAPH_FL; - trace_recursion_set_depth(trace->depth); + ftrace_graph_set_depth(task_var, trace->depth); /* * If no irqs are to be traced, but a set_graph_function @@ -958,7 +988,7 @@ ftrace_graph_addr_finish(struct fgraph_ops *gops, struct ftrace_graph_ret *trace unsigned long *task_var = fgraph_get_task_var(gops); if ((*task_var & TRACE_GRAPH_FL) && - trace->depth == trace_recursion_depth()) + trace->depth == ftrace_graph_depth(task_var)) *task_var &= ~TRACE_GRAPH_FL; }