Skip to content

Commit aa570ff

Browse files
author
Alexei Starovoitov
committed
Merge branch 'rename-info_cnt-to-nr_info'
Yonghong Song says: ==================== Before func_info and line_info are added to the kernel, there are several fields in structure bpf_prog_info specifying the "count" of a user buffer, e.g., __u32 nr_jited_ksyms; __u32 nr_jited_func_lens; The naming convention has the prefix "nr_". The func_info and line_info support added several fields __u32 func_info_cnt; __u32 line_info_cnt; __u32 jited_line_info_cnt; to indicate the "count" of buffers func_info, line_info and jited_line_info. The original intention is to keep the field names the same as those in structure bpf_attr, so it will be clear that the "count" returned to user space will be the same as the one passed to the kernel during prog load. Unfortunately, the field names *_info_cnt are not consistent with other existing fields in bpf_prog_info. This patch set renamed the fields *_info_cnt to nr_*_info to keep naming convention consistent. ==================== Signed-off-by: Alexei Starovoitov <[email protected]>
2 parents 7a5725d + cfc5424 commit aa570ff

File tree

6 files changed

+81
-81
lines changed

6 files changed

+81
-81
lines changed

include/uapi/linux/bpf.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2696,11 +2696,11 @@ struct bpf_prog_info {
26962696
__u32 btf_id;
26972697
__u32 func_info_rec_size;
26982698
__aligned_u64 func_info;
2699-
__u32 func_info_cnt;
2700-
__u32 line_info_cnt;
2699+
__u32 nr_func_info;
2700+
__u32 nr_line_info;
27012701
__aligned_u64 line_info;
27022702
__aligned_u64 jited_line_info;
2703-
__u32 jited_line_info_cnt;
2703+
__u32 nr_jited_line_info;
27042704
__u32 line_info_rec_size;
27052705
__u32 jited_line_info_rec_size;
27062706
} __attribute__((aligned(8)));

kernel/bpf/syscall.c

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2055,15 +2055,15 @@ static int set_info_rec_size(struct bpf_prog_info *info)
20552055
* _rec_size back to the info.
20562056
*/
20572057

2058-
if ((info->func_info_cnt || info->func_info_rec_size) &&
2058+
if ((info->nr_func_info || info->func_info_rec_size) &&
20592059
info->func_info_rec_size != sizeof(struct bpf_func_info))
20602060
return -EINVAL;
20612061

2062-
if ((info->line_info_cnt || info->line_info_rec_size) &&
2062+
if ((info->nr_line_info || info->line_info_rec_size) &&
20632063
info->line_info_rec_size != sizeof(struct bpf_line_info))
20642064
return -EINVAL;
20652065

2066-
if ((info->jited_line_info_cnt || info->jited_line_info_rec_size) &&
2066+
if ((info->nr_jited_line_info || info->jited_line_info_rec_size) &&
20672067
info->jited_line_info_rec_size != sizeof(__u64))
20682068
return -EINVAL;
20692069

@@ -2125,9 +2125,9 @@ static int bpf_prog_get_info_by_fd(struct bpf_prog *prog,
21252125
info.xlated_prog_len = 0;
21262126
info.nr_jited_ksyms = 0;
21272127
info.nr_jited_func_lens = 0;
2128-
info.func_info_cnt = 0;
2129-
info.line_info_cnt = 0;
2130-
info.jited_line_info_cnt = 0;
2128+
info.nr_func_info = 0;
2129+
info.nr_line_info = 0;
2130+
info.nr_jited_line_info = 0;
21312131
goto done;
21322132
}
21332133

@@ -2268,14 +2268,14 @@ static int bpf_prog_get_info_by_fd(struct bpf_prog *prog,
22682268
if (prog->aux->btf)
22692269
info.btf_id = btf_id(prog->aux->btf);
22702270

2271-
ulen = info.func_info_cnt;
2272-
info.func_info_cnt = prog->aux->func_info_cnt;
2273-
if (info.func_info_cnt && ulen) {
2271+
ulen = info.nr_func_info;
2272+
info.nr_func_info = prog->aux->func_info_cnt;
2273+
if (info.nr_func_info && ulen) {
22742274
if (bpf_dump_raw_ok()) {
22752275
char __user *user_finfo;
22762276

22772277
user_finfo = u64_to_user_ptr(info.func_info);
2278-
ulen = min_t(u32, info.func_info_cnt, ulen);
2278+
ulen = min_t(u32, info.nr_func_info, ulen);
22792279
if (copy_to_user(user_finfo, prog->aux->func_info,
22802280
info.func_info_rec_size * ulen))
22812281
return -EFAULT;
@@ -2284,14 +2284,14 @@ static int bpf_prog_get_info_by_fd(struct bpf_prog *prog,
22842284
}
22852285
}
22862286

2287-
ulen = info.line_info_cnt;
2288-
info.line_info_cnt = prog->aux->nr_linfo;
2289-
if (info.line_info_cnt && ulen) {
2287+
ulen = info.nr_line_info;
2288+
info.nr_line_info = prog->aux->nr_linfo;
2289+
if (info.nr_line_info && ulen) {
22902290
if (bpf_dump_raw_ok()) {
22912291
__u8 __user *user_linfo;
22922292

22932293
user_linfo = u64_to_user_ptr(info.line_info);
2294-
ulen = min_t(u32, info.line_info_cnt, ulen);
2294+
ulen = min_t(u32, info.nr_line_info, ulen);
22952295
if (copy_to_user(user_linfo, prog->aux->linfo,
22962296
info.line_info_rec_size * ulen))
22972297
return -EFAULT;
@@ -2300,18 +2300,18 @@ static int bpf_prog_get_info_by_fd(struct bpf_prog *prog,
23002300
}
23012301
}
23022302

2303-
ulen = info.jited_line_info_cnt;
2303+
ulen = info.nr_jited_line_info;
23042304
if (prog->aux->jited_linfo)
2305-
info.jited_line_info_cnt = prog->aux->nr_linfo;
2305+
info.nr_jited_line_info = prog->aux->nr_linfo;
23062306
else
2307-
info.jited_line_info_cnt = 0;
2308-
if (info.jited_line_info_cnt && ulen) {
2307+
info.nr_jited_line_info = 0;
2308+
if (info.nr_jited_line_info && ulen) {
23092309
if (bpf_dump_raw_ok()) {
23102310
__u64 __user *user_linfo;
23112311
u32 i;
23122312

23132313
user_linfo = u64_to_user_ptr(info.jited_line_info);
2314-
ulen = min_t(u32, info.jited_line_info_cnt, ulen);
2314+
ulen = min_t(u32, info.nr_jited_line_info, ulen);
23152315
for (i = 0; i < ulen; i++) {
23162316
if (put_user((__u64)(long)prog->aux->jited_linfo[i],
23172317
&user_linfo[i]))

tools/bpf/bpftool/prog.c

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,7 @@ static int do_dump(int argc, char **argv)
425425
{
426426
unsigned int finfo_rec_size, linfo_rec_size, jited_linfo_rec_size;
427427
void *func_info = NULL, *linfo = NULL, *jited_linfo = NULL;
428-
unsigned int finfo_cnt, linfo_cnt = 0, jited_linfo_cnt = 0;
428+
unsigned int nr_finfo, nr_linfo = 0, nr_jited_linfo = 0;
429429
struct bpf_prog_linfo *prog_linfo = NULL;
430430
unsigned long *func_ksyms = NULL;
431431
struct bpf_prog_info info = {};
@@ -537,10 +537,10 @@ static int do_dump(int argc, char **argv)
537537
}
538538
}
539539

540-
finfo_cnt = info.func_info_cnt;
540+
nr_finfo = info.nr_func_info;
541541
finfo_rec_size = info.func_info_rec_size;
542-
if (finfo_cnt && finfo_rec_size) {
543-
func_info = malloc(finfo_cnt * finfo_rec_size);
542+
if (nr_finfo && finfo_rec_size) {
543+
func_info = malloc(nr_finfo * finfo_rec_size);
544544
if (!func_info) {
545545
p_err("mem alloc failed");
546546
close(fd);
@@ -549,9 +549,9 @@ static int do_dump(int argc, char **argv)
549549
}
550550

551551
linfo_rec_size = info.line_info_rec_size;
552-
if (info.line_info_cnt && linfo_rec_size && info.btf_id) {
553-
linfo_cnt = info.line_info_cnt;
554-
linfo = malloc(linfo_cnt * linfo_rec_size);
552+
if (info.nr_line_info && linfo_rec_size && info.btf_id) {
553+
nr_linfo = info.nr_line_info;
554+
linfo = malloc(nr_linfo * linfo_rec_size);
555555
if (!linfo) {
556556
p_err("mem alloc failed");
557557
close(fd);
@@ -560,13 +560,13 @@ static int do_dump(int argc, char **argv)
560560
}
561561

562562
jited_linfo_rec_size = info.jited_line_info_rec_size;
563-
if (info.jited_line_info_cnt &&
563+
if (info.nr_jited_line_info &&
564564
jited_linfo_rec_size &&
565565
info.nr_jited_ksyms &&
566566
info.nr_jited_func_lens &&
567567
info.btf_id) {
568-
jited_linfo_cnt = info.jited_line_info_cnt;
569-
jited_linfo = malloc(jited_linfo_cnt * jited_linfo_rec_size);
568+
nr_jited_linfo = info.nr_jited_line_info;
569+
jited_linfo = malloc(nr_jited_linfo * jited_linfo_rec_size);
570570
if (!jited_linfo) {
571571
p_err("mem alloc failed");
572572
close(fd);
@@ -582,13 +582,13 @@ static int do_dump(int argc, char **argv)
582582
info.nr_jited_ksyms = nr_func_ksyms;
583583
info.jited_func_lens = ptr_to_u64(func_lens);
584584
info.nr_jited_func_lens = nr_func_lens;
585-
info.func_info_cnt = finfo_cnt;
585+
info.nr_func_info = nr_finfo;
586586
info.func_info_rec_size = finfo_rec_size;
587587
info.func_info = ptr_to_u64(func_info);
588-
info.line_info_cnt = linfo_cnt;
588+
info.nr_line_info = nr_linfo;
589589
info.line_info_rec_size = linfo_rec_size;
590590
info.line_info = ptr_to_u64(linfo);
591-
info.jited_line_info_cnt = jited_linfo_cnt;
591+
info.nr_jited_line_info = nr_jited_linfo;
592592
info.jited_line_info_rec_size = jited_linfo_rec_size;
593593
info.jited_line_info = ptr_to_u64(jited_linfo);
594594

@@ -614,9 +614,9 @@ static int do_dump(int argc, char **argv)
614614
goto err_free;
615615
}
616616

617-
if (info.func_info_cnt != finfo_cnt) {
618-
p_err("incorrect func_info_cnt %d vs. expected %d",
619-
info.func_info_cnt, finfo_cnt);
617+
if (info.nr_func_info != nr_finfo) {
618+
p_err("incorrect nr_func_info %d vs. expected %d",
619+
info.nr_func_info, nr_finfo);
620620
goto err_free;
621621
}
622622

@@ -630,12 +630,12 @@ static int do_dump(int argc, char **argv)
630630
/* kernel.kptr_restrict is set. No func_info available. */
631631
free(func_info);
632632
func_info = NULL;
633-
finfo_cnt = 0;
633+
nr_finfo = 0;
634634
}
635635

636-
if (linfo && info.line_info_cnt != linfo_cnt) {
637-
p_err("incorrect line_info_cnt %u vs. expected %u",
638-
info.line_info_cnt, linfo_cnt);
636+
if (linfo && info.nr_line_info != nr_linfo) {
637+
p_err("incorrect nr_line_info %u vs. expected %u",
638+
info.nr_line_info, nr_linfo);
639639
goto err_free;
640640
}
641641

@@ -645,9 +645,9 @@ static int do_dump(int argc, char **argv)
645645
goto err_free;
646646
}
647647

648-
if (jited_linfo && info.jited_line_info_cnt != jited_linfo_cnt) {
649-
p_err("incorrect jited_line_info_cnt %u vs. expected %u",
650-
info.jited_line_info_cnt, jited_linfo_cnt);
648+
if (jited_linfo && info.nr_jited_line_info != nr_jited_linfo) {
649+
p_err("incorrect nr_jited_line_info %u vs. expected %u",
650+
info.nr_jited_line_info, nr_jited_linfo);
651651
goto err_free;
652652
}
653653

@@ -670,7 +670,7 @@ static int do_dump(int argc, char **argv)
670670
goto err_free;
671671
}
672672

673-
if (linfo_cnt) {
673+
if (nr_linfo) {
674674
prog_linfo = bpf_prog_linfo__new(&info);
675675
if (!prog_linfo)
676676
p_info("error in processing bpf_line_info. continue without it.");

tools/include/uapi/linux/bpf.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2695,11 +2695,11 @@ struct bpf_prog_info {
26952695
__u32 btf_id;
26962696
__u32 func_info_rec_size;
26972697
__aligned_u64 func_info;
2698-
__u32 func_info_cnt;
2699-
__u32 line_info_cnt;
2698+
__u32 nr_func_info;
2699+
__u32 nr_line_info;
27002700
__aligned_u64 line_info;
27012701
__aligned_u64 jited_line_info;
2702-
__u32 jited_line_info_cnt;
2702+
__u32 nr_jited_line_info;
27032703
__u32 line_info_rec_size;
27042704
__u32 jited_line_info_rec_size;
27052705
} __attribute__((aligned(8)));

tools/lib/bpf/bpf_prog_linfo.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ struct bpf_prog_linfo *bpf_prog_linfo__new(const struct bpf_prog_info *info)
105105
struct bpf_prog_linfo *prog_linfo;
106106
__u32 nr_linfo, nr_jited_func;
107107

108-
nr_linfo = info->line_info_cnt;
108+
nr_linfo = info->nr_line_info;
109109

110110
/*
111111
* Test !info->line_info because the kernel may NULL
@@ -138,7 +138,7 @@ struct bpf_prog_linfo *bpf_prog_linfo__new(const struct bpf_prog_info *info)
138138
nr_jited_func = info->nr_jited_ksyms;
139139
if (!nr_jited_func ||
140140
!info->jited_line_info ||
141-
info->jited_line_info_cnt != nr_linfo ||
141+
info->nr_jited_line_info != nr_linfo ||
142142
info->jited_line_info_rec_size < sizeof(__u64) ||
143143
info->nr_jited_func_lens != nr_jited_func ||
144144
!info->jited_ksyms ||

0 commit comments

Comments
 (0)