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 2ECC53793BA for ; Wed, 18 Mar 2026 13:13:55 +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=1773839636; cv=none; b=Q4wHckZE2PqZ4YVYyScYnvZ7Los10JpNn4Ow29t490dU6eAaILsbWnPABiRRnKdtf9kJFcPjEYcHY2TLDRuhrQlBPyh+DAdJrUD9jYerIf6lrSCnqImSktNV5Jy3UGKyrfbx6cPbFA1TWK7j14OWtIoWFZEfEJgGQcPPtg5Tj4Y= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773839636; c=relaxed/simple; bh=pg5b/sFk+xMixvySpdHTHu2wf33qexzP6uHrG5HlZFw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=KDyiJ/5du4FmW4D3qew+eOrt/Jh45r60ELr3fPTXqZtI1qwyZbS77Y3Ld4F8idVwkEVYp3p4OsW4NCd30L3Y44c6TSLy3E2c1cXK9M3kTdtG2QXajtQhrx8XzqLa55kn+tNKvrbLJkUFB2VEh8T6+JNnibp99Vt2DGZTAKT/v4s= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=O1MswW95; 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="O1MswW95" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2E1FFC19421; Wed, 18 Mar 2026 13:13:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1773839635; bh=pg5b/sFk+xMixvySpdHTHu2wf33qexzP6uHrG5HlZFw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=O1MswW951yzuViay0FPLdB/VEb1yxVJ7HPAd//R8xv8IEVUUVwtIrEzbvkL86LPxV nbaiDKXSxG7SvNIO+D/75McmOV4iErUn5KYYm/JNio39YDQsSA6byI1gKjFNp0njs8 dgc/a+mnhGlLUTKkMD4g5zmPcf6dz+BIJ9Pq0JEukcP6O9W2umYEvTou9eLclztzsx Q0IuOrvuLobU/IMaVtRHBLFTMe8qddKi9iJdYQTPQLXSPapaSD6czbKixLOE/gadHX pO9TQS9+1G0AHgJi4wgolGlVUFnOMQOB2AafdxxaTxHmGbUxWeN0uauzPM52wk/xXM I1V2gaUWfGtBA== From: Sasha Levin To: stable@vger.kernel.org Cc: Shengming Hu , "Masami Hiramatsu (Google)" , "Steven Rostedt (Google)" , Sasha Levin Subject: [PATCH 6.18.y] fgraph: Fix thresh_return nosleeptime double-adjust Date: Wed, 18 Mar 2026 09:13:53 -0400 Message-ID: <20260318131353.723405-1-sashal@kernel.org> X-Mailer: git-send-email 2.51.0 In-Reply-To: <2026031739-bride-reproduce-be1c@gregkh> References: <2026031739-bride-reproduce-be1c@gregkh> Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Shengming Hu [ Upstream commit b96d0c59cdbb2a22b2545f6f3d5c6276b05761dd ] 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) Signed-off-by: Sasha Levin --- kernel/trace/trace_functions_graph.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/kernel/trace/trace_functions_graph.c b/kernel/trace/trace_functions_graph.c index a7f4b9a47a71a..0e65d1f452657 100644 --- a/kernel/trace/trace_functions_graph.c +++ b/kernel/trace/trace_functions_graph.c @@ -378,9 +378,14 @@ static void trace_graph_thresh_return(struct ftrace_graph_ret *trace, struct fgraph_ops *gops, struct ftrace_regs *fregs) { + struct trace_array *tr = gops->private; struct fgraph_times *ftimes; + unsigned int trace_ctx; + u64 calltime, rettime; int size; + rettime = trace_clock_local(); + ftrace_graph_addr_finish(gops, trace); if (trace_recursion_test(TRACE_GRAPH_NOTRACE_BIT)) { @@ -394,11 +399,13 @@ static void trace_graph_thresh_return(struct ftrace_graph_ret *trace, handle_nosleeptime(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