
hulk inclusion category: feature bugzilla: https://gitee.com/openeuler/kernel/issues/ICA1GK -------------------------------- Which is to get the memory cgroup that a task lies in. Signed-off-by: GONG Ruiqi <gongruiqi1@huawei.com> --- kernel/bpf-rvi/Makefile | 2 +- kernel/bpf-rvi/common_kfuncs.c | 31 +++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 kernel/bpf-rvi/common_kfuncs.c diff --git a/kernel/bpf-rvi/Makefile b/kernel/bpf-rvi/Makefile index 8c226d5f1b3e..9c846eefda4d 100644 --- a/kernel/bpf-rvi/Makefile +++ b/kernel/bpf-rvi/Makefile @@ -1,4 +1,4 @@ # SPDX-License-Identifier: GPL-2.0 # Copyright (c) 2025 Huawei Technologies Co., Ltd -obj-y := generic_single_iter.o +obj-y := generic_single_iter.o common_kfuncs.o diff --git a/kernel/bpf-rvi/common_kfuncs.c b/kernel/bpf-rvi/common_kfuncs.c new file mode 100644 index 000000000000..c751dccc2a67 --- /dev/null +++ b/kernel/bpf-rvi/common_kfuncs.c @@ -0,0 +1,31 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* Copyright (c) 2025 Huawei Technologies Co., Ltd + */ +#include <linux/memcontrol.h> +#include <linux/btf_ids.h> +#include <linux/bpf.h> + +/* + * Common support kfuncs + */ + +__bpf_kfunc struct mem_cgroup *bpf_mem_cgroup_from_task(struct task_struct *p) +{ + return mem_cgroup_from_task(p); +} + +BTF_SET8_START(bpf_common_kfuncs_ids) +BTF_ID_FLAGS(func, bpf_mem_cgroup_from_task, KF_RET_NULL | KF_RCU) +BTF_SET8_END(bpf_common_kfuncs_ids) + +static const struct btf_kfunc_id_set bpf_common_kfuncs_set = { + .owner = THIS_MODULE, + .set = &bpf_common_kfuncs_ids, +}; + +static int __init bpf_common_kfuncs_init(void) +{ + return register_btf_kfunc_id_set(BPF_PROG_TYPE_TRACING, + &bpf_common_kfuncs_set); +} +late_initcall(bpf_common_kfuncs_init); -- 2.25.1