blob: ef8ac33bb2e925f3181ee716bd2041fb2ccf9faa [file] [log] [blame]
Alexei Starovoitov9d8b6122016-03-08 15:07:52 -08001/* Copyright (c) 2016, Facebook
2 *
3 * This program is free software; you can redistribute it and/or
4 * modify it under the terms of version 2 of the GNU General Public
5 * License as published by the Free Software Foundation.
6 */
7#include <linux/skbuff.h>
8#include <linux/netdevice.h>
9#include <linux/version.h>
10#include <uapi/linux/bpf.h>
11#include "bpf_helpers.h"
12
13struct bpf_map_def SEC("maps") my_map = {
14 .type = BPF_MAP_TYPE_HASH,
15 .key_size = sizeof(long),
16 .value_size = sizeof(long),
17 .max_entries = 1024,
18};
19struct bpf_map_def SEC("maps") my_map2 = {
20 .type = BPF_MAP_TYPE_PERCPU_HASH,
21 .key_size = sizeof(long),
22 .value_size = sizeof(long),
23 .max_entries = 1024,
24};
25
26#define PROG(foo) \
27int foo(struct pt_regs *ctx) \
28{ \
29 long v = ctx->ip, *val; \
30\
31 val = bpf_map_lookup_elem(&my_map, &v); \
32 bpf_map_update_elem(&my_map, &v, &v, BPF_ANY); \
33 bpf_map_update_elem(&my_map2, &v, &v, BPF_ANY); \
34 bpf_map_delete_elem(&my_map2, &v); \
35 return 0; \
36}
37
38/* add kprobes to all possible *spin* functions */
39SEC("kprobe/spin_unlock")PROG(p1)
40SEC("kprobe/spin_lock")PROG(p2)
41SEC("kprobe/mutex_spin_on_owner")PROG(p3)
42SEC("kprobe/rwsem_spin_on_owner")PROG(p4)
43SEC("kprobe/spin_unlock_irqrestore")PROG(p5)
44SEC("kprobe/_raw_spin_unlock_irqrestore")PROG(p6)
45SEC("kprobe/_raw_spin_unlock_bh")PROG(p7)
46SEC("kprobe/_raw_spin_unlock")PROG(p8)
47SEC("kprobe/_raw_spin_lock_irqsave")PROG(p9)
48SEC("kprobe/_raw_spin_trylock_bh")PROG(p10)
49SEC("kprobe/_raw_spin_lock_irq")PROG(p11)
50SEC("kprobe/_raw_spin_trylock")PROG(p12)
51SEC("kprobe/_raw_spin_lock")PROG(p13)
52SEC("kprobe/_raw_spin_lock_bh")PROG(p14)
53/* and to inner bpf helpers */
54SEC("kprobe/htab_map_update_elem")PROG(p15)
55SEC("kprobe/__htab_percpu_map_update_elem")PROG(p16)
56SEC("kprobe/htab_map_alloc")PROG(p17)
57
58char _license[] SEC("license") = "GPL";
59u32 _version SEC("version") = LINUX_VERSION_CODE;