From: Stephen Hemminger <stephen@networkplumber.org>
To: dev@dpdk.org
Cc: Stephen Hemminger <stephen@networkplumber.org>,
Marat Khalili <marat.khalili@huawei.com>,
Konstantin Ananyev <konstantin.ananyev@huawei.com>
Subject: [PATCH v7 05/10] test/bpf: add test for large shift
Date: Wed, 22 Jul 2026 09:05:17 -0700 [thread overview]
Message-ID: <20260722183351.633025-6-stephen@networkplumber.org> (raw)
In-Reply-To: <20260722183351.633025-1-stephen@networkplumber.org>
There were multiple bugs with immediate values in shift instructions.
The code was not masking as required by RFC.
Add new tests that cover these instructions.
Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
Acked-by: Marat Khalili <marat.khalili@huawei.com>
Acked-by: Konstantin Ananyev <konstantin.ananyev@huawei.com>
---
app/test/test_bpf.c | 59 +++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 59 insertions(+)
diff --git a/app/test/test_bpf.c b/app/test/test_bpf.c
index f4286bcefe..413d47357f 100644
--- a/app/test/test_bpf.c
+++ b/app/test/test_bpf.c
@@ -2012,6 +2012,51 @@ test_div1_check(uint64_t rc, const void *arg)
return cmp_res(__func__, 0, rc, dve.out, dvt->out, sizeof(dve.out));
}
+/*
+ * Shift counts are masked to the operand width (RFC 9669: 0x3f for 64-bit,
+ * 0x1f for 32-bit). Counts >= 128 also exercise the x86 imm_size() path that
+ * used to desync the stream, and the arm64 UBFM/SBFM immediate encoding.
+ */
+static const struct ebpf_insn test_shift_big_imm_prog[] = {
+ {
+ .code = (EBPF_ALU64 | EBPF_MOV | BPF_K),
+ .dst_reg = EBPF_REG_0,
+ .imm = 1
+ },
+ {
+ .code = (EBPF_ALU64 | BPF_LSH | BPF_K),
+ .dst_reg = EBPF_REG_0,
+ .imm = 191
+ },
+ {
+ .code = (EBPF_ALU64 | EBPF_ARSH | BPF_K),
+ .dst_reg = EBPF_REG_0,
+ .imm = 200
+ },
+ {
+ .code = (EBPF_ALU64 | BPF_RSH | BPF_K),
+ .dst_reg = EBPF_REG_0,
+ .imm = 130
+ },
+ {
+ .code = (BPF_JMP | EBPF_EXIT)
+ },
+};
+
+static void
+test_shift_big_imm_prepare(void *arg)
+{
+ memset(arg, 0, sizeof(struct dummy_offset));
+}
+
+static int
+test_shift_big_imm_check(uint64_t rc, const void *arg)
+{
+ uint64_t expect = 0x3FE0000000000000ULL;
+
+ return cmp_res(__func__, expect, rc, arg, arg, 0);
+}
+
/* call test-cases */
static const struct ebpf_insn test_call1_prog[] = {
@@ -3480,6 +3525,20 @@ static const struct bpf_test tests[] = {
.prepare = test_mul1_prepare,
.check_result = test_div1_check,
},
+ {
+ .name = "test_shift_big_imm",
+ .arg_sz = sizeof(struct dummy_offset),
+ .prm = {
+ .ins = test_shift_big_imm_prog,
+ .nb_ins = RTE_DIM(test_shift_big_imm_prog),
+ .prog_arg = {
+ .type = RTE_BPF_ARG_PTR,
+ .size = sizeof(struct dummy_offset),
+ },
+ },
+ .prepare = test_shift_big_imm_prepare,
+ .check_result = test_shift_big_imm_check,
+ },
{
.name = "test_call1",
.arg_sz = sizeof(struct dummy_offset),
--
2.53.0
next prev parent reply other threads:[~2026-07-22 18:34 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <0260608203322.1116296-1-stephen@networkplumber.org>
2026-07-22 16:05 ` [PATCH v7 00/10] bpf: bug fixes Stephen Hemminger
2026-07-22 16:05 ` [PATCH v7 01/10] bpf/x86: fix JIT encoding of fixed-width immediates Stephen Hemminger
2026-07-22 16:05 ` [PATCH v7 02/10] test/bpf: add JSET test with small immediate Stephen Hemminger
2026-07-22 16:05 ` [PATCH v7 03/10] bpf: mask shift count in interpreter per RFC 9669 Stephen Hemminger
2026-07-22 16:05 ` [PATCH v7 04/10] bpf/arm64: mask shift count " Stephen Hemminger
2026-07-22 16:05 ` Stephen Hemminger [this message]
2026-07-22 16:05 ` [PATCH v7 06/10] bpf/arm64: fix offset type to allow a negative jump Stephen Hemminger
2026-07-22 16:05 ` [PATCH v7 07/10] bpf/arm64: add BPF_ABS/BPF_IND packet load support Stephen Hemminger
2026-07-22 16:05 ` [PATCH v7 08/10] test/bpf: check that JIT was generated Stephen Hemminger
2026-07-22 16:05 ` [PATCH v7 09/10] test/bpf: check that bpf_convert can be JIT'd Stephen Hemminger
2026-07-22 16:05 ` [PATCH v7 10/10] bpf: fix uninitialized warning Stephen Hemminger
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=20260722183351.633025-6-stephen@networkplumber.org \
--to=stephen@networkplumber.org \
--cc=dev@dpdk.org \
--cc=konstantin.ananyev@huawei.com \
--cc=marat.khalili@huawei.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox