Re: [PATCH bpf-next 2/2] selftests/bpf: add inline assembly helpers to access array elements

From: Barret Rhoden
Date: Thu Jan 04 2024 - 16:32:53 EST


On 1/3/24 16:21, Andrii Nakryiko wrote:
On Wed, Jan 3, 2024 at 12:06 PM Barret Rhoden<brho@xxxxxxxxxx> wrote:
On 1/3/24 14:51, Andrii Nakryiko wrote:
I'm curious how bpf_cmp_likely/bpf_cmp_unlikely (just applied to
bpf-next) compares to this?
these work great!

e.g.

if (bpf_cmp_likely(idx, <, NR_MAP_ELEMS))
map_elems[idx] = i;

works fine. since that's essentially the code that bpf_array_elem() was
trying to replace, i'd rather just use the new bpf_cmp helpers than have
the special array_elem helpers.
ok, cool, thanks for checking! The less special macros, the better.

sorry - turns out it only worked in testing. in my actual program, i still run into issues. the comparison is done, which is what bpf_cmp enforces. but the compiler is discarding the comparison. i have more info in the other thread, but figured i'd mention it here too. =(