kernel: keep the arm32 vDSO clock off the virtual counter (#35) #36

Merged
noah merged 1 commits from rb/ln-vdso-phys-counter into rebuild 2026-10-29 06:05:11 -06:00
Owner

Fixes #35. Refs flare-edge#2319.

What was wrong

On bench a the vDSO CLOCK_MONOTONIC runs 738.9 s ahead of the kernel clock. The skew is a fixed offset: it moved -0.1 ppm over 30 s (flare-edge tools/bench/clock-skew, image 9462). Every absolute deadline taken from the vDSO, such as std's Condvar::wait_timeout or pthread_cond_timedwait, therefore expires minutes late (flare-edge#2319 and the #2311 reset loop).

Cause: the RV1106 timer node lists only the secure and non-secure physical PPIs (13, 14) and has no virtual-timer PPI. The firmware does not enter the kernel in HYP mode, so arch_timer_select_ppi() puts the kernel on the physical counter, and nothing zeroes CNTVOFF. The arm32 vDSO always reads the virtual counter.

Change

New patch patches/82-arch-timer-vdso-phys-counter.patch. It applies after 20, because it edits two DTS files that patch 20 adds.

  • rv1106.dtsi and rv1106-warden-m2.dts: the timer node now carries arm,cpu-registers-not-fw-configured. This is the upstream binding for firmware that leaves the timer registers unset.
    • The arch timer stays on ARCH_TIMER_PHYS_SECURE_PPI, as it is today.
    • arch/arm/kernel/vdso.c cntvct_functional() now returns false, so the vDSO drops __vdso_clock_gettime, __vdso_clock_gettime64, __vdso_gettimeofday and __vdso_clock_getres. libc then goes straight to the syscall, which costs about 1 us per call.
  • drivers/clocksource/arm_arch_timer.c arch_counter_register(): this is the safety net for a device tree without the property. On arm32, a kernel on the physical counter that was not entered in HYP mode sets vdso_clock_mode = VDSO_CLOCKMODE_NONE and logs arch_timer: physical counter without HYP: vDSO clock disabled.
    • With HYP mode, the hyp stub zeroes CNTVOFF (hyp-stub.S), so nothing changes there.
    • QEMU -M virt has a virtual PPI, so it is unchanged too.
  • tests/arch-timer/check-vdso-counter.py checks both guards in the patched tree. CI's patches-apply job runs it on the real tree, together with its 12 regression cases (run-check-vdso-counter-tests.sh).
  • patches/README.md: a series table row, and the "applies in order" wording.

Option 2 of #35 (the boot firmware zeroes CNTVOFF, which keeps the fast vDSO) is not part of this PR. It is optional once this lands.

Local gate

Regression cases on bfe-mpc-0056 (lane-remote LN <worktree> -- bash tests/arch-timer/run-check-vdso-counter-tests.sh):

PASS: fixed tree passes
PASS: timer node without the property fails
PASS: property only inside a comment fails
PASS: property only in a child node fails
PASS: timer node with a virtual PPI needs no property
PASS: missing arm32 fallback fails
PASS: fallback that does not set VDSO_CLOCKMODE_NONE fails
PASS: fallback before the vdso_default assignment fails
PASS: no timer node at all fails
PASS: a second board DTS without the property fails
PASS: missing arm_arch_timer.c fails
PASS: no argument is a usage error
check-vdso-counter: all 12 passed

The checker on the real tree (pristine 6.18.46 plus the series), with and without patch 82:

vdso-counter: ok (DT property and arm32 physical-counter fallback present)
after rc=0
FAIL: arch/arm/boot/dts/rockchip/rv1106-warden-m2.dts: timer node has no virtual-timer PPI and no arm,cpu-registers-not-fw-configured
FAIL: arch/arm/boot/dts/rockchip/rv1106.dtsi: timer node has no virtual-timer PPI and no arm,cpu-registers-not-fw-configured
FAIL: drivers/clocksource/arm_arch_timer.c: arch_counter_register() lacks the arm32 physical-counter vDSO fallback (vdso_clock_mode = VDSO_CLOCKMODE_NONE)
before rc=1

Full kernel build: build/build-kernel.sh, CROSS_COMPILE=arm-linux-gnueabihf-, JOBS=4, aic8800 modules collected, run under the SDK build lock.

== collected 3 module(s) from drivers/net/wireless/aic8800
final.config sha256: d06991e697282228c7583a20438634f89582a2818b79abc93951a9933561e6cd
== build OK

The built tree was checked as follows:

  • fdtget -p rv1106-warden.dtb /timer lists compatible interrupts clock-frequency arm,cpu-registers-not-fw-configured.
  • vmlinux contains the fallback message.
  • .config has CONFIG_VDSO=y CONFIG_ARM_ARCH_TIMER=y CONFIG_ARM_VIRT_EXT=y.

shellcheck is clean, and the prose scan reports 0 findings.

Bench acceptance (follows)

A kernel-only boot.img cannot be packed on the workstation, because resource_tool comes from the vendor SDK. The bench proof therefore runs from a flare-edge firmware image built with this SDK. The flare-edge branch rb/w31-sdk-vdso-pin (c3dbb2fa) pins vendor/warden-sdk to this branch's head b4596ed.

The acceptance check is flare-edge tools/bench/clock-skew/run.sh --rate-s 30 on that image. It expects vdso_skew_ms under 1, wait_abs_vdso ok and verdict=PASS. Before this change, image 9462 gave vdso_skew_ms=738925.463, wait_abs_vdso=5010 hang and verdict=FAIL. The result will be posted here and on flare-edge#2319.

Generated with Claude Code
https://claude.ai/code/session_01KerYPVh72hhNgKi3wS5ijG

Fixes #35. Refs flare-edge#2319. ## What was wrong On bench a the vDSO `CLOCK_MONOTONIC` runs 738.9 s ahead of the kernel clock. The skew is a fixed offset: it moved -0.1 ppm over 30 s (flare-edge `tools/bench/clock-skew`, image 9462). Every absolute deadline taken from the vDSO, such as std's `Condvar::wait_timeout` or `pthread_cond_timedwait`, therefore expires minutes late (flare-edge#2319 and the #2311 reset loop). Cause: the RV1106 timer node lists only the secure and non-secure physical PPIs (13, 14) and has no virtual-timer PPI. The firmware does not enter the kernel in HYP mode, so `arch_timer_select_ppi()` puts the kernel on the physical counter, and nothing zeroes CNTVOFF. The arm32 vDSO always reads the virtual counter. ## Change New patch `patches/82-arch-timer-vdso-phys-counter.patch`. It applies after 20, because it edits two DTS files that patch 20 adds. - `rv1106.dtsi` and `rv1106-warden-m2.dts`: the timer node now carries `arm,cpu-registers-not-fw-configured`. This is the upstream binding for firmware that leaves the timer registers unset. - The arch timer stays on `ARCH_TIMER_PHYS_SECURE_PPI`, as it is today. - `arch/arm/kernel/vdso.c` `cntvct_functional()` now returns false, so the vDSO drops `__vdso_clock_gettime`, `__vdso_clock_gettime64`, `__vdso_gettimeofday` and `__vdso_clock_getres`. libc then goes straight to the syscall, which costs about 1 us per call. - `drivers/clocksource/arm_arch_timer.c` `arch_counter_register()`: this is the safety net for a device tree without the property. On arm32, a kernel on the physical counter that was not entered in HYP mode sets `vdso_clock_mode = VDSO_CLOCKMODE_NONE` and logs `arch_timer: physical counter without HYP: vDSO clock disabled`. - With HYP mode, the hyp stub zeroes CNTVOFF (`hyp-stub.S`), so nothing changes there. - QEMU `-M virt` has a virtual PPI, so it is unchanged too. - `tests/arch-timer/check-vdso-counter.py` checks both guards in the patched tree. CI's patches-apply job runs it on the real tree, together with its 12 regression cases (`run-check-vdso-counter-tests.sh`). - `patches/README.md`: a series table row, and the "applies in order" wording. Option 2 of #35 (the boot firmware zeroes CNTVOFF, which keeps the fast vDSO) is not part of this PR. It is optional once this lands. ## Local gate Regression cases on bfe-mpc-0056 (`lane-remote LN <worktree> -- bash tests/arch-timer/run-check-vdso-counter-tests.sh`): ``` PASS: fixed tree passes PASS: timer node without the property fails PASS: property only inside a comment fails PASS: property only in a child node fails PASS: timer node with a virtual PPI needs no property PASS: missing arm32 fallback fails PASS: fallback that does not set VDSO_CLOCKMODE_NONE fails PASS: fallback before the vdso_default assignment fails PASS: no timer node at all fails PASS: a second board DTS without the property fails PASS: missing arm_arch_timer.c fails PASS: no argument is a usage error check-vdso-counter: all 12 passed ``` The checker on the real tree (pristine 6.18.46 plus the series), with and without patch 82: ``` vdso-counter: ok (DT property and arm32 physical-counter fallback present) after rc=0 FAIL: arch/arm/boot/dts/rockchip/rv1106-warden-m2.dts: timer node has no virtual-timer PPI and no arm,cpu-registers-not-fw-configured FAIL: arch/arm/boot/dts/rockchip/rv1106.dtsi: timer node has no virtual-timer PPI and no arm,cpu-registers-not-fw-configured FAIL: drivers/clocksource/arm_arch_timer.c: arch_counter_register() lacks the arm32 physical-counter vDSO fallback (vdso_clock_mode = VDSO_CLOCKMODE_NONE) before rc=1 ``` Full kernel build: `build/build-kernel.sh`, `CROSS_COMPILE=arm-linux-gnueabihf-`, `JOBS=4`, aic8800 modules collected, run under the SDK build lock. ``` == collected 3 module(s) from drivers/net/wireless/aic8800 final.config sha256: d06991e697282228c7583a20438634f89582a2818b79abc93951a9933561e6cd == build OK ``` The built tree was checked as follows: - `fdtget -p rv1106-warden.dtb /timer` lists `compatible interrupts clock-frequency arm,cpu-registers-not-fw-configured`. - `vmlinux` contains the fallback message. - `.config` has `CONFIG_VDSO=y CONFIG_ARM_ARCH_TIMER=y CONFIG_ARM_VIRT_EXT=y`. `shellcheck` is clean, and the prose scan reports 0 findings. ## Bench acceptance (follows) A kernel-only `boot.img` cannot be packed on the workstation, because `resource_tool` comes from the vendor SDK. The bench proof therefore runs from a flare-edge firmware image built with this SDK. The flare-edge branch `rb/w31-sdk-vdso-pin` (c3dbb2fa) pins `vendor/warden-sdk` to this branch's head b4596ed. The acceptance check is flare-edge `tools/bench/clock-skew/run.sh --rate-s 30` on that image. It expects `vdso_skew_ms` under 1, `wait_abs_vdso` ok and `verdict=PASS`. Before this change, image 9462 gave `vdso_skew_ms=738925.463`, `wait_abs_vdso=5010 hang` and `verdict=FAIL`. The result will be posted here and on flare-edge#2319. Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01KerYPVh72hhNgKi3wS5ijG
noah added 1 commit 2026-10-29 03:48:52 -06:00
kernel: keep the arm32 vDSO clock off the virtual counter (#35)
ci / test (push) Successful in 31s
ci / bench (push) Successful in 14s
ci / mcdc (push) Successful in 26s
ci / prune-artifacts (push) Skipped
ci / kernel-build (push) Skipped
ci / quality (push) Successful in 1m18s
ci / badges (push) Skipped
ci / bench (pull_request) Successful in 10s
ci / patches-apply (push) Successful in 52s
ci / qemu-tools (push) Successful in 3m26s
ci / kernel-symbols (push) Successful in 5m12s
ci / test (pull_request) Successful in 8s
ci / prune-artifacts (pull_request) Skipped
ci / kernel-build (pull_request) Skipped
ci / badges (pull_request) Skipped
ci / qemu-tools (pull_request) Successful in 2m59s
ci / mcdc (pull_request) Successful in 19s
ci / patches-apply (pull_request) Successful in 52s
ci / quality (pull_request) Successful in 1m15s
ci / kernel-symbols (pull_request) Successful in 6m57s
b4596ed737
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 one: on bench a clock_gettime() ran 738.9 s ahead of the
kernel clock (pure offset, -0.1 ppm over 30 s) and every absolute deadline
taken from it expired minutes late (flare-edge#2319, the #2311 reset loop).

New patch 82-arch-timer-vdso-phys-counter.patch:
- rv1106.dtsi and rv1106-warden-m2.dts: the timer node carries
  arm,cpu-registers-not-fw-configured. The kernel keeps the physical
  timer it uses today, and arch/arm/kernel/vdso.c drops the vDSO clock
  symbols, so libc goes straight to the syscall.
- arm_arch_timer.c: on arm32, a kernel on the physical counter without
  HYP mode sets the counter's vdso_clock_mode to VDSO_CLOCKMODE_NONE, the
  safety net for a device tree without the property. QEMU -M virt (virtual
  PPI present) is unchanged.

tests/arch-timer/check-vdso-counter.py checks both guards in the patched
tree; CI's patches-apply job runs it and its 12 regression cases.

Fixes #35
Refs flare-edge#2319

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KerYPVh72hhNgKi3wS5ijG
Author
Owner

Bench result for the arm32 vDSO counter fix (lane LN, 2026-10-29 11:33-12:02Z, under a FLASH lock on bench a).

Image: run 9545 firmware-rv1106-test-dev-insecure (flare-edge rb/w31-sdk-vdso-pin c3dbb2f, SDK b4596ed), written with tools/bench-flash-slot.sh to the inactive slot _a (read-back sha256 matched for boot, oem, rootfs), armed with 3 tries, NOT marked good.

Kernel log on _a:

arch_timer: cp15 timer running at 24.00MHz (phys).
arch_timer: physical counter without HYP: vDSO clock disabled
clocksource: Switched to clocksource arch_sys_counter

clock-skew (tools/bench/clock-skew/run.sh, clockskew from 15620f47, --rate-s 30), 33 s after boot:

image: VERSION=0.17.79-rc BUILD_DATE=2026-10-29 GIT_COMMIT=c3dbb2f FLAVOR=test WIFI_EAP=0 KERNEL=6.18.46 KCONFIG_SHA256=7de6e4896da603e0993db36a261796abbb040fd6ac3733a39d163762e4fda27f SDK=/home/noah/projects/flare-edge/sdk 
clockskew: vdso_symbol=absent
clockskew: kernel_ns=32973263139
clockskew: vdso_ns=absent
clockskew: libc_ns=32973267222
clockskew: uptime_s=32.97
clockskew: vdso_rate_ppm=skipped no vdso clock
clockskew: libc_skew_ms=0.000
clockskew: wait_relative=1006 ok
clockskew: wait_abs_kernel=1008 ok
clockskew: wait_abs_vdso=skipped no vdso clock
clockskew: verdict=PASS

Again at 699 s uptime:

clockskew: uptime_s=698.57
clockskew: libc_skew_ms=-0.000
clockskew: verdict=PASS

Before the fix (same panel, image 9462 on _b): vdso_skew_ms=738925.463, wait_abs_vdso=5010 hang, verdict FAIL. With the fix the vDSO clock_gettime symbol is gone (arm32 vdso_nullpatch when the clock mode is NONE), libc falls back to the syscall, libc_skew_ms is 0 and every timed wait returns on time: verdict PASS.

The panel was then put back on _b (9d03840, B pri 15 confirmed; A pri 14, 2 tries left, not successful), rebooted, and checked healthy: slot _b, uptime 796 s with no reset, mosquitto, warden-io, warden-modbus, appd, warden-automation, warden-flared, warden-ui and warden-telemetry running with unchanged PIDs. Lock released 12:03Z.

Bench result for the arm32 vDSO counter fix (lane LN, 2026-10-29 11:33-12:02Z, under a FLASH lock on bench a). Image: run 9545 firmware-rv1106-test-dev-insecure (flare-edge rb/w31-sdk-vdso-pin c3dbb2f, SDK b4596ed), written with tools/bench-flash-slot.sh to the inactive slot _a (read-back sha256 matched for boot, oem, rootfs), armed with 3 tries, NOT marked good. Kernel log on _a: ``` arch_timer: cp15 timer running at 24.00MHz (phys). arch_timer: physical counter without HYP: vDSO clock disabled clocksource: Switched to clocksource arch_sys_counter ``` clock-skew (tools/bench/clock-skew/run.sh, clockskew from 15620f47, --rate-s 30), 33 s after boot: ``` image: VERSION=0.17.79-rc BUILD_DATE=2026-10-29 GIT_COMMIT=c3dbb2f FLAVOR=test WIFI_EAP=0 KERNEL=6.18.46 KCONFIG_SHA256=7de6e4896da603e0993db36a261796abbb040fd6ac3733a39d163762e4fda27f SDK=/home/noah/projects/flare-edge/sdk clockskew: vdso_symbol=absent clockskew: kernel_ns=32973263139 clockskew: vdso_ns=absent clockskew: libc_ns=32973267222 clockskew: uptime_s=32.97 clockskew: vdso_rate_ppm=skipped no vdso clock clockskew: libc_skew_ms=0.000 clockskew: wait_relative=1006 ok clockskew: wait_abs_kernel=1008 ok clockskew: wait_abs_vdso=skipped no vdso clock clockskew: verdict=PASS ``` Again at 699 s uptime: ``` clockskew: uptime_s=698.57 clockskew: libc_skew_ms=-0.000 clockskew: verdict=PASS ``` Before the fix (same panel, image 9462 on _b): vdso_skew_ms=738925.463, wait_abs_vdso=5010 hang, verdict FAIL. With the fix the vDSO clock_gettime symbol is gone (arm32 vdso_nullpatch when the clock mode is NONE), libc falls back to the syscall, libc_skew_ms is 0 and every timed wait returns on time: verdict PASS. The panel was then put back on _b (9d03840, B pri 15 confirmed; A pri 14, 2 tries left, not successful), rebooted, and checked healthy: slot _b, uptime 796 s with no reset, mosquitto, warden-io, warden-modbus, appd, warden-automation, warden-flared, warden-ui and warden-telemetry running with unchanged PIDs. Lock released 12:03Z.
noah merged commit 4d30c3083b into rebuild 2026-10-29 06:05:11 -06:00
Sign in to join this conversation.
No Reviewers
No labels
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: blueflare/bfe-core1106-sdk#36