From 0360b8dc462d87b5a793e14b6feebfb639e8046e Mon Sep 17 00:00:00 2001 From: Noah Date: Fri, 9 Oct 2026 10:12:15 -0600 Subject: [PATCH] kernel: single M0 batch (cgroups, namespaces, PSI, raw table, nftables) with a symbol list and clock keep-alive One kernel flash for everything later work needs (rebuild M0, d09 M0-2): - warden_defconfig: cgroup v2 controllers (MEMCG, CGROUP_PIDS, CGROUP_SCHED, FAIR_GROUP_SCHED, CFS_BANDWIDTH), the byte-metering match symbols (XT_MATCH_CGROUP, XT_CONNMARK, XT_MARK, IP6_NF_MANGLE), IKCONFIG and IKCONFIG_PROC, XT_MATCH_OWNER, the raw tables and the CT target (the NOTRACK for flare-edge#537), NAMESPACES with its five sub-options (USER_NS stays closed at boot by a sysctl), PSI, and the nftables set (NF_TABLES, ip and ip6 families, NFT_CT, NFT_MASQ, NFT_NAT, NFT_LIMIT, NFT_SOCKET, NFT_REJECT). TIME_NS and RT_GROUP_SCHED are explicitly unset. HW_RANDOM_ROCKCHIP is built in as a probe for the hardware RNG. - build/required-symbols.txt and probe-symbols.txt are the source of record; build-kernel.sh asserts both against the final .config instead of a hand-written list (olddefconfig drops an unknown or unsatisfied symbol without a word). - WARDEN_CONFIG_ONLY=1 stops after that assertion (a seconds-long CI gate) and, like a full build, writes the final .config and its sha256 (CONFIG_OUT), the digest firmware images record as KCONFIG_SHA256. - clk_core_mcu_rtc gets CLK_IGNORE_UNUSED like clk_core_mcu, in the patch and in the enablement source it documents, so 6.18 keeps the HPMCU mtime clock up. - CI: a kernel-symbols job expands the real configuration and asserts the lists on every push; offline tests prove the assertion fires for every failure shape. Co-Authored-By: Claude Sonnet 5.5 Claude-Session: https://claude.ai/code/session_01Cxh2piVufTWbzKTmUafTkk --- .github/workflows/ci.yml | 53 ++++++++++ README.md | 7 ++ build/build-kernel.sh | 64 ++++++++++--- build/lib-required-symbols.sh | 54 +++++++++++ build/probe-symbols.txt | 8 ++ build/required-symbols.txt | 72 ++++++++++++++ build/warden_defconfig | 82 ++++++++++++++++ kernel/rv1106-enablement/clk/clk-rv1106.c | 13 ++- patches/10-clk-rv1106.patch | 8 +- .../run-required-symbols-tests.sh | 96 +++++++++++++++++++ 10 files changed, 438 insertions(+), 19 deletions(-) create mode 100644 build/lib-required-symbols.sh create mode 100644 build/probe-symbols.txt create mode 100644 build/required-symbols.txt create mode 100755 tests/required-symbols/run-required-symbols-tests.sh diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d70d6a7..f5349fe 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -201,6 +201,59 @@ jobs: - name: build A/B disk image run: bash qemu/mkimage.sh + kernel-symbols: + # The symbol gate (rebuild M0, kernel_symbols_exist): expand the real + # configuration (pristine tarball + patch series + warden_defconfig) and + # assert build/required-symbols.txt and probe-symbols.txt against the final + # .config, without compiling. olddefconfig drops a symbol that does not exist + # or whose dependencies are unmet without a word; this is what turns that + # into a red check on every push, in seconds rather than the ~9 minutes of a + # kernel build. The generic arm cross toolchain is enough: only the compiler + # version text of the configuration depends on it. + runs-on: ubuntu-latest + timeout-minutes: 15 + steps: + - uses: actions/checkout@v4 + - name: offline symbol-list tests + run: bash tests/required-symbols/run-required-symbols-tests.sh + - name: install cross toolchain + kernel config deps + run: | + sudo apt-get update -qq + sudo apt-get install -y -qq gcc-arm-linux-gnueabihf bc bison flex libssl-dev + - name: provision `python` (SDK quirk, the build calls bare python) + run: | + mkdir -p "$RUNNER_TEMP/bin" + ln -sf "$(command -v python3)" "$RUNNER_TEMP/bin/python" + echo "$RUNNER_TEMP/bin" >> "$GITHUB_PATH" + - name: cache pristine kernel tarball + uses: actions/cache@v4 + with: + path: ~/linux-6.18.46.tar.xz + key: linux-6.18.46-tarball + - name: expand the configuration and assert the symbols + env: + # WORK must be OUTSIDE the repo checkout (git apply, issue #1). + WORK: ${{ runner.temp }}/kcfg-work + CONFIG_OUT: ${{ runner.temp }}/final.config + CROSS_COMPILE: arm-linux-gnueabihf- + WARDEN_CONFIG_ONLY: "1" + run: | + export KERNEL_TARBALL="$HOME/linux-6.18.46.tar.xz" + bash build/build-kernel.sh + test -s "$CONFIG_OUT" && test -s "$CONFIG_OUT.sha256" + # the sidecar is the sha256 of the file it sits beside + test "$(sha256sum "$CONFIG_OUT" | cut -d' ' -f1)" = "$(cat "$CONFIG_OUT.sha256")" + - name: the expansion is deterministic (same inputs, same digest) + env: + WORK: ${{ runner.temp }}/kcfg-work-2 + CONFIG_OUT: ${{ runner.temp }}/final-2.config + CROSS_COMPILE: arm-linux-gnueabihf- + WARDEN_CONFIG_ONLY: "1" + run: | + export KERNEL_TARBALL="$HOME/linux-6.18.46.tar.xz" + bash build/build-kernel.sh + cmp "${{ runner.temp }}/final.config" "$CONFIG_OUT" + patches-apply: # The RV1106 series must apply cleanly onto pristine linux-6.18.46. runs-on: ubuntu-latest diff --git a/README.md b/README.md index a8d656a..321a92b 100644 --- a/README.md +++ b/README.md @@ -47,6 +47,13 @@ Add `WARDEN_KCONFIG_FRAGMENT=qemu/configs/virt.fragment` to step 1 for the kernel variant with the simulator's extra devices; `qemu/README.md` has the scenario tests (portal, OTA apply, display + touch, watchdog). +Every kernel symbol the platform needs is listed in `build/required-symbols.txt` +(and `build/probe-symbols.txt` for a symbol under test). `build-kernel.sh` asserts +both against the final `.config`, because `olddefconfig` drops an unknown or +unsatisfied symbol without a word. `WARDEN_CONFIG_ONLY=1 CONFIG_OUT=` stops +after that assertion, so the gate takes seconds; `.sha256` holds the digest +of the final `.config` that firmware images record as `KCONFIG_SHA256`. + ## Layout | Directory | Contents | diff --git a/build/build-kernel.sh b/build/build-kernel.sh index ae3d056..6068bf0 100755 --- a/build/build-kernel.sh +++ b/build/build-kernel.sh @@ -19,6 +19,15 @@ # (qemu/configs/virt.fragment builds the QEMU -M virt variant); # every fragment option is verified to have taken effect # WARDEN_CCACHE=1 compile through ccache (CI caches ~/.ccache) +# WARDEN_CONFIG_ONLY=1 +# stop after the configuration and the symbol assertions +# (no compile): a seconds-long symbol gate for CI and the +# pre-build identity of /etc/warden-release. Needs CONFIG_OUT +# or an explicit WORK, because a scratch WORK is removed. +# CONFIG_OUT where the final .config is copied (default +# $WORK/final.config); ${CONFIG_OUT}.sha256 gets its sha256 +# (hex only). Written by both modes: the config-only value +# must equal the full build's, and the build checks it. # WARDEN_MODULES_COLLECT # space-separated in-tree dirs whose .ko files are wanted # (e.g. "drivers/net/wireless/aic8800"). Runs a full @@ -32,6 +41,10 @@ set -euo pipefail KVER=6.18.46 HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" # build/ +# shellcheck source=build/lib-required-symbols.sh +. "$HERE/lib-required-symbols.sh" +REQ_SYMBOLS="$HERE/required-symbols.txt" +PROBE_SYMBOLS="$HERE/probe-symbols.txt" REPO="$(cd "$HERE/.." && pwd)" PATCHES="$REPO/patches" JOBS="${JOBS:-$(nproc)}" @@ -48,6 +61,16 @@ else WORK_OWNED=1 fi trap '[ "${WORK_OWNED:-0}" = 1 ] && rm -rf "$WORK"' EXIT +CONFIG_ONLY="${WARDEN_CONFIG_ONLY:-0}" +case "$CONFIG_ONLY" in + 0|1) ;; + *) echo "FATAL: WARDEN_CONFIG_ONLY must be 0 or 1, got '$CONFIG_ONLY'" >&2; exit 1 ;; +esac +if [ "$CONFIG_ONLY" = 1 ] && [ "$WORK_OWNED" = 1 ] && [ -z "${CONFIG_OUT:-}" ]; then + echo "FATAL: WARDEN_CONFIG_ONLY=1 needs CONFIG_OUT (or an explicit WORK): a scratch WORK is removed on exit" >&2 + exit 1 +fi +CONFIG_OUT="${CONFIG_OUT:-$WORK/final.config}" log() { printf '\033[36m== %s\033[0m\n' "$*"; } @@ -121,21 +144,14 @@ command -v "${CROSS_COMPILE}gcc" >/dev/null \ || { echo "cross toolchain ${CROSS_COMPILE}gcc not on PATH (set SDK_TC, or CROSS_COMPILE to one that is)" >&2; exit 1; } make -C "$SRC" ARCH=arm CROSS_COMPILE="$CROSS_COMPILE" olddefconfig >/dev/null -# Took-effect assertion for the symbols whose silent loss is a security hole, -# not a build failure. olddefconfig drops a defconfig line whose dependencies -# are unmet without a word, and the panel's firewall then quietly stops -# covering IPv6 (flare-edge#533: no ip6tables filter table, so the IPv4 -# default-drop never applied to IPv6). Every symbol here must be built in -# (=y): the panel has no /lib/modules. -req_fail=0 -for sym in CONFIG_NF_DEFRAG_IPV6 CONFIG_IP6_NF_IPTABLES \ - CONFIG_IP6_NF_IPTABLES_LEGACY CONFIG_IP6_NF_FILTER; do - grep -qxF "$sym=y" "$SRC/.config" || { - echo "FATAL: required option $sym is not =y in the final .config (unmet Kconfig dependency?)" >&2 - req_fail=1 - } -done -[ "$req_fail" = 0 ] || exit 1 +# Took-effect assertion for every symbol the platform needs. olddefconfig drops +# a defconfig line whose dependencies are unmet, or whose symbol does not exist, +# without a word: flare-edge#533 shipped a firewall that quietly stopped +# covering IPv6 that way. build/required-symbols.txt (and build/probe-symbols.txt +# for a probe kernel) is the one list; every symbol in it is built in (=y, the +# panel has no /lib/modules) or explicitly unset. +req_assert_config "$SRC/.config" "$REQ_SYMBOLS" "$PROBE_SYMBOLS" || exit 1 +log "required symbols verified in final .config ($(req_assertions "$REQ_SYMBOLS" | wc -l) required, $(req_assertions "$PROBE_SYMBOLS" | wc -l) probe)" # Fragment took-effect assertion: merge_config -m only pastes text, and # olddefconfig silently resolves any symbol whose dependencies are unmet: @@ -167,6 +183,21 @@ if [ -n "${WARDEN_KCONFIG_FRAGMENT:-}" ]; then log "fragment options verified in final .config" fi +# The final .config, and its identity. KCONFIG_SHA256 in /etc/warden-release is +# this digest (the whole file, compiler version text included): CONFIG_IKCONFIG_PROC +# embeds a byte copy, so /proc/config.gz hashes to the same value. +emit_config_identity() { + mkdir -p "$(dirname "$CONFIG_OUT")" + cp "$SRC/.config" "$CONFIG_OUT" + sha256sum "$CONFIG_OUT" | awk '{print $1}' > "$CONFIG_OUT.sha256" + echo "final.config sha256: $(cat "$CONFIG_OUT.sha256")" +} +if [ "$CONFIG_ONLY" = 1 ]; then + emit_config_identity + log "config-only: symbols verified, stopping before the compile" + exit 0 +fi + # Optional ccache (CI: cache ~/.ccache across dispatches; harmless if unset). KCC="${CROSS_COMPILE}gcc" if [ "${WARDEN_CCACHE:-0}" = 1 ]; then @@ -201,6 +232,9 @@ if [ -n "${WARDEN_MODULES_COLLECT:-}" ]; then ls -la "$MODOUT" fi +# Identity of the .config the compile actually used, not the one before it. +emit_config_identity + Z="$SRC/arch/arm/boot/zImage" D="$SRC/arch/arm/boot/dts/rockchip/rv1106-warden.dtb" log "build OK" diff --git a/build/lib-required-symbols.sh b/build/lib-required-symbols.sh new file mode 100644 index 0000000..b7d8993 --- /dev/null +++ b/build/lib-required-symbols.sh @@ -0,0 +1,54 @@ +# shellcheck shell=bash +# Shared by build-kernel.sh and the symbol tests (tests/required-symbols/). +# +# build/required-symbols.txt is the source of record for every kernel symbol +# the platform needs (rebuild M0, names.md 21.1). Format, one item per line: +# +# CONFIG_X=y assert the symbol is =y in the final .config +# # CONFIG_X is not set assert the symbol is NOT set (an explicit unset) +# ## tier R section header (R required, C recommended, +# A assertion only / derived, never in a defconfig) +# # any other text comment +# (blank lines ignored) +# +# build/probe-symbols.txt has the same format for tier P: symbols built into +# the test kernel to run a probe. They are asserted like the others, and join +# required-symbols.txt only when the probe passes. + +# req_assertions FILE: print the assertion lines of FILE. +req_assertions() { + grep -E '^(CONFIG_[A-Za-z0-9_]+=[ymn]|# CONFIG_[A-Za-z0-9_]+ is not set)$' "$1" || true +} + +# req_assert_config CONFIG LIST...: check each assertion of each LIST against +# CONFIG (a final .config). Prints one FATAL line per failure and returns 1 if +# any failed. A missing or empty LIST is itself a failure (fail closed). +req_assert_config() { + local cfg="$1" list line opt n bad=0 + shift + [ -s "$cfg" ] || { echo "FATAL: config '$cfg' is missing or empty" >&2; return 1; } + for list in "$@"; do + [ -f "$list" ] || { echo "FATAL: symbol list '$list' is missing" >&2; return 1; } + n=0 + while IFS= read -r line; do + n=$((n + 1)) + case "$line" in + CONFIG_*=*) + grep -qxF "$line" "$cfg" || { + echo "FATAL: required option $line is not in the final .config (unmet Kconfig dependency, or the symbol does not exist?)" >&2 + bad=1 + } ;; + "# CONFIG_"*" is not set") + # An unset holds if the symbol is absent or shown as "is not set"; + # only a live =value fails (a dependency may hide the symbol). + opt="${line#\# }"; opt="${opt% is not set}" + grep -qE "^$opt=" "$cfg" && { + echo "FATAL: option $opt must not be set but is in the final .config" >&2 + bad=1 + } ;; + esac + done < <(req_assertions "$list") + [ "$n" -gt 0 ] || { echo "FATAL: symbol list '$list' holds no assertions" >&2; return 1; } + done + return "$bad" +} diff --git a/build/probe-symbols.txt b/build/probe-symbols.txt new file mode 100644 index 0000000..df1bb94 --- /dev/null +++ b/build/probe-symbols.txt @@ -0,0 +1,8 @@ +## Tier P: symbols built into the test kernel to run a probe (rebuild M0). +## Asserted like required-symbols.txt. A symbol moves to required-symbols.txt +## when its probe passes on the panel, and leaves this file and the defconfig +## when it fails. +## +## tier P probe V3 (N-36, d06 O14, d09 T14): hardware RNG +CONFIG_HW_RANDOM=y +CONFIG_HW_RANDOM_ROCKCHIP=y diff --git a/build/required-symbols.txt b/build/required-symbols.txt new file mode 100644 index 0000000..0b0b809 --- /dev/null +++ b/build/required-symbols.txt @@ -0,0 +1,72 @@ +## Kernel symbols the platform needs. Source of record (rebuild M0, names.md +## 21.1): build-kernel.sh asserts every line against the final .config, the +## tests/required-symbols guards read this file, and the FE kernel_symbols_exist +## gate checks every CONFIG_ name in the specs against it and the Kconfig tree. +## Format: see build/lib-required-symbols.sh. Tier P lives in probe-symbols.txt. +## +## tier R already shipped (flare-edge#533) +CONFIG_NF_DEFRAG_IPV6=y +CONFIG_IP6_NF_IPTABLES=y +CONFIG_IP6_NF_IPTABLES_LEGACY=y +CONFIG_IP6_NF_FILTER=y +## +## tier R cgroup v2 controllers (W-D7) +CONFIG_MEMCG=y +CONFIG_CGROUP_PIDS=y +CONFIG_CGROUP_SCHED=y +CONFIG_FAIR_GROUP_SCHED=y +CONFIG_CFS_BANDWIDTH=y +## +## tier R byte metering (D50 D51 D52) +CONFIG_NETFILTER_XT_MATCH_CGROUP=y +CONFIG_NETFILTER_XT_CONNMARK=y +CONFIG_NETFILTER_XT_MARK=y +CONFIG_IP6_NF_MANGLE=y +## +## tier R /proc/config.gz (D51) +CONFIG_IKCONFIG=y +CONFIG_IKCONFIG_PROC=y +## +## tier R uid fallback and NOTRACK (SCH-04, flare-edge#537) +CONFIG_NETFILTER_XT_MATCH_OWNER=y +CONFIG_IP_NF_RAW=y +CONFIG_IP6_NF_RAW=y +CONFIG_NETFILTER_XT_TARGET_CT=y +## +## tier R namespaces and PSI (SCH-04, NN-11) +CONFIG_NAMESPACES=y +CONFIG_UTS_NS=y +CONFIG_IPC_NS=y +CONFIG_PID_NS=y +CONFIG_NET_NS=y +CONFIG_USER_NS=y +CONFIG_PSI=y +## +## tier R nftables (N-40) +CONFIG_NF_TABLES=y +CONFIG_NF_TABLES_IPV4=y +CONFIG_NF_TABLES_IPV6=y +CONFIG_NFT_CT=y +CONFIG_NFT_MASQ=y +CONFIG_NFT_NAT=y +CONFIG_NFT_LIMIT=y +CONFIG_NFT_SOCKET=y +CONFIG_NFT_REJECT=y +## +## tier C recommended +CONFIG_NETFILTER_XT_MATCH_ADDRTYPE=y +CONFIG_NF_CONNTRACK_PROCFS=y +## +## tier A assertion only (a defconfig line is optional) +CONFIG_SECCOMP=y +CONFIG_SECCOMP_FILTER=y +CONFIG_MULTIUSER=y +CONFIG_SYSVIPC=y +# CONFIG_RT_GROUP_SCHED is not set +# CONFIG_TIME_NS is not set +## +## tier A derived (selected or defaulted by other symbols; never in a defconfig) +CONFIG_NF_CONNTRACK_MARK=y +CONFIG_SOCK_CGROUP_DATA=y +CONFIG_NFT_REJECT_IPV4=y +CONFIG_NFT_REJECT_IPV6=y diff --git a/build/warden_defconfig b/build/warden_defconfig index 134eb26..75073d4 100644 --- a/build/warden_defconfig +++ b/build/warden_defconfig @@ -1395,3 +1395,85 @@ CONFIG_NF_DEFRAG_IPV6=y CONFIG_IP6_NF_IPTABLES=y CONFIG_IP6_NF_IPTABLES_LEGACY=y CONFIG_IP6_NF_FILTER=y +# +# Cgroup v2 controllers, byte metering, raw table, namespaces and PSI +# (rebuild M0; D50 D51 D52 W-D7 SCH-04 N-40 NN-11). The single kernel flash: +# every option later work needs, so no second t2 update reaches a panel. +# build/required-symbols.txt is the source of record and build-kernel.sh +# asserts every line of it against the final .config. All built in: the panel +# has no /lib/modules. +# +# Per-app limits (W-D7): memory.max / memory.events / memory.oom.group, +# pids.max, cpu.weight and the cpu.max hard cap. +CONFIG_MEMCG=y +CONFIG_CGROUP_PIDS=y +CONFIG_CGROUP_SCHED=y +CONFIG_FAIR_GROUP_SCHED=y +CONFIG_CFS_BANDWIDTH=y +# RT group scheduling would block the v2 cpu controller; it must stay off. +# CONFIG_RT_GROUP_SCHED is not set +# +# Byte metering by cgroup (D50 D51 D52): the cgroup match, CONNMARK so inbound +# replies inherit the service, the mark match, and the ip6tables mangle table +# (it defaults to =m under legacy). The meter itself is nftables since N-40. +CONFIG_NETFILTER_XT_MATCH_CGROUP=y +CONFIG_NETFILTER_XT_CONNMARK=y +CONFIG_NETFILTER_XT_MARK=y +CONFIG_IP6_NF_MANGLE=y +# +# /proc/config.gz (D51). IKCONFIG is a tristate: it must be =y, no module tree. +# The whole .config digest (KCONFIG_SHA256 in /etc/warden-release) equals the +# sha256 of the decompressed embed. +CONFIG_IKCONFIG=y +CONFIG_IKCONFIG_PROC=y +# +# Uid fallback metering (SCH-04), and the raw table with the CT target for the +# NOTRACK of the discovery sweep (flare-edge#537). The legacy tables stay for +# that interim and for any legacy tool in the image. +CONFIG_NETFILTER_XT_MATCH_OWNER=y +CONFIG_IP_NF_RAW=y +CONFIG_IP6_NF_RAW=y +CONFIG_NETFILTER_XT_TARGET_CT=y +# +# Cheap rule helpers. CONNTRACK_PROCFS keeps /proc/net/nf_conntrack so the +# cause of #537 and its fix can be proven (C14). +CONFIG_NETFILTER_XT_MATCH_ADDRTYPE=y +CONFIG_NF_CONNTRACK_PROCFS=y +# +# Namespaces for future app sandboxing (SCH-04, NN-11): NAMESPACES is a prompt +# only under EXPERT and defaults off there, so it needs this line. All five +# sub-options are set; USER_NS stays closed at runtime by +# user.max_user_namespaces=0 (S02warden-sysctl) until the app sandbox needs it. +# TIME_NS defaults on, so it is unset explicitly. +CONFIG_NAMESPACES=y +CONFIG_UTS_NS=y +CONFIG_IPC_NS=y +CONFIG_PID_NS=y +CONFIG_NET_NS=y +CONFIG_USER_NS=y +# CONFIG_TIME_NS is not set +# +# Pressure stall information (SCH-04): /proc/pressure/* and per-cgroup +# cpu.pressure and memory.pressure. On at boot (PSI_DEFAULT_DISABLED stays off). +CONFIG_PSI=y +# +# nftables (N-40): the applier and the meter target nft in the families ip and +# ip6. Counters, meta, payload, sets and jump are nf_tables core; there is no +# NFT_COUNTER symbol. NFT_REJECT_IPV4 and NFT_REJECT_IPV6 have no prompt and +# derive from NFT_REJECT, so they are asserted in required-symbols.txt and +# never set here (a line for a promptless symbol is dropped). +CONFIG_NF_TABLES=y +CONFIG_NF_TABLES_IPV4=y +CONFIG_NF_TABLES_IPV6=y +CONFIG_NFT_CT=y +CONFIG_NFT_MASQ=y +CONFIG_NFT_NAT=y +CONFIG_NFT_LIMIT=y +CONFIG_NFT_SOCKET=y +CONFIG_NFT_REJECT=y +# +# Probe tier (N-36, d06 O14, probe V3): the Rockchip hardware RNG, built into +# the test kernel. build/probe-symbols.txt lists it; it moves to +# required-symbols.txt only if V3 passes on the panel, and comes out of this +# file if it fails. +CONFIG_HW_RANDOM_ROCKCHIP=y diff --git a/kernel/rv1106-enablement/clk/clk-rv1106.c b/kernel/rv1106-enablement/clk/clk-rv1106.c index 03a64d8..2d34c3b 100644 --- a/kernel/rv1106-enablement/clk/clk-rv1106.c +++ b/kernel/rv1106-enablement/clk/clk-rv1106.c @@ -337,12 +337,21 @@ static struct rockchip_clk_branch rv1106_clk_branches[] __initdata = { /* PD_CORE */ GATE(CLK_PVTM_CORE, "clk_pvtm_core", "xin24m", 0, RV1106_CORECLKGATE_CON(0), 14, GFLAGS), - GATE(CLK_CORE_MCU_RTC, "clk_core_mcu_rtc", "xin24m", 0, + /* clk_core_mcu_rtc is the 24 MHz mtime of the HPMCU, kept up for the + * mtime safety tick. Nothing in Linux claims it, so clk_disable_unused() + * would gate it after boot; IGNORE_UNUSED keeps it running, like + * clk_core_mcu below (rebuild M0, SCH-01). */ + GATE(CLK_CORE_MCU_RTC, "clk_core_mcu_rtc", "xin24m", CLK_IGNORE_UNUSED, RV1106_CORECLKGATE_CON(1), 6, GFLAGS), COMPOSITE(HCLK_CPU, "hclk_cpu", mux_gpll_24m_p, CLK_IS_CRITICAL, RV1106_CORECLKSEL_CON(2), 5, 1, MFLAGS, 0, 5, DFLAGS, RV1106_CORECLKGATE_CON(0), 12, GFLAGS), - COMPOSITE(CLK_CORE_MCU, "clk_core_mcu", mux_gpll_24m_p, 0, + /* The HPMCU (RISC-V SCR1 coprocessor) runs on clk_core_mcu, but nothing in + * Linux claims it, so clk_disable_unused() switches it off at boot and any + * firmware loaded into the coprocessor never executes. Mark it + * IGNORE_UNUSED so the coprocessor clock stays up (5.10 left it running; + * our 6.18 disabled it). A future remoteproc/coproc driver could claim it. */ + COMPOSITE(CLK_CORE_MCU, "clk_core_mcu", mux_gpll_24m_p, CLK_IGNORE_UNUSED, RV1106_CORECLKSEL_CON(3), 11, 1, MFLAGS, 6, 5, DFLAGS, RV1106_CORECLKGATE_CON(1), 1, GFLAGS), COMPOSITE_NOMUX(0, "pclk_dbg", "armclk", CLK_IS_CRITICAL, diff --git a/patches/10-clk-rv1106.patch b/patches/10-clk-rv1106.patch index 342c04f..fb6c27e 100644 --- a/patches/10-clk-rv1106.patch +++ b/patches/10-clk-rv1106.patch @@ -33,7 +33,7 @@ new file mode 100644 index 000000000..b44eeeadd --- /dev/null +++ b/drivers/clk/rockchip/clk-rv1106.c -@@ -0,0 +1,1299 @@ +@@ -0,0 +1,1303 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (c) 2022 Rockchip Electronics Co. Ltd. @@ -373,7 +373,11 @@ index 000000000..b44eeeadd + /* PD_CORE */ + GATE(CLK_PVTM_CORE, "clk_pvtm_core", "xin24m", 0, + RV1106_CORECLKGATE_CON(0), 14, GFLAGS), -+ GATE(CLK_CORE_MCU_RTC, "clk_core_mcu_rtc", "xin24m", 0, ++ /* clk_core_mcu_rtc is the 24 MHz mtime of the HPMCU, kept up for the ++ * mtime safety tick. Nothing in Linux claims it, so clk_disable_unused() ++ * would gate it after boot; IGNORE_UNUSED keeps it running, like ++ * clk_core_mcu below (rebuild M0, SCH-01). */ ++ GATE(CLK_CORE_MCU_RTC, "clk_core_mcu_rtc", "xin24m", CLK_IGNORE_UNUSED, + RV1106_CORECLKGATE_CON(1), 6, GFLAGS), + COMPOSITE(HCLK_CPU, "hclk_cpu", mux_gpll_24m_p, CLK_IS_CRITICAL, + RV1106_CORECLKSEL_CON(2), 5, 1, MFLAGS, 0, 5, DFLAGS, diff --git a/tests/required-symbols/run-required-symbols-tests.sh b/tests/required-symbols/run-required-symbols-tests.sh new file mode 100755 index 0000000..1b3051f --- /dev/null +++ b/tests/required-symbols/run-required-symbols-tests.sh @@ -0,0 +1,96 @@ +#!/usr/bin/env bash +# Offline tests for the required-symbols mechanism (rebuild M0): +# build/lib-required-symbols.sh, the symbol lists, and build-kernel.sh's +# WARDEN_CONFIG_ONLY entry checks. No kernel tarball, no compiler. +# +# What a regression here costs: olddefconfig drops a defconfig line whose symbol +# or dependencies are missing without a word (flare-edge#533 shipped a firewall +# that quietly skipped IPv6 that way), so the assertion against the final +# .config is the only thing between a dropped symbol and a panel. This proves the +# assertion itself fires, on fake .config files, for every failure shape. +set -uo pipefail + +HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +REPO="$(cd "$HERE/../.." && pwd)" +LIB="$REPO/build/lib-required-symbols.sh" +REQ="$REPO/build/required-symbols.txt" +PROBE="$REPO/build/probe-symbols.txt" +TMP="$(mktemp -d)"; trap 'rm -rf "$TMP"' EXIT +FAIL=0 +ok() { printf '[PASS] %s\n' "$1"; } +bad() { printf '[FAIL] %s\n' "$1"; FAIL=1; } + +# shellcheck source=build/lib-required-symbols.sh +. "$LIB" + +# A .config that satisfies a list: every =y line verbatim, every unset line +# absent (Kconfig writes "# CONFIG_X is not set" for those). +mkconfig() { # + { req_assertions "$1" | grep -v '^# ' + req_assertions "$1" | grep '^# ' + echo 'CONFIG_SOMETHING_ELSE=y'; } > "$2" +} + +mkconfig "$REQ" "$TMP/good-req"; mkconfig "$PROBE" "$TMP/good-probe"; cat "$TMP/good-req" "$TMP/good-probe" > "$TMP/good" +req_assert_config "$TMP/good" "$REQ" "$PROBE" >/dev/null 2>&1 \ + && ok "a config that satisfies both lists passes" || bad "a satisfying config was refused" + +n=$(req_assertions "$REQ" | wc -l) +[ "$n" -ge 40 ] && ok "required-symbols.txt holds $n assertions" || bad "required-symbols.txt holds only $n assertions" + +# every =y assertion must be refused when its line is missing, one at a time +missing_ok=0; missing_bad=0 +while IFS= read -r line; do + case "$line" in CONFIG_*=y) ;; *) continue ;; esac + grep -vxF "$line" "$TMP/good" > "$TMP/cfg-missing" + if req_assert_config "$TMP/cfg-missing" "$REQ" "$PROBE" >/dev/null 2>&1; then missing_bad=$((missing_bad+1)); echo " not caught: $line" + else missing_ok=$((missing_ok+1)); fi +done < <(req_assertions "$REQ"; req_assertions "$PROBE") +[ "$missing_bad" = 0 ] && ok "dropping any one of $missing_ok =y assertions fails the check" || bad "$missing_bad dropped symbols were not caught" + +# =m is not =y +sed 's/^CONFIG_NFT_CT=y$/CONFIG_NFT_CT=m/' "$TMP/good" > "$TMP/cfg-m" +req_assert_config "$TMP/cfg-m" "$REQ" "$PROBE" >/dev/null 2>&1 && bad "a modular symbol was accepted" || ok "a symbol built as a module is refused" + +# unset assertions: a live value fails, absence and 'is not set' pass +for sym in $(req_assertions "$REQ" | sed -n 's/^# \(CONFIG_[A-Z0-9_]*\) is not set$/\1/p'); do + { cat "$TMP/good"; echo "$sym=y"; } > "$TMP/cfg-set" + req_assert_config "$TMP/cfg-set" "$REQ" "$PROBE" >/dev/null 2>&1 && bad "$sym=y was accepted although it must stay unset" || ok "$sym=y is refused (must stay unset)" + grep -vF "$sym" "$TMP/good" > "$TMP/cfg-absent" + req_assert_config "$TMP/cfg-absent" "$REQ" "$PROBE" >/dev/null 2>&1 && ok "$sym absent from the config is accepted" || bad "$sym absent from the config was refused" +done + +# fail-closed shapes +: > "$TMP/empty" +req_assert_config "$TMP/empty" "$REQ" >/dev/null 2>&1 && bad "an empty config was accepted" || ok "an empty config is refused" +req_assert_config "$TMP/good" "$TMP/no-such-list" >/dev/null 2>&1 && bad "a missing list was accepted" || ok "a missing symbol list is refused" +printf '## only comments\n# a comment\n' > "$TMP/no-assertions" +req_assert_config "$TMP/good" "$TMP/no-assertions" >/dev/null 2>&1 && bad "a list with no assertions was accepted" || ok "a list with no assertions is refused" + +# comment handling: a prose line starting "# CONFIG_" without "is not set" is a comment +printf '## c\n# CONFIG_PROSE is the name of a thing\nCONFIG_REAL=y\n' > "$TMP/prose" +[ "$(req_assertions "$TMP/prose")" = "CONFIG_REAL=y" ] && ok "a prose comment is not an assertion" || bad "a prose comment was parsed as an assertion" + +# the lists: a symbol is asserted once, in one list +dups=$( { req_assertions "$REQ"; req_assertions "$PROBE"; } | sed 's/^# //; s/ is not set//; s/=.*//' | sort | uniq -d | tr '\n' ' ') +# HW_RANDOM may appear in the probe list only; anything else twice is a mistake +[ -z "$dups" ] && ok "no symbol is asserted twice across the lists" || bad "symbols asserted twice: $dups" + +# build-kernel.sh entry checks (they run before the tarball is touched) +BK="$REPO/build/build-kernel.sh" +out=$(WARDEN_CONFIG_ONLY=2 bash "$BK" 2>&1); rc=$? +[ "$rc" != 0 ] && printf '%s' "$out" | grep -q 'WARDEN_CONFIG_ONLY must be 0 or 1' \ + && ok "WARDEN_CONFIG_ONLY=2 is refused" || bad "WARDEN_CONFIG_ONLY=2 was not refused" +mkdir -p "$TMP/bin"; printf '#!/bin/sh\nexit 0\n' > "$TMP/bin/python"; chmod +x "$TMP/bin/python" +out=$(env -u WORK -u CONFIG_OUT PATH="$TMP/bin:$PATH" WARDEN_CONFIG_ONLY=1 bash "$BK" 2>&1); rc=$? +[ "$rc" != 0 ] && printf '%s' "$out" | grep -q 'needs CONFIG_OUT' \ + && ok "config-only with a scratch WORK and no CONFIG_OUT is refused (the result would be deleted)" \ + || bad "config-only without CONFIG_OUT was not refused: $out" + +# wiring text +grep -q 'req_assert_config "\$SRC/.config" "\$REQ_SYMBOLS" "\$PROBE_SYMBOLS"' "$BK" \ + && ok "build-kernel.sh asserts both lists" || bad "build-kernel.sh does not assert the lists" +grep -q 'for sym in CONFIG_' "$BK" && bad "build-kernel.sh has a hand-written symbol list again" || ok "build-kernel.sh has no hand-written list" + +if [ "$FAIL" -eq 0 ]; then echo "ALL REQUIRED-SYMBOLS TESTS PASSED"; else echo "REQUIRED-SYMBOLS TESTS FAILED"; fi +exit $FAIL