selftests/bpf: libarena: Directly return arena pointers from functions

Now that the __arena annotation includes a BTF type tag, and the
verifier can identify arena pointers at BTF loading time, return
arena pointers as their true type instead of casting to u64. Remove the
preprocessor typecast wrappers used to hide this from the caller.

Acked-by: Eduard Zingerman <eddyz87@gmail.com>
Signed-off-by: Emil Tsalapatis <emil@etsalapatis.com>
Link: https://lore.kernel.org/r/20260602004120.17087-6-emil@etsalapatis.com
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
This commit is contained in:
Emil Tsalapatis 2026-06-01 20:41:19 -04:00 committed by Alexei Starovoitov
parent b9b23fe176
commit 367e6e4a81
4 changed files with 14 additions and 16 deletions

View File

@ -76,7 +76,6 @@ struct buddy {
int buddy_init(struct buddy __arena *buddy);
int buddy_destroy(struct buddy __arena *buddy);
int buddy_free(struct buddy __arena *buddy, void __arena *free);
u64 buddy_alloc_internal(struct buddy __arena *buddy, size_t size);
#define buddy_alloc(alloc, size) ((void __arena *)buddy_alloc_internal((alloc), (size)))
void __arena *buddy_alloc(struct buddy __arena *buddy, size_t size);
#endif /* __BPF__ */

View File

@ -48,8 +48,7 @@ extern volatile u64 asan_violated;
int arena_fls(__u64 word);
u64 arena_malloc_internal(size_t size);
#define arena_malloc(size) ((void __arena *)arena_malloc_internal((size)))
void __arena *arena_malloc(size_t size);
void arena_free(void __arena *ptr);
/*

View File

@ -750,25 +750,25 @@ static u64 buddy_alloc_from_new_chunk(struct buddy __arena *buddy, struct buddy_
return (u64)address;
}
__weak
u64 buddy_alloc_internal(struct buddy __arena *buddy, size_t size)
void __arena *buddy_alloc(struct buddy __arena *buddy, size_t size)
{
u64 address = (u64)NULL;
void __arena *address = NULL;
struct buddy_chunk __arena *chunk;
int order;
if (!buddy)
return (u64)NULL;
return NULL;
order = size_to_order(size);
if (order >= BUDDY_CHUNK_NUM_ORDERS || order < 0) {
arena_stderr("invalid order %d (sz %lu)\n", order, size);
return (u64)NULL;
return NULL;
}
if (buddy_lock(buddy))
return (u64)NULL;
return NULL;
address = buddy_alloc_from_existing_chunks(buddy, order);
address = (u8 __arena *)buddy_alloc_from_existing_chunks(buddy, order);
buddy_unlock(buddy);
if (address)
goto done;
@ -776,12 +776,12 @@ u64 buddy_alloc_internal(struct buddy __arena *buddy, size_t size)
/* Get a new chunk. */
chunk = buddy_chunk_get(buddy);
if (chunk)
address = buddy_alloc_from_new_chunk(buddy, chunk, order);
address = (u8 __arena *)buddy_alloc_from_new_chunk(buddy, chunk, order);
done:
/* If we failed to allocate memory, return NULL. */
if (!address)
return (u64)NULL;
return NULL;
/*
* Unpoison exactly the amount of bytes requested. If the
@ -789,10 +789,10 @@ u64 buddy_alloc_internal(struct buddy __arena *buddy, size_t size)
* unused bytes that were part of the header.
*/
if (size < BUDDY_HEADER_OFF + sizeof(struct buddy_header __arena))
asan_poison((u8 __arena *)address + BUDDY_HEADER_OFF, BUDDY_POISONED,
asan_poison(address + BUDDY_HEADER_OFF, BUDDY_POISONED,
sizeof(struct buddy_header __arena));
asan_unpoison((u8 __arena *)address, size);
asan_unpoison(address, size);
return address;
}

View File

@ -38,9 +38,9 @@ __weak int arena_buddy_reset(void)
return buddy_init(&buddy);
}
__weak u64 arena_malloc_internal(size_t size)
__weak void __arena *arena_malloc(size_t size)
{
return buddy_alloc_internal(&buddy, size);
return buddy_alloc(&buddy, size);
}
__weak void arena_free(void __arena *ptr)