Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

bpf: libbpf: retry loading program on EAGAIN

Commit c3494801cd17 ("bpf: check pending signals while
verifying programs") makes it possible for the BPF_PROG_LOAD
to fail with EAGAIN. Retry unconditionally in this case.

Fixes: c3494801cd17 ("bpf: check pending signals while verifying programs")
Signed-off-by: Lorenz Bauer <lmb@cloudflare.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>

authored by

Lorenz Bauer and committed by
Daniel Borkmann
86edaed3 6bf3bbe1

+15 -4
+15 -4
tools/lib/bpf/bpf.c
··· 65 65 return syscall(__NR_bpf, cmd, attr, size); 66 66 } 67 67 68 + static inline int sys_bpf_prog_load(union bpf_attr *attr, unsigned int size) 69 + { 70 + int fd; 71 + 72 + do { 73 + fd = sys_bpf(BPF_PROG_LOAD, attr, size); 74 + } while (fd < 0 && errno == EAGAIN); 75 + 76 + return fd; 77 + } 78 + 68 79 int bpf_create_map_xattr(const struct bpf_create_map_attr *create_attr) 69 80 { 70 81 __u32 name_len = create_attr->name ? strlen(create_attr->name) : 0; ··· 243 232 memcpy(attr.prog_name, load_attr->name, 244 233 min(name_len, BPF_OBJ_NAME_LEN - 1)); 245 234 246 - fd = sys_bpf(BPF_PROG_LOAD, &attr, sizeof(attr)); 235 + fd = sys_bpf_prog_load(&attr, sizeof(attr)); 247 236 if (fd >= 0) 248 237 return fd; 249 238 ··· 280 269 break; 281 270 } 282 271 283 - fd = sys_bpf(BPF_PROG_LOAD, &attr, sizeof(attr)); 272 + fd = sys_bpf_prog_load(&attr, sizeof(attr)); 284 273 285 274 if (fd >= 0) 286 275 goto done; ··· 294 283 attr.log_size = log_buf_sz; 295 284 attr.log_level = 1; 296 285 log_buf[0] = 0; 297 - fd = sys_bpf(BPF_PROG_LOAD, &attr, sizeof(attr)); 286 + fd = sys_bpf_prog_load(&attr, sizeof(attr)); 298 287 done: 299 288 free(finfo); 300 289 free(linfo); ··· 339 328 attr.kern_version = kern_version; 340 329 attr.prog_flags = prog_flags; 341 330 342 - return sys_bpf(BPF_PROG_LOAD, &attr, sizeof(attr)); 331 + return sys_bpf_prog_load(&attr, sizeof(attr)); 343 332 } 344 333 345 334 int bpf_map_update_elem(int fd, const void *key, const void *value,