From mboxrd@z Thu Jan 1 00:00:00 1970 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=1796181587; b=fixfA1000KAMvqUB6Jz6aQfUpqLB40PEXH276vfMV52sHgtpEy7hapcugYt+7tYelyr8 6nGibThYfsxjZt2NHdOxU1P6DLMWbkqqcHEs7HUNFcYY1cYO0CC9/Y4J5H+5TtvhdAW3N 2U7ga8Z4IFd4XDS6a1qpyC9PryombW+Er0/e2Qv7zckA08CRZGmFlH9wWazoli2BCkzLE 8zJwbj5/WUgHvcj8jyiyi7LbtSp53mZfld6pP5lB++hOTT5rJbZzkQRqvoJCDo397I+WG nBp3UzivORdhFaZVwYax52uVJUuMq/4/BRU8r/1WhoHFUgIEwTdwxvpyVALrOgnwtvg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796181587; h=Received:DKIM-Signature:Content-Type:MIME-Version:Message-Id: In-Reply-To:References:Subject:From:To:Cc:Date; bh=zl+fBYSES9sXol/IEOk6s0xHNO2Vk6ZOFheLoRhXxVI=; b=llf9S9jNmSYhb4jBzrfZc4jGELxsi9LmAjfLRpa/dM6NVq0hcTkBxqOr1KAbdXIXlP1x 8/26BJsxwjr8kZrp3nzhVzVIimN1SOH4fatlOYs2ugZt5U/UwUJJJhTtqwpfDExBu/ePa 4CBOBk8T2tVEkOb8Vz+dGDsfWTM6LAw/xRzNXfALORnFMzwELc6rXU06fzHX/F/KfdZ4g XyRlqbu69Gv5DVrJfK38Vy+v8Vg+0amN95n/Z9anw4fK4KFFHGUQxn4xMHBgT8zUKid9c pf9Xj0H/a6yeyJrl2iWaI55wO9PRNVvQp2goLZPd7iuApOhhd6CllCnW/6fD3hsjyWQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b="GgIB/Vdm"; 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 89DA3606A32A; Wed, 2 Dec 2026 03:19:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=GgIB/Vdm Received: by smtp.kernel.org (Postfix) with ESMTPSA id DD12C1F00893; Wed, 2 Dec 2026 03:19:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796181587; bh=zl+fBYSES9sXol/IEOk6s0xHNO2Vk6ZOFheLoRhXxVI=; h=In-Reply-To:References:Subject:From:To:Cc:Date; b=GgIB/VdmQ1Ruvasmjy3mGDZusCOIQV1ljhZbywSmp59LOtBGaJ6PdCRM4UrUuaygI OrpBiFOR15f+5I7og0K0VYzHaDhMoykqfY3GjTJO4EFSSS7hJxJzftmTUvZgUpDY79 A6lTP85aoc85Cs7/Au5w2yJqTlfiIj8V4JkJeb/LkC6rsSK8CcgQUwuLBH4Jocrmu8 5n/QLa4pMe8LRQ3fD1cRK/mu+Hl2P/aNTuBJSdD09XLRYd5fk18Uj0ZmVZg1NE5GPU 5vt+G7KH77cx062r60OIXm7V7nmnCt6nOU5g8tx5F50pxEO1RBVPS6eB1RD0NgjlV4 obMprbWsqF90A== Content-Type: multipart/mixed; boundary="===============2987370516826855286==" X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Message-Id: <512e79b4496e5fce49ead171f27601bf869950e7ae54704276e47ff50a2963e2@mail.kernel.org> In-Reply-To: <20261202023506.35176-2-kmehltretter@gmail.com> References: <20261202023506.35176-2-kmehltretter@gmail.com> Subject: Re: [RFC PATCH v3 1/2] bpf: Move arena allocations and frees outside arena->spinlock From: bot+bpf-ci@kernel.org To: kmehltretter@gmail.com,bigeasy@linutronix.de,ast@kernel.org,vbabka@kernel.org Cc: kmehltretter@gmail.com,harry@kernel.org,akpm@linux-foundation.org,peterz@infradead.org,tglx@linutronix.de,daniel@iogearbox.net,andrii@kernel.org,martin.lau@linux.dev,eddyz87@gmail.com,memxor@gmail.com,song@kernel.org,yonghong.song@linux.dev,jolsa@kernel.org,emil@etsalapatis.com,ihor.solodrai@linux.dev,ameryhung@gmail.com,david@kernel.org,ljs@kernel.org,liam@infradead.org,rppt@kernel.org,surenb@google.com,mhocko@suse.com,swarajgaikwad1925@gmail.com,clrkwllms@kernel.org,rostedt@goodmis.org,bpf@vger.kernel.org,linux-mm@kvack.org,linux-rt-devel@lists.linux.dev,linux-kernel@vger.kernel.org,ast@kernel.org,andrii@kernel.org,daniel@iogearbox.net,martin.lau@kernel.org,eddyz87@gmail.com,yonghong.song@linux.dev,mason@kernel.org,ihor.solodrai@linux.dev Date: Wed, 2 Dec 2026 03:19:43 +0000 (UTC) --===============2987370516826855286== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit > bpf: Move arena allocations and frees outside arena->spinlock TL;DR: - arena_alloc_pages() and arena_reserve_pages() now preallocate a spare node, so they may return -ENOMEM or 0 on allocation failure where they previously succeeded, including on PREEMPT_RT. - Possible extra alloc/free per arena allocation. > diff --git a/kernel/bpf/arena.c b/kernel/bpf/arena.c > --- a/kernel/bpf/arena.c > +++ b/kernel/bpf/arena.c [ ... ] > @@ -886,6 +895,8 @@ static long arena_alloc_pages(struct bpf_arena *arena, long uaddr, long page_cnt > return 0; > } > bpf_map_memcg_enter(&arena->map, &old_memcg, &new_memcg); > + if (range_tree_nodes_prepare(&range_nodes)) > + goto out_memcg; > > ret = bpf_alloc_pages(node_id, page_cnt, &pages, sleepable); > if (ret) When uaddr == 0, arena_adjust_tree() takes the range_tree_find() path and range_tree_clear() starts at the found node's rn_start, so the node is only trimmed or removed and the spare is never used: ret = range_tree_find(&arena->rt, page_cnt); ... *pgoff = ret; return range_tree_clear(&arena->rt, *pgoff, page_cnt, range_nodes); Before this patch that path allocated no range_node. Now arena_alloc_pages() fails and returns 0 if kmalloc_nolock() fails here. Can this regress a sleepable bpf_arena_alloc_pages(&arena, NULL, 1, NUMA_NO_NODE, 0) call? If the map's memcg is at memory.max and the per-CPU obj stock has no bytes for this objcg, the kmalloc_nolock() charge goes through __memcg_slab_post_alloc_hook() -> __obj_cgroup_charge() -> try_charge_memcg(), where !gfpflags_allow_blocking() goes to nomem and the allocation returns NULL. Previously the same call reclaimed through bpf_alloc_page() with GFP_KERNEL | __GFP_ACCOUNT | __GFP_RETRY_MAYFAIL and then cleared the range without any kmalloc. kmalloc_nolock() can also return NULL on trylock contention. This also adds a kmalloc_nolock()/kfree_nolock() pair to every arena allocation, including the arena stack allocation done by bpf_arena_stack_get(). Would it work to prepare the node only when uaddr != 0, since only the fixed-address path can split an interval? [ ... ] > @@ -1262,8 +1285,16 @@ static int arena_reserve_pages(struct bpf_arena *arena, long uaddr, u32 page_cnt > if (pgoff + page_cnt > page_cnt_max) > return -EINVAL; > > - if (raw_res_spin_lock_irqsave(&arena->spinlock, flags)) > - return -EBUSY; > + bpf_map_memcg_enter(&arena->map, &old_memcg, &new_memcg); > + if (range_tree_nodes_prepare(&range_nodes)) { > + ret = -ENOMEM; > + goto out_memcg; > + } > + > + if (raw_res_spin_lock_irqsave(&arena->spinlock, flags)) { > + ret = -EBUSY; > + goto out_free_node; > + } > > /* Cannot guard already allocated pages. */ > ret = is_range_tree_set(&arena->rt, pgoff, page_cnt); Does this make arena_reserve_pages() fail with -ENOMEM for reservations that need no spare node? range_tree_clear() only consumes the spare when it splits an interval (rn->rn_start < start && rn->rn_last > last). A reservation at either edge of a free interval only trims it. For example, reserving the first N pages of a fresh arena, whose tree holds [0, max-1], takes the right side branch. Before this patch such a reservation allocated nothing and could not fail for lack of memory. kmalloc_nolock() returns NULL without trying when can_spin_trylock() is false. With the next patch in the series, e1c6badba891 ("mm: restrict can_spin_trylock() to preemptible context on PREEMPT_RT"), that covers every non-preemptible context on PREEMPT_RT. bpf_arena_reserve_pages() is registered KF_SPINLOCK_SAFE, so a program may call it under bpf_spin_lock (IRQs off), and it can also be called from kprobe or tracepoint programs. On PREEMPT_RT in those contexts every reservation would then return -ENOMEM, including the edge-aligned ones, where without this patch only splitting reservations would fail. On other configurations the same check adds a failure when the nolock trylock or the non-reclaiming __GFP_ACCOUNT charge fails. arena_free_range() in the same patch handles this differently: it calls range_tree_nodes_prepare() and ignores the result, so range_tree_set() fails only when it really needs the node. Would doing the same here, dropping the check and letting range_tree_clear() report -ENOMEM, keep the old behaviour for non-splitting reservations? The same pattern in arena_alloc_pages() (the issue above) also puts a non-reclaiming kmalloc_nolock() ahead of the reclaiming bpf_alloc_page() for sleepable callers. --- 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/46798506165 --===============2987370516826855286==--