All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH bpf-next v1 0/7] Dynamic pointers
@ 2022-04-02  1:58 Joanne Koong
  2022-04-02  1:58 ` [PATCH bpf-next v1 1/7] bpf: Add MEM_UNINIT as a bpf_type_flag Joanne Koong
                   ` (7 more replies)
  0 siblings, 8 replies; 32+ messages in thread
From: Joanne Koong @ 2022-04-02  1:58 UTC (permalink / raw)
  To: bpf; +Cc: andrii, ast, daniel, Joanne Koong

From: Joanne Koong <joannelkoong@gmail.com>

This patchset implements the basics of dynamic pointers in bpf.

A dynamic pointer (struct bpf_dynptr) is a pointer that stores extra metadata
alongside the address it points to. This abstraction is useful in bpf, given
that every memory access in a bpf program must be safe. The verifier and bpf
helper functions can use the metadata to enforce safety guarantees for things 
such as dynamically sized strings and kernel heap allocations.

From the program side, the bpf_dynptr is an opaque struct and the verifier
will enforce that its contents are never written to by the program.
It can only be written to through specific bpf helper functions.

There are several uses cases for dynamic pointers in bpf programs. A list of
some are: dynamically sized ringbuf reservations without any extra memcpys,
dynamic string parsing and memory comparisons, dynamic memory allocations that
can be persisted in a map, and dynamic parsing of sk_buff and xdp_md packet
data.

At a high-level, the patches are as follows:
1/7 - Adds MEM_UNINIT as a bpf_type_flag
2/7 - Adds MEM_RELEASE as a bpf_type_flag
3/7 - Adds bpf_dynptr_from_mem, bpf_malloc, and bpf_free
4/7 - Adds bpf_dynptr_read and bpf_dynptr_write
5/7 - Adds dynptr data slices (ptr to underlying dynptr memory)
6/7 - Adds dynptr support for ring buffers
7/7 - Tests to check that verifier rejects certain fail cases and passes
certain success cases

This is the first dynptr patchset in a larger series. The next series of
patches will add persisting dynamic memory allocations in maps, parsing packet
data through dynptrs, dynptrs to referenced objects, convenience helpers for
using dynptrs as iterators, and more helper functions for interacting with
strings and memory dynamically.

Joanne Koong (7):
  bpf: Add MEM_UNINIT as a bpf_type_flag
  bpf: Add MEM_RELEASE as a bpf_type_flag
  bpf: Add bpf_dynptr_from_mem, bpf_malloc, bpf_free
  bpf: Add bpf_dynptr_read and bpf_dynptr_write
  bpf: Add dynptr data slices
  bpf: Dynptr support for ring buffers
  bpf: Dynptr tests

 include/linux/bpf.h                           | 107 +++-
 include/linux/bpf_verifier.h                  |  23 +-
 include/uapi/linux/bpf.h                      | 100 ++++
 kernel/bpf/bpf_lsm.c                          |   4 +-
 kernel/bpf/btf.c                              |   3 +-
 kernel/bpf/cgroup.c                           |   4 +-
 kernel/bpf/helpers.c                          | 190 ++++++-
 kernel/bpf/ringbuf.c                          |  75 ++-
 kernel/bpf/stackmap.c                         |   6 +-
 kernel/bpf/verifier.c                         | 406 ++++++++++++--
 kernel/trace/bpf_trace.c                      |  20 +-
 net/core/filter.c                             |  28 +-
 scripts/bpf_doc.py                            |   2 +
 tools/include/uapi/linux/bpf.h                | 100 ++++
 .../testing/selftests/bpf/prog_tests/dynptr.c | 303 ++++++++++
 .../testing/selftests/bpf/progs/dynptr_fail.c | 527 ++++++++++++++++++
 .../selftests/bpf/progs/dynptr_success.c      | 147 +++++
 17 files changed, 1955 insertions(+), 90 deletions(-)
 create mode 100644 tools/testing/selftests/bpf/prog_tests/dynptr.c
 create mode 100644 tools/testing/selftests/bpf/progs/dynptr_fail.c
 create mode 100644 tools/testing/selftests/bpf/progs/dynptr_success.c

-- 
2.30.2


^ permalink raw reply	[flat|nested] 32+ messages in thread

end of thread, other threads:[~2022-04-15  1:43 UTC | newest]

Thread overview: 32+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-02  1:58 [PATCH bpf-next v1 0/7] Dynamic pointers Joanne Koong
2022-04-02  1:58 ` [PATCH bpf-next v1 1/7] bpf: Add MEM_UNINIT as a bpf_type_flag Joanne Koong
2022-04-06 18:33   ` Andrii Nakryiko
2022-04-02  1:58 ` [PATCH bpf-next v1 2/7] bpf: Add MEM_RELEASE " Joanne Koong
2022-04-04  7:34   ` Kumar Kartikeya Dwivedi
2022-04-04 19:04     ` Joanne Koong
2022-04-06 18:42   ` Andrii Nakryiko
2022-04-02  1:58 ` [PATCH bpf-next v1 3/7] bpf: Add bpf_dynptr_from_mem, bpf_malloc, bpf_free Joanne Koong
2022-04-06 22:23   ` Andrii Nakryiko
2022-04-08 22:04     ` Joanne Koong
2022-04-08 22:46       ` Andrii Nakryiko
2022-04-08 23:37         ` Joanne Koong
2022-04-09  1:11           ` Alexei Starovoitov
2022-04-12  2:12             ` Andrii Nakryiko
2022-04-15  1:43               ` Joanne Koong
2022-04-12  2:05           ` Andrii Nakryiko
2022-04-02  1:58 ` [PATCH bpf-next v1 4/7] bpf: Add bpf_dynptr_read and bpf_dynptr_write Joanne Koong
2022-04-02 13:35   ` Toke Høiland-Jørgensen
2022-04-04 20:18     ` Joanne Koong
2022-04-06 22:32   ` Andrii Nakryiko
2022-04-08 23:07     ` Joanne Koong
2022-04-02  1:58 ` [PATCH bpf-next v1 5/7] bpf: Add dynptr data slices Joanne Koong
2022-04-02  1:58 ` [PATCH bpf-next v1 6/7] bpf: Dynptr support for ring buffers Joanne Koong
2022-04-02  6:40   ` kernel test robot
2022-04-06 22:50   ` Andrii Nakryiko
2022-04-02  1:58 ` [PATCH bpf-next v1 7/7] bpf: Dynptr tests Joanne Koong
2022-04-06 23:11   ` Andrii Nakryiko
2022-04-08 23:16     ` Joanne Koong
2022-04-06 23:13 ` [PATCH bpf-next v1 0/7] Dynamic pointers Andrii Nakryiko
2022-04-07 12:44   ` Brendan Jackman
2022-04-07 20:40     ` Joanne Koong
2022-04-08 10:21       ` Brendan Jackman

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.