On Fri, Aug 12, 2022 at 12:02:39PM -0700, Stanislav Fomichev wrote: > diff --git a/kernel/bpf/helpers.c b/kernel/bpf/helpers.c > index 3c1b9bbcf971..de7d2fabb06d 100644 > --- a/kernel/bpf/helpers.c > +++ b/kernel/bpf/helpers.c > @@ -429,7 +429,6 @@ const struct bpf_func_proto bpf_get_current_ancestor_cgroup_id_proto = { > }; > > #ifdef CONFIG_CGROUP_BPF > - > BPF_CALL_2(bpf_get_local_storage, struct bpf_map *, map, u64, flags) > { > /* flags argument is not used now, > @@ -460,7 +459,37 @@ const struct bpf_func_proto bpf_get_local_storage_proto = { > .arg1_type = ARG_CONST_MAP_PTR, > .arg2_type = ARG_ANYTHING, > }; > -#endif > + > +BPF_CALL_0(bpf_get_retval) > +{ > + struct bpf_cg_run_ctx *ctx = > + container_of(current->bpf_ctx, struct bpf_cg_run_ctx, run_ctx); > + > + return ctx->retval; > +} > + > +const struct bpf_func_proto bpf_get_retval_proto = { > + .func = bpf_get_retval, > + .gpl_only = false, > + .ret_type = RET_INTEGER, > +}; > + > +BPF_CALL_1(bpf_set_retval, int, retval) > +{ > + struct bpf_cg_run_ctx *ctx = > + container_of(current->bpf_ctx, struct bpf_cg_run_ctx, run_ctx); > + > + ctx->retval = retval; > + return 0; > +} > + > +const struct bpf_func_proto bpf_set_retval_proto = { > + .func = bpf_set_retval, > + .gpl_only = false, > + .ret_type = RET_INTEGER, > + .arg1_type = ARG_ANYTHING, > +}; > +#endif /* CONFIG_CGROUP_BPF */ > > #define BPF_STRTOX_BASE_MASK 0x1F > > @@ -1726,6 +1755,40 @@ bpf_base_func_proto(enum bpf_func_id func_id) > } > } > > +/* Common helpers for cgroup hooks. */ > +const struct bpf_func_proto * > +cgroup_common_func_proto(enum bpf_func_id func_id, const struct bpf_prog *prog) > +{ > + switch (func_id) { > +#ifdef CONFIG_CGROUP_BPF > + case BPF_FUNC_get_local_storage: > + return &bpf_get_local_storage_proto; > + case BPF_FUNC_get_retval: > + return &bpf_get_retval_proto; > + case BPF_FUNC_set_retval: > + return &bpf_set_retval_proto; > +#endif > + default: > + return NULL; > + } > +} > + > +/* Common helpers for cgroup hooks with valid process context. */ > +const struct bpf_func_proto * > +cgroup_current_func_proto(enum bpf_func_id func_id, const struct bpf_prog *prog) > +{ > + switch (func_id) { > +#ifdef CONFIG_CGROUPS > + case BPF_FUNC_get_current_uid_gid: > + return &bpf_get_current_uid_gid_proto; > + case BPF_FUNC_get_current_cgroup_id: > + return &bpf_get_current_cgroup_id_proto; > +#endif > + default: > + return NULL; > + } > +} Does it make sense to move all these changes to kernel/bpf/cgroup.c instead such that there is no need to do 'ifdef CONFIG_CGROUPS*'. bpf_get_local_storage probably needs to move to kernel/bpf/cgroup.c also.