Merge pull request 'kernel: keep the arm32 vDSO clock off the virtual counter (#35)' (#36) from rb/ln-vdso-phys-counter into rebuild
ci / test (push) Successful in 8s
ci / mcdc (push) Successful in 29s
ci / bench (push) Successful in 16s
ci / patches-apply (push) Successful in 22s
ci / prune-artifacts (push) Skipped
ci / kernel-build (push) Skipped
ci / quality (push) Successful in 1m15s
ci / badges (push) Skipped
ci / qemu-tools (push) Successful in 4m1s
ci / kernel-symbols (push) Successful in 4m5s

This commit was merged in pull request #36.
This commit is contained in:
2026-10-29 06:05:10 -06:00
5 changed files with 291 additions and 2 deletions
+7
View File
@@ -328,6 +328,13 @@ jobs:
&& echo "applied $p" || { echo "FAILED to apply $p"; exit 1; }
done
echo "full series applied cleanly onto pristine 6.18.46"
- name: arm32 vDSO stays off the virtual counter (bfe-core1106-sdk#35)
# The kernel times on the physical counter and the firmware leaves
# CNTVOFF non-zero, so the vDSO clock must stay off: the DT property and
# the arm_arch_timer.c fallback both have to survive in the patched tree.
run: |
bash tests/arch-timer/run-check-vdso-counter-tests.sh
python3 tests/arch-timer/check-vdso-counter.py /tmp/linux-6.18.46
# Automatic artifact GC (mirrors flare-edge). An exceeded account-wide Actions
# storage quota blocks ALL new runs (startup_failure), not just uploads, so
@@ -0,0 +1,62 @@
diff --git a/arch/arm/boot/dts/rockchip/rv1106-warden-m2.dts b/arch/arm/boot/dts/rockchip/rv1106-warden-m2.dts
--- a/arch/arm/boot/dts/rockchip/rv1106-warden-m2.dts
+++ b/arch/arm/boot/dts/rockchip/rv1106-warden-m2.dts
@@ -74,6 +74,15 @@
interrupts = <GIC_PPI 13 (GIC_CPU_MASK_SIMPLE(1) | IRQ_TYPE_LEVEL_HIGH)>,
<GIC_PPI 14 (GIC_CPU_MASK_SIMPLE(1) | IRQ_TYPE_LEVEL_HIGH)>;
clock-frequency = <24000000>;
+ /*
+ * The boot firmware does not enter the kernel in HYP mode and leaves
+ * CNTVOFF non-zero (bfe-core1106-sdk#35): the virtual counter the
+ * arm32 vDSO reads runs a fixed offset away from the physical one
+ * the kernel keeps time on. This keeps the kernel on the physical
+ * timer and drops the vDSO clock calls, so clock_gettime() uses the
+ * syscall and agrees with every kernel deadline.
+ */
+ arm,cpu-registers-not-fw-configured;
};
gic: interrupt-controller@ff1f0000 {
diff --git a/arch/arm/boot/dts/rockchip/rv1106.dtsi b/arch/arm/boot/dts/rockchip/rv1106.dtsi
--- a/arch/arm/boot/dts/rockchip/rv1106.dtsi
+++ b/arch/arm/boot/dts/rockchip/rv1106.dtsi
@@ -417,6 +417,15 @@
interrupts = <GIC_PPI 13 (GIC_CPU_MASK_SIMPLE(1) | IRQ_TYPE_LEVEL_HIGH)>,
<GIC_PPI 14 (GIC_CPU_MASK_SIMPLE(1) | IRQ_TYPE_LEVEL_HIGH)>;
clock-frequency = <24000000>;
+ /*
+ * The boot firmware does not enter the kernel in HYP mode and leaves
+ * CNTVOFF non-zero (bfe-core1106-sdk#35): the virtual counter the
+ * arm32 vDSO reads runs a fixed offset away from the physical one
+ * the kernel keeps time on. This keeps the kernel on the physical
+ * timer and drops the vDSO clock calls, so clock_gettime() uses the
+ * syscall and agrees with every kernel deadline.
+ */
+ arm,cpu-registers-not-fw-configured;
};
grf: syscon@ff000000 {
diff --git a/drivers/clocksource/arm_arch_timer.c b/drivers/clocksource/arm_arch_timer.c
--- a/drivers/clocksource/arm_arch_timer.c
+++ b/drivers/clocksource/arm_arch_timer.c
@@ -933,6 +933,20 @@ static void __init arch_counter_register(void)
arch_timer_read_counter = rd;
clocksource_counter.vdso_clock_mode = vdso_default;
+ /*
+ * The arm32 vDSO always reads the virtual counter. A kernel that keeps
+ * time on the physical counter and was not entered in HYP mode never
+ * had CNTVOFF zeroed by the hyp stub, so the vDSO clock may sit a fixed
+ * offset away from the kernel's and absolute deadlines taken from it
+ * expire late. Fall back to the syscall then.
+ */
+ if (IS_ENABLED(CONFIG_ARM) && arch_timer_uses_ppi != ARCH_TIMER_VIRT_PPI &&
+ !is_hyp_mode_available() &&
+ clocksource_counter.vdso_clock_mode != VDSO_CLOCKMODE_NONE) {
+ clocksource_counter.vdso_clock_mode = VDSO_CLOCKMODE_NONE;
+ pr_info("physical counter without HYP: vDSO clock disabled\n");
+ }
+
width = arch_counter_get_width();
clocksource_counter.mask = CLOCKSOURCE_MASK(width);
cyclecounter.mask = CLOCKSOURCE_MASK(width);
+4 -2
View File
@@ -1,8 +1,9 @@
# The Kernel Patch Series
The delta that forward-ports the vendor Rockchip 5.10.160 RV1106 support onto a
pristine upstream **linux-6.18.46**, as a reviewable, subsystem-split series. Every
patch applies cleanly onto pristine 6.18.46 (`git apply --check`), and the whole set
pristine upstream **linux-6.18.46**, as a reviewable, subsystem-split series. The
series applies cleanly, in order, onto pristine 6.18.46 (`git apply --check`; a fix
patch such as 82 edits files that an earlier patch adds), and the whole set
reproduces the 223-file / ~136K-line delta that boots and is hardware-verified on
`warden-c8a3` (see `../kernel/rv1106-enablement/`).
@@ -28,6 +29,7 @@ with `../build/warden_defconfig` -> `zImage` + `rv1106-warden.dtb`).
| `60-wifi-aic8800.patch` | out-of-tree AIC8800 wifi/BT (the 88.5K-line vendor blob) |
| `70-audio-codec.patch` | `rv1106_codec` + I2S wiring |
| `80-misc-thermal-rtc-adc.patch` | tsadc, rtc-rockchip, saradc, trng, otp, gmac, goodix touch |
| `82-arch-timer-vdso-phys-counter.patch` | arch timer: keep the arm32 vDSO clock off the virtual counter while the kernel times on the physical one (CNTVOFF left non-zero by the boot firmware, #35); checked by `tests/arch-timer/check-vdso-counter.py` |
| `90-kconfig-no-python-symbol.patch` | drops `DRM_MSM_VALIDATE_XML` so the expanded `.config` (and `KCONFIG_SHA256`) does not depend on the host python (#19) |
## License
+109
View File
@@ -0,0 +1,109 @@
#!/usr/bin/env python3
"""Check that a patched kernel tree keeps the arm32 vDSO clock off the
virtual counter when the kernel times on the physical one (bfe-core1106-sdk#35).
On the RV1106 the boot firmware does not enter the kernel in HYP mode and
leaves CNTVOFF non-zero. The DT timer node lists no virtual-timer PPI, so the
kernel keeps time on the physical counter, while the arm32 vDSO always reads
the virtual counter: clock_gettime() then runs about 739 s ahead of the kernel
clock and every absolute deadline taken from it expires late (flare-edge#2319).
Two guards must both be present in the patched tree:
1. Every armv7/armv8 timer node in the RV1106 device trees that has no
virtual-timer PPI (GIC_PPI 11) carries `arm,cpu-registers-not-fw-configured`,
which makes arch/arm/kernel/vdso.c drop the vDSO clock symbols.
2. drivers/clocksource/arm_arch_timer.c sets the counter's vdso_clock_mode to
VDSO_CLOCKMODE_NONE on arm32 when the kernel uses the physical counter
without HYP mode (the safety net for a device tree without the property).
Usage: check-vdso-counter.py <patched kernel source dir>
Exit 0 when both hold, 1 with one FAIL line per problem, 2 on bad usage.
"""
import pathlib
import re
import sys
DTS_GLOB = "arch/arm/boot/dts/rockchip/rv1106*.dts*"
TIMER_C = "drivers/clocksource/arm_arch_timer.c"
PROPERTY = "arm,cpu-registers-not-fw-configured"
def strip_comments(text):
text = re.sub(r"/\*.*?\*/", "", text, flags=re.S)
return re.sub(r"//[^\n]*", "", text)
def timer_nodes(text):
"""Yield the body of every node whose compatible is an arch timer."""
for m in re.finditer(r"\b[\w@,.-]+\s*\{", text):
depth, i = 1, m.end()
while depth and i < len(text):
depth += {"{": 1, "}": -1}.get(text[i], 0)
i += 1
body = text[m.end():i - 1]
# Only the node's own properties, not its children's.
own = re.sub(r"\{.*\}", "", body, flags=re.S)
if re.search(r'compatible\s*=\s*"arm,armv[78]-timer"', own):
yield own
def check_dts(root):
problems, seen = [], 0
for path in sorted(root.glob(DTS_GLOB)):
text = strip_comments(path.read_text(errors="replace"))
for own in timer_nodes(text):
seen += 1
has_virt = re.search(r"GIC_PPI\s+11\b", own) is not None
has_prop = re.search(r"(^|[\s;])" + re.escape(PROPERTY) + r"\s*;", own) is not None
if not has_virt and not has_prop:
problems.append(f"{path.relative_to(root)}: timer node has no virtual-timer "
f"PPI and no {PROPERTY}")
if not seen:
problems.append(f"no arm,armv7-timer node found under {DTS_GLOB}")
return problems
def check_timer_c(root):
path = root / TIMER_C
if not path.is_file():
return [f"{TIMER_C} missing"]
text = strip_comments(path.read_text(errors="replace"))
m = re.search(r"static void __init arch_counter_register\(void\)\s*\{", text)
if not m:
return [f"{TIMER_C}: arch_counter_register() not found"]
depth, i = 1, m.end()
while depth and i < len(text):
depth += {"{": 1, "}": -1}.get(text[i], 0)
i += 1
body = text[m.end():i - 1]
guard = re.search(
r"if\s*\(\s*IS_ENABLED\(CONFIG_ARM\)\s*&&\s*"
r"arch_timer_uses_ppi\s*!=\s*ARCH_TIMER_VIRT_PPI\s*&&\s*"
r"!\s*is_hyp_mode_available\(\)[^{]*\{([^}]*)\}", body)
if not guard or not re.search(
r"clocksource_counter\.vdso_clock_mode\s*=\s*VDSO_CLOCKMODE_NONE\s*;", guard.group(1)):
return [f"{TIMER_C}: arch_counter_register() lacks the arm32 physical-counter "
"vDSO fallback (vdso_clock_mode = VDSO_CLOCKMODE_NONE)"]
default_at = body.find("clocksource_counter.vdso_clock_mode = vdso_default;")
if default_at < 0 or default_at > guard.start():
return [f"{TIMER_C}: the vDSO fallback must come after the vdso_default assignment"]
return []
def main(argv):
if len(argv) != 2 or not pathlib.Path(argv[1]).is_dir():
print("usage: check-vdso-counter.py <patched kernel source dir>", file=sys.stderr)
return 2
root = pathlib.Path(argv[1])
problems = check_dts(root) + check_timer_c(root)
for p in problems:
print(f"FAIL: {p}")
if problems:
return 1
print("vdso-counter: ok (DT property and arm32 physical-counter fallback present)")
return 0
if __name__ == "__main__":
sys.exit(main(sys.argv))
+109
View File
@@ -0,0 +1,109 @@
#!/bin/bash
# Regression tests for tests/arch-timer/check-vdso-counter.py (bfe-core1106-sdk#35).
#
# The checker guards the fix for the vDSO clock running 739 s ahead of the
# kernel clock on the RV1106: the DT timer property and the arm32 fallback in
# arm_arch_timer.c. Each case builds a small fake kernel tree and expects an
# exit status; the real patched tree is checked in CI's patches-apply job.
set -uo pipefail
HERE="$(cd "$(dirname "$0")" && pwd)"
CHECK="$HERE/check-vdso-counter.py"
TMP="$(mktemp -d)"
trap 'rm -rf "$TMP"' EXIT
TIMER_NODE_GOOD=' timer {
compatible = "arm,armv7-timer";
interrupts = <GIC_PPI 13 (GIC_CPU_MASK_SIMPLE(1) | IRQ_TYPE_LEVEL_HIGH)>,
<GIC_PPI 14 (GIC_CPU_MASK_SIMPLE(1) | IRQ_TYPE_LEVEL_HIGH)>;
clock-frequency = <24000000>;
arm,cpu-registers-not-fw-configured;
};'
TIMER_NODE_BARE=' timer {
compatible = "arm,armv7-timer";
interrupts = <GIC_PPI 13 (GIC_CPU_MASK_SIMPLE(1) | IRQ_TYPE_LEVEL_HIGH)>,
<GIC_PPI 14 (GIC_CPU_MASK_SIMPLE(1) | IRQ_TYPE_LEVEL_HIGH)>;
clock-frequency = <24000000>;
};'
TIMER_NODE_COMMENTED=' timer {
compatible = "arm,armv7-timer";
interrupts = <GIC_PPI 13 (GIC_CPU_MASK_SIMPLE(1) | IRQ_TYPE_LEVEL_HIGH)>,
<GIC_PPI 14 (GIC_CPU_MASK_SIMPLE(1) | IRQ_TYPE_LEVEL_HIGH)>;
/* arm,cpu-registers-not-fw-configured; */
};'
TIMER_NODE_VIRT=' timer {
compatible = "arm,armv7-timer";
interrupts = <GIC_PPI 13 IRQ_TYPE_LEVEL_LOW>, <GIC_PPI 14 IRQ_TYPE_LEVEL_LOW>,
<GIC_PPI 11 IRQ_TYPE_LEVEL_LOW>, <GIC_PPI 10 IRQ_TYPE_LEVEL_LOW>;
};'
TIMER_NODE_CHILD=' timer {
compatible = "arm,armv7-timer";
interrupts = <GIC_PPI 13 IRQ_TYPE_LEVEL_LOW>, <GIC_PPI 14 IRQ_TYPE_LEVEL_LOW>;
sub {
arm,cpu-registers-not-fw-configured;
};
};'
GUARD=' if (IS_ENABLED(CONFIG_ARM) && arch_timer_uses_ppi != ARCH_TIMER_VIRT_PPI &&
!is_hyp_mode_available() &&
clocksource_counter.vdso_clock_mode != VDSO_CLOCKMODE_NONE) {
clocksource_counter.vdso_clock_mode = VDSO_CLOCKMODE_NONE;
pr_info("physical counter without HYP: vDSO clock disabled\n");
}'
GUARD_WRONG=' if (IS_ENABLED(CONFIG_ARM) && arch_timer_uses_ppi != ARCH_TIMER_VIRT_PPI &&
!is_hyp_mode_available()) {
pr_info("physical counter without HYP\n");
}'
DEFAULT=' clocksource_counter.vdso_clock_mode = vdso_default;'
mk_tree() { # mk_tree <name> <dtsi timer node> <timer.c body before> <body after>
local d="$TMP/$1"
mkdir -p "$d/arch/arm/boot/dts/rockchip" "$d/drivers/clocksource"
printf '/ {\n\tcpus { cpu@0 { reg = <0>; }; };\n%s\n};\n' "$2" \
> "$d/arch/arm/boot/dts/rockchip/rv1106.dtsi"
printf '#include "rv1106.dtsi"\n/ { model = "x"; };\n' \
> "$d/arch/arm/boot/dts/rockchip/rv1106-warden.dts"
printf 'static void __init arch_counter_register(void)\n{\n\tu64 (*rd)(void);\n%s\n\n%s\n\twidth = 56;\n}\n' \
"$3" "$4" > "$d/drivers/clocksource/arm_arch_timer.c"
echo "$d"
}
fails=0 n=0
expect() { # expect <name> <exit> <tree>
local got out
out="$(python3 "$CHECK" "$3" 2>&1)"; got=$?
n=$((n + 1))
if [ "$got" = "$2" ]; then
echo "PASS: $1"
else
echo "FAIL: $1 (wanted exit $2, got $got)"
while IFS= read -r line; do echo " $line"; done <<< "$out"
fails=$((fails + 1))
fi
}
expect "fixed tree passes" 0 "$(mk_tree good "$TIMER_NODE_GOOD" "$DEFAULT" "$GUARD")"
expect "timer node without the property fails" 1 "$(mk_tree bare "$TIMER_NODE_BARE" "$DEFAULT" "$GUARD")"
expect "property only inside a comment fails" 1 "$(mk_tree comm "$TIMER_NODE_COMMENTED" "$DEFAULT" "$GUARD")"
expect "property only in a child node fails" 1 "$(mk_tree child "$TIMER_NODE_CHILD" "$DEFAULT" "$GUARD")"
expect "timer node with a virtual PPI needs no property" 0 "$(mk_tree virt "$TIMER_NODE_VIRT" "$DEFAULT" "$GUARD")"
expect "missing arm32 fallback fails" 1 "$(mk_tree noguard "$TIMER_NODE_GOOD" "$DEFAULT" "")"
expect "fallback that does not set VDSO_CLOCKMODE_NONE fails" 1 "$(mk_tree wrong "$TIMER_NODE_GOOD" "$DEFAULT" "$GUARD_WRONG")"
expect "fallback before the vdso_default assignment fails" 1 "$(mk_tree order "$TIMER_NODE_GOOD" "$GUARD" "$DEFAULT")"
expect "no timer node at all fails" 1 "$(mk_tree none "" "$DEFAULT" "$GUARD")"
d="$(mk_tree m2 "$TIMER_NODE_GOOD" "$DEFAULT" "$GUARD")"
printf '/ {\n%s\n};\n' "$TIMER_NODE_BARE" > "$d/arch/arm/boot/dts/rockchip/rv1106-warden-m2.dts"
expect "a second board DTS without the property fails" 1 "$d"
rm -f "$d/drivers/clocksource/arm_arch_timer.c"
expect "missing arm_arch_timer.c fails" 1 "$d"
n=$((n + 1))
if python3 "$CHECK" >/dev/null 2>&1; [ $? = 2 ]; then echo "PASS: no argument is a usage error"
else echo "FAIL: no argument is a usage error"; fails=$((fails + 1)); fi
if [ "$fails" -ne 0 ]; then
echo "check-vdso-counter: $fails of $n FAILED"; exit 1
fi
echo "check-vdso-counter: all $n passed"