Skip to content

Commit d6d418b

Browse files
fomichevanakryiko
authored andcommitted
libbpf: Cap 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 5 (arbitrary) times and give up. v2: * 10 -> 5 retires (Andrii Nakryiko) Signed-off-by: Stanislav Fomichev <[email protected]> Signed-off-by: Andrii Nakryiko <[email protected]> Acked-by: Andrii Nakryiko <[email protected]> Link: https://lore.kernel.org/bpf/[email protected]
1 parent 9cf309c commit d6d418b

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

tools/lib/bpf/bpf.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,12 @@ static inline int sys_bpf(enum bpf_cmd cmd, union bpf_attr *attr,
6767

6868
static inline int sys_bpf_prog_load(union bpf_attr *attr, unsigned int size)
6969
{
70+
int retries = 5;
7071
int fd;
7172

7273
do {
7374
fd = sys_bpf(BPF_PROG_LOAD, attr, size);
74-
} while (fd < 0 && errno == EAGAIN);
75+
} while (fd < 0 && errno == EAGAIN && retries-- > 0);
7576

7677
return fd;
7778
}

0 commit comments

Comments
 (0)