lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAEf4BzbP0hAJYr-dahNZqKe9wyYL6hD9FayS-qdQV+Lmyi_VTQ@mail.gmail.com>
Date:   Fri, 19 Nov 2021 14:45:43 -0800
From:   Andrii Nakryiko <andrii.nakryiko@...il.com>
To:     Daniel Borkmann <daniel@...earbox.net>
Cc:     kajoljain <kjain@...ux.ibm.com>, bpf <bpf@...r.kernel.org>,
        open list <linux-kernel@...r.kernel.org>,
        Arnaldo Carvalho de Melo <acme@...nel.org>,
        Peter Ziljstra <peterz@...radead.org>,
        Song Liu <songliubraving@...com>,
        Andrii Nakryiko <andrii@...nel.org>, Martin Lau <kafai@...com>,
        Yonghong Song <yhs@...com>,
        john fastabend <john.fastabend@...il.com>,
        "David S. Miller" <davem@...emloft.net>,
        KP Singh <kpsingh@...nel.org>,
        Jesper Dangaard Brouer <hawk@...nel.org>,
        Jakub Kicinski <kuba@...nel.org>, maddy@...ux.ibm.com,
        atrajeev@...ux.vnet.ibm.com,
        "linux-perf-use." <linux-perf-users@...r.kernel.org>,
        rnsastry@...ux.ibm.com
Subject: Re: [PATCH v2] bpf: Remove config check to enable bpf support for
 branch records

On Fri, Nov 19, 2021 at 8:08 AM Daniel Borkmann <daniel@...earbox.net> wrote:
>
> 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@...ux.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@...radead.org>
> >>> Signed-off-by: Kajol Jain <kjain@...ux.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).

Yep, I think so too.

>
> > ....
> > }
> >
> > Thanks,
> > Kajol Jain

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ