Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1793216119; b=mJgCZU+B6hE7/g0o3tbFZ6dPRRV/dH4JEXeMEuJtY+e3/raHTJNn9Hh+kbvikak8Yp19 7P7X2F9dRBmoubtkCuHBJc13atONcV5wOZmlNCFQkfcAu2w0T1/zB2BfGuoyGDZuGVKUi S71qFH0Et2crd1DJ3YrW/Z6tYTaC7Is1Gd7uH/850m/eqekCqAEbRxyZMGJLK8Hubelr8 U9xkeBi0HJogiu2NIizTWpXdwXHfR1zWY07gtWQ+lDOlUIgpKNuo13WLNZGWfXGqop7Pf qWw8PitILM0fYhWEmZO33bAJew7xOUyV5wwWhn97ZdeBKP+YbjTAb4+TJC9HVoC/+JA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1793216119; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=WaujTV3bx8qk//TG1o3jAFppFSYOFud5XVGImV9sr5s=; b=XlZY4FhCeushOemiaXf6GE4aN+RwSM94rnwP2En2bQnp9CKo08WsJDwJP2K0d+SJSD3r kJ7e5dqx2mHdTFMv/1UWuvt6IrRNn9yScUu7gJFbprCvyVNe6kW54OhSXNy2rbESS4Wxa +HF2VFkeK71JJjeaB+DRUCnlrzPtrf0jfJJH//GFuH6bM3+nmDeGEQnUEWNHLwXK4z6CO Iq8IUGMjVtXaO68LivtYC8SB9RSbHUBv2ffbUzhVsqVDT4Dpeyv1uLq3m19ZhzEc2c6Xn 6LosOR6VKx6JkxJPd9whkVtSd7+KPnLr6Olrag4vNH3ue4ASZRAokJKkne0WTFfrEFA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=Z60TWLhn; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F3142606A31A; Wed, 28 Oct 2026 19:35:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key, unprotected) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=Z60TWLhn Received: by smtp.kernel.org (Postfix) with ESMTPSA id 47A4E1F01825; Wed, 28 Oct 2026 19:35:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1793216118; bh=WaujTV3bx8qk//TG1o3jAFppFSYOFud5XVGImV9sr5s=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=Z60TWLhnqUoGekehmecZHZWbLcKS3II6oVXVes4k1C2+rOQUflgWJlXWKAUhxAlor nroelsKDvnwmA8adxZfRvUWJM2gwC+7JWQds2M8UO8DENn6y0M2NVM8smss5DCX4xV boTGJ8yZ+oKp4ci6DcWYs+jWYTu/T+K7Hd4aovx8= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Shakeel Butt , Peilin Ye , Alexei Starovoitov , Sasha Levin Subject: [PATCH 6.1 1446/1887] bpf: Tell memcg to use allow_spinning=false path in bpf_timer_init() Date: Wed, 28 Oct 2026 17:59:02 +0100 Message-ID: <20261028170532.364105847@linuxfoundation.org> X-Mailer: git-send-email 2.56.0 In-Reply-To: <20261028170459.200466217@linuxfoundation.org> References: <20261028170459.200466217@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: patches@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.1-stable review patch. If anyone has any objections, please let me know. ------------------ From: Peilin Ye [ Upstream commit 6d78b4473cdb08b74662355a9e8510bde09c511e ] Currently, calling bpf_map_kmalloc_node() from __bpf_async_init() can cause various locking issues; see the following stack trace (edited for style) as one example: ... [10.011566] do_raw_spin_lock.cold [10.011570] try_to_wake_up (5) double-acquiring the same [10.011575] kick_pool rq_lock, causing a hardlockup [10.011579] __queue_work [10.011582] queue_work_on [10.011585] kernfs_notify [10.011589] cgroup_file_notify [10.011593] try_charge_memcg (4) memcg accounting raises an [10.011597] obj_cgroup_charge_pages MEMCG_MAX event [10.011599] obj_cgroup_charge_account [10.011600] __memcg_slab_post_alloc_hook [10.011603] __kmalloc_node_noprof ... [10.011611] bpf_map_kmalloc_node [10.011612] __bpf_async_init [10.011615] bpf_timer_init (3) BPF calls bpf_timer_init() [10.011617] bpf_prog_xxxxxxxxxxxxxxxx_fcg_runnable [10.011619] bpf__sched_ext_ops_runnable [10.011620] enqueue_task_scx (2) BPF runs with rq_lock held [10.011622] enqueue_task [10.011626] ttwu_do_activate [10.011629] sched_ttwu_pending (1) grabs rq_lock ... The above was reproduced on bpf-next (b338cf849ec8) by modifying ./tools/sched_ext/scx_flatcg.bpf.c to call bpf_timer_init() during ops.runnable(), and hacking the memcg accounting code a bit to make a bpf_timer_init() call more likely to raise an MEMCG_MAX event. We have also run into other similar variants (both internally and on bpf-next), including double-acquiring cgroup_file_kn_lock, the same worker_pool::lock, etc. As suggested by Shakeel, fix this by using __GFP_HIGH instead of GFP_ATOMIC in __bpf_async_init(), so that e.g. if try_charge_memcg() raises an MEMCG_MAX event, we call __memcg_memory_event() with @allow_spinning=false and avoid calling cgroup_file_notify() there. Depends on mm patch "memcg: skip cgroup_file_notify if spinning is not allowed": https://lore.kernel.org/bpf/20250905201606.66198-1-shakeel.butt@linux.dev/ v0 approach s/bpf_map_kmalloc_node/bpf_mem_alloc/ https://lore.kernel.org/bpf/20250905061919.439648-1-yepeilin@google.com/ v1 approach: https://lore.kernel.org/bpf/20250905234547.862249-1-yepeilin@google.com/ Fixes: b00628b1c7d5 ("bpf: Introduce bpf timers.") Suggested-by: Shakeel Butt Signed-off-by: Peilin Ye Link: https://lore.kernel.org/r/20250909095222.2121438-1-yepeilin@google.com Signed-off-by: Alexei Starovoitov Signed-off-by: Sasha Levin --- kernel/bpf/helpers.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/kernel/bpf/helpers.c b/kernel/bpf/helpers.c index a5ab200c48663..a89a88b5fb985 100644 --- a/kernel/bpf/helpers.c +++ b/kernel/bpf/helpers.c @@ -1214,8 +1214,11 @@ BPF_CALL_3(bpf_timer_init, struct bpf_timer_kern *, timer, struct bpf_map *, map ret = -EBUSY; goto out; } - /* allocate hrtimer via map_kmalloc to use memcg accounting */ - t = bpf_map_kmalloc_node(map, sizeof(*t), GFP_ATOMIC, map->numa_node); + /* Allocate via bpf_map_kmalloc_node() for memcg accounting. Until + * kmalloc_nolock() is available, avoid locking issues by using + * __GFP_HIGH (GFP_ATOMIC & ~__GFP_RECLAIM). + */ + t = bpf_map_kmalloc_node(map, sizeof(*t), __GFP_HIGH, map->numa_node); if (!t) { ret = -ENOMEM; goto out; -- 2.53.0