Re: [PATCH 4/6] selftests/bpf: libarena: Add calloc() call

[email protected]
Newsgroups org.kernel.vger.bpf
Message-ID <a60462e917e53f5f3372ae21a7d8ee422ab6fda09cbd31cfa64f87e1c8b962c0@mail.kernel.org>
> diff --git a/tools/testing/selftests/bpf/libarena/include/libarena/common.h b/tools/testing/selftests/bpf/libarena/include/libarena/common.h
> index 931ace9a49e2..d32a51ff5e7f 100644
> --- a/tools/testing/selftests/bpf/libarena/include/libarena/common.h
> +++ b/tools/testing/selftests/bpf/libarena/include/libarena/common.h
> @@ -49,6 +49,7 @@ extern volatile u64 asan_violated;
>  int arena_fls(__u64 word);
>
>  void __arena *arena_malloc(size_t size);
> +void __arena *arena_calloc(size_t ncount, size_t size);
>  void arena_free(void __arena *ptr);
>
>  /*
> @@ -61,6 +62,23 @@ void arena_free(void __arena *ptr);
>   */
>  #define arena_subprog_init() do { asm volatile ("" :: "r"(&arena)); } while (0)
>
> +/*
> + * BPF does not currently support the memset intrinsics. for large
> + * sequential copies, or assignments of large data structures,
> + * the frontend will generate an intrinsic that causes the BPF
> + * backend to exit due to a missing implementation. Provide
> + * implementations for the intrinsic.
> + */
> +static inline int arena_memset(s8 __arena *dst, s8 val, size_t size)
> +{
> +	size_t i;
> +
> +	for (i = zero; i < size && can_loop; i++)
> +		dst[i] = val;
> +
> +	return 0;
> +}

This comment was moved and reworded from asan.bpf.c, but now has three
issues. First, the sentence boundary is lost: it reads "support the
memset intrinsics. for large sequential copies" with a lowercase
"for" starting what appears to be a new sentence. The original had
"intrinsics. For large sequential copies" as a clear sentence break.

Second, "intrinsics" is plural here but only memset is provided. The
plural was accurate when the original comment listed
"memset/memcpy/memcmp", but that list was dropped.

Third, "Provide implementations for the intrinsic" doesn't match what
the code does. There's no memset symbol or lowering hook here, so
__builtin_memset(), a plain memset() call, or a large struct
assignment will still fail in the BPF backend. What's actually
provided is a helper that must be called explicitly as arena_memset().

The original comment was more accurate: "Provide a simple
implementation just for memset to use it for poisoning/unpoisoning
the map." A reader of the new comment might reasonably think the
compiler-generated intrinsic is now handled.

Could the comment be updated to reflect what this function actually
provides?

> diff --git a/tools/testing/selftests/bpf/libarena/src/asan.bpf.c b/tools/testing/selftests/bpf/libarena/src/asan.bpf.c
> index 5135d5c72a46..de656b69d13a 100644
> --- a/tools/testing/selftests/bpf/libarena/src/asan.bpf.c
> +++ b/tools/testing/selftests/bpf/libarena/src/asan.bpf.c

[ ... ]

> diff --git a/tools/testing/selftests/bpf/libarena/src/common.bpf.c b/tools/testing/selftests/bpf/libarena/src/common.bpf.c
> index 41b1de3452fe..d1af60b81838 100644
> --- a/tools/testing/selftests/bpf/libarena/src/common.bpf.c
> +++ b/tools/testing/selftests/bpf/libarena/src/common.bpf.c

[ ... ]


---
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/32062809860
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.