bpf.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Andrey Ignatov <rdna@fb.com>
To: <bpf@vger.kernel.org>
Cc: Andrey Ignatov <rdna@fb.com>, <ast@kernel.org>,
	<daniel@iogearbox.net>, <kafai@fb.com>, <kernel-team@fb.com>
Subject: [PATCH bpf-next 0/6] bpf: Support access to bpf map fields
Date: Wed, 17 Jun 2020 13:43:41 -0700	[thread overview]
Message-ID: <cover.1592426215.git.rdna@fb.com> (raw)

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 4 for more details on the feature and use-cases.

Other patches:

Patch 1 is refactoring to simplify btf_parse_vmlinux().
Patch 2 introduces a new function to simplify iteration over btf.
Patch 3 is a rename to avoid having two different `struct bpf_htab`.

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


Andrey Ignatov (6):
  bpf: Switch btf_parse_vmlinux to btf_find_by_name_kind
  bpf: Introduce btf_find_by_name_kind_next()
  bpf: Rename bpf_htab to bpf_shtab in sock_map
  bpf: Support access to bpf map fields
  bpf: Set map_btf_name for all map types
  selftests/bpf: Test access to bpf map pointer

 include/linux/bpf.h                           |   8 +
 include/linux/bpf_verifier.h                  |   1 +
 include/linux/btf.h                           |   2 +
 kernel/bpf/arraymap.c                         |   6 +
 kernel/bpf/bpf_struct_ops.c                   |   1 +
 kernel/bpf/btf.c                              |  97 ++-
 kernel/bpf/cpumap.c                           |   1 +
 kernel/bpf/devmap.c                           |   2 +
 kernel/bpf/hashtab.c                          |   5 +
 kernel/bpf/local_storage.c                    |   1 +
 kernel/bpf/lpm_trie.c                         |   1 +
 kernel/bpf/queue_stack_maps.c                 |   2 +
 kernel/bpf/reuseport_array.c                  |   1 +
 kernel/bpf/ringbuf.c                          |   1 +
 kernel/bpf/stackmap.c                         |   1 +
 kernel/bpf/verifier.c                         |  77 +-
 net/core/bpf_sk_storage.c                     |   1 +
 net/core/sock_map.c                           |  84 +--
 net/xdp/xskmap.c                              |   1 +
 .../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 +-
 23 files changed, 1007 insertions(+), 68 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

-- 
2.24.1


             reply	other threads:[~2020-06-17 20:44 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-06-17 20:43 Andrey Ignatov [this message]
2020-06-17 20:43 ` [PATCH bpf-next 1/6] bpf: Switch btf_parse_vmlinux to btf_find_by_name_kind Andrey Ignatov
2020-06-19  4:45   ` Andrii Nakryiko
2020-06-17 20:43 ` [PATCH bpf-next 2/6] bpf: Introduce btf_find_by_name_kind_next() Andrey Ignatov
2020-06-17 20:43 ` [PATCH bpf-next 3/6] bpf: Rename bpf_htab to bpf_shtab in sock_map Andrey Ignatov
2020-06-17 20:43 ` [PATCH bpf-next 4/6] bpf: Support access to bpf map fields Andrey Ignatov
2020-06-18  6:18   ` [Potential Spoof] " Martin KaFai Lau
2020-06-18 19:42     ` Andrey Ignatov
2020-06-18 21:03       ` Martin KaFai Lau
2020-06-18 23:51       ` Andrey Ignatov
2020-06-19  0:07         ` Andrii Nakryiko
2020-06-19  0:27           ` Andrey Ignatov
2020-06-19  1:11             ` Martin KaFai Lau
2020-06-19  1:53               ` Andrey Ignatov
2020-06-17 20:43 ` [PATCH bpf-next 5/6] bpf: Set map_btf_name for all map types Andrey Ignatov
2020-06-17 20:43 ` [PATCH bpf-next 6/6] selftests/bpf: Test access to bpf map pointer Andrey Ignatov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=cover.1592426215.git.rdna@fb.com \
    --to=rdna@fb.com \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=kafai@fb.com \
    --cc=kernel-team@fb.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).