From d1f90bcdc7cf95cf442321f18452d0367e80b7d5 Mon Sep 17 00:00:00 2001
From: "Dmitry V. Levin" <ldv@altlinux.org>
Date: Tue, 12 Mar 2019 11:17:20 +0000
Subject: [PATCH] bpf: add support for *jited_ksyms and *jited_func_lens fields
in struct bpf_prog_info
* bpf_attr.h (struct bpf_prog_info_struct): Add nr_jited_ksyms,
nr_jited_func_lens, jited_ksyms, and jited_func_lens fields.
* bpf.c (struct obj_get_info_saved): Likewise.
(print_bpf_prog_info): Decode these fields introduced by Linux commits
v4.18-rc1~114^2~148^2~3^2~6 and v4.18-rc1~114^2~148^2~3^2~2.
* tests/bpf-obj_get_info_by_fd.c (main): Update expected output.
---
bpf.c | 40 ++++++++++++++++++++++++++++++++++++++++
bpf_attr.h | 6 +++++-
tests/bpf-obj_get_info_by_fd.c | 21 +++++++++++++++++++++
3 files changed, 66 insertions(+), 1 deletion(-)
Index: strace-4.24/bpf.c
===================================================================
--- strace-4.24.orig/bpf.c 2020-01-28 00:15:59.919446522 +0100
+++ strace-4.24/bpf.c 2020-01-28 00:16:27.823183735 +0100
@@ -427,6 +427,11 @@
uint32_t jited_prog_len;
uint32_t xlated_prog_len;
uint32_t nr_map_ids;
+
+ uint32_t nr_jited_ksyms;
+ uint32_t nr_jited_func_lens;
+ uint64_t jited_ksyms;
+ uint64_t jited_func_lens;
};
static void
@@ -497,6 +502,10 @@
saved->jited_prog_len = info.jited_prog_len;
saved->xlated_prog_len = info.xlated_prog_len;
saved->nr_map_ids = info.nr_map_ids;
+ saved->nr_jited_ksyms = info.nr_jited_ksyms;
+ saved->nr_jited_func_lens = info.nr_jited_func_lens;
+ saved->jited_ksyms = info.jited_ksyms;
+ saved->jited_func_lens = info.jited_func_lens;
return;
}
@@ -559,6 +568,37 @@
PRINT_FIELD_DEV(", ", info, netns_dev);
PRINT_FIELD_U(", ", info, netns_ino);
+ /*
+ * The next four fields were introduced by Linux commits
+ * v4.18-rc1~114^2~148^2~3^2~6 and v4.18-rc1~114^2~148^2~3^2~2.
+ */
+ if (len <= offsetof(struct bpf_prog_info_struct, nr_jited_ksyms))
+ goto print_bpf_prog_info_end;
+
+ tprints(", nr_jited_ksyms=");
+ if (saved->nr_jited_ksyms != info.nr_jited_ksyms)
+ tprintf("%" PRIu32 " => ", saved->nr_jited_ksyms);
+ tprintf("%" PRIu32, info.nr_jited_ksyms);
+
+ tprints(", nr_jited_func_lens=");
+ if (saved->nr_jited_func_lens != info.nr_jited_func_lens)
+ tprintf("%" PRIu32 " => ", saved->nr_jited_func_lens);
+ tprintf("%" PRIu32, info.nr_jited_func_lens);
+
+ tprints(", jited_ksyms=");
+ if (saved->jited_ksyms != info.jited_ksyms) {
+ printaddr64(saved->jited_ksyms);
+ tprints(" => ");
+ }
+ printaddr64(info.jited_ksyms);
+
+ tprints(", jited_func_lens=");
+ if (saved->jited_func_lens != info.jited_func_lens) {
+ printaddr64(saved->jited_func_lens);
+ tprints(" => ");
+ }
+ printaddr64(info.jited_func_lens);
+
decode_attr_extra_data(tcp, info_buf, size, bpf_prog_info_struct_size);
print_bpf_prog_info_end:
Index: strace-4.24/bpf_attr.h
===================================================================
--- strace-4.24.orig/bpf_attr.h 2020-01-28 00:15:59.919446522 +0100
+++ strace-4.24/bpf_attr.h 2020-01-28 00:16:27.823183735 +0100
@@ -272,10 +272,14 @@
*/
uint64_t ATTRIBUTE_ALIGNED(8) netns_dev; /* skip check */
uint64_t ATTRIBUTE_ALIGNED(8) netns_ino; /* skip check */
+ uint32_t nr_jited_ksyms;
+ uint32_t nr_jited_func_lens;
+ uint64_t ATTRIBUTE_ALIGNED(8) jited_ksyms;
+ uint64_t ATTRIBUTE_ALIGNED(8) jited_func_lens;
};
# define bpf_prog_info_struct_size \
sizeof(struct bpf_prog_info_struct)
-# define expected_bpf_prog_info_struct_size 104
+# define expected_bpf_prog_info_struct_size 128
#endif /* !STRACE_BPF_ATTR_H */
Index: strace-4.24/tests/bpf-obj_get_info_by_fd.c
===================================================================
--- strace-4.24.orig/tests/bpf-obj_get_info_by_fd.c 2020-01-28 00:15:59.920446513 +0100
+++ strace-4.24/tests/bpf-obj_get_info_by_fd.c 2020-01-28 00:16:27.823183735 +0100
@@ -358,6 +358,8 @@
memset(prog_info, 0, PROG_INFO_SZ);
for (unsigned int i = 0; i < 4; i++) {
prog_info->jited_prog_len = 0;
+ prog_info->nr_jited_ksyms = 0;
+ prog_info->nr_jited_func_lens = 0;
memset(prog_info + 1, 0, PROG_INFO_SZ - sizeof(*prog_info));
switch (i) {
case 1:
@@ -485,6 +487,25 @@
offsetof(struct bpf_prog_info_struct, netns_ino))
printf(", netns_ino=%" PRIu64, prog_info->netns_ino);
+ if (bpf_prog_get_info_attr.info_len >
+ offsetof(struct bpf_prog_info_struct, nr_jited_ksyms)) {
+ printf(", nr_jited_ksyms=0");
+ if (prog_info->nr_jited_ksyms)
+ printf(" => %u", prog_info->nr_jited_ksyms);
+ }
+ if (bpf_prog_get_info_attr.info_len >
+ offsetof(struct bpf_prog_info_struct, nr_jited_func_lens)) {
+ printf(", nr_jited_func_lens=0");
+ if (prog_info->nr_jited_func_lens)
+ printf(" => %u", prog_info->nr_jited_func_lens);
+ }
+ if (bpf_prog_get_info_attr.info_len >
+ offsetof(struct bpf_prog_info_struct, jited_ksyms))
+ printf(", jited_ksyms=NULL");
+ if (bpf_prog_get_info_attr.info_len >
+ offsetof(struct bpf_prog_info_struct, jited_func_lens))
+ printf(", jited_func_lens=NULL");
+
printf("}");
# else /* !VERBOSE */
printf("%p", prog_info);
Index: strace-4.24/tests-m32/bpf-obj_get_info_by_fd.c
===================================================================
--- strace-4.24.orig/tests-m32/bpf-obj_get_info_by_fd.c 2020-01-28 00:16:14.855305862 +0100
+++ strace-4.24/tests-m32/bpf-obj_get_info_by_fd.c 2020-01-28 00:16:37.300094485 +0100
@@ -358,6 +358,8 @@
memset(prog_info, 0, PROG_INFO_SZ);
for (unsigned int i = 0; i < 4; i++) {
prog_info->jited_prog_len = 0;
+ prog_info->nr_jited_ksyms = 0;
+ prog_info->nr_jited_func_lens = 0;
memset(prog_info + 1, 0, PROG_INFO_SZ - sizeof(*prog_info));
switch (i) {
case 1:
@@ -485,6 +487,25 @@
offsetof(struct bpf_prog_info_struct, netns_ino))
printf(", netns_ino=%" PRIu64, prog_info->netns_ino);
+ if (bpf_prog_get_info_attr.info_len >
+ offsetof(struct bpf_prog_info_struct, nr_jited_ksyms)) {
+ printf(", nr_jited_ksyms=0");
+ if (prog_info->nr_jited_ksyms)
+ printf(" => %u", prog_info->nr_jited_ksyms);
+ }
+ if (bpf_prog_get_info_attr.info_len >
+ offsetof(struct bpf_prog_info_struct, nr_jited_func_lens)) {
+ printf(", nr_jited_func_lens=0");
+ if (prog_info->nr_jited_func_lens)
+ printf(" => %u", prog_info->nr_jited_func_lens);
+ }
+ if (bpf_prog_get_info_attr.info_len >
+ offsetof(struct bpf_prog_info_struct, jited_ksyms))
+ printf(", jited_ksyms=NULL");
+ if (bpf_prog_get_info_attr.info_len >
+ offsetof(struct bpf_prog_info_struct, jited_func_lens))
+ printf(", jited_func_lens=NULL");
+
printf("}");
# else /* !VERBOSE */
printf("%p", prog_info);
Index: strace-4.24/tests-mx32/bpf-obj_get_info_by_fd.c
===================================================================
--- strace-4.24.orig/tests-mx32/bpf-obj_get_info_by_fd.c 2020-01-28 00:16:23.096228252 +0100
+++ strace-4.24/tests-mx32/bpf-obj_get_info_by_fd.c 2020-01-28 00:16:34.082124791 +0100
@@ -358,6 +358,8 @@
memset(prog_info, 0, PROG_INFO_SZ);
for (unsigned int i = 0; i < 4; i++) {
prog_info->jited_prog_len = 0;
+ prog_info->nr_jited_ksyms = 0;
+ prog_info->nr_jited_func_lens = 0;
memset(prog_info + 1, 0, PROG_INFO_SZ - sizeof(*prog_info));
switch (i) {
case 1:
@@ -485,6 +487,25 @@
offsetof(struct bpf_prog_info_struct, netns_ino))
printf(", netns_ino=%" PRIu64, prog_info->netns_ino);
+ if (bpf_prog_get_info_attr.info_len >
+ offsetof(struct bpf_prog_info_struct, nr_jited_ksyms)) {
+ printf(", nr_jited_ksyms=0");
+ if (prog_info->nr_jited_ksyms)
+ printf(" => %u", prog_info->nr_jited_ksyms);
+ }
+ if (bpf_prog_get_info_attr.info_len >
+ offsetof(struct bpf_prog_info_struct, nr_jited_func_lens)) {
+ printf(", nr_jited_func_lens=0");
+ if (prog_info->nr_jited_func_lens)
+ printf(" => %u", prog_info->nr_jited_func_lens);
+ }
+ if (bpf_prog_get_info_attr.info_len >
+ offsetof(struct bpf_prog_info_struct, jited_ksyms))
+ printf(", jited_ksyms=NULL");
+ if (bpf_prog_get_info_attr.info_len >
+ offsetof(struct bpf_prog_info_struct, jited_func_lens))
+ printf(", jited_func_lens=NULL");
+
printf("}");
# else /* !VERBOSE */
printf("%p", prog_info);