linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v4] bpf: Remove config check to enable bpf support for branch records
@ 2021-12-06  7:33 Kajol Jain
  2021-12-06 14:30 ` patchwork-bot+netdevbpf
  0 siblings, 1 reply; 2+ messages in thread
From: Kajol Jain @ 2021-12-06  7:33 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, andrii.nakryiko

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

Commit fff7b64355ea ("bpf: Add bpf_read_branch_records() helper")
added bpf support to capture branch records in x86. Enable this feature
for other architectures as well by removing check specific to x86.

Incase any architecture doesn't support branch records,
bpf_read_branch_records still have appropriate checks and it
will return error number -EINVAL in that scenario. But based on
documentation there in include/uapi/linux/bpf.h file, incase of
unsupported archs, this function should return -ENOENT. Hence update
the appropriate checks to return -ENOENT instead.

Selftest 'perf_branches' result on power9 machine which has branch stacks
support.

Before this patch changes:
[command]# ./test_progs -t perf_branches
 #88/1 perf_branches/perf_branches_hw:FAIL
 #88/2 perf_branches/perf_branches_no_hw:OK
 #88 perf_branches:FAIL
Summary: 0/1 PASSED, 0 SKIPPED, 1 FAILED

After this patch changes:
[command]# ./test_progs -t perf_branches
 #88/1 perf_branches/perf_branches_hw:OK
 #88/2 perf_branches/perf_branches_no_hw:OK
 #88 perf_branches:OK
Summary: 1/2 PASSED, 0 SKIPPED, 0 FAILED

Selftest 'perf_branches' result on power9 machine which doesn't
have branch stack report.

After this patch changes:
[command]# ./test_progs -t perf_branches
 #88/1 perf_branches/perf_branches_hw:SKIP
 #88/2 perf_branches/perf_branches_no_hw:OK
 #88 perf_branches:OK
Summary: 1/1 PASSED, 1 SKIPPED, 0 FAILED

Fixes: fff7b64355eac ("bpf: Add bpf_read_branch_records() helper")
Suggested-by: Peter Zijlstra <peterz@infradead.org>
Signed-off-by: Kajol Jain <kjain@linux.ibm.com>
---


Tested this patch changes on power9 machine using selftest
'perf branches' which is added in commit 67306f84ca78 ("selftests/bpf:
Add bpf_read_branch_records()")

Changelog:
v3 -> v4
- Make return type again as -EINVAL for invalid/unsupported
  flags case as suggested by Daniel Borkmann.

- Link to the v3 patch: https://lkml.org/lkml/2021/11/23/248

v2 -> v3
- Change the return error number for bpf_read_branch_records
  function from -EINVAL to -ENOENT for appropriate checks
  as suggested by Daniel Borkmann.

- Link to the v2 patch: https://lkml.org/lkml/2021/11/18/510

v1 -> v2
- Inorder to add bpf support to capture branch record in
  powerpc, rather then adding config for powerpc, entirely
  remove config check from bpf_read_branch_records function
  as suggested by Peter Zijlstra

- Link to the v1 patch: https://lkml.org/lkml/2021/11/14/434

 kernel/trace/bpf_trace.c | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)

diff --git a/kernel/trace/bpf_trace.c b/kernel/trace/bpf_trace.c
index ae9755037b7e..e36d184615fb 100644
--- a/kernel/trace/bpf_trace.c
+++ b/kernel/trace/bpf_trace.c
@@ -1400,9 +1400,6 @@ 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
-	return -ENOENT;
-#else
 	static const u32 br_entry_size = sizeof(struct perf_branch_entry);
 	struct perf_branch_stack *br_stack = ctx->data->br_stack;
 	u32 to_copy;
@@ -1411,7 +1408,7 @@ BPF_CALL_4(bpf_read_branch_records, struct bpf_perf_event_data_kern *, ctx,
 		return -EINVAL;
 
 	if (unlikely(!br_stack))
-		return -EINVAL;
+		return -ENOENT;
 
 	if (flags & BPF_F_GET_BRANCH_RECORDS_SIZE)
 		return br_stack->nr * br_entry_size;
@@ -1423,7 +1420,6 @@ BPF_CALL_4(bpf_read_branch_records, struct bpf_perf_event_data_kern *, ctx,
 	memcpy(buf, br_stack->entries, to_copy);
 
 	return to_copy;
-#endif
 }
 
 static const struct bpf_func_proto bpf_read_branch_records_proto = {
-- 
2.27.0


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

* Re: [PATCH v4] bpf: Remove config check to enable bpf support for branch records
  2021-12-06  7:33 [PATCH v4] bpf: Remove config check to enable bpf support for branch records Kajol Jain
@ 2021-12-06 14:30 ` patchwork-bot+netdevbpf
  0 siblings, 0 replies; 2+ messages in thread
From: patchwork-bot+netdevbpf @ 2021-12-06 14:30 UTC (permalink / raw)
  To: Kajol Jain
  Cc: bpf, linux-kernel, acme, peterz, songliubraving, daniel, andrii,
	kafai, yhs, john.fastabend, davem, kpsingh, hawk, kuba, maddy,
	atrajeev, linux-perf-users, rnsastry, andrii.nakryiko

Hello:

This patch was applied to bpf/bpf-next.git (master)
by Daniel Borkmann <daniel@iogearbox.net>:

On Mon,  6 Dec 2021 13:03:15 +0530 you wrote:
> Branch data available to bpf programs can be very useful to get
> stack traces out of userspace application.
> 
> Commit fff7b64355ea ("bpf: Add bpf_read_branch_records() helper")
> added bpf support to capture branch records in x86. Enable this feature
> for other architectures as well by removing check specific to x86.
> 
> [...]

Here is the summary with links:
  - [v4] bpf: Remove config check to enable bpf support for branch records
    https://git.kernel.org/bpf/bpf-next/c/db52f57211b4

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



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

end of thread, other threads:[~2021-12-06 14:30 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-12-06  7:33 [PATCH v4] bpf: Remove config check to enable bpf support for branch records Kajol Jain
2021-12-06 14:30 ` patchwork-bot+netdevbpf

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