2016-03-09 07:07:52 +08:00
|
|
|
/* Copyright (c) 2016, Facebook
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of version 2 of the GNU General Public
|
|
|
|
* License as published by the Free Software Foundation.
|
|
|
|
*/
|
2023-08-18 17:01:12 +08:00
|
|
|
#include "vmlinux.h"
|
2016-03-09 07:07:52 +08:00
|
|
|
#include <linux/version.h>
|
2020-01-20 21:06:49 +08:00
|
|
|
#include <bpf/bpf_helpers.h>
|
|
|
|
#include <bpf/bpf_tracing.h>
|
2016-03-09 07:07:52 +08:00
|
|
|
|
2023-08-18 17:01:12 +08:00
|
|
|
#ifndef PERF_MAX_STACK_DEPTH
|
|
|
|
#define PERF_MAX_STACK_DEPTH 127
|
|
|
|
#endif
|
|
|
|
|
2020-08-23 16:53:33 +08:00
|
|
|
struct {
|
|
|
|
__uint(type, BPF_MAP_TYPE_HASH);
|
|
|
|
__type(key, long);
|
|
|
|
__type(value, long);
|
|
|
|
__uint(max_entries, 1024);
|
|
|
|
} my_map SEC(".maps");
|
|
|
|
struct {
|
|
|
|
__uint(type, BPF_MAP_TYPE_PERCPU_HASH);
|
|
|
|
__uint(key_size, sizeof(long));
|
|
|
|
__uint(value_size, sizeof(long));
|
|
|
|
__uint(max_entries, 1024);
|
|
|
|
} my_map2 SEC(".maps");
|
2016-03-09 07:07:52 +08:00
|
|
|
|
2020-08-23 16:53:33 +08:00
|
|
|
struct {
|
|
|
|
__uint(type, BPF_MAP_TYPE_STACK_TRACE);
|
|
|
|
__uint(key_size, sizeof(u32));
|
|
|
|
__uint(value_size, PERF_MAX_STACK_DEPTH * sizeof(u64));
|
|
|
|
__uint(max_entries, 10000);
|
|
|
|
} stackmap SEC(".maps");
|
2016-03-09 07:07:53 +08:00
|
|
|
|
2016-03-09 07:07:52 +08:00
|
|
|
#define PROG(foo) \
|
|
|
|
int foo(struct pt_regs *ctx) \
|
|
|
|
{ \
|
2016-04-05 01:01:34 +08:00
|
|
|
long v = PT_REGS_IP(ctx), *val; \
|
2016-03-09 07:07:52 +08:00
|
|
|
\
|
|
|
|
val = bpf_map_lookup_elem(&my_map, &v); \
|
|
|
|
bpf_map_update_elem(&my_map, &v, &v, BPF_ANY); \
|
|
|
|
bpf_map_update_elem(&my_map2, &v, &v, BPF_ANY); \
|
|
|
|
bpf_map_delete_elem(&my_map2, &v); \
|
2016-03-09 07:07:53 +08:00
|
|
|
bpf_get_stackid(ctx, &stackmap, BPF_F_REUSE_STACKID); \
|
2016-03-09 07:07:52 +08:00
|
|
|
return 0; \
|
|
|
|
}
|
|
|
|
|
|
|
|
/* add kprobes to all possible *spin* functions */
|
2023-08-18 17:01:19 +08:00
|
|
|
SEC("kprobe.multi/spin_*lock*")PROG(spin_lock)
|
|
|
|
SEC("kprobe.multi/*_spin_on_owner")PROG(spin_on_owner)
|
|
|
|
SEC("kprobe.multi/_raw_spin_*lock*")PROG(raw_spin_lock)
|
2023-08-18 17:01:12 +08:00
|
|
|
|
2016-03-09 07:07:52 +08:00
|
|
|
/* and to inner bpf helpers */
|
|
|
|
SEC("kprobe/htab_map_update_elem")PROG(p15)
|
|
|
|
SEC("kprobe/__htab_percpu_map_update_elem")PROG(p16)
|
|
|
|
SEC("kprobe/htab_map_alloc")PROG(p17)
|
|
|
|
|
|
|
|
char _license[] SEC("license") = "GPL";
|
|
|
|
u32 _version SEC("version") = LINUX_VERSION_CODE;
|