From: Alexei Starovoitov <alexei.starovoitov@gmail.com>
To: bpf@vger.kernel.org
Cc: daniel@iogearbox.net, andrii@kernel.org, martin.lau@kernel.org,
memxor@gmail.com, eddyz87@gmail.com, kernel-team@fb.com
Subject: [PATCH v3 bpf-next 3/4] bpf: Add cond_break macro
Date: Thu, 29 Feb 2024 19:37:33 -0800 [thread overview]
Message-ID: <20240301033734.95939-4-alexei.starovoitov@gmail.com> (raw)
In-Reply-To: <20240301033734.95939-1-alexei.starovoitov@gmail.com>
From: Alexei Starovoitov <ast@kernel.org>
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] - . - 4) / 8;
.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] - . - 4) / 8;
.short 0;
that produces correct asm on little endian.
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
---
tools/testing/selftests/bpf/bpf_experimental.h | 12 ++++++++++++
1 file changed, 12 insertions(+)
diff --git a/tools/testing/selftests/bpf/bpf_experimental.h b/tools/testing/selftests/bpf/bpf_experimental.h
index 0d749006d107..2d408d8b9b70 100644
--- a/tools/testing/selftests/bpf/bpf_experimental.h
+++ b/tools/testing/selftests/bpf/bpf_experimental.h
@@ -326,6 +326,18 @@ l_true: \
})
#endif
+#define cond_break \
+ ({ __label__ l_break, l_continue; \
+ asm volatile goto(".byte 0xe5; \
+ .byte 0; \
+ .long (%l[l_break] - . - 4) / 8; \
+ .short 0" \
+ :::: l_break); \
+ goto l_continue; \
+ l_break: break; \
+ l_continue:; \
+ })
+
#ifndef bpf_nop_mov
#define bpf_nop_mov(var) \
asm volatile("%[reg]=%[reg]"::[reg]"r"((short)var))
--
2.34.1
next prev parent reply other threads:[~2024-03-01 3:37 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-03-01 3:37 [PATCH v3 bpf-next 0/4] bpf: Introduce may_goto and cond_break Alexei Starovoitov
2024-03-01 3:37 ` [PATCH v3 bpf-next 1/4] bpf: Introduce may_goto instruction Alexei Starovoitov
2024-03-01 3:37 ` [PATCH v3 bpf-next 2/4] bpf: Recognize that two registers are safe when their ranges match Alexei Starovoitov
2024-03-01 3:37 ` Alexei Starovoitov [this message]
2024-03-01 3:37 ` [PATCH v3 bpf-next 4/4] selftests/bpf: Test may_goto Alexei Starovoitov
2024-03-01 19:47 ` John Fastabend
2024-03-01 21:16 ` Alexei Starovoitov
2024-03-01 21:47 ` John Fastabend
2024-03-01 22:06 ` John Fastabend
2024-03-01 22:12 ` Alexei Starovoitov
2024-03-01 21:22 ` Alexei Starovoitov
2024-03-01 5:24 ` [PATCH v3 bpf-next 0/4] bpf: Introduce may_goto and cond_break John Fastabend
2024-03-02 1:20 ` Eduard Zingerman
2024-03-02 1:28 ` Alexei Starovoitov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240301033734.95939-4-alexei.starovoitov@gmail.com \
--to=alexei.starovoitov@gmail.com \
--cc=andrii@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=eddyz87@gmail.com \
--cc=kernel-team@fb.com \
--cc=martin.lau@kernel.org \
--cc=memxor@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.