Link: https://lore.kernel.org/r/20260217200002.683975158@linuxfoundation.org Tested-by: Florian Fainelli <florian.fainelli@broadcom.com> Tested-by: Takeshi Ogasawara <takeshi.ogasawara@futuring-girl.com> Tested-by: Peter Schneider <pschneider1968@googlemail.com> Tested-by: Jon Hunter <jonathanh@nvidia.com> Tested-by: Salvatore Bonaccorso <carnil@debian.org> Tested-by: Brett A C Sheffield <bacs@librecast.net> Tested-by: Mark Brown <broonie@kernel.org> Tested-by: Luna Jernberg <droidbittin@gmail.com> Tested-by: Ronald Warsow <rwarsow@gmx.de> Tested-by: Justin M. Forbes <jforbes@fedoraproject.org> Tested-by: Ron Economos <re@w6rz.net> Tested-by: Miguel Ojeda <ojeda@kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
50 lines
1007 B
C
50 lines
1007 B
C
// SPDX-License-Identifier: GPL-2.0
|
|
#include <vmlinux.h>
|
|
#include <bpf/bpf_tracing.h>
|
|
#include <bpf/bpf_helpers.h>
|
|
|
|
struct map_value {
|
|
struct task_struct __kptr_untrusted *ptr;
|
|
};
|
|
|
|
struct {
|
|
__uint(type, BPF_MAP_TYPE_LRU_HASH);
|
|
__uint(max_entries, 1);
|
|
__type(key, int);
|
|
__type(value, struct map_value);
|
|
} lru_map SEC(".maps");
|
|
|
|
int pid = 0;
|
|
int result = 1;
|
|
|
|
SEC("fentry/bpf_ktime_get_ns")
|
|
int printk(void *ctx)
|
|
{
|
|
struct map_value v = {};
|
|
|
|
if (pid == bpf_get_current_task_btf()->pid)
|
|
bpf_map_update_elem(&lru_map, &(int){0}, &v, 0);
|
|
return 0;
|
|
}
|
|
|
|
SEC("fentry/do_nanosleep")
|
|
int nanosleep(void *ctx)
|
|
{
|
|
struct map_value val = {}, *v;
|
|
struct task_struct *current;
|
|
|
|
bpf_map_update_elem(&lru_map, &(int){0}, &val, 0);
|
|
v = bpf_map_lookup_elem(&lru_map, &(int){0});
|
|
if (!v)
|
|
return 0;
|
|
bpf_map_delete_elem(&lru_map, &(int){0});
|
|
current = bpf_get_current_task_btf();
|
|
v->ptr = current;
|
|
pid = current->pid;
|
|
bpf_ktime_get_ns();
|
|
result = !v->ptr;
|
|
return 0;
|
|
}
|
|
|
|
char _license[] SEC("license") = "GPL";
|