Re: [PATCH] bpf: do not start from first bucket if elem is not found on a htab

From: Maciej Åenczykowski
Date: Mon Apr 01 2019 - 17:38:14 EST


> This breaks BPF selftest suite unfortunately:
>
> # ./test_maps
> test_maps: test_maps.c:114: test_hashmap: Assertion `bpf_map_get_next_key(fd, &key, &next_key) == 0 && (next_key == first_key)' failed.
> Aborted
>
> Some more background, situation is a bit tricky: pre 8fe45924387b ("bpf:
> map_get_next_key to return first key on NULL") there was no reliable way
> of getting to the start of a hash table, meaning it needed an 'invalid'
> key to return the first element for starting traversal which commit fixed
> by being able to pass in NULL. So some applications might still just rely
> on e.g. key of zero bytes (if guaranteed to not be used otherwise) to do
> just that. With this patch, we'd start out from anywhere in the hash table.

sdf@ just mentioned this internally as well... I think we simply will
need to add a flags field
with at least two options/flags:
- return error if key not found
- resume from bucket instead of beginning if key not found
and while we're at it:
- return concatenated key+value instead of just key to save an
immediate lookup on the returned key