public inbox for bpf@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH bpf-next v2 0/5] support bpf_fastcall patterns for calls to kfuncs
@ 2024-08-17  1:51 Eduard Zingerman
  2024-08-17  1:51 ` [PATCH bpf-next v2 1/5] bpf: rename nocsr -> bpf_fastcall in verifier Eduard Zingerman
                   ` (4 more replies)
  0 siblings, 5 replies; 15+ messages in thread
From: Eduard Zingerman @ 2024-08-17  1:51 UTC (permalink / raw)
  To: bpf, ast
  Cc: andrii, daniel, martin.lau, kernel-team, yonghong.song,
	jose.marchesi, Eduard Zingerman

As an extension of [1], allow bpf_fastcall patterns for kfuncs:
- pattern rules are the same as for helpers;
- spill/fill removal is allowed only for kfuncs listed in the
  is_fastcall_kfunc_call (under assumption that such kfuncs would
  always be members of special_kfunc_list).

Allow bpf_fastcall rewrite for bpf_cast_to_kern_ctx() and
bpf_rdonly_cast() in order to conjure selftests for this feature.

After this patch-set verifier would rewrite the program below:

  r2 = 1
  *(u64 *)(r10 - 32) = r2
  call %[bpf_cast_to_kern_ctx]
  r2 = *(u64 *)(r10 - 32)
  r0 = r2;"

As follows:

  r2 = 1   /* spill/fill at r10[-32] is removed */
  r0 = r1  /* replacement for bpf_cast_to_kern_ctx() */
  r0 = r2
  exit

Also, attribute used by LLVM implementation of the feature had been
changed from no_caller_saved_registers to bpf_fastcall (see [2]).
This patch-set replaces references to nocsr by references to
bpf_fastcall to keep LLVM and Kernel parts in sync.

[1] no_caller_saved_registers attribute for helper calls
    https://lore.kernel.org/bpf/20240722233844.1406874-1-eddyz87@gmail.com/
[2] [BPF] introduce __attribute__((bpf_fastcall))
    https://github.com/llvm/llvm-project/pull/101228

Changes v1->v2:
- added two patches replacing all mentions of nocsr by bpf_fastcall
  (suggested by Andrii);
- removed KF_NOCSR flag (suggested by Yonghong).

v1: https://lore.kernel.org/bpf/20240812234356.2089263-1-eddyz87@gmail.com/

Eduard Zingerman (5):
  bpf: rename nocsr -> bpf_fastcall in verifier
  selftests/bpf: rename nocsr -> bpf_fastcall in selftests
  bpf: support bpf_fastcall patterns for kfuncs
  bpf: allow bpf_fastcall for bpf_cast_to_kern_ctx and bpf_rdonly_cast
  selftests/bpf: check if bpf_fastcall is recognized for kfuncs

 include/linux/bpf.h                           |   6 +-
 include/linux/bpf_verifier.h                  |  18 +-
 kernel/bpf/helpers.c                          |   2 +-
 kernel/bpf/verifier.c                         | 183 +++++++++++-------
 .../selftests/bpf/prog_tests/verifier.c       |   4 +-
 ...rifier_nocsr.c => verifier_bpf_fastcall.c} |  76 ++++++--
 6 files changed, 188 insertions(+), 101 deletions(-)
 rename tools/testing/selftests/bpf/progs/{verifier_nocsr.c => verifier_bpf_fastcall.c} (90%)

-- 
2.45.2


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

end of thread, other threads:[~2024-08-22  1:43 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-08-17  1:51 [PATCH bpf-next v2 0/5] support bpf_fastcall patterns for calls to kfuncs Eduard Zingerman
2024-08-17  1:51 ` [PATCH bpf-next v2 1/5] bpf: rename nocsr -> bpf_fastcall in verifier Eduard Zingerman
2024-08-22  1:14   ` Yonghong Song
2024-08-22  1:17   ` Yonghong Song
2024-08-22  1:43     ` Eduard Zingerman
2024-08-17  1:51 ` [PATCH bpf-next v2 2/5] selftests/bpf: rename nocsr -> bpf_fastcall in selftests Eduard Zingerman
2024-08-22  1:20   ` Yonghong Song
2024-08-17  1:51 ` [PATCH bpf-next v2 3/5] bpf: support bpf_fastcall patterns for kfuncs Eduard Zingerman
2024-08-17 20:09   ` kernel test robot
2024-08-18  2:50     ` Eduard Zingerman
2024-08-22  1:23   ` Yonghong Song
2024-08-17  1:51 ` [PATCH bpf-next v2 4/5] bpf: allow bpf_fastcall for bpf_cast_to_kern_ctx and bpf_rdonly_cast Eduard Zingerman
2024-08-22  1:23   ` Yonghong Song
2024-08-17  1:51 ` [PATCH bpf-next v2 5/5] selftests/bpf: check if bpf_fastcall is recognized for kfuncs Eduard Zingerman
2024-08-22  1:38   ` Yonghong Song

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox