mirror of
https://github.com/torvalds/linux.git
synced 2024-11-25 13:41:51 +00:00
d205d4af3a
commit7bd230a266
("mm/slab: enable slab allocation tagging for kmalloc and friends") [1] swap kmem_cache_alloc_node() to kmem_cache_alloc_node_noprof(). linux/samples/bpf$ sudo ./tracex4 libbpf: prog 'bpf_prog2': failed to create kretprobe 'kmem_cache_alloc_node+0x0' perf event: No such file or directory ERROR: bpf_program__attach failed Signed-off-by: Rong Tao <rongtao@cestc.cn> Signed-off-by: Andrii Nakryiko <andrii@kernel.org> Link:7bd230a266
Link: https://lore.kernel.org/bpf/tencent_34E5BCCAC5ABF3E81222AD81B1D05F16DE06@qq.com
55 lines
1.2 KiB
C
55 lines
1.2 KiB
C
/* Copyright (c) 2015 PLUMgrid, http://plumgrid.com
|
|
*
|
|
* 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.
|
|
*/
|
|
#include "vmlinux.h"
|
|
#include <linux/version.h>
|
|
#include <bpf/bpf_helpers.h>
|
|
#include <bpf/bpf_tracing.h>
|
|
|
|
struct pair {
|
|
u64 val;
|
|
u64 ip;
|
|
};
|
|
|
|
struct {
|
|
__uint(type, BPF_MAP_TYPE_HASH);
|
|
__type(key, long);
|
|
__type(value, struct pair);
|
|
__uint(max_entries, 1000000);
|
|
} my_map SEC(".maps");
|
|
|
|
/* kprobe is NOT a stable ABI. If kernel internals change this bpf+kprobe
|
|
* example will no longer be meaningful
|
|
*/
|
|
SEC("kprobe/kmem_cache_free")
|
|
int bpf_prog1(struct pt_regs *ctx)
|
|
{
|
|
long ptr = PT_REGS_PARM2(ctx);
|
|
|
|
bpf_map_delete_elem(&my_map, &ptr);
|
|
return 0;
|
|
}
|
|
|
|
SEC("kretprobe/kmem_cache_alloc_node_noprof")
|
|
int bpf_prog2(struct pt_regs *ctx)
|
|
{
|
|
long ptr = PT_REGS_RC(ctx);
|
|
long ip = 0;
|
|
|
|
/* get ip address of kmem_cache_alloc_node_noprof() caller */
|
|
BPF_KRETPROBE_READ_RET_IP(ip, ctx);
|
|
|
|
struct pair v = {
|
|
.val = bpf_ktime_get_ns(),
|
|
.ip = ip,
|
|
};
|
|
|
|
bpf_map_update_elem(&my_map, &ptr, &v, BPF_ANY);
|
|
return 0;
|
|
}
|
|
char _license[] SEC("license") = "GPL";
|
|
u32 _version SEC("version") = LINUX_VERSION_CODE;
|