public inbox for bpf@vger.kernel.org
 help / color / mirror / Atom feed
From: Kumar Kartikeya Dwivedi <memxor@gmail.com>
To: bpf@vger.kernel.org
Cc: Alexei Starovoitov <ast@kernel.org>,
	Andrii Nakryiko <andrii@kernel.org>,
	Daniel Borkmann <daniel@iogearbox.net>,
	Martin KaFai Lau <martin.lau@kernel.org>,
	KP Singh <kpsingh@kernel.org>,
	Dave Marchevsky <davemarchevsky@meta.com>,
	David Vernet <void@manifault.com>
Subject: [PATCH bpf-next v2 0/7] Add support for kptrs in more BPF maps
Date: Tue, 21 Feb 2023 21:06:39 +0100	[thread overview]
Message-ID: <20230221200646.2500777-1-memxor@gmail.com> (raw)

This set adds support for kptrs in percpu hashmaps, percpu LRU hashmaps,
and local storage maps (covering sk, cgrp, task, inode). There are also
minor miscellaneous cleanups rolled in, unrelated to the set, that I
collected over time. Feel free to drop them, they have been
intentionally placed after the kptr support to ease partial application
of the series.

Tests are expanded to test more existing maps at runtime and also test
the code path for the local storage maps (which is shared by all
implementations).

A question for reviewers is what the position of the BPF runtime should
be on dealing with reference cycles that can be created by BPF programs
at runtime using this additional support. For instance, one can store
the kptr of the task in its own task local storage, creating a cycle
which prevents destruction of task local storage. Cycles can be formed
using arbitrarily long kptr ownership chains. Therefore, just preventing
storage of such kptrs in some maps is not a sufficient solution, and is
more likely to hurt usability.

There is precedence in existing runtimes which promise memory safety,
like Rust, where reference cycles and memory leaks are permitted.
However, traditionally the safety guarantees of BPF have been stronger.
Thus, more discussion and thought is invited on this topic to ensure we
cover all usage aspects.

Changelog:
----------
v1 -> v2
v1: https://lore.kernel.org/bpf/20230219155249.1755998-1-memxor@gmail.com

 * Simplify selftests, fix a couple of bugs

Kumar Kartikeya Dwivedi (7):
  bpf: Support kptrs in percpu hashmap and percpu LRU hashmap
  bpf: Support kptrs in local storage maps
  bpf: Annotate data races in bpf_local_storage
  bpf: Remove unused MEM_ALLOC | PTR_TRUSTED checks
  bpf: Fix check_reg_type for PTR_TO_BTF_ID
  bpf: Wrap register invalidation with a helper
  selftests/bpf: Add more tests for kptrs in maps

 kernel/bpf/bpf_local_storage.c                |  51 ++-
 kernel/bpf/hashtab.c                          |  59 +--
 kernel/bpf/syscall.c                          |   8 +-
 kernel/bpf/verifier.c                         |  65 ++--
 .../selftests/bpf/prog_tests/map_kptr.c       | 122 ++++--
 tools/testing/selftests/bpf/progs/map_kptr.c  | 353 +++++++++++++++---
 6 files changed, 540 insertions(+), 118 deletions(-)


base-commit: 951bce29c8988209cc359e1fa35a4aaa35542fd5
-- 
2.39.2


             reply	other threads:[~2023-02-21 20:06 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-21 20:06 Kumar Kartikeya Dwivedi [this message]
2023-02-21 20:06 ` [PATCH bpf-next v2 1/7] bpf: Support kptrs in percpu hashmap and percpu LRU hashmap Kumar Kartikeya Dwivedi
2023-02-21 20:06 ` [PATCH bpf-next v2 2/7] bpf: Support kptrs in local storage maps Kumar Kartikeya Dwivedi
2023-02-22 20:48   ` Alexei Starovoitov
2023-02-21 20:06 ` [PATCH bpf-next v2 3/7] bpf: Annotate data races in bpf_local_storage Kumar Kartikeya Dwivedi
2023-02-21 20:06 ` [PATCH bpf-next v2 4/7] bpf: Remove unused MEM_ALLOC | PTR_TRUSTED checks Kumar Kartikeya Dwivedi
2023-02-21 20:06 ` [PATCH bpf-next v2 5/7] bpf: Fix check_reg_type for PTR_TO_BTF_ID Kumar Kartikeya Dwivedi
2023-02-21 20:06 ` [PATCH bpf-next v2 6/7] bpf: Wrap register invalidation with a helper Kumar Kartikeya Dwivedi
2023-02-21 20:06 ` [PATCH bpf-next v2 7/7] selftests/bpf: Add more tests for kptrs in maps Kumar Kartikeya Dwivedi
2023-02-22 21:00 ` [PATCH bpf-next v2 0/7] Add support for kptrs in more BPF maps patchwork-bot+netdevbpf

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=20230221200646.2500777-1-memxor@gmail.com \
    --to=memxor@gmail.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=davemarchevsky@meta.com \
    --cc=kpsingh@kernel.org \
    --cc=martin.lau@kernel.org \
    --cc=void@manifault.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