Skip to contentSkip to conversation

perf: get_perf_callchain return NULL for crosstask

PATCH In review Jordan Rome 3 participants 3 messages Nov 11, 2023 – Nov 12, 2023

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

PATCH v2 1/1 perf: get_perf_callchain return NULL for crosstask

Return NULL instead of returning 1 incorrect frame, which currently happens when trying to walk the user stack for any task that isn't current. Returning NULL is a better indicator that this behavior is not supported.

This issue was found using bpf_get_task_stack inside a BPF iterator ("iter/task"), which iterates over all tasks. The single address/frame in the buffer when getting user stacks for tasks that aren't current could not be symbolized (testing multiple symbolizers).

---

Changes in v2:
* move user and crosstask check before get_callchain_entry

v1:
https://lore.kernel.org/linux-perf-users/CAEf4BzaWtOeTBb_+b7Td3NHaKjZU+OohuBJje_nvw9kd6xPA3g@mail.gmail.com/T/#t

 kernel/events/callchain.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)
kernel/events/callchain.c +3 -4
index 1273be84392c..104ea2975a57 100644
@@ -184,6 +184,9 @@ get_perf_callchain(struct pt_regs *regs, u32 init_nr, bool kernel, bool user,
 	struct perf_callchain_entry_ctx ctx;
 	int rctx;
 
+	if (user && crosstask)
+		return NULL;
+
 	entry = get_callchain_entry(&rctx);
 	if (!entry)
 		return NULL;
@@ -209,9 +212,6 @@ get_perf_callchain(struct pt_regs *regs, u32 init_nr, bool kernel, bool user,
 		}
 
 		if (regs) {
-			if (crosstask)
-				goto exit_put;
-
 			if (add_mark)
 				perf_callchain_store_context(&ctx, PERF_CONTEXT_USER);
 
@@ -219,7 +219,6 @@ get_perf_callchain(struct pt_regs *regs, u32 init_nr, bool kernel, bool user,
 		}
 	}
 
-exit_put:
 	put_callchain_entry(rctx);
 
 	return entry;
Signature · 1 line
2.39.3
Acked-by on v2 1/1
#1 lore raw
Quoted 12 lines · Jordan Rome

Return NULL instead of returning 1 incorrect frame, which currently happens when trying to walk the user stack for any task that isn't current. Returning NULL is a better indicator that this behavior is not supported.

This issue was found using bpf_get_task_stack inside a BPF iterator ("iter/task"), which iterates over all tasks. The single address/frame in the buffer when getting user stacks for tasks that aren't current could not be symbolized (testing multiple symbolizers).

Quoted 6 lines

---

Changes in v2:
* move user and crosstask check before get_callchain_entry

LGTM.

Quoted 41 lines

v1:
https://lore.kernel.org/linux-perf-users/CAEf4BzaWtOeTBb_+b7Td3NHaKjZU+OohuBJje_nvw9kd6xPA3g@mail.gmail.com/T/#t

 kernel/events/callchain.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)
kernel/events/callchain.c +3 -5
index 1273be84392c..104ea2975a57 100644
@@ -184,6 +184,9 @@ get_perf_callchain(struct pt_regs *regs, u32 init_nr, bool kernel, bool user,
        struct perf_callchain_entry_ctx ctx;
        int rctx;
 
+       if (user && crosstask)
+               return NULL;
+
        entry = get_callchain_entry(&rctx);
        if (!entry)
                return NULL;
@@ -209,9 +212,6 @@ get_perf_callchain(struct pt_regs *regs, u32 init_nr, bool kernel, bool user,
                }
 
                if (regs) {
-                       if (crosstask)
-                               goto exit_put;
-
                        if (add_mark)
                                perf_callchain_store_context(&ctx, PERF_CONTEXT_USER);
 
@@ -219,7 +219,6 @@ get_perf_callchain(struct pt_regs *regs, u32 init_nr, bool kernel, bool user,
                }
        }
 
-exit_put:
        put_callchain_entry(rctx);
 
        return entry;
--

2.39.3

Acked-by on v2 1/1
#2 lore raw
In reply to Jordan Rome
Quoted 5 lines · Jordan Rome

Return NULL instead of returning 1 incorrect frame, which currently happens when trying to walk the user stack for any task that isn't current. Returning NULL is a better indicator that this behavior is not supported.

Quoted 7 lines

This issue was found using bpf_get_task_stack inside a BPF iterator ("iter/task"), which iterates over all tasks. The single address/frame in the buffer when getting user stacks for tasks that aren't current could not be symbolized (testing multiple symbolizers).

jirka

Quoted 47 lines

---

Changes in v2:
* move user and crosstask check before get_callchain_entry

v1:
https://lore.kernel.org/linux-perf-users/CAEf4BzaWtOeTBb_+b7Td3NHaKjZU+OohuBJje_nvw9kd6xPA3g@mail.gmail.com/T/#t

 kernel/events/callchain.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)
kernel/events/callchain.c +3 -4
index 1273be84392c..104ea2975a57 100644
@@ -184,6 +184,9 @@ get_perf_callchain(struct pt_regs *regs, u32 init_nr, bool kernel, bool user,
 	struct perf_callchain_entry_ctx ctx;
 	int rctx;
 
+	if (user && crosstask)
+		return NULL;
+
 	entry = get_callchain_entry(&rctx);
 	if (!entry)
 		return NULL;
@@ -209,9 +212,6 @@ get_perf_callchain(struct pt_regs *regs, u32 init_nr, bool kernel, bool user,
 		}
 
 		if (regs) {
-			if (crosstask)
-				goto exit_put;
-
 			if (add_mark)
 				perf_callchain_store_context(&ctx, PERF_CONTEXT_USER);
 
@@ -219,7 +219,6 @@ get_perf_callchain(struct pt_regs *regs, u32 init_nr, bool kernel, bool user,
 		}
 	}
 
-exit_put:
 	put_callchain_entry(rctx);
 
 	return entry;
Signature · 1 line
2.39.3