~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/samples/bpf/spintest_kern.c

Version: ~ [ linux-5.14-rc3 ] ~ [ linux-5.13.5 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.53 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.135 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.198 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.240 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.276 ] ~ [ linux-4.8.17 ] ~ [ linux-4.7.10 ] ~ [ linux-4.6.7 ] ~ [ linux-4.5.7 ] ~ [ linux-4.4.276 ] ~ [ linux-4.3.6 ] ~ [ linux-4.2.8 ] ~ [ linux-4.1.52 ] ~ [ linux-4.0.9 ] ~ [ linux-3.18.140 ] ~ [ linux-3.16.85 ] ~ [ linux-3.14.79 ] ~ [ linux-3.12.74 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.5 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 /* 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 <uapi/linux/perf_event.h>
 12 #include "bpf_helpers.h"
 13 
 14 struct bpf_map_def SEC("maps") my_map = {
 15         .type = BPF_MAP_TYPE_HASH,
 16         .key_size = sizeof(long),
 17         .value_size = sizeof(long),
 18         .max_entries = 1024,
 19 };
 20 struct bpf_map_def SEC("maps") my_map2 = {
 21         .type = BPF_MAP_TYPE_PERCPU_HASH,
 22         .key_size = sizeof(long),
 23         .value_size = sizeof(long),
 24         .max_entries = 1024,
 25 };
 26 
 27 struct bpf_map_def SEC("maps") stackmap = {
 28         .type = BPF_MAP_TYPE_STACK_TRACE,
 29         .key_size = sizeof(u32),
 30         .value_size = PERF_MAX_STACK_DEPTH * sizeof(u64),
 31         .max_entries = 10000,
 32 };
 33 
 34 #define PROG(foo) \
 35 int foo(struct pt_regs *ctx) \
 36 { \
 37         long v = PT_REGS_IP(ctx), *val; \
 38 \
 39         val = bpf_map_lookup_elem(&my_map, &v); \
 40         bpf_map_update_elem(&my_map, &v, &v, BPF_ANY); \
 41         bpf_map_update_elem(&my_map2, &v, &v, BPF_ANY); \
 42         bpf_map_delete_elem(&my_map2, &v); \
 43         bpf_get_stackid(ctx, &stackmap, BPF_F_REUSE_STACKID); \
 44         return 0; \
 45 }
 46 
 47 /* add kprobes to all possible *spin* functions */
 48 SEC("kprobe/spin_unlock")PROG(p1)
 49 SEC("kprobe/spin_lock")PROG(p2)
 50 SEC("kprobe/mutex_spin_on_owner")PROG(p3)
 51 SEC("kprobe/rwsem_spin_on_owner")PROG(p4)
 52 SEC("kprobe/spin_unlock_irqrestore")PROG(p5)
 53 SEC("kprobe/_raw_spin_unlock_irqrestore")PROG(p6)
 54 SEC("kprobe/_raw_spin_unlock_bh")PROG(p7)
 55 SEC("kprobe/_raw_spin_unlock")PROG(p8)
 56 SEC("kprobe/_raw_spin_lock_irqsave")PROG(p9)
 57 SEC("kprobe/_raw_spin_trylock_bh")PROG(p10)
 58 SEC("kprobe/_raw_spin_lock_irq")PROG(p11)
 59 SEC("kprobe/_raw_spin_trylock")PROG(p12)
 60 SEC("kprobe/_raw_spin_lock")PROG(p13)
 61 SEC("kprobe/_raw_spin_lock_bh")PROG(p14)
 62 /* and to inner bpf helpers */
 63 SEC("kprobe/htab_map_update_elem")PROG(p15)
 64 SEC("kprobe/__htab_percpu_map_update_elem")PROG(p16)
 65 SEC("kprobe/htab_map_alloc")PROG(p17)
 66 
 67 char _license[] SEC("license") = "GPL";
 68 u32 _version SEC("version") = LINUX_VERSION_CODE;
 69 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | Wiki (Japanese) | Wiki (English) | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

osdn.jp