| .. | .. |
|---|
| 8 | 8 | #include <linux/netdevice.h> |
|---|
| 9 | 9 | #include <linux/version.h> |
|---|
| 10 | 10 | #include <uapi/linux/bpf.h> |
|---|
| 11 | | -#include "bpf_helpers.h" |
|---|
| 11 | +#include <bpf/bpf_helpers.h> |
|---|
| 12 | +#include <bpf/bpf_tracing.h> |
|---|
| 13 | +#include <bpf/bpf_core_read.h> |
|---|
| 14 | +#include "trace_common.h" |
|---|
| 12 | 15 | |
|---|
| 13 | 16 | #define MAX_ENTRIES 1000 |
|---|
| 14 | 17 | #define MAX_NR_CPUS 1024 |
|---|
| 15 | 18 | |
|---|
| 16 | | -struct bpf_map_def SEC("maps") hash_map = { |
|---|
| 17 | | - .type = BPF_MAP_TYPE_HASH, |
|---|
| 18 | | - .key_size = sizeof(u32), |
|---|
| 19 | | - .value_size = sizeof(long), |
|---|
| 20 | | - .max_entries = MAX_ENTRIES, |
|---|
| 19 | +struct { |
|---|
| 20 | + __uint(type, BPF_MAP_TYPE_HASH); |
|---|
| 21 | + __type(key, u32); |
|---|
| 22 | + __type(value, long); |
|---|
| 23 | + __uint(max_entries, MAX_ENTRIES); |
|---|
| 24 | +} hash_map SEC(".maps"); |
|---|
| 25 | + |
|---|
| 26 | +struct { |
|---|
| 27 | + __uint(type, BPF_MAP_TYPE_LRU_HASH); |
|---|
| 28 | + __type(key, u32); |
|---|
| 29 | + __type(value, long); |
|---|
| 30 | + __uint(max_entries, 10000); |
|---|
| 31 | +} lru_hash_map SEC(".maps"); |
|---|
| 32 | + |
|---|
| 33 | +struct { |
|---|
| 34 | + __uint(type, BPF_MAP_TYPE_LRU_HASH); |
|---|
| 35 | + __type(key, u32); |
|---|
| 36 | + __type(value, long); |
|---|
| 37 | + __uint(max_entries, 10000); |
|---|
| 38 | + __uint(map_flags, BPF_F_NO_COMMON_LRU); |
|---|
| 39 | +} nocommon_lru_hash_map SEC(".maps"); |
|---|
| 40 | + |
|---|
| 41 | +struct inner_lru { |
|---|
| 42 | + __uint(type, BPF_MAP_TYPE_LRU_HASH); |
|---|
| 43 | + __type(key, u32); |
|---|
| 44 | + __type(value, long); |
|---|
| 45 | + __uint(max_entries, MAX_ENTRIES); |
|---|
| 46 | + __uint(map_flags, BPF_F_NUMA_NODE); |
|---|
| 47 | + __uint(numa_node, 0); |
|---|
| 48 | +} inner_lru_hash_map SEC(".maps"); |
|---|
| 49 | + |
|---|
| 50 | +struct { |
|---|
| 51 | + __uint(type, BPF_MAP_TYPE_ARRAY_OF_MAPS); |
|---|
| 52 | + __uint(max_entries, MAX_NR_CPUS); |
|---|
| 53 | + __uint(key_size, sizeof(u32)); |
|---|
| 54 | + __array(values, struct inner_lru); /* use inner_lru as inner map */ |
|---|
| 55 | +} array_of_lru_hashs SEC(".maps") = { |
|---|
| 56 | + /* statically initialize the first element */ |
|---|
| 57 | + .values = { &inner_lru_hash_map }, |
|---|
| 21 | 58 | }; |
|---|
| 22 | 59 | |
|---|
| 23 | | -struct bpf_map_def SEC("maps") lru_hash_map = { |
|---|
| 24 | | - .type = BPF_MAP_TYPE_LRU_HASH, |
|---|
| 25 | | - .key_size = sizeof(u32), |
|---|
| 26 | | - .value_size = sizeof(long), |
|---|
| 27 | | - .max_entries = 10000, |
|---|
| 28 | | -}; |
|---|
| 60 | +struct { |
|---|
| 61 | + __uint(type, BPF_MAP_TYPE_PERCPU_HASH); |
|---|
| 62 | + __uint(key_size, sizeof(u32)); |
|---|
| 63 | + __uint(value_size, sizeof(long)); |
|---|
| 64 | + __uint(max_entries, MAX_ENTRIES); |
|---|
| 65 | +} percpu_hash_map SEC(".maps"); |
|---|
| 29 | 66 | |
|---|
| 30 | | -struct bpf_map_def SEC("maps") nocommon_lru_hash_map = { |
|---|
| 31 | | - .type = BPF_MAP_TYPE_LRU_HASH, |
|---|
| 32 | | - .key_size = sizeof(u32), |
|---|
| 33 | | - .value_size = sizeof(long), |
|---|
| 34 | | - .max_entries = 10000, |
|---|
| 35 | | - .map_flags = BPF_F_NO_COMMON_LRU, |
|---|
| 36 | | -}; |
|---|
| 67 | +struct { |
|---|
| 68 | + __uint(type, BPF_MAP_TYPE_HASH); |
|---|
| 69 | + __type(key, u32); |
|---|
| 70 | + __type(value, long); |
|---|
| 71 | + __uint(max_entries, MAX_ENTRIES); |
|---|
| 72 | + __uint(map_flags, BPF_F_NO_PREALLOC); |
|---|
| 73 | +} hash_map_alloc SEC(".maps"); |
|---|
| 37 | 74 | |
|---|
| 38 | | -struct bpf_map_def SEC("maps") inner_lru_hash_map = { |
|---|
| 39 | | - .type = BPF_MAP_TYPE_LRU_HASH, |
|---|
| 40 | | - .key_size = sizeof(u32), |
|---|
| 41 | | - .value_size = sizeof(long), |
|---|
| 42 | | - .max_entries = MAX_ENTRIES, |
|---|
| 43 | | - .map_flags = BPF_F_NUMA_NODE, |
|---|
| 44 | | - .numa_node = 0, |
|---|
| 45 | | -}; |
|---|
| 75 | +struct { |
|---|
| 76 | + __uint(type, BPF_MAP_TYPE_PERCPU_HASH); |
|---|
| 77 | + __uint(key_size, sizeof(u32)); |
|---|
| 78 | + __uint(value_size, sizeof(long)); |
|---|
| 79 | + __uint(max_entries, MAX_ENTRIES); |
|---|
| 80 | + __uint(map_flags, BPF_F_NO_PREALLOC); |
|---|
| 81 | +} percpu_hash_map_alloc SEC(".maps"); |
|---|
| 46 | 82 | |
|---|
| 47 | | -struct bpf_map_def SEC("maps") array_of_lru_hashs = { |
|---|
| 48 | | - .type = BPF_MAP_TYPE_ARRAY_OF_MAPS, |
|---|
| 49 | | - .key_size = sizeof(u32), |
|---|
| 50 | | - .max_entries = MAX_NR_CPUS, |
|---|
| 51 | | -}; |
|---|
| 83 | +struct { |
|---|
| 84 | + __uint(type, BPF_MAP_TYPE_LPM_TRIE); |
|---|
| 85 | + __uint(key_size, 8); |
|---|
| 86 | + __uint(value_size, sizeof(long)); |
|---|
| 87 | + __uint(max_entries, 10000); |
|---|
| 88 | + __uint(map_flags, BPF_F_NO_PREALLOC); |
|---|
| 89 | +} lpm_trie_map_alloc SEC(".maps"); |
|---|
| 52 | 90 | |
|---|
| 53 | | -struct bpf_map_def SEC("maps") percpu_hash_map = { |
|---|
| 54 | | - .type = BPF_MAP_TYPE_PERCPU_HASH, |
|---|
| 55 | | - .key_size = sizeof(u32), |
|---|
| 56 | | - .value_size = sizeof(long), |
|---|
| 57 | | - .max_entries = MAX_ENTRIES, |
|---|
| 58 | | -}; |
|---|
| 91 | +struct { |
|---|
| 92 | + __uint(type, BPF_MAP_TYPE_ARRAY); |
|---|
| 93 | + __type(key, u32); |
|---|
| 94 | + __type(value, long); |
|---|
| 95 | + __uint(max_entries, MAX_ENTRIES); |
|---|
| 96 | +} array_map SEC(".maps"); |
|---|
| 59 | 97 | |
|---|
| 60 | | -struct bpf_map_def SEC("maps") hash_map_alloc = { |
|---|
| 61 | | - .type = BPF_MAP_TYPE_HASH, |
|---|
| 62 | | - .key_size = sizeof(u32), |
|---|
| 63 | | - .value_size = sizeof(long), |
|---|
| 64 | | - .max_entries = MAX_ENTRIES, |
|---|
| 65 | | - .map_flags = BPF_F_NO_PREALLOC, |
|---|
| 66 | | -}; |
|---|
| 98 | +struct { |
|---|
| 99 | + __uint(type, BPF_MAP_TYPE_LRU_HASH); |
|---|
| 100 | + __type(key, u32); |
|---|
| 101 | + __type(value, long); |
|---|
| 102 | + __uint(max_entries, MAX_ENTRIES); |
|---|
| 103 | +} lru_hash_lookup_map SEC(".maps"); |
|---|
| 67 | 104 | |
|---|
| 68 | | -struct bpf_map_def SEC("maps") percpu_hash_map_alloc = { |
|---|
| 69 | | - .type = BPF_MAP_TYPE_PERCPU_HASH, |
|---|
| 70 | | - .key_size = sizeof(u32), |
|---|
| 71 | | - .value_size = sizeof(long), |
|---|
| 72 | | - .max_entries = MAX_ENTRIES, |
|---|
| 73 | | - .map_flags = BPF_F_NO_PREALLOC, |
|---|
| 74 | | -}; |
|---|
| 75 | | - |
|---|
| 76 | | -struct bpf_map_def SEC("maps") lpm_trie_map_alloc = { |
|---|
| 77 | | - .type = BPF_MAP_TYPE_LPM_TRIE, |
|---|
| 78 | | - .key_size = 8, |
|---|
| 79 | | - .value_size = sizeof(long), |
|---|
| 80 | | - .max_entries = 10000, |
|---|
| 81 | | - .map_flags = BPF_F_NO_PREALLOC, |
|---|
| 82 | | -}; |
|---|
| 83 | | - |
|---|
| 84 | | -struct bpf_map_def SEC("maps") array_map = { |
|---|
| 85 | | - .type = BPF_MAP_TYPE_ARRAY, |
|---|
| 86 | | - .key_size = sizeof(u32), |
|---|
| 87 | | - .value_size = sizeof(long), |
|---|
| 88 | | - .max_entries = MAX_ENTRIES, |
|---|
| 89 | | -}; |
|---|
| 90 | | - |
|---|
| 91 | | -struct bpf_map_def SEC("maps") lru_hash_lookup_map = { |
|---|
| 92 | | - .type = BPF_MAP_TYPE_LRU_HASH, |
|---|
| 93 | | - .key_size = sizeof(u32), |
|---|
| 94 | | - .value_size = sizeof(long), |
|---|
| 95 | | - .max_entries = MAX_ENTRIES, |
|---|
| 96 | | -}; |
|---|
| 97 | | - |
|---|
| 98 | | -SEC("kprobe/sys_getuid") |
|---|
| 105 | +SEC("kprobe/" SYSCALL(sys_getuid)) |
|---|
| 99 | 106 | int stress_hmap(struct pt_regs *ctx) |
|---|
| 100 | 107 | { |
|---|
| 101 | 108 | u32 key = bpf_get_current_pid_tgid(); |
|---|
| .. | .. |
|---|
| 110 | 117 | return 0; |
|---|
| 111 | 118 | } |
|---|
| 112 | 119 | |
|---|
| 113 | | -SEC("kprobe/sys_geteuid") |
|---|
| 120 | +SEC("kprobe/" SYSCALL(sys_geteuid)) |
|---|
| 114 | 121 | int stress_percpu_hmap(struct pt_regs *ctx) |
|---|
| 115 | 122 | { |
|---|
| 116 | 123 | u32 key = bpf_get_current_pid_tgid(); |
|---|
| .. | .. |
|---|
| 124 | 131 | return 0; |
|---|
| 125 | 132 | } |
|---|
| 126 | 133 | |
|---|
| 127 | | -SEC("kprobe/sys_getgid") |
|---|
| 134 | +SEC("kprobe/" SYSCALL(sys_getgid)) |
|---|
| 128 | 135 | int stress_hmap_alloc(struct pt_regs *ctx) |
|---|
| 129 | 136 | { |
|---|
| 130 | 137 | u32 key = bpf_get_current_pid_tgid(); |
|---|
| .. | .. |
|---|
| 138 | 145 | return 0; |
|---|
| 139 | 146 | } |
|---|
| 140 | 147 | |
|---|
| 141 | | -SEC("kprobe/sys_getegid") |
|---|
| 148 | +SEC("kprobe/" SYSCALL(sys_getegid)) |
|---|
| 142 | 149 | int stress_percpu_hmap_alloc(struct pt_regs *ctx) |
|---|
| 143 | 150 | { |
|---|
| 144 | 151 | u32 key = bpf_get_current_pid_tgid(); |
|---|
| .. | .. |
|---|
| 152 | 159 | return 0; |
|---|
| 153 | 160 | } |
|---|
| 154 | 161 | |
|---|
| 155 | | -SEC("kprobe/sys_connect") |
|---|
| 162 | +SEC("kprobe/" SYSCALL(sys_connect)) |
|---|
| 156 | 163 | int stress_lru_hmap_alloc(struct pt_regs *ctx) |
|---|
| 157 | 164 | { |
|---|
| 165 | + struct pt_regs *real_regs = (struct pt_regs *)PT_REGS_PARM1_CORE(ctx); |
|---|
| 158 | 166 | char fmt[] = "Failed at stress_lru_hmap_alloc. ret:%dn"; |
|---|
| 159 | 167 | union { |
|---|
| 160 | 168 | u16 dst6[8]; |
|---|
| .. | .. |
|---|
| 173 | 181 | long val = 1; |
|---|
| 174 | 182 | u32 key = 0; |
|---|
| 175 | 183 | |
|---|
| 176 | | - in6 = (struct sockaddr_in6 *)PT_REGS_PARM2(ctx); |
|---|
| 177 | | - addrlen = (int)PT_REGS_PARM3(ctx); |
|---|
| 184 | + in6 = (struct sockaddr_in6 *)PT_REGS_PARM2_CORE(real_regs); |
|---|
| 185 | + addrlen = (int)PT_REGS_PARM3_CORE(real_regs); |
|---|
| 178 | 186 | |
|---|
| 179 | 187 | if (addrlen != sizeof(*in6)) |
|---|
| 180 | 188 | return 0; |
|---|
| 181 | 189 | |
|---|
| 182 | | - ret = bpf_probe_read(test_params.dst6, sizeof(test_params.dst6), |
|---|
| 183 | | - &in6->sin6_addr); |
|---|
| 190 | + ret = bpf_probe_read_user(test_params.dst6, sizeof(test_params.dst6), |
|---|
| 191 | + &in6->sin6_addr); |
|---|
| 184 | 192 | if (ret) |
|---|
| 185 | 193 | goto done; |
|---|
| 186 | 194 | |
|---|
| .. | .. |
|---|
| 231 | 239 | return 0; |
|---|
| 232 | 240 | } |
|---|
| 233 | 241 | |
|---|
| 234 | | -SEC("kprobe/sys_gettid") |
|---|
| 242 | +SEC("kprobe/" SYSCALL(sys_gettid)) |
|---|
| 235 | 243 | int stress_lpm_trie_map_alloc(struct pt_regs *ctx) |
|---|
| 236 | 244 | { |
|---|
| 237 | 245 | union { |
|---|
| .. | .. |
|---|
| 253 | 261 | return 0; |
|---|
| 254 | 262 | } |
|---|
| 255 | 263 | |
|---|
| 256 | | -SEC("kprobe/sys_getpgid") |
|---|
| 264 | +SEC("kprobe/" SYSCALL(sys_getpgid)) |
|---|
| 257 | 265 | int stress_hash_map_lookup(struct pt_regs *ctx) |
|---|
| 258 | 266 | { |
|---|
| 259 | 267 | u32 key = 1, i; |
|---|
| .. | .. |
|---|
| 266 | 274 | return 0; |
|---|
| 267 | 275 | } |
|---|
| 268 | 276 | |
|---|
| 269 | | -SEC("kprobe/sys_getppid") |
|---|
| 277 | +SEC("kprobe/" SYSCALL(sys_getppid)) |
|---|
| 270 | 278 | int stress_array_map_lookup(struct pt_regs *ctx) |
|---|
| 271 | 279 | { |
|---|
| 272 | 280 | u32 key = 1, i; |
|---|