Skip to content

Add lookup_and_delete_elem support to BPF hash map types

Denis Salopek bpf 7 versions – Applied

Status from this message: Applied to bpf-next, thanks. Fixed up a small merge conflict in libbpf.map.

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v7 Latest3 patches 5 repliesApplied
  2. v63 patches 2 repliesSuperseded
  3. v53 patches 3 repliesSuperseded
Earlier versions · 4
VersionPostedPatchesRepliesStatus
v41 patch5 repliesSuperseded
v31 patch2 repliesSuperseded
v21 patch3 repliesSuperseded
v11 patch6 repliesSuperseded

Patches in v7 Applied

#Subject and filesSizeRepliesApplied
1/3bpf: add lookup_and_delete_elem support to hashtabinclude/linux/bpf.h include/uapi/linux/bpf.h kernel/bpf/hashtab.c +2 more+156 -40 replies
2/3bpf: extend libbpf with bpf_map_lookup_and_delete_elem_flagstools/lib/bpf/bpf.c tools/lib/bpf/bpf.h tools/lib/bpf/libbpf.map+16 -00 replies
3/3selftests/bpf: add bpf_lookup_and_delete_elem teststools/testing/selftests/bpf/prog_tests/lookup_and_delete.c tools/testing/selftests/bpf/progs/test_lookup_and_delete.c tools/testing/selftests/bpf/test_lru_map.c +1 more+339 -00 replies

Reviews trailers per patch

All 3 patches have a Reviewed-by or Acked-by.

PatchYonghong Song
1/3A-b
2/3A-b
3/3A-b

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v7 thread

Cover letter [PATCH v7 bpf-next 0/3] Add lookup_and_delete_elem support to BPF hash map types

This patch series extends the existing bpf_map_lookup_and_delete_elem() functionality with 4 more map types:
- BPF_MAP_TYPE_HASH,
- BPF_MAP_TYPE_PERCPU_HASH,
- BPF_MAP_TYPE_LRU_HASH and
- BPF_MAP_TYPE_LRU_PERCPU_HASH.

Patch 1 adds most of its functionality and logic as well as documentation.

As it was previously limited to only stacks and queues which do not support the BPF_F_LOCK flag, patch 2 enables its usage by adding a new libbpf API bpf_map_lookup_and_delete_elem_flags() based on the existing bpf_map_lookup_elem_flags().

Patch 3 adds selftests for lookup_and_delete_elem().

Changes in patch 1:
v7: Minor formating nits, add Acked-by.
v6: Remove unneeded flag check, minor code/format fixes.
v5: Split patch to 3 patches. Extend BPF_MAP_LOOKUP_AND_DELETE_ELEM documentation with this changes.
v4: Fix the return value for unsupported map types.
v3: Add bpf_map_lookup_and_delete_elem_flags() and enable BPF_F_LOCK flag, change CHECKs to ASSERT_OKs, initialize variables to 0.
v2: Add functionality for LRU/per-CPU, add test_progs tests.

Changes in patch 2:
v7: No change.
v6: Add Acked-by.
v5: Move to the newest libbpf version (0.4.0).

Changes in patch 3:
v7: Remove ASSERT_GE macro which is already added in some other commit, change ASSERT_OK to ASSERT_OK_PTR, add Acked-by.
v6: Remove PERCPU macros, add ASSERT_GE macro to test_progs.h, remove leftover code.
v5: Use more appropriate macros. Better check for changed value.

Denis Salopek (3):
bpf: add lookup_and_delete_elem support to hashtab
bpf: extend libbpf with bpf_map_lookup_and_delete_elem_flags selftests/bpf: add bpf_lookup_and_delete_elem tests

 include/linux/bpf.h                           |   2 +
 include/uapi/linux/bpf.h                      |  13 +
 kernel/bpf/hashtab.c                          |  98 ++++++
 kernel/bpf/syscall.c                          |  34 ++-
 tools/include/uapi/linux/bpf.h                |  13 +
 tools/lib/bpf/bpf.c                           |  13 +
 tools/lib/bpf/bpf.h                           |   2 +
 tools/lib/bpf/libbpf.map                      |   1 +
 .../bpf/prog_tests/lookup_and_delete.c        | 288 ++++++++++++++++++
 .../bpf/progs/test_lookup_and_delete.c        |  26 ++
 tools/testing/selftests/bpf/test_lru_map.c    |   8 +
 tools/testing/selftests/bpf/test_maps.c       |  17 ++
 12 files changed, 511 insertions(+), 4 deletions(-)
 create mode 100644 tools/testing/selftests/bpf/prog_tests/lookup_and_delete.c
 create mode 100644 tools/testing/selftests/bpf/progs/test_lookup_and_delete.c
Signature · 1 line
2.26.2