> diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h
> index f3b8c71870d8..d71e86b85ba7 100644
> --- a/include/linux/memcontrol.h
> +++ b/include/linux/memcontrol.h

[ ... ]

> +#else /* CONFIG_BPF_SYSCALL */
> +
> +static inline unsigned long
> +bpf_memcg_get_high_delay(struct mem_cgroup *memcg) { return 0 }
> +static inline bpf_memcg_below_low(struct mem_cgroup *memcg) { return false }
> +static inline bpf_memcg_below_min(struct mem_cgroup *memcg) { return false }
                 ^^^^^^^^^^^^^^^^^^^^

These stub functions appear to have syntax issues that would prevent
compilation when CONFIG_BPF_SYSCALL is disabled:

1. bpf_memcg_get_high_delay() is missing a semicolon after "return 0"
2. bpf_memcg_below_low() is missing the "bool" return type
3. bpf_memcg_below_min() is missing the "bool" return type

Should these be:

  static inline unsigned long
  bpf_memcg_get_high_delay(struct mem_cgroup *memcg) { return 0; }
  static inline bool bpf_memcg_below_low(struct mem_cgroup *memcg) { return 
false; }
  static inline bool bpf_memcg_below_min(struct mem_cgroup *memcg) { return 
false; }

> +static inline void memcontrol_bpf_online(struct mem_cgroup *memcg) { }
> +static inline void memcontrol_bpf_offline(struct mem_cgroup *memcg) { }
> +
> +#endif /* CONFIG_BPF_SYSCALL */

[ ... ]

> diff --git a/mm/bpf_memcontrol.c b/mm/bpf_memcontrol.c
> index 716df49d7647..415e3c59b6a6 100644
> --- a/mm/bpf_memcontrol.c
> +++ b/mm/bpf_memcontrol.c

[ ... ]

> +static void clean_memcg_bpf_ops(struct mem_cgroup *memcg,
> +                             struct memcg_bpf_ops *ops)
> +{
> +     struct mem_cgroup *iter = NULL;
> +
> +     while ((iter = mem_cgroup_iter(memcg, iter, NULL))) {
> +             if (ops) {
> +                     if (!WARN_ON(READ_ONCE(memcg->bpf_ops) != ops))
> +                             WRITE_ONCE(memcg->bpf_ops, NULL);
                                         ^^^^^

When ops is non-NULL, this code checks and writes to memcg->bpf_ops, but
should it be using iter->bpf_ops instead? The else branch at the bottom
correctly uses iter. As written, when called from bpf_memcg_ops_unreg()
with a non-NULL ops argument, this only clears the root cgroup's bpf_ops
pointer while leaving all descendant cgroups with stale pointers to the
ops structure that will be freed after synchronize_srcu().

> +             } else
> +                     WRITE_ONCE(iter->bpf_ops, NULL);
> +     }
> +}

[ ... ]

> +static int __init bpf_memcontrol_init(void)
> +{
> +     int err, err2;
> +
> +     err = register_btf_kfunc_id_set(BPF_PROG_TYPE_UNSPEC,
> +                                     &bpf_memcontrol_kfunc_set);
> +     if (err)
> +             pr_warn("error while registering bpf memcontrol kfuncs: %d", 
> err);
> +
> +     err2 = register_bpf_struct_ops(&bpf_memcg_bpf_ops, memcg_bpf_ops);
> +     if (err)
            ^^^

The condition here checks err but prints err2. Should this be "if (err2)"
to log when the struct_ops registration fails?

> +             pr_warn("error while registering memcontrol bpf ops: %d", err2);
> +
> +     return err ? err : err2;
> +}
> +late_initcall(bpf_memcontrol_init);

Note: The clean_memcg_bpf_ops() issue appears to be addressed in a later
commit in this series (90eaa9cd0346 "mm/bpf: Add BPF_F_ALLOW_OVERRIDE
support for memcg_bpf_ops") which removes and rewrites the function
entirely. However, the syntax errors in the stubs and the error check
typo in bpf_memcontrol_init() do not appear to be fixed in the series.


---
AI reviewed your patch. Please fix the bug or email reply why it's not a bug.
See: https://github.com/kernel-patches/vmtest/blob/master/ci/claude/README.md

CI run summary: https://github.com/kernel-patches/bpf/actions/runs/21280790825

Reply via email to