Skip to contentSkip to conversation

ftrace: fix incorrect hash size in register_ftrace_direct()

PATCH In review Menglong Dong 4 participants 5 messages Apr 13, 2025 – Apr 16, 2025

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 ftrace: fix incorrect hash size in register_ftrace_direct()

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")

---
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(-)
kernel/trace/ftrace.c +4 -3
index 1a48aedb5255..d153ad13e0e0 100644
@@ -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;
 
Signature · 1 line
2.39.5
maintainer Acked-by on v2 1/1
#1 lore raw
Quoted 4 lines · On Sun, 13 Apr 2025 09:44:44 +0800 Menglong Dong <[email protected]>…

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.

Loogs good to me.

Thanks!

Quoted 32 lines
Fixes d05cb470663a ("ftrace: Fix modification of direct_function hash while in use")

---
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(-)
kernel/trace/ftrace.c +4 -3
index 1a48aedb5255..d153ad13e0e0 100644
@@ -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;
 
Signature · 1 line
2.39.5
Signature · 1 line
Masami Hiramatsu (Google) <[email protected]>
#2 lore raw
Quoted 9 lines · Masami Hiramatsu
Quoted 4 lines · On Sun, 13 Apr 2025 09:44:44 +0800 Menglong Dong <[email protected]>…

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.

Quoted 6 lines

Loogs good to me.

Thanks!

I'm a bit confused by the "[PATCH bpf]" prefix... This fix doesn't seem to be BPF-related, so I'm not sure why it would go through the bpf tree. I presume Masami or Steven will route it through their tree, is that right?

Quoted 37 lines
Quoted 29 lines
Fixes d05cb470663a ("ftrace: Fix modification of direct_function hash while in use")

---
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(-)
kernel/trace/ftrace.c +4 -4
index 1a48aedb5255..d153ad13e0e0 100644
@@ -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;
 
--
Quoted 3 lines

2.39.5

--
Masami Hiramatsu (Google) <[email protected]>

maintainer
#3 lore raw
Quoted 4 lines · On Tue, 15 Apr 2025 16:14:01 -0700 Andrii Nakryiko <[email protected]>…

I'm a bit confused by the "[PATCH bpf]" prefix... This fix doesn't seem to be BPF-related, so I'm not sure why it would go through the bpf tree. I presume Masami or Steven will route it through their tree, is that right?

I can take this in my tree.

-- Steve

#4 lore raw
In reply to Andrii Nakryiko
Quoted 15 lines · Andrii Nakryiko
Quoted 13 lines · Masami Hiramatsu
Quoted 4 lines · On Sun, 13 Apr 2025 09:44:44 +0800 Menglong Dong <[email protected]>…

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.

Loogs good to me.

Quoted 8 lines
Quoted 2 lines

Thanks!

I'm a bit confused by the "[PATCH bpf]" prefix... This fix doesn't seem to be BPF-related, so I'm not sure why it would go through the bpf tree. I presume Masami or Steven will route it through their tree, is that right?

Sorry about the confusing......I throught the register_ftrace_direct() is mainly used by BPF, and it should go to the ftrace tree :/

Thanks!
Menglong Dong

Quoted 38 lines
Quoted 38 lines
Quoted 30 lines
Fixes d05cb470663a ("ftrace: Fix modification of direct_function hash while in use")

---
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(-)
kernel/trace/ftrace.c +4 -4
index 1a48aedb5255..d153ad13e0e0 100644
@@ -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;
 
--
Quoted 3 lines

2.39.5

--
Masami Hiramatsu (Google) <[email protected]>