netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Andrii Nakryiko <andrii.nakryiko@gmail.com>
To: "Mauricio Vásquez" <mauricio@kinvolk.io>
Cc: Networking <netdev@vger.kernel.org>, bpf <bpf@vger.kernel.org>,
	Alexei Starovoitov <ast@kernel.org>,
	Daniel Borkmann <daniel@iogearbox.net>,
	Andrii Nakryiko <andrii@kernel.org>,
	Quentin Monnet <quentin@isovalent.com>
Subject: Re: [PATCH bpf-next] libbpf: Fix strict mode calculation
Date: Fri, 4 Feb 2022 14:55:16 -0800	[thread overview]
Message-ID: <CAEf4Bza+vB-rJD9NNphsU8UbiD06JH9wLzDvX5ZCKnLALSPNpw@mail.gmail.com> (raw)
In-Reply-To: <20220204220435.301896-1-mauricio@kinvolk.io>

On Fri, Feb 4, 2022 at 2:05 PM Mauricio Vásquez <mauricio@kinvolk.io> wrote:
>
> The correct formula to get all possible values is
> ((__LIBBPF_STRICT_LAST - 1) * 2 - 1) as stated in
> libbpf_set_strict_mode().
>
> Fixes: 93b8952d223a ("libbpf: deprecate legacy BPF map definitions")
>
> Signed-off-by: Mauricio Vásquez <mauricio@kinvolk.io>
> ---
>  tools/bpf/bpftool/main.c                     |  6 +++++-
>  tools/testing/selftests/bpf/prog_tests/btf.c | 10 ++++++++--

please split changes to bpftool and separately selftests/bpf (and in
v2 you'll have a separate libbpf patch as well).

>  2 files changed, 13 insertions(+), 3 deletions(-)
>
> diff --git a/tools/bpf/bpftool/main.c b/tools/bpf/bpftool/main.c
> index 9d01fa9de033..c5b27e41d1e9 100644
> --- a/tools/bpf/bpftool/main.c
> +++ b/tools/bpf/bpftool/main.c
> @@ -483,8 +483,12 @@ int main(int argc, char **argv)
>                 /* Allow legacy map definitions for skeleton generation.
>                  * It will still be rejected if users use LIBBPF_STRICT_ALL
>                  * mode for loading generated skeleton.
> +                *
> +                * __LIBBPF_STRICT_LAST is the last power-of-2 value used + 1, so to
> +                * get all possible values we compensate last +1, and then (2*x - 1)
> +                * to get the bit mask
>                  */
> -               mode = (__LIBBPF_STRICT_LAST - 1) & ~LIBBPF_STRICT_MAP_DEFINITIONS;
> +               mode = ((__LIBBPF_STRICT_LAST - 1) * 2 - 1) & ~LIBBPF_STRICT_MAP_DEFINITIONS;
>                 ret = libbpf_set_strict_mode(mode);
>                 if (ret)
>                         p_err("failed to enable libbpf strict mode: %d", ret);
> diff --git a/tools/testing/selftests/bpf/prog_tests/btf.c b/tools/testing/selftests/bpf/prog_tests/btf.c
> index 14f9b6136794..90d5cd4f504c 100644
> --- a/tools/testing/selftests/bpf/prog_tests/btf.c
> +++ b/tools/testing/selftests/bpf/prog_tests/btf.c
> @@ -4533,6 +4533,7 @@ static void do_test_file(unsigned int test_num)
>         struct btf_ext *btf_ext = NULL;
>         struct bpf_prog_info info = {};
>         struct bpf_object *obj = NULL;
> +       enum libbpf_strict_mode mode;
>         struct bpf_func_info *finfo;
>         struct bpf_program *prog;
>         __u32 info_len, rec_size;
> @@ -4560,8 +4561,13 @@ static void do_test_file(unsigned int test_num)
>         has_btf_ext = btf_ext != NULL;
>         btf_ext__free(btf_ext);
>
> -       /* temporary disable LIBBPF_STRICT_MAP_DEFINITIONS to test legacy maps */
> -       libbpf_set_strict_mode((__LIBBPF_STRICT_LAST - 1) & ~LIBBPF_STRICT_MAP_DEFINITIONS);
> +       /* temporary disable LIBBPF_STRICT_MAP_DEFINITIONS to test legacy maps
> +        * __LIBBPF_STRICT_LAST is the last power-of-2 value used + 1, so to
> +        * get all possible values we compensate last +1, and then (2*x - 1)
> +        * to get the bit mask
> +        */
> +       mode = ((__LIBBPF_STRICT_LAST - 1) * 2 - 1) & ~LIBBPF_STRICT_MAP_DEFINITIONS
> +       libbpf_set_strict_mode(mode);
>         obj = bpf_object__open(test->file);
>         err = libbpf_get_error(obj);
>         if (CHECK(err, "obj: %d", err))
> --
> 2.25.1
>

      parent reply	other threads:[~2022-02-04 22:55 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-02-04 22:04 [PATCH bpf-next] libbpf: Fix strict mode calculation Mauricio Vásquez
2022-02-04 22:24 ` Mauricio Vásquez Bernal
2022-02-04 22:54   ` Andrii Nakryiko
2022-02-04 22:55 ` Andrii Nakryiko [this message]

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=CAEf4Bza+vB-rJD9NNphsU8UbiD06JH9wLzDvX5ZCKnLALSPNpw@mail.gmail.com \
    --to=andrii.nakryiko@gmail.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=mauricio@kinvolk.io \
    --cc=netdev@vger.kernel.org \
    --cc=quentin@isovalent.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).