Skip to content

wdt: leave an armed watchdog as found under m1n1.wdt=keep - #503

Closed
rolotrealanis98 wants to merge 3 commits into
aurora-silicon:mainfrom
rolotrealanis98:feat/wdt-keep
Closed

rolotrealanis98 wants to merge 3 commits into
aurora-silicon:mainfrom
rolotrealanis98:feat/wdt-keep

Conversation

@rolotrealanis98

Copy link
Copy Markdown
Contributor

What: With m1n1.wdt=keep in iBoot's boot arguments, leave a watchdog that an earlier, non-aura first stage armed as found instead of disabling it, and reboot after the 15 s host window instead of idling in the proxy, so that a hung boot falls back to that first stage's other slot.
Tested: not yet on hardware at f3dc5d0; host test and local CI only (Evidence)
Risk: two-way · all Macs, only when the boot arguments carry the exact token; without it nothing changes
Not yet: a boot with a first stage that writes the token in iBoot's command line; the 15 s fallback reboot; one plain Stage 2 boot without the token (watchdog disabled as today)

Details

Aura disables the SoC watchdog at start. A first stage that is not aura can arm it for the next stage and rely on it: an A/B m1n1 stage 1 arms 150 s before starting its stage 2 and passes m1n1.wdt=keep, so a stage 2 or kernel that hangs before Linux's apple_wdt probes resets the Mac, iBoot counts a failed boot, and stage 1 boots its fallback slot. Disarming it drops that deadline.

  1. wdt: leave an armed watchdog as found under m1n1.wdt=keep. With the exact token in the boot arguments and the primary watchdog armed at start (WDT_CTL read first), wdt_disable_at_start() leaves both watchdogs as they are and says so; otherwise it disables them as before. The token is read like every other boot option, from iBoot's command line up to its terminator: no offset scan, nothing past the terminator. Nothing in aura feeds the kept watchdog, and the proxy does not kick it. A host that needs longer disarms it with P_WDT_DISABLE; any disarm or re-arm in the stage ends the keep. kboot logs it and marks the watchdog u-boot,noautostart, as on a trial boot.
  2. proxy_fallback: a stage under m1n1.wdt=keep reboots instead of idling in the proxy. It waits PROXY_FALLBACK_HOST_MS (15 s) for a host, as an aura-try trial does, and reboots if none came. A host that attaches keeps the proxy. Both share the one window in proxy_fallback(); a trial booted with the token stays a trial (its watchdog is armed before the window, as before). The host tests cover the keep cases.

The code is in every stage, Stage 1 included, but acts only when the token is in the boot arguments. docs/boot-options.md documents it and says it does not belong in the NVRAM boot-args.

Evidence
  • Host test test_wdt_keep_option: token matching, every stage, nothing read past the terminator, unterminated and empty lines.
  • J716s behind its A/B m1n1 stage 1, 27.3 beta stub, earlier form (also read the token past the terminator and kicked from the proxy): watchdog left armed, Linux's apple_wdt took it over, a boot that hung in the kernel was reset about 150 s later and fell back unattended. Not run at this head.

Local run of the repository's CI steps (pytest, format check, policy) in a Fedora 43 container, on base d81910e: 13 of 13 steps pass at f3dc5d0, and 13 of 13 on the unmodified base.

Aura disables the SoC watchdog at start. A first stage that is not
aura can arm it for the next stage and count on it: the J716s' A/B m1n1
stage 1 arms 150 s before it starts its stage 2 and appends
m1n1.wdt=keep, so that a stage 2 or kernel that hangs before Linux's
apple_wdt probes resets the Mac, iBoot counts a failed boot and stage 1
boots its fallback slot. Disarming it drops that deadline: a hung boot
waits for someone to hold the power button, and the next start boots
the same file again.

With the exact token m1n1.wdt=keep in the boot arguments, and the
primary watchdog armed when aura starts, wdt_disable_at_start() leaves
the primary and the secondary as they are and says so; without the
token, or with a disarmed watchdog, it disables both as before. The
token keeps its m1n1 spelling because the stage that writes it is an
m1n1 build. It is read from the command line up to its terminator
only, as every other boot option is: nothing past iBoot's string is
read, since iBoot defines no bytes there.

Nothing in aura feeds the kept watchdog. As on an aura-try trial, a
host that needs longer than the period disarms it with P_WDT_DISABLE,
and any disarm or re-arm in this stage (the trial watchdog, the Stage 1
boot watchdog) ends the keep. kboot logs "watchdog left armed for the
OS" once its log buffer exists, and marks the watchdog
u-boot,noautostart, as it does on a trial boot.

Tests: test_wdt_keep_option (token matching, every stage, and nothing
read past the terminator: not a token 4 bytes in, where a stage with
m1n1's unpacked boot_args union writes the command line).

Signed-off-by: rolotrealanis98 <122947376+rolotrealanis98@users.noreply.github.com>

Signed-off-by: Rolando Trevino <122947376+rolotrealanis98@users.noreply.github.com>
… in the proxy

A stage booted with m1n1.wdt=keep has a fallback behind it, in a first
stage that is not aura: a reset before the OS counts as a failed boot,
and that stage then boots its other slot. When such a stage cannot
start its payload, or a hand-off fails, it stops in the proxy, where
nobody may be at the Mac to drive it.

proxy_fallback() now treats it as it treats an aura-try trial: it waits
PROXY_FALLBACK_HOST_MS (15 s) for a host and reboots if none came. This
does not depend on the watchdog being still armed: a disarmed one would
leave the Mac in the proxy until the power button is held, and a power
cycle does not count as a failed boot. A host that attaches keeps the
proxy; a watchdog the first stage armed still runs under it, and a host
that needs longer disarms it. Without the token and outside a trial,
nothing changes.

Signed-off-by: rolotrealanis98 <122947376+rolotrealanis98@users.noreply.github.com>

Signed-off-by: Rolando Trevino <122947376+rolotrealanis98@users.noreply.github.com>
@RyanTheTide

Copy link
Copy Markdown
Contributor

@rolotrealanis98 checking open drafts today. To come out of draft, this still needs:

  • It conflicts with main. Merge main in or rebase (no force push needed: a merge commit is fine).
  • Then a test run at the final head on a Mac with the hardware it touches, and mark it ready for review.

If it's no longer needed, say so here and we'll close it. Otherwise it stays open as a draft until these are done.

main reworked src/wdt.c: wdt_disable() and wdt_reboot() now record the
watchdog block through wdt_set_addrs(), with the simple-reconfig WD2
channel where the ADT offers it, and the host tests take the whole of
wdt.c from '#define WDT_COUNT' on.

- src/wdt.c: keep both includes (boot_options.h, memory.h), both sets
  of statics (wdt_kept; wdt_reconfig and the WD2 helpers) and the
  keep's reset of wdt_kept in wdt_arm(). wdt_disable_at_start() still
  keeps only a primary armed with RESET_EN, and now records the block
  with wdt_set_addrs() as wdt_disable() would, so wdt_reboot() takes
  the same channel either way. Without the token nothing changes.
- tests/python/test_wdt_arm.py, test_wdt_boot_window.py: take main's
  harness, which compiles wdt.c whole; wdt_kept comes from it now, and
  a boot_wdt_keep_enabled() stub returns false.

Signed-off-by: Rolando Trevino <122947376+rolotrealanis98@users.noreply.github.com>
@rolotrealanis98

Copy link
Copy Markdown
Contributor Author

Merged main in (8db4028, a normal merge, no force push). Main reworked wdt.c around the WD2 simple-reconfig channel; the keep still applies only to a primary armed with RESET_EN, and now records the block through wdt_set_addrs() as wdt_disable() does, so wdt_reboot() takes the same channel either way. The two wdt host tests take main's harness. Local CI at 8db4028 matches main on every step (the gcc Stage 1 size is unchanged); please approve the workflow runs (none ran on this fork PR).

Hardware: on my chain the stage 1 writes m1n1.wdt=keep at m1n1's boot_args offset, past iBoot's terminator, which this PR does not read, so a J716s boot here is the "no token" case and behaves as before. The "token" case needs the stage 1 to put the token in iBoot's line (or a first-stage header, as you suggested). It stays a draft until I can post that row.

@rolotrealanis98

Copy link
Copy Markdown
Contributor Author

Update: beyond the token placement, a loader on current main can't hand off on this J716s chain at all right now (SMP: boot CPU RVBAR check failed, details in #502), so neither the "token" nor the "no token" row can be taken here until that's handled.

@aurora-silicon-review aurora-silicon-review Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict: Changes requested at 8db4028e324e.

The new keep path reads base + WDT_CTL after checking only that the decoded base is nonzero. Validate alignment and that the control register fits inside the decoded aperture before the first MMIO access. Add direct coverage of wdt_disable_at_start() for an inherited armed watchdog with no writes, and for an invalid aperture with no read on that path. GitHub currently reports only readiness at this head, and the PR's test description names the earlier revision. Attach current-head CI and owner-approved fallback evidence before merge.

@rolotrealanis98

Copy link
Copy Markdown
Contributor Author

Closing as superseded by main's watchdog rework (4f68a25, 0ec6b94, b1c638c). On a plain boot, Stage 2 now takes the boot watchdog over with a fresh period right after its start, a stop in the proxy restarts the Mac unless a host attaches, and the hand-off disarms it. That covers what this PR was for (a hang before the OS on the J716s' m1n1 A/B chain resets the Mac instead of sitting in the proxy). Merged with main, this PR's keep would be re-armed by wdt_arm_boot() right after wdt_disable_at_start() and disarmed at the hand-off, so it would change nothing.

The review's aperture check (alignment, control register inside the decoded aperture, no wrap, with direct tests of wdt_disable_at_start()) was done before the merge showed this; if a kept first-stage watchdog surviving into the kernel is wanted later, I'll open it fresh on top of the new code with that check in.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants