public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH bpf v2] ftrace: fix incorrect hash size in register_ftrace_direct()
@ 2025-04-13  1:44 Menglong Dong
  2025-04-14  7:05 ` Masami Hiramatsu
  0 siblings, 1 reply; 5+ messages in thread
From: Menglong Dong @ 2025-04-13  1:44 UTC (permalink / raw)
  To: rostedt
  Cc: mhiramat, mark.rutland, mathieu.desnoyers, linux-kernel,
	linux-trace-kernel, bpf, Menglong Dong

The maximum of the ftrace hash bits is made fls(32) in
register_ftrace_direct(), which seems illogical. So, we fix it by making
the max hash bits FTRACE_HASH_MAX_BITS instead.

Fixes: d05cb470663a ("ftrace: Fix modification of direct_function hash while in use")
Signed-off-by: Menglong Dong <dongml2@chinatelecom.cn>
---
v2:
- thanks for Steven's advice, we fix the problem by making the max hash
  bits FTRACE_HASH_MAX_BITS instead.
---
 kernel/trace/ftrace.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
index 1a48aedb5255..d153ad13e0e0 100644
--- a/kernel/trace/ftrace.c
+++ b/kernel/trace/ftrace.c
@@ -5914,9 +5914,10 @@ int register_ftrace_direct(struct ftrace_ops *ops, unsigned long addr)
 
 	/* Make a copy hash to place the new and the old entries in */
 	size = hash->count + direct_functions->count;
-	if (size > 32)
-		size = 32;
-	new_hash = alloc_ftrace_hash(fls(size));
+	size = fls(size);
+	if (size > FTRACE_HASH_MAX_BITS)
+		size = FTRACE_HASH_MAX_BITS;
+	new_hash = alloc_ftrace_hash(size);
 	if (!new_hash)
 		goto out_unlock;
 
-- 
2.39.5


^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2025-04-16  1:08 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-04-13  1:44 [PATCH bpf v2] ftrace: fix incorrect hash size in register_ftrace_direct() Menglong Dong
2025-04-14  7:05 ` Masami Hiramatsu
2025-04-15 23:14   ` Andrii Nakryiko
2025-04-16  0:55     ` Steven Rostedt
2025-04-16  1:06     ` Menglong Dong

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox