From: Daniel Borkmann <daniel@iogearbox.net>
To: kajoljain <kjain@linux.ibm.com>,
Andrii Nakryiko <andrii.nakryiko@gmail.com>
Cc: bpf <bpf@vger.kernel.org>,
open list <linux-kernel@vger.kernel.org>,
Arnaldo Carvalho de Melo <acme@kernel.org>,
Peter Ziljstra <peterz@infradead.org>,
Song Liu <songliubraving@fb.com>,
Andrii Nakryiko <andrii@kernel.org>, Martin Lau <kafai@fb.com>,
Yonghong Song <yhs@fb.com>,
john fastabend <john.fastabend@gmail.com>,
"David S. Miller" <davem@davemloft.net>,
KP Singh <kpsingh@kernel.org>,
Jesper Dangaard Brouer <hawk@kernel.org>,
Jakub Kicinski <kuba@kernel.org>,
maddy@linux.ibm.com, atrajeev@linux.vnet.ibm.com,
"linux-perf-use." <linux-perf-users@vger.kernel.org>,
rnsastry@linux.ibm.com
Subject: Re: [PATCH v2] bpf: Remove config check to enable bpf support for branch records
Date: Fri, 19 Nov 2021 17:08:46 +0100 [thread overview]
Message-ID: <859f8b57-7ae2-3c68-5642-93bec7a59a20@iogearbox.net> (raw)
In-Reply-To: <ce150f51-ef50-de85-fc52-0f2ee3a3000f@linux.ibm.com>
On 11/19/21 10:35 AM, kajoljain wrote:
> On 11/19/21 4:18 AM, Andrii Nakryiko wrote:
>> On Thu, Nov 18, 2021 at 5:10 AM Kajol Jain <kjain@linux.ibm.com> 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.
>>> Incase any platform didn't support branch stack, it will return with
>>> -EINVAL.
>>>
>>> Selftest 'perf_branches' result on power9 machine with 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
>>> support branch stack
>>>
>>> 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:
>>> 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
>>
>> what will be returned for architectures that don't support branch
>> records? Will it be zero instead of -ENOENT?
>
> Hi Andrii,
> Incase any architecture doesn't support branch records and if it
> tries to do branch sampling with sample type as
> PERF_SAMPLE_BRANCH_STACK, perf_event_open itself will fail.
>
> And even if, perf_event_open succeeds we have appropriate checks in
> bpf_read_branch_records function, which will return -EINVAL for those
> architectures.
>
> Reference from linux/kernel/trace/bpf_trace.c
>
> Here, br_stack will be empty, for unsupported architectures.
>
> BPF_CALL_4(bpf_read_branch_records, struct bpf_perf_event_data_kern *, ctx,
> void *, buf, u32, size, u64, flags)
> {
> .....
> if (unlikely(flags & ~BPF_F_GET_BRANCH_RECORDS_SIZE))
> return -EINVAL;
>
> if (unlikely(!br_stack))
> return -EINVAL;
In that case for unsupported archs we should probably bail out with -ENOENT here
as helper doc says '**-ENOENT** if architecture does not support branch records'
(see bpf_read_branch_records() doc in include/uapi/linux/bpf.h).
> ....
> }
>
> Thanks,
> Kajol Jain
next prev parent reply other threads:[~2021-11-19 16:08 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-11-18 13:05 [PATCH v2] bpf: Remove config check to enable bpf support for branch records Kajol Jain
2021-11-18 22:48 ` Andrii Nakryiko
2021-11-19 9:35 ` kajoljain
2021-11-19 16:08 ` Daniel Borkmann [this message]
2021-11-19 22:45 ` Andrii Nakryiko
2021-11-23 7:44 ` kajoljain
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=859f8b57-7ae2-3c68-5642-93bec7a59a20@iogearbox.net \
--to=daniel@iogearbox.net \
--cc=acme@kernel.org \
--cc=andrii.nakryiko@gmail.com \
--cc=andrii@kernel.org \
--cc=atrajeev@linux.vnet.ibm.com \
--cc=bpf@vger.kernel.org \
--cc=davem@davemloft.net \
--cc=hawk@kernel.org \
--cc=john.fastabend@gmail.com \
--cc=kafai@fb.com \
--cc=kjain@linux.ibm.com \
--cc=kpsingh@kernel.org \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-perf-users@vger.kernel.org \
--cc=maddy@linux.ibm.com \
--cc=peterz@infradead.org \
--cc=rnsastry@linux.ibm.com \
--cc=songliubraving@fb.com \
--cc=yhs@fb.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).