Skip to content

bpf: Support access to bpf map fields

Andrey Ignatov bpf 2 versions – Applied

Status from this message: Applied, thanks!

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v2 Latest5 patches 9 repliesApplied
  2. v16 patches 9 repliesSuperseded

Changes in v2 from the cover letter

- move btf id cache to a new bpf_map_ops.map_btf_id field (Martin, Andrii);
- don't check btf names for collisions (Martin);
- drop btf_find_by_name_kind_next() patch since it was needed only for collision check;
- don't fall back to struct bpf_map if a map type doesn't specify both map_btf_name and map_btf_id;

Patches in v2 Applied

#Subject and filesSizeRepliesApplied
1/5bpf: Switch btf_parse_vmlinux to btf_find_by_name_kindkernel/bpf/btf.c+6 -171 reply
2/5bpf: Rename bpf_htab to bpf_shtab in sock_mapnet/core/sock_map.c+41 -411 reply
3/5bpf: Support access to bpf map fieldsinclude/linux/bpf.h include/linux/bpf_verifier.h kernel/bpf/arraymap.c +4 more+131 -93 replies
4/5bpf: Set map_btf_{name,id} for all map typeskernel/bpf/arraymap.c kernel/bpf/bpf_struct_ops.c kernel/bpf/cpumap.c +11 more+72 -01 reply
5/5selftests/bpf: Test access to bpf map pointertools/testing/selftests/bpf/prog_tests/map_ptr.c tools/testing/selftests/bpf/progs/map_ptr_kern.c tools/testing/selftests/bpf/verifier/map_ptr.c+780 -01 reply

Reviews trailers per patch

All 5 patches have a Reviewed-by or Acked-by of their own; the series has one for all of them.

PatchAndrii NakryikoJohn FastabendMartin KaFai Lau
SeriesA-b
1/5A-b A-b
2/5A-b
3/5A-b
4/5A-b
5/5A-b

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes. Scroll the table sideways for all 3 reviewers.

Read the v2 thread

Cover letter [PATCH v2 bpf-next 0/5] bpf: Support access to bpf map fields

v1->v2:
- move btf id cache to a new bpf_map_ops.map_btf_id field (Martin, Andrii);
- don't check btf names for collisions (Martin);
- drop btf_find_by_name_kind_next() patch since it was needed only for collision check;
- don't fall back to struct bpf_map if a map type doesn't specify both map_btf_name and map_btf_id;

This patch set adds support to access bpf map fields from bpf programs using btf_struct_access().

That way a program can cast a pointer to map to either struct bpf_map * or map type specific struct pointer such as struct bpf_array * or struct bpf_htab *, and access necessary fields, e.g. map->max_entries.

The fields, in turn, should be defined by a user provided struct with preserve_access_index attribute or included from vmlinux.h.

Please see patch 3 for more details on the feature and use-cases.

Other patches:

Patch 1 is refactoring to simplify btf_parse_vmlinux(). Patch 2 is a rename to avoid having two different struct bpf_htab.

Patch 4 enables access to map fields for all map types. Patch 5 adds selftests.

Andrey Ignatov (5):
bpf: Switch btf_parse_vmlinux to btf_find_by_name_kind
bpf: Rename bpf_htab to bpf_shtab in sock_map
bpf: Support access to bpf map fields
bpf: Set map_btf_{name,id} for all map types selftests/bpf: Test access to bpf map pointer

 include/linux/bpf.h                           |   9 +
 include/linux/bpf_verifier.h                  |   1 +
 kernel/bpf/arraymap.c                         |  18 +
 kernel/bpf/bpf_struct_ops.c                   |   3 +
 kernel/bpf/btf.c                              |  63 +-
 kernel/bpf/cpumap.c                           |   3 +
 kernel/bpf/devmap.c                           |   6 +
 kernel/bpf/hashtab.c                          |  15 +
 kernel/bpf/local_storage.c                    |   3 +
 kernel/bpf/lpm_trie.c                         |   3 +
 kernel/bpf/queue_stack_maps.c                 |   6 +
 kernel/bpf/reuseport_array.c                  |   3 +
 kernel/bpf/ringbuf.c                          |   3 +
 kernel/bpf/stackmap.c                         |   3 +
 kernel/bpf/verifier.c                         |  82 ++-
 net/core/bpf_sk_storage.c                     |   3 +
 net/core/sock_map.c                           |  88 +--
 net/xdp/xskmap.c                              |   3 +
 .../selftests/bpf/prog_tests/map_ptr.c        |  32 +
 .../selftests/bpf/progs/map_ptr_kern.c        | 686 ++++++++++++++++++
 .../testing/selftests/bpf/verifier/map_ptr.c  |  62 ++
 .../selftests/bpf/verifier/map_ptr_mixing.c   |   2 +-
 22 files changed, 1030 insertions(+), 67 deletions(-)
 create mode 100644 tools/testing/selftests/bpf/prog_tests/map_ptr.c
 create mode 100644 tools/testing/selftests/bpf/progs/map_ptr_kern.c
 create mode 100644 tools/testing/selftests/bpf/verifier/map_ptr.c
Signature · 1 line
2.24.1