All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andrii Nakryiko <andrii.nakryiko@gmail.com>
To: Dave Marchevsky <davemarchevsky@fb.com>
Cc: Andrii Nakryiko <andrii@kernel.org>, bpf <bpf@vger.kernel.org>,
	Alexei Starovoitov <ast@kernel.org>,
	Daniel Borkmann <daniel@iogearbox.net>,
	Kernel Team <kernel-team@fb.com>,
	Hengqi Chen <hengqi.chen@gmail.com>
Subject: Re: [PATCH v2 bpf-next 02/12] libbpf: pass number of prog load attempts explicitly
Date: Fri, 5 Nov 2021 09:53:14 -0700	[thread overview]
Message-ID: <CAEf4BzbYDuv2XP=VrorB=b2HU09-wzUVB+s-MvUeOm1pxPU9mA@mail.gmail.com> (raw)
In-Reply-To: <bc6ddd1f-b614-294a-5d6a-1a6af4ee5259@fb.com>

On Thu, Nov 4, 2021 at 11:43 PM Dave Marchevsky <davemarchevsky@fb.com> wrote:
>
> On 11/3/21 6:08 PM, Andrii Nakryiko wrote:
> > Allow to control number of BPF_PROG_LOAD attempts from outside the
> > sys_bpf_prog_load() helper.
> >
> > Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
> > ---
> >  tools/lib/bpf/bpf.c | 15 ++++++++-------
> >  1 file changed, 8 insertions(+), 7 deletions(-)
> >
> > diff --git a/tools/lib/bpf/bpf.c b/tools/lib/bpf/bpf.c
> > index c09cbb868c9f..8e6a23c42560 100644
> > --- a/tools/lib/bpf/bpf.c
> > +++ b/tools/lib/bpf/bpf.c
> > @@ -74,14 +74,15 @@ static inline int sys_bpf_fd(enum bpf_cmd cmd, union bpf_attr *attr,
> >       return ensure_good_fd(fd);
> >  }
> >
> > -static inline int sys_bpf_prog_load(union bpf_attr *attr, unsigned int size)
> > +#define PROG_LOAD_ATTEMPTS 5
> > +
> > +static inline int sys_bpf_prog_load(union bpf_attr *attr, unsigned int size, int attempts)
>
> nit: Should attempts be unsigned? Although, with the pre-decrement below, I can
> see the case for leaving as is.

Yeah, I find signed integers a bit "safer" in practice for all sorts
of counters. Overflows and underflows have higher chances of being
detected.

>
> Regardless,
>
> Acked-by: Dave Marchevsky <davemarchevsky@fb.com>
>
> >  {
> > -     int retries = 5;
> >       int fd;
> >
> >       do {
> >               fd = sys_bpf_fd(BPF_PROG_LOAD, attr, size);
> > -     } while (fd < 0 && errno == EAGAIN && retries-- > 0);
> > +     } while (fd < 0 && errno == EAGAIN && --attempts > 0);
> >
> >       return fd;
> >  }
>
> [...]

  reply	other threads:[~2021-11-05 16:53 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-03 22:08 [PATCH v2 bpf-next 00/12] libbpf: add unified bpf_prog_load() low-level API Andrii Nakryiko
2021-11-03 22:08 ` [PATCH v2 bpf-next 01/12] libbpf: rename DECLARE_LIBBPF_OPTS into LIBBPF_OPTS Andrii Nakryiko
2021-11-05  6:37   ` Dave Marchevsky
2021-11-03 22:08 ` [PATCH v2 bpf-next 02/12] libbpf: pass number of prog load attempts explicitly Andrii Nakryiko
2021-11-05  6:42   ` Dave Marchevsky
2021-11-05 16:53     ` Andrii Nakryiko [this message]
2021-11-03 22:08 ` [PATCH v2 bpf-next 03/12] libbpf: unify low-level BPF_PROG_LOAD APIs into bpf_prog_load() Andrii Nakryiko
2021-11-03 22:08 ` [PATCH v2 bpf-next 04/12] libbpf: remove internal use of deprecated bpf_prog_load() variants Andrii Nakryiko
2021-11-03 22:08 ` [PATCH v2 bpf-next 05/12] libbpf: stop using to-be-deprecated APIs Andrii Nakryiko
2021-11-03 22:08 ` [PATCH v2 bpf-next 06/12] bpftool: stop using deprecated bpf_load_program() Andrii Nakryiko
2021-11-03 22:08 ` [PATCH v2 bpf-next 07/12] libbpf: remove deprecation attribute from struct bpf_prog_prep_result Andrii Nakryiko
2021-11-05  6:51   ` Dave Marchevsky
2021-11-03 22:08 ` [PATCH v2 bpf-next 08/12] selftests/bpf: fix non-strict SEC() program sections Andrii Nakryiko
2021-11-05  6:54   ` Dave Marchevsky
2021-11-03 22:08 ` [PATCH v2 bpf-next 09/12] selftests/bpf: convert legacy prog load APIs to bpf_prog_load() Andrii Nakryiko
2021-11-03 22:08 ` [PATCH v2 bpf-next 10/12] selftests/bpf: merge test_stub.c into testing_helpers.c Andrii Nakryiko
2021-11-05  7:51   ` Dave Marchevsky
2021-11-10  1:48   ` Alexei Starovoitov
2021-11-10  2:38     ` Andrii Nakryiko
2021-11-10  3:31       ` Alexei Starovoitov
2021-11-03 22:08 ` [PATCH v2 bpf-next 11/12] selftests/bpf: use explicit bpf_prog_test_load() calls everywhere Andrii Nakryiko
2021-11-05  7:36   ` Dave Marchevsky
2021-11-05 16:55     ` Andrii Nakryiko
2021-11-05 20:55   ` Dave Marchevsky
2021-11-03 22:08 ` [PATCH v2 bpf-next 12/12] selftests/bpf: use explicit bpf_test_load_program() helper calls Andrii Nakryiko
2021-11-05 20:56   ` Dave Marchevsky

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='CAEf4BzbYDuv2XP=VrorB=b2HU09-wzUVB+s-MvUeOm1pxPU9mA@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=davemarchevsky@fb.com \
    --cc=hengqi.chen@gmail.com \
    --cc=kernel-team@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.