bpf.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Andrii Nakryiko <andrii.nakryiko@gmail.com>
To: Daniel Borkmann <daniel@iogearbox.net>
Cc: Andrii Nakryiko <andriin@fb.com>, bpf <bpf@vger.kernel.org>,
	Networking <netdev@vger.kernel.org>,
	Alexei Starovoitov <ast@fb.com>, Kernel Team <kernel-team@fb.com>
Subject: Re: [PATCH v2 bpf] bpf: enforce BPF ringbuf size to be the power of 2
Date: Tue, 30 Jun 2020 08:15:33 -0700	[thread overview]
Message-ID: <CAEf4BzZDJyEfSqnnDv0pe6J8GZwQVE8tucJWs3hHNeQemwVN9w@mail.gmail.com> (raw)
In-Reply-To: <285e32b1-daa5-1be4-5939-c86249680311@iogearbox.net>

On Tue, Jun 30, 2020 at 7:52 AM Daniel Borkmann <daniel@iogearbox.net> wrote:
>
> On 6/30/20 8:15 AM, Andrii Nakryiko wrote:
> > BPF ringbuf assumes the size to be a multiple of page size and the power of
> > 2 value. The latter is important to avoid division while calculating position
> > inside the ring buffer and using (N-1) mask instead. This patch fixes omission
> > to enforce power-of-2 size rule.
> >
> > Fixes: 457f44363a88 ("bpf: Implement BPF ring buffer and verifier support for it")
> > Signed-off-by: Andrii Nakryiko <andriin@fb.com>
>
> Lgtm, applied, thanks!
>

Thanks, Daniel!

> [...]
> > @@ -166,9 +157,16 @@ static struct bpf_map *ringbuf_map_alloc(union bpf_attr *attr)
> >               return ERR_PTR(-EINVAL);
> >
> >       if (attr->key_size || attr->value_size ||
> > -         attr->max_entries == 0 || !PAGE_ALIGNED(attr->max_entries))
> > +         !is_power_of_2(attr->max_entries) ||
> > +         !PAGE_ALIGNED(attr->max_entries))
>
> Technically !IS_ALIGNED(attr->max_entries, PAGE_SIZE) might have been a bit cleaner
> since PAGE_ALIGNED() is only intended for pointers, though, not wrong here given
> max_entries is u32.

I've found a bunch of uses on non-pointers, e.g., `if
(!PAGE_ALIGNED(fs_info->nodesize)) {` in BTRFS code, so assumed it's
intended to be used more generically. But let me know if you want me
to do IS_ALIGNED change.

>
> Thanks,
> Daniel

      reply	other threads:[~2020-06-30 15:15 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-06-30  6:15 [PATCH v2 bpf] bpf: enforce BPF ringbuf size to be the power of 2 Andrii Nakryiko
2020-06-30 14:52 ` Daniel Borkmann
2020-06-30 15:15   ` 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=CAEf4BzZDJyEfSqnnDv0pe6J8GZwQVE8tucJWs3hHNeQemwVN9w@mail.gmail.com \
    --to=andrii.nakryiko@gmail.com \
    --cc=andriin@fb.com \
    --cc=ast@fb.com \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=kernel-team@fb.com \
    --cc=netdev@vger.kernel.org \
    /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).