Skip to content
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
134 changes: 129 additions & 5 deletions .github/scripts/build_check
Original file line number Diff line number Diff line change
@@ -1,16 +1,140 @@
#!/usr/bin/env bash
# SPDX-License-Identifier: GPL-2.0-only

set -oe pipefail
set -o pipefail

wpattern=" warning: "
logfile="build.log"
warnings_file="build_warnings.log"
unexpected_warnings_file="unexpected_build_warnings.log"
allowlist_file=".github/scripts/build_warning_allowlist"

docker run -v "$(pwd)"/BM:/src builder make test | tee "$logfile"
repo_root="$(git rev-parse --show-toplevel 2>/dev/null || pwd)"
bm_dir="${repo_root}/BM"
container_name="lkvs-build-check-${GITHUB_RUN_ID:-manual}-${GITHUB_RUN_ATTEMPT:-0}"

# tdx-compliance builds a kernel module and requires a matching
# /lib/modules/$(uname -r)/build tree, which is not available/matched in
# the CI docker environment. Keep workload-xsave covered by CI.
ci_skip_subdirs="${DDT_SKIP_SUBDIRS:-tdx-compliance}"

cleanup_container()
{
docker rm -f "$container_name" >/dev/null 2>&1 || true
}

rm -f "$logfile" "$warnings_file" "$unexpected_warnings_file"
cleanup_container
trap cleanup_container EXIT

echo "===== Build check configuration ====="
echo "repo_root=${repo_root}"
echo "bm_dir=${bm_dir}"
echo "container_name=${container_name}"
echo "DDT_SKIP_SUBDIRS=${ci_skip_subdirs}"
echo "====================================="

echo "===== Docker build environment info ====="
docker run --rm \
-v "${bm_dir}":/src \
-w /src \
builder \
sh -c '
echo "Container userspace:"
cat /etc/os-release 2>/dev/null || true

echo
echo "Toolchain versions:"
gcc --version 2>/dev/null | head -n 1 || true
g++ --version 2>/dev/null | head -n 1 || true

echo
echo "uname before BM test target copies fake uname:"
command -v uname || true
uname -a || true
uname -r || true

echo
echo "Available kernel module build directories:"
ls -ld /lib/modules/*/build 2>/dev/null || true

echo
echo "Fake uname shipped in image, if present:"
ls -l /usr/local/uname 2>/dev/null || true
' || true
echo "========================================="

echo "===== Preconfigure rasdaemon in a smaller Docker run ====="
docker run --rm \
-v "${bm_dir}":/src \
-w /src \
builder \
sh -c '
set -e
cd /src/ras/rasdaemon

if [ ! -x ./configure ]; then
autoreconf -i
fi

if [ ! -f ./Makefile ]; then
./configure --enable-sqlite3 --enable-mce \
--enable-extlog --enable-memory-failure --enable-memory-ce-pfa
fi
'

preconfigure_rc=$?
if [ "$preconfigure_rc" -ne 0 ]; then
echo "==========================================="
echo "rasdaemon preconfigure failed with rc=${preconfigure_rc}"
echo "==========================================="
exit "$preconfigure_rc"
fi

echo "===== Start build in named container ====="
docker run \
--name "$container_name" \
-v "${bm_dir}":/src \
-w /src \
builder \
make DDT_SKIP_SUBDIRS="${ci_skip_subdirs}" test 2>&1 | tee "$logfile"

docker_rc=${PIPESTATUS[0]}

if [ "$docker_rc" -ne 0 ]; then
echo "==========================================="
echo "docker build container failed with rc=${docker_rc}"
echo "==========================================="
exit "$docker_rc"
fi

grep "$wpattern" "$logfile" > "$warnings_file" || true

if [ -s "$warnings_file" ]; then
if [ -f "$allowlist_file" ]; then
grep -Ev -f "$allowlist_file" "$warnings_file" > "$unexpected_warnings_file" || true
else
cp "$warnings_file" "$unexpected_warnings_file"
fi

if [ -s "$unexpected_warnings_file" ]; then
echo "==========================================="
echo "There are unexpected build warning(s), fix required!"
echo "==========================================="
cat "$unexpected_warnings_file"
exit 1
fi

if grep "$wpattern" "$logfile"; then
echo "==========================================="
echo "There are build warning(s), fix required!"
echo "Only known/allowed build warning(s) found."
echo "Allowed warnings count: $(wc -l < "$warnings_file")"
echo "==========================================="
else
echo "==========================================="
echo "No build warnings found."
echo "==========================================="
false
fi

echo "==========================================="
echo "Build check passed."
echo "==========================================="
38 changes: 38 additions & 0 deletions .github/scripts/build_warning_allowlist
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
^wrss\.c:31: warning: "SHADOW_STACK_SET_TOKEN" redefined
^shstk_unlock_test\.c:35: warning: "SHADOW_STACK_SET_TOKEN" redefined
^shstk_cp\.c:28: warning: "SHADOW_STACK_SET_TOKEN" redefined
^glibc_shstk_test\.c:154:9: warning: 'memset' writing 44 bytes into a region of size 20 overflows the destination
^glibc_shstk_test\.c:167:9: warning: 'memset' writing 28 bytes into a region of size 20 overflows the destination

^cmpccxadd\.c:70:16: warning: format '%d' expects argument of type 'int', but argument [0-9]+ has type 'long unsigned int'
^cmpccxadd\.c:85:16: warning: format '%d' expects argument of type 'int', but argument [0-9]+ has type 'long unsigned int'
^cmpccxadd\.c:101:16: warning: format '%d' expects argument of type 'int', but argument [0-9]+ has type 'long int'
^cmpccxadd\.c:116:16: warning: format '%d' expects argument of type 'int', but argument [0-9]+ has type 'long int'
^cmpccxadd\.c:147:[0-9]+: warning: format '%d' expects argument of type 'int', but argument [0-9]+ has type 'long unsigned int'
^cmpccxadd\.c:162:[0-9]+: warning: format '%d' expects argument of type 'int', but argument [0-9]+ has type 'long int'

^sort_test\.c:55:42: warning: format '%zu' expects argument of type 'size_t', but argument 2 has type 'int'
^ltp-pan\.c:433:15: warning: variable 'av' set but not used
^victim\.c:57:13: warning: variable 'fatarray' set but not used
^erst-inject\.c:137:34: warning: variable 'mem_err' set but not used
^/usr/include/features\.h:196:3: warning: #warning "_BSD_SOURCE and _SVID_SOURCE are deprecated, use _DEFAULT_SOURCE"

^tinjpage\.c:824:36: warning: '%s' directive output may be truncated writing up to 255 bytes into a region of size 100
^tinjpage\.c:230:35: warning: 'fclose' called on pointer returned from a mismatched allocation function
^tsoftinj\.c:149:38: warning: '%s' directive output may be truncated writing up to 255 bytes into a region of size 100
^page-poisoning\.c:399:44: warning: '/dirty' directive output may be truncated writing 6 bytes into a region of size between 1 and 4096
^page-poisoning\.c:469:35: warning: '/clean' directive output may be truncated writing 6 bytes into a region of size between 1 and 4096

^einj\.c:168:45: warning: format '%x' expects argument of type 'unsigned int', but argument 4 has type 'long long unsigned int'
^einj_mem_uc\.c:985:17: warning: ignoring return value of 'fscanf' declared with attribute 'warn_unused_result'
^proc_cpuinfo\.c:52:64: warning: format '%d' expects argument of type 'int', but argument 3 has type 'long int'
^/usr/bin/ld: warning: do_memcpy\.o: missing \.note\.GNU-stack section implies executable stack

^memattr\.c:138:40: warning: format '%ld' expects argument of type 'long int', but argument 2 has type 'int'
^memattr\.c:138:63: warning: format '%d' expects argument of type 'int', but argument 4 has type 'long unsigned int'
^memattr\.c:138:68: warning: format '%d' expects argument of type 'int', but argument 5 has type 'long unsigned int'
^victim\.c:347:17: warning: ignoring return value of 'read' declared with attribute 'warn_unused_result'

^page\.c:382:25: warning: ignoring return value of 'asprintf' declared with attribute 'warn_unused_result'
^page\.c:389:25: warning: ignoring return value of 'asprintf' declared with attribute 'warn_unused_result'
^page\.c:400:25: warning: ignoring return value of 'asprintf' declared with attribute 'warn_unused_result'
119 changes: 89 additions & 30 deletions .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,49 +11,67 @@ on:

jobs:
CodeCheck:
runs-on: ubuntu-latest
runs-on: ubuntu-24.04
steps:
- name: Setup Environment
shell: bash
run: |
sudo apt install -y python3 python3-pip python3-git python3-ply git shellcheck perl codespell
set -euo pipefail

sudo apt-get update
sudo apt-get install -y python3 python3-pip python3-git python3-ply git shellcheck perl codespell wget

sudo mkdir -p /usr/share/codespell
sudo wget https://raw.githubusercontent.com/codespell-project/codespell/master/codespell_lib/data/dictionary.txt -O /usr/share/codespell/dictionary.txt
sudo wget https://raw.githubusercontent.com/torvalds/linux/master/scripts/spelling.txt -O /usr/bin/spelling.txt
sudo wget https://raw.githubusercontent.com/torvalds/linux/master/scripts/const_structs.checkpatch -O /usr/bin/const_structs.checkpatch
sudo wget https://raw.githubusercontent.com/torvalds/linux/master/scripts/checkpatch.pl -O /bin/checkpatch.pl
sudo chmod +x /bin/checkpatch.pl
- name: Checkout Repository
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Check Code
run: |
git config --global --add safe.directory "$GITHUB_WORKSPACE"
./.github/scripts/pr_check "origin/${{ github.base_ref }}" "${{ github.sha }}"

BuildCheck:
runs-on: ubuntu-latest
runs-on: ubuntu-24.04
steps:
- name: Setup Environment
- name: Show runner info
shell: bash
run: |
sudo apt remove docker docker-engine docker.io containerd runc -y
sudo apt install ca-certificates curl gnupg lsb-release -y
sudo mkdir -p /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt update
sudo apt install docker-ce docker-ce-cli containerd.io docker-compose-plugin -y
set -euo pipefail

echo "===== GitHub runner context ====="
echo "Runner OS: ${RUNNER_OS:-unknown}"
echo "Runner arch: ${RUNNER_ARCH:-unknown}"
echo "GitHub ref: ${GITHUB_REF:-unknown}"
echo "GitHub SHA: ${GITHUB_SHA:-unknown}"

echo "===== /etc/os-release ====="
cat /etc/os-release || true

echo "===== uname ====="
uname -a || true

echo "===== docker ====="
docker --version
docker info >/dev/null && echo "Docker daemon is ready."
- name: Checkout Repository
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
fetch-depth: 0
submodules: recursive
- name: Build Docker Image
run: sudo docker build -f BM/Dockerfile.build -t builder BM
run: docker build -f BM/Dockerfile.build.ddt -t builder BM
- name: Build Project
run: sudo ./.github/scripts/build_check
run: ./.github/scripts/build_check

python-style-check:
name: Python ${{ matrix.python-version }}
runs-on: ubuntu-latest
runs-on: ubuntu-24.04

strategy:
matrix:
Expand All @@ -62,11 +80,11 @@ jobs:

steps:
- name: Check out repository code
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
Expand All @@ -76,33 +94,74 @@ jobs:
- name: Run inspekt
run: inspekt checkall ./KVM --disable-style E501,E265,W601,E402,E722,E741 --disable-lint=W,R,C,E0601,E1002,E1101,E1103,E1120,F0401,I0011,I1101 --enable-lint W0611,W1201 --no-license-check
- run: echo "This job's status is ${{ job.status }}."

cfg-lint-check:
name: Cfg lint
runs-on: ubuntu-latest
runs-on: ubuntu-24.04
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}

steps:
- name: Check out repository code
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Get changed files
- name: Get changed cfg files
id: cfg-files
uses: tj-actions/changed-files@v46
with:
files: |
./KVM/qemu/*.cfg
shell: bash
run: |
set -euo pipefail

BASE="${{ github.event.pull_request.base.sha }}"
HEAD="${{ github.event.pull_request.head.sha }}"
MERGE_BASE="$(git merge-base "${BASE}" "${HEAD}")"

echo "Base SHA: ${BASE}"
echo "Head SHA: ${HEAD}"
echo "Merge base: ${MERGE_BASE}"

# Include added, copied, modified, renamed, and type-changed cfg files; exclude deleted files.
git diff --name-only --diff-filter=ACMRT "${MERGE_BASE}" "${HEAD}" -- 'KVM/qemu/*.cfg' > changed_cfg_files.txt

echo "Changed cfg files:"
cat changed_cfg_files.txt || true

{
echo "all_changed_files<<EOF"
cat changed_cfg_files.txt
echo "EOF"
} >> "$GITHUB_OUTPUT"

if [ -s changed_cfg_files.txt ]; then
echo "any_changed=true" >> "$GITHUB_OUTPUT"
else
echo "any_changed=false" >> "$GITHUB_OUTPUT"
fi
- name: Set matrix
id: set-matrix
run: echo matrix=$(python3 -c 'print("${{ steps.cfg-files.outputs.all_changed_files }}".split())') >> $GITHUB_OUTPUT
shell: bash
run: |
python3 - <<'PY' >> "$GITHUB_OUTPUT"
import json

with open("changed_cfg_files.txt", "r", encoding="utf-8") as f:
files = [line.strip() for line in f if line.strip()]

print(f"matrix={json.dumps(files)}")
PY
- name: Check cfg files lint
if: steps.cfg-files.outputs.any_changed == 'true'
shell: bash
run: |
./.github/scripts/cfg-lint-check.py ${{ steps.cfg-files.outputs.all_changed_files }}
set -euo pipefail
mapfile -t cfg_files < changed_cfg_files.txt
echo "Linting cfg files:"
printf ' %s\n' "${cfg_files[@]}"
./.github/scripts/cfg-lint-check.py "${cfg_files[@]}"

cartesian-syntax-check:
name: Cartesian syntax
runs-on: ubuntu-latest
runs-on: ubuntu-24.04
needs: cfg-lint-check
if: ${{ needs.cfg-lint-check.outputs.matrix != '[]' }}
strategy:
Expand All @@ -112,7 +171,7 @@ jobs:

steps:
- name: Check out repository code
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Parse ${{ matrix.file }} into Cartesian configuration
Expand Down
8 changes: 7 additions & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,16 @@
branch = stable
[submodule "BM/ras/mce-test"]
path = BM/ras/mce-test
url = https://github.com/laifryiee/mce-test.git
url = https://git.kernel.org/pub/scm/utils/cpu/mce/mce-test.git
[submodule "BM/ras/ras-tools"]
path = BM/ras/ras-tools
url = https://git.kernel.org/pub/scm/linux/kernel/git/aegl/ras-tools.git
[submodule "BM/ras/mcelog"]
path = BM/ras/mcelog
url = https://github.com/andikleen/mcelog.git
[submodule "BM/ras/mce-inject"]
path = BM/ras/mce-inject
url = https://git.kernel.org/pub/scm/utils/cpu/mce/mce-inject.git
[submodule "BM/ras/rasdaemon"]
path = BM/ras/rasdaemon
url = https://github.com/mchehab/rasdaemon.git
Loading
Loading