Commit 4b7ede0b authored by Kumar Kartikeya Dwivedi's avatar Kumar Kartikeya Dwivedi Committed by Alexei Starovoitov
Browse files

selftests/bpf: Introduce cond_break_label



Add a new cond_break_label macro that jumps to the specified label when
the cond_break termination check fires, and allows us to better handle
the uncontrolled termination of the loop.

Signed-off-by: default avatarKumar Kartikeya Dwivedi <memxor@gmail.com>
Link: https://lore.kernel.org/r/20250306035431.2186189-2-memxor@gmail.com


Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
parent dc438a9b
Loading
Loading
Loading
Loading
+9 −6
Original line number Diff line number Diff line
@@ -368,12 +368,12 @@ l_true: \
	ret;						\
	})

#define cond_break					\
#define __cond_break(expr)				\
	({ __label__ l_break, l_continue;		\
	asm volatile goto("may_goto %l[l_break]"	\
		      :::: l_break);			\
	goto l_continue;				\
	l_break: break;					\
	l_break: expr;					\
	l_continue:;					\
	})
#else
@@ -392,7 +392,7 @@ l_true: \
	ret;						\
	})

#define cond_break					\
#define __cond_break(expr)				\
	({ __label__ l_break, l_continue;		\
	asm volatile goto("1:.byte 0xe5;		\
		      .byte 0;				\
@@ -400,7 +400,7 @@ l_true: \
		      .short 0"				\
		      :::: l_break);			\
	goto l_continue;				\
	l_break: break;					\
	l_break: expr;					\
	l_continue:;					\
	})
#else
@@ -418,7 +418,7 @@ l_true: \
	ret;						\
	})

#define cond_break					\
#define __cond_break(expr)				\
	({ __label__ l_break, l_continue;		\
	asm volatile goto("1:.byte 0xe5;		\
		      .byte 0;				\
@@ -426,12 +426,15 @@ l_true: \
		      .short 0"				\
		      :::: l_break);			\
	goto l_continue;				\
	l_break: break;					\
	l_break: expr;					\
	l_continue:;					\
	})
#endif
#endif

#define cond_break __cond_break(break)
#define cond_break_label(label) __cond_break(goto label)

#ifndef bpf_nop_mov
#define bpf_nop_mov(var) \
	asm volatile("%[reg]=%[reg]"::[reg]"r"((short)var))