selftests/bpf: switch BPF_ANNOTATE_KV_PAIR tests to BTF-defined maps
authorAndrii Nakryiko <andriin@fb.com>
Mon, 17 Jun 2019 19:26:58 +0000 (12:26 -0700)
committerDaniel Borkmann <daniel@iogearbox.net>
Mon, 17 Jun 2019 22:10:43 +0000 (00:10 +0200)
Switch tests that already rely on BTF to BTF-defined map definitions.

Signed-off-by: Andrii Nakryiko <andriin@fb.com>
Acked-by: Song Liu <songliubraving@fb.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
tools/testing/selftests/bpf/progs/netcnt_prog.c
tools/testing/selftests/bpf/progs/test_map_lock.c
tools/testing/selftests/bpf/progs/test_send_signal_kern.c
tools/testing/selftests/bpf/progs/test_sock_fields_kern.c
tools/testing/selftests/bpf/progs/test_spin_lock.c

index 9f741e6..a25c82a 100644 (file)
 #define REFRESH_TIME_NS        100000000
 #define NS_PER_SEC     1000000000
 
-struct bpf_map_def SEC("maps") percpu_netcnt = {
+struct {
+       __u32 type;
+       struct bpf_cgroup_storage_key *key;
+       struct percpu_net_cnt *value;
+} percpu_netcnt SEC(".maps") = {
        .type = BPF_MAP_TYPE_PERCPU_CGROUP_STORAGE,
-       .key_size = sizeof(struct bpf_cgroup_storage_key),
-       .value_size = sizeof(struct percpu_net_cnt),
 };
 
-BPF_ANNOTATE_KV_PAIR(percpu_netcnt, struct bpf_cgroup_storage_key,
-                    struct percpu_net_cnt);
-
-struct bpf_map_def SEC("maps") netcnt = {
+struct {
+       __u32 type;
+       struct bpf_cgroup_storage_key *key;
+       struct net_cnt *value;
+} netcnt SEC(".maps") = {
        .type = BPF_MAP_TYPE_CGROUP_STORAGE,
-       .key_size = sizeof(struct bpf_cgroup_storage_key),
-       .value_size = sizeof(struct net_cnt),
 };
 
-BPF_ANNOTATE_KV_PAIR(netcnt, struct bpf_cgroup_storage_key,
-                    struct net_cnt);
-
 SEC("cgroup/skb")
 int bpf_nextcnt(struct __sk_buff *skb)
 {
index af8cc68..40d9c28 100644 (file)
@@ -11,29 +11,31 @@ struct hmap_elem {
        int var[VAR_NUM];
 };
 
-struct bpf_map_def SEC("maps") hash_map = {
+struct {
+       __u32 type;
+       __u32 max_entries;
+       __u32 *key;
+       struct hmap_elem *value;
+} hash_map SEC(".maps") = {
        .type = BPF_MAP_TYPE_HASH,
-       .key_size = sizeof(int),
-       .value_size = sizeof(struct hmap_elem),
        .max_entries = 1,
 };
 
-BPF_ANNOTATE_KV_PAIR(hash_map, int, struct hmap_elem);
-
 struct array_elem {
        struct bpf_spin_lock lock;
        int var[VAR_NUM];
 };
 
-struct bpf_map_def SEC("maps") array_map = {
+struct {
+       __u32 type;
+       __u32 max_entries;
+       int *key;
+       struct array_elem *value;
+} array_map SEC(".maps") = {
        .type = BPF_MAP_TYPE_ARRAY,
-       .key_size = sizeof(int),
-       .value_size = sizeof(struct array_elem),
        .max_entries = 1,
 };
 
-BPF_ANNOTATE_KV_PAIR(array_map, int, struct array_elem);
-
 SEC("map_lock_demo")
 int bpf_map_lock_test(struct __sk_buff *skb)
 {
index 45a1a1a..6ac68be 100644 (file)
@@ -4,24 +4,26 @@
 #include <linux/version.h>
 #include "bpf_helpers.h"
 
-struct bpf_map_def SEC("maps") info_map = {
+struct {
+       __u32 type;
+       __u32 max_entries;
+       __u32 *key;
+       __u64 *value;
+} info_map SEC(".maps") = {
        .type = BPF_MAP_TYPE_ARRAY,
-       .key_size = sizeof(__u32),
-       .value_size = sizeof(__u64),
        .max_entries = 1,
 };
 
-BPF_ANNOTATE_KV_PAIR(info_map, __u32, __u64);
-
-struct bpf_map_def SEC("maps") status_map = {
+struct {
+       __u32 type;
+       __u32 max_entries;
+       __u32 *key;
+       __u64 *value;
+} status_map SEC(".maps") = {
        .type = BPF_MAP_TYPE_ARRAY,
-       .key_size = sizeof(__u32),
-       .value_size = sizeof(__u64),
        .max_entries = 1,
 };
 
-BPF_ANNOTATE_KV_PAIR(status_map, __u32, __u64);
-
 SEC("send_signal_demo")
 int bpf_send_signal_test(void *ctx)
 {
index 1c39e4c..c3d383d 100644 (file)
@@ -27,31 +27,43 @@ enum bpf_linum_array_idx {
        __NR_BPF_LINUM_ARRAY_IDX,
 };
 
-struct bpf_map_def SEC("maps") addr_map = {
+struct {
+       __u32 type;
+       __u32 max_entries;
+       __u32 *key;
+       struct sockaddr_in6 *value;
+} addr_map SEC(".maps") = {
        .type = BPF_MAP_TYPE_ARRAY,
-       .key_size = sizeof(__u32),
-       .value_size = sizeof(struct sockaddr_in6),
        .max_entries = __NR_BPF_ADDR_ARRAY_IDX,
 };
 
-struct bpf_map_def SEC("maps") sock_result_map = {
+struct {
+       __u32 type;
+       __u32 max_entries;
+       __u32 *key;
+       struct bpf_sock *value;
+} sock_result_map SEC(".maps") = {
        .type = BPF_MAP_TYPE_ARRAY,
-       .key_size = sizeof(__u32),
-       .value_size = sizeof(struct bpf_sock),
        .max_entries = __NR_BPF_RESULT_ARRAY_IDX,
 };
 
-struct bpf_map_def SEC("maps") tcp_sock_result_map = {
+struct {
+       __u32 type;
+       __u32 max_entries;
+       __u32 *key;
+       struct bpf_tcp_sock *value;
+} tcp_sock_result_map SEC(".maps") = {
        .type = BPF_MAP_TYPE_ARRAY,
-       .key_size = sizeof(__u32),
-       .value_size = sizeof(struct bpf_tcp_sock),
        .max_entries = __NR_BPF_RESULT_ARRAY_IDX,
 };
 
-struct bpf_map_def SEC("maps") linum_map = {
+struct {
+       __u32 type;
+       __u32 max_entries;
+       __u32 *key;
+       __u32 *value;
+} linum_map SEC(".maps") = {
        .type = BPF_MAP_TYPE_ARRAY,
-       .key_size = sizeof(__u32),
-       .value_size = sizeof(__u32),
        .max_entries = __NR_BPF_LINUM_ARRAY_IDX,
 };
 
@@ -60,26 +72,26 @@ struct bpf_spinlock_cnt {
        __u32 cnt;
 };
 
-struct bpf_map_def SEC("maps") sk_pkt_out_cnt = {
+struct {
+       __u32 type;
+       __u32 map_flags;
+       int *key;
+       struct bpf_spinlock_cnt *value;
+} sk_pkt_out_cnt SEC(".maps") = {
        .type = BPF_MAP_TYPE_SK_STORAGE,
-       .key_size = sizeof(int),
-       .value_size = sizeof(struct bpf_spinlock_cnt),
-       .max_entries = 0,
        .map_flags = BPF_F_NO_PREALLOC,
 };
 
-BPF_ANNOTATE_KV_PAIR(sk_pkt_out_cnt, int, struct bpf_spinlock_cnt);
-
-struct bpf_map_def SEC("maps") sk_pkt_out_cnt10 = {
+struct {
+       __u32 type;
+       __u32 map_flags;
+       int *key;
+       struct bpf_spinlock_cnt *value;
+} sk_pkt_out_cnt10 SEC(".maps") = {
        .type = BPF_MAP_TYPE_SK_STORAGE,
-       .key_size = sizeof(int),
-       .value_size = sizeof(struct bpf_spinlock_cnt),
-       .max_entries = 0,
        .map_flags = BPF_F_NO_PREALLOC,
 };
 
-BPF_ANNOTATE_KV_PAIR(sk_pkt_out_cnt10, int, struct bpf_spinlock_cnt);
-
 static bool is_loopback6(__u32 *a6)
 {
        return !a6[0] && !a6[1] && !a6[2] && a6[3] == bpf_htonl(1);
index 40f9043..0a77ae3 100644 (file)
@@ -10,30 +10,29 @@ struct hmap_elem {
        int test_padding;
 };
 
-struct bpf_map_def SEC("maps") hmap = {
+struct {
+       __u32 type;
+       __u32 max_entries;
+       int *key;
+       struct hmap_elem *value;
+} hmap SEC(".maps") = {
        .type = BPF_MAP_TYPE_HASH,
-       .key_size = sizeof(int),
-       .value_size = sizeof(struct hmap_elem),
        .max_entries = 1,
 };
 
-BPF_ANNOTATE_KV_PAIR(hmap, int, struct hmap_elem);
-
-
 struct cls_elem {
        struct bpf_spin_lock lock;
        volatile int cnt;
 };
 
-struct bpf_map_def SEC("maps") cls_map = {
+struct {
+       __u32 type;
+       struct bpf_cgroup_storage_key *key;
+       struct cls_elem *value;
+} cls_map SEC(".maps") = {
        .type = BPF_MAP_TYPE_CGROUP_STORAGE,
-       .key_size = sizeof(struct bpf_cgroup_storage_key),
-       .value_size = sizeof(struct cls_elem),
 };
 
-BPF_ANNOTATE_KV_PAIR(cls_map, struct bpf_cgroup_storage_key,
-                    struct cls_elem);
-
 struct bpf_vqueue {
        struct bpf_spin_lock lock;
        /* 4 byte hole */
@@ -42,14 +41,16 @@ struct bpf_vqueue {
        unsigned int rate;
 };
 
-struct bpf_map_def SEC("maps") vqueue = {
+struct {
+       __u32 type;
+       __u32 max_entries;
+       int *key;
+       struct bpf_vqueue *value;
+} vqueue SEC(".maps") = {
        .type = BPF_MAP_TYPE_ARRAY,
-       .key_size = sizeof(int),
-       .value_size = sizeof(struct bpf_vqueue),
        .max_entries = 1,
 };
 
-BPF_ANNOTATE_KV_PAIR(vqueue, int, struct bpf_vqueue);
 #define CREDIT_PER_NS(delta, rate) (((delta) * rate) >> 20)
 
 SEC("spin_lock_demo")