From mboxrd@z Thu Jan 1 00:00:00 1970 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 B835A3D75AE; Wed, 4 Mar 2026 22:03:00 +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=1772661780; cv=none; b=V6GlZsz+cnwFq56jNyV7V+S66ZJJJA1L6sBysDLJV2OuxhmECySPEqsNn1r3Sks1N6lPezpcdbItQEBtOJPrrpkFJhJMmy1p4Ltz9VP7cgZU4ZtN/uuujwxDC4YRSaHTsux2dKb3bzjpz4LflPkH58uyedAsGq6OjLVwA4yc04c= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772661780; c=relaxed/simple; bh=JtVyn/J1VepzhDKxVBAvYJ/BmMmBffLK0UXbcjin1T8=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=BzvgEpmAd/FzmiNiCR/BZg2ixI3srSq7sHbZYoTkaEL3nbhcRg3yw+1Z5llf6buWCRNlFmQ26iv3FM+ZLmi6CDqvod219WUdVm6iNlmG9bjVm2jk8Cv8YBL1t3sdYJ+er0092h/bUJdKvQafArbBczuO1DtU/dQPxJFYP/Fi2x8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=oXsbM/8O; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="oXsbM/8O" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6E03BC2BCAF; Wed, 4 Mar 2026 22:03:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1772661780; bh=JtVyn/J1VepzhDKxVBAvYJ/BmMmBffLK0UXbcjin1T8=; h=Date:From:To:Cc:Subject:References:From; b=oXsbM/8OCJ2loOoypdiN6faEHTN3RQPgJ+qxtJAqFrbUO6K7BTT9/vvvNwX2BVgal VfYuhhkUlmfSI2/T+05ZtnR/WsFd513QabKX0ZoQdgkMEJdKpTvVJXCLcQTfO896jK KzhqPJ+HNWMnOO6eIWSoSfYFtLJrWR0Uc3ow8fvmflk2FjUyFvQvr9CPD/MNwWwpdn J1XDNCZ+EP4RnSyylzNjox01e+nsE5HFnmxIL5znblKJV76Q76cxawOj0ZyHIJ3Kaf 9eSjV7+e/bvYpKZHdnPc+faQIkuLArBtNdl4CZOioqjmS0jJWwtOcCMEpTbH3fNMZJ 2zrCZIMpwF3Vg== Received: from rostedt by gandalf with local (Exim 4.99.1) (envelope-from ) id 1vxuJd-00000003CRH-2pWg; Wed, 04 Mar 2026 17:03:37 -0500 Message-ID: <20260304220337.531696199@kernel.org> User-Agent: quilt/0.69 Date: Wed, 04 Mar 2026 17:03:21 -0500 From: Steven Rostedt To: linux-kernel@vger.kernel.org Cc: Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Andrew Morton , stable@vger.kernel.org, Shengming Hu Subject: [for-linus][PATCH 2/6] fgraph: Fix thresh_return nosleeptime double-adjust References: <20260304220319.218314827@kernel.org> Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 From: Shengming Hu trace_graph_thresh_return() called handle_nosleeptime() and then delegated to trace_graph_return(), which calls handle_nosleeptime() again. When sleep-time accounting is disabled this double-adjusts calltime and can produce bogus durations (including underflow). Fix this by computing rettime once, applying handle_nosleeptime() only once, using the adjusted calltime for threshold comparison, and writing the return event directly via __trace_graph_return() when the threshold is met. Cc: stable@vger.kernel.org Link: https://patch.msgid.link/20260221113314048jE4VRwIyZEALiYByGK0My@zte.com.cn Fixes: 3c9880f3ab52b ("ftrace: Use a running sleeptime instead of saving on shadow stack") Acked-by: Masami Hiramatsu (Google) Signed-off-by: Shengming Hu Signed-off-by: Steven Rostedt (Google) --- kernel/trace/trace_functions_graph.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/kernel/trace/trace_functions_graph.c b/kernel/trace/trace_functions_graph.c index 817d0f1696b6..0d2d3a2ea7dd 100644 --- a/kernel/trace/trace_functions_graph.c +++ b/kernel/trace/trace_functions_graph.c @@ -403,8 +403,12 @@ static void trace_graph_thresh_return(struct ftrace_graph_ret *trace, unsigned long *task_var = fgraph_get_task_var(gops); struct fgraph_times *ftimes; struct trace_array *tr; + unsigned int trace_ctx; + u64 calltime, rettime; int size; + rettime = trace_clock_local(); + ftrace_graph_addr_finish(gops, trace); if (*task_var & TRACE_GRAPH_NOTRACE) { @@ -419,11 +423,13 @@ static void trace_graph_thresh_return(struct ftrace_graph_ret *trace, tr = gops->private; handle_nosleeptime(tr, trace, ftimes, size); - if (tracing_thresh && - (trace_clock_local() - ftimes->calltime < tracing_thresh)) + calltime = ftimes->calltime; + + if (tracing_thresh && (rettime - calltime < tracing_thresh)) return; - else - trace_graph_return(trace, gops, fregs); + + trace_ctx = tracing_gen_ctx(); + __trace_graph_return(tr, trace, trace_ctx, calltime, rettime); } static struct fgraph_ops funcgraph_ops = { -- 2.51.0