Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

bpf: selftests: test_loader: Support __btf_path() annotation

This commit adds support for per-prog btf_custom_path. This is necessary
for testing CO-RE relocations on non-vmlinux types using test_loader
infrastructure.

Acked-by: Andrii Nakryiko <andrii@kernel.org>
Signed-off-by: Daniel Xu <dxu@dxuuu.xyz>
Link: https://lore.kernel.org/r/660ea7f2fdbdd5103bc1af87c9fc931f05327926.1702325874.git.dxu@dxuuu.xyz
Signed-off-by: Martin KaFai Lau <martin.lau@kernel.org>

authored by

Daniel Xu and committed by
Martin KaFai Lau
7d19c00e 2f708035

+8
+1
tools/testing/selftests/bpf/progs/bpf_misc.h
··· 71 71 #define __retval_unpriv(val) __attribute__((btf_decl_tag("comment:test_retval_unpriv="#val))) 72 72 #define __auxiliary __attribute__((btf_decl_tag("comment:test_auxiliary"))) 73 73 #define __auxiliary_unpriv __attribute__((btf_decl_tag("comment:test_auxiliary_unpriv"))) 74 + #define __btf_path(path) __attribute__((btf_decl_tag("comment:test_btf_path=" path))) 74 75 75 76 /* Convenience macro for use with 'asm volatile' blocks */ 76 77 #define __naked __attribute__((naked))
+7
tools/testing/selftests/bpf/test_loader.c
··· 27 27 #define TEST_TAG_RETVAL_PFX_UNPRIV "comment:test_retval_unpriv=" 28 28 #define TEST_TAG_AUXILIARY "comment:test_auxiliary" 29 29 #define TEST_TAG_AUXILIARY_UNPRIV "comment:test_auxiliary_unpriv" 30 + #define TEST_BTF_PATH "comment:test_btf_path=" 30 31 31 32 /* Warning: duplicated in bpf_misc.h */ 32 33 #define POINTER_VALUE 0xcafe4all ··· 59 58 const char *prog_name; 60 59 struct test_subspec priv; 61 60 struct test_subspec unpriv; 61 + const char *btf_custom_path; 62 62 int log_level; 63 63 int prog_flags; 64 64 int mode_mask; ··· 290 288 goto cleanup; 291 289 update_flags(&spec->prog_flags, flags, clear); 292 290 } 291 + } else if (str_has_pfx(s, TEST_BTF_PATH)) { 292 + spec->btf_custom_path = s + sizeof(TEST_BTF_PATH) - 1; 293 293 } 294 294 } 295 295 ··· 581 577 return; 582 578 } 583 579 } 580 + 581 + /* Implicitly reset to NULL if next test case doesn't specify */ 582 + open_opts->btf_custom_path = spec->btf_custom_path; 584 583 585 584 tobj = bpf_object__open_mem(obj_bytes, obj_byte_cnt, open_opts); 586 585 if (!ASSERT_OK_PTR(tobj, "obj_open_mem")) /* shouldn't happen */