]> www.infradead.org Git - users/dwmw2/linux.git/commitdiff
selftests/bpf: Introduce cond_break_label
authorKumar Kartikeya Dwivedi <memxor@gmail.com>
Thu, 6 Mar 2025 03:54:29 +0000 (19:54 -0800)
committerAlexei Starovoitov <ast@kernel.org>
Sat, 15 Mar 2025 18:48:56 +0000 (11:48 -0700)
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: Kumar Kartikeya Dwivedi <memxor@gmail.com>
Link: https://lore.kernel.org/r/20250306035431.2186189-2-memxor@gmail.com
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
tools/testing/selftests/bpf/bpf_experimental.h

index cd8ecd39c3f3c68d40c6e3e1465b42ed66537027..6535c8ae3c46927449859b31b881617fed92066f 100644 (file)
@@ -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))