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

selftests/bpf: drop unnecessary bpf_iter.h type duplication

Drop bpf_iter.h header which uses vmlinux.h but re-defines a bunch of
iterator structures and some of BPF constants for use in BPF iterator
selftests.

None of that is necessary when fresh vmlinux.h header is generated for
vmlinux image that matches latest selftests. So drop ugly hacks and have
a nice plain vmlinux.h usage everywhere.

We could do the same with all the kfunc __ksym redefinitions, but that
has dependency on very fresh pahole, so I'm not addressing that here.

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

authored by

Andrii Nakryiko and committed by
Alexei Starovoitov
e626a13f 74975e13

+33 -210
-174
tools/testing/selftests/bpf/progs/bpf_iter.h
··· 1 - /* SPDX-License-Identifier: GPL-2.0 */ 2 - /* Copyright (c) 2020 Facebook */ 3 - /* "undefine" structs in vmlinux.h, because we "override" them below */ 4 - #define bpf_iter_meta bpf_iter_meta___not_used 5 - #define bpf_iter__bpf_map bpf_iter__bpf_map___not_used 6 - #define bpf_iter__ipv6_route bpf_iter__ipv6_route___not_used 7 - #define bpf_iter__netlink bpf_iter__netlink___not_used 8 - #define bpf_iter__task bpf_iter__task___not_used 9 - #define bpf_iter__task_file bpf_iter__task_file___not_used 10 - #define bpf_iter__task_vma bpf_iter__task_vma___not_used 11 - #define bpf_iter__tcp bpf_iter__tcp___not_used 12 - #define tcp6_sock tcp6_sock___not_used 13 - #define bpf_iter__udp bpf_iter__udp___not_used 14 - #define udp6_sock udp6_sock___not_used 15 - #define bpf_iter__unix bpf_iter__unix___not_used 16 - #define bpf_iter__bpf_map_elem bpf_iter__bpf_map_elem___not_used 17 - #define bpf_iter__bpf_sk_storage_map bpf_iter__bpf_sk_storage_map___not_used 18 - #define bpf_iter__sockmap bpf_iter__sockmap___not_used 19 - #define bpf_iter__bpf_link bpf_iter__bpf_link___not_used 20 - #define bpf_iter__cgroup bpf_iter__cgroup___not_used 21 - #define btf_ptr btf_ptr___not_used 22 - #define BTF_F_COMPACT BTF_F_COMPACT___not_used 23 - #define BTF_F_NONAME BTF_F_NONAME___not_used 24 - #define BTF_F_PTR_RAW BTF_F_PTR_RAW___not_used 25 - #define BTF_F_ZERO BTF_F_ZERO___not_used 26 - #define bpf_iter__ksym bpf_iter__ksym___not_used 27 - #define bpf_iter__kmem_cache bpf_iter__kmem_cache___not_used 28 - #include "vmlinux.h" 29 - #undef bpf_iter_meta 30 - #undef bpf_iter__bpf_map 31 - #undef bpf_iter__ipv6_route 32 - #undef bpf_iter__netlink 33 - #undef bpf_iter__task 34 - #undef bpf_iter__task_file 35 - #undef bpf_iter__task_vma 36 - #undef bpf_iter__tcp 37 - #undef tcp6_sock 38 - #undef bpf_iter__udp 39 - #undef udp6_sock 40 - #undef bpf_iter__unix 41 - #undef bpf_iter__bpf_map_elem 42 - #undef bpf_iter__bpf_sk_storage_map 43 - #undef bpf_iter__sockmap 44 - #undef bpf_iter__bpf_link 45 - #undef bpf_iter__cgroup 46 - #undef btf_ptr 47 - #undef BTF_F_COMPACT 48 - #undef BTF_F_NONAME 49 - #undef BTF_F_PTR_RAW 50 - #undef BTF_F_ZERO 51 - #undef bpf_iter__ksym 52 - #undef bpf_iter__kmem_cache 53 - 54 - struct bpf_iter_meta { 55 - struct seq_file *seq; 56 - __u64 session_id; 57 - __u64 seq_num; 58 - } __attribute__((preserve_access_index)); 59 - 60 - struct bpf_iter__ipv6_route { 61 - struct bpf_iter_meta *meta; 62 - struct fib6_info *rt; 63 - } __attribute__((preserve_access_index)); 64 - 65 - struct bpf_iter__netlink { 66 - struct bpf_iter_meta *meta; 67 - struct netlink_sock *sk; 68 - } __attribute__((preserve_access_index)); 69 - 70 - struct bpf_iter__task { 71 - struct bpf_iter_meta *meta; 72 - struct task_struct *task; 73 - } __attribute__((preserve_access_index)); 74 - 75 - struct bpf_iter__task_file { 76 - struct bpf_iter_meta *meta; 77 - struct task_struct *task; 78 - __u32 fd; 79 - struct file *file; 80 - } __attribute__((preserve_access_index)); 81 - 82 - struct bpf_iter__task_vma { 83 - struct bpf_iter_meta *meta; 84 - struct task_struct *task; 85 - struct vm_area_struct *vma; 86 - } __attribute__((preserve_access_index)); 87 - 88 - struct bpf_iter__bpf_map { 89 - struct bpf_iter_meta *meta; 90 - struct bpf_map *map; 91 - } __attribute__((preserve_access_index)); 92 - 93 - struct bpf_iter__tcp { 94 - struct bpf_iter_meta *meta; 95 - struct sock_common *sk_common; 96 - uid_t uid; 97 - } __attribute__((preserve_access_index)); 98 - 99 - struct tcp6_sock { 100 - struct tcp_sock tcp; 101 - struct ipv6_pinfo inet6; 102 - } __attribute__((preserve_access_index)); 103 - 104 - struct bpf_iter__udp { 105 - struct bpf_iter_meta *meta; 106 - struct udp_sock *udp_sk; 107 - uid_t uid __attribute__((aligned(8))); 108 - int bucket __attribute__((aligned(8))); 109 - } __attribute__((preserve_access_index)); 110 - 111 - struct udp6_sock { 112 - struct udp_sock udp; 113 - struct ipv6_pinfo inet6; 114 - } __attribute__((preserve_access_index)); 115 - 116 - struct bpf_iter__unix { 117 - struct bpf_iter_meta *meta; 118 - struct unix_sock *unix_sk; 119 - uid_t uid; 120 - } __attribute__((preserve_access_index)); 121 - 122 - struct bpf_iter__bpf_map_elem { 123 - struct bpf_iter_meta *meta; 124 - struct bpf_map *map; 125 - void *key; 126 - void *value; 127 - }; 128 - 129 - struct bpf_iter__bpf_sk_storage_map { 130 - struct bpf_iter_meta *meta; 131 - struct bpf_map *map; 132 - struct sock *sk; 133 - void *value; 134 - }; 135 - 136 - struct bpf_iter__sockmap { 137 - struct bpf_iter_meta *meta; 138 - struct bpf_map *map; 139 - void *key; 140 - struct sock *sk; 141 - }; 142 - 143 - struct bpf_iter__bpf_link { 144 - struct bpf_iter_meta *meta; 145 - struct bpf_link *link; 146 - }; 147 - 148 - struct bpf_iter__cgroup { 149 - struct bpf_iter_meta *meta; 150 - struct cgroup *cgroup; 151 - } __attribute__((preserve_access_index)); 152 - 153 - struct btf_ptr { 154 - void *ptr; 155 - __u32 type_id; 156 - __u32 flags; 157 - }; 158 - 159 - enum { 160 - BTF_F_COMPACT = (1ULL << 0), 161 - BTF_F_NONAME = (1ULL << 1), 162 - BTF_F_PTR_RAW = (1ULL << 2), 163 - BTF_F_ZERO = (1ULL << 3), 164 - }; 165 - 166 - struct bpf_iter__ksym { 167 - struct bpf_iter_meta *meta; 168 - struct kallsym_iter *ksym; 169 - }; 170 - 171 - struct bpf_iter__kmem_cache { 172 - struct bpf_iter_meta *meta; 173 - struct kmem_cache *s; 174 - } __attribute__((preserve_access_index));
+1 -1
tools/testing/selftests/bpf/progs/bpf_iter_bpf_array_map.c
··· 1 1 // SPDX-License-Identifier: GPL-2.0 2 2 /* Copyright (c) 2020 Facebook */ 3 - #include "bpf_iter.h" 3 + #include <vmlinux.h> 4 4 #include <bpf/bpf_helpers.h> 5 5 #include <bpf/bpf_tracing.h> 6 6
+1 -1
tools/testing/selftests/bpf/progs/bpf_iter_bpf_hash_map.c
··· 1 1 // SPDX-License-Identifier: GPL-2.0 2 2 /* Copyright (c) 2020 Facebook */ 3 - #include "bpf_iter.h" 3 + #include <vmlinux.h> 4 4 #include <bpf/bpf_helpers.h> 5 5 6 6 char _license[] SEC("license") = "GPL";
+1 -1
tools/testing/selftests/bpf/progs/bpf_iter_bpf_link.c
··· 1 1 // SPDX-License-Identifier: GPL-2.0 2 2 /* Copyright (c) 2022 Red Hat, Inc. */ 3 - #include "bpf_iter.h" 3 + #include <vmlinux.h> 4 4 #include <bpf/bpf_helpers.h> 5 5 6 6 char _license[] SEC("license") = "GPL";
+1 -1
tools/testing/selftests/bpf/progs/bpf_iter_bpf_map.c
··· 1 1 // SPDX-License-Identifier: GPL-2.0 2 2 /* Copyright (c) 2020 Facebook */ 3 - #include "bpf_iter.h" 3 + #include <vmlinux.h> 4 4 #include <bpf/bpf_helpers.h> 5 5 6 6 char _license[] SEC("license") = "GPL";
+1 -1
tools/testing/selftests/bpf/progs/bpf_iter_bpf_percpu_array_map.c
··· 1 1 // SPDX-License-Identifier: GPL-2.0 2 2 /* Copyright (c) 2020 Facebook */ 3 - #include "bpf_iter.h" 3 + #include <vmlinux.h> 4 4 #include <bpf/bpf_helpers.h> 5 5 #include <bpf/bpf_tracing.h> 6 6
+1 -1
tools/testing/selftests/bpf/progs/bpf_iter_bpf_percpu_hash_map.c
··· 1 1 // SPDX-License-Identifier: GPL-2.0 2 2 /* Copyright (c) 2020 Facebook */ 3 - #include "bpf_iter.h" 3 + #include <vmlinux.h> 4 4 #include <bpf/bpf_helpers.h> 5 5 #include <bpf/bpf_tracing.h> 6 6
+1 -1
tools/testing/selftests/bpf/progs/bpf_iter_bpf_sk_storage_helpers.c
··· 1 1 // SPDX-License-Identifier: GPL-2.0 2 2 /* Copyright (c) 2020 Google LLC. */ 3 - #include "bpf_iter.h" 3 + #include <vmlinux.h> 4 4 #include <bpf/bpf_helpers.h> 5 5 #include <bpf/bpf_tracing.h> 6 6
+1 -1
tools/testing/selftests/bpf/progs/bpf_iter_bpf_sk_storage_map.c
··· 1 1 // SPDX-License-Identifier: GPL-2.0 2 2 /* Copyright (c) 2020 Facebook */ 3 - #include "bpf_iter.h" 3 + #include <vmlinux.h> 4 4 #include "bpf_tracing_net.h" 5 5 #include <bpf/bpf_helpers.h> 6 6 #include <bpf/bpf_tracing.h>
+1 -1
tools/testing/selftests/bpf/progs/bpf_iter_ipv6_route.c
··· 1 1 // SPDX-License-Identifier: GPL-2.0 2 2 /* Copyright (c) 2020 Facebook */ 3 - #include "bpf_iter.h" 3 + #include <vmlinux.h> 4 4 #include "bpf_tracing_net.h" 5 5 #include <bpf/bpf_helpers.h> 6 6
+1 -1
tools/testing/selftests/bpf/progs/bpf_iter_ksym.c
··· 1 1 // SPDX-License-Identifier: GPL-2.0 2 2 /* Copyright (c) 2022, Oracle and/or its affiliates. */ 3 - #include "bpf_iter.h" 3 + #include <vmlinux.h> 4 4 #include <bpf/bpf_helpers.h> 5 5 6 6 char _license[] SEC("license") = "GPL";
+1 -1
tools/testing/selftests/bpf/progs/bpf_iter_netlink.c
··· 1 1 // SPDX-License-Identifier: GPL-2.0 2 2 /* Copyright (c) 2020 Facebook */ 3 - #include "bpf_iter.h" 3 + #include <vmlinux.h> 4 4 #include "bpf_tracing_net.h" 5 5 #include <bpf/bpf_helpers.h> 6 6
+1 -1
tools/testing/selftests/bpf/progs/bpf_iter_setsockopt.c
··· 1 1 // SPDX-License-Identifier: GPL-2.0 2 2 /* Copyright (c) 2021 Facebook */ 3 - #include "bpf_iter.h" 3 + #include <vmlinux.h> 4 4 #include "bpf_tracing_net.h" 5 5 #include <bpf/bpf_helpers.h> 6 6 #include <bpf/bpf_endian.h>
+1 -1
tools/testing/selftests/bpf/progs/bpf_iter_setsockopt_unix.c
··· 1 1 // SPDX-License-Identifier: GPL-2.0 2 2 /* Copyright Amazon.com Inc. or its affiliates. */ 3 - #include "bpf_iter.h" 3 + #include <vmlinux.h> 4 4 #include "bpf_tracing_net.h" 5 5 #include <bpf/bpf_helpers.h> 6 6 #include <limits.h>
+1 -1
tools/testing/selftests/bpf/progs/bpf_iter_sockmap.c
··· 1 1 // SPDX-License-Identifier: GPL-2.0 2 2 /* Copyright (c) 2020 Cloudflare */ 3 - #include "bpf_iter.h" 3 + #include <vmlinux.h> 4 4 #include "bpf_tracing_net.h" 5 5 #include <bpf/bpf_helpers.h> 6 6 #include <bpf/bpf_tracing.h>
+1 -1
tools/testing/selftests/bpf/progs/bpf_iter_task_btf.c
··· 1 1 // SPDX-License-Identifier: GPL-2.0 2 2 /* Copyright (c) 2020, Oracle and/or its affiliates. */ 3 - #include "bpf_iter.h" 3 + #include <vmlinux.h> 4 4 #include <bpf/bpf_helpers.h> 5 5 #include <bpf/bpf_core_read.h> 6 6
+1 -1
tools/testing/selftests/bpf/progs/bpf_iter_task_file.c
··· 1 1 // SPDX-License-Identifier: GPL-2.0 2 2 /* Copyright (c) 2020 Facebook */ 3 - #include "bpf_iter.h" 3 + #include <vmlinux.h> 4 4 #include <bpf/bpf_helpers.h> 5 5 6 6 char _license[] SEC("license") = "GPL";
+1 -1
tools/testing/selftests/bpf/progs/bpf_iter_task_stack.c
··· 1 1 // SPDX-License-Identifier: GPL-2.0 2 2 /* Copyright (c) 2020 Facebook */ 3 - #include "bpf_iter.h" 3 + #include <vmlinux.h> 4 4 #include <bpf/bpf_helpers.h> 5 5 6 6 char _license[] SEC("license") = "GPL";
+1 -1
tools/testing/selftests/bpf/progs/bpf_iter_task_vmas.c
··· 1 1 // SPDX-License-Identifier: GPL-2.0 2 2 /* Copyright (c) 2020 Facebook */ 3 - #include "bpf_iter.h" 3 + #include <vmlinux.h> 4 4 #include <bpf/bpf_helpers.h> 5 5 6 6 char _license[] SEC("license") = "GPL";
+1 -1
tools/testing/selftests/bpf/progs/bpf_iter_tasks.c
··· 1 1 // SPDX-License-Identifier: GPL-2.0 2 2 /* Copyright (c) 2020 Facebook */ 3 - #include "bpf_iter.h" 3 + #include <vmlinux.h> 4 4 #include <bpf/bpf_helpers.h> 5 5 #include <bpf/bpf_tracing.h> 6 6
+1 -1
tools/testing/selftests/bpf/progs/bpf_iter_tcp4.c
··· 1 1 // SPDX-License-Identifier: GPL-2.0 2 2 /* Copyright (c) 2020 Facebook */ 3 - #include "bpf_iter.h" 3 + #include <vmlinux.h> 4 4 #include "bpf_tracing_net.h" 5 5 #include <bpf/bpf_helpers.h> 6 6 #include <bpf/bpf_endian.h>
+1 -1
tools/testing/selftests/bpf/progs/bpf_iter_tcp6.c
··· 1 1 // SPDX-License-Identifier: GPL-2.0 2 2 /* Copyright (c) 2020 Facebook */ 3 - #include "bpf_iter.h" 3 + #include <vmlinux.h> 4 4 #include "bpf_tracing_net.h" 5 5 #include <bpf/bpf_helpers.h> 6 6 #include <bpf/bpf_endian.h>
+1 -1
tools/testing/selftests/bpf/progs/bpf_iter_test_kern3.c
··· 1 1 // SPDX-License-Identifier: GPL-2.0 2 2 /* Copyright (c) 2020 Facebook */ 3 - #include "bpf_iter.h" 3 + #include <vmlinux.h> 4 4 #include <bpf/bpf_helpers.h> 5 5 6 6 char _license[] SEC("license") = "GPL";
+1 -1
tools/testing/selftests/bpf/progs/bpf_iter_test_kern4.c
··· 1 1 // SPDX-License-Identifier: GPL-2.0 2 2 /* Copyright (c) 2020 Facebook */ 3 - #include "bpf_iter.h" 3 + #include <vmlinux.h> 4 4 #include <bpf/bpf_helpers.h> 5 5 6 6 char _license[] SEC("license") = "GPL";
+1 -1
tools/testing/selftests/bpf/progs/bpf_iter_test_kern5.c
··· 1 1 // SPDX-License-Identifier: GPL-2.0 2 2 /* Copyright (c) 2020 Facebook */ 3 - #include "bpf_iter.h" 3 + #include <vmlinux.h> 4 4 #include <bpf/bpf_helpers.h> 5 5 #include <bpf/bpf_tracing.h> 6 6
+1 -1
tools/testing/selftests/bpf/progs/bpf_iter_test_kern6.c
··· 1 1 // SPDX-License-Identifier: GPL-2.0 2 2 /* Copyright (c) 2020 Facebook */ 3 - #include "bpf_iter.h" 3 + #include <vmlinux.h> 4 4 #include <bpf/bpf_helpers.h> 5 5 6 6 char _license[] SEC("license") = "GPL";
+1 -1
tools/testing/selftests/bpf/progs/bpf_iter_test_kern_common.h
··· 1 1 /* SPDX-License-Identifier: GPL-2.0 */ 2 2 /* Copyright (c) 2020 Facebook */ 3 - #include "bpf_iter.h" 3 + #include <vmlinux.h> 4 4 #include <bpf/bpf_helpers.h> 5 5 6 6 char _license[] SEC("license") = "GPL";
+1 -1
tools/testing/selftests/bpf/progs/bpf_iter_udp4.c
··· 1 1 // SPDX-License-Identifier: GPL-2.0 2 2 /* Copyright (c) 2020 Facebook */ 3 - #include "bpf_iter.h" 3 + #include <vmlinux.h> 4 4 #include "bpf_tracing_net.h" 5 5 #include <bpf/bpf_helpers.h> 6 6 #include <bpf/bpf_endian.h>
+1 -1
tools/testing/selftests/bpf/progs/bpf_iter_udp6.c
··· 1 1 // SPDX-License-Identifier: GPL-2.0 2 2 /* Copyright (c) 2020 Facebook */ 3 - #include "bpf_iter.h" 3 + #include <vmlinux.h> 4 4 #include "bpf_tracing_net.h" 5 5 #include <bpf/bpf_helpers.h> 6 6 #include <bpf/bpf_endian.h>
+1 -1
tools/testing/selftests/bpf/progs/bpf_iter_unix.c
··· 1 1 // SPDX-License-Identifier: GPL-2.0 2 2 /* Copyright Amazon.com Inc. or its affiliates. */ 3 - #include "bpf_iter.h" 3 + #include <vmlinux.h> 4 4 #include "bpf_tracing_net.h" 5 5 #include <bpf/bpf_helpers.h> 6 6 #include <bpf/bpf_endian.h>
+1 -1
tools/testing/selftests/bpf/progs/bpf_iter_vma_offset.c
··· 1 1 // SPDX-License-Identifier: GPL-2.0 2 2 /* Copyright (c) 2022 Meta Platforms, Inc. and affiliates. */ 3 - #include "bpf_iter.h" 3 + #include <vmlinux.h> 4 4 #include <bpf/bpf_helpers.h> 5 5 6 6 char _license[] SEC("license") = "GPL";
+1 -2
tools/testing/selftests/bpf/progs/cgroup_iter.c
··· 1 1 // SPDX-License-Identifier: GPL-2.0 2 2 /* Copyright (c) 2022 Google */ 3 - 4 - #include "bpf_iter.h" 3 + #include <vmlinux.h> 5 4 #include <bpf/bpf_helpers.h> 6 5 #include <bpf/bpf_tracing.h> 7 6
+1 -2
tools/testing/selftests/bpf/progs/cgrp_ls_sleepable.c
··· 1 1 // SPDX-License-Identifier: GPL-2.0 2 2 /* Copyright (c) 2022 Meta Platforms, Inc. and affiliates. */ 3 - 4 - #include "bpf_iter.h" 3 + #include <vmlinux.h> 5 4 #include <bpf/bpf_helpers.h> 6 5 #include <bpf/bpf_tracing.h> 7 6 #include "bpf_misc.h"
+1 -2
tools/testing/selftests/bpf/progs/kmem_cache_iter.c
··· 1 1 // SPDX-License-Identifier: GPL-2.0 2 2 /* Copyright (c) 2024 Google */ 3 - 4 - #include "bpf_iter.h" 3 + #include <vmlinux.h> 5 4 #include <bpf/bpf_helpers.h> 6 5 #include <bpf/bpf_tracing.h> 7 6