OSDN Git Service

bpf: Add batch ops to all htab bpf map
authorYonghong Song <yhs@fb.com>
Wed, 15 Jan 2020 18:43:04 +0000 (10:43 -0800)
committerAlexei Starovoitov <ast@kernel.org>
Wed, 15 Jan 2020 22:00:35 +0000 (14:00 -0800)
commit057996380a42bb64ccc04383cfa9c0ace4ea11f0
tree8cdd6bfa636e365b25f6ddc96c7955fa39254969
parentc60f2d2861778de6370a4f4ca6ab1d7d4a32efae
bpf: Add batch ops to all htab bpf map

htab can't use generic batch support due some problematic behaviours
inherent to the data structre, i.e. while iterating the bpf map  a
concurrent program might delete the next entry that batch was about to
use, in that case there's no easy solution to retrieve the next entry,
the issue has been discussed multiple times (see [1] and [2]).

The only way hmap can be traversed without the problem previously
exposed is by making sure that the map is traversing entire buckets.
This commit implements those strict requirements for hmap, the
implementation follows the same interaction that generic support with
some exceptions:

 - If keys/values buffer are not big enough to traverse a bucket,
   ENOSPC will be returned.
 - out_batch contains the value of the next bucket in the iteration, not
   the next key, but this is transparent for the user since the user
   should never use out_batch for other than bpf batch syscalls.

This commits implements BPF_MAP_LOOKUP_BATCH and adds support for new
command BPF_MAP_LOOKUP_AND_DELETE_BATCH. Note that for update/delete
batch ops it is possible to use the generic implementations.

[1] https://lore.kernel.org/bpf/20190724165803.87470-1-brianvv@google.com/
[2] https://lore.kernel.org/bpf/20190906225434.3635421-1-yhs@fb.com/

Signed-off-by: Yonghong Song <yhs@fb.com>
Signed-off-by: Brian Vazquez <brianvv@google.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Link: https://lore.kernel.org/bpf/20200115184308.162644-6-brianvv@google.com
include/linux/bpf.h
include/uapi/linux/bpf.h
kernel/bpf/hashtab.c
kernel/bpf/syscall.c