.. | .. |
---|
2 | 2 | #include <linux/version.h> |
---|
3 | 3 | #include <uapi/linux/bpf.h> |
---|
4 | 4 | #include <bpf/bpf_helpers.h> |
---|
| 5 | +#include <bpf/bpf_tracing.h> |
---|
| 6 | +#include <bpf/bpf_core_read.h> |
---|
5 | 7 | |
---|
6 | 8 | struct { |
---|
7 | 9 | __uint(type, BPF_MAP_TYPE_PERF_EVENT_ARRAY); |
---|
.. | .. |
---|
45 | 47 | return 0; |
---|
46 | 48 | } |
---|
47 | 49 | |
---|
48 | | -SEC("kprobe/htab_map_lookup_elem") |
---|
49 | | -int bpf_prog2(struct pt_regs *ctx) |
---|
| 50 | +/* |
---|
| 51 | + * Since *_map_lookup_elem can't be expected to trigger bpf programs |
---|
| 52 | + * due to potential deadlocks (bpf_disable_instrumentation), this bpf |
---|
| 53 | + * program will be attached to bpf_map_copy_value (which is called |
---|
| 54 | + * from map_lookup_elem) and will only filter the hashtable type. |
---|
| 55 | + */ |
---|
| 56 | +SEC("kprobe/bpf_map_copy_value") |
---|
| 57 | +int BPF_KPROBE(bpf_prog2, struct bpf_map *map) |
---|
50 | 58 | { |
---|
51 | 59 | u32 key = bpf_get_smp_processor_id(); |
---|
52 | 60 | struct bpf_perf_event_value *val, buf; |
---|
| 61 | + enum bpf_map_type type; |
---|
53 | 62 | int error; |
---|
54 | 63 | |
---|
| 64 | + type = BPF_CORE_READ(map, map_type); |
---|
| 65 | + if (type != BPF_MAP_TYPE_HASH) |
---|
| 66 | + return 0; |
---|
| 67 | + |
---|
55 | 68 | error = bpf_perf_event_read_value(&counters, key, &buf, sizeof(buf)); |
---|
56 | 69 | if (error) |
---|
57 | 70 | return 0; |
---|