BPF List
 help / color / mirror / Atom feed
* [PATCH bpf-next v5 0/5] bpf: Allow void return type for global subprogs
@ 2026-02-27 15:46 Emil Tsalapatis
  2026-02-27 15:46 ` [PATCH bpf-next v5 1/5] bpf: Factor out program return value calculation Emil Tsalapatis
                   ` (4 more replies)
  0 siblings, 5 replies; 18+ messages in thread
From: Emil Tsalapatis @ 2026-02-27 15:46 UTC (permalink / raw)
  To: bpf
  Cc: andrii, ast, daniel, eddyz87, martin.lau, memxor, song,
	yonghong.song, Emil Tsalapatis

Global subprogs are currently not allowed to return void. Adjust
verifier logic to allow global functions with a void return type.
Exception callbacks are excluded from this change, and still require
a scalar return type. 

Adding additional logic for void globals significantly complicates
check_return_code(), mainly because of how the new feature interacts
with bpf_throw(). To avoid complicating the code, refactor the return
value range validation logic into two separate functions, one for
program exits through BPF_EXIT and one for program exits through
bpf_throw(). The changes are non-functional.

Also adjust existing selftests that were ensuring that global subprogs
with void return types fail to verify. These tests should now load
successfully.

Patches 1-3 refactor check_return_code into two separate functions, one
for BPF_EXIT and one for bpf_throw(). No functional changes.

Patches 4-5 enable void globals in the verifier and add additional
selftests.

v4 -> v5
(https://lore.kernel.org/bpf/20260225033356.518313-1-emil@etsalapatis.com/)
- Split value validation logic from throw/nonthrow to main prog/subprog (Eduard)
- Turn return_retval_range() to bool and incorporate return_32bit in retval (Eduard)
- Adjust if-else chain in return_retval_range for cgroup programs into switch
  statement to bring it in line with the other program types

v3 -> v4
(https://lore.kernel.org/bpf/20260223215046.1706110-1-emil@etsalapatis.com/)
- Factor out bpf_throw() return value validation logic into its own
  function (Eduard)
- Validate the range of bpf_throw() return values from void globals (Eduard)
- Move new selftest to verifier_global_subprogs.c (Eduard)
- Remove unnecessary verifier_bug_if() statements (Eduard)
- Add new test to ensure void globals can call bpf_throw

v2 -> v3
(https://lore.kernel.org/bpf/20260210183257.217285-1-emil@etsalapatis.com/)
- Allow freplace for global programs that return void and add selftests (Kumar)

v1 -> v2
(https://lore.kernel.org/bpf/20260127231414.359283-1-emil@etsalapatis.com/)

- Only mark R0 as valid for non-void global functions (AI)
- Rename subprog_is_void to subprog_returns_void (Kumar)
- Add test that R0 is invalid after calling a void global (Alexei)
- Add check to ensure exception callbacks do not return void
and associated selftest

Cc: Kumar Kartikeya Dwivedi <memxor@gmail.com>

Eduard Zingerman (2):
  bpf: Extract program_returns_void() for clarity
  bpf: extract check_subprogram_return_code() for clarity

Emil Tsalapatis (3):
  bpf: Factor out program return value calculation
  bpf: Allow void global functions in the verifier
  selftests: bpf: Add tests for void global subprogs

 include/linux/bpf_verifier.h                  |   1 +
 kernel/bpf/btf.c                              |   7 +-
 kernel/bpf/verifier.c                         | 348 ++++++++++++------
 .../selftests/bpf/prog_tests/exceptions.c     |   1 +
 .../selftests/bpf/prog_tests/fexit_bpf2bpf.c  |  24 ++
 .../testing/selftests/bpf/progs/exceptions.c  |  14 +
 .../selftests/bpf/progs/exceptions_fail.c     |  35 +-
 .../bpf/progs/freplace_int_with_void.c        |  14 +
 .../selftests/bpf/progs/freplace_void.c       |  12 +
 .../selftests/bpf/progs/test_global_func7.c   |   2 +-
 .../bpf/progs/verifier_global_subprogs.c      |  19 +
 11 files changed, 349 insertions(+), 128 deletions(-)
 create mode 100644 tools/testing/selftests/bpf/progs/freplace_int_with_void.c
 create mode 100644 tools/testing/selftests/bpf/progs/freplace_void.c

-- 
2.49.0


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

end of thread, other threads:[~2026-02-28  1:22 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-02-27 15:46 [PATCH bpf-next v5 0/5] bpf: Allow void return type for global subprogs Emil Tsalapatis
2026-02-27 15:46 ` [PATCH bpf-next v5 1/5] bpf: Factor out program return value calculation Emil Tsalapatis
2026-02-27 15:50   ` Emil Tsalapatis
2026-02-27 18:57   ` Eduard Zingerman
2026-02-28  0:36     ` Emil Tsalapatis
2026-02-27 20:27   ` kernel test robot
2026-02-27 20:49   ` kernel test robot
2026-02-28  1:22   ` kernel test robot
2026-02-27 15:46 ` [PATCH bpf-next v5 2/5] bpf: Extract program_returns_void() for clarity Emil Tsalapatis
2026-02-27 15:46 ` [PATCH bpf-next v5 3/5] bpf: extract check_subprogram_return_code() " Emil Tsalapatis
2026-02-27 19:42   ` Eduard Zingerman
2026-02-27 15:46 ` [PATCH bpf-next v5 4/5] bpf: Allow void global functions in the verifier Emil Tsalapatis
2026-02-27 16:24   ` bot+bpf-ci
2026-02-27 19:32   ` Eduard Zingerman
2026-02-28  0:39     ` Emil Tsalapatis
2026-02-27 15:46 ` [PATCH bpf-next v5 5/5] selftests: bpf: Add tests for void global subprogs Emil Tsalapatis
2026-02-27 19:53   ` Eduard Zingerman
2026-02-28  0:32     ` Emil Tsalapatis

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