All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH -tip] bpf: Check flags for branch stack in bpf_read_branch_records helper
@ 2022-09-27 20:32 Jiri Olsa
  2022-09-27 20:41 ` Liang, Kan
                   ` (3 more replies)
  0 siblings, 4 replies; 7+ messages in thread
From: Jiri Olsa @ 2022-09-27 20:32 UTC (permalink / raw)
  To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo
  Cc: Kan Liang, lkml, Ingo Molnar, Alexander Shishkin, Mark Rutland,
	Namhyung Kim, bpf, Song Liu, Daniel Xu

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(+)

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


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH -tip] bpf: Check flags for branch stack in bpf_read_branch_records helper
  2022-09-27 20:32 [PATCH -tip] bpf: Check flags for branch stack in bpf_read_branch_records helper Jiri Olsa
@ 2022-09-27 20:41 ` Liang, Kan
  2022-09-27 20:46 ` Peter Zijlstra
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 7+ messages in thread
From: Liang, Kan @ 2022-09-27 20:41 UTC (permalink / raw)
  To: Jiri Olsa, Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo
  Cc: lkml, Ingo Molnar, Alexander Shishkin, Mark Rutland,
	Namhyung Kim, bpf, Song Liu, Daniel Xu



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;
>  

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH -tip] bpf: Check flags for branch stack in bpf_read_branch_records helper
  2022-09-27 20:32 [PATCH -tip] bpf: Check flags for branch stack in bpf_read_branch_records helper Jiri Olsa
  2022-09-27 20:41 ` Liang, Kan
@ 2022-09-27 20:46 ` Peter Zijlstra
  2022-09-27 21:24   ` Jiri Olsa
  2022-09-27 21:49 ` Song Liu
  2022-09-28  6:57 ` [tip: perf/core] " tip-bot2 for Jiri Olsa
  3 siblings, 1 reply; 7+ messages in thread
From: Peter Zijlstra @ 2022-09-27 20:46 UTC (permalink / raw)
  To: Jiri Olsa
  Cc: Ingo Molnar, Arnaldo Carvalho de Melo, Kan Liang, lkml,
	Ingo Molnar, Alexander Shishkin, Mark Rutland, Namhyung Kim, bpf,
	Song Liu, Daniel Xu

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?

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH -tip] bpf: Check flags for branch stack in bpf_read_branch_records helper
  2022-09-27 20:46 ` Peter Zijlstra
@ 2022-09-27 21:24   ` Jiri Olsa
  0 siblings, 0 replies; 7+ messages in thread
From: Jiri Olsa @ 2022-09-27 21:24 UTC (permalink / raw)
  To: Peter Zijlstra
  Cc: Ingo Molnar, Arnaldo Carvalho de Melo, Kan Liang, lkml,
	Ingo Molnar, Alexander Shishkin, Mark Rutland, Namhyung Kim, bpf,
	Song Liu, Daniel Xu

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

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH -tip] bpf: Check flags for branch stack in bpf_read_branch_records helper
  2022-09-27 20:32 [PATCH -tip] bpf: Check flags for branch stack in bpf_read_branch_records helper Jiri Olsa
  2022-09-27 20:41 ` Liang, Kan
  2022-09-27 20:46 ` Peter Zijlstra
@ 2022-09-27 21:49 ` Song Liu
  2022-09-27 21:50   ` Song Liu
  2022-09-28  6:57 ` [tip: perf/core] " tip-bot2 for Jiri Olsa
  3 siblings, 1 reply; 7+ messages in thread
From: Song Liu @ 2022-09-27 21:49 UTC (permalink / raw)
  To: Jiri Olsa
  Cc: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo, Kan Liang,
	lkml, Ingo Molnar, Alexander Shishkin, Mark Rutland,
	Namhyung Kim, bpf, Daniel Xu



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


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH -tip] bpf: Check flags for branch stack in bpf_read_branch_records helper
  2022-09-27 21:49 ` Song Liu
@ 2022-09-27 21:50   ` Song Liu
  0 siblings, 0 replies; 7+ messages in thread
From: Song Liu @ 2022-09-27 21:50 UTC (permalink / raw)
  To: Jiri Olsa
  Cc: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo, Kan Liang,
	lkml, Ingo Molnar, Alexander Shishkin, Mark Rutland,
	Namhyung Kim, bpf, Daniel Xu



> 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


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [tip: perf/core] bpf: Check flags for branch stack in bpf_read_branch_records helper
  2022-09-27 20:32 [PATCH -tip] bpf: Check flags for branch stack in bpf_read_branch_records helper Jiri Olsa
                   ` (2 preceding siblings ...)
  2022-09-27 21:49 ` Song Liu
@ 2022-09-28  6:57 ` tip-bot2 for Jiri Olsa
  3 siblings, 0 replies; 7+ messages in thread
From: tip-bot2 for Jiri Olsa @ 2022-09-28  6:57 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: Jiri Olsa, Peter Zijlstra (Intel), Kan Liang, x86, linux-kernel

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 <jolsa@kernel.org>
AuthorDate:    Tue, 27 Sep 2022 22:32:59 +02:00
Committer:     Peter Zijlstra <peterz@infradead.org>
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")

Fixes: a9a931e26668 ("perf: Use sample_flags for branch stack")
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Reviewed-by: Kan Liang <kan.liang@linux.intel.com>
Link: https://lore.kernel.org/r/20220927203259.590950-1-jolsa@kernel.org
---
 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 68e5cdd..1fcd123 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;
 

^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2022-09-28  6:57 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-27 20:32 [PATCH -tip] bpf: Check flags for branch stack in bpf_read_branch_records helper Jiri Olsa
2022-09-27 20:41 ` Liang, Kan
2022-09-27 20:46 ` Peter Zijlstra
2022-09-27 21:24   ` Jiri Olsa
2022-09-27 21:49 ` Song Liu
2022-09-27 21:50   ` Song Liu
2022-09-28  6:57 ` [tip: perf/core] " tip-bot2 for Jiri Olsa

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.