selftests/bpf: Test gen_pro/epilogue that generate kfuncs
authorAmery Hung <ameryhung@gmail.com>
Tue, 25 Feb 2025 23:35:45 +0000 (15:35 -0800)
committerAlexei Starovoitov <ast@kernel.org>
Wed, 26 Feb 2025 03:04:43 +0000 (19:04 -0800)
commit4e4136c6446753e6da4424a734f84de82c70600f
tree01f5a412da2f7f50d2b9011cb6f3b0793cf49e79
parentd519594ee2445d7cd1ad51f4db4cee58f8213400
selftests/bpf: Test gen_pro/epilogue that generate kfuncs

Test gen_prologue and gen_epilogue that generate kfuncs that have not
been seen in the main program.

The main bpf program and return value checks are identical to
pro_epilogue.c introduced in commit 47e69431b57a ("selftests/bpf: Test
gen_prologue and gen_epilogue"). However, now when bpf_testmod_st_ops
detects a program name with prefix "test_kfunc_", it generates slightly
different prologue and epilogue: They still add 1000 to args->a in
prologue, add 10000 to args->a and set r0 to 2 * args->a in epilogue,
but involve kfuncs.

At high level, the alternative version of prologue and epilogue look
like this:

  cgrp = bpf_cgroup_from_id(0);
  if (cgrp)
          bpf_cgroup_release(cgrp);
  else
          /* Perform what original bpf_testmod_st_ops prologue or
           * epilogue does
           */

Since 0 is never a valid cgroup id, the original prologue or epilogue
logic will be performed. As a result, the __retval check should expect
the exact same return value.

Signed-off-by: Amery Hung <ameryhung@gmail.com>
Acked-by: Martin KaFai Lau <martin.lau@kernel.org>
Link: https://lore.kernel.org/r/20250225233545.285481-2-ameryhung@gmail.com
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
include/linux/filter.h
kernel/bpf/btf.c
tools/testing/selftests/bpf/prog_tests/pro_epilogue.c
tools/testing/selftests/bpf/progs/pro_epilogue_with_kfunc.c [new file with mode: 0644]
tools/testing/selftests/bpf/test_kmods/bpf_testmod.c