Skip to contentSkip to conversation

ftrace: properly merge notrace hash

PATCH Superseded Andy Chiu 2 participants 3 messages Apr 7, 2025 – Apr 8, 2025

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Andy Chiu

author
#0 lore raw

PATCH 1/1 ftrace: properly merge notrace hash

The global notrace hash should be jointly decided by the intersection of each subops's notrace hash, but not the filter hash.

Fixes 5fccc7552ccb ("ftrace: Add subops logic to allow one ops to manage many")
---
 kernel/trace/ftrace.c | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)
kernel/trace/ftrace.c +5 -6
index 1a48aedb5255..ee662f380b61 100644
@@ -3526,18 +3526,17 @@ int ftrace_startup_subops(struct ftrace_ops *ops, struct ftrace_ops *subops, int
 	    ftrace_hash_empty(subops->func_hash->notrace_hash)) {
 		notrace_hash = EMPTY_HASH;
 	} else {
-		size_bits = max(ops->func_hash->filter_hash->size_bits,
-				subops->func_hash->filter_hash->size_bits);
+		size_bits = max(ops->func_hash->notrace_hash->size_bits,
+				subops->func_hash->notrace_hash->size_bits);
 		notrace_hash = alloc_ftrace_hash(size_bits);
 		if (!notrace_hash) {
-			free_ftrace_hash(filter_hash);
+			free_ftrace_hash(notrace_hash);
 			return -ENOMEM;
 		}
 
-		ret = intersect_hash(&notrace_hash, ops->func_hash->filter_hash,
-				     subops->func_hash->filter_hash);
+		ret = intersect_hash(&notrace_hash, ops->func_hash->notrace_hash,
+				     subops->func_hash->notrace_hash);
 		if (ret < 0) {
-			free_ftrace_hash(filter_hash);
 			free_ftrace_hash(notrace_hash);
 			return ret;
 		}
Signature · 1 line
2.39.3 (Apple Git-145)
maintainer
#1 lore raw
Quoted 22 lines · On Tue, 8 Apr 2025 02:07:44 +0800 Andy Chiu <[email protected]> wrote:

The global notrace hash should be jointly decided by the intersection of each subops's notrace hash, but not the filter hash.

Fixes 5fccc7552ccb ("ftrace: Add subops logic to allow one ops to manage many")
---
 kernel/trace/ftrace.c | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)
kernel/trace/ftrace.c +2 -2
index 1a48aedb5255..ee662f380b61 100644
@@ -3526,18 +3526,17 @@ int ftrace_startup_subops(struct ftrace_ops *ops, struct ftrace_ops *subops, int
 	    ftrace_hash_empty(subops->func_hash->notrace_hash)) {
 		notrace_hash = EMPTY_HASH;
 	} else {
-		size_bits = max(ops->func_hash->filter_hash->size_bits,
-				subops->func_hash->filter_hash->size_bits);
+		size_bits = max(ops->func_hash->notrace_hash->size_bits,
+				subops->func_hash->notrace_hash->size_bits);
 		notrace_hash = alloc_ftrace_hash(size_bits);

kernel/trace/ftrace.c int ftrace_startup_subops(struct ftrace_ops *ops, struct ftrace_ops *subops, int · line 3538

Quoted 10 lines
kernel/trace/ftrace.c +3 -3
 		if (!notrace_hash) {
-			free_ftrace_hash(filter_hash);
+			free_ftrace_hash(notrace_hash);
 			return -ENOMEM;
 		}
 
-		ret = intersect_hash(&notrace_hash, ops->func_hash->filter_hash,
-				     subops->func_hash->filter_hash);
+		ret = intersect_hash(&notrace_hash, ops->func_hash->notrace_hash,
+				     subops->func_hash->notrace_hash);

Thanks for catching this.

kernel/trace/ftrace.c int ftrace_startup_subops(struct ftrace_ops *ops, struct ftrace_ops *subops, int · line 3540

Quoted 2 lines
kernel/trace/ftrace.c +0 -1
 		if (ret < 0) {
-			free_ftrace_hash(filter_hash);

The filter_hash still needs to be freed, as it could have been allocated in the previous if statement and never used (both the filter_hash and notrace_hash get used at the end of the function via ftrace_update_ops().

Care to send a v2?

-- Steve

Quoted 3 lines
kernel/trace/ftrace.c +0 -0
 			free_ftrace_hash(notrace_hash);
 			return ret;
 		}
author
#2 lore raw

Steven Rostedt <[email protected]> 於 2025年4月8日 週二 上午4:08寫道:

Quoted 40 lines
Quoted 22 lines · On Tue, 8 Apr 2025 02:07:44 +0800 Andy Chiu <[email protected]> wrote:

The global notrace hash should be jointly decided by the intersection of each subops's notrace hash, but not the filter hash.

Fixes 5fccc7552ccb ("ftrace: Add subops logic to allow one ops to manage many")
---
 kernel/trace/ftrace.c | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)
kernel/trace/ftrace.c +2 -2
index 1a48aedb5255..ee662f380b61 100644
@@ -3526,18 +3526,17 @@ int ftrace_startup_subops(struct ftrace_ops *ops, struct ftrace_ops *subops, int
          ftrace_hash_empty(subops->func_hash->notrace_hash)) {
              notrace_hash = EMPTY_HASH;
      } else {
-             size_bits = max(ops->func_hash->filter_hash->size_bits,
-                             subops->func_hash->filter_hash->size_bits);
+             size_bits = max(ops->func_hash->notrace_hash->size_bits,
+                             subops->func_hash->notrace_hash->size_bits);
              notrace_hash = alloc_ftrace_hash(size_bits);

kernel/trace/ftrace.c int ftrace_startup_subops(struct ftrace_ops *ops, struct ftrace_ops *subops, int · line 3538

Quoted 10 lines
kernel/trace/ftrace.c +3 -3
              if (!notrace_hash) {
-                     free_ftrace_hash(filter_hash);
+                     free_ftrace_hash(notrace_hash);
                      return -ENOMEM;
              }
 
-             ret = intersect_hash(&notrace_hash, ops->func_hash->filter_hash,
-                                  subops->func_hash->filter_hash);
+             ret = intersect_hash(&notrace_hash, ops->func_hash->notrace_hash,
+                                  subops->func_hash->notrace_hash);

Thanks for catching this.

Quoted 8 lines

kernel/trace/ftrace.c int ftrace_startup_subops(struct ftrace_ops *ops, struct ftrace_ops *subops, int · line 3540

Quoted 2 lines
kernel/trace/ftrace.c +0 -1
              if (ret < 0) {
-                     free_ftrace_hash(filter_hash);

The filter_hash still needs to be freed, as it could have been allocated in the previous if statement and never used (both the filter_hash and notrace_hash get used at the end of the function via ftrace_update_ops().

Care to send a v2?

Yes, thanks for reminding! Let me send a v2 with filter_hash freed on this condition.

Regards,
Andy