Skip to content

Commit 33fcd00

Browse files
kjain101gregkh
authored andcommitted
bpf: Remove config check to enable bpf support for branch records
[ Upstream commit db52f57 ] Branch data available to BPF programs can be very useful to get stack traces out of userspace application. Commit fff7b64 ("bpf: Add bpf_read_branch_records() helper") added BPF support to capture branch records in x86. Enable this feature also for other architectures as well by removing checks specific to x86. If an architecture doesn't support branch records, bpf_read_branch_records() still has appropriate checks and it will return an -EINVAL in that scenario. Based on UAPI helper doc in include/uapi/linux/bpf.h, unsupported architectures should return -ENOENT in such case. Hence, update the appropriate check to return -ENOENT instead. Selftest 'perf_branches' result on power9 machine which has the branch stacks support: - Before this patch: [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: [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: [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: fff7b64 ("bpf: Add bpf_read_branch_records() helper") Suggested-by: Peter Zijlstra <[email protected]> Signed-off-by: Kajol Jain <[email protected]> Signed-off-by: Daniel Borkmann <[email protected]> Link: https://lore.kernel.org/bpf/[email protected] Signed-off-by: Sasha Levin <[email protected]>
1 parent 832d478 commit 33fcd00

File tree

1 file changed

+1
-5
lines changed

1 file changed

+1
-5
lines changed

kernel/trace/bpf_trace.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1322,9 +1322,6 @@ static const struct bpf_func_proto bpf_perf_prog_read_value_proto = {
13221322
BPF_CALL_4(bpf_read_branch_records, struct bpf_perf_event_data_kern *, ctx,
13231323
void *, buf, u32, size, u64, flags)
13241324
{
1325-
#ifndef CONFIG_X86
1326-
return -ENOENT;
1327-
#else
13281325
static const u32 br_entry_size = sizeof(struct perf_branch_entry);
13291326
struct perf_branch_stack *br_stack = ctx->data->br_stack;
13301327
u32 to_copy;
@@ -1333,7 +1330,7 @@ BPF_CALL_4(bpf_read_branch_records, struct bpf_perf_event_data_kern *, ctx,
13331330
return -EINVAL;
13341331

13351332
if (unlikely(!br_stack))
1336-
return -EINVAL;
1333+
return -ENOENT;
13371334

13381335
if (flags & BPF_F_GET_BRANCH_RECORDS_SIZE)
13391336
return br_stack->nr * br_entry_size;
@@ -1345,7 +1342,6 @@ BPF_CALL_4(bpf_read_branch_records, struct bpf_perf_event_data_kern *, ctx,
13451342
memcpy(buf, br_stack->entries, to_copy);
13461343

13471344
return to_copy;
1348-
#endif
13491345
}
13501346

13511347
static const struct bpf_func_proto bpf_read_branch_records_proto = {

0 commit comments

Comments
 (0)