Skip to content

Commit 876843c

Browse files
fomichevMartin KaFai Lau
authored andcommitted
bpftool: mark orphaned programs during prog show
Commit ef01f4e ("bpf: restore the ebpf program ID for BPF_AUDIT_UNLOAD and PERF_BPF_EVENT_PROG_UNLOAD") stopped removing program's id from idr when the offloaded/bound netdev goes away. I was supposed to take a look and check in [0], but apparently I did not. Martin points out it might be useful to keep it that way for observability sake, but we at least need to mark those programs as unusable. Mark those programs as 'orphaned' and keep printing the list when we encounter ENODEV. 0: unspec tag 0000000000000000 xlated 0B not jited memlock 4096B orphaned [0]: https://lore.kernel.org/all/CAKH8qBtyR20ZWAc11z1-6pGb3Hd47AQUTbE_cfoktG59TqaJ7Q@mail.gmail.com/ v3: * use two spaces for " orphaned" (Quentin) Cc: [email protected] Fixes: ef01f4e ("bpf: restore the ebpf program ID for BPF_AUDIT_UNLOAD and PERF_BPF_EVENT_PROG_UNLOAD") Signed-off-by: Stanislav Fomichev <[email protected]> Reviewed-by: Quentin Monnet <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Martin KaFai Lau <[email protected]>
1 parent b16904f commit 876843c

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

tools/bpf/bpftool/prog.c

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,7 @@ static void print_prog_header_json(struct bpf_prog_info *info, int fd)
442442
jsonw_uint_field(json_wtr, "recursion_misses", info->recursion_misses);
443443
}
444444

445-
static void print_prog_json(struct bpf_prog_info *info, int fd)
445+
static void print_prog_json(struct bpf_prog_info *info, int fd, bool orphaned)
446446
{
447447
char *memlock;
448448

@@ -461,6 +461,7 @@ static void print_prog_json(struct bpf_prog_info *info, int fd)
461461
jsonw_uint_field(json_wtr, "uid", info->created_by_uid);
462462
}
463463

464+
jsonw_bool_field(json_wtr, "orphaned", orphaned);
464465
jsonw_uint_field(json_wtr, "bytes_xlated", info->xlated_prog_len);
465466

466467
if (info->jited_prog_len) {
@@ -527,7 +528,7 @@ static void print_prog_header_plain(struct bpf_prog_info *info, int fd)
527528
printf("\n");
528529
}
529530

530-
static void print_prog_plain(struct bpf_prog_info *info, int fd)
531+
static void print_prog_plain(struct bpf_prog_info *info, int fd, bool orphaned)
531532
{
532533
char *memlock;
533534

@@ -554,6 +555,9 @@ static void print_prog_plain(struct bpf_prog_info *info, int fd)
554555
printf(" memlock %sB", memlock);
555556
free(memlock);
556557

558+
if (orphaned)
559+
printf(" orphaned");
560+
557561
if (info->nr_map_ids)
558562
show_prog_maps(fd, info->nr_map_ids);
559563

@@ -581,15 +585,15 @@ static int show_prog(int fd)
581585
int err;
582586

583587
err = bpf_prog_get_info_by_fd(fd, &info, &len);
584-
if (err) {
588+
if (err && err != -ENODEV) {
585589
p_err("can't get prog info: %s", strerror(errno));
586590
return -1;
587591
}
588592

589593
if (json_output)
590-
print_prog_json(&info, fd);
594+
print_prog_json(&info, fd, err == -ENODEV);
591595
else
592-
print_prog_plain(&info, fd);
596+
print_prog_plain(&info, fd, err == -ENODEV);
593597

594598
return 0;
595599
}

0 commit comments

Comments
 (0)