History

bpf: Remove config check to enable bpf support for branch records

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

Kajol Jain committed 4 years ago

Commit db52f571 parent 942df4d1 file · +1 −5Browse files

Unified · Split

kernel/trace/bpf_trace.c+1−5
@@ -1404,9 +1404,6 @@ static const struct bpf_func_proto bpf_perf_prog_read_value_proto = { · 1403 unmodified lines
1404BPF_CALL_4(bpf_read_branch_records, struct bpf_perf_event_data_kern *, ctx,1404BPF_CALL_4(bpf_read_branch_records, struct bpf_perf_event_data_kern *, ctx,
1405 void *, buf, u32, size, u64, flags)1405 void *, buf, u32, size, u64, flags)
1406{1406{
1407#ifndef CONFIG_X86
1408 return -ENOENT;
1409#else
1410 static const u32 br_entry_size = sizeof(struct perf_branch_entry);1407 static const u32 br_entry_size = sizeof(struct perf_branch_entry);
1411 struct perf_branch_stack *br_stack = ctx->data->br_stack;1408 struct perf_branch_stack *br_stack = ctx->data->br_stack;
1412 u32 to_copy;1409 u32 to_copy;
@@ -1415,7 +1412,7 @@ BPF_CALL_4(bpf_read_branch_records, struct bpf_perf_event_data_kern *, ctx, · 2 unmodified lines
1415 return -EINVAL;1412 return -EINVAL;
1416 1413
1417 if (unlikely(!br_stack))1414 if (unlikely(!br_stack))
1418 return -EINVAL;1415 return -ENOENT;
1419 1416
1420 if (flags & BPF_F_GET_BRANCH_RECORDS_SIZE)1417 if (flags & BPF_F_GET_BRANCH_RECORDS_SIZE)
1421 return br_stack->nr * br_entry_size;1418 return br_stack->nr * br_entry_size;
@@ -1427,7 +1424,6 @@ BPF_CALL_4(bpf_read_branch_records, struct bpf_perf_event_data_kern *, ctx, · 5 unmodified lines
1427 memcpy(buf, br_stack->entries, to_copy);1424 memcpy(buf, br_stack->entries, to_copy);
1428 1425
1429 return to_copy;1426 return to_copy;
1430#endif
1431}1427}
1432 1428
1433static const struct bpf_func_proto bpf_read_branch_records_proto = {1429static const struct bpf_func_proto bpf_read_branch_records_proto = {