Skip to content

bpf: Allow void return type for global subprogs

Emil Tsalapatis bpf 6 versions – Applied

Status from this message: This series was applied to bpf/bpf-next.git (master)

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v6 Latest5 patches 2 repliesApplied 5/5
  2. v55 patches 8 repliesSuperseded
  3. v44 patches 5 repliesSuperseded
Earlier versions · 3
VersionPostedPatchesRepliesStatus
v32 patches7 repliesSuperseded
v22 patches0 repliesSuperseded
v11 patch4 repliesSuperseded

Changes in v6 from the cover letter

Patches in v6 All 5 applied

#Subject and filesSizeRepliesApplied
1/5bpf: Factor out program return value calculationinclude/linux/bpf_verifier.h kernel/bpf/verifier.c+126 -1010 repliesApplied
2/5bpf: Extract program_returns_void() for claritykernel/bpf/verifier.c+36 -280 repliesApplied
3/5bpf: extract check_global_subprog_return_code() for claritykernel/bpf/verifier.c+44 -182 repliesApplied
4/5bpf: Allow void global functions in the verifierkernel/bpf/btf.c kernel/bpf/verifier.c tools/testing/selftests/bpf/progs/exceptions_fail.c +1 more+60 -120 repliesApplied
5/5selftests: bpf: Add tests for void global subprogstools/testing/selftests/bpf/prog_tests/exceptions.c tools/testing/selftests/bpf/prog_tests/fexit_bpf2bpf.c tools/testing/selftests/bpf/progs/exceptions.c +4 more+111 -30 repliesApplied

Reviews trailers per patch

3 of 5 patches have a Reviewed-by or Acked-by.

PatchEduard Zingerman
1/5A-b
2/5
3/5
4/5A-b
5/5A-b

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v6 thread

Cover letter [PATCH bpf-next v6 0/5] bpf: Allow void return type for global subprogs

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.

v5 -> v6
(https://lore.kernel.org/bpf/[email protected]/)

Patch 1:

- Removed unused variables (kernel test robot)
- Add break; on empty default to suppress warning (kernel test robot)
- Added explanation on why change in switch statement for BPF_PROG_TYPE_TRACING in check_return_code is a no-op

Patches 2/3:

- Added From: tags to Eduard's patches and changed my Reviewed-by to Signed-off-by to properly denote patch route (submitting-patches.rst)
- Renamed check_subprogram_return_code for into check_global_subprog_return_code (Eduard)

Patch 4:

- Remove unnecessary subprog_is_global() check in check_return_code (Eduard)
- Fix indentation on patch 4 (AI)

Patch 5:

- Fix unused data in selftests (Eduard)

v4 -> v5
(https://lore.kernel.org/bpf/[email protected]/)
- 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/[email protected]/)
- 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/[email protected]/)
- Allow freplace for global programs that return void and add selftests (Kumar)

v1 -> v2
(https://lore.kernel.org/bpf/[email protected]/)

- 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 <[email protected]>

Eduard Zingerman (2):
bpf: Extract program_returns_void() for clarity
bpf: extract check_global_subprog_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                         | 349 ++++++++++++------
 .../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        |  11 +
 .../selftests/bpf/progs/freplace_void.c       |  10 +
 .../selftests/bpf/progs/test_global_func7.c   |   2 +-
 .../bpf/progs/verifier_global_subprogs.c      |  19 +
 11 files changed, 344 insertions(+), 129 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
Signature · 1 line
2.49.0