Commit bd368cb5 authored by Hengqi Chen's avatar Hengqi Chen Committed by Andrii Nakryiko

selftests/bpf: Use BTF-defined key/value for map definitions

Change map definitions in BPF selftests to use BTF-defined
key/value types. This unifies the map definitions and ensures
libbpf won't emit warning about retrying map creation.
Signed-off-by: default avatarHengqi Chen <hengqi.chen@gmail.com>
Signed-off-by: default avatarAndrii Nakryiko <andrii@kernel.org>
Link: https://lore.kernel.org/bpf/20210930161456.3444544-3-hengqi.chen@gmail.com
parent f7310523
...@@ -9,8 +9,8 @@ ...@@ -9,8 +9,8 @@
char _license[] SEC("license") = "GPL"; char _license[] SEC("license") = "GPL";
struct { struct {
__uint(type, BPF_MAP_TYPE_PERF_EVENT_ARRAY); __uint(type, BPF_MAP_TYPE_PERF_EVENT_ARRAY);
__uint(key_size, sizeof(int)); __type(key, int);
__uint(value_size, sizeof(int)); __type(value, int);
} perf_buf_map SEC(".maps"); } perf_buf_map SEC(".maps");
#define _(P) (__builtin_preserve_access_index(P)) #define _(P) (__builtin_preserve_access_index(P))
......
...@@ -11,8 +11,8 @@ typedef __u64 stack_trace_t[PERF_MAX_STACK_DEPTH]; ...@@ -11,8 +11,8 @@ typedef __u64 stack_trace_t[PERF_MAX_STACK_DEPTH];
struct { struct {
__uint(type, BPF_MAP_TYPE_STACK_TRACE); __uint(type, BPF_MAP_TYPE_STACK_TRACE);
__uint(max_entries, 16384); __uint(max_entries, 16384);
__uint(key_size, sizeof(__u32)); __type(key, __u32);
__uint(value_size, sizeof(stack_trace_t)); __type(value, stack_trace_t);
} stackmap SEC(".maps"); } stackmap SEC(".maps");
struct { struct {
......
...@@ -7,22 +7,22 @@ int _version SEC("version") = 1; ...@@ -7,22 +7,22 @@ int _version SEC("version") = 1;
struct { struct {
__uint(type, BPF_MAP_TYPE_SOCKMAP); __uint(type, BPF_MAP_TYPE_SOCKMAP);
__uint(max_entries, 20); __uint(max_entries, 20);
__uint(key_size, sizeof(int)); __type(key, int);
__uint(value_size, sizeof(int)); __type(value, int);
} sock_map_rx SEC(".maps"); } sock_map_rx SEC(".maps");
struct { struct {
__uint(type, BPF_MAP_TYPE_SOCKMAP); __uint(type, BPF_MAP_TYPE_SOCKMAP);
__uint(max_entries, 20); __uint(max_entries, 20);
__uint(key_size, sizeof(int)); __type(key, int);
__uint(value_size, sizeof(int)); __type(value, int);
} sock_map_tx SEC(".maps"); } sock_map_tx SEC(".maps");
struct { struct {
__uint(type, BPF_MAP_TYPE_SOCKMAP); __uint(type, BPF_MAP_TYPE_SOCKMAP);
__uint(max_entries, 20); __uint(max_entries, 20);
__uint(key_size, sizeof(int)); __type(key, int);
__uint(value_size, sizeof(int)); __type(value, int);
} sock_map_msg SEC(".maps"); } sock_map_msg SEC(".maps");
struct { struct {
......
...@@ -21,8 +21,8 @@ struct inner_map_sz2 { ...@@ -21,8 +21,8 @@ struct inner_map_sz2 {
struct outer_arr { struct outer_arr {
__uint(type, BPF_MAP_TYPE_ARRAY_OF_MAPS); __uint(type, BPF_MAP_TYPE_ARRAY_OF_MAPS);
__uint(max_entries, 3); __uint(max_entries, 3);
__uint(key_size, sizeof(int)); __type(key, int);
__uint(value_size, sizeof(int)); __type(value, int);
/* it's possible to use anonymous struct as inner map definition here */ /* it's possible to use anonymous struct as inner map definition here */
__array(values, struct { __array(values, struct {
__uint(type, BPF_MAP_TYPE_ARRAY); __uint(type, BPF_MAP_TYPE_ARRAY);
...@@ -61,8 +61,8 @@ struct inner_map_sz4 { ...@@ -61,8 +61,8 @@ struct inner_map_sz4 {
struct outer_arr_dyn { struct outer_arr_dyn {
__uint(type, BPF_MAP_TYPE_ARRAY_OF_MAPS); __uint(type, BPF_MAP_TYPE_ARRAY_OF_MAPS);
__uint(max_entries, 3); __uint(max_entries, 3);
__uint(key_size, sizeof(int)); __type(key, int);
__uint(value_size, sizeof(int)); __type(value, int);
__array(values, struct { __array(values, struct {
__uint(type, BPF_MAP_TYPE_ARRAY); __uint(type, BPF_MAP_TYPE_ARRAY);
__uint(map_flags, BPF_F_INNER_MAP); __uint(map_flags, BPF_F_INNER_MAP);
...@@ -81,7 +81,7 @@ struct outer_arr_dyn { ...@@ -81,7 +81,7 @@ struct outer_arr_dyn {
struct outer_hash { struct outer_hash {
__uint(type, BPF_MAP_TYPE_HASH_OF_MAPS); __uint(type, BPF_MAP_TYPE_HASH_OF_MAPS);
__uint(max_entries, 5); __uint(max_entries, 5);
__uint(key_size, sizeof(int)); __type(key, int);
/* Here everything works flawlessly due to reuse of struct inner_map /* Here everything works flawlessly due to reuse of struct inner_map
* and compiler will complain at the attempt to use non-inner_map * and compiler will complain at the attempt to use non-inner_map
* references below. This is great experience. * references below. This is great experience.
...@@ -111,8 +111,8 @@ struct sockarr_sz2 { ...@@ -111,8 +111,8 @@ struct sockarr_sz2 {
struct outer_sockarr_sz1 { struct outer_sockarr_sz1 {
__uint(type, BPF_MAP_TYPE_ARRAY_OF_MAPS); __uint(type, BPF_MAP_TYPE_ARRAY_OF_MAPS);
__uint(max_entries, 1); __uint(max_entries, 1);
__uint(key_size, sizeof(int)); __type(key, int);
__uint(value_size, sizeof(int)); __type(value, int);
__array(values, struct sockarr_sz1); __array(values, struct sockarr_sz1);
} outer_sockarr SEC(".maps") = { } outer_sockarr SEC(".maps") = {
.values = { (void *)&sockarr_sz1 }, .values = { (void *)&sockarr_sz1 },
......
...@@ -9,18 +9,16 @@ struct { ...@@ -9,18 +9,16 @@ struct {
__uint(type, BPF_MAP_TYPE_ARRAY_OF_MAPS); __uint(type, BPF_MAP_TYPE_ARRAY_OF_MAPS);
__uint(max_entries, 1); __uint(max_entries, 1);
__uint(map_flags, 0); __uint(map_flags, 0);
__uint(key_size, sizeof(__u32)); __type(key, __u32);
/* must be sizeof(__u32) for map in map */ __type(value, __u32);
__uint(value_size, sizeof(__u32));
} mim_array SEC(".maps"); } mim_array SEC(".maps");
struct { struct {
__uint(type, BPF_MAP_TYPE_HASH_OF_MAPS); __uint(type, BPF_MAP_TYPE_HASH_OF_MAPS);
__uint(max_entries, 1); __uint(max_entries, 1);
__uint(map_flags, 0); __uint(map_flags, 0);
__uint(key_size, sizeof(int)); __type(key, int);
/* must be sizeof(__u32) for map in map */ __type(value, __u32);
__uint(value_size, sizeof(__u32));
} mim_hash SEC(".maps"); } mim_hash SEC(".maps");
SEC("xdp") SEC("xdp")
......
...@@ -13,7 +13,7 @@ struct inner { ...@@ -13,7 +13,7 @@ struct inner {
struct { struct {
__uint(type, BPF_MAP_TYPE_ARRAY_OF_MAPS); __uint(type, BPF_MAP_TYPE_ARRAY_OF_MAPS);
__uint(max_entries, 0); /* This will make map creation to fail */ __uint(max_entries, 0); /* This will make map creation to fail */
__uint(key_size, sizeof(__u32)); __type(key, __u32);
__array(values, struct inner); __array(values, struct inner);
} mim SEC(".maps"); } mim SEC(".maps");
......
...@@ -7,15 +7,15 @@ ...@@ -7,15 +7,15 @@
struct { struct {
__uint(type, BPF_MAP_TYPE_PERF_EVENT_ARRAY); __uint(type, BPF_MAP_TYPE_PERF_EVENT_ARRAY);
__uint(max_entries, 1); __uint(max_entries, 1);
__uint(key_size, sizeof(int)); __type(key, int);
__uint(value_size, sizeof(int)); __type(value, int);
} array_1 SEC(".maps"); } array_1 SEC(".maps");
struct { struct {
__uint(type, BPF_MAP_TYPE_PERF_EVENT_ARRAY); __uint(type, BPF_MAP_TYPE_PERF_EVENT_ARRAY);
__uint(max_entries, 1); __uint(max_entries, 1);
__uint(key_size, sizeof(int)); __type(key, int);
__uint(value_size, sizeof(int)); __type(value, int);
__uint(map_flags, BPF_F_PRESERVE_ELEMS); __uint(map_flags, BPF_F_PRESERVE_ELEMS);
} array_2 SEC(".maps"); } array_2 SEC(".maps");
......
...@@ -8,8 +8,8 @@ ...@@ -8,8 +8,8 @@
struct { struct {
__uint(type, BPF_MAP_TYPE_PERF_EVENT_ARRAY); __uint(type, BPF_MAP_TYPE_PERF_EVENT_ARRAY);
__uint(key_size, sizeof(int)); __type(key, int);
__uint(value_size, sizeof(int)); __type(value, int);
} perf_buf_map SEC(".maps"); } perf_buf_map SEC(".maps");
SEC("tp/raw_syscalls/sys_enter") SEC("tp/raw_syscalls/sys_enter")
......
...@@ -24,8 +24,8 @@ int _version SEC("version") = 1; ...@@ -24,8 +24,8 @@ int _version SEC("version") = 1;
struct { struct {
__uint(type, BPF_MAP_TYPE_ARRAY_OF_MAPS); __uint(type, BPF_MAP_TYPE_ARRAY_OF_MAPS);
__uint(max_entries, 1); __uint(max_entries, 1);
__uint(key_size, sizeof(__u32)); __type(key, __u32);
__uint(value_size, sizeof(__u32)); __type(value, __u32);
} outer_map SEC(".maps"); } outer_map SEC(".maps");
struct { struct {
......
...@@ -28,8 +28,8 @@ struct { ...@@ -28,8 +28,8 @@ struct {
__uint(type, BPF_MAP_TYPE_STACK_TRACE); __uint(type, BPF_MAP_TYPE_STACK_TRACE);
__uint(max_entries, 128); __uint(max_entries, 128);
__uint(map_flags, BPF_F_STACK_BUILD_ID); __uint(map_flags, BPF_F_STACK_BUILD_ID);
__uint(key_size, sizeof(__u32)); __type(key, __u32);
__uint(value_size, sizeof(stack_trace_t)); __type(value, stack_trace_t);
} stackmap SEC(".maps"); } stackmap SEC(".maps");
struct { struct {
......
...@@ -27,8 +27,8 @@ typedef __u64 stack_trace_t[PERF_MAX_STACK_DEPTH]; ...@@ -27,8 +27,8 @@ typedef __u64 stack_trace_t[PERF_MAX_STACK_DEPTH];
struct { struct {
__uint(type, BPF_MAP_TYPE_STACK_TRACE); __uint(type, BPF_MAP_TYPE_STACK_TRACE);
__uint(max_entries, 16384); __uint(max_entries, 16384);
__uint(key_size, sizeof(__u32)); __type(key, __u32);
__uint(value_size, sizeof(stack_trace_t)); __type(value, stack_trace_t);
} stackmap SEC(".maps"); } stackmap SEC(".maps");
struct { struct {
......
...@@ -24,8 +24,8 @@ struct { ...@@ -24,8 +24,8 @@ struct {
struct { struct {
__uint(type, BPF_MAP_TYPE_PERF_EVENT_ARRAY); __uint(type, BPF_MAP_TYPE_PERF_EVENT_ARRAY);
__uint(max_entries, 2); __uint(max_entries, 2);
__uint(key_size, sizeof(int)); __type(key, int);
__uint(value_size, sizeof(__u32)); __type(value, __u32);
} perf_event_map SEC(".maps"); } perf_event_map SEC(".maps");
int _version SEC("version") = 1; int _version SEC("version") = 1;
......
...@@ -36,8 +36,8 @@ struct meta { ...@@ -36,8 +36,8 @@ struct meta {
struct { struct {
__uint(type, BPF_MAP_TYPE_PERF_EVENT_ARRAY); __uint(type, BPF_MAP_TYPE_PERF_EVENT_ARRAY);
__uint(key_size, sizeof(int)); __type(key, int);
__uint(value_size, sizeof(int)); __type(value, int);
} perf_buf_map SEC(".maps"); } perf_buf_map SEC(".maps");
__u64 test_result_fentry = 0; __u64 test_result_fentry = 0;
......
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