From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796335379; b=AS2V2fb0P92jnguiPUK7D1+wKPtezEKF8et2X6rO1B0Gq7HpY33dugR8orvNGI5sEez9 A1MkNnd0jqRF070jy5Vb8Mb/B2uHt0ltJSPDSa1MrMe+56F0Ro+lFxw45awjNB/UeWCXv i258Maj44lG1uQ00KfQ7wgidXKUxvK1lOvx3I2wti3RvQO3Is7VnE7YhvrzzjXcy2rEca fxxx+rbmFq9es6FCzYndS7KhiEynhyaKFnldEaV5Bw38zV6tdXLVkHFqHdLZtrru7QQVR Pg4u49zQGRr9Cypzq+5br8lM6jfKe+ARKxanK77WQ9KBBa4WZz9JGMT1DuYLX3Cgj0Q== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796335379; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:MIME-Version:Content-Transfer-Encoding; bh=H6IqI1DjiJ+iWo6mNQ7XJrQ05JrjNhpNHbDYB7Ghw4U=; b=Lpf/OcIyiH6JCn36MigHgaDSiuiyFEg2ZjExNY9whLdgz4anHmkfQlxtP4eFqnxqX5md /BuZ8RjfCh2E1Vhubp7K3W6M83OXGrslhdKZ1hxW9jLTKOw2UXUOVvo2wM9iXh4eQxgPT usYhAdwIkLuXDVI/NfcgSeudvE5V2rwqXa3ZOU3TsOHXiHX9U+X/oaaG1YmVVMP3CxqRu HBtm2QPkkcmSR8kb/rKaLznbM4uFu7T4f9s9TY3i2Tfv7+n/RE8iGxpjHCpbGzeNUVyrI FJENxr70dAVzq2KATW5xEoJJeCkvhsjjqJ9v/hebltF9uCd/Gs8fyNJTDGN+fVV+XNg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=kdZpclgH; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 220B8606A332; Thu, 3 Dec 2026 22:02:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=kdZpclgH Received: by smtp.kernel.org (Postfix) with ESMTPSA id 41FF51F00934; Thu, 3 Dec 2026 22:02:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796335378; bh=H6IqI1DjiJ+iWo6mNQ7XJrQ05JrjNhpNHbDYB7Ghw4U=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=kdZpclgHGvpE6QXvs4KdcSmnoa2yYedpTwxHabJ6L6zcUPgxZu9Y/tZMvvEQCUVBu PS52EGI9TnCnEVQRh/d5n2VBfsv6y27IIBQqPJhxe8iZaK9GZZzP3yWiKqdO89QP2C +lVtAaRJlE3SCy8m1hVx+Osk55igZF7F7IOSCNnf9CxXo8Do+R1f3/AfUcifqcGift kLPK38pt+2W1lFblPiTBiC53w3QxSixQK9OS0Cqgdb2NCfTU9roNG6AlbUz3cy8gmf yrSiv+VVFyQ9hen8X9P0P43jugcoKgXG3hNNptQFJuvF7+MOjqJtCH40rrLSqZns4g zX0ylyyhuvMUQ== From: Sasha Levin To: stable@vger.kernel.org Cc: "Masami Hiramatsu (Google)" , Alexei Starovoitov , Florent Revest , Martin KaFai Lau , bpf , Jiri Olsa , Alan Maguire , Mark Rutland , Michael Ellerman , Nicholas Piggin , Christophe Leroy , Naveen N Rao , Madhavan Srinivasan , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , Mathieu Desnoyers , "Steven Rostedt (Google)" , Sasha Levin Subject: [PATCH 6.12.y 1/2] fgraph: Get ftrace recursion lock in function_graph_enter Date: Thu, 3 Dec 2026 17:02:53 -0500 Message-ID: <20261203220245.782035-1-sashal@kernel.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <2026120236-tripping-outlast-4f1d@gregkh> References: <2026120236-tripping-outlast-4f1d@gregkh> X-Mailing-List: stable@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: "Masami Hiramatsu (Google)" [ Upstream commit d576aec24df9f58ed0ebe2ff854daafe837f0225 ] Get the ftrace recursion lock in the generic function_graph_enter() instead of each architecture code. This changes all function_graph tracer callbacks running in non-preemptive state. On x86 and powerpc, this is by default, but on the other architecutres, this will be new. Cc: Alexei Starovoitov Cc: Florent Revest Cc: Martin KaFai Lau Cc: bpf Cc: Jiri Olsa Cc: Alan Maguire Cc: Mark Rutland Cc: Michael Ellerman Cc: Nicholas Piggin Cc: Christophe Leroy Cc: Naveen N Rao Cc: Madhavan Srinivasan Cc: Thomas Gleixner Cc: Ingo Molnar Cc: Borislav Petkov Cc: Dave Hansen Cc: x86@kernel.org Cc: "H. Peter Anvin" Cc: Mathieu Desnoyers Link: https://lore.kernel.org/173379653720.973433.18438622234884980494.stgit@devnote2 Signed-off-by: Masami Hiramatsu (Google) Signed-off-by: Steven Rostedt (Google) Stable-dep-of: 65f42f1fa038 ("fgraph: Do not mark index 0 in every shadow stack frame") Signed-off-by: Sasha Levin --- arch/powerpc/kernel/trace/ftrace.c | 6 ------ arch/powerpc/kernel/trace/ftrace_64_pg.c | 6 ------ arch/x86/kernel/ftrace.c | 7 ------- kernel/trace/fgraph.c | 8 +++++++- 4 files changed, 7 insertions(+), 20 deletions(-) diff --git a/arch/powerpc/kernel/trace/ftrace.c b/arch/powerpc/kernel/trace/ftrace.c index df41f4a7c738b..4e09d140c5625 100644 --- a/arch/powerpc/kernel/trace/ftrace.c +++ b/arch/powerpc/kernel/trace/ftrace.c @@ -422,7 +422,6 @@ void ftrace_graph_func(unsigned long ip, unsigned long parent_ip, struct ftrace_ops *op, struct ftrace_regs *fregs) { unsigned long sp = arch_ftrace_regs(fregs)->regs.gpr[1]; - int bit; if (unlikely(ftrace_graph_is_dead())) goto out; @@ -430,14 +429,9 @@ void ftrace_graph_func(unsigned long ip, unsigned long parent_ip, if (unlikely(atomic_read(¤t->tracing_graph_pause))) goto out; - bit = ftrace_test_recursion_trylock(ip, parent_ip); - if (bit < 0) - goto out; - if (!function_graph_enter(parent_ip, ip, 0, (unsigned long *)sp)) parent_ip = ppc_function_entry(return_to_handler); - ftrace_test_recursion_unlock(bit); out: arch_ftrace_regs(fregs)->regs.link = parent_ip; } diff --git a/arch/powerpc/kernel/trace/ftrace_64_pg.c b/arch/powerpc/kernel/trace/ftrace_64_pg.c index d3c5552e4984d..9613717880de0 100644 --- a/arch/powerpc/kernel/trace/ftrace_64_pg.c +++ b/arch/powerpc/kernel/trace/ftrace_64_pg.c @@ -803,7 +803,6 @@ static unsigned long __prepare_ftrace_return(unsigned long parent, unsigned long ip, unsigned long sp) { unsigned long return_hooker; - int bit; if (unlikely(ftrace_graph_is_dead())) goto out; @@ -811,16 +810,11 @@ __prepare_ftrace_return(unsigned long parent, unsigned long ip, unsigned long sp if (unlikely(atomic_read(¤t->tracing_graph_pause))) goto out; - bit = ftrace_test_recursion_trylock(ip, parent); - if (bit < 0) - goto out; - return_hooker = ppc_function_entry(return_to_handler); if (!function_graph_enter(parent, ip, 0, (unsigned long *)sp)) parent = return_hooker; - ftrace_test_recursion_unlock(bit); out: return parent; } diff --git a/arch/x86/kernel/ftrace.c b/arch/x86/kernel/ftrace.c index 6bcc080f361e3..2653cae451928 100644 --- a/arch/x86/kernel/ftrace.c +++ b/arch/x86/kernel/ftrace.c @@ -620,7 +620,6 @@ void prepare_ftrace_return(unsigned long ip, unsigned long *parent, unsigned long frame_pointer) { unsigned long return_hooker = (unsigned long)&return_to_handler; - int bit; /* * When resuming from suspend-to-ram, this function can be indirectly @@ -640,14 +639,8 @@ void prepare_ftrace_return(unsigned long ip, unsigned long *parent, if (unlikely(atomic_read(¤t->tracing_graph_pause))) return; - bit = ftrace_test_recursion_trylock(ip, *parent); - if (bit < 0) - return; - if (!function_graph_enter(*parent, ip, frame_pointer, parent)) *parent = return_hooker; - - ftrace_test_recursion_unlock(bit); } #ifdef CONFIG_HAVE_DYNAMIC_FTRACE_WITH_ARGS diff --git a/kernel/trace/fgraph.c b/kernel/trace/fgraph.c index c2d9937158117..a58ec55a47f9b 100644 --- a/kernel/trace/fgraph.c +++ b/kernel/trace/fgraph.c @@ -622,8 +622,13 @@ int function_graph_enter(unsigned long ret, unsigned long func, struct ftrace_graph_ent trace; unsigned long bitmap = 0; int offset; + int bit; int i; + bit = ftrace_test_recursion_trylock(func, ret); + if (bit < 0) + return -EBUSY; + trace.func = func; trace.depth = ++current->curr_ret_depth; @@ -669,12 +674,13 @@ int function_graph_enter(unsigned long ret, unsigned long func, * flag, set that bit always. */ set_bitmap(current, offset, bitmap | BIT(0)); - + ftrace_test_recursion_unlock(bit); return 0; out_ret: current->curr_ret_stack -= FGRAPH_FRAME_OFFSET + 1; out: current->curr_ret_depth--; + ftrace_test_recursion_unlock(bit); return -EBUSY; } -- 2.53.0