mirror of
https://gitee.com/bianbu-linux/linux-6.6
synced 2025-04-24 14:07:52 -04:00
Daniel Borkmann says: ==================== pull-request: bpf-next 2022-01-24 We've added 80 non-merge commits during the last 14 day(s) which contain a total of 128 files changed, 4990 insertions(+), 895 deletions(-). The main changes are: 1) Add XDP multi-buffer support and implement it for the mvneta driver, from Lorenzo Bianconi, Eelco Chaudron and Toke Høiland-Jørgensen. 2) Add unstable conntrack lookup helpers for BPF by using the BPF kfunc infra, from Kumar Kartikeya Dwivedi. 3) Extend BPF cgroup programs to export custom ret value to userspace via two helpers bpf_get_retval() and bpf_set_retval(), from YiFei Zhu. 4) Add support for AF_UNIX iterator batching, from Kuniyuki Iwashima. 5) Complete missing UAPI BPF helper description and change bpf_doc.py script to enforce consistent & complete helper documentation, from Usama Arif. 6) Deprecate libbpf's legacy BPF map definitions and streamline XDP APIs to follow tc-based APIs, from Andrii Nakryiko. 7) Support BPF_PROG_QUERY for BPF programs attached to sockmap, from Di Zhu. 8) Deprecate libbpf's bpf_map__def() API and replace users with proper getters and setters, from Christy Lee. 9) Extend libbpf's btf__add_btf() with an additional hashmap for strings to reduce overhead, from Kui-Feng Lee. 10) Fix bpftool and libbpf error handling related to libbpf's hashmap__new() utility function, from Mauricio Vásquez. 11) Add support to BTF program names in bpftool's program dump, from Raman Shukhau. 12) Fix resolve_btfids build to pick up host flags, from Connor O'Brien. * https://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf-next: (80 commits) selftests, bpf: Do not yet switch to new libbpf XDP APIs selftests, xsk: Fix rx_full stats test bpf: Fix flexible_array.cocci warnings xdp: disable XDP_REDIRECT for xdp frags bpf: selftests: add CPUMAP/DEVMAP selftests for xdp frags bpf: selftests: introduce bpf_xdp_{load,store}_bytes selftest net: xdp: introduce bpf_xdp_pointer utility routine bpf: generalise tail call map compatibility check libbpf: Add SEC name for xdp frags programs bpf: selftests: update xdp_adjust_tail selftest to include xdp frags bpf: test_run: add xdp_shared_info pointer in bpf_test_finish signature bpf: introduce frags support to bpf_prog_test_run_xdp() bpf: move user_size out of bpf_test_init bpf: add frags support to xdp copy helpers bpf: add frags support to the bpf_xdp_adjust_tail() API bpf: introduce bpf_xdp_get_buff_len helper net: mvneta: enable jumbo frames if the loaded XDP program support frags bpf: introduce BPF_F_XDP_HAS_FRAGS flag in prog_flags loading the ebpf program net: mvneta: add frags support to XDP_TX xdp: add frags support to xdp_return_{buff/frame} ... ==================== Link: https://lore.kernel.org/r/20220124221235.18993-1-daniel@iogearbox.net Signed-off-by: Jakub Kicinski <kuba@kernel.org>
This commit is contained in:
commit
caaba96131
128 changed files with 5000 additions and 905 deletions
|
@ -902,7 +902,7 @@ static int do_show(int argc, char **argv)
|
|||
equal_fn_for_key_as_id, NULL);
|
||||
btf_map_table = hashmap__new(hash_fn_for_key_as_id,
|
||||
equal_fn_for_key_as_id, NULL);
|
||||
if (!btf_prog_table || !btf_map_table) {
|
||||
if (IS_ERR(btf_prog_table) || IS_ERR(btf_map_table)) {
|
||||
hashmap__free(btf_prog_table);
|
||||
hashmap__free(btf_map_table);
|
||||
if (fd >= 0)
|
||||
|
|
|
@ -50,6 +50,7 @@ static int show_bpf_prog(int id, enum bpf_attach_type attach_type,
|
|||
const char *attach_flags_str,
|
||||
int level)
|
||||
{
|
||||
char prog_name[MAX_PROG_FULL_NAME];
|
||||
struct bpf_prog_info info = {};
|
||||
__u32 info_len = sizeof(info);
|
||||
int prog_fd;
|
||||
|
@ -63,6 +64,7 @@ static int show_bpf_prog(int id, enum bpf_attach_type attach_type,
|
|||
return -1;
|
||||
}
|
||||
|
||||
get_prog_full_name(&info, prog_fd, prog_name, sizeof(prog_name));
|
||||
if (json_output) {
|
||||
jsonw_start_object(json_wtr);
|
||||
jsonw_uint_field(json_wtr, "id", info.id);
|
||||
|
@ -73,7 +75,7 @@ static int show_bpf_prog(int id, enum bpf_attach_type attach_type,
|
|||
jsonw_uint_field(json_wtr, "attach_type", attach_type);
|
||||
jsonw_string_field(json_wtr, "attach_flags",
|
||||
attach_flags_str);
|
||||
jsonw_string_field(json_wtr, "name", info.name);
|
||||
jsonw_string_field(json_wtr, "name", prog_name);
|
||||
jsonw_end_object(json_wtr);
|
||||
} else {
|
||||
printf("%s%-8u ", level ? " " : "", info.id);
|
||||
|
@ -81,7 +83,7 @@ static int show_bpf_prog(int id, enum bpf_attach_type attach_type,
|
|||
printf("%-15s", attach_type_name[attach_type]);
|
||||
else
|
||||
printf("type %-10u", attach_type);
|
||||
printf(" %-15s %-15s\n", attach_flags_str, info.name);
|
||||
printf(" %-15s %-15s\n", attach_flags_str, prog_name);
|
||||
}
|
||||
|
||||
close(prog_fd);
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
#include <bpf/bpf.h>
|
||||
#include <bpf/hashmap.h>
|
||||
#include <bpf/libbpf.h> /* libbpf_num_possible_cpus */
|
||||
#include <bpf/btf.h>
|
||||
|
||||
#include "main.h"
|
||||
|
||||
|
@ -304,6 +305,49 @@ const char *get_fd_type_name(enum bpf_obj_type type)
|
|||
return names[type];
|
||||
}
|
||||
|
||||
void get_prog_full_name(const struct bpf_prog_info *prog_info, int prog_fd,
|
||||
char *name_buff, size_t buff_len)
|
||||
{
|
||||
const char *prog_name = prog_info->name;
|
||||
const struct btf_type *func_type;
|
||||
const struct bpf_func_info finfo;
|
||||
struct bpf_prog_info info = {};
|
||||
__u32 info_len = sizeof(info);
|
||||
struct btf *prog_btf = NULL;
|
||||
|
||||
if (buff_len <= BPF_OBJ_NAME_LEN ||
|
||||
strlen(prog_info->name) < BPF_OBJ_NAME_LEN - 1)
|
||||
goto copy_name;
|
||||
|
||||
if (!prog_info->btf_id || prog_info->nr_func_info == 0)
|
||||
goto copy_name;
|
||||
|
||||
info.nr_func_info = 1;
|
||||
info.func_info_rec_size = prog_info->func_info_rec_size;
|
||||
if (info.func_info_rec_size > sizeof(finfo))
|
||||
info.func_info_rec_size = sizeof(finfo);
|
||||
info.func_info = ptr_to_u64(&finfo);
|
||||
|
||||
if (bpf_obj_get_info_by_fd(prog_fd, &info, &info_len))
|
||||
goto copy_name;
|
||||
|
||||
prog_btf = btf__load_from_kernel_by_id(info.btf_id);
|
||||
if (!prog_btf)
|
||||
goto copy_name;
|
||||
|
||||
func_type = btf__type_by_id(prog_btf, finfo.type_id);
|
||||
if (!func_type || !btf_is_func(func_type))
|
||||
goto copy_name;
|
||||
|
||||
prog_name = btf__name_by_offset(prog_btf, func_type->name_off);
|
||||
|
||||
copy_name:
|
||||
snprintf(name_buff, buff_len, "%s", prog_name);
|
||||
|
||||
if (prog_btf)
|
||||
btf__free(prog_btf);
|
||||
}
|
||||
|
||||
int get_fd_type(int fd)
|
||||
{
|
||||
char path[PATH_MAX];
|
||||
|
|
|
@ -227,7 +227,7 @@ static int codegen_datasecs(struct bpf_object *obj, const char *obj_name)
|
|||
/* only generate definitions for memory-mapped internal maps */
|
||||
if (!bpf_map__is_internal(map))
|
||||
continue;
|
||||
if (!(bpf_map__def(map)->map_flags & BPF_F_MMAPABLE))
|
||||
if (!(bpf_map__map_flags(map) & BPF_F_MMAPABLE))
|
||||
continue;
|
||||
|
||||
if (!get_map_ident(map, map_ident, sizeof(map_ident)))
|
||||
|
@ -468,7 +468,7 @@ static void codegen_destroy(struct bpf_object *obj, const char *obj_name)
|
|||
if (!get_map_ident(map, ident, sizeof(ident)))
|
||||
continue;
|
||||
if (bpf_map__is_internal(map) &&
|
||||
(bpf_map__def(map)->map_flags & BPF_F_MMAPABLE))
|
||||
(bpf_map__map_flags(map) & BPF_F_MMAPABLE))
|
||||
printf("\tmunmap(skel->%1$s, %2$zd);\n",
|
||||
ident, bpf_map_mmap_sz(map));
|
||||
codegen("\
|
||||
|
@ -536,7 +536,7 @@ static int gen_trace(struct bpf_object *obj, const char *obj_name, const char *h
|
|||
continue;
|
||||
|
||||
if (!bpf_map__is_internal(map) ||
|
||||
!(bpf_map__def(map)->map_flags & BPF_F_MMAPABLE))
|
||||
!(bpf_map__map_flags(map) & BPF_F_MMAPABLE))
|
||||
continue;
|
||||
|
||||
codegen("\
|
||||
|
@ -600,10 +600,10 @@ static int gen_trace(struct bpf_object *obj, const char *obj_name, const char *h
|
|||
continue;
|
||||
|
||||
if (!bpf_map__is_internal(map) ||
|
||||
!(bpf_map__def(map)->map_flags & BPF_F_MMAPABLE))
|
||||
!(bpf_map__map_flags(map) & BPF_F_MMAPABLE))
|
||||
continue;
|
||||
|
||||
if (bpf_map__def(map)->map_flags & BPF_F_RDONLY_PROG)
|
||||
if (bpf_map__map_flags(map) & BPF_F_RDONLY_PROG)
|
||||
mmap_flags = "PROT_READ";
|
||||
else
|
||||
mmap_flags = "PROT_READ | PROT_WRITE";
|
||||
|
@ -927,7 +927,6 @@ static int do_skeleton(int argc, char **argv)
|
|||
s = (struct bpf_object_skeleton *)calloc(1, sizeof(*s));\n\
|
||||
if (!s) \n\
|
||||
goto err; \n\
|
||||
obj->skeleton = s; \n\
|
||||
\n\
|
||||
s->sz = sizeof(*s); \n\
|
||||
s->name = \"%1$s\"; \n\
|
||||
|
@ -962,7 +961,7 @@ static int do_skeleton(int argc, char **argv)
|
|||
i, bpf_map__name(map), i, ident);
|
||||
/* memory-mapped internal maps */
|
||||
if (bpf_map__is_internal(map) &&
|
||||
(bpf_map__def(map)->map_flags & BPF_F_MMAPABLE)) {
|
||||
(bpf_map__map_flags(map) & BPF_F_MMAPABLE)) {
|
||||
printf("\ts->maps[%zu].mmaped = (void **)&obj->%s;\n",
|
||||
i, ident);
|
||||
}
|
||||
|
@ -1000,6 +999,7 @@ static int do_skeleton(int argc, char **argv)
|
|||
\n\
|
||||
s->data = (void *)%2$s__elf_bytes(&s->data_sz); \n\
|
||||
\n\
|
||||
obj->skeleton = s; \n\
|
||||
return 0; \n\
|
||||
err: \n\
|
||||
bpf_object__destroy_skeleton(s); \n\
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
/* Copyright (C) 2020 Facebook */
|
||||
|
||||
#include <errno.h>
|
||||
#include <linux/err.h>
|
||||
#include <net/if.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
|
@ -306,7 +307,7 @@ static int do_show(int argc, char **argv)
|
|||
if (show_pinned) {
|
||||
link_table = hashmap__new(hash_fn_for_key_as_id,
|
||||
equal_fn_for_key_as_id, NULL);
|
||||
if (!link_table) {
|
||||
if (IS_ERR(link_table)) {
|
||||
p_err("failed to create hashmap for pinned paths");
|
||||
return -1;
|
||||
}
|
||||
|
|
|
@ -478,7 +478,14 @@ int main(int argc, char **argv)
|
|||
}
|
||||
|
||||
if (!legacy_libbpf) {
|
||||
ret = libbpf_set_strict_mode(LIBBPF_STRICT_ALL);
|
||||
enum libbpf_strict_mode mode;
|
||||
|
||||
/* Allow legacy map definitions for skeleton generation.
|
||||
* It will still be rejected if users use LIBBPF_STRICT_ALL
|
||||
* mode for loading generated skeleton.
|
||||
*/
|
||||
mode = (__LIBBPF_STRICT_LAST - 1) & ~LIBBPF_STRICT_MAP_DEFINITIONS;
|
||||
ret = libbpf_set_strict_mode(mode);
|
||||
if (ret)
|
||||
p_err("failed to enable libbpf strict mode: %d", ret);
|
||||
}
|
||||
|
|
|
@ -140,6 +140,10 @@ struct cmd {
|
|||
int cmd_select(const struct cmd *cmds, int argc, char **argv,
|
||||
int (*help)(int argc, char **argv));
|
||||
|
||||
#define MAX_PROG_FULL_NAME 128
|
||||
void get_prog_full_name(const struct bpf_prog_info *prog_info, int prog_fd,
|
||||
char *name_buff, size_t buff_len);
|
||||
|
||||
int get_fd_type(int fd);
|
||||
const char *get_fd_type_name(enum bpf_obj_type type);
|
||||
char *get_fdinfo(int fd, const char *key);
|
||||
|
|
|
@ -699,7 +699,7 @@ static int do_show(int argc, char **argv)
|
|||
if (show_pinned) {
|
||||
map_table = hashmap__new(hash_fn_for_key_as_id,
|
||||
equal_fn_for_key_as_id, NULL);
|
||||
if (!map_table) {
|
||||
if (IS_ERR(map_table)) {
|
||||
p_err("failed to create hashmap for pinned paths");
|
||||
return -1;
|
||||
}
|
||||
|
|
|
@ -551,7 +551,7 @@ static int do_attach_detach_xdp(int progfd, enum net_attach_type attach_type,
|
|||
if (attach_type == NET_ATTACH_TYPE_XDP_OFFLOAD)
|
||||
flags |= XDP_FLAGS_HW_MODE;
|
||||
|
||||
return bpf_set_link_xdp_fd(ifindex, progfd, flags);
|
||||
return bpf_xdp_attach(ifindex, progfd, flags, NULL);
|
||||
}
|
||||
|
||||
static int do_attach(int argc, char **argv)
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
// SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
|
||||
/* Copyright (C) 2020 Facebook */
|
||||
#include <errno.h>
|
||||
#include <linux/err.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
@ -101,7 +102,7 @@ int build_obj_refs_table(struct hashmap **map, enum bpf_obj_type type)
|
|||
libbpf_print_fn_t default_print;
|
||||
|
||||
*map = hashmap__new(hash_fn_for_key_as_id, equal_fn_for_key_as_id, NULL);
|
||||
if (!*map) {
|
||||
if (IS_ERR(*map)) {
|
||||
p_err("failed to create hashmap for PID references");
|
||||
return -1;
|
||||
}
|
||||
|
|
|
@ -424,8 +424,10 @@ out_free:
|
|||
free(value);
|
||||
}
|
||||
|
||||
static void print_prog_header_json(struct bpf_prog_info *info)
|
||||
static void print_prog_header_json(struct bpf_prog_info *info, int fd)
|
||||
{
|
||||
char prog_name[MAX_PROG_FULL_NAME];
|
||||
|
||||
jsonw_uint_field(json_wtr, "id", info->id);
|
||||
if (info->type < ARRAY_SIZE(prog_type_name))
|
||||
jsonw_string_field(json_wtr, "type",
|
||||
|
@ -433,8 +435,10 @@ static void print_prog_header_json(struct bpf_prog_info *info)
|
|||
else
|
||||
jsonw_uint_field(json_wtr, "type", info->type);
|
||||
|
||||
if (*info->name)
|
||||
jsonw_string_field(json_wtr, "name", info->name);
|
||||
if (*info->name) {
|
||||
get_prog_full_name(info, fd, prog_name, sizeof(prog_name));
|
||||
jsonw_string_field(json_wtr, "name", prog_name);
|
||||
}
|
||||
|
||||
jsonw_name(json_wtr, "tag");
|
||||
jsonw_printf(json_wtr, "\"" BPF_TAG_FMT "\"",
|
||||
|
@ -455,7 +459,7 @@ static void print_prog_json(struct bpf_prog_info *info, int fd)
|
|||
char *memlock;
|
||||
|
||||
jsonw_start_object(json_wtr);
|
||||
print_prog_header_json(info);
|
||||
print_prog_header_json(info, fd);
|
||||
print_dev_json(info->ifindex, info->netns_dev, info->netns_ino);
|
||||
|
||||
if (info->load_time) {
|
||||
|
@ -507,16 +511,20 @@ static void print_prog_json(struct bpf_prog_info *info, int fd)
|
|||
jsonw_end_object(json_wtr);
|
||||
}
|
||||
|
||||
static void print_prog_header_plain(struct bpf_prog_info *info)
|
||||
static void print_prog_header_plain(struct bpf_prog_info *info, int fd)
|
||||
{
|
||||
char prog_name[MAX_PROG_FULL_NAME];
|
||||
|
||||
printf("%u: ", info->id);
|
||||
if (info->type < ARRAY_SIZE(prog_type_name))
|
||||
printf("%s ", prog_type_name[info->type]);
|
||||
else
|
||||
printf("type %u ", info->type);
|
||||
|
||||
if (*info->name)
|
||||
printf("name %s ", info->name);
|
||||
if (*info->name) {
|
||||
get_prog_full_name(info, fd, prog_name, sizeof(prog_name));
|
||||
printf("name %s ", prog_name);
|
||||
}
|
||||
|
||||
printf("tag ");
|
||||
fprint_hex(stdout, info->tag, BPF_TAG_SIZE, "");
|
||||
|
@ -534,7 +542,7 @@ static void print_prog_plain(struct bpf_prog_info *info, int fd)
|
|||
{
|
||||
char *memlock;
|
||||
|
||||
print_prog_header_plain(info);
|
||||
print_prog_header_plain(info, fd);
|
||||
|
||||
if (info->load_time) {
|
||||
char buf[32];
|
||||
|
@ -641,7 +649,7 @@ static int do_show(int argc, char **argv)
|
|||
if (show_pinned) {
|
||||
prog_table = hashmap__new(hash_fn_for_key_as_id,
|
||||
equal_fn_for_key_as_id, NULL);
|
||||
if (!prog_table) {
|
||||
if (IS_ERR(prog_table)) {
|
||||
p_err("failed to create hashmap for pinned paths");
|
||||
return -1;
|
||||
}
|
||||
|
@ -972,10 +980,10 @@ static int do_dump(int argc, char **argv)
|
|||
|
||||
if (json_output && nb_fds > 1) {
|
||||
jsonw_start_object(json_wtr); /* prog object */
|
||||
print_prog_header_json(&info);
|
||||
print_prog_header_json(&info, fds[i]);
|
||||
jsonw_name(json_wtr, "insns");
|
||||
} else if (nb_fds > 1) {
|
||||
print_prog_header_plain(&info);
|
||||
print_prog_header_plain(&info, fds[i]);
|
||||
}
|
||||
|
||||
err = prog_dump(&info, mode, filepath, opcodes, visual, linum);
|
||||
|
|
|
@ -480,7 +480,6 @@ static int do_unregister(int argc, char **argv)
|
|||
static int do_register(int argc, char **argv)
|
||||
{
|
||||
LIBBPF_OPTS(bpf_object_open_opts, open_opts);
|
||||
const struct bpf_map_def *def;
|
||||
struct bpf_map_info info = {};
|
||||
__u32 info_len = sizeof(info);
|
||||
int nr_errs = 0, nr_maps = 0;
|
||||
|
@ -510,8 +509,7 @@ static int do_register(int argc, char **argv)
|
|||
}
|
||||
|
||||
bpf_object__for_each_map(map, obj) {
|
||||
def = bpf_map__def(map);
|
||||
if (def->type != BPF_MAP_TYPE_STRUCT_OPS)
|
||||
if (bpf_map__type(map) != BPF_MAP_TYPE_STRUCT_OPS)
|
||||
continue;
|
||||
|
||||
link = bpf_map__attach_struct_ops(map);
|
||||
|
|
|
@ -20,6 +20,8 @@ LD = $(HOSTLD)
|
|||
ARCH = $(HOSTARCH)
|
||||
RM ?= rm
|
||||
CROSS_COMPILE =
|
||||
CFLAGS := $(KBUILD_HOSTCFLAGS)
|
||||
LDFLAGS := $(KBUILD_HOSTLDFLAGS)
|
||||
|
||||
OUTPUT ?= $(srctree)/tools/bpf/resolve_btfids/
|
||||
|
||||
|
@ -47,10 +49,10 @@ $(SUBCMDOBJ): fixdep FORCE | $(OUTPUT)/libsubcmd
|
|||
|
||||
$(BPFOBJ): $(wildcard $(LIBBPF_SRC)/*.[ch] $(LIBBPF_SRC)/Makefile) | $(LIBBPF_OUT)
|
||||
$(Q)$(MAKE) $(submake_extras) -C $(LIBBPF_SRC) OUTPUT=$(LIBBPF_OUT) \
|
||||
DESTDIR=$(LIBBPF_DESTDIR) prefix= \
|
||||
DESTDIR=$(LIBBPF_DESTDIR) prefix= EXTRA_CFLAGS="$(CFLAGS)" \
|
||||
$(abspath $@) install_headers
|
||||
|
||||
CFLAGS := -g \
|
||||
CFLAGS += -g \
|
||||
-I$(srctree)/tools/include \
|
||||
-I$(srctree)/tools/include/uapi \
|
||||
-I$(LIBBPF_INCLUDE) \
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue