Linux-mm Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Ben Gardon" <bgardon@google.com>,
	"Alexei Starovoitov" <ast@kernel.org>,
	"Daniel Borkmann" <daniel@iogearbox.net>,
	"Andrii Nakryiko" <andrii@kernel.org>,
	"Andrew Morton" <akpm@linux-foundation.org>,
	"Johannes Weiner" <hannes@cmpxchg.org>,
	"Michal Hocko" <mhocko@kernel.org>,
	"Shakeel Butt" <shakeel.butt@linux.dev>,
	"Roman Gushchin" <roman.gushchin@linux.dev>,
	"Tejun Heo" <tj@kernel.org>
Cc: "JP Kobryn" <jp.kobryn@linux.dev>,
	"Eduard Zingerman" <eddyz87@gmail.com>,
	"Kumar Kartikeya Dwivedi" <memxor@gmail.com>,
	"Martin KaFai Lau" <martin.lau@linux.dev>,
	"Song Liu" <song@kernel.org>,
	"Yonghong Song" <yonghong.song@linux.dev>,
	"Jiri Olsa" <jolsa@kernel.org>,
	"Emil Tsalapatis" <emil@etsalapatis.com>,
	"Ihor Solodrai" <ihor.solodrai@linux.dev>,
	"David Rientjes" <rientjes@google.com>,
	"Suren Baghdasaryan" <surenb@google.com>,
	"Josh Don" <joshdon@google.com>,
	"Sweet Tea Dorminy" <sweettea-kernel@dorminy.me>,
	"Chuyi Zhou" <zhouchuyi@bytedance.com>,
	"Yafang Shao" <laoar.shao@gmail.com>,
	benbwgardon@gmail.com, bpf@vger.kernel.org, linux-mm@kvack.org,
	"Muchun Song" <muchun.song@linux.dev>,
	mkoutny@suse.com
Subject: Re: [PATCH bpf-next v4 15/17] mm, bpf: introduce bpf_mem_cgroup_raise_max() kfunc
Date: Wed, 02 Dec 2026 21:45:21 +0000	[thread overview]
Message-ID: <sashiko-outbox-246659@kernel.org> (raw)
In-Reply-To: <20261202210415.517651-16-bgardon@google.com>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] mm: memcontrol-v1: lock ordering inversion in
  memcg1_raise_max() under oom_lock
--

commit d797e91b36bda7b1b912733cac44ec80ba2bf974
Author: Ben Gardon <bgardon@google.com>

mm, bpf: introduce bpf_mem_cgroup_raise_max() kfunc

This commit introduces the bpf_mem_cgroup_raise_max() kfunc and
mem_cgroup_raise_max() helper to allow BPF OOM handlers and proactive
programs to increase a non-root memory cgroup's hard limit.

> diff --git a/mm/memcontrol-v1.c b/mm/memcontrol-v1.c
> index b7f2868885071..d50fe775f1f3e 100644
> --- a/mm/memcontrol-v1.c
> +++ b/mm/memcontrol-v1.c
> @@ -1418,6 +1418,22 @@ void vmpressure_unregister_event(struct mem_cgroup *memcg,
>  
>  static DEFINE_MUTEX(memcg_max_mutex);
>  
> +int memcg1_raise_max(struct mem_cgroup *memcg, unsigned long max_pages)
> +{
> +	int ret = 0;
> +
> +	mutex_lock(&memcg_max_mutex);
> +	if (max_pages <= memcg->memory.max || max_pages > memcg->memsw.max)
> +		ret = -EINVAL;
> +	else
> +		WRITE_ONCE(memcg->memory.max, max_pages);
> +	mutex_unlock(&memcg_max_mutex);
> +
> +	if (!ret)
> +		memcg1_oom_recover(memcg);
> +	return ret;
> +}

[Severity: Medium]
Can locking memcg_max_mutex here cause a lock ordering inversion when
bpf_mem_cgroup_raise_max() is called from a bpf_oom_ops
handle_out_of_memory() callback under oom_lock?

memcg_update_tcp_max() holds memcg_max_mutex across static_branch_inc(),
which acquires cpu_hotplug_lock via cpus_read_lock():

mm/memcontrol-v1.c:memcg_update_tcp_max() {
	mutex_lock(&memcg_max_mutex);
	...
	if (!memcg->tcpmem_active) {
		static_branch_inc(&memcg_sockets_enabled_key);
		memcg->tcpmem_active = true;
	}
out:
	mutex_unlock(&memcg_max_mutex);
}

Elsewhere, cpu_hotplug_lock nests outside cgroup_threadgroup_rwsem and
oom_lock:

CPU0                              CPU1
----                              ----
lock(cpu_hotplug_lock)
lock(cgroup_threadgroup_rwsem)
                                  lock(memcg_max_mutex)
                                  lock(cpu_hotplug_lock)
lock(oom_lock)
lock(memcg_max_mutex)

 *** DEADLOCK ***

CPU0: copy_process() -> cgroup_can_fork() -> futex_hash_allocate_default()
      -> try_charge_memcg() -> mem_cgroup_out_of_memory()
      -> bpf_handle_oom() -> bpf_mem_cgroup_raise_max()
      -> memcg1_raise_max()
      (with cpu_hotplug_lock -> cgroup_threadgroup_rwsem established by
      cgroup_attach_lock())
CPU1: memcg_update_tcp_max() -> static_branch_inc()
      -> static_key_slow_inc() -> cpus_read_lock()

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261202210415.517651-1-bgardon@google.com?part=15


  reply	other threads:[~2026-12-02 21:45 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-02 21:03 [PATCH bpf-next v4 00/17] mm: BPF OOM Ben Gardon
2026-12-02 21:03 ` [PATCH bpf-next v4 01/17] bpf: mark struct oom_control's memcg field as TRUSTED_OR_NULL Ben Gardon
2026-12-02 21:03 ` [PATCH bpf-next v4 02/17] mm, bpf: introduce BPF OOM struct ops Ben Gardon
2026-12-02 21:59   ` bot+bpf-ci
2026-12-02 21:03 ` [PATCH bpf-next v4 03/17] mm, bpf: introduce bpf_oom_kill_process() BPF kfunc Ben Gardon
2026-12-02 21:58   ` bot+bpf-ci
2026-12-02 21:03 ` [PATCH bpf-next v4 04/17] mm, bpf: introduce bpf_out_of_memory() " Ben Gardon
2026-12-02 21:18   ` sashiko-bot
2026-12-02 21:59   ` bot+bpf-ci
2026-12-02 21:03 ` [PATCH bpf-next v4 05/17] selftests/bpf: Add BPF OOM struct ops test Ben Gardon
2026-12-02 21:03 ` [PATCH bpf-next v4 06/17] sched/psi: add a tracepoint to psi_avgs_work() Ben Gardon
2026-12-02 21:15   ` sashiko-bot
2026-12-02 21:03 ` [PATCH bpf-next v4 07/17] sched/psi: add cgroup_id field to psi_group structure Ben Gardon
2026-12-02 21:03 ` [PATCH bpf-next v4 08/17] mm, bpf: allow calling bpf_out_of_memory() from a PSI tracepoint Ben Gardon
2026-12-02 21:03 ` [PATCH bpf-next v4 09/17] selftests/bpf: Enable CONFIG_PSI Ben Gardon
2026-12-02 21:04 ` [PATCH bpf-next v4 10/17] selftests/bpf: Add PSI tracepoint OOM test Ben Gardon
2026-12-02 21:04 ` [PATCH bpf-next v4 11/17] selftests/bpf: Add systemd-oomd style OOM policy test Ben Gardon
2026-12-02 21:58   ` bot+bpf-ci
2026-12-02 21:04 ` [PATCH bpf-next v4 12/17] mm, bpf: introduce bpf_oom_proactive_kill() for proactive OOM prevention Ben Gardon
2026-12-02 21:58   ` bot+bpf-ci
2026-12-02 21:04 ` [PATCH bpf-next v4 13/17] selftests/bpf: Add bpf_oom_proactive_kill() proactive OOM test Ben Gardon
2026-12-02 21:04 ` [PATCH bpf-next v4 14/17] selftests/bpf: Add negative and verifier tests for BPF OOM kfuncs Ben Gardon
2026-12-02 21:15   ` sashiko-bot
2026-12-02 21:58   ` bot+bpf-ci
2026-12-02 21:04 ` [PATCH bpf-next v4 15/17] mm, bpf: introduce bpf_mem_cgroup_raise_max() kfunc Ben Gardon
2026-12-02 21:45   ` sashiko-bot [this message]
2026-12-02 21:58   ` bot+bpf-ci
2026-12-02 21:04 ` [PATCH bpf-next v4 16/17] selftests/bpf: Add bpf_mem_cgroup_raise_max() OOM test Ben Gardon
2026-12-02 21:04 ` [PATCH bpf-next v4 17/17] Documentation/bpf: Document BPF OOM handling and kfuncs Ben Gardon
2026-12-02 21:58   ` bot+bpf-ci
2026-12-02 21:38 ` [PATCH bpf-next v4 00/17] mm: BPF OOM Ben Gardon

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=sashiko-outbox-246659@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=akpm@linux-foundation.org \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=benbwgardon@gmail.com \
    --cc=bgardon@google.com \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=eddyz87@gmail.com \
    --cc=emil@etsalapatis.com \
    --cc=hannes@cmpxchg.org \
    --cc=ihor.solodrai@linux.dev \
    --cc=jolsa@kernel.org \
    --cc=joshdon@google.com \
    --cc=jp.kobryn@linux.dev \
    --cc=laoar.shao@gmail.com \
    --cc=linux-mm@kvack.org \
    --cc=martin.lau@linux.dev \
    --cc=memxor@gmail.com \
    --cc=mhocko@kernel.org \
    --cc=mkoutny@suse.com \
    --cc=muchun.song@linux.dev \
    --cc=rientjes@google.com \
    --cc=roman.gushchin@linux.dev \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=shakeel.butt@linux.dev \
    --cc=song@kernel.org \
    --cc=surenb@google.com \
    --cc=sweettea-kernel@dorminy.me \
    --cc=tj@kernel.org \
    --cc=yonghong.song@linux.dev \
    --cc=zhouchuyi@bytedance.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox