* [PATCH bpf-next] libbpf: add retries in sys_bpf_prog_load
@ 2020-12-02 17:50 Stanislav Fomichev
2020-12-02 22:46 ` Andrii Nakryiko
0 siblings, 1 reply; 3+ messages in thread
From: Stanislav Fomichev @ 2020-12-02 17:50 UTC (permalink / raw)
To: netdev, bpf; +Cc: davem, ast, daniel, Stanislav Fomichev
I've seen a situation, where a process that's under pprof constantly
generates SIGPROF which prevents program loading indefinitely.
The right thing to do probably is to disable signals in the upper
layers while loading, but it still would be nice to get some error from
libbpf instead of an endless loop.
Let's add some small retry limit to the program loading:
try loading the program 10 (arbitrary) times and give up.
Signed-off-by: Stanislav Fomichev <sdf@google.com>
---
tools/lib/bpf/bpf.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/tools/lib/bpf/bpf.c b/tools/lib/bpf/bpf.c
index d27e34133973..31ebd6b3ec7c 100644
--- a/tools/lib/bpf/bpf.c
+++ b/tools/lib/bpf/bpf.c
@@ -67,11 +67,12 @@ static inline int sys_bpf(enum bpf_cmd cmd, union bpf_attr *attr,
static inline int sys_bpf_prog_load(union bpf_attr *attr, unsigned int size)
{
+ int retries = 10;
int fd;
do {
fd = sys_bpf(BPF_PROG_LOAD, attr, size);
- } while (fd < 0 && errno == EAGAIN);
+ } while (fd < 0 && errno == EAGAIN && retries-- > 0);
return fd;
}
--
2.29.2.454.gaff20da3a2-goog
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH bpf-next] libbpf: add retries in sys_bpf_prog_load
2020-12-02 17:50 [PATCH bpf-next] libbpf: add retries in sys_bpf_prog_load Stanislav Fomichev
@ 2020-12-02 22:46 ` Andrii Nakryiko
2020-12-02 22:51 ` Stanislav Fomichev
0 siblings, 1 reply; 3+ messages in thread
From: Andrii Nakryiko @ 2020-12-02 22:46 UTC (permalink / raw)
To: Stanislav Fomichev
Cc: Networking, bpf, David S. Miller, Alexei Starovoitov,
Daniel Borkmann
On Wed, Dec 2, 2020 at 9:52 AM Stanislav Fomichev <sdf@google.com> wrote:
>
> I've seen a situation, where a process that's under pprof constantly
> generates SIGPROF which prevents program loading indefinitely.
> The right thing to do probably is to disable signals in the upper
> layers while loading, but it still would be nice to get some error from
> libbpf instead of an endless loop.
>
> Let's add some small retry limit to the program loading:
> try loading the program 10 (arbitrary) times and give up.
>
> Signed-off-by: Stanislav Fomichev <sdf@google.com>
> ---
The subject is misleading as hell. You are not adding retries, you are
limiting the number of retries.
Otherwise, LGTM. I'd probably go with an even smaller number, can't
imagine any normal use case having more than once EAGAIN. So I'd say
feel free to reduce it to 5 even.
Acked-by: Andrii Nakryiko <andrii@kernel.org>
> tools/lib/bpf/bpf.c | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/tools/lib/bpf/bpf.c b/tools/lib/bpf/bpf.c
> index d27e34133973..31ebd6b3ec7c 100644
> --- a/tools/lib/bpf/bpf.c
> +++ b/tools/lib/bpf/bpf.c
> @@ -67,11 +67,12 @@ static inline int sys_bpf(enum bpf_cmd cmd, union bpf_attr *attr,
>
> static inline int sys_bpf_prog_load(union bpf_attr *attr, unsigned int size)
> {
> + int retries = 10;
> int fd;
>
> do {
> fd = sys_bpf(BPF_PROG_LOAD, attr, size);
> - } while (fd < 0 && errno == EAGAIN);
> + } while (fd < 0 && errno == EAGAIN && retries-- > 0);
>
> return fd;
> }
> --
> 2.29.2.454.gaff20da3a2-goog
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH bpf-next] libbpf: add retries in sys_bpf_prog_load
2020-12-02 22:46 ` Andrii Nakryiko
@ 2020-12-02 22:51 ` Stanislav Fomichev
0 siblings, 0 replies; 3+ messages in thread
From: Stanislav Fomichev @ 2020-12-02 22:51 UTC (permalink / raw)
To: Andrii Nakryiko
Cc: Networking, bpf, David S. Miller, Alexei Starovoitov,
Daniel Borkmann
On Wed, Dec 2, 2020 at 2:46 PM Andrii Nakryiko
<andrii.nakryiko@gmail.com> wrote:
>
> On Wed, Dec 2, 2020 at 9:52 AM Stanislav Fomichev <sdf@google.com> wrote:
> >
> > I've seen a situation, where a process that's under pprof constantly
> > generates SIGPROF which prevents program loading indefinitely.
> > The right thing to do probably is to disable signals in the upper
> > layers while loading, but it still would be nice to get some error from
> > libbpf instead of an endless loop.
> >
> > Let's add some small retry limit to the program loading:
> > try loading the program 10 (arbitrary) times and give up.
> >
> > Signed-off-by: Stanislav Fomichev <sdf@google.com>
> > ---
>
> The subject is misleading as hell. You are not adding retries, you are
> limiting the number of retries.
Ah, sorry, should've been s/add/cap/ :-(
> Otherwise, LGTM. I'd probably go with an even smaller number, can't
> imagine any normal use case having more than once EAGAIN. So I'd say
> feel free to reduce it to 5 even.
>
> Acked-by: Andrii Nakryiko <andrii@kernel.org>
Let me respin with a proper subject and 5 retries.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2020-12-02 22:52 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-12-02 17:50 [PATCH bpf-next] libbpf: add retries in sys_bpf_prog_load Stanislav Fomichev
2020-12-02 22:46 ` Andrii Nakryiko
2020-12-02 22:51 ` Stanislav Fomichev
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox