1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright (c) 2022 Meta Platforms, Inc. and affiliates. */
5 #include <bpf/bpf_helpers.h>
6 #include <bpf/bpf_tracing.h>
8 char _license[] SEC("license") = "GPL";
11 __uint(type, BPF_MAP_TYPE_CGRP_STORAGE);
12 __uint(map_flags, BPF_F_NO_PREALLOC);
18 __uint(type, BPF_MAP_TYPE_CGRP_STORAGE);
19 __uint(map_flags, BPF_F_NO_PREALLOC);
27 struct cgroup *bpf_task_get_cgroup1(struct task_struct *task, int hierarchy_id) __ksym;
28 void bpf_cgroup_release(struct cgroup *cgrp) __ksym;
30 static void __on_update(struct cgroup *cgrp)
34 ptr = bpf_cgrp_storage_get(&map_a, cgrp, 0, BPF_LOCAL_STORAGE_GET_F_CREATE);
38 ptr = bpf_cgrp_storage_get(&map_b, cgrp, 0, BPF_LOCAL_STORAGE_GET_F_CREATE);
43 SEC("fentry/bpf_local_storage_update")
44 int BPF_PROG(on_update)
46 struct task_struct *task = bpf_get_current_task_btf();
50 cgrp = bpf_task_get_cgroup1(task, target_hid);
55 bpf_cgroup_release(cgrp);
59 __on_update(task->cgroups->dfl_cgrp);
63 static void __on_enter(struct pt_regs *regs, long id, struct cgroup *cgrp)
67 ptr = bpf_cgrp_storage_get(&map_a, cgrp, 0, BPF_LOCAL_STORAGE_GET_F_CREATE);
71 ptr = bpf_cgrp_storage_get(&map_b, cgrp, 0, BPF_LOCAL_STORAGE_GET_F_CREATE);
76 SEC("tp_btf/sys_enter")
77 int BPF_PROG(on_enter, struct pt_regs *regs, long id)
79 struct task_struct *task = bpf_get_current_task_btf();
83 cgrp = bpf_task_get_cgroup1(task, target_hid);
87 __on_enter(regs, id, cgrp);
88 bpf_cgroup_release(cgrp);
92 __on_enter(regs, id, task->cgroups->dfl_cgrp);