diff mbox series

[-tip] bpf: Check flags for branch stack in bpf_read_branch_records helper

Message ID 20220927203259.590950-1-jolsa@kernel.org (mailing list archive)
State New, archived
Delegated to: BPF
Headers show
Series [-tip] bpf: Check flags for branch stack in bpf_read_branch_records helper | expand

Checks

Context Check Description
netdev/tree_selection success Guessed tree name to be net-next
netdev/fixes_present success Fixes tag not required for -next series
netdev/subject_prefix warning Target tree name not specified in the subject
netdev/cover_letter success Single patches do not need cover letters
netdev/patch_count success Link
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit fail Errors and warnings before: 11 this patch: 5
netdev/cc_maintainers warning 11 maintainers not CCed: sdf@google.com john.fastabend@gmail.com andrii@kernel.org yhs@fb.com rostedt@goodmis.org ast@kernel.org haoluo@google.com kpsingh@kernel.org song@kernel.org daniel@iogearbox.net martin.lau@linux.dev
netdev/build_clang fail Errors and warnings before: 5 this patch: 6
netdev/module_param success Was 0 now: 0
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes fail Problems with Fixes tag: 1
netdev/build_allmodconfig_warn fail Errors and warnings before: 11 this patch: 5
netdev/checkpatch warning WARNING: Unknown commit id 'a9a931e26668', maybe rebased or not pulled?
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0
bpf/vmtest-bpf-next-PR fail PR summary
bpf/vmtest-bpf-next-VM_Test-1 fail Logs for build for s390x with gcc
bpf/vmtest-bpf-next-VM_Test-2 fail Logs for build for s390x with gcc
bpf/vmtest-bpf-next-VM_Test-3 fail Logs for build for x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-4 fail Logs for build for x86_64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-5 success Logs for llvm-toolchain
bpf/vmtest-bpf-next-VM_Test-6 success Logs for set-matrix

Commit Message

Jiri Olsa Sept. 27, 2022, 8:32 p.m. UTC
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")

Cc: Kan Liang <kan.liang@linux.intel.com>
Fixes: a9a931e26668 ("perf: Use sample_flags for branch stack")
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
---
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(+)

Comments

Liang, Kan Sept. 27, 2022, 8:41 p.m. UTC | #1
On 2022-09-27 4:32 p.m., Jiri Olsa wrote:
> 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")
> 
> Cc: Kan Liang <kan.liang@linux.intel.com>
> Fixes: a9a931e26668 ("perf: Use sample_flags for branch stack")
> Signed-off-by: Jiri Olsa <jolsa@kernel.org>

Thanks for the fix.

Reviewed-by: Kan Liang <kan.liang@linux.intel.com>

Thanks,
Kan

> ---
> 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(+)
> 
> diff --git a/kernel/trace/bpf_trace.c b/kernel/trace/bpf_trace.c
> index 68e5cdd24cef..1fcd1234607e 100644
> --- a/kernel/trace/bpf_trace.c
> +++ b/kernel/trace/bpf_trace.c
> @@ -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;
>
Peter Zijlstra Sept. 27, 2022, 8:46 p.m. UTC | #2
On Tue, Sep 27, 2022 at 10:32:59PM +0200, Jiri Olsa wrote:
> 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")
> 
> Cc: Kan Liang <kan.liang@linux.intel.com>
> Fixes: a9a931e26668 ("perf: Use sample_flags for branch stack")
> Signed-off-by: Jiri Olsa <jolsa@kernel.org>
> ---
> 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?
Jiri Olsa Sept. 27, 2022, 9:24 p.m. UTC | #3
On Tue, Sep 27, 2022 at 10:46:12PM +0200, Peter Zijlstra wrote:
> On Tue, Sep 27, 2022 at 10:32:59PM +0200, Jiri Olsa wrote:
> > 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")
> > 
> > Cc: Kan Liang <kan.liang@linux.intel.com>
> > Fixes: a9a931e26668 ("perf: Use sample_flags for branch stack")
> > Signed-off-by: Jiri Olsa <jolsa@kernel.org>
> > ---
> > 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?

yes, sounds good

thanks,
jirka
Song Liu Sept. 27, 2022, 9:49 p.m. UTC | #4
> On Sep 27, 2022, at 1:32 PM, Jiri Olsa <jolsa@kernel.org> wrote:
> 
> 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")
> 
> Cc: Kan Liang <kan.liang@linux.intel.com>
> Fixes: a9a931e26668 ("perf: Use sample_flags for branch stack")
> Signed-off-by: Jiri Olsa <jolsa@kernel.org>

Thanks for the fix! I noticed the issue last week, but haven't
got time to look into it. 

Song

> ---
> 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(+)
> 
> diff --git a/kernel/trace/bpf_trace.c b/kernel/trace/bpf_trace.c
> index 68e5cdd24cef..1fcd1234607e 100644
> --- a/kernel/trace/bpf_trace.c
> +++ b/kernel/trace/bpf_trace.c
> @@ -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;
> 
> -- 
> 2.37.3
>
Song Liu Sept. 27, 2022, 9:50 p.m. UTC | #5
> On Sep 27, 2022, at 2:49 PM, Song Liu <songliubraving@fb.com> wrote:
> 
> 
> 
>> On Sep 27, 2022, at 1:32 PM, Jiri Olsa <jolsa@kernel.org> wrote:
>> 
>> 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")
>> 
>> Cc: Kan Liang <kan.liang@linux.intel.com>
>> Fixes: a9a931e26668 ("perf: Use sample_flags for branch stack")
>> Signed-off-by: Jiri Olsa <jolsa@kernel.org>

Acked-by: Song Liu <song@kernel.org>

> 
> Thanks for the fix! I noticed the issue last week, but haven't
> got time to look into it. 
> 
> Song
> 
>> ---
>> 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(+)
>> 
>> diff --git a/kernel/trace/bpf_trace.c b/kernel/trace/bpf_trace.c
>> index 68e5cdd24cef..1fcd1234607e 100644
>> --- a/kernel/trace/bpf_trace.c
>> +++ b/kernel/trace/bpf_trace.c
>> @@ -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;
>> 
>> -- 
>> 2.37.3
diff mbox series

Patch

diff --git a/kernel/trace/bpf_trace.c b/kernel/trace/bpf_trace.c
index 68e5cdd24cef..1fcd1234607e 100644
--- a/kernel/trace/bpf_trace.c
+++ b/kernel/trace/bpf_trace.c
@@ -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;