Re: [PATCH v2 bpf-next 02/12] libbpf: pass number of prog load attempts explicitly

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, Nov 4, 2021 at 11:43 PM Dave Marchevsky <davemarchevsky@xxxxxx> 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@xxxxxxxxxx>
> > ---
> >  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@xxxxxx>
>
> >  {
> > -     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;
> >  }
>
> [...]



[Index of Archives]     [Linux Samsung SoC]     [Linux Rockchip SoC]     [Linux Actions SoC]     [Linux for Synopsys ARC Processors]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]


  Powered by Linux