diff mbox series

[bpf-next,2/2] selftests/bpf: set vpath in Makefile to search for skels

Message ID 20240916195919.1872371-2-ihor.solodrai@pm.me (mailing list archive)
State New
Delegated to: BPF
Headers show
Series [bpf-next,1/2] selftests/bpf: remove test_skb_cgroup_id.sh from TEST_PROGS | expand

Checks

Context Check Description
bpf/vmtest-bpf-next-VM_Test-0 success Logs for Lint
bpf/vmtest-bpf-next-VM_Test-1 success Logs for ShellCheck
bpf/vmtest-bpf-next-VM_Test-2 success Logs for Unittests
bpf/vmtest-bpf-next-VM_Test-3 success Logs for Validate matrix.py
bpf/vmtest-bpf-next-VM_Test-5 success Logs for aarch64-gcc / build-release
bpf/vmtest-bpf-next-VM_Test-13 success Logs for s390x-gcc / test (test_progs, false, 360) / test_progs on s390x with gcc
bpf/vmtest-bpf-next-VM_Test-4 success Logs for aarch64-gcc / build / build for aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-8 success Logs for aarch64-gcc / test (test_progs_no_alu32, false, 360) / test_progs_no_alu32 on aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-9 success Logs for aarch64-gcc / test (test_verifier, false, 360) / test_verifier on aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-6 success Logs for aarch64-gcc / test (test_maps, false, 360) / test_maps on aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-10 success Logs for aarch64-gcc / veristat
bpf/vmtest-bpf-next-VM_Test-11 success Logs for s390x-gcc / build / build for s390x with gcc
bpf/vmtest-bpf-next-VM_Test-12 success Logs for s390x-gcc / build-release
bpf/vmtest-bpf-next-VM_Test-14 success Logs for s390x-gcc / test (test_progs_no_alu32, false, 360) / test_progs_no_alu32 on s390x with gcc
bpf/vmtest-bpf-next-VM_Test-16 success Logs for s390x-gcc / veristat
bpf/vmtest-bpf-next-VM_Test-15 success Logs for s390x-gcc / test (test_verifier, false, 360) / test_verifier on s390x with gcc
bpf/vmtest-bpf-next-VM_Test-21 success Logs for x86_64-gcc / test (test_progs, false, 360) / test_progs on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-19 success Logs for x86_64-gcc / build-release
bpf/vmtest-bpf-next-VM_Test-17 success Logs for set-matrix
bpf/vmtest-bpf-next-VM_Test-20 success Logs for x86_64-gcc / test (test_maps, false, 360) / test_maps on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-23 success Logs for x86_64-gcc / test (test_progs_no_alu32_parallel, true, 30) / test_progs_no_alu32_parallel on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-24 success Logs for x86_64-gcc / test (test_progs_parallel, true, 30) / test_progs_parallel on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-18 success Logs for x86_64-gcc / build / build for x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-22 success Logs for x86_64-gcc / test (test_progs_no_alu32, false, 360) / test_progs_no_alu32 on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-25 success Logs for x86_64-gcc / test (test_verifier, false, 360) / test_verifier on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-26 success Logs for x86_64-gcc / veristat / veristat on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-28 success Logs for x86_64-llvm-17 / build-release / build for x86_64 with llvm-17-O2
bpf/vmtest-bpf-next-VM_Test-29 success Logs for x86_64-llvm-17 / test (test_maps, false, 360) / test_maps on x86_64 with llvm-17
bpf/vmtest-bpf-next-VM_Test-27 success Logs for x86_64-llvm-17 / build / build for x86_64 with llvm-17
bpf/vmtest-bpf-next-VM_Test-30 success Logs for x86_64-llvm-17 / test (test_progs, false, 360) / test_progs on x86_64 with llvm-17
bpf/vmtest-bpf-next-VM_Test-31 success Logs for x86_64-llvm-17 / test (test_progs_no_alu32, false, 360) / test_progs_no_alu32 on x86_64 with llvm-17
bpf/vmtest-bpf-next-VM_Test-32 success Logs for x86_64-llvm-17 / test (test_verifier, false, 360) / test_verifier on x86_64 with llvm-17
bpf/vmtest-bpf-next-VM_Test-34 success Logs for x86_64-llvm-18 / build / build for x86_64 with llvm-18
bpf/vmtest-bpf-next-VM_Test-35 success Logs for x86_64-llvm-18 / build-release / build for x86_64 with llvm-18-O2
bpf/vmtest-bpf-next-VM_Test-40 success Logs for x86_64-llvm-18 / test (test_verifier, false, 360) / test_verifier on x86_64 with llvm-18
bpf/vmtest-bpf-next-VM_Test-39 success Logs for x86_64-llvm-18 / test (test_progs_no_alu32, false, 360) / test_progs_no_alu32 on x86_64 with llvm-18
bpf/vmtest-bpf-next-VM_Test-36 success Logs for x86_64-llvm-18 / test (test_maps, false, 360) / test_maps on x86_64 with llvm-18
bpf/vmtest-bpf-next-VM_Test-33 success Logs for x86_64-llvm-17 / veristat
bpf/vmtest-bpf-next-VM_Test-41 success Logs for x86_64-llvm-18 / veristat
bpf/vmtest-bpf-next-VM_Test-37 success Logs for x86_64-llvm-18 / test (test_progs, false, 360) / test_progs on x86_64 with llvm-18
bpf/vmtest-bpf-next-VM_Test-38 success Logs for x86_64-llvm-18 / test (test_progs_cpuv4, false, 360) / test_progs_cpuv4 on x86_64 with llvm-18
bpf/vmtest-bpf-next-PR success PR summary
bpf/vmtest-bpf-next-VM_Test-7 success Logs for aarch64-gcc / test (test_progs, false, 360) / test_progs on aarch64 with gcc
netdev/series_format success Single patches do not need cover letters
netdev/tree_selection success Clearly marked for bpf-next
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 16 this patch: 16
netdev/build_tools success Errors and warnings before: 0 this patch: 0
netdev/cc_maintainers warning 10 maintainers not CCed: sdf@fomichev.me haoluo@google.com jolsa@kernel.org shuah@kernel.org linux-kselftest@vger.kernel.org song@kernel.org yonghong.song@linux.dev kpsingh@kernel.org martin.lau@linux.dev john.fastabend@gmail.com
netdev/build_clang success Errors and warnings before: 17 this patch: 17
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 22 this patch: 22
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 15 lines checked
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Ihor Solodrai Sept. 16, 2024, 7:59 p.m. UTC
Auto-dependencies generated for %.test.o files refer to skels using
filenames as opposed to full paths. This requires make to be able to
link this name to an actual path, because not all generated skels are
put in the working directory.

In the original patch [1], this was mitigated by this target:

$(notdir %.skel.h): $(TRUNNER_OUTPUT)/%.skel.h
	@true

This turned out to be insufficient.

First, %.lskel.h and %.subskel.h were missed, because a typical
selftests/bpf build could find these files in the working directory.
This error was detected by an out-of-tree build [2].

Second, even with missing rules added, this target causes unnecessary
rebuilds in the out-of-tree case, as X.skel.h is searched for in the
working directory, and not in the $(OUTPUT).

Using vpath directive [3] is a better solution. Instead of introducing
a separate target (X.skel.h in addition to $(TRUNNER_OUTPUT)/X.skel.h),
make is instructed to search for skels in the output, which allows make
to correctly detect that skel has already been generated.

[1]: https://lore.kernel.org/bpf/VJihUTnvtwEgv_mOnpfy7EgD9D2MPNoHO-MlANeLIzLJPGhDeyOuGKIYyKgk0O6KPjfM-MuhtvPwZcngN8WFqbTnTRyCSMc2aMZ1ODm1T_g=@pm.me/
[2]: https://lore.kernel.org/bpf/CIjrhJwoIqMc2IhuppVqh4ZtJGbx8kC8rc9PHhAIU6RccnWT4I04F_EIr4GxQwxZe89McuGJlCnUk9UbkdvWtSJjAsd7mHmnTy9F8K2TLZM=@pm.me/
[3]: https://www.gnu.org/software/make/manual/html_node/Selective-Search.html

Reported-by: Björn Töpel <bjorn@kernel.org>
Signed-off-by: Ihor Solodrai <ihor.solodrai@pm.me>
---
 tools/testing/selftests/bpf/Makefile | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

Comments

Ihor Solodrai Sept. 16, 2024, 8:11 p.m. UTC | #1
On Monday, September 16th, 2024 at 12:59 PM, Ihor Solodrai <ihor.solodrai@pm.me> wrote:

[...]

> ---
> tools/testing/selftests/bpf/Makefile | 9 +++++----
> 1 file changed, 5 insertions(+), 4 deletions(-)
> 
> diff --git a/tools/testing/selftests/bpf/Makefile b/tools/testing/selftests/bpf/Makefile
> index df75f1beb731..365740f24d2e 100644
> --- a/tools/testing/selftests/bpf/Makefile
> +++ b/tools/testing/selftests/bpf/Makefile
> @@ -622,10 +622,11 @@ $(TRUNNER_BPF_SKELS_LINKED): $(TRUNNER_OUTPUT)/%: $$$$(%-deps) $(BPFTOOL) | $(TR
> 
> # When the compiler generates a %.d file, only skel basenames (not
> # full paths) are specified as prerequisites for corresponding %.o
> -# file. This target makes %.skel.h basename dependent on full paths,
> -# linking generated %.d dependency with actual %.skel.h files.
> -$(notdir %.skel.h): $(TRUNNER_OUTPUT)/%.skel.h
> - @true
> +# file. vpath directives below instruct make to search for skel files
> +# in TRUNNER_OUTPUT, if they are not present in the working directory.
> +vpath %.skel.h $(TRUNNER_OUTPUT)
> +vpath %.lskel.h $(TRUNNER_OUTPUT)
> +vpath %.subskel.h $(TRUNNER_OUTPUT)
> 
> endif
> 
> --
> 2.34.1

Hi Björn.

It'd be great if you could confirm that this patch works for your
use-case.

Regarding unnecessary rebuilds, you will still see some skels and
bpf.o objects rebuilt on out-of-tree builds. These are related to
$(LINKED_SKELS) in selftests/bpf/Makefile. They are entangled with
%-deps variables, and I couldn't come up with a similar solution for
them quickly. However, there are just a couple of them, and the
rebuild is relatively fast, so I decided to submit a patch that fixes
most of the problem.

Thank you!
Eduard Zingerman Sept. 17, 2024, 4 a.m. UTC | #2
On Mon, 2024-09-16 at 19:59 +0000, Ihor Solodrai wrote:

[...]

> diff --git a/tools/testing/selftests/bpf/Makefile b/tools/testing/selftests/bpf/Makefile
> index df75f1beb731..365740f24d2e 100644
> --- a/tools/testing/selftests/bpf/Makefile
> +++ b/tools/testing/selftests/bpf/Makefile
> @@ -622,10 +622,11 @@ $(TRUNNER_BPF_SKELS_LINKED): $(TRUNNER_OUTPUT)/%: $$$$(%-deps) $(BPFTOOL) | $(TR
>  
>  # When the compiler generates a %.d file, only skel basenames (not
>  # full paths) are specified as prerequisites for corresponding %.o
> -# file. This target makes %.skel.h basename dependent on full paths,
> -# linking generated %.d dependency with actual %.skel.h files.
> -$(notdir %.skel.h): $(TRUNNER_OUTPUT)/%.skel.h
> -	@true
> +# file. vpath directives below instruct make to search for skel files
> +# in TRUNNER_OUTPUT, if they are not present in the working directory.
> +vpath %.skel.h $(TRUNNER_OUTPUT)
> +vpath %.lskel.h $(TRUNNER_OUTPUT)
> +vpath %.subskel.h $(TRUNNER_OUTPUT)
>  
>  endif

When I try this patch, the following happens after first full tests build:

$ touch progs/verifier_and.c; make -j test_progs

  CLNG-BPF [test_progs] verifier_and.bpf.o
  CLNG-BPF [test_progs-no_alu32] verifier_and.bpf.o
  CLNG-BPF [test_progs-cpuv4] verifier_and.bpf.o
  GEN-SKEL [test_progs] verifier_and.skel.h
  GEN-SKEL [test_progs-no_alu32] verifier_and.skel.h
  GEN-SKEL [test_progs-cpuv4] verifier_and.skel.h
  TEST-OBJ [test_progs] verifier.test.o
  BINARY   test_progs

Note that multiple binaries are built.
Björn Töpel Sept. 17, 2024, 8:53 a.m. UTC | #3
Ihor Solodrai <ihor.solodrai@pm.me> writes:

> Auto-dependencies generated for %.test.o files refer to skels using
> filenames as opposed to full paths. This requires make to be able to
> link this name to an actual path, because not all generated skels are
> put in the working directory.
>
> In the original patch [1], this was mitigated by this target:
>
> $(notdir %.skel.h): $(TRUNNER_OUTPUT)/%.skel.h
> 	@true
>
> This turned out to be insufficient.
>
> First, %.lskel.h and %.subskel.h were missed, because a typical
> selftests/bpf build could find these files in the working directory.
> This error was detected by an out-of-tree build [2].
>
> Second, even with missing rules added, this target causes unnecessary
> rebuilds in the out-of-tree case, as X.skel.h is searched for in the
> working directory, and not in the $(OUTPUT).
>
> Using vpath directive [3] is a better solution. Instead of introducing
> a separate target (X.skel.h in addition to $(TRUNNER_OUTPUT)/X.skel.h),
> make is instructed to search for skels in the output, which allows make
> to correctly detect that skel has already been generated.
>
> [1]: https://lore.kernel.org/bpf/VJihUTnvtwEgv_mOnpfy7EgD9D2MPNoHO-MlANeLIzLJPGhDeyOuGKIYyKgk0O6KPjfM-MuhtvPwZcngN8WFqbTnTRyCSMc2aMZ1ODm1T_g=@pm.me/
> [2]: https://lore.kernel.org/bpf/CIjrhJwoIqMc2IhuppVqh4ZtJGbx8kC8rc9PHhAIU6RccnWT4I04F_EIr4GxQwxZe89McuGJlCnUk9UbkdvWtSJjAsd7mHmnTy9F8K2TLZM=@pm.me/
> [3]: https://www.gnu.org/software/make/manual/html_node/Selective-Search.html
>
> Reported-by: Björn Töpel <bjorn@kernel.org>
> Signed-off-by: Ihor Solodrai <ihor.solodrai@pm.me>

As you point out, there are rebuilds triggered for the bpf "install"
target. Now rebuild are better than failures. Thanks for the fix!

Tested-by: Björn Töpel <bjorn@rivosinc.com>
Ihor Solodrai Sept. 17, 2024, 3:04 p.m. UTC | #4
On Monday, September 16th, 2024 at 9:00 PM, Eduard Zingerman <eddyz87@gmail.com> wrote:

[...]

> 
> When I try this patch, the following happens after first full tests build:
> 
> $ touch progs/verifier_and.c; make -j test_progs
> 
> CLNG-BPF [test_progs] verifier_and.bpf.o
> CLNG-BPF [test_progs-no_alu32] verifier_and.bpf.o
> CLNG-BPF [test_progs-cpuv4] verifier_and.bpf.o
> GEN-SKEL [test_progs] verifier_and.skel.h
> GEN-SKEL [test_progs-no_alu32] verifier_and.skel.h
> GEN-SKEL [test_progs-cpuv4] verifier_and.skel.h
> TEST-OBJ [test_progs] verifier.test.o
> BINARY test_progs
> 
> Note that multiple binaries are built.

Eduard, I've just tried on master (without this patch)

    $ touch progs/verifier_and.c; make -j test_progs

and I get a similar sequence:

    CLNG-BPF [test_progs] verifier_and.bpf.o
    GEN-SKEL [test_progs] verifier_and.skel.h
    CLNG-BPF [test_progs-cpuv4] verifier_and.bpf.o
    GEN-SKEL [test_progs-cpuv4] verifier_and.skel.h
    CLNG-BPF [test_progs-no_alu32] verifier_and.bpf.o
    GEN-SKEL [test_progs-no_alu32] verifier_and.skel.h
    TEST-OBJ [test_progs] verifier.test.o
    BINARY   test_progs
    TEST-OBJ [test_progs-no_alu32] verifier.test.o
    EXT-COPY [test_progs-no_alu32] urandom_read bpf_testmod.ko bpf_test_no_cfi.ko liburandom_read.so xdp_synproxy sign-file uprobe_multi ima_setup.sh verify_sig_setup.sh btf_dump_test_case_bitfields.c btf_dump_test_case_multidim.c btf_dump_test_case_namespacing.c btf_dump_test_case_ordering.c btf_dump_test_case_packing.c btf_dump_test_case_padding.c btf_dump_test_case_syntax.c
    BINARY   test_progs-no_alu32
    TEST-OBJ [test_progs-cpuv4] verifier.test.o
    EXT-COPY [test_progs-cpuv4] urandom_read bpf_testmod.ko bpf_test_no_cfi.ko liburandom_read.so xdp_synproxy sign-file uprobe_multi ima_setup.sh verify_sig_setup.sh btf_dump_test_case_bitfields.c btf_dump_test_case_multidim.c btf_dump_test_case_namespacing.c btf_dump_test_case_ordering.c btf_dump_test_case_packing.c btf_dump_test_case_padding.c btf_dump_test_case_syntax.c
    BINARY   test_progs-cpuv4


%.bpf.o -> %.skel.h -> %.test.o have to be built for each TRUNNER,
right? And then each TRUNNER needs to be rebuilt because of %.test.o
change. Using vpath for skels doesn't change this behavior.

Maybe I'm missing something, let me know.
Eduard Zingerman Sept. 17, 2024, 5:53 p.m. UTC | #5
On Tue, 2024-09-17 at 15:04 +0000, Ihor Solodrai wrote:

[...]

> Eduard, I've just tried on master (without this patch)
> 
>     $ touch progs/verifier_and.c; make -j test_progs
> 
> and I get a similar sequence:
> 
>     CLNG-BPF [test_progs] verifier_and.bpf.o
>     GEN-SKEL [test_progs] verifier_and.skel.h
>     CLNG-BPF [test_progs-cpuv4] verifier_and.bpf.o
>     GEN-SKEL [test_progs-cpuv4] verifier_and.skel.h
>     CLNG-BPF [test_progs-no_alu32] verifier_and.bpf.o
>     GEN-SKEL [test_progs-no_alu32] verifier_and.skel.h
>     TEST-OBJ [test_progs] verifier.test.o
>     BINARY   test_progs
>     TEST-OBJ [test_progs-no_alu32] verifier.test.o
>     EXT-COPY [test_progs-no_alu32] urandom_read bpf_testmod.ko bpf_test_no_cfi.ko liburandom_read.so xdp_synproxy sign-file uprobe_multi ima_setup.sh verify_sig_setup.sh btf_dump_test_case_bitfields.c btf_dump_test_case_multidim.c btf_dump_test_case_namespacing.c btf_dump_test_case_ordering.c btf_dump_test_case_packing.c btf_dump_test_case_padding.c btf_dump_test_case_syntax.c
>     BINARY   test_progs-no_alu32
>     TEST-OBJ [test_progs-cpuv4] verifier.test.o
>     EXT-COPY [test_progs-cpuv4] urandom_read bpf_testmod.ko bpf_test_no_cfi.ko liburandom_read.so xdp_synproxy sign-file uprobe_multi ima_setup.sh verify_sig_setup.sh btf_dump_test_case_bitfields.c btf_dump_test_case_multidim.c btf_dump_test_case_namespacing.c btf_dump_test_case_ordering.c btf_dump_test_case_packing.c btf_dump_test_case_padding.c btf_dump_test_case_syntax.c
>     BINARY   test_progs-cpuv4
> 
> 
> %.bpf.o -> %.skel.h -> %.test.o have to be built for each TRUNNER,
> right? And then each TRUNNER needs to be rebuilt because of %.test.o
> change. Using vpath for skels doesn't change this behavior.
> 
> Maybe I'm missing something, let me know.
> 

Hm, right, sorry for the noise.
diff mbox series

Patch

diff --git a/tools/testing/selftests/bpf/Makefile b/tools/testing/selftests/bpf/Makefile
index df75f1beb731..365740f24d2e 100644
--- a/tools/testing/selftests/bpf/Makefile
+++ b/tools/testing/selftests/bpf/Makefile
@@ -622,10 +622,11 @@  $(TRUNNER_BPF_SKELS_LINKED): $(TRUNNER_OUTPUT)/%: $$$$(%-deps) $(BPFTOOL) | $(TR
 
 # When the compiler generates a %.d file, only skel basenames (not
 # full paths) are specified as prerequisites for corresponding %.o
-# file. This target makes %.skel.h basename dependent on full paths,
-# linking generated %.d dependency with actual %.skel.h files.
-$(notdir %.skel.h): $(TRUNNER_OUTPUT)/%.skel.h
-	@true
+# file. vpath directives below instruct make to search for skel files
+# in TRUNNER_OUTPUT, if they are not present in the working directory.
+vpath %.skel.h $(TRUNNER_OUTPUT)
+vpath %.lskel.h $(TRUNNER_OUTPUT)
+vpath %.subskel.h $(TRUNNER_OUTPUT)
 
 endif