return true;
}
-void
-print_ebpf_prog(struct tcb *const tcp, const kernel_ulong_t addr,
- const uint32_t len)
+static void
+print_ebpf_prog(struct tcb *const tcp, const uint64_t addr, const uint32_t len)
{
+ print_big_u64_addr(addr);
if (abbrev(tcp)) {
printaddr(addr);
} else {
struct ebpf_insn insn;
print_array(tcp, addr, len, &insn, sizeof(insn),
- umoven_or_printaddr, print_ebpf_insn, &eid);
+ tfetch_mem, print_ebpf_insn, &eid);
}
}
"BPF_PROG_TYPE_???");
PRINT_FIELD_U(", ", attr, insn_cnt);
tprints(", insns=");
- print_big_u64_addr(attr.insns);
print_ebpf_prog(tcp, attr.insns, attr.insn_cnt);
tprintf(", license=");
break;
PRINT_FIELD_U(", ", attr, log_level);
PRINT_FIELD_U(", ", attr, log_size);
- PRINT_FIELD_ADDR64(", ", attr, log_buf);
+ tprintf(", log_buf=");
+ print_big_u64_addr(attr.log_buf);
+ printstr_ex(tcp, attr.log_buf, attr.log_size, QUOTE_0_TERMINATED);
/* kern_version field was added in Linux commit v4.1-rc1~84^2~50. */
if (len <= offsetof(struct BPF_PROG_LOAD_struct, kern_version))
}
END_BPF_CMD_DECODER(RVAL_DECODED)
+struct obj_get_info_saved;
+typedef void (*print_bpf_obj_info_fn)(struct tcb *,
+ uint32_t bpf_fd,
+ const char *info_buf,
+ uint32_t size,
+ struct obj_get_info_saved *saved);
+
+struct obj_get_info_saved {
+ print_bpf_obj_info_fn print_fn;
+
+ uint32_t info_len;
+
+ uint32_t jited_prog_len;
+ uint32_t xlated_prog_len;
+ uint32_t nr_map_ids;
+};
+
+static void
+print_bpf_map_info(struct tcb * const tcp, uint32_t bpf_fd,
+ const char *info_buf, uint32_t size,
+ struct obj_get_info_saved *saved)
+{
+ if (entering(tcp))
+ return;
+
+ struct bpf_map_info_struct info = { 0 };
+ const unsigned int len = MIN(size, bpf_map_info_struct_size);
+
+ memcpy(&info, info_buf, len);
+
+ PRINT_FIELD_XVAL("{", info, type, bpf_map_types, "BPF_MAP_TYPE_???");
+ PRINT_FIELD_U(", ", info, id);
+ PRINT_FIELD_U(", ", info, key_size);
+ PRINT_FIELD_U(", ", info, value_size);
+ PRINT_FIELD_U(", ", info, max_entries);
+ PRINT_FIELD_FLAGS(", ", info, map_flags, bpf_map_flags, "BPF_F_???");
+
+ /*
+ * "name" field was introduced by Linux commit v4.15-rc1~84^2~605^2~3.
+ */
+ if (len <= offsetof(struct bpf_map_info_struct, name))
+ goto print_bpf_map_info_end;
+ PRINT_FIELD_CSTRING(", ", info, name);
+
+ /*
+ * ifindex, netns_dev, and netns_ino fields were introduced
+ * by Linux commit v4.16-rc1~123^2~109^2~5^2~4.
+ */
+ if (len <= offsetof(struct bpf_map_info_struct, ifindex))
+ goto print_bpf_map_info_end;
+ PRINT_FIELD_IFINDEX(", ", info, ifindex);
+ PRINT_FIELD_DEV(", ", info, netns_dev);
+ PRINT_FIELD_U(", ", info, netns_ino);
+
+ decode_attr_extra_data(tcp, info_buf, size, bpf_map_info_struct_size);
+
+print_bpf_map_info_end:
+ tprints("}");
+}
+
+static void
+print_bpf_prog_info(struct tcb * const tcp, uint32_t bpf_fd,
+ const char *info_buf, uint32_t size,
+ struct obj_get_info_saved *saved)
+{
+ struct bpf_prog_info_struct info = { 0 };
+ const unsigned int len = MIN(size, bpf_prog_info_struct_size);
+ uint64_t map_id_buf;
+
+ memcpy(&info, info_buf, len);
+
+ if (entering(tcp)) {
+ saved->jited_prog_len = info.jited_prog_len;
+ saved->xlated_prog_len = info.xlated_prog_len;
+ saved->nr_map_ids = info.nr_map_ids;
+
+ return;
+ }
+
+ PRINT_FIELD_XVAL("{", info, type, bpf_prog_types, "BPF_PROG_TYPE_???");
+ PRINT_FIELD_U(", ", info, id);
+ PRINT_FIELD_HEX_ARRAY(", ", info, tag);
+
+ tprints(", jited_prog_len=");
+ if (saved->jited_prog_len != info.jited_prog_len)
+ tprintf("%" PRIu32 " => ", saved->jited_prog_len);
+ tprintf("%" PRIu32, info.jited_prog_len);
+
+ tprints(", jited_prog_insns=");
+ print_big_u64_addr(info.jited_prog_insns);
+ printstr_ex(tcp, info.jited_prog_insns, info.jited_prog_len,
+ QUOTE_FORCE_HEX);
+
+ tprints(", xlated_prog_len=");
+ if (saved->xlated_prog_len != info.xlated_prog_len)
+ tprintf("%" PRIu32 " => ", saved->xlated_prog_len);
+ tprintf("%" PRIu32, info.xlated_prog_len);
+
+ tprints(", xlated_prog_insns=");
+ print_ebpf_prog(tcp, info.xlated_prog_insns,
+ MIN(saved->xlated_prog_len, info.xlated_prog_len) / 8);
+
+ /*
+ * load_time, created_by_uid, nr_map_ids, map_ids, and name fields
+ * were introduced by Linux commit v4.15-rc1~84^2~605^2~4.
+ */
+ if (len <= offsetof(struct bpf_prog_info_struct, load_time))
+ goto print_bpf_prog_info_end;
+ PRINT_FIELD_U(", ", info, load_time);
+ PRINT_FIELD_UID(", ", info, created_by_uid);
+
+ tprints(", nr_map_ids=");
+ if (saved->nr_map_ids != info.nr_map_ids)
+ tprintf("%" PRIu32 " => ", saved->nr_map_ids);
+ tprintf("%" PRIu32, info.nr_map_ids);
+
+ tprints(", map_ids=");
+ print_big_u64_addr(info.map_ids);
+ print_array(tcp, info.map_ids, MIN(saved->nr_map_ids, info.nr_map_ids),
+ &map_id_buf, sizeof(map_id_buf),
+ tfetch_mem, print_uint32_array_member, 0);
+
+ PRINT_FIELD_CSTRING(", ", info, name);
+
+ /*
+ * ifindex, netns_dev, and netns_ino fields were introduced
+ * by Linux commit v4.16-rc1~123^2~227^2~5^2~2.
+ */
+ if (len <= offsetof(struct bpf_prog_info_struct, ifindex))
+ goto print_bpf_prog_info_end;
+ PRINT_FIELD_IFINDEX(", ", info, ifindex);
+ PRINT_FIELD_DEV(", ", info, netns_dev);
+ PRINT_FIELD_U(", ", info, netns_ino);
+
+ decode_attr_extra_data(tcp, info_buf, size, bpf_prog_info_struct_size);
+
+print_bpf_prog_info_end:
+ tprints("}");
+}
+
+static const char *
+fetch_bpf_obj_info(struct tcb * const tcp, uint64_t info, uint32_t size)
+{
+ static char *info_buf;
+
+ if (!info_buf)
+ info_buf = xmalloc(get_pagesize());
+
+ memset(info_buf, 0, get_pagesize());
+
+ if (size > 0 && size <= get_pagesize()
+ && !umoven(tcp, info, size, info_buf))
+ return info_buf;
+
+ return NULL;
+}
+
+static void
+print_bpf_obj_info_addr(struct tcb * const tcp, uint64_t addr)
+{
+ if (exiting(tcp))
+ printaddr64(addr);
+}
+
+static void
+print_bpf_obj_info(struct tcb * const tcp, uint32_t bpf_fd, uint64_t info,
+ uint32_t size, struct obj_get_info_saved *saved)
+{
+ if (abbrev(tcp)) {
+ print_bpf_obj_info_addr(tcp, info);
+ return;
+ }
+
+ static struct {
+ const char *id;
+ print_bpf_obj_info_fn print_fn;
+ } obj_printers[] = {
+ { "anon_inode:bpf-map", print_bpf_map_info },
+ { "anon_inode:bpf-prog", print_bpf_prog_info }
+ };
+
+ if (entering(tcp)) {
+ char path[PATH_MAX + 1];
+
+ if (getfdpath(tcp, bpf_fd, path, sizeof(path)) > 0) {
+ for (size_t i = 0; i < ARRAY_SIZE(obj_printers); ++i) {
+ if (!strcmp(path, obj_printers[i].id)) {
+ saved->print_fn =
+ obj_printers[i].print_fn;
+ break;
+ }
+ }
+ }
+ }
+
+ if (!saved || !saved->print_fn) {
+ print_bpf_obj_info_addr(tcp, info);
+ return;
+ }
+
+ const char *info_buf = fetch_bpf_obj_info(tcp, info, size);
+
+ if (info_buf)
+ saved->print_fn(tcp, bpf_fd, info_buf, size, saved);
+ else
+ print_bpf_obj_info_addr(tcp, info);
+}
+
BEGIN_BPF_CMD_DECODER(BPF_OBJ_GET_INFO_BY_FD)
{
- PRINT_FIELD_FD("{info={", attr, bpf_fd, tcp);
- PRINT_FIELD_U(", ", attr, info_len);
- PRINT_FIELD_X(", ", attr, info);
+ struct obj_get_info_saved *saved;
+
+ if (entering(tcp)) {
+ saved = xcalloc(1, sizeof(*saved));
+ saved->info_len = attr.info_len;
+ set_tcb_priv_data(tcp, saved, free);
+
+ PRINT_FIELD_FD("{info={", attr, bpf_fd, tcp);
+ PRINT_FIELD_U(", ", attr, info_len);
+ } else {
+ saved = get_tcb_priv_data(tcp);
+
+ if (saved && (saved->info_len != attr.info_len))
+ tprintf(" => %u", attr.info_len);
+
+ tprintf(", info=");
+ }
+
+ print_bpf_obj_info(tcp, attr.bpf_fd, attr.info, attr.info_len, saved);
+
+ if (entering(tcp))
+ return 0;
+
tprints("}");
}
-END_BPF_CMD_DECODER(RVAL_DECODED | RVAL_FD)
+END_BPF_CMD_DECODER(RVAL_DECODED)
BEGIN_BPF_CMD_DECODER(BPF_PROG_QUERY)
{
print_big_u64_addr(attr.prog_ids);
print_array(tcp, attr.prog_ids, attr.prog_cnt, &prog_id_buf,
- sizeof(prog_id_buf), umoven_or_printaddr,
+ sizeof(prog_id_buf), tfetch_mem,
print_uint32_array_member, 0);
tprints(", prog_cnt=");