From: "Kumar Kartikeya Dwivedi" <memxor@gmail.com>
To: <sashiko-reviews@lists.linux.dev>,
"Emil Tsalapatis" <emil@etsalapatis.com>
Cc: <bpf@vger.kernel.org>
Subject: Re: [PATCH 3/6] selftests/bpf: libarena: Disable IRQs during allocation
Date: Thu, 20 Aug 2026 21:28:00 +0200 [thread overview]
Message-ID: <DKU0P1YGJWHF.3PPZPRDGZX4I3@gmail.com> (raw)
In-Reply-To: <20260817192833.63B111F000E9@smtp.kernel.org>
On Mon Aug 17, 2026 at 9:28 PM CEST, sashiko-bot wrote:
> Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
>
> Pre-existing issues:
> - [High] Unhandled lock failure path in `buddy_alloc` and `buddy_alloc_from_new_chunk` leaks newly allocated memory chunks.
> --
>
> --- Patch [3]: [PATCH 3/6] selftests/bpf: libarena: Disable IRQs during allocation ---
> commit 33cf3ed979bbaa281367dbd5d393dc12a91a1af9
> Author: Emil Tsalapatis <emil@etsalapatis.com>
>
> selftests/bpf: libarena: Disable IRQs during allocation
>
> This commit updates the buddy allocator in libarena to use IRQ-saving
> spinlocks to prevent ABBA deadlocks. These deadlocks were observed with
> sched_ext schedulers when an IRQ interrupts an allocation and subsequently
> attempts to take runqueue locks.
>
>> diff --git a/tools/testing/selftests/bpf/libarena/src/buddy.bpf.c b/tools/testing/selftests/bpf/libarena/src/buddy.bpf.c
>> index c674ee5cfcc1d..2490ab1396de0 100644
>> --- a/tools/testing/selftests/bpf/libarena/src/buddy.bpf.c
>> +++ b/tools/testing/selftests/bpf/libarena/src/buddy.bpf.c
>
> [ ... ]
>
>> @@ -730,9 +727,10 @@ static u64 buddy_alloc_from_existing_chunks(struct buddy __arena *buddy, int ord
>> */
>> static u64 buddy_alloc_from_new_chunk(struct buddy __arena *buddy, struct buddy_chunk __arena *chunk, int order)
>> {
>> + unsigned long flags;
>> u64 address;
>>
>> - if (buddy_lock(buddy))
>> + if (buddy_lock(buddy, flags))
>> return (u64)NULL;
>
> [Severity: High]
> This isn't a bug introduced by this patch, but does this leak the newly
> allocated arena chunk if the lock acquisition fails?
>
> When buddy_alloc() needs more memory, it allocates a chunk and passes it
> here:
>
> buddy_alloc()
> chunk = buddy_chunk_get(buddy);
> if (chunk)
> address = buddy_alloc_from_new_chunk(buddy, chunk, order);
>
> If buddy_lock() fails in buddy_alloc_from_new_chunk() (for example, returning
> an error like -ETIMEDOUT under heavy contention), it returns NULL without
> linking the new chunk to buddy->first_chunk.
>
> The NULL return then propagates up to buddy_alloc(), which discards the chunk
> pointer completely without freeing it. Since BPF MCS spinlocks can fail under
> heavy task load, could this predictably exhaust arena memory?
>
> Should this error path call bpf_arena_free_pages() on the orphaned chunk
> before returning?
>
The rest are meh, but this one seems plausible. Please check and follow up.
>>
>>
>> @@ -745,7 +743,7 @@ static u64 buddy_alloc_from_new_chunk(struct buddy __arena *buddy, struct buddy_
>>
>> address = buddy_chunk_alloc(buddy->first_chunk, order);
>>
>> - buddy_unlock(buddy);
>> + buddy_unlock(buddy, flags);
>>
>> return (u64)address;
>> }
>
> [ ... ]
next prev parent reply other threads:[~2026-08-20 19:28 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-17 19:16 [PATCH 0/6] selftests/bpf: Fixes and improvements for libarena Emil Tsalapatis
2026-08-17 19:16 ` [PATCH 1/6] selftests/bpf: libarena: Normalize SPDX headers across files Emil Tsalapatis
2026-08-17 19:21 ` sashiko-bot
2026-08-17 19:16 ` [PATCH 2/6] selftests/bpf: libarena: Inline nonatomic bitmap operations Emil Tsalapatis
2026-08-17 19:26 ` sashiko-bot
2026-08-17 20:25 ` bot+bpf-ci
2026-08-17 19:16 ` [PATCH 3/6] selftests/bpf: libarena: Disable IRQs during allocation Emil Tsalapatis
2026-08-17 19:28 ` sashiko-bot
2026-08-20 19:28 ` Kumar Kartikeya Dwivedi [this message]
2026-08-17 20:38 ` bot+bpf-ci
2026-08-17 19:16 ` [PATCH 4/6] selftests/bpf: libarena: Add calloc() call Emil Tsalapatis
2026-08-17 19:23 ` sashiko-bot
2026-08-17 20:25 ` bot+bpf-ci
2026-08-17 19:16 ` [PATCH 5/6] selftests/bpf: libarena: Add a benchmark for malloc()/calloc() Emil Tsalapatis
2026-08-17 19:31 ` sashiko-bot
2026-08-17 20:25 ` bot+bpf-ci
2026-08-17 19:16 ` [PATCH 6/6] selftests/bpf: libarena: Optimize and make public arena_memset Emil Tsalapatis
2026-08-17 20:25 ` bot+bpf-ci
2026-08-20 19:20 ` [PATCH 0/6] selftests/bpf: Fixes and improvements for libarena patchwork-bot+netdevbpf
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=DKU0P1YGJWHF.3PPZPRDGZX4I3@gmail.com \
--to=memxor@gmail.com \
--cc=bpf@vger.kernel.org \
--cc=emil@etsalapatis.com \
--cc=sashiko-reviews@lists.linux.dev \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.