Skip to content

Commit 4db7d2a

Browse files
author
Kernel Patches Daemon
committed
adding ci files
1 parent 9ff5efd commit 4db7d2a

14 files changed

+6321
-18
lines changed

.github/actions/vmtest/action.yml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
name: 'vmtest'
2+
description: 'Build + run vmtest'
3+
inputs:
4+
arch:
5+
description: 'what arch to test'
6+
required: true
7+
default: 'x86_64'
8+
toolchain:
9+
description: 'what toolchain to use'
10+
required: true
11+
default: 'gcc'
12+
runs:
13+
using: "composite"
14+
steps:
15+
# 1. Setup environment
16+
- name: Setup build environment
17+
uses: libbpf/ci/setup-build-env@master
18+
# 2. Build
19+
- name: Build kernel image
20+
shell: bash
21+
run: ${GITHUB_ACTION_PATH}/build.sh ${{ inputs.arch }} ${{ inputs.toolchain }}
22+
- name: Build selftests
23+
shell: bash
24+
run: ${GITHUB_ACTION_PATH}/build_selftests.sh ${{ inputs.toolchain }}
25+
env:
26+
VMLINUX_BTF: ${{ github.workspace }}/vmlinux
27+
# 3. Test
28+
- name: Prepare rootfs
29+
uses: libbpf/ci/prepare-rootfs@master
30+
with:
31+
project-name: 'libbpf'
32+
arch: ${{ inputs.arch }}
33+
kernel-root: '.'
34+
- name: Run selftests
35+
uses: libbpf/ci/run-qemu@master
36+
with:
37+
arch: ${{ inputs.arch}}
38+
img: '/tmp/root.img'
39+
vmlinuz: '${{ github.workspace }}/vmlinuz'

.github/actions/vmtest/build.sh

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/bin/bash
2+
3+
set -euo pipefail
4+
5+
ARCH="$1"
6+
TOOLCHAIN="$2"
7+
TOOLCHAIN_NAME="$(echo $TOOLCHAIN | cut -d '-' -f 1)"
8+
TOOLCHAIN_VERSION="$(echo $TOOLCHAIN | cut -d '-' -f 2)"
9+
10+
if [ "$TOOLCHAIN_NAME" == "llvm" ]; then
11+
export LLVM="-$TOOLCHAIN_VERSION"
12+
fi
13+
14+
THISDIR="$(cd $(dirname $0) && pwd)"
15+
16+
source "${THISDIR}"/helpers.sh
17+
18+
travis_fold start build_kernel "Building kernel with $TOOLCHAIN"
19+
20+
cp ${GITHUB_WORKSPACE}/travis-ci/vmtest/configs/config-latest.${ARCH} .config
21+
22+
make -j $((4*$(nproc))) olddefconfig all > /dev/null
23+
24+
travis_fold end build_kernel
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#!/bin/bash
2+
3+
set -euo pipefail
4+
5+
THISDIR="$(cd $(dirname $0) && pwd)"
6+
7+
source "${THISDIR}"/helpers.sh
8+
9+
TOOLCHAIN="$1"
10+
TOOLCHAIN_NAME="$(echo $TOOLCHAIN | cut -d '-' -f 1)"
11+
TOOLCHAIN_VERSION="$(echo $TOOLCHAIN | cut -d '-' -f 2)"
12+
13+
if [ "$TOOLCHAIN_NAME" == "llvm" ]; then
14+
export LLVM="-$TOOLCHAIN_VERSION"
15+
LLVM_VER=$TOOLCHAIN_VERSION
16+
else
17+
LLVM_VER=15
18+
fi
19+
20+
travis_fold start prepare_selftests "Building selftests with $TOOLCHAIN"
21+
22+
LIBBPF_PATH="${REPO_ROOT}"
23+
24+
PREPARE_SELFTESTS_SCRIPT=${THISDIR}/prepare_selftests-${KERNEL}.sh
25+
if [ -f "${PREPARE_SELFTESTS_SCRIPT}" ]; then
26+
(cd "${REPO_ROOT}/${REPO_PATH}/tools/testing/selftests/bpf" && ${PREPARE_SELFTESTS_SCRIPT})
27+
fi
28+
29+
if [[ "${KERNEL}" = 'LATEST' ]]; then
30+
VMLINUX_H=
31+
else
32+
VMLINUX_H=${THISDIR}/vmlinux.h
33+
fi
34+
35+
cd ${REPO_ROOT}/${REPO_PATH}
36+
make \
37+
CLANG=clang-${LLVM_VER} \
38+
LLC=llc-${LLVM_VER} \
39+
LLVM_STRIP=llvm-strip-${LLVM_VER} \
40+
VMLINUX_BTF="${VMLINUX_BTF}" \
41+
VMLINUX_H="${VMLINUX_H}" \
42+
-C "${REPO_ROOT}/${REPO_PATH}/tools/testing/selftests/bpf" \
43+
-j $((4*$(nproc))) > /dev/null
44+
cd -
45+
mkdir "${LIBBPF_PATH}"/selftests
46+
cp -R "${REPO_ROOT}/${REPO_PATH}/tools/testing/selftests/bpf" \
47+
"${LIBBPF_PATH}"/selftests
48+
cd "${LIBBPF_PATH}"
49+
rm selftests/bpf/.gitignore
50+
git add selftests
51+
52+
travis_fold end prepare_selftests

.github/actions/vmtest/helpers.sh

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# $1 - start or end
2+
# $2 - fold identifier, no spaces
3+
# $3 - fold section description
4+
travis_fold() {
5+
local YELLOW='\033[1;33m'
6+
local NOCOLOR='\033[0m'
7+
if [ -z ${GITHUB_WORKFLOW+x} ]; then
8+
echo travis_fold:$1:$2
9+
if [ ! -z "${3:-}" ]; then
10+
echo -e "${YELLOW}$3${NOCOLOR}"
11+
fi
12+
echo
13+
else
14+
if [ $1 = "start" ]; then
15+
line="::group::$2"
16+
if [ ! -z "${3:-}" ]; then
17+
line="$line - ${YELLOW}$3${NOCOLOR}"
18+
fi
19+
else
20+
line="::endgroup::"
21+
fi
22+
echo -e "$line"
23+
fi
24+
}
25+
26+
__print() {
27+
local TITLE=""
28+
if [[ -n $2 ]]; then
29+
TITLE=" title=$2"
30+
fi
31+
echo "::$1${TITLE}::$3"
32+
}
33+
34+
# $1 - title
35+
# $2 - message
36+
print_error() {
37+
__print error $1 $2
38+
}
39+
40+
# $1 - title
41+
# $2 - message
42+
print_notice() {
43+
__print notice $1 $2
44+
}

.github/workflows/test.yml

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
name: bpf-ci
2+
3+
on:
4+
pull_request:
5+
6+
concurrency:
7+
group: ci-test-${{ github.head_ref }}
8+
cancel-in-progress: true
9+
10+
jobs:
11+
VM_Test:
12+
runs-on: ${{ matrix.runs_on }}
13+
name: Kernel ${{ matrix.kernel }} on ${{ matrix.runs_on }} with ${{ matrix.toolchain }}
14+
timeout-minutes: 100
15+
strategy:
16+
fail-fast: false
17+
matrix:
18+
include:
19+
- kernel: 'LATEST'
20+
runs_on: ubuntu-latest
21+
arch: 'x86_64'
22+
toolchain: 'gcc'
23+
- kernel: 'LATEST'
24+
runs_on: ubuntu-latest
25+
arch: 'x86_64'
26+
toolchain: 'llvm-15'
27+
- kernel: 'LATEST'
28+
runs_on: z15
29+
arch: 's390x'
30+
toolchain: 'gcc'
31+
env:
32+
AUTHOR_EMAIL: "$(git log -1 --pretty=\"%aE\")"
33+
KERNEL: LATEST
34+
REPO_ROOT: ${{ github.workspace }}
35+
REPO_PATH: ""
36+
steps:
37+
- uses: actions/checkout@v2
38+
- if: ${{ github.repository == 'kernel-patches/vmtest' }}
39+
name: Download bpf-next tree
40+
uses: libbpf/ci/get-linux-source@master
41+
with:
42+
dest: '.kernel'
43+
- if: ${{ github.repository == 'kernel-patches/vmtest' }}
44+
name: Move linux source in place
45+
shell: bash
46+
run: |
47+
rm -rf .kernel/.git
48+
cp -rf .kernel/. .
49+
rm -rf .kernel
50+
- uses: libbpf/ci/patch-kernel@master
51+
with:
52+
patches-root: '${{ github.workspace }}/travis-ci/diffs'
53+
repo-root: '${{ github.workspace }}'
54+
- uses: ./.github/actions/vmtest
55+
with:
56+
arch: ${{ matrix.arch }}
57+
toolchain: ${{ matrix.toolchain }}

README

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +0,0 @@
1-
Linux kernel
2-
============
3-
4-
There are several guides for kernel developers and users. These guides can
5-
be rendered in a number of formats, like HTML and PDF. Please read
6-
Documentation/admin-guide/README.rst first.
7-
8-
In order to build the documentation, use ``make htmldocs`` or
9-
``make pdfdocs``. The formatted documentation can also be read online at:
10-
11-
https://www.kernel.org/doc/html/latest/
12-
13-
There are various text files in the Documentation/ subdirectory,
14-
several of them using the Restructured Text markup notation.
15-
16-
Please read the Documentation/process/changes.rst file, as it contains the
17-
requirements for building and running the kernel, and information about
18-
the problems which may result by upgrading your kernel.
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
From 8c89b5db7a2894e33417dd69680729e8f65f5709 Mon Sep 17 00:00:00 2001
2+
From: Yonghong Song <[email protected]>
3+
Date: Mon, 18 Apr 2022 21:32:30 -0700
4+
Subject: [PATCH] selftests/bpf: Limit unroll_count for pyperf600 test
5+
6+
LLVM commit [1] changed loop pragma behavior such that
7+
full loop unroll is always honored with user pragma.
8+
Previously, unroll count also depends on the unrolled
9+
code size. For pyperf600, without [1], the loop unroll
10+
count is 150. With [1], the loop unroll count is 600.
11+
12+
The unroll count of 600 caused the program size close to
13+
298k and this caused the following code is generated:
14+
0: 7b 1a 00 ff 00 00 00 00 *(u64 *)(r10 - 256) = r1
15+
; uint64_t pid_tgid = bpf_get_current_pid_tgid();
16+
1: 85 00 00 00 0e 00 00 00 call 14
17+
2: bf 06 00 00 00 00 00 00 r6 = r0
18+
; pid_t pid = (pid_t)(pid_tgid >> 32);
19+
3: bf 61 00 00 00 00 00 00 r1 = r6
20+
4: 77 01 00 00 20 00 00 00 r1 >>= 32
21+
5: 63 1a fc ff 00 00 00 00 *(u32 *)(r10 - 4) = r1
22+
6: bf a2 00 00 00 00 00 00 r2 = r10
23+
7: 07 02 00 00 fc ff ff ff r2 += -4
24+
; PidData* pidData = bpf_map_lookup_elem(&pidmap, &pid);
25+
8: 18 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 r1 = 0 ll
26+
10: 85 00 00 00 01 00 00 00 call 1
27+
11: bf 08 00 00 00 00 00 00 r8 = r0
28+
; if (!pidData)
29+
12: 15 08 15 e8 00 00 00 00 if r8 == 0 goto -6123 <LBB0_27588+0xffffffffffdae100>
30+
31+
Note that insn 12 has a branch offset -6123 which is clearly illegal
32+
and will be rejected by the verifier. The negative offset is due to
33+
the branch range is greater than INT16_MAX.
34+
35+
This patch changed the unroll count to be 150 to avoid above
36+
branch target insn out-of-range issue. Also the llvm is enhanced ([2])
37+
to assert if the branch target insn is out of INT16 range.
38+
39+
[1] https://reviews.llvm.org/D119148
40+
[2] https://reviews.llvm.org/D123877
41+
42+
Signed-off-by: Yonghong Song <[email protected]>
43+
Signed-off-by: Alexei Starovoitov <[email protected]>
44+
Link: https://lore.kernel.org/bpf/[email protected]
45+
---
46+
tools/testing/selftests/bpf/progs/pyperf.h | 4 ++++
47+
tools/testing/selftests/bpf/progs/pyperf600.c | 11 +++++++----
48+
2 files changed, 11 insertions(+), 4 deletions(-)
49+
50+
diff --git a/tools/testing/selftests/bpf/progs/pyperf.h b/tools/testing/selftests/bpf/progs/pyperf.h
51+
index 1ed28882daf3..5d3dc4d66d47 100644
52+
--- a/tools/testing/selftests/bpf/progs/pyperf.h
53+
+++ b/tools/testing/selftests/bpf/progs/pyperf.h
54+
@@ -299,7 +299,11 @@ int __on_event(struct bpf_raw_tracepoint_args *ctx)
55+
#ifdef NO_UNROLL
56+
#pragma clang loop unroll(disable)
57+
#else
58+
+#ifdef UNROLL_COUNT
59+
+#pragma clang loop unroll_count(UNROLL_COUNT)
60+
+#else
61+
#pragma clang loop unroll(full)
62+
+#endif
63+
#endif /* NO_UNROLL */
64+
/* Unwind python stack */
65+
for (int i = 0; i < STACK_MAX_LEN; ++i) {
66+
diff --git a/tools/testing/selftests/bpf/progs/pyperf600.c b/tools/testing/selftests/bpf/progs/pyperf600.c
67+
index cb49b89e37cd..ce1aa5189cc4 100644
68+
--- a/tools/testing/selftests/bpf/progs/pyperf600.c
69+
+++ b/tools/testing/selftests/bpf/progs/pyperf600.c
70+
@@ -1,9 +1,12 @@
71+
// SPDX-License-Identifier: GPL-2.0
72+
// Copyright (c) 2019 Facebook
73+
#define STACK_MAX_LEN 600
74+
-/* clang will not unroll the loop 600 times.
75+
- * Instead it will unroll it to the amount it deemed
76+
- * appropriate, but the loop will still execute 600 times.
77+
- * Total program size is around 90k insns
78+
+/* Full unroll of 600 iterations will have total
79+
+ * program size close to 298k insns and this may
80+
+ * cause BPF_JMP insn out of 16-bit integer range.
81+
+ * So limit the unroll size to 150 so the
82+
+ * total program size is around 80k insns but
83+
+ * the loop will still execute 600 times.
84+
*/
85+
+#define UNROLL_COUNT 150
86+
#include "pyperf.h"
87+
--
88+
2.30.2
89+
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
From 0744fe5996e977b7a1634504b6a77426f6384bbe Mon Sep 17 00:00:00 2001
2+
From: Song Liu <[email protected]>
3+
Date: Thu, 26 May 2022 12:06:12 -0700
4+
Subject: [PATCH bpf] selftests/bpf: fix stacktrace_build_id with missing
5+
kprobe/urandom_read
6+
7+
Kernel function urandom_read is replaced with urandom_read_iter.
8+
Therefore, kprobe on urandom_read is not working any more:
9+
10+
[root@eth50-1 bpf]# ./test_progs -n 161
11+
test_stacktrace_build_id:PASS:skel_open_and_load 0 nsec
12+
libbpf: kprobe perf_event_open() failed: No such file or directory
13+
libbpf: prog 'oncpu': failed to create kprobe 'urandom_read+0x0' \
14+
perf event: No such file or directory
15+
libbpf: prog 'oncpu': failed to auto-attach: -2
16+
test_stacktrace_build_id:FAIL:attach_tp err -2
17+
161 stacktrace_build_id:FAIL
18+
19+
Fix this by replacing urandom_read with urandom_read_iter in the test.
20+
21+
Fixes: 1b388e7765f2 ("random: convert to using fops->read_iter()")
22+
Reported-by: Mykola Lysenko <[email protected]>
23+
Signed-off-by: Song Liu <[email protected]>
24+
---
25+
tools/testing/selftests/bpf/progs/test_stacktrace_build_id.c | 2 +-
26+
1 file changed, 1 insertion(+), 1 deletion(-)
27+
28+
diff --git a/tools/testing/selftests/bpf/progs/test_stacktrace_build_id.c b/tools/testing/selftests/bpf/progs/test_stacktrace_build_id.c
29+
index 6c62bfb8bb6f..0c4426592a26 100644
30+
--- a/tools/testing/selftests/bpf/progs/test_stacktrace_build_id.c
31+
+++ b/tools/testing/selftests/bpf/progs/test_stacktrace_build_id.c
32+
@@ -39,7 +39,7 @@ struct {
33+
__type(value, stack_trace_t);
34+
} stack_amap SEC(".maps");
35+
36+
-SEC("kprobe/urandom_read")
37+
+SEC("kprobe/urandom_read_iter")
38+
int oncpu(struct pt_regs *args)
39+
{
40+
__u32 max_len = sizeof(struct bpf_stack_build_id)
41+
--
42+
2.30.2
43+
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# TEMPORARY
2+
btf_dump/btf_dump: syntax
3+
kprobe_multi_test/bench_attach
4+
core_reloc/enum64val
5+
varlen
6+
core_reloc/size___diff_sz
7+
core_reloc/type_based___diff_sz

0 commit comments

Comments
 (0)