netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* PATCH: Error message if set memlock=infinite failed during bpf load
@ 2020-04-01  6:57 Stefan Majer
  2020-04-01 19:57 ` David Ahern
  0 siblings, 1 reply; 3+ messages in thread
From: Stefan Majer @ 2020-04-01  6:57 UTC (permalink / raw)
  To: netdev

Executing ip vrf exec <vrfname> command sometimes fails with:

bpf: Failed to load program: Operation not permitted

This error message might be misleading because the underlying reason can be
that memlock limit is to small.

It is already implemented to set memlock to infinite, but without
error handling.

With this patch at least a warning is printed out to inform the user
what might be the root cause.


Signed-off-by: Stefan Majer <stefan.majer@gmail.com>

diff --git a/lib/bpf.c b/lib/bpf.c
index 10cf9bf4..210830d9 100644
--- a/lib/bpf.c
+++ b/lib/bpf.c
@@ -1416,8 +1416,8 @@ static void bpf_init_env(void)
  .rlim_max = RLIM_INFINITY,
  };

- /* Don't bother in case we fail! */
- setrlimit(RLIMIT_MEMLOCK, &limit);
+ if (!setrlimit(RLIMIT_MEMLOCK, &limit))
+ fprintf(stderr, "Continue without setting ulimit memlock=infinity.
Error:%s\n", strerror(errno));

  if (!bpf_get_work_dir(BPF_PROG_TYPE_UNSPEC))
  fprintf(stderr, "Continuing without mounted eBPF fs. Too old kernel?\n");

-- 
Stefan Majer

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: PATCH: Error message if set memlock=infinite failed during bpf load
  2020-04-01  6:57 PATCH: Error message if set memlock=infinite failed during bpf load Stefan Majer
@ 2020-04-01 19:57 ` David Ahern
  2020-04-02  6:02   ` Stefan Majer
  0 siblings, 1 reply; 3+ messages in thread
From: David Ahern @ 2020-04-01 19:57 UTC (permalink / raw)
  To: Stefan Majer, netdev, Stephen Hemminger

On 4/1/20 12:57 AM, Stefan Majer wrote:
> Executing ip vrf exec <vrfname> command sometimes fails with:
> 
> bpf: Failed to load program: Operation not permitted
> 
> This error message might be misleading because the underlying reason can be
> that memlock limit is to small.
> 
> It is already implemented to set memlock to infinite, but without
> error handling.
> 
> With this patch at least a warning is printed out to inform the user
> what might be the root cause.
> 
> 
> Signed-off-by: Stefan Majer <stefan.majer@gmail.com>
> 
> diff --git a/lib/bpf.c b/lib/bpf.c
> index 10cf9bf4..210830d9 100644
> --- a/lib/bpf.c
> +++ b/lib/bpf.c
> @@ -1416,8 +1416,8 @@ static void bpf_init_env(void)
>   .rlim_max = RLIM_INFINITY,
>   };
> 
> - /* Don't bother in case we fail! */
> - setrlimit(RLIMIT_MEMLOCK, &limit);
> + if (!setrlimit(RLIMIT_MEMLOCK, &limit))
> + fprintf(stderr, "Continue without setting ulimit memlock=infinity.
> Error:%s\n", strerror(errno));
> 
>   if (!bpf_get_work_dir(BPF_PROG_TYPE_UNSPEC))
>   fprintf(stderr, "Continuing without mounted eBPF fs. Too old kernel?\n");
> 

bpf_init_env is not called for 'ip vrf exec'.

Since other bpf code raises the limit it would be consistent for 'ip vrf
exec' to do the same. I know this limit has been a pain for some users.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: PATCH: Error message if set memlock=infinite failed during bpf load
  2020-04-01 19:57 ` David Ahern
@ 2020-04-02  6:02   ` Stefan Majer
  0 siblings, 0 replies; 3+ messages in thread
From: Stefan Majer @ 2020-04-02  6:02 UTC (permalink / raw)
  To: David Ahern; +Cc: netdev, Stephen Hemminger

Hi David,

i thought is was my poor C knowledge that i was unable to get the
point where bpf_init_env is called from ip vrf, but thanks.

So should we also do:

diff --git a/ip/ipvrf.c b/ip/ipvrf.c
index b9a43675..16d19621 100644
--- a/ip/ipvrf.c
+++ b/ip/ipvrf.c
@@ -256,6 +256,8 @@ static int prog_load(int idx)
                BPF_EXIT_INSN(),
        };

+       bpf_init_env();
+
        return bpf_prog_load(BPF_PROG_TYPE_CGROUP_SOCK, prog, sizeof(prog),
                             "GPL", bpf_log_buf, sizeof(bpf_log_buf));
 }
diff --git a/lib/bpf.c b/lib/bpf.c
index 10cf9bf4..210830d9 100644
--- a/lib/bpf.c
+++ b/lib/bpf.c
@@ -1416,8 +1416,8 @@ static void bpf_init_env(void)
                .rlim_max = RLIM_INFINITY,
        };

-       /* Don't bother in case we fail! */
-       setrlimit(RLIMIT_MEMLOCK, &limit);
+       if (!setrlimit(RLIMIT_MEMLOCK, &limit))
+               fprintf(stderr, "Continue without setting ulimit
memlock=infinity. Error:%s\n", strerror(errno));

        if (!bpf_get_work_dir(BPF_PROG_TYPE_UNSPEC))
                fprintf(stderr, "Continuing without mounted eBPF fs.
Too old kernel?\n");

Greetings
Stefan

On Wed, Apr 1, 2020 at 9:57 PM David Ahern <dsahern@gmail.com> wrote:
>
> On 4/1/20 12:57 AM, Stefan Majer wrote:
> > Executing ip vrf exec <vrfname> command sometimes fails with:
> >
> > bpf: Failed to load program: Operation not permitted
> >
> > This error message might be misleading because the underlying reason can be
> > that memlock limit is to small.
> >
> > It is already implemented to set memlock to infinite, but without
> > error handling.
> >
> > With this patch at least a warning is printed out to inform the user
> > what might be the root cause.
> >
> >
> > Signed-off-by: Stefan Majer <stefan.majer@gmail.com>
> >
> > diff --git a/lib/bpf.c b/lib/bpf.c
> > index 10cf9bf4..210830d9 100644
> > --- a/lib/bpf.c
> > +++ b/lib/bpf.c
> > @@ -1416,8 +1416,8 @@ static void bpf_init_env(void)
> >   .rlim_max = RLIM_INFINITY,
> >   };
> >
> > - /* Don't bother in case we fail! */
> > - setrlimit(RLIMIT_MEMLOCK, &limit);
> > + if (!setrlimit(RLIMIT_MEMLOCK, &limit))
> > + fprintf(stderr, "Continue without setting ulimit memlock=infinity.
> > Error:%s\n", strerror(errno));
> >
> >   if (!bpf_get_work_dir(BPF_PROG_TYPE_UNSPEC))
> >   fprintf(stderr, "Continuing without mounted eBPF fs. Too old kernel?\n");
> >
>
> bpf_init_env is not called for 'ip vrf exec'.
>
> Since other bpf code raises the limit it would be consistent for 'ip vrf
> exec' to do the same. I know this limit has been a pain for some users.



-- 
Stefan Majer

^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-04-02  6:02 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-04-01  6:57 PATCH: Error message if set memlock=infinite failed during bpf load Stefan Majer
2020-04-01 19:57 ` David Ahern
2020-04-02  6:02   ` Stefan Majer

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).