diff options
Diffstat (limited to 'tools/testing/selftests/bpf/progs')
31 files changed, 535 insertions, 660 deletions
diff --git a/tools/testing/selftests/bpf/progs/bpf_flow.c b/tools/testing/selftests/bpf/progs/bpf_flow.c index 849f42e548b5..5ae485a6af3f 100644 --- a/tools/testing/selftests/bpf/progs/bpf_flow.c +++ b/tools/testing/selftests/bpf/progs/bpf_flow.c @@ -58,26 +58,18 @@ struct frag_hdr { }; struct { - __u32 type; - __u32 max_entries; - __u32 key_size; - __u32 value_size; -} jmp_table SEC(".maps") = { - .type = BPF_MAP_TYPE_PROG_ARRAY, - .max_entries = 8, - .key_size = sizeof(__u32), - .value_size = sizeof(__u32), -}; + __uint(type, BPF_MAP_TYPE_PROG_ARRAY); + __uint(max_entries, 8); + __uint(key_size, sizeof(__u32)); + __uint(value_size, sizeof(__u32)); +} jmp_table SEC(".maps"); struct { - __u32 type; - __u32 max_entries; - __u32 *key; - struct bpf_flow_keys *value; -} last_dissection SEC(".maps") = { - .type = BPF_MAP_TYPE_ARRAY, - .max_entries = 1, -}; + __uint(type, BPF_MAP_TYPE_ARRAY); + __uint(max_entries, 1); + __type(key, __u32); + __type(value, struct bpf_flow_keys); +} last_dissection SEC(".maps"); static __always_inline int export_flow_keys(struct bpf_flow_keys *keys, int ret) diff --git a/tools/testing/selftests/bpf/progs/get_cgroup_id_kern.c b/tools/testing/selftests/bpf/progs/get_cgroup_id_kern.c index 014dba10b8a5..16c54ade6888 100644 --- a/tools/testing/selftests/bpf/progs/get_cgroup_id_kern.c +++ b/tools/testing/selftests/bpf/progs/get_cgroup_id_kern.c @@ -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) diff --git a/tools/testing/selftests/bpf/progs/netcnt_prog.c b/tools/testing/selftests/bpf/progs/netcnt_prog.c index a25c82a5b7c8..38a997852cad 100644 --- a/tools/testing/selftests/bpf/progs/netcnt_prog.c +++ b/tools/testing/selftests/bpf/progs/netcnt_prog.c @@ -11,20 +11,16 @@ #define NS_PER_SEC 1000000000 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, -}; + __uint(type, BPF_MAP_TYPE_PERCPU_CGROUP_STORAGE); + __type(key, struct bpf_cgroup_storage_key); + __type(value, struct percpu_net_cnt); +} percpu_netcnt SEC(".maps"); struct { - __u32 type; - struct bpf_cgroup_storage_key *key; - struct net_cnt *value; -} netcnt SEC(".maps") = { - .type = BPF_MAP_TYPE_CGROUP_STORAGE, -}; + __uint(type, BPF_MAP_TYPE_CGROUP_STORAGE); + __type(key, struct bpf_cgroup_storage_key); + __type(value, struct net_cnt); +} netcnt SEC(".maps"); SEC("cgroup/skb") int bpf_nextcnt(struct __sk_buff *skb) diff --git a/tools/testing/selftests/bpf/progs/pyperf.h b/tools/testing/selftests/bpf/progs/pyperf.h index abf6224649be..003fe106fc70 100644 --- a/tools/testing/selftests/bpf/progs/pyperf.h +++ b/tools/testing/selftests/bpf/progs/pyperf.h @@ -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) { diff --git a/tools/testing/selftests/bpf/progs/socket_cookie_prog.c b/tools/testing/selftests/bpf/progs/socket_cookie_prog.c index 6aabb681fb9a..e4440fdd94cb 100644 --- a/tools/testing/selftests/bpf/progs/socket_cookie_prog.c +++ b/tools/testing/selftests/bpf/progs/socket_cookie_prog.c @@ -13,14 +13,11 @@ struct socket_cookie { }; struct { - __u32 type; - __u32 map_flags; - int *key; - struct socket_cookie *value; -} socket_cookies SEC(".maps") = { - .type = BPF_MAP_TYPE_SK_STORAGE, - .map_flags = BPF_F_NO_PREALLOC, -}; + __uint(type, BPF_MAP_TYPE_SK_STORAGE); + __uint(map_flags, BPF_F_NO_PREALLOC); + __type(key, int); + __type(value, struct socket_cookie); +} socket_cookies SEC(".maps"); SEC("cgroup/connect6") int set_cookie(struct bpf_sock_addr *ctx) diff --git a/tools/testing/selftests/bpf/progs/sockmap_verdict_prog.c b/tools/testing/selftests/bpf/progs/sockmap_verdict_prog.c index d85c874ef25e..433e23918a62 100644 --- a/tools/testing/selftests/bpf/progs/sockmap_verdict_prog.c +++ b/tools/testing/selftests/bpf/progs/sockmap_verdict_prog.c @@ -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) diff --git a/tools/testing/selftests/bpf/progs/strobemeta.h b/tools/testing/selftests/bpf/progs/strobemeta.h index 553bc3b62e89..8a399bdfd920 100644 --- a/tools/testing/selftests/bpf/progs/strobemeta.h +++ b/tools/testing/selftests/bpf/progs/strobemeta.h @@ -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 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 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 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 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_PERF_EVENT_ARRAY); + __uint(max_entries, 32); + __uint(key_size, sizeof(int)); + __uint(value_size, sizeof(int)); +} samples SEC(".maps"); + +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 { + __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 { + __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 { + __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 */ diff --git a/tools/testing/selftests/bpf/progs/test_attach_probe.c b/tools/testing/selftests/bpf/progs/test_attach_probe.c new file mode 100644 index 000000000000..63a8dfef893b --- /dev/null +++ b/tools/testing/selftests/bpf/progs/test_attach_probe.c @@ -0,0 +1,52 @@ +// SPDX-License-Identifier: GPL-2.0 +// Copyright (c) 2017 Facebook + +#include <linux/ptrace.h> +#include <linux/bpf.h> +#include "bpf_helpers.h" + +struct { + __uint(type, BPF_MAP_TYPE_ARRAY); + __uint(max_entries, 4); + __type(key, int); + __type(value, int); +} results_map SEC(".maps"); + +SEC("kprobe/sys_nanosleep") +int handle_sys_nanosleep_entry(struct pt_regs *ctx) +{ + const int key = 0, value = 1; + + bpf_map_update_elem(&results_map, &key, &value, 0); + return 0; +} + +SEC("kretprobe/sys_nanosleep") +int handle_sys_getpid_return(struct pt_regs *ctx) +{ + const int key = 1, value = 2; + + bpf_map_update_elem(&results_map, &key, &value, 0); + return 0; +} + +SEC("uprobe/trigger_func") +int handle_uprobe_entry(struct pt_regs *ctx) +{ + const int key = 2, value = 3; + + bpf_map_update_elem(&results_map, &key, &value, 0); + return 0; +} + +SEC("uretprobe/trigger_func") +int handle_uprobe_return(struct pt_regs *ctx) +{ + const int key = 3, value = 4; + + bpf_map_update_elem(&results_map, &key, &value, 0); + return 0; +} + +char _license[] SEC("license") = "GPL"; +__u32 _version SEC("version") = 1; diff --git a/tools/testing/selftests/bpf/progs/test_btf_newkv.c b/tools/testing/selftests/bpf/progs/test_btf_newkv.c index 28c16bb583b6..5ee3622ddebb 100644 --- a/tools/testing/selftests/bpf/progs/test_btf_newkv.c +++ b/tools/testing/selftests/bpf/progs/test_btf_newkv.c @@ -21,14 +21,11 @@ struct bpf_map_def SEC("maps") btf_map_legacy = { BPF_ANNOTATE_KV_PAIR(btf_map_legacy, int, struct ipv_counts); struct { - int *key; - struct ipv_counts *value; - unsigned int type; - unsigned int max_entries; -} btf_map SEC(".maps") = { - .type = BPF_MAP_TYPE_ARRAY, - .max_entries = 4, -}; + __uint(type, BPF_MAP_TYPE_ARRAY); + __uint(max_entries, 4); + __type(key, int); + __type(value, struct ipv_counts); +} btf_map SEC(".maps"); struct dummy_tracepoint_args { unsigned long long pad; diff --git a/tools/testing/selftests/bpf/progs/test_get_stack_rawtp.c b/tools/testing/selftests/bpf/progs/test_get_stack_rawtp.c index aaa6ec250e15..d06b47a09097 100644 --- a/tools/testing/selftests/bpf/progs/test_get_stack_rawtp.c +++ b/tools/testing/selftests/bpf/progs/test_get_stack_rawtp.c @@ -16,26 +16,18 @@ struct stack_trace_t { }; struct { - __u32 type; - __u32 max_entries; - __u32 key_size; - __u32 value_size; -} perfmap SEC(".maps") = { - .type = BPF_MAP_TYPE_PERF_EVENT_ARRAY, - .max_entries = 2, - .key_size = sizeof(int), - .value_size = sizeof(__u32), -}; + __uint(type, BPF_MAP_TYPE_PERF_EVENT_ARRAY); + __uint(max_entries, 2); + __uint(key_size, sizeof(int)); + __uint(value_size, sizeof(__u32)); +} perfmap SEC(".maps"); struct { - __u32 type; - __u32 max_entries; - __u32 *key; - struct stack_trace_t *value; -} stackdata_map SEC(".maps") = { - .type = BPF_MAP_TYPE_PERCPU_ARRAY, - .max_entries = 1, -}; + __uint(type, BPF_MAP_TYPE_PERCPU_ARRAY); + __uint(max_entries, 1); + __type(key, __u32); + __type(value, struct stack_trace_t); +} stackdata_map SEC(".maps"); /* Allocate per-cpu space twice the needed. For the code below * usize = bpf_get_stack(ctx, raw_data, max_len, BPF_F_USER_STACK); @@ -56,14 +48,11 @@ struct { * This is an acceptable workaround since there is one entry here. */ struct { - __u32 type; - __u32 max_entries; - __u32 *key; + __uint(type, BPF_MAP_TYPE_PERCPU_ARRAY); + __uint(max_entries, 1); + __type(key, __u32); __u64 (*value)[2 * MAX_STACK_RAWTP]; -} rawdata_map SEC(".maps") = { - .type = BPF_MAP_TYPE_PERCPU_ARRAY, - .max_entries = 1, -}; +} rawdata_map SEC(".maps"); SEC("tracepoint/raw_syscalls/sys_enter") int bpf_prog1(void *ctx) diff --git a/tools/testing/selftests/bpf/progs/test_global_data.c b/tools/testing/selftests/bpf/progs/test_global_data.c index 866cc7ddbe43..32a6073acb99 100644 --- a/tools/testing/selftests/bpf/progs/test_global_data.c +++ b/tools/testing/selftests/bpf/progs/test_global_data.c @@ -8,24 +8,18 @@ #include "bpf_helpers.h" struct { - __u32 type; - __u32 max_entries; - __u32 *key; - __u64 *value; -} result_number SEC(".maps") = { - .type = BPF_MAP_TYPE_ARRAY, - .max_entries = 11, -}; + __uint(type, BPF_MAP_TYPE_ARRAY); + __uint(max_entries, 11); + __type(key, __u32); + __type(value, __u64); +} result_number SEC(".maps"); struct { - __u32 type; - __u32 max_entries; - __u32 *key; + __uint(type, BPF_MAP_TYPE_ARRAY); + __uint(max_entries, 5); + __type(key, __u32); const char (*value)[32]; -} result_string SEC(".maps") = { - .type = BPF_MAP_TYPE_ARRAY, - .max_entries = 5, -}; +} result_string SEC(".maps"); struct foo { __u8 a; @@ -34,14 +28,11 @@ struct foo { }; struct { - __u32 type; - __u32 max_entries; - __u32 *key; - struct foo *value; -} result_struct SEC(".maps") = { - .type = BPF_MAP_TYPE_ARRAY, - .max_entries = 5, -}; + __uint(type, BPF_MAP_TYPE_ARRAY); + __uint(max_entries, 5); + __type(key, __u32); + __type(value, struct foo); +} result_struct SEC(".maps"); /* Relocation tests for __u64s. */ static __u64 num0; diff --git a/tools/testing/selftests/bpf/progs/test_l4lb.c b/tools/testing/selftests/bpf/progs/test_l4lb.c index 848cbb90f581..1d652ee8e73d 100644 --- a/tools/testing/selftests/bpf/progs/test_l4lb.c +++ b/tools/testing/selftests/bpf/progs/test_l4lb.c @@ -170,54 +170,39 @@ struct eth_hdr { }; struct { - __u32 type; - __u32 max_entries; - struct vip *key; - struct vip_meta *value; -} vip_map SEC(".maps") = { - .type = BPF_MAP_TYPE_HASH, - .max_entries = MAX_VIPS, -}; + __uint(type, BPF_MAP_TYPE_HASH); + __uint(max_entries, MAX_VIPS); + __type(key, struct vip); + __type(value, struct vip_meta); +} vip_map SEC(".maps"); struct { - __u32 type; - __u32 max_entries; - __u32 *key; - __u32 *value; -} ch_rings SEC(".maps") = { - .type = BPF_MAP_TYPE_ARRAY, - .max_entries = CH_RINGS_SIZE, -}; + __uint(type, BPF_MAP_TYPE_ARRAY); + __uint(max_entries, CH_RINGS_SIZE); + __type(key, __u32); + __type(value, __u32); +} ch_rings SEC(".maps"); struct { - __u32 type; - __u32 max_entries; - __u32 *key; - struct real_definition *value; -} reals SEC(".maps") = { - .type = BPF_MAP_TYPE_ARRAY, - .max_entries = MAX_REALS, -}; + __uint(type, BPF_MAP_TYPE_ARRAY); + __uint(max_entries, MAX_REALS); + __type(key, __u32); + __type(value, struct real_definition); +} reals SEC(".maps"); struct { - __u32 type; - __u32 max_entries; - __u32 *key; - struct vip_stats *value; -} stats SEC(".maps") = { - .type = BPF_MAP_TYPE_PERCPU_ARRAY, - .max_entries = MAX_VIPS, -}; + __uint(type, BPF_MAP_TYPE_PERCPU_ARRAY); + __uint(max_entries, MAX_VIPS); + __type(key, __u32); + __type(value, struct vip_stats); +} stats SEC(".maps"); struct { - __u32 type; - __u32 max_entries; - __u32 *key; - struct ctl_value *value; -} ctl_array SEC(".maps") = { - .type = BPF_MAP_TYPE_ARRAY, - .max_entries = CTL_MAP_SIZE, -}; + __uint(type, BPF_MAP_TYPE_ARRAY); + __uint(max_entries, CTL_MAP_SIZE); + __type(key, __u32); + __type(value, struct ctl_value); +} ctl_array SEC(".maps"); static __always_inline __u32 get_packet_hash(struct packet_description *pckt, bool ipv6) diff --git a/tools/testing/selftests/bpf/progs/test_l4lb_noinline.c b/tools/testing/selftests/bpf/progs/test_l4lb_noinline.c index c63ecf3ca573..2e4efe70b1e5 100644 --- a/tools/testing/selftests/bpf/progs/test_l4lb_noinline.c +++ b/tools/testing/selftests/bpf/progs/test_l4lb_noinline.c @@ -166,54 +166,39 @@ struct eth_hdr { }; struct { - __u32 type; - __u32 max_entries; - struct vip *key; - struct vip_meta *value; -} vip_map SEC(".maps") = { - .type = BPF_MAP_TYPE_HASH, - .max_entries = MAX_VIPS, -}; + __uint(type, BPF_MAP_TYPE_HASH); + __uint(max_entries, MAX_VIPS); + __type(key, struct vip); + __type(value, struct vip_meta); +} vip_map SEC(".maps"); struct { - __u32 type; - __u32 max_entries; - __u32 *key; - __u32 *value; -} ch_rings SEC(".maps") = { - .type = BPF_MAP_TYPE_ARRAY, - .max_entries = CH_RINGS_SIZE, -}; + __uint(type, BPF_MAP_TYPE_ARRAY); + __uint(max_entries, CH_RINGS_SIZE); + __type(key, __u32); + __type(value, __u32); +} ch_rings SEC(".maps"); struct { - __u32 type; - __u32 max_entries; - __u32 *key; - struct real_definition *value; -} reals SEC(".maps") = { - .type = BPF_MAP_TYPE_ARRAY, - .max_entries = MAX_REALS, -}; + __uint(type, BPF_MAP_TYPE_ARRAY); + __uint(max_entries, MAX_REALS); + __type(key, __u32); + __type(value, struct real_definition); +} reals SEC(".maps"); struct { - __u32 type; - __u32 max_entries; - __u32 *key; - struct vip_stats *value; -} stats SEC(".maps") = { - .type = BPF_MAP_TYPE_PERCPU_ARRAY, - .max_entries = MAX_VIPS, -}; + __uint(type, BPF_MAP_TYPE_PERCPU_ARRAY); + __uint(max_entries, MAX_VIPS); + __type(key, __u32); + __type(value, struct vip_stats); +} stats SEC(".maps"); struct { - __u32 type; - __u32 max_entries; - __u32 *key; - struct ctl_value *value; -} ctl_array SEC(".maps") = { - .type = BPF_MAP_TYPE_ARRAY, - .max_entries = CTL_MAP_SIZE, -}; + __uint(type, BPF_MAP_TYPE_ARRAY); + __uint(max_entries, CTL_MAP_SIZE); + __type(key, __u32); + __type(value, struct ctl_value); +} ctl_array SEC(".maps"); static __u32 get_packet_hash(struct packet_description *pckt, bool ipv6) diff --git a/tools/testing/selftests/bpf/progs/test_map_in_map.c b/tools/testing/selftests/bpf/progs/test_map_in_map.c index 2985f262846e..113226115365 100644 --- a/tools/testing/selftests/bpf/progs/test_map_in_map.c +++ b/tools/testing/selftests/bpf/progs/test_map_in_map.c @@ -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) diff --git a/tools/testing/selftests/bpf/progs/test_map_lock.c b/tools/testing/selftests/bpf/progs/test_map_lock.c index 40d9c2853393..bb7ce35f691b 100644 --- a/tools/testing/selftests/bpf/progs/test_map_lock.c +++ b/tools/testing/selftests/bpf/progs/test_map_lock.c @@ -12,14 +12,11 @@ struct hmap_elem { }; struct { - __u32 type; - __u32 max_entries; - __u32 *key; - struct hmap_elem *value; -} hash_map SEC(".maps") = { - .type = BPF_MAP_TYPE_HASH, - .max_entries = 1, -}; + __uint(type, BPF_MAP_TYPE_HASH); + __uint(max_entries, 1); + __type(key, __u32); + __type(value, struct hmap_elem); +} hash_map SEC(".maps"); struct array_elem { struct bpf_spin_lock lock; @@ -27,14 +24,11 @@ struct array_elem { }; struct { - __u32 type; - __u32 max_entries; - int *key; - struct array_elem *value; -} array_map SEC(".maps") = { - .type = BPF_MAP_TYPE_ARRAY, - .max_entries = 1, -}; + __uint(type, BPF_MAP_TYPE_ARRAY); + __uint(max_entries, 1); + __type(key, int); + __type(value, struct array_elem); +} array_map SEC(".maps"); SEC("map_lock_demo") int bpf_map_lock_test(struct __sk_buff *skb) diff --git a/tools/testing/selftests/bpf/progs/test_obj_id.c b/tools/testing/selftests/bpf/progs/test_obj_id.c index 726340fa6fe0..3d30c02bdae9 100644 --- a/tools/testing/selftests/bpf/progs/test_obj_id.c +++ b/tools/testing/selftests/bpf/progs/test_obj_id.c @@ -13,12 +13,12 @@ int _version SEC("version") = 1; -struct bpf_map_def SEC("maps") test_map_id = { - .type = BPF_MAP_TYPE_ARRAY, - .key_size = sizeof(__u32), - .value_size = sizeof(__u64), - .max_entries = 1, -}; +struct { + __uint(type, BPF_MAP_TYPE_ARRAY); + __uint(max_entries, 1); + __type(key, __u32); + __type(value, __u64); +} test_map_id SEC(".maps"); SEC("test_obj_id_dummy") int test_obj_id(struct __sk_buff *skb) diff --git a/tools/testing/selftests/bpf/progs/test_perf_buffer.c b/tools/testing/selftests/bpf/progs/test_perf_buffer.c new file mode 100644 index 000000000000..876c27deb65a --- /dev/null +++ b/tools/testing/selftests/bpf/progs/test_perf_buffer.c @@ -0,0 +1,25 @@ +// SPDX-License-Identifier: GPL-2.0 +// Copyright (c) 2019 Facebook + +#include <linux/ptrace.h> +#include <linux/bpf.h> +#include "bpf_helpers.h" + +struct { + __uint(type, BPF_MAP_TYPE_PERF_EVENT_ARRAY); + __uint(key_size, sizeof(int)); + __uint(value_size, sizeof(int)); +} perf_buf_map SEC(".maps"); + +SEC("kprobe/sys_nanosleep") +int handle_sys_nanosleep_entry(struct pt_regs *ctx) +{ + int cpu = bpf_get_smp_processor_id(); + + bpf_perf_event_output(ctx, &perf_buf_map, BPF_F_CURRENT_CPU, + &cpu, sizeof(cpu)); + return 0; +} + +char _license[] SEC("license") = "GPL"; +__u32 _version SEC("version") = 1; diff --git a/tools/testing/selftests/bpf/progs/test_select_reuseport_kern.c b/tools/testing/selftests/bpf/progs/test_select_reuseport_kern.c index 435a9527733e..ea7d84f01235 100644 --- a/tools/testing/selftests/bpf/progs/test_select_reuseport_kern.c +++ b/tools/testing/selftests/bpf/progs/test_select_reuseport_kern.c @@ -22,56 +22,39 @@ int _version SEC("version") = 1; #endif struct { - __u32 type; - __u32 max_entries; - __u32 key_size; - __u32 value_size; -} outer_map SEC(".maps") = { - .type = BPF_MAP_TYPE_ARRAY_OF_MAPS, - .max_entries = 1, - .key_size = sizeof(__u32), - .value_size = sizeof(__u32), -}; + __uint(type, BPF_MAP_TYPE_ARRAY_OF_MAPS); + __uint(max_entries, 1); + __uint(key_size, sizeof(__u32)); + __uint(value_size, sizeof(__u32)); +} outer_map SEC(".maps"); struct { - __u32 type; - __u32 max_entries; - __u32 *key; - __u32 *value; -} result_map SEC(".maps") = { - .type = BPF_MAP_TYPE_ARRAY, - .max_entries = NR_RESULTS, -}; + __uint(type, BPF_MAP_TYPE_ARRAY); + __uint(max_entries, NR_RESULTS); + __type(key, __u32); + __type(value, __u32); +} result_map SEC(".maps"); struct { - __u32 type; - __u32 max_entries; - __u32 *key; - int *value; -} tmp_index_ovr_map SEC(".maps") = { - .type = BPF_MAP_TYPE_ARRAY, - .max_entries = 1, -}; + __uint(type, BPF_MAP_TYPE_ARRAY); + __uint(max_entries, 1); + __type(key, __u32); + __type(value, int); +} tmp_index_ovr_map SEC(".maps"); struct { - __u32 type; - __u32 max_entries; - __u32 *key; - __u32 *value; -} linum_map SEC(".maps") = { - .type = BPF_MAP_TYPE_ARRAY, - .max_entries = 1, -}; + __uint(type, BPF_MAP_TYPE_ARRAY); + __uint(max_entries, 1); + __type(key, __u32); + __type(value, __u32); +} linum_map SEC(".maps"); struct { - __u32 type; - __u32 max_entries; - __u32 *key; - struct data_check *value; -} data_check_map SEC(".maps") = { - .type = BPF_MAP_TYPE_ARRAY, - .max_entries = 1, -}; + __uint(type, BPF_MAP_TYPE_ARRAY); + __uint(max_entries, 1); + __type(key, __u32); + __type(value, struct data_check); +} data_check_map SEC(".maps"); #define GOTO_DONE(_result) ({ \ result = (_result); \ diff --git a/tools/testing/selftests/bpf/progs/test_send_signal_kern.c b/tools/testing/selftests/bpf/progs/test_send_signal_kern.c index 6ac68be5d68b..0e6be01157e6 100644 --- a/tools/testing/selftests/bpf/progs/test_send_signal_kern.c +++ b/tools/testing/selftests/bpf/progs/test_send_signal_kern.c @@ -5,24 +5,18 @@ #include "bpf_helpers.h" struct { - __u32 type; - __u32 max_entries; - __u32 *key; - __u64 *value; -} info_map SEC(".maps") = { - .type = BPF_MAP_TYPE_ARRAY, - .max_entries = 1, -}; + __uint(type, BPF_MAP_TYPE_ARRAY); + __uint(max_entries, 1); + __type(key, __u32); + __type(value, __u64); +} info_map SEC(".maps"); struct { - __u32 type; - __u32 max_entries; - __u32 *key; - __u64 *value; -} status_map SEC(".maps") = { - .type = BPF_MAP_TYPE_ARRAY, - .max_entries = 1, -}; + __uint(type, BPF_MAP_TYPE_ARRAY); + __uint(max_entries, 1); + __type(key, __u32); + __type(value, __u64); +} status_map SEC(".maps"); SEC("send_signal_demo") int bpf_send_signal_test(void *ctx) diff --git a/tools/testing/selftests/bpf/progs/test_sock_fields_kern.c b/tools/testing/selftests/bpf/progs/test_sock_fields_kern.c index c3d383d650cb..a47b003623ef 100644 --- a/tools/testing/selftests/bpf/progs/test_sock_fields_kern.c +++ b/tools/testing/selftests/bpf/progs/test_sock_fields_kern.c @@ -28,44 +28,32 @@ enum bpf_linum_array_idx { }; struct { - __u32 type; - __u32 max_entries; - __u32 *key; - struct sockaddr_in6 *value; -} addr_map SEC(".maps") = { - .type = BPF_MAP_TYPE_ARRAY, - .max_entries = __NR_BPF_ADDR_ARRAY_IDX, -}; + __uint(type, BPF_MAP_TYPE_ARRAY); + __uint(max_entries, __NR_BPF_ADDR_ARRAY_IDX); + __type(key, __u32); + __type(value, struct sockaddr_in6); +} addr_map SEC(".maps"); struct { - __u32 type; - __u32 max_entries; - __u32 *key; - struct bpf_sock *value; -} sock_result_map SEC(".maps") = { - .type = BPF_MAP_TYPE_ARRAY, - .max_entries = __NR_BPF_RESULT_ARRAY_IDX, -}; + __uint(type, BPF_MAP_TYPE_ARRAY); + __uint(max_entries, __NR_BPF_RESULT_ARRAY_IDX); + __type(key, __u32); + __type(value, struct bpf_sock); +} sock_result_map SEC(".maps"); struct { - __u32 type; - __u32 max_entries; - __u32 *key; - struct bpf_tcp_sock *value; -} tcp_sock_result_map SEC(".maps") = { - .type = BPF_MAP_TYPE_ARRAY, - .max_entries = __NR_BPF_RESULT_ARRAY_IDX, -}; + __uint(type, BPF_MAP_TYPE_ARRAY); + __uint(max_entries, __NR_BPF_RESULT_ARRAY_IDX); + __type(key, __u32); + __type(value, struct bpf_tcp_sock); +} tcp_sock_result_map SEC(".maps"); struct { - __u32 type; - __u32 max_entries; - __u32 *key; - __u32 *value; -} linum_map SEC(".maps") = { - .type = BPF_MAP_TYPE_ARRAY, - .max_entries = __NR_BPF_LINUM_ARRAY_IDX, -}; + __uint(type, BPF_MAP_TYPE_ARRAY); + __uint(max_entries, __NR_BPF_LINUM_ARRAY_IDX); + __type(key, __u32); + __type(value, __u32); +} linum_map SEC(".maps"); struct bpf_spinlock_cnt { struct bpf_spin_lock lock; @@ -73,24 +61,18 @@ struct bpf_spinlock_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, - .map_flags = BPF_F_NO_PREALLOC, -}; + __uint(type, BPF_MAP_TYPE_SK_STORAGE); + __uint(map_flags, BPF_F_NO_PREALLOC); + __type(key, int); + __type(value, struct bpf_spinlock_cnt); +} sk_pkt_out_cnt SEC(".maps"); 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, - .map_flags = BPF_F_NO_PREALLOC, -}; + __uint(type, BPF_MAP_TYPE_SK_STORAGE); + __uint(map_flags, BPF_F_NO_PREALLOC); + __type(key, int); + __type(value, struct bpf_spinlock_cnt); +} sk_pkt_out_cnt10 SEC(".maps"); static bool is_loopback6(__u32 *a6) { diff --git a/tools/testing/selftests/bpf/progs/test_spin_lock.c b/tools/testing/selftests/bpf/progs/test_spin_lock.c index 0a77ae36d981..a43b999c8da2 100644 --- a/tools/testing/selftests/bpf/progs/test_spin_lock.c +++ b/tools/testing/selftests/bpf/progs/test_spin_lock.c @@ -11,14 +11,11 @@ struct hmap_elem { }; struct { - __u32 type; - __u32 max_entries; - int *key; - struct hmap_elem *value; -} hmap SEC(".maps") = { - .type = BPF_MAP_TYPE_HASH, - .max_entries = 1, -}; + __uint(type, BPF_MAP_TYPE_HASH); + __uint(max_entries, 1); + __type(key, int); + __type(value, struct hmap_elem); +} hmap SEC(".maps"); struct cls_elem { struct bpf_spin_lock lock; @@ -26,12 +23,10 @@ struct cls_elem { }; struct { - __u32 type; - struct bpf_cgroup_storage_key *key; - struct cls_elem *value; -} cls_map SEC(".maps") = { - .type = BPF_MAP_TYPE_CGROUP_STORAGE, -}; + __uint(type, BPF_MAP_TYPE_CGROUP_STORAGE); + __type(key, struct bpf_cgroup_storage_key); + __type(value, struct cls_elem); +} cls_map SEC(".maps"); struct bpf_vqueue { struct bpf_spin_lock lock; @@ -42,14 +37,11 @@ struct bpf_vqueue { }; struct { - __u32 type; - __u32 max_entries; - int *key; - struct bpf_vqueue *value; -} vqueue SEC(".maps") = { - .type = BPF_MAP_TYPE_ARRAY, - .max_entries = 1, -}; + __uint(type, BPF_MAP_TYPE_ARRAY); + __uint(max_entries, 1); + __type(key, int); + __type(value, struct bpf_vqueue); +} vqueue SEC(".maps"); #define CREDIT_PER_NS(delta, rate) (((delta) * rate) >> 20) diff --git a/tools/testing/selftests/bpf/progs/test_stacktrace_build_id.c b/tools/testing/selftests/bpf/progs/test_stacktrace_build_id.c index fcf2280bb60c..bbfc8337b6f0 100644 --- a/tools/testing/selftests/bpf/progs/test_stacktrace_build_id.c +++ b/tools/testing/selftests/bpf/progs/test_stacktrace_build_id.c @@ -9,51 +9,36 @@ #endif struct { - __u32 type; - __u32 max_entries; - __u32 *key; - __u32 *value; -} control_map SEC(".maps") = { - .type = BPF_MAP_TYPE_ARRAY, - .max_entries = 1, -}; + __uint(type, BPF_MAP_TYPE_ARRAY); + __uint(max_entries, 1); + __type(key, __u32); + __type(value, __u32); +} control_map SEC(".maps"); struct { - __u32 type; - __u32 max_entries; - __u32 *key; - __u32 *value; -} stackid_hmap SEC(".maps") = { - .type = BPF_MAP_TYPE_HASH, - .max_entries = 16384, -}; + __uint(type, BPF_MAP_TYPE_HASH); + __uint(max_entries, 16384); + __type(key, __u32); + __type(value, __u32); +} stackid_hmap SEC(".maps"); typedef struct bpf_stack_build_id stack_trace_t[PERF_MAX_STACK_DEPTH]; struct { - __u32 type; - __u32 max_entries; - __u32 map_flags; - __u32 key_size; - __u32 value_size; -} stackmap SEC(".maps") = { - .type = BPF_MAP_TYPE_STACK_TRACE, - .max_entries = 128, - .map_flags = BPF_F_STACK_BUILD_ID, - .key_size = sizeof(__u32), - .value_size = sizeof(stack_trace_t), -}; + __uint(type, BPF_MAP_TYPE_STACK_TRACE); + __uint(max_entries, 128); + __uint(map_flags, BPF_F_STACK_BUILD_ID); + __uint(key_size, sizeof(__u32)); + __uint(value_size, sizeof(stack_trace_t)); +} stackmap SEC(".maps"); struct { - __u32 type; - __u32 max_entries; - __u32 *key; + __uint(type, BPF_MAP_TYPE_ARRAY); + __uint(max_entries, 128); + __type(key, __u32); /* there seems to be a bug in kernel not handling typedef properly */ struct bpf_stack_build_id (*value)[PERF_MAX_STACK_DEPTH]; -} stack_amap SEC(".maps") = { - .type = BPF_MAP_TYPE_ARRAY, - .max_entries = 128, -}; +} stack_amap SEC(".maps"); /* taken from /sys/kernel/debug/tracing/events/random/urandom_read/format */ struct random_urandom_args { diff --git a/tools/testing/selftests/bpf/progs/test_stacktrace_map.c b/tools/testing/selftests/bpf/progs/test_stacktrace_map.c index 7ad09adbf648..803c15dc109d 100644 --- a/tools/testing/selftests/bpf/progs/test_stacktrace_map.c +++ b/tools/testing/selftests/bpf/progs/test_stacktrace_map.c @@ -9,48 +9,34 @@ #endif struct { - __u32 type; - __u32 max_entries; - __u32 *key; - __u32 *value; -} control_map SEC(".maps") = { - .type = BPF_MAP_TYPE_ARRAY, - .max_entries = 1, -}; + __uint(type, BPF_MAP_TYPE_ARRAY); + __uint(max_entries, 1); + __type(key, __u32); + __type(value, __u32); +} control_map SEC(".maps"); struct { - __u32 type; - __u32 max_entries; - __u32 *key; - __u32 *value; -} stackid_hmap SEC(".maps") = { - .type = BPF_MAP_TYPE_HASH, - .max_entries = 16384, -}; + __uint(type, BPF_MAP_TYPE_HASH); + __uint(max_entries, 16384); + __type(key, __u32); + __type(value, __u32); +} stackid_hmap SEC(".maps"); typedef __u64 stack_trace_t[PERF_MAX_STACK_DEPTH]; struct { - __u32 type; - __u32 max_entries; - __u32 key_size; - __u32 value_size; -} stackmap SEC(".maps") = { - .type = BPF_MAP_TYPE_STACK_TRACE, - .max_entries = 16384, - .key_size = sizeof(__u32), - .value_size = sizeof(stack_trace_t), -}; + __uint(type, BPF_MAP_TYPE_STACK_TRACE); + __uint(max_entries, 16384); + __uint(key_size, sizeof(__u32)); + __uint(value_size, sizeof(stack_trace_t)); +} stackmap SEC(".maps"); struct { - __u32 type; - __u32 max_entries; - __u32 *key; + __uint(type, BPF_MAP_TYPE_ARRAY); + __uint(max_entries, 16384); + __type(key, __u32); __u64 (*value)[PERF_MAX_STACK_DEPTH]; -} stack_amap SEC(".maps") = { - .type = BPF_MAP_TYPE_ARRAY, - .max_entries = 16384, -}; +} stack_amap SEC(".maps"); /* taken from /sys/kernel/debug/tracing/events/sched/sched_switch/format */ struct sched_switch_args { diff --git a/tools/testing/selftests/bpf/progs/test_tcp_estats.c b/tools/testing/selftests/bpf/progs/test_tcp_estats.c index df98f7e32832..c8c595da38d4 100644 --- a/tools/testing/selftests/bpf/progs/test_tcp_estats.c +++ b/tools/testing/selftests/bpf/progs/test_tcp_estats.c @@ -149,14 +149,11 @@ struct tcp_estats_basic_event { }; struct { - __u32 type; - __u32 max_entries; - __u32 *key; - struct tcp_estats_basic_event *value; -} ev_record_map SEC(".maps") = { - .type = BPF_MAP_TYPE_HASH, - .max_entries = 1024, -}; + __uint(type, BPF_MAP_TYPE_HASH); + __uint(max_entries, 1024); + __type(key, __u32); + __type(value, struct tcp_estats_basic_event); +} ev_record_map SEC(".maps"); struct dummy_tracepoint_args { unsigned long long pad; diff --git a/tools/testing/selftests/bpf/progs/test_tcpbpf_kern.c b/tools/testing/selftests/bpf/progs/test_tcpbpf_kern.c index 38e10c9fd996..2e233613d1fc 100644 --- a/tools/testing/selftests/bpf/progs/test_tcpbpf_kern.c +++ b/tools/testing/selftests/bpf/progs/test_tcpbpf_kern.c @@ -15,24 +15,18 @@ #include "test_tcpbpf.h" struct { - __u32 type; - __u32 max_entries; - __u32 *key; - struct tcpbpf_globals *value; -} global_map SEC(".maps") = { - .type = BPF_MAP_TYPE_ARRAY, - .max_entries = 4, -}; + __uint(type, BPF_MAP_TYPE_ARRAY); + __uint(max_entries, 4); + __type(key, __u32); + __type(value, struct tcpbpf_globals); +} global_map SEC(".maps"); struct { - __u32 type; - __u32 max_entries; - __u32 *key; - int *value; -} sockopt_results SEC(".maps") = { - .type = BPF_MAP_TYPE_ARRAY, - .max_entries = 2, -}; + __uint(type, BPF_MAP_TYPE_ARRAY); + __uint(max_entries, 2); + __type(key, __u32); + __type(value, int); +} sockopt_results SEC(".maps"); static inline void update_event_map(int event) { diff --git a/tools/testing/selftests/bpf/progs/test_tcpnotify_kern.c b/tools/testing/selftests/bpf/progs/test_tcpnotify_kern.c index d073d37d4e27..08346e7765d5 100644 --- a/tools/testing/selftests/bpf/progs/test_tcpnotify_kern.c +++ b/tools/testing/selftests/bpf/progs/test_tcpnotify_kern.c @@ -15,26 +15,18 @@ #include "test_tcpnotify.h" struct { - __u32 type; - __u32 max_entries; - __u32 *key; - struct tcpnotify_globals *value; -} global_map SEC(".maps") = { - .type = BPF_MAP_TYPE_ARRAY, - .max_entries = 4, -}; + __uint(type, BPF_MAP_TYPE_ARRAY); + __uint(max_entries, 4); + __type(key, __u32); + __type(value, struct tcpnotify_globals); +} global_map SEC(".maps"); struct { - __u32 type; - __u32 max_entries; - __u32 key_size; - __u32 value_size; -} perf_event_map SEC(".maps") = { - .type = BPF_MAP_TYPE_PERF_EVENT_ARRAY, - .max_entries = 2, - .key_size = sizeof(int), - .value_size = sizeof(__u32), -}; + __uint(type, BPF_MAP_TYPE_PERF_EVENT_ARRAY); + __uint(max_entries, 2); + __uint(key_size, sizeof(int)); + __uint(value_size, sizeof(__u32)); +} perf_event_map SEC(".maps"); int _version SEC("version") = 1; diff --git a/tools/testing/selftests/bpf/progs/test_xdp.c b/tools/testing/selftests/bpf/progs/test_xdp.c index ec3d2c1c8cf9..0941c655b07b 100644 --- a/tools/testing/selftests/bpf/progs/test_xdp.c +++ b/tools/testing/selftests/bpf/progs/test_xdp.c @@ -23,24 +23,18 @@ int _version SEC("version") = 1; struct { - __u32 type; - __u32 max_entries; - __u32 *key; - __u64 *value; -} rxcnt SEC(".maps") = { - .type = BPF_MAP_TYPE_PERCPU_ARRAY, - .max_entries = 256, -}; + __uint(type, BPF_MAP_TYPE_PERCPU_ARRAY); + __uint(max_entries, 256); + __type(key, __u32); + __type(value, __u64); +} rxcnt SEC(".maps"); struct { - __u32 type; - __u32 max_entries; - struct vip *key; - struct iptnl_info *value; -} vip2tnl SEC(".maps") = { - .type = BPF_MAP_TYPE_HASH, - .max_entries = MAX_IPTNL_ENTRIES, -}; + __uint(type, BPF_MAP_TYPE_HASH); + __uint(max_entries, MAX_IPTNL_ENTRIES); + __type(key, struct vip); + __type(value, struct iptnl_info); +} vip2tnl SEC(".maps"); static __always_inline void count_tx(__u32 protocol) { diff --git a/tools/testing/selftests/bpf/progs/test_xdp_loop.c b/tools/testing/selftests/bpf/progs/test_xdp_loop.c index 7fa4677df22e..97175f73c3fe 100644 --- a/tools/testing/selftests/bpf/progs/test_xdp_loop.c +++ b/tools/testing/selftests/bpf/progs/test_xdp_loop.c @@ -18,19 +18,19 @@ int _version SEC("version") = 1; -struct bpf_map_def SEC("maps") rxcnt = { - .type = BPF_MAP_TYPE_PERCPU_ARRAY, - .key_size = sizeof(__u32), - .value_size = sizeof(__u64), - .max_entries = 256, -}; - -struct bpf_map_def SEC("maps") vip2tnl = { - .type = BPF_MAP_TYPE_HASH, - .key_size = sizeof(struct vip), - .value_size = sizeof(struct iptnl_info), - .max_entries = MAX_IPTNL_ENTRIES, -}; +struct { + __uint(type, BPF_MAP_TYPE_PERCPU_ARRAY); + __uint(max_entries, 256); + __type(key, __u32); + __type(value, __u64); +} rxcnt SEC(".maps"); + +struct { + __uint(type, BPF_MAP_TYPE_HASH); + __uint(max_entries, MAX_IPTNL_ENTRIES); + __type(key, struct vip); + __type(value, struct iptnl_info); +} vip2tnl SEC(".maps"); static __always_inline void count_tx(__u32 protocol) { diff --git a/tools/testing/selftests/bpf/progs/test_xdp_noinline.c b/tools/testing/selftests/bpf/progs/test_xdp_noinline.c index d2eddb5553d1..dad8a7e33eaa 100644 --- a/tools/testing/selftests/bpf/progs/test_xdp_noinline.c +++ b/tools/testing/selftests/bpf/progs/test_xdp_noinline.c @@ -164,66 +164,47 @@ struct lb_stats { }; struct { - __u32 type; - __u32 max_entries; - struct vip_definition *key; - struct vip_meta *value; -} vip_map SEC(".maps") = { - .type = BPF_MAP_TYPE_HASH, - .max_entries = 512, -}; + __uint(type, BPF_MAP_TYPE_HASH); + __uint(max_entries, 512); + __type(key, struct vip_definition); + __type(value, struct vip_meta); +} vip_map SEC(".maps"); struct { - __u32 type; - __u32 max_entries; - __u32 map_flags; - struct flow_key *key; - struct real_pos_lru *value; -} lru_cache SEC(".maps") = { - .type = BPF_MAP_TYPE_LRU_HASH, - .max_entries = 300, - .map_flags = 1U << 1, -}; + __uint(type, BPF_MAP_TYPE_LRU_HASH); + __uint(max_entries, 300); + __uint(map_flags, 1U << 1); + __type(key, struct flow_key); + __type(value, struct real_pos_lru); +} lru_cache SEC(".maps"); struct { - __u32 type; - __u32 max_entries; - __u32 *key; - __u32 *value; -} ch_rings SEC(".maps") = { - .type = BPF_MAP_TYPE_ARRAY, - .max_entries = 12 * 655, -}; + __uint(type, BPF_MAP_TYPE_ARRAY); + __uint(max_entries, 12 * 655); + __type(key, __u32); + __type(value, __u32); +} ch_rings SEC(".maps"); struct { - __u32 type; - __u32 max_entries; - __u32 *key; - struct real_definition *value; -} reals SEC(".maps") = { - .type = BPF_MAP_TYPE_ARRAY, - .max_entries = 40, -}; + __uint(type, BPF_MAP_TYPE_ARRAY); + __uint(max_entries, 40); + __type(key, __u32); + __type(value, struct real_definition); +} reals SEC(".maps"); struct { - __u32 type; - __u32 max_entries; - __u32 *key; - struct lb_stats *value; -} stats SEC(".maps") = { - .type = BPF_MAP_TYPE_PERCPU_ARRAY, - .max_entries = 515, -}; + __uint(type, BPF_MAP_TYPE_PERCPU_ARRAY); + __uint(max_entries, 515); + __type(key, __u32); + __type(value, struct lb_stats); +} stats SEC(".maps"); struct { - __u32 type; - __u32 max_entries; - __u32 *key; - struct ctl_value *value; -} ctl_array SEC(".maps") = { - .type = BPF_MAP_TYPE_ARRAY, - .max_entries = 16, -}; + __uint(type, BPF_MAP_TYPE_ARRAY); + __uint(max_entries, 16); + __type(key, __u32); + __type(value, struct ctl_value); +} ctl_array SEC(".maps"); struct eth_hdr { unsigned char eth_dest[6]; diff --git a/tools/testing/selftests/bpf/progs/xdp_redirect_map.c b/tools/testing/selftests/bpf/progs/xdp_redirect_map.c index e87a985b9df9..1c5f298d7196 100644 --- a/tools/testing/selftests/bpf/progs/xdp_redirect_map.c +++ b/tools/testing/selftests/bpf/progs/xdp_redirect_map.c @@ -3,12 +3,12 @@ #include <linux/bpf.h> #include "bpf_helpers.h" -struct bpf_map_def SEC("maps") tx_port = { - .type = BPF_MAP_TYPE_DEVMAP, - .key_size = sizeof(int), - .value_size = sizeof(int), - .max_entries = 8, -}; +struct { + __uint(type, BPF_MAP_TYPE_DEVMAP); + __uint(max_entries, 8); + __uint(key_size, sizeof(int)); + __uint(value_size, sizeof(int)); +} tx_port SEC(".maps"); SEC("redirect_map_0") int xdp_redirect_map_0(struct xdp_md *xdp) diff --git a/tools/testing/selftests/bpf/progs/xdping_kern.c b/tools/testing/selftests/bpf/progs/xdping_kern.c index 87393e7c667c..112a2857f4e2 100644 --- a/tools/testing/selftests/bpf/progs/xdping_kern.c +++ b/tools/testing/selftests/bpf/progs/xdping_kern.c @@ -17,12 +17,12 @@ #include "xdping.h" -struct bpf_map_def SEC("maps") ping_map = { - .type = BPF_MAP_TYPE_HASH, - .key_size = sizeof(__u32), - .value_size = sizeof(struct pinginfo), - .max_entries = 256, -}; +struct { + __uint(type, BPF_MAP_TYPE_HASH); + __uint(max_entries, 256); + __type(key, __u32); + __type(value, struct pinginfo); +} ping_map SEC(".maps"); static __always_inline void swap_src_dst_mac(void *data) { |