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: <CAEf4BzZrEcZFNSH=YDi_NmT2oqaOhmgQvPv0THXKy4haEzBFvQ@mail.gmail.com>
Date:   Tue, 31 Aug 2021 21:08:47 -0700
From:   Andrii Nakryiko <andrii.nakryiko@...il.com>
To:     Song Liu <songliubraving@...com>
Cc:     bpf <bpf@...r.kernel.org>,
        open list <linux-kernel@...r.kernel.org>,
        Arnaldo Carvalho de Melo <acme@...nel.org>,
        Peter Ziljstra <peterz@...radead.org>,
        Ingo Molnar <mingo@...hat.com>,
        Kajol Jain <kjain@...ux.ibm.com>,
        Kernel Team <kernel-team@...com>
Subject: Re: [PATCH v4 bpf-next 3/3] selftests/bpf: add test for bpf_get_branch_snapshot

On Tue, Aug 31, 2021 at 7:01 PM Song Liu <songliubraving@...com> wrote:
>
> This test uses bpf_get_branch_snapshot from a fexit program. The test uses
> a target function (bpf_testmod_loop_test) and compares the record against
> kallsyms. If there isn't enough record matching kallsyms, the test fails.
>
> Signed-off-by: Song Liu <songliubraving@...com>
> ---

LGTM, few minor nits below

Acked-by: Andrii Nakryiko <andrii@...nel.org>

>  .../selftests/bpf/bpf_testmod/bpf_testmod.c   |  14 ++-
>  .../bpf/prog_tests/get_branch_snapshot.c      | 101 ++++++++++++++++++
>  .../selftests/bpf/progs/get_branch_snapshot.c |  44 ++++++++
>  tools/testing/selftests/bpf/trace_helpers.c   |  37 +++++++
>  tools/testing/selftests/bpf/trace_helpers.h   |   5 +
>  5 files changed, 200 insertions(+), 1 deletion(-)
>  create mode 100644 tools/testing/selftests/bpf/prog_tests/get_branch_snapshot.c
>  create mode 100644 tools/testing/selftests/bpf/progs/get_branch_snapshot.c
>

[...]

> +
> +void test_get_branch_snapshot(void)
> +{
> +       struct get_branch_snapshot *skel = NULL;
> +       int err;
> +
> +       if (create_perf_events()) {
> +               test__skip();  /* system doesn't support LBR */
> +               goto cleanup;
> +       }
> +
> +       skel = get_branch_snapshot__open_and_load();
> +       if (!ASSERT_OK_PTR(skel, "get_branch_snapshot__open_and_load"))
> +               goto cleanup;
> +
> +       err = kallsyms_find("bpf_testmod_loop_test", &skel->bss->address_low);
> +       if (!ASSERT_OK(err, "kallsyms_find"))
> +               goto cleanup;
> +
> +       err = kallsyms_find_next("bpf_testmod_loop_test", &skel->bss->address_high);
> +       if (!ASSERT_OK(err, "kallsyms_find_next"))
> +               goto cleanup;
> +
> +       err = get_branch_snapshot__attach(skel);
> +       if (!ASSERT_OK(err, "get_branch_snapshot__attach"))
> +               goto cleanup;
> +
> +       /* trigger the program */
> +       system("cat /sys/kernel/bpf_testmod > /dev/null 2>& 1");

ugh :( see prog_tests/module_attach.c, we can extract and reuse
trigger_module_test_read() and trigger_module_test_write()

> +
> +       if (skel->bss->total_entries < 16) {
> +               /* too few entries for the hit/waste test */
> +               test__skip();
> +               goto cleanup;
> +       }
> +

[...]

> +SEC("fexit/bpf_testmod_loop_test")
> +int BPF_PROG(test1, int n, int ret)
> +{
> +       long i;
> +
> +       total_entries = bpf_get_branch_snapshot(entries, sizeof(entries), 0);
> +       total_entries /= sizeof(struct perf_branch_entry);
> +
> +       bpf_printk("total_entries %lu\n", total_entries);
> +
> +       for (i = 0; i < PERF_MAX_BRANCH_SNAPSHOT; i++) {
> +               if (i >= total_entries)
> +                       break;
> +               if (in_range(entries[i].from) && in_range(entries[i].to))
> +                       test1_hits++;
> +               else if (!test1_hits)
> +                       wasted_entries++;
> +               bpf_printk("i %d from %llx to %llx", i, entries[i].from,
> +                          entries[i].to);

debug leftovers? this will be polluting trace_pipe unnecessarily; same
for above total_entries bpf_printk()

> +       }
> +       return 0;
> +}
> diff --git a/tools/testing/selftests/bpf/trace_helpers.c b/tools/testing/selftests/bpf/trace_helpers.c
> index e7a19b04d4eaf..5100a169b72b1 100644
> --- a/tools/testing/selftests/bpf/trace_helpers.c
> +++ b/tools/testing/selftests/bpf/trace_helpers.c
> @@ -1,4 +1,5 @@
>  // SPDX-License-Identifier: GPL-2.0
> +#include <ctype.h>
>  #include <stdio.h>
>  #include <stdlib.h>
>  #include <string.h>
> @@ -117,6 +118,42 @@ int kallsyms_find(const char *sym, unsigned long long *addr)
>         return err;
>  }
>

[...]

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ