bpf: Check flags for branch stack in bpf_read_branch_records helper
Subsystems (4)
Jiri Olsa
reviewerPATCH 1/1 bpf: Check flags for branch stack in bpf_read_branch_records helper
Recent commit [1] changed branch stack data indication from br_stack pointer to sample_flags in perf_sample_data struct.
We need to check sample_flags for PERF_SAMPLE_BRANCH_STACK bit for valid branch stack data.
[1] a9a931e26668 ("perf: Use sample_flags for branch stack")
---
NOTE sending on top of tip/master because [1] is not
merged in bpf-next/master yet
kernel/trace/bpf_trace.c | 3 +++ 1 file changed, 3 insertions(+)
kernel/trace/bpf_trace.c +3 -0
@@ -1507,6 +1507,9 @@ BPF_CALL_4(bpf_read_branch_records, struct bpf_perf_event_data_kern *, ctx,if (unlikely (flags & ~BPF_F_GET_BRANCH_RECORDS_SIZE ))return -EINVAL ; +if (unlikely (!(ctx->data->sample_flags &PERF_SAMPLE_BRANCH_STACK ))) +return -ENOENT ; +if (unlikely (!br_stack))return -ENOENT ;
Signature · 1 line
2.37.3
Quoted 11 lines · Jiri Olsa
Recent commit [1] changed branch stack data indication from
br_stackpointer tosample_flagsinperf_sample_datastruct.We need to check
sample_flagsforPERF_SAMPLE_BRANCH_STACKbit for valid branch stack data.[1]
a9a931e26668("perf: Usesample_flagsfor branch stack")Cc Kan Liang <[email protected]>Fixes a9a931e26668 ("perf: Use sample_flags for branch stack")Signed-off-by Jiri Olsa <[email protected]>
Thanks for the fix.
Thanks,
Kan
Quoted 21 lines
---
NOTE sending on top of tip/master because [1] is not
merged in bpf-next/master yetkernel/trace/bpf_trace.c | 3 +++ 1 file changed, 3 insertions(+)kernel/trace/bpf_trace.c +3
-0@@ -1507,6 +1507,9 @@ BPF_CALL_4(bpf_read_branch_records, struct bpf_perf_event_data_kern *, ctx,if (unlikely (flags & ~BPF_F_GET_BRANCH_RECORDS_SIZE ))return -EINVAL ; +if (unlikely (!(ctx->data->sample_flags &PERF_SAMPLE_BRANCH_STACK ))) +return -ENOENT ; +if (unlikely (!br_stack))return -ENOENT ;
Quoted 6 lines · Jiri Olsa
Recent commit [1] changed branch stack data indication from
br_stackpointer tosample_flagsinperf_sample_datastruct.We need to check
sample_flagsforPERF_SAMPLE_BRANCH_STACKbit for valid branch stack data.
Quoted 8 lines
[1]
a9a931e26668("perf: Usesample_flagsfor branch stack")Cc Kan Liang <[email protected]>Fixes a9a931e26668 ("perf: Use sample_flags for branch stack")Signed-off-by Jiri Olsa <[email protected]>---
NOTE sending on top of tip/master because [1] is not
merged in bpf-next/master yet
Shall I stick this in tip/perf/core right along with [1] then?
Quoted 9 lines · Peter Zijlstra
Quoted 8 lines · Jiri Olsa
Recent commit [1] changed branch stack data indication from
br_stackpointer tosample_flagsinperf_sample_datastruct.We need to check
sample_flagsforPERF_SAMPLE_BRANCH_STACKbit for valid branch stack data.[1]
a9a931e26668("perf: Usesample_flagsfor branch stack")
Quoted 8 lines
Quoted 6 lines
Cc Kan Liang <[email protected]>Fixes a9a931e26668 ("perf: Use sample_flags for branch stack")Signed-off-by Jiri Olsa <[email protected]>---
NOTE sending on top of tip/master because [1] is not
merged in bpf-next/master yetShall I stick this in tip/perf/core right along with [1] then?
yes, sounds good
thanks,
jirka
Quoted 7 lines · Jiri Olsa
Recent commit [1] changed branch stack data indication from
br_stackpointer tosample_flagsinperf_sample_datastruct.
Quoted 8 lines
We need to check
sample_flagsforPERF_SAMPLE_BRANCH_STACKbit for valid branch stack data.[1]
a9a931e26668("perf: Usesample_flagsfor branch stack")Cc Kan Liang <[email protected]>Fixes a9a931e26668 ("perf: Use sample_flags for branch stack")Signed-off-by Jiri Olsa <[email protected]>
Thanks for the fix! I noticed the issue last week, but haven't got time to look into it.
Song
Quoted 24 lines
---
NOTE sending on top of tip/master because [1] is not
merged in bpf-next/master yet
kernel/trace/bpf_trace.c| 3 +++1 file changed, 3 insertions(+)kernel/trace/bpf_trace.c +3
-0@@ -1507,6 +1507,9 @@ BPF_CALL_4(bpf_read_branch_records, struct bpf_perf_event_data_kern *, ctx,if (unlikely (flags & ~BPF_F_GET_BRANCH_RECORDS_SIZE ))return -EINVAL ; +if (unlikely (!(ctx->data->sample_flags &PERF_SAMPLE_BRANCH_STACK ))) +return -ENOENT ; +if (unlikely (!br_stack))return -ENOENT ;Signature · 1 line
2.37.3
Song Liu
Acked-byQuoted 11 lines · Song Liu
Quoted 8 lines · Jiri Olsa
Recent commit [1] changed branch stack data indication from
br_stackpointer tosample_flagsinperf_sample_datastruct.
Quoted 8 lines
Quoted 8 lines
We need to check
sample_flagsforPERF_SAMPLE_BRANCH_STACKbit for valid branch stack data.[1]
a9a931e26668("perf: Usesample_flagsfor branch stack")Cc Kan Liang <[email protected]>Fixes a9a931e26668 ("perf: Use sample_flags for branch stack")Signed-off-by Jiri Olsa <[email protected]>
Quoted 29 lines
Thanks for the fix! I noticed the issue last week, but haven't got time to look into it.
Song
Quoted 23 lines
---
NOTE sending on top of tip/master because [1] is not
merged in bpf-next/master yet
kernel/trace/bpf_trace.c| 3 +++1 file changed, 3 insertions(+)kernel/trace/bpf_trace.c +3
-0@@ -1507,6 +1507,9 @@ BPF_CALL_4(bpf_read_branch_records, struct bpf_perf_event_data_kern *, ctx,if (unlikely (flags & ~BPF_F_GET_BRANCH_RECORDS_SIZE ))return -EINVAL ; +if (unlikely (!(ctx->data->sample_flags &PERF_SAMPLE_BRANCH_STACK ))) +return -ENOENT ; +if (unlikely (!br_stack))return -ENOENT ;Signature · 1 line
2.37.3
The following commit has been merged into the perf/core branch of tip:
The following commit has been merged into the perf/core branch of tip:
Commit-ID: cce6a2d7e0e494c453ad73e1e78bd50684f20cca Gitweb: https://git.kernel.org/tip/cce6a2d7e0e494c453ad73e1e78bd50684f20cca Author: Jiri Olsa <[email protected]> AuthorDate: Tue, 27 Sep 2022 22:32:59 +02:00 Committer: Peter Zijlstra <[email protected]> CommitterDate: Tue, 27 Sep 2022 22:50:25 +02:00
bpf: Check flags for branch stack in bpf_read_branch_records helper
Recent commit [1] changed branch stack data indication from br_stack pointer to sample_flags in perf_sample_data struct.
We need to check sample_flags for PERF_SAMPLE_BRANCH_STACK bit for valid branch stack data.
[1] a9a931e26668 ("perf: Use sample_flags for branch stack")
--- kernel/trace/bpf_trace.c | 3 +++ 1 file changed, 3 insertions(+)
kernel/trace/bpf_trace.c +3 -0
@@ -1507,6 +1507,9 @@ BPF_CALL_4(bpf_read_branch_records, struct bpf_perf_event_data_kern *, ctx,if (unlikely (flags & ~BPF_F_GET_BRANCH_RECORDS_SIZE ))return -EINVAL ; +if (unlikely (!(ctx->data->sample_flags &PERF_SAMPLE_BRANCH_STACK ))) +return -ENOENT ; +if (unlikely (!br_stack))return -ENOENT ;