linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] bpf: Enable bpf support for reading branch records in powerpc
@ 2021-11-15  4:44 Kajol Jain
  2021-11-15 23:30 ` Daniel Borkmann
  0 siblings, 1 reply; 4+ messages in thread
From: Kajol Jain @ 2021-11-15  4:44 UTC (permalink / raw)
  To: bpf, linux-kernel
  Cc: acme, peterz, songliubraving, daniel, andrii, kafai, yhs,
	john.fastabend, davem, kpsingh, hawk, kuba, maddy, atrajeev,
	linux-perf-users, rnsastry, kjain

Branch data available to bpf programs can be very useful to get
stack traces out of userspace applications.

Commit fff7b64355ea ("bpf: Add bpf_read_branch_records() helper")
added bpf support to capture branch records in x86. Enable this feature
for powerpc as well.

Commit 67306f84ca78 ("selftests/bpf: Add bpf_read_branch_records()
selftest") adds selftest corresponding to bpf branch read
function bpf_read_branch_records(). Used this selftest to
test bpf support, for reading branch records in powerpc.

Selftest result in power9 box before this patch changes:

[command]# ./test_progs -t perf_branches
Failed to load bpf_testmod.ko into the kernel: -8
WARNING! Selftests relying on bpf_testmod.ko will be skipped.
test_perf_branches_common:PASS:test_perf_branches_load 0 nsec
test_perf_branches_common:PASS:attach_perf_event 0 nsec
test_perf_branches_common:PASS:set_affinity 0 nsec
check_good_sample:PASS:output not valid 0 nsec
check_good_sample:FAIL:read_branches_size err -2
check_good_sample:FAIL:read_branches_stack err -2
check_good_sample:FAIL:read_branches_stack stack bytes written=-2
not multiple of struct size=24
check_good_sample:FAIL:read_branches_global err -2
check_good_sample:FAIL:read_branches_global global bytes written=-2
not multiple of struct size=24
check_good_sample:PASS:read_branches_size 0 nsec
 #75/1 perf_branches_hw:FAIL
 #75/2 perf_branches_no_hw:OK
 #75 perf_branches:FAIL
Summary: 0/1 PASSED, 0 SKIPPED, 2 FAILED

Selftest result in power9 box after this patch changes:

[command]#: ./test_progs -t perf_branches
 #75/1 perf_branches_hw:OK
 #75/2 perf_branches_no_hw:OK
 #75 perf_branches:OK
Summary: 1/2 PASSED, 0 SKIPPED, 0 FAILED

Signed-off-by: Kajol Jain<kjain@linux.ibm.com>
---
 kernel/trace/bpf_trace.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/kernel/trace/bpf_trace.c b/kernel/trace/bpf_trace.c
index fdd14072fc3b..2b7343b64bb7 100644
--- a/kernel/trace/bpf_trace.c
+++ b/kernel/trace/bpf_trace.c
@@ -1245,7 +1245,7 @@ static const struct bpf_func_proto bpf_perf_prog_read_value_proto = {
 BPF_CALL_4(bpf_read_branch_records, struct bpf_perf_event_data_kern *, ctx,
 	   void *, buf, u32, size, u64, flags)
 {
-#ifndef CONFIG_X86
+#if !(defined(CONFIG_X86) || defined(CONFIG_PPC64))
 	return -ENOENT;
 #else
 	static const u32 br_entry_size = sizeof(struct perf_branch_entry);
-- 
2.27.0


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

* Re: [PATCH] bpf: Enable bpf support for reading branch records in powerpc
  2021-11-15  4:44 [PATCH] bpf: Enable bpf support for reading branch records in powerpc Kajol Jain
@ 2021-11-15 23:30 ` Daniel Borkmann
  2021-11-16  8:34   ` Peter Zijlstra
  0 siblings, 1 reply; 4+ messages in thread
From: Daniel Borkmann @ 2021-11-15 23:30 UTC (permalink / raw)
  To: Kajol Jain, bpf, linux-kernel
  Cc: acme, peterz, songliubraving, andrii, kafai, yhs, john.fastabend,
	davem, kpsingh, hawk, kuba, maddy, atrajeev, linux-perf-users,
	rnsastry

On 11/15/21 5:44 AM, Kajol Jain wrote:
> Branch data available to bpf programs can be very useful to get
> stack traces out of userspace applications.
> 
> Commit fff7b64355ea ("bpf: Add bpf_read_branch_records() helper")
> added bpf support to capture branch records in x86. Enable this feature
> for powerpc as well.
> 
> Commit 67306f84ca78 ("selftests/bpf: Add bpf_read_branch_records()
> selftest") adds selftest corresponding to bpf branch read
> function bpf_read_branch_records(). Used this selftest to
> test bpf support, for reading branch records in powerpc.
> 
> Selftest result in power9 box before this patch changes:
> 
> [command]# ./test_progs -t perf_branches
> Failed to load bpf_testmod.ko into the kernel: -8
> WARNING! Selftests relying on bpf_testmod.ko will be skipped.
> test_perf_branches_common:PASS:test_perf_branches_load 0 nsec
> test_perf_branches_common:PASS:attach_perf_event 0 nsec
> test_perf_branches_common:PASS:set_affinity 0 nsec
> check_good_sample:PASS:output not valid 0 nsec
> check_good_sample:FAIL:read_branches_size err -2
> check_good_sample:FAIL:read_branches_stack err -2
> check_good_sample:FAIL:read_branches_stack stack bytes written=-2
> not multiple of struct size=24
> check_good_sample:FAIL:read_branches_global err -2
> check_good_sample:FAIL:read_branches_global global bytes written=-2
> not multiple of struct size=24
> check_good_sample:PASS:read_branches_size 0 nsec
>   #75/1 perf_branches_hw:FAIL
>   #75/2 perf_branches_no_hw:OK
>   #75 perf_branches:FAIL
> Summary: 0/1 PASSED, 0 SKIPPED, 2 FAILED
> 
> Selftest result in power9 box after this patch changes:
> 
> [command]#: ./test_progs -t perf_branches
>   #75/1 perf_branches_hw:OK
>   #75/2 perf_branches_no_hw:OK
>   #75 perf_branches:OK
> Summary: 1/2 PASSED, 0 SKIPPED, 0 FAILED
> 
> Signed-off-by: Kajol Jain<kjain@linux.ibm.com>
> ---
>   kernel/trace/bpf_trace.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/kernel/trace/bpf_trace.c b/kernel/trace/bpf_trace.c
> index fdd14072fc3b..2b7343b64bb7 100644
> --- a/kernel/trace/bpf_trace.c
> +++ b/kernel/trace/bpf_trace.c
> @@ -1245,7 +1245,7 @@ static const struct bpf_func_proto bpf_perf_prog_read_value_proto = {
>   BPF_CALL_4(bpf_read_branch_records, struct bpf_perf_event_data_kern *, ctx,
>   	   void *, buf, u32, size, u64, flags)
>   {
> -#ifndef CONFIG_X86
> +#if !(defined(CONFIG_X86) || defined(CONFIG_PPC64))

Can this really be enabled generically? Looking at 3925f46bb590 ("powerpc/perf: Enable
branch stack sampling framework") it says POWER8 [and beyond]. Should there be a generic
Kconfig symbol like ARCH_HAS_BRANCH_RECORDS that can be selected by archs instead?

>   	return -ENOENT;
>   #else
>   	static const u32 br_entry_size = sizeof(struct perf_branch_entry);
> 


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

* Re: [PATCH] bpf: Enable bpf support for reading branch records in powerpc
  2021-11-15 23:30 ` Daniel Borkmann
@ 2021-11-16  8:34   ` Peter Zijlstra
  2021-11-16 15:21     ` kajoljain
  0 siblings, 1 reply; 4+ messages in thread
From: Peter Zijlstra @ 2021-11-16  8:34 UTC (permalink / raw)
  To: Daniel Borkmann
  Cc: Kajol Jain, bpf, linux-kernel, acme, songliubraving, andrii,
	kafai, yhs, john.fastabend, davem, kpsingh, hawk, kuba, maddy,
	atrajeev, linux-perf-users, rnsastry

On Tue, Nov 16, 2021 at 12:30:07AM +0100, Daniel Borkmann wrote:

> > diff --git a/kernel/trace/bpf_trace.c b/kernel/trace/bpf_trace.c
> > index fdd14072fc3b..2b7343b64bb7 100644
> > --- a/kernel/trace/bpf_trace.c
> > +++ b/kernel/trace/bpf_trace.c
> > @@ -1245,7 +1245,7 @@ static const struct bpf_func_proto bpf_perf_prog_read_value_proto = {
> >   BPF_CALL_4(bpf_read_branch_records, struct bpf_perf_event_data_kern *, ctx,
> >   	   void *, buf, u32, size, u64, flags)
> >   {
> > -#ifndef CONFIG_X86
> > +#if !(defined(CONFIG_X86) || defined(CONFIG_PPC64))
> 
> Can this really be enabled generically? Looking at 3925f46bb590 ("powerpc/perf: Enable
> branch stack sampling framework") it says POWER8 [and beyond]. Should there be a generic
> Kconfig symbol like ARCH_HAS_BRANCH_RECORDS that can be selected by archs instead?

I conplained about it before as well. I'd just take it out entirely.

If perf_snapshot_branch_stack isn't implemnted it'll return 0 and then
we'll -Esomething anyway.



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

* Re: [PATCH] bpf: Enable bpf support for reading branch records in powerpc
  2021-11-16  8:34   ` Peter Zijlstra
@ 2021-11-16 15:21     ` kajoljain
  0 siblings, 0 replies; 4+ messages in thread
From: kajoljain @ 2021-11-16 15:21 UTC (permalink / raw)
  To: Peter Zijlstra, Daniel Borkmann
  Cc: bpf, linux-kernel, acme, songliubraving, andrii, kafai, yhs,
	john.fastabend, davem, kpsingh, hawk, kuba, maddy, atrajeev,
	linux-perf-users, rnsastry



On 11/16/21 2:04 PM, Peter Zijlstra wrote:
> On Tue, Nov 16, 2021 at 12:30:07AM +0100, Daniel Borkmann wrote:
> 
>>> diff --git a/kernel/trace/bpf_trace.c b/kernel/trace/bpf_trace.c
>>> index fdd14072fc3b..2b7343b64bb7 100644
>>> --- a/kernel/trace/bpf_trace.c
>>> +++ b/kernel/trace/bpf_trace.c
>>> @@ -1245,7 +1245,7 @@ static const struct bpf_func_proto bpf_perf_prog_read_value_proto = {
>>>   BPF_CALL_4(bpf_read_branch_records, struct bpf_perf_event_data_kern *, ctx,
>>>   	   void *, buf, u32, size, u64, flags)
>>>   {
>>> -#ifndef CONFIG_X86
>>> +#if !(defined(CONFIG_X86) || defined(CONFIG_PPC64))
>>
>> Can this really be enabled generically? Looking at 3925f46bb590 ("powerpc/perf: Enable
>> branch stack sampling framework") it says POWER8 [and beyond]. Should there be a generic
>> Kconfig symbol like ARCH_HAS_BRANCH_RECORDS that can be selected by archs instead?
> 

Hi Peterz/Daniel,
    Thanks for reviewing the patch

> I conplained about it before as well. I'd just take it out entirely.

I agree, it make more sense to entirely remove this arch check from
here. Because anyway, incase any arch doesn't support this
functionality, bpf_read_branch_records will return -EINVAL.

> 
> If perf_snapshot_branch_stack isn't implemnted it'll return 0 and then
> we'll -Esomething anyway.

In this patch, we are basically adding powerpc support to capture
branch records via bpf_read_branch_records function. We are still
looking into adding support for perf_snapshot_branch_stack for powerpc.

 I will send a follow up to remove arch check in bpf_read_branch_records
function.

Thanks,
Kajol Jain
> 
> 

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

end of thread, other threads:[~2021-11-16 15:22 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-15  4:44 [PATCH] bpf: Enable bpf support for reading branch records in powerpc Kajol Jain
2021-11-15 23:30 ` Daniel Borkmann
2021-11-16  8:34   ` Peter Zijlstra
2021-11-16 15:21     ` kajoljain

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).