Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: run test_progs-cpuv4 flavor #253

Merged
merged 3 commits into from
Dec 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/scripts/matrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ def get_tests(config):
"test_maps",
"test_verifier",
]
if int(config.get("llvm-version", 0)) >= 18:
tests.append("test_progs_cpuv4")
if config.get("parallel_tests", False):
return tests
return [test for test in tests if not test.endswith("parallel")]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
From dfce9cb3140592b886838e06f3e0c25fea2a9cae Mon Sep 17 00:00:00 2001
From: Yonghong Song <[email protected]>
Date: Thu, 30 Nov 2023 18:46:40 -0800
Subject: [PATCH 1/1] bpf: Fix a verifier bug due to incorrect branch offset
comparison with cpu=v4

Bpf cpu=v4 support is introduced in [1] and Commit 4cd58e9af8b9
("bpf: Support new 32bit offset jmp instruction") added support for new
32bit offset jmp instruction. Unfortunately, in function
bpf_adj_delta_to_off(), for new branch insn with 32bit offset, the offset
(plus/minor a small delta) compares to 16-bit offset bound
[S16_MIN, S16_MAX], which caused the following verification failure:
$ ./test_progs-cpuv4 -t verif_scale_pyperf180
...
insn 10 cannot be patched due to 16-bit range
...
libbpf: failed to load object 'pyperf180.bpf.o'
scale_test:FAIL:expect_success unexpected error: -12 (errno 12)
#405 verif_scale_pyperf180:FAIL

Note that due to recent llvm18 development, the patch [2] (already applied
in bpf-next) needs to be applied to bpf tree for testing purpose.

The fix is rather simple. For 32bit offset branch insn, the adjusted
offset compares to [S32_MIN, S32_MAX] and then verification succeeded.

[1] https://lore.kernel.org/all/[email protected]
[2] https://lore.kernel.org/bpf/[email protected]

Fixes: 4cd58e9af8b9 ("bpf: Support new 32bit offset jmp instruction")
Signed-off-by: Yonghong Song <[email protected]>
Signed-off-by: Andrii Nakryiko <[email protected]>
Link: https://lore.kernel.org/bpf/[email protected]
---
kernel/bpf/core.c | 12 ++++++++----
1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/kernel/bpf/core.c b/kernel/bpf/core.c
index cd3afe57ece3..fe254ae035fe 100644
--- a/kernel/bpf/core.c
+++ b/kernel/bpf/core.c
@@ -371,14 +371,18 @@ static int bpf_adj_delta_to_imm(struct bpf_insn *insn, u32 pos, s32 end_old,
static int bpf_adj_delta_to_off(struct bpf_insn *insn, u32 pos, s32 end_old,
s32 end_new, s32 curr, const bool probe_pass)
{
- const s32 off_min = S16_MIN, off_max = S16_MAX;
+ s64 off_min, off_max, off;
s32 delta = end_new - end_old;
- s32 off;

- if (insn->code == (BPF_JMP32 | BPF_JA))
+ if (insn->code == (BPF_JMP32 | BPF_JA)) {
off = insn->imm;
- else
+ off_min = S32_MIN;
+ off_max = S32_MAX;
+ } else {
off = insn->off;
+ off_min = S16_MIN;
+ off_max = S16_MAX;
+ }

if (curr < pos && curr + off + 1 >= end_old)
off += delta;
--
2.34.1

Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
From d31a7125891994681503770cff46a119692fb2b9 Mon Sep 17 00:00:00 2001
From: Andrii Nakryiko <[email protected]>
Date: Mon, 11 Dec 2023 17:09:38 -0800
Subject: [PATCH 1/1] selftests/bpf: work around latest Clang smartness

Work around the issue while we deal with it in the Clang itself.
See [0].

[0] https://github.com/llvm/llvm-project/pull/73662#issuecomment-1849281758

Signed-off-by: Andrii Nakryiko <[email protected]>
---
tools/testing/selftests/bpf/progs/iters.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/testing/selftests/bpf/progs/iters.c b/tools/testing/selftests/bpf/progs/iters.c
index 3aca3dc145b5..929ba6fa2105 100644
--- a/tools/testing/selftests/bpf/progs/iters.c
+++ b/tools/testing/selftests/bpf/progs/iters.c
@@ -1420,7 +1420,7 @@ SEC("raw_tp")
__success
int iter_arr_with_actual_elem_count(const void *ctx)
{
- int i, n = loop_data.n, sum = 0;
+ unsigned i, n = loop_data.n, sum = 0;

if (n > ARRAY_SIZE(loop_data.data))
return 0;
--
2.34.1

5 changes: 5 additions & 0 deletions ci/vmtest/run_selftests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,10 @@ test_progs_no_alu32_parallel() {
test_progs_helper "-no_alu32" "-j"
}

test_progs_cpuv4() {
test_progs_helper "-cpuv4" ""
}

test_maps() {
foldable start test_maps "Testing test_maps"
taskset 0xF ./test_maps && true
Expand Down Expand Up @@ -179,6 +183,7 @@ read_test_names "$@"
if [ ${#TEST_NAMES[@]} -eq 0 ]; then
test_progs
test_progs_no_alu32
test_progs_cpuv4
test_maps
test_verifier
else
Expand Down
Loading