Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 1639b17c authored by Andrii Nakryiko's avatar Andrii Nakryiko Committed by Daniel Borkmann
Browse files

selftests/bpf: convert legacy BPF maps to BTF-defined ones



Convert selftests that were originally left out and new ones added
recently to consistently use BTF-defined maps.

Reported-by: default avatarkernel test robot <rong.a.chen@intel.com>
Signed-off-by: default avatarAndrii Nakryiko <andriin@fb.com>
Acked-by: default avatarSong Liu <songliubraving@fb.com>
Acked-by: default avatarYonghong Song <yhs@fb.com>
Signed-off-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
parent bc7430cc
Loading
Loading
Loading
Loading
+13 −13
Original line number Diff line number Diff line
@@ -4,19 +4,19 @@
#include <linux/bpf.h>
#include "bpf_helpers.h"

struct bpf_map_def SEC("maps") cg_ids = {
	.type = BPF_MAP_TYPE_ARRAY,
	.key_size = sizeof(__u32),
	.value_size = sizeof(__u64),
	.max_entries = 1,
};

struct bpf_map_def SEC("maps") pidmap = {
	.type = BPF_MAP_TYPE_ARRAY,
	.key_size = sizeof(__u32),
	.value_size = sizeof(__u32),
	.max_entries = 1,
};
struct {
	__uint(type, BPF_MAP_TYPE_ARRAY);
	__uint(max_entries, 1);
	__type(key, __u32);
	__type(value, __u64);
} cg_ids SEC(".maps");

struct {
	__uint(type, BPF_MAP_TYPE_ARRAY);
	__uint(max_entries, 1);
	__type(key, __u32);
	__type(value, __u32);
} pidmap SEC(".maps");

SEC("tracepoint/syscalls/sys_enter_nanosleep")
int trace(void *ctx)
+41 −49
Original line number Diff line number Diff line
@@ -58,14 +58,6 @@ typedef struct {
} Event;


struct bpf_elf_map {
	__u32 type;
	__u32 size_key;
	__u32 size_value;
	__u32 max_elem;
	__u32 flags;
};

typedef int pid_t;

typedef struct {
@@ -118,47 +110,47 @@ static __always_inline bool get_frame_data(void *frame_ptr, PidData *pidData,
	return true;
}

struct bpf_elf_map SEC("maps") pidmap = {
	.type = BPF_MAP_TYPE_HASH,
	.size_key = sizeof(int),
	.size_value = sizeof(PidData),
	.max_elem = 1,
};

struct bpf_elf_map SEC("maps") eventmap = {
	.type = BPF_MAP_TYPE_HASH,
	.size_key = sizeof(int),
	.size_value = sizeof(Event),
	.max_elem = 1,
};

struct bpf_elf_map SEC("maps") symbolmap = {
	.type = BPF_MAP_TYPE_HASH,
	.size_key = sizeof(Symbol),
	.size_value = sizeof(int),
	.max_elem = 1,
};

struct bpf_elf_map SEC("maps") statsmap = {
	.type = BPF_MAP_TYPE_ARRAY,
	.size_key = sizeof(Stats),
	.size_value = sizeof(int),
	.max_elem = 1,
};

struct bpf_elf_map SEC("maps") perfmap = {
	.type = BPF_MAP_TYPE_PERF_EVENT_ARRAY,
	.size_key = sizeof(int),
	.size_value = sizeof(int),
	.max_elem = 32,
};

struct bpf_elf_map SEC("maps") stackmap = {
	.type = BPF_MAP_TYPE_STACK_TRACE,
	.size_key = sizeof(int),
	.size_value = sizeof(long long) * 127,
	.max_elem = 1000,
};
struct {
	__uint(type, BPF_MAP_TYPE_HASH);
	__uint(max_entries, 1);
	__type(key, int);
	__type(value, PidData);
} pidmap SEC(".maps");

struct {
	__uint(type, BPF_MAP_TYPE_HASH);
	__uint(max_entries, 1);
	__type(key, int);
	__type(value, Event);
} eventmap SEC(".maps");

struct {
	__uint(type, BPF_MAP_TYPE_HASH);
	__uint(max_entries, 1);
	__type(key, Symbol);
	__type(value, int);
} symbolmap SEC(".maps");

struct {
	__uint(type, BPF_MAP_TYPE_ARRAY);
	__uint(max_entries, 1);
	__type(key, int);
	__type(value, Stats);
} statsmap SEC(".maps");

struct {
	__uint(type, BPF_MAP_TYPE_PERF_EVENT_ARRAY);
	__uint(max_entries, 32);
	__uint(key_size, sizeof(int));
	__uint(value_size, sizeof(int));
} perfmap SEC(".maps");

struct {
	__uint(type, BPF_MAP_TYPE_STACK_TRACE);
	__uint(max_entries, 1000);
	__uint(key_size, sizeof(int));
	__uint(value_size, sizeof(long long) * 127);
} stackmap SEC(".maps");

static __always_inline int __on_event(struct pt_regs *ctx)
{
+24 −24
Original line number Diff line number Diff line
@@ -4,33 +4,33 @@

int _version SEC("version") = 1;

struct bpf_map_def SEC("maps") sock_map_rx = {
	.type = BPF_MAP_TYPE_SOCKMAP,
	.key_size = sizeof(int),
	.value_size = sizeof(int),
	.max_entries = 20,
};
struct {
	__uint(type, BPF_MAP_TYPE_SOCKMAP);
	__uint(max_entries, 20);
	__uint(key_size, sizeof(int));
	__uint(value_size, sizeof(int));
} sock_map_rx SEC(".maps");

struct bpf_map_def SEC("maps") sock_map_tx = {
	.type = BPF_MAP_TYPE_SOCKMAP,
	.key_size = sizeof(int),
	.value_size = sizeof(int),
	.max_entries = 20,
};
struct {
	__uint(type, BPF_MAP_TYPE_SOCKMAP);
	__uint(max_entries, 20);
	__uint(key_size, sizeof(int));
	__uint(value_size, sizeof(int));
} sock_map_tx SEC(".maps");

struct bpf_map_def SEC("maps") sock_map_msg = {
	.type = BPF_MAP_TYPE_SOCKMAP,
	.key_size = sizeof(int),
	.value_size = sizeof(int),
	.max_entries = 20,
};
struct {
	__uint(type, BPF_MAP_TYPE_SOCKMAP);
	__uint(max_entries, 20);
	__uint(key_size, sizeof(int));
	__uint(value_size, sizeof(int));
} sock_map_msg SEC(".maps");

struct bpf_map_def SEC("maps") sock_map_break = {
	.type = BPF_MAP_TYPE_ARRAY,
	.key_size = sizeof(int),
	.value_size = sizeof(int),
	.max_entries = 20,
};
struct {
	__uint(type, BPF_MAP_TYPE_ARRAY);
	__uint(max_entries, 20);
	__type(key, int);
	__type(value, int);
} sock_map_break SEC(".maps");

SEC("sk_skb2")
int bpf_prog2(struct __sk_buff *skb)
+34 −34
Original line number Diff line number Diff line
@@ -204,40 +204,40 @@ struct strobelight_bpf_sample {
	char dummy_safeguard;
};

struct bpf_map_def SEC("maps") samples = {
	.type = BPF_MAP_TYPE_PERF_EVENT_ARRAY,
	.key_size = sizeof(int),
	.value_size = sizeof(int),
	.max_entries = 32,
};
struct {
	__uint(type, BPF_MAP_TYPE_PERF_EVENT_ARRAY);
	__uint(max_entries, 32);
	__uint(key_size, sizeof(int));
	__uint(value_size, sizeof(int));
} samples SEC(".maps");

struct bpf_map_def SEC("maps") stacks_0 = {
	.type = BPF_MAP_TYPE_STACK_TRACE,
	.key_size = sizeof(uint32_t),
	.value_size = sizeof(uint64_t) * PERF_MAX_STACK_DEPTH,
	.max_entries = 16,
};
struct {
	__uint(type, BPF_MAP_TYPE_STACK_TRACE);
	__uint(max_entries, 16);
	__uint(key_size, sizeof(uint32_t));
	__uint(value_size, sizeof(uint64_t) * PERF_MAX_STACK_DEPTH);
} stacks_0 SEC(".maps");

struct bpf_map_def SEC("maps") stacks_1 = {
	.type = BPF_MAP_TYPE_STACK_TRACE,
	.key_size = sizeof(uint32_t),
	.value_size = sizeof(uint64_t) * PERF_MAX_STACK_DEPTH,
	.max_entries = 16,
};
struct {
	__uint(type, BPF_MAP_TYPE_STACK_TRACE);
	__uint(max_entries, 16);
	__uint(key_size, sizeof(uint32_t));
	__uint(value_size, sizeof(uint64_t) * PERF_MAX_STACK_DEPTH);
} stacks_1 SEC(".maps");

struct bpf_map_def SEC("maps") sample_heap = {
	.type = BPF_MAP_TYPE_PERCPU_ARRAY,
	.key_size = sizeof(uint32_t),
	.value_size = sizeof(struct strobelight_bpf_sample),
	.max_entries = 1,
};
struct {
	__uint(type, BPF_MAP_TYPE_PERCPU_ARRAY);
	__uint(max_entries, 1);
	__type(key, uint32_t);
	__type(value, struct strobelight_bpf_sample);
} sample_heap SEC(".maps");

struct bpf_map_def SEC("maps") strobemeta_cfgs = {
	.type = BPF_MAP_TYPE_PERCPU_ARRAY,
	.key_size = sizeof(pid_t),
	.value_size = sizeof(struct strobemeta_cfg),
	.max_entries = STROBE_MAX_CFGS,
};
struct {
	__uint(type, BPF_MAP_TYPE_PERCPU_ARRAY);
	__uint(max_entries, STROBE_MAX_CFGS);
	__type(key, pid_t);
	__type(value, struct strobemeta_cfg);
} strobemeta_cfgs SEC(".maps");

/* Type for the dtv.  */
/* https://github.com/lattera/glibc/blob/master/nptl/sysdeps/x86_64/tls.h#L34 */
+15 −15
Original line number Diff line number Diff line
@@ -5,23 +5,23 @@
#include <linux/types.h>
#include "bpf_helpers.h"

struct bpf_map_def SEC("maps") mim_array = {
	.type = BPF_MAP_TYPE_ARRAY_OF_MAPS,
	.key_size = sizeof(int),
struct {
	__uint(type, BPF_MAP_TYPE_ARRAY_OF_MAPS);
	__uint(max_entries, 1);
	__uint(map_flags, 0);
	__uint(key_size, sizeof(__u32));
	/* must be sizeof(__u32) for map in map */
	.value_size = sizeof(__u32),
	.max_entries = 1,
	.map_flags = 0,
};

struct bpf_map_def SEC("maps") mim_hash = {
	.type = BPF_MAP_TYPE_HASH_OF_MAPS,
	.key_size = sizeof(int),
	__uint(value_size, sizeof(__u32));
} mim_array SEC(".maps");

struct {
	__uint(type, BPF_MAP_TYPE_HASH_OF_MAPS);
	__uint(max_entries, 1);
	__uint(map_flags, 0);
	__uint(key_size, sizeof(int));
	/* must be sizeof(__u32) for map in map */
	.value_size = sizeof(__u32),
	.max_entries = 1,
	.map_flags = 0,
};
	__uint(value_size, sizeof(__u32));
} mim_hash SEC(".maps");

SEC("xdp_mimtest")
int xdp_mimtest0(struct xdp_md *ctx)
Loading