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

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
...@@ -4,19 +4,19 @@ ...@@ -4,19 +4,19 @@
#include <linux/bpf.h> #include <linux/bpf.h>
#include "bpf_helpers.h" #include "bpf_helpers.h"
struct bpf_map_def SEC("maps") cg_ids = { struct {
.type = BPF_MAP_TYPE_ARRAY, __uint(type, BPF_MAP_TYPE_ARRAY);
.key_size = sizeof(__u32), __uint(max_entries, 1);
.value_size = sizeof(__u64), __type(key, __u32);
.max_entries = 1, __type(value, __u64);
}; } cg_ids SEC(".maps");
struct bpf_map_def SEC("maps") pidmap = { struct {
.type = BPF_MAP_TYPE_ARRAY, __uint(type, BPF_MAP_TYPE_ARRAY);
.key_size = sizeof(__u32), __uint(max_entries, 1);
.value_size = sizeof(__u32), __type(key, __u32);
.max_entries = 1, __type(value, __u32);
}; } pidmap SEC(".maps");
SEC("tracepoint/syscalls/sys_enter_nanosleep") SEC("tracepoint/syscalls/sys_enter_nanosleep")
int trace(void *ctx) int trace(void *ctx)
......
...@@ -58,14 +58,6 @@ typedef struct { ...@@ -58,14 +58,6 @@ typedef struct {
} Event; } Event;
struct bpf_elf_map {
__u32 type;
__u32 size_key;
__u32 size_value;
__u32 max_elem;
__u32 flags;
};
typedef int pid_t; typedef int pid_t;
typedef struct { typedef struct {
...@@ -118,47 +110,47 @@ static __always_inline bool get_frame_data(void *frame_ptr, PidData *pidData, ...@@ -118,47 +110,47 @@ static __always_inline bool get_frame_data(void *frame_ptr, PidData *pidData,
return true; return true;
} }
struct bpf_elf_map SEC("maps") pidmap = { struct {
.type = BPF_MAP_TYPE_HASH, __uint(type, BPF_MAP_TYPE_HASH);
.size_key = sizeof(int), __uint(max_entries, 1);
.size_value = sizeof(PidData), __type(key, int);
.max_elem = 1, __type(value, PidData);
}; } pidmap SEC(".maps");
struct bpf_elf_map SEC("maps") eventmap = { struct {
.type = BPF_MAP_TYPE_HASH, __uint(type, BPF_MAP_TYPE_HASH);
.size_key = sizeof(int), __uint(max_entries, 1);
.size_value = sizeof(Event), __type(key, int);
.max_elem = 1, __type(value, Event);
}; } eventmap SEC(".maps");
struct bpf_elf_map SEC("maps") symbolmap = { struct {
.type = BPF_MAP_TYPE_HASH, __uint(type, BPF_MAP_TYPE_HASH);
.size_key = sizeof(Symbol), __uint(max_entries, 1);
.size_value = sizeof(int), __type(key, Symbol);
.max_elem = 1, __type(value, int);
}; } symbolmap SEC(".maps");
struct bpf_elf_map SEC("maps") statsmap = { struct {
.type = BPF_MAP_TYPE_ARRAY, __uint(type, BPF_MAP_TYPE_ARRAY);
.size_key = sizeof(Stats), __uint(max_entries, 1);
.size_value = sizeof(int), __type(key, int);
.max_elem = 1, __type(value, Stats);
}; } statsmap SEC(".maps");
struct bpf_elf_map SEC("maps") perfmap = { struct {
.type = BPF_MAP_TYPE_PERF_EVENT_ARRAY, __uint(type, BPF_MAP_TYPE_PERF_EVENT_ARRAY);
.size_key = sizeof(int), __uint(max_entries, 32);
.size_value = sizeof(int), __uint(key_size, sizeof(int));
.max_elem = 32, __uint(value_size, sizeof(int));
}; } perfmap SEC(".maps");
struct bpf_elf_map SEC("maps") stackmap = { struct {
.type = BPF_MAP_TYPE_STACK_TRACE, __uint(type, BPF_MAP_TYPE_STACK_TRACE);
.size_key = sizeof(int), __uint(max_entries, 1000);
.size_value = sizeof(long long) * 127, __uint(key_size, sizeof(int));
.max_elem = 1000, __uint(value_size, sizeof(long long) * 127);
}; } stackmap SEC(".maps");
static __always_inline int __on_event(struct pt_regs *ctx) static __always_inline int __on_event(struct pt_regs *ctx)
{ {
......
...@@ -4,33 +4,33 @@ ...@@ -4,33 +4,33 @@
int _version SEC("version") = 1; int _version SEC("version") = 1;
struct bpf_map_def SEC("maps") sock_map_rx = { struct {
.type = BPF_MAP_TYPE_SOCKMAP, __uint(type, BPF_MAP_TYPE_SOCKMAP);
.key_size = sizeof(int), __uint(max_entries, 20);
.value_size = sizeof(int), __uint(key_size, sizeof(int));
.max_entries = 20, __uint(value_size, sizeof(int));
}; } sock_map_rx SEC(".maps");
struct bpf_map_def SEC("maps") sock_map_tx = { struct {
.type = BPF_MAP_TYPE_SOCKMAP, __uint(type, BPF_MAP_TYPE_SOCKMAP);
.key_size = sizeof(int), __uint(max_entries, 20);
.value_size = sizeof(int), __uint(key_size, sizeof(int));
.max_entries = 20, __uint(value_size, sizeof(int));
}; } sock_map_tx SEC(".maps");
struct bpf_map_def SEC("maps") sock_map_msg = { struct {
.type = BPF_MAP_TYPE_SOCKMAP, __uint(type, BPF_MAP_TYPE_SOCKMAP);
.key_size = sizeof(int), __uint(max_entries, 20);
.value_size = sizeof(int), __uint(key_size, sizeof(int));
.max_entries = 20, __uint(value_size, sizeof(int));
}; } sock_map_msg SEC(".maps");
struct bpf_map_def SEC("maps") sock_map_break = { struct {
.type = BPF_MAP_TYPE_ARRAY, __uint(type, BPF_MAP_TYPE_ARRAY);
.key_size = sizeof(int), __uint(max_entries, 20);
.value_size = sizeof(int), __type(key, int);
.max_entries = 20, __type(value, int);
}; } sock_map_break SEC(".maps");
SEC("sk_skb2") SEC("sk_skb2")
int bpf_prog2(struct __sk_buff *skb) int bpf_prog2(struct __sk_buff *skb)
......
...@@ -204,40 +204,40 @@ struct strobelight_bpf_sample { ...@@ -204,40 +204,40 @@ struct strobelight_bpf_sample {
char dummy_safeguard; char dummy_safeguard;
}; };
struct bpf_map_def SEC("maps") samples = { struct {
.type = BPF_MAP_TYPE_PERF_EVENT_ARRAY, __uint(type, BPF_MAP_TYPE_PERF_EVENT_ARRAY);
.key_size = sizeof(int), __uint(max_entries, 32);
.value_size = sizeof(int), __uint(key_size, sizeof(int));
.max_entries = 32, __uint(value_size, sizeof(int));
}; } samples SEC(".maps");
struct bpf_map_def SEC("maps") stacks_0 = { struct {
.type = BPF_MAP_TYPE_STACK_TRACE, __uint(type, BPF_MAP_TYPE_STACK_TRACE);
.key_size = sizeof(uint32_t), __uint(max_entries, 16);
.value_size = sizeof(uint64_t) * PERF_MAX_STACK_DEPTH, __uint(key_size, sizeof(uint32_t));
.max_entries = 16, __uint(value_size, sizeof(uint64_t) * PERF_MAX_STACK_DEPTH);
}; } stacks_0 SEC(".maps");
struct bpf_map_def SEC("maps") stacks_1 = { struct {
.type = BPF_MAP_TYPE_STACK_TRACE, __uint(type, BPF_MAP_TYPE_STACK_TRACE);
.key_size = sizeof(uint32_t), __uint(max_entries, 16);
.value_size = sizeof(uint64_t) * PERF_MAX_STACK_DEPTH, __uint(key_size, sizeof(uint32_t));
.max_entries = 16, __uint(value_size, sizeof(uint64_t) * PERF_MAX_STACK_DEPTH);
}; } stacks_1 SEC(".maps");
struct bpf_map_def SEC("maps") sample_heap = { struct {
.type = BPF_MAP_TYPE_PERCPU_ARRAY, __uint(type, BPF_MAP_TYPE_PERCPU_ARRAY);
.key_size = sizeof(uint32_t), __uint(max_entries, 1);
.value_size = sizeof(struct strobelight_bpf_sample), __type(key, uint32_t);
.max_entries = 1, __type(value, struct strobelight_bpf_sample);
}; } sample_heap SEC(".maps");
struct bpf_map_def SEC("maps") strobemeta_cfgs = { struct {
.type = BPF_MAP_TYPE_PERCPU_ARRAY, __uint(type, BPF_MAP_TYPE_PERCPU_ARRAY);
.key_size = sizeof(pid_t), __uint(max_entries, STROBE_MAX_CFGS);
.value_size = sizeof(struct strobemeta_cfg), __type(key, pid_t);
.max_entries = STROBE_MAX_CFGS, __type(value, struct strobemeta_cfg);
}; } strobemeta_cfgs SEC(".maps");
/* Type for the dtv. */ /* Type for the dtv. */
/* https://github.com/lattera/glibc/blob/master/nptl/sysdeps/x86_64/tls.h#L34 */ /* https://github.com/lattera/glibc/blob/master/nptl/sysdeps/x86_64/tls.h#L34 */
......
...@@ -5,23 +5,23 @@ ...@@ -5,23 +5,23 @@
#include <linux/types.h> #include <linux/types.h>
#include "bpf_helpers.h" #include "bpf_helpers.h"
struct bpf_map_def SEC("maps") mim_array = { struct {
.type = BPF_MAP_TYPE_ARRAY_OF_MAPS, __uint(type, BPF_MAP_TYPE_ARRAY_OF_MAPS);
.key_size = sizeof(int), __uint(max_entries, 1);
__uint(map_flags, 0);
__uint(key_size, sizeof(__u32));
/* must be sizeof(__u32) for map in map */ /* must be sizeof(__u32) for map in map */
.value_size = sizeof(__u32), __uint(value_size, sizeof(__u32));
.max_entries = 1, } mim_array SEC(".maps");
.map_flags = 0,
}; struct {
__uint(type, BPF_MAP_TYPE_HASH_OF_MAPS);
struct bpf_map_def SEC("maps") mim_hash = { __uint(max_entries, 1);
.type = BPF_MAP_TYPE_HASH_OF_MAPS, __uint(map_flags, 0);
.key_size = sizeof(int), __uint(key_size, sizeof(int));
/* must be sizeof(__u32) for map in map */ /* must be sizeof(__u32) for map in map */
.value_size = sizeof(__u32), __uint(value_size, sizeof(__u32));
.max_entries = 1, } mim_hash SEC(".maps");
.map_flags = 0,
};
SEC("xdp_mimtest") SEC("xdp_mimtest")
int xdp_mimtest0(struct xdp_md *ctx) int xdp_mimtest0(struct xdp_md *ctx)
......
...@@ -13,12 +13,12 @@ ...@@ -13,12 +13,12 @@
int _version SEC("version") = 1; int _version SEC("version") = 1;
struct bpf_map_def SEC("maps") test_map_id = { struct {
.type = BPF_MAP_TYPE_ARRAY, __uint(type, BPF_MAP_TYPE_ARRAY);
.key_size = sizeof(__u32), __uint(max_entries, 1);
.value_size = sizeof(__u64), __type(key, __u32);
.max_entries = 1, __type(value, __u64);
}; } test_map_id SEC(".maps");
SEC("test_obj_id_dummy") SEC("test_obj_id_dummy")
int test_obj_id(struct __sk_buff *skb) int test_obj_id(struct __sk_buff *skb)
......
...@@ -18,19 +18,19 @@ ...@@ -18,19 +18,19 @@
int _version SEC("version") = 1; int _version SEC("version") = 1;
struct bpf_map_def SEC("maps") rxcnt = { struct {
.type = BPF_MAP_TYPE_PERCPU_ARRAY, __uint(type, BPF_MAP_TYPE_PERCPU_ARRAY);
.key_size = sizeof(__u32), __uint(max_entries, 256);
.value_size = sizeof(__u64), __type(key, __u32);
.max_entries = 256, __type(value, __u64);
}; } rxcnt SEC(".maps");
struct bpf_map_def SEC("maps") vip2tnl = { struct {
.type = BPF_MAP_TYPE_HASH, __uint(type, BPF_MAP_TYPE_HASH);
.key_size = sizeof(struct vip), __uint(max_entries, MAX_IPTNL_ENTRIES);
.value_size = sizeof(struct iptnl_info), __type(key, struct vip);
.max_entries = MAX_IPTNL_ENTRIES, __type(value, struct iptnl_info);
}; } vip2tnl SEC(".maps");
static __always_inline void count_tx(__u32 protocol) static __always_inline void count_tx(__u32 protocol)
{ {
......
...@@ -3,12 +3,12 @@ ...@@ -3,12 +3,12 @@
#include <linux/bpf.h> #include <linux/bpf.h>
#include "bpf_helpers.h" #include "bpf_helpers.h"
struct bpf_map_def SEC("maps") tx_port = { struct {
.type = BPF_MAP_TYPE_DEVMAP, __uint(type, BPF_MAP_TYPE_DEVMAP);
.key_size = sizeof(int), __uint(max_entries, 8);
.value_size = sizeof(int), __uint(key_size, sizeof(int));
.max_entries = 8, __uint(value_size, sizeof(int));
}; } tx_port SEC(".maps");
SEC("redirect_map_0") SEC("redirect_map_0")
int xdp_redirect_map_0(struct xdp_md *xdp) int xdp_redirect_map_0(struct xdp_md *xdp)
......
...@@ -17,12 +17,12 @@ ...@@ -17,12 +17,12 @@
#include "xdping.h" #include "xdping.h"
struct bpf_map_def SEC("maps") ping_map = { struct {
.type = BPF_MAP_TYPE_HASH, __uint(type, BPF_MAP_TYPE_HASH);
.key_size = sizeof(__u32), __uint(max_entries, 256);
.value_size = sizeof(struct pinginfo), __type(key, __u32);
.max_entries = 256, __type(value, struct pinginfo);
}; } ping_map SEC(".maps");
static __always_inline void swap_src_dst_mac(void *data) static __always_inline void swap_src_dst_mac(void *data)
{ {
......
...@@ -10,21 +10,21 @@ ...@@ -10,21 +10,21 @@
int _version SEC("version") = 1; int _version SEC("version") = 1;
struct bpf_map_def __attribute__ ((section("maps"), used)) map_in = { struct {
.type = MAP_TYPE, __uint(type, MAP_TYPE);
.key_size = 0, __uint(max_entries, 32);
.value_size = sizeof(__u32), __uint(map_flags, 0);
.max_entries = 32, __uint(key_size, 0);
.map_flags = 0, __uint(value_size, sizeof(__u32));
}; } map_in SEC(".maps");
struct bpf_map_def __attribute__ ((section("maps"), used)) map_out = { struct {
.type = MAP_TYPE, __uint(type, MAP_TYPE);
.key_size = 0, __uint(max_entries, 32);
.value_size = sizeof(__u32), __uint(map_flags, 0);
.max_entries = 32, __uint(key_size, 0);
.map_flags = 0, __uint(value_size, sizeof(__u32));
}; } map_out SEC(".maps");
SEC("test") SEC("test")
int _test(struct __sk_buff *skb) int _test(struct __sk_buff *skb)
......
...@@ -28,61 +28,61 @@ ...@@ -28,61 +28,61 @@
* are established and verdicts are decided. * are established and verdicts are decided.
*/ */
struct bpf_map_def SEC("maps") sock_map = { struct {
.type = TEST_MAP_TYPE, __uint(type, TEST_MAP_TYPE);
.key_size = sizeof(int), __uint(max_entries, 20);
.value_size = sizeof(int), __uint(key_size, sizeof(int));
.max_entries = 20, __uint(value_size, sizeof(int));
}; } sock_map SEC(".maps");
struct bpf_map_def SEC("maps") sock_map_txmsg = { struct {
.type = TEST_MAP_TYPE, __uint(type, TEST_MAP_TYPE);
.key_size = sizeof(int), __uint(max_entries, 20);
.value_size = sizeof(int), __uint(key_size, sizeof(int));
.max_entries = 20, __uint(value_size, sizeof(int));
}; } sock_map_txmsg SEC(".maps");
struct bpf_map_def SEC("maps") sock_map_redir = { struct {
.type = TEST_MAP_TYPE, __uint(type, TEST_MAP_TYPE);
.key_size = sizeof(int), __uint(max_entries, 20);
.value_size = sizeof(int), __uint(key_size, sizeof(int));
.max_entries = 20, __uint(value_size, sizeof(int));
}; } sock_map_redir SEC(".maps");
struct bpf_map_def SEC("maps") sock_apply_bytes = { struct {
.type = BPF_MAP_TYPE_ARRAY, __uint(type, BPF_MAP_TYPE_ARRAY);
.key_size = sizeof(int), __uint(max_entries, 1);
.value_size = sizeof(int), __type(key, int);
.max_entries = 1 __type(value, int);
}; } sock_apply_bytes SEC(".maps");
struct bpf_map_def SEC("maps") sock_cork_bytes = { struct {
.type = BPF_MAP_TYPE_ARRAY, __uint(type, BPF_MAP_TYPE_ARRAY);
.key_size = sizeof(int), __uint(max_entries, 1);
.value_size = sizeof(int), __type(key, int);
.max_entries = 1 __type(value, int);
}; } sock_cork_bytes SEC(".maps");
struct bpf_map_def SEC("maps") sock_bytes = { struct {
.type = BPF_MAP_TYPE_ARRAY, __uint(type, BPF_MAP_TYPE_ARRAY);
.key_size = sizeof(int), __uint(max_entries, 6);
.value_size = sizeof(int), __type(key, int);
.max_entries = 6 __type(value, int);
}; } sock_bytes SEC(".maps");
struct bpf_map_def SEC("maps") sock_redir_flags = { struct {
.type = BPF_MAP_TYPE_ARRAY, __uint(type, BPF_MAP_TYPE_ARRAY);
.key_size = sizeof(int), __uint(max_entries, 1);
.value_size = sizeof(int), __type(key, int);
.max_entries = 1 __type(value, int);
}; } sock_redir_flags SEC(".maps");
struct bpf_map_def SEC("maps") sock_skb_opts = { struct {
.type = BPF_MAP_TYPE_ARRAY, __uint(type, BPF_MAP_TYPE_ARRAY);
.key_size = sizeof(int), __uint(max_entries, 1);
.value_size = sizeof(int), __type(key, int);
.max_entries = 1 __type(value, int);
}; } sock_skb_opts SEC(".maps");
SEC("sk_skb1") SEC("sk_skb1")
int bpf_prog1(struct __sk_buff *skb) int bpf_prog1(struct __sk_buff *skb)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment