Repository navigation
watchdog: apple: report no time left once the counter passed the bite, and add KUnit tests - #2919
Conversation
apple_wdt_get_timeleft() subtracts the current count from the bite time in u32. The counter keeps running while the reset is not armed (the watchdog is stopped, or was never started), so once it has passed the bite time the difference wraps and the time left reads as up to the whole counter range (178 s at 24 MHz) instead of 0. Return 0 when the counter is at or past the bite time. Fixes: 4ed224a ("watchdog: Add Apple SoC watchdog driver") Signed-off-by: Ryan Murray <[email protected]>
Add a suite for the Apple SoC watchdog driver that runs its operations on a register block in kernel memory with a fixed clock rate: - start, stop, ping and restart write exactly the registers they should, and no other; - set_timeout() for a range of timeouts, including the clamp to what the 32-bit counter can hold; - the time left before the reset, after a ping, and once the counter has passed the bite time; - suspend and resume of an idle, an active and a hardware-running watchdog. Tests only, no functional change. Signed-off-by: Ryan Murray <[email protected]>
|
Review at 23a46a1. The units are right: ticks of the DT clock (clkref, 24 MHz fixed-clock, read with clk_get_rate() at probe) divided by clk_rate gives whole seconds, rounded down. The change only reads registers, so it cannot make the watchdog fire, or stop it firing. Arming, pings and the bite value are unchanged.
Otherwise the tests are good. The fill-pattern check catches stray writes to WD0 and WD2, and the set_timeout table covers the clamp to the 32-bit counter, including UINT_MAX/1000. |
There was a problem hiding this comment.
Formal §1–§6 pre-PR checklist review at 23a46a1d08b47f8e461037377c05139b58d04b71.
Checklist Summary
- §1 No model gating: Pass.
- §2 Production-ready, no hacks: Needs change — see blocker 1 below.
- §3 Safety: Pass (
apple_wdt_get_timeleft()is read-only and does not alter arming, ping, or bite register writes). - §4 Clean-room & attribution: Pass (both commits carry human author/committer and
Signed-off-by: Ryan Murray <[email protected]>only, zero AI trailers in commits; PR body disclosure present). - §5 Evidence: Owed — see blocker 2 below.
- §6 Naming: Pass.
Blockers
- Incomplete fix for 32-bit counter wrap while disarmed (
drivers/watchdog/apple_wdt.c:116-127): On a free-running 32-bit counter at 24 MHz,WD1_CUR_TIMEwraps back to0every ~179 s whileAPPLE_WDT_CTRL_RESET_ENis clear. Once it wraps belowreset_time,cur_time >= reset_timeis false again and a stopped watchdog resumes reporting bogus non-zerotimeleft(timeout..1s) every counter period. ReadAPPLE_WDT_WD1_CTRLand return0whenever!(ctrl & APPLE_WDT_CTRL_RESET_EN)(keepingcur_time >= reset_timefor the armed case). Updateapple_wdt-test.cto setAPPLE_WDT_WD1_CTRL = APPLE_WDT_CTRL_RESET_ENexplicitly in armed timeleft tests (rather than relying onAPPLE_WDT_TEST_FILL(0x1c)having bit 2 set) and add a disarmed wrapped-counter test case (CUR_TIME < BITE_TIMEwithCTRL = 0->0). - §5 hardware evidence owed: This PR changes driver behavior (
apple_wdt.c) based on the unverified premise thatWD1_CUR_TIMEkeeps running while disarmed, and every Apple Silicon Mac carriesapple_wdt. Owed: a hardware row on any Apple Silicon Mac reading/sys/class/watchdog/watchdog0/timeleftwith the watchdog stopped across >180 s (verifying both past-bite and post-wrap behavior), plus regression check (0 SELinux denials, 0 failed units, 0 new kernel errors).
Non-blocking notes
drivers/watchdog/apple_wdt-test.c:174: comment says 4 GHz is "one tick short of a 32-bit rate" (U32_MAXis4294967295, not4000000001).- KUnit integration keeps all functions
staticunderCONFIG_KUNIT=nand has clean teardown. - CI checks are still queued/in-progress at review time.
|
Merge readiness at
Areas: Updated by pr-readiness on pushes, edits, reviews and comments, and on a schedule. Rules: merge policy · labels. |
DjDeveloperr
left a comment
There was a problem hiding this comment.
Verdict: FINISH, then merge at 23a46a1d08b4
Blockers:
drivers/watchdog/apple_wdt.c:116-127:WD1_CUR_TIMEis a free-running 32-bit counter at 24 MHz, so with the watchdog disarmed it wraps to 0 about every 179 s. Once it wraps belowreset_time,cur_time >= reset_timeis false again, and a stopped watchdog reports a bogus time left. Fix: report 0 wheneverRESET_ENis clear, or track the bite across wraps, with a KUnit case for the wrap.
Checked: no Apple material, no gates. The KUnit tests cover the armed path.
Superseded by the review at 23a46a1
WD1_CUR_TIME is a free-running 32-bit counter. With RESET_EN clear it keeps counting and wraps to zero every 2^32 ticks (about 179 s at 24 MHz). Once it wraps back below the bite time, the cur >= bite check no longer catches it and a stopped watchdog reports up to the whole timeout as time left, although no reset is coming. Read the control register first and report 0 whenever RESET_EN is clear. The cur >= bite check stays for the armed counter that reads past the bite while the reset is on its way. The KUnit tests arm the reset where they expect time left, and a new case covers the disarmed counter past the bite, wrapped back below it, with only IRQ bits set, and a start/stop pair. With the driver change reverted, the new case fails 4 expectations. Signed-off-by: Ryan Murray <[email protected]>
|
Fixed in d790d27 (one normal push, no force). Blocker 1 (free-running counter wraps below the bite time): Testing: Still to run: a lab Mac row at this head ( |
|
Also forward-merged |
|
Row at The armed path reads correctly on hardware. The disarmed and wrapped cases are covered by the KUnit cases, since systemd keeps the watchdog armed on these Macs. DetailBoth rows ran on the default cmdline with the kernel booted once as a non-default entry, then back to fleet89, which was verified afterwards (saved entry, empty next_entry, kernel removed, 0 failed, Enforcing). Per Mac: SELinux Enforcing, 0 failed units, 0 AVC, 0 err-level kernel lines, 0 oops; Wi-Fi ping OK; s2idle (rtc1, 15 s) rc=0 with ping and a 64 MiB direct NVMe read after the wake; Apple SoC watchdog armed with time left counting (44 s and 58 s of systemd's 60 s); dEQP-VK |
|
Row at Third family: the armed path reads correctly on the Neo too. DetailNeo (J700, T8140/G17P), fixa2 booted once as a non-default BLS entry, then back to fleet89, verified afterwards (saved entry, empty next_entry, kernel removed, 0 failed, Enforcing). SELinux Enforcing, 0 failed units, 0 AVC, 0 oops, 0 err-level kernel lines; Wi-Fi up; G17P Vulkan device; dEQP-VK api.smoke 8/8 and draw.renderpass.simple_draw 4/4; watchdog armed (57 s left of 60); s2idle on rtc0 rc=0 with a 64 MiB direct NVMe read after the wake. Two lines are the same on fleet89 (baseline traced): the boot-time "G17: crash logs from the firmware data segment" note, and Wi-Fi needing ~9 s after the wake before ping answers. Logs: traces/kernel/20261127-fixa2-rows/neo/ (store). |
…mode The merge of main brought the WD2 simple-reconfig path, where WD1 RESET_EN is never set and the WD2 bark IRQ_EN is what resets the SoC. The disarmed check still read WD1_CTRL, so in reconfig mode get_timeleft() always reported 0 (apple-wdt-tests step 4 failed). Read the control register of the watchdog that resets: WD2 IRQ_EN with reconfig, WD1 RESET_EN without. Drop the duplicated cur >= reset check the merge left behind. The host test now also checks a stopped WD2 with its counter below the bark; with the WD2 check removed it fails. Signed-off-by: Ryan Murray <[email protected]>
|
CI fix at 3500a17: the main merge (5b1cdc4) brought the WD2 simple-reconfig path, where WD1 RESET_EN is never set and the WD2 bark IRQ_EN is what resets. The disarmed check still read WD1_CTRL, so in reconfig mode
Tested: |
|
Hardware row at this head (3500a17): A18 Pro (T8140, J700), legacy WD1 mode (no The watchdog was stopped by setting systemd's
Same row on the M4 Pro (T6040, J616s), legacy WD1 mode, same fixa5 kernel:
A reconfig-mode (WD2) Mac was not run. Only T6050 has the Evidence (lab store): |
There was a problem hiding this comment.
Verdict: MERGE at 3500a179
Blockers: none (26/26 CI green and 3-family exact-head hardware rows PASS; ready to merge).
Checked:
drivers/watchdog/apple_wdt.c:d790d275and3500a179cleanly resolve both the free-running 32-bit counter wraparound blocker and WD2 reconfig-mode compatibility by checkingAPPLE_WDT_WD2_CTRL & APPLE_WDT_CTRL_IRQ_ENwhenwdt->reconfigis set andAPPLE_WDT_WD1_CTRL & APPLE_WDT_CTRL_RESET_ENotherwise before computing remaining ticks, returning0when disarmed or past bite time.- KUnit (
drivers/watchdog/apple_wdt-test.c) and host tests (tools/asahi/apple-wdt-tests.py) cover stopped WD1/WD2 and wraparound edge cases; 26/26 CI checks green (SUCCESS),MERGEABLEonmain. - Exact-head hardware rows PASS across J700 (A18 Pro), J316s (M1 Pro), and J413 (M2 Air); checked for Apple material, tool attribution, private serials, and gating: clean.
Evidence
- Head:
3500a179b5d6(base: main,mergeable: MERGEABLE,+463/-1across 5 files).
|
code-owner ping <@422957901716652033> / @DjDeveloperr: merge train at |
|
Merging under the 6-point rule (Ryan 09:29, permanent), at |
Problem.
apple_wdt_get_timeleft()subtracts the current count from the bite time in u32. The counter keeps running while the reset is not armed (the watchdog is stopped or was never started), so once it has passed the bite time, the time left wraps to up to the whole counter range (about 178 s at 24 MHz) instead of 0. The driver also had no test.Change.
watchdog: apple: report no time left once the counter passed the bite: return 0 when the counter is at or past the bite time.watchdog: apple: add KUnit tests: a newapple_wdtsuite (included from the driver) on a register block in kernel memory. It checks that start, stop, ping and restart write exactly their registers and no other, set_timeout() for a range of timeouts including the clamp to the 32-bit counter, the time left (normal, after a ping, past the bite), and suspend/resume of an idle, an active and a hardware-running watchdog. Plus a standalonedrivers/watchdog/apple_wdt.kunitconfig.Testing.
kunit.py run --arch=arm64(QEMU, gcc): 20/20 with the fix, standalone kunitconfig 20/20, and again with all six of this series' branches merged on integration/aurora 322eadc.apple_wdt_test_timeleft_past_bitefails (19/20).Still to run. A hardware row is not needed for the fix (it only changes the value reported once the counter has passed the bite). Reading
/sys/class/watchdog/watchdog0/timelefton a Mac with the watchdog stopped would show it.