From: Martin KaFai Lau <martin.lau@linux.dev>
To: bpf@vger.kernel.org
Cc: Alexei Starovoitov <ast@kernel.org>,
Andrii Nakryiko <andrii@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
Eduard Zingerman <eddyz87@gmail.com>,
Yonghong Song <yonghong.song@linux.dev>,
Amery Hung <ameryhung@gmail.com>,
kernel-team@meta.com
Subject: [PATCH v2 bpf-next 0/8] bpf: Add gen_epilogue and allow kfunc call in pro/epilogue
Date: Wed, 21 Aug 2024 16:34:30 -0700 [thread overview]
Message-ID: <20240821233440.1855263-1-martin.lau@linux.dev> (raw)
From: Martin KaFai Lau <martin.lau@kernel.org>
This set allows the subsystem to patch codes before BPF_EXIT.
The verifier ops, .gen_epilogue, is added for this purpose.
One of the use case will be in the bpf qdisc, the bpf qdisc
subsystem can ensure the skb->dev is in the correct value.
The bpf qdisc subsystem can either inline fixing it in the
epilogue or call another kfunc to handle (e.g. drop) it in
the epilogue. Another use case could be in bpf_tcp_ca.c to
enforce snd_cwnd has sane value (e.g. non zero).
The existing .gen_prologue can call bpf helper.
This set also allows the existing .gen_prologue and the new
.gen_epilogue to call kfunc. Other than the skb drop
mentioned above, the bpf qdisc subsystem can call
kfunc to enforce initializing / releasing resources (e.g.
qdisc_watchdog_init/cancel) in some of the qdisc_ops.
v2:
* Remove the RFC tag. Keep the ordering at where .gen_epilogue is
called in the verifier relative to the check_max_stack_depth().
This will be consistent with the other extra stack_depth
usage like optimize_bpf_loop().
* Use __xlated check provided by the test_loader to
check the patched instructions after gen_pro/epilogue (Eduard).
* Added Patch 3 by Eduard (Thanks!).
Eduard Zingerman (1):
selftests/bpf: attach struct_ops maps before test prog runs
Martin KaFai Lau (7):
bpf: Add gen_epilogue to bpf_verifier_ops
bpf: Export bpf_base_func_proto
selftests/bpf: Test gen_prologue and gen_epilogue
selftests/bpf: Add tailcall epilogue test
bpf: Add module parameter to gen_prologue and gen_epilogue
bpf: Allow pro/epilogue to call kfunc
selftests/bpf: Add kfunc call test in gen_prologue and gen_epilogue
include/linux/bpf.h | 4 +-
include/linux/btf.h | 1 +
kernel/bpf/btf.c | 2 +-
kernel/bpf/cgroup.c | 3 +-
kernel/bpf/helpers.c | 1 +
kernel/bpf/verifier.c | 145 ++++++++++-
net/core/filter.c | 6 +-
.../selftests/bpf/bpf_testmod/bpf_testmod.c | 228 ++++++++++++++++++
.../selftests/bpf/bpf_testmod/bpf_testmod.h | 11 +
.../bpf/bpf_testmod/bpf_testmod_kfunc.h | 6 +
.../selftests/bpf/prog_tests/pro_epilogue.c | 50 ++++
.../selftests/bpf/progs/epilogue_tailcall.c | 58 +++++
.../selftests/bpf/progs/pro_epilogue_kfunc.c | 174 +++++++++++++
.../bpf/progs/pro_epilogue_subprog.c | 143 +++++++++++
tools/testing/selftests/bpf/test_loader.c | 27 +++
15 files changed, 850 insertions(+), 9 deletions(-)
create mode 100644 tools/testing/selftests/bpf/prog_tests/pro_epilogue.c
create mode 100644 tools/testing/selftests/bpf/progs/epilogue_tailcall.c
create mode 100644 tools/testing/selftests/bpf/progs/pro_epilogue_kfunc.c
create mode 100644 tools/testing/selftests/bpf/progs/pro_epilogue_subprog.c
--
2.43.5
next reply other threads:[~2024-08-21 23:35 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-08-21 23:34 Martin KaFai Lau [this message]
2024-08-21 23:34 ` [PATCH v2 bpf-next 1/8] bpf: Add gen_epilogue to bpf_verifier_ops Martin KaFai Lau
2024-08-22 0:22 ` Alexei Starovoitov
2024-08-22 0:30 ` Eduard Zingerman
2024-08-22 0:34 ` Alexei Starovoitov
2024-08-22 0:38 ` Eduard Zingerman
2024-08-22 0:52 ` Martin KaFai Lau
2024-08-21 23:34 ` [PATCH v2 bpf-next 2/8] bpf: Export bpf_base_func_proto Martin KaFai Lau
2024-08-21 23:34 ` [PATCH v2 bpf-next 3/8] selftests/bpf: attach struct_ops maps before test prog runs Martin KaFai Lau
2024-08-21 23:34 ` [PATCH v2 bpf-next 4/8] selftests/bpf: Test gen_prologue and gen_epilogue Martin KaFai Lau
2024-08-21 23:34 ` [PATCH v2 bpf-next 5/8] selftests/bpf: Add tailcall epilogue test Martin KaFai Lau
2024-08-21 23:34 ` [PATCH v2 bpf-next 6/8] bpf: Add module parameter to gen_prologue and gen_epilogue Martin KaFai Lau
2024-08-21 23:34 ` [PATCH v2 bpf-next 7/8] bpf: Allow pro/epilogue to call kfunc Martin KaFai Lau
2024-08-22 1:32 ` Alexei Starovoitov
2024-08-22 6:09 ` Martin KaFai Lau
2024-08-22 13:47 ` Alexei Starovoitov
2024-08-22 17:38 ` Martin KaFai Lau
2024-08-22 17:58 ` Alexei Starovoitov
2024-08-21 23:34 ` [PATCH v2 bpf-next 8/8] selftests/bpf: Add kfunc call test in gen_prologue and gen_epilogue Martin KaFai Lau
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=20240821233440.1855263-1-martin.lau@linux.dev \
--to=martin.lau@linux.dev \
--cc=ameryhung@gmail.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=eddyz87@gmail.com \
--cc=kernel-team@meta.com \
--cc=yonghong.song@linux.dev \
/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