Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

selftests/bpf: convert remaining legacy map definitions

Converted few remaining legacy BPF map definition to BTF-defined ones.
For the remaining two bpf_map_def-based legacy definitions that we want
to keep for testing purposes until libbpf 1.0 release, guard them in
pragma to suppres deprecation warnings which will be added in libbpf in
the next commit.

Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Link: https://lore.kernel.org/r/20220120060529.1890907-3-andrii@kernel.org
Signed-off-by: Alexei Starovoitov <ast@kernel.org>

authored by

Andrii Nakryiko and committed by
Alexei Starovoitov
ccc3f569 32b34294

+48 -42
+6 -6
tools/testing/selftests/bpf/progs/freplace_cls_redirect.c
··· 7 7 #include <bpf/bpf_endian.h> 8 8 #include <bpf/bpf_helpers.h> 9 9 10 - struct bpf_map_def SEC("maps") sock_map = { 11 - .type = BPF_MAP_TYPE_SOCKMAP, 12 - .key_size = sizeof(int), 13 - .value_size = sizeof(int), 14 - .max_entries = 2, 15 - }; 10 + struct { 11 + __uint(type, BPF_MAP_TYPE_SOCKMAP); 12 + __type(key, int); 13 + __type(value, int); 14 + __uint(max_entries, 2); 15 + } sock_map SEC(".maps"); 16 16 17 17 SEC("freplace/cls_redirect") 18 18 int freplace_cls_redirect_test(struct __sk_buff *skb)
+12 -12
tools/testing/selftests/bpf/progs/sample_map_ret0.c
··· 2 2 #include <linux/bpf.h> 3 3 #include <bpf/bpf_helpers.h> 4 4 5 - struct bpf_map_def SEC("maps") htab = { 6 - .type = BPF_MAP_TYPE_HASH, 7 - .key_size = sizeof(__u32), 8 - .value_size = sizeof(long), 9 - .max_entries = 2, 10 - }; 5 + struct { 6 + __uint(type, BPF_MAP_TYPE_HASH); 7 + __type(key, __u32); 8 + __type(value, long); 9 + __uint(max_entries, 2); 10 + } htab SEC(".maps"); 11 11 12 - struct bpf_map_def SEC("maps") array = { 13 - .type = BPF_MAP_TYPE_ARRAY, 14 - .key_size = sizeof(__u32), 15 - .value_size = sizeof(long), 16 - .max_entries = 2, 17 - }; 12 + struct { 13 + __uint(type, BPF_MAP_TYPE_ARRAY); 14 + __type(key, __u32); 15 + __type(value, long); 16 + __uint(max_entries, 2); 17 + } array SEC(".maps"); 18 18 19 19 /* Sample program which should always load for testing control paths. */ 20 20 SEC(".text") int func()
+3
tools/testing/selftests/bpf/progs/test_btf_haskv.c
··· 9 9 unsigned int v6; 10 10 }; 11 11 12 + #pragma GCC diagnostic push 13 + #pragma GCC diagnostic ignored "-Wdeprecated-declarations" 12 14 struct bpf_map_def SEC("maps") btf_map = { 13 15 .type = BPF_MAP_TYPE_ARRAY, 14 16 .key_size = sizeof(int), 15 17 .value_size = sizeof(struct ipv_counts), 16 18 .max_entries = 4, 17 19 }; 20 + #pragma GCC diagnostic pop 18 21 19 22 BPF_ANNOTATE_KV_PAIR(btf_map, int, struct ipv_counts); 20 23
+3
tools/testing/selftests/bpf/progs/test_btf_newkv.c
··· 9 9 unsigned int v6; 10 10 }; 11 11 12 + #pragma GCC diagnostic push 13 + #pragma GCC diagnostic ignored "-Wdeprecated-declarations" 12 14 /* just to validate we can handle maps in multiple sections */ 13 15 struct bpf_map_def SEC("maps") btf_map_legacy = { 14 16 .type = BPF_MAP_TYPE_ARRAY, ··· 18 16 .value_size = sizeof(long long), 19 17 .max_entries = 4, 20 18 }; 19 + #pragma GCC diagnostic pop 21 20 22 21 BPF_ANNOTATE_KV_PAIR(btf_map_legacy, int, struct ipv_counts); 23 22
+6 -6
tools/testing/selftests/bpf/progs/test_btf_nokv.c
··· 8 8 unsigned int v6; 9 9 }; 10 10 11 - struct bpf_map_def SEC("maps") btf_map = { 12 - .type = BPF_MAP_TYPE_ARRAY, 13 - .key_size = sizeof(int), 14 - .value_size = sizeof(struct ipv_counts), 15 - .max_entries = 4, 16 - }; 11 + struct { 12 + __uint(type, BPF_MAP_TYPE_ARRAY); 13 + __uint(key_size, sizeof(int)); 14 + __uint(value_size, sizeof(struct ipv_counts)); 15 + __uint(max_entries, 4); 16 + } btf_map SEC(".maps"); 17 17 18 18 __attribute__((noinline)) 19 19 int test_long_fname_2(void)
+6 -6
tools/testing/selftests/bpf/progs/test_skb_cgroup_id_kern.c
··· 10 10 11 11 #define NUM_CGROUP_LEVELS 4 12 12 13 - struct bpf_map_def SEC("maps") cgroup_ids = { 14 - .type = BPF_MAP_TYPE_ARRAY, 15 - .key_size = sizeof(__u32), 16 - .value_size = sizeof(__u64), 17 - .max_entries = NUM_CGROUP_LEVELS, 18 - }; 13 + struct { 14 + __uint(type, BPF_MAP_TYPE_ARRAY); 15 + __type(key, __u32); 16 + __type(value, __u64); 17 + __uint(max_entries, NUM_CGROUP_LEVELS); 18 + } cgroup_ids SEC(".maps"); 19 19 20 20 static __always_inline void log_nth_level(struct __sk_buff *skb, __u32 level) 21 21 {
+6 -6
tools/testing/selftests/bpf/progs/test_tc_edt.c
··· 17 17 #define THROTTLE_RATE_BPS (5 * 1000 * 1000) 18 18 19 19 /* flow_key => last_tstamp timestamp used */ 20 - struct bpf_map_def SEC("maps") flow_map = { 21 - .type = BPF_MAP_TYPE_HASH, 22 - .key_size = sizeof(uint32_t), 23 - .value_size = sizeof(uint64_t), 24 - .max_entries = 1, 25 - }; 20 + struct { 21 + __uint(type, BPF_MAP_TYPE_HASH); 22 + __type(key, uint32_t); 23 + __type(value, uint64_t); 24 + __uint(max_entries, 1); 25 + } flow_map SEC(".maps"); 26 26 27 27 static inline int throttle_flow(struct __sk_buff *skb) 28 28 {
+6 -6
tools/testing/selftests/bpf/progs/test_tcp_check_syncookie_kern.c
··· 16 16 #include <bpf/bpf_helpers.h> 17 17 #include <bpf/bpf_endian.h> 18 18 19 - struct bpf_map_def SEC("maps") results = { 20 - .type = BPF_MAP_TYPE_ARRAY, 21 - .key_size = sizeof(__u32), 22 - .value_size = sizeof(__u32), 23 - .max_entries = 3, 24 - }; 19 + struct { 20 + __uint(type, BPF_MAP_TYPE_ARRAY); 21 + __type(key, __u32); 22 + __type(value, __u32); 23 + __uint(max_entries, 3); 24 + } results SEC(".maps"); 25 25 26 26 static __always_inline __s64 gen_syncookie(void *data_end, struct bpf_sock *sk, 27 27 void *iph, __u32 ip_size,