[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <dae9aa2f4d4de48d86d1e65ab1ce73e01bcff2d003361feb26d06d91eb15b6f7@mail.kernel.org>
Date: Mon, 26 Jan 2026 09:30:25 +0000 (UTC)
From: bot+bpf-ci@...nel.org
To: hui.zhu@...ux.dev,akpm@...ux-foundation.org,hannes@...xchg.org,mhocko@...nel.org,roman.gushchin@...ux.dev,shakeel.butt@...ux.dev,muchun.song@...ux.dev,ast@...nel.org,daniel@...earbox.net,andrii@...nel.org,martin.lau@...ux.dev,eddyz87@...il.com,song@...nel.org,yonghong.song@...ux.dev,john.fastabend@...il.com,kpsingh@...nel.org,sdf@...ichev.me,haoluo@...gle.com,jolsa@...nel.org,shuah@...nel.org,peterz@...radead.org,ojeda@...nel.org,nathan@...nel.org,kees@...nel.org,tj@...nel.org,jeffxu@...omium.org,mkoutny@...e.com,kernel@...rr.cc,brauner@...nel.org,rdunlap@...radead.org,brgerst@...il.com,masahiroy@...nel.org,davem@...emloft.net,kuba@...nel.org,hawk@...nel.org,inwardvessel@...il.com,willemb@...gle.com,kerneljasonxing@...il.com,paul.chaignon@...il.com,a.s.protopopov@...il.com,ameryhung@...il.com,chenridong@...weicloud.com,lance.yang@...ux.dev,jiayuan.chen@...ux.dev,linux-kernel@...r.kernel.org,linux-mm@...ck.org,cgroups@...r.kernel.org,bpf@...r.kernel.org,netdev@...r.kernel.org,linu
x-kselftest@...r.kernel.org
Cc: zhuhui@...inos.cn,geliang@...nel.org,ast@...nel.org,andrii@...nel.org,daniel@...earbox.net,martin.lau@...nel.org,eddyz87@...il.com,yonghong.song@...ux.dev,clm@...a.com,ihor.solodrai@...ux.dev
Subject: Re: [RFC PATCH bpf-next v4 08/12] mm: memcontrol: Add BPF struct_ops for memory controller
> diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h
> index f3b8c71870d8..1083be5d0362 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 two stubs are missing the bool return type. This will cause a
compilation error when CONFIG_BPF_SYSCALL is not set. Should these be:
static inline bool bpf_memcg_below_low(...)
static inline bool bpf_memcg_below_min(...)
> +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..20c5c3552ce3 100644
> --- a/mm/bpf_memcontrol.c
> +++ b/mm/bpf_memcontrol.c
[ ... ]
> +static int bpf_memcg_ops_reg(void *kdata, struct bpf_link *link)
> +{
> + struct bpf_struct_ops_link *ops_link
> + = container_of(link, struct bpf_struct_ops_link, link);
> + struct memcg_bpf_ops *ops = kdata;
> + struct mem_cgroup *memcg, *iter = NULL;
> + int err = 0;
> +
> + memcg = mem_cgroup_get_from_ino(ops_link->cgroup_id);
> + if (IS_ERR_OR_NULL(memcg))
> + return PTR_ERR(memcg);
> +
> + cgroup_lock();
> + while ((iter = mem_cgroup_iter(memcg, iter, NULL))) {
> + if (READ_ONCE(iter->bpf_ops)) {
> + mem_cgroup_iter_break(memcg, iter);
> + err = -EBUSY;
> + break;
> + }
> + WRITE_ONCE(iter->bpf_ops, ops);
> + }
> + if (err)
> + clean_memcg_bpf_ops(memcg, NULL);
^^^^
When registration fails because a descendant cgroup already has a BPF
program attached, this calls clean_memcg_bpf_ops() with NULL. Looking at
clean_memcg_bpf_ops():
while ((iter = mem_cgroup_iter(memcg, iter, NULL))) {
if (ops) {
if (!WARN_ON(READ_ONCE(iter->bpf_ops) != ops))
WRITE_ONCE(iter->bpf_ops, NULL);
} else
WRITE_ONCE(iter->bpf_ops, NULL); // unconditional clear
}
With ops=NULL, this will unconditionally clear bpf_ops for all
descendants in the hierarchy, including the cgroup that already had a
different BPF program attached (which caused the -EBUSY error). This
would incorrectly detach that existing program.
Should this be clean_memcg_bpf_ops(memcg, ops) instead, so it only clears
the ops that were written during this failed registration attempt?
Note: This issue appears to be addressed in the subsequent commit
5f3bb9a8c33f ("mm/bpf: Add BPF_F_ALLOW_OVERRIDE support for
memcg_bpf_ops") which completely rewrites the registration logic.
> + cgroup_unlock();
> +
> + mem_cgroup_put(memcg);
> + return err;
> +}
---
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/21352241149
Powered by blists - more mailing lists