aboutsummaryrefslogtreecommitdiffstats
path: root/tools/testing/selftests/bpf/progs/bpf_misc.h
diff options
context:
space:
mode:
authorEduard Zingerman <[email protected]>2023-01-21 00:22:37 +0000
committerAlexei Starovoitov <[email protected]>2023-01-21 01:55:03 +0000
commit91b875a5e43b3a8dec4fbdca067c8860004b5f0e (patch)
treebab8c7725800dd1098181173d86babe99d84f97c /tools/testing/selftests/bpf/progs/bpf_misc.h
parentbpf: Avoid recomputing spi in process_dynptr_func (diff)
downloadkernel-91b875a5e43b3a8dec4fbdca067c8860004b5f0e.tar.gz
kernel-91b875a5e43b3a8dec4fbdca067c8860004b5f0e.zip
selftests/bpf: convenience macro for use with 'asm volatile' blocks
A set of macros useful for writing naked BPF functions using inline assembly. E.g. as follows: struct map_struct { ... } map SEC(".maps"); SEC(...) __naked int foo_test(void) { asm volatile( "r0 = 0;" "*(u64*)(r10 - 8) = r0;" "r1 = %[map] ll;" "r2 = r10;" "r2 += -8;" "call %[bpf_map_lookup_elem];" "r0 = 0;" "exit;" : : __imm(bpf_map_lookup_elem), __imm_addr(map) : __clobber_all); } Acked-by: Andrii Nakryiko <[email protected]> Acked-by: Yonghong Song <[email protected]> Signed-off-by: Eduard Zingerman <[email protected]> [ Kartikeya: Add acks, include __clobber_common from Andrii ] Signed-off-by: Kumar Kartikeya Dwivedi <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Alexei Starovoitov <[email protected]>
Diffstat (limited to 'tools/testing/selftests/bpf/progs/bpf_misc.h')
-rw-r--r--tools/testing/selftests/bpf/progs/bpf_misc.h7
1 files changed, 7 insertions, 0 deletions
diff --git a/tools/testing/selftests/bpf/progs/bpf_misc.h b/tools/testing/selftests/bpf/progs/bpf_misc.h
index 4a01ea9113bf..2d7b89b447b2 100644
--- a/tools/testing/selftests/bpf/progs/bpf_misc.h
+++ b/tools/testing/selftests/bpf/progs/bpf_misc.h
@@ -7,6 +7,13 @@
#define __success __attribute__((btf_decl_tag("comment:test_expect_success")))
#define __log_level(lvl) __attribute__((btf_decl_tag("comment:test_log_level="#lvl)))
+/* Convenience macro for use with 'asm volatile' blocks */
+#define __naked __attribute__((naked))
+#define __clobber_all "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7", "r8", "r9", "memory"
+#define __clobber_common "r0", "r1", "r2", "r3", "r4", "r5", "memory"
+#define __imm(name) [name]"i"(name)
+#define __imm_addr(name) [name]"i"(&name)
+
#if defined(__TARGET_ARCH_x86)
#define SYSCALL_WRAPPER 1
#define SYS_PREFIX "__x64_"