Skip to content

Commit 0637580

Browse files
Alexei Starovoitovanakryiko
authored andcommitted
bpf: Add cond_break macro
Use may_goto instruction to implement cond_break macro. Ideally the macro should be written as: asm volatile goto(".byte 0xe5; .byte 0; .short %l[l_break] ... .long 0; but LLVM doesn't recognize fixup of 2 byte PC relative yet. Hence use asm volatile goto(".byte 0xe5; .byte 0; .long %l[l_break] ... .short 0; that produces correct asm on little endian. Signed-off-by: Alexei Starovoitov <ast@kernel.org> Signed-off-by: Andrii Nakryiko <andrii@kernel.org> Acked-by: Eduard Zingerman <eddyz87@gmail.com> Acked-by: John Fastabend <john.fastabend@gmail.com> Tested-by: John Fastabend <john.fastabend@gmail.com> Link: https://lore.kernel.org/bpf/20240306031929.42666-4-alexei.starovoitov@gmail.com
1 parent 4f81c16 commit 0637580

1 file changed

Lines changed: 12 additions & 0 deletions

File tree

tools/testing/selftests/bpf/bpf_experimental.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,18 @@ l_true: \
326326
})
327327
#endif
328328

329+
#define cond_break \
330+
({ __label__ l_break, l_continue; \
331+
asm volatile goto("1:.byte 0xe5; \
332+
.byte 0; \
333+
.long ((%l[l_break] - 1b - 8) / 8) & 0xffff; \
334+
.short 0" \
335+
:::: l_break); \
336+
goto l_continue; \
337+
l_break: break; \
338+
l_continue:; \
339+
})
340+
329341
#ifndef bpf_nop_mov
330342
#define bpf_nop_mov(var) \
331343
asm volatile("%[reg]=%[reg]"::[reg]"r"((short)var))

0 commit comments

Comments
 (0)