libbpf: add retries in sys_bpf_prog_load
Subsystems (4)
PATCH 1/1 libbpf: add retries in sys_bpf_prog_load
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.
--- tools/lib/bpf/bpf.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
tools/lib/bpf/bpf.c +2 -1
@@ -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; }
Signature · 1 line
2.29.2.454.gaff20da3a2-goog
Quoted 7 lines · 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.
Quoted 5 lines
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 <[email protected]>---
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.
Quoted 24 lines
tools/lib/bpf/bpf.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)tools/lib/bpf/bpf.c +2
-2@@ -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
Quoted 9 lines · Andrii Nakryiko
Quoted 7 lines · 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.
Quoted 8 lines
Quoted 5 lines
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 <[email protected]>---
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/ :-(
Quoted 5 lines
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 <[email protected]>
Let me respin with a proper subject and 5 retries.