Repository navigation
The fatal path waits a second on the clock for the console registers, not 10^8 pauses - #946
Conversation
… not 10^8 pauses `PANIC_LOCK_SPIN_LIMIT` bounded `panic_registers`' wait for another holder of `BackendGuard` at 100,000,000 `try_lock`s and `pause`s, and its comment called that "~1s of spin". Nothing converted it to time, so the wait lasted whatever that many pauses cost on the CPU running them. The wait is now `PANIC_LOCK_WAIT`, a one-second `Budget`, polled through `clock::settles`, the kernel's existing bounded poll: it compares the CPU's free-running counter against a deadline converted once, never the nanosecond clock's divide, so it is as safe from an NMI as the count was. `serial_lock` loses its count-bounded `within` and its `Seized::Expired`; `BackendLock::try_seize` asks once, and the waiting is the caller's. Before the clock is calibrated `settles` asks once. That is the right answer here: on both architectures `kernel_main` runs `arch::boot::clock`, which sets the counter's period, before `arch::boot::start_other_cpus`, so an uncalibrated fatal path runs on the only CPU, any holder is beneath its frame, and no wait could end with the registers let go. `panic_console::seize` reasons the same way. The loom models drive `try_seize` and their own bounded asks; the model that checked `within` asked exactly its count is deleted with the count. Closes issues/the-panic-lock-spin-limit-is-a-count-its-comment-calls-a-second.md; the two issues that named it or `PANIC_LOCK_SPIN_LIMIT` are updated.
Review of #946 at 06a3a53 (base origin/main 979d4c5)Assessment. This is the right change, made in the right place. The lock ( NMI and fatal-path safety of
It takes no lock, does no logging, does no MMIO beyond what The uncalibrated argument holds on both architectures. Loom.
In Issue edits. Both are legitimate.
Findings
SEND BACK |
Review round 1 suggestion; prose only.
|
Round 1 resolution, head
|
Review round 2: #946 at
|
What this changes
serial::panic_registersnow waits for another holder of the console registers forPANIC_LOCK_WAIT, a one-secondBudgeton the clock, polled throughclock::settles, instead of 100,000,000try_lock+pauseiterations that the old comment called "~1s".serial_lockloses its count-boundedwithinandSeized::Expired;BackendLock::try_seizeasks once and the caller owns the wait. Before calibrationsettlesasks once.Why
The count was not time: the wait lasted however long 10^8 pauses took on the CPU running them.
clock::settlesis the kernel's existing bounded poll. It compares the CPU's counter against a deadline converted once, without calling the nanosecond clock's divide, so it is as usable from an NMI as the count was.Uncalibrated, one ask is correct:
kernel_mainrunsarch::boot::clock(which sets the counter period) beforearch::boot::start_other_cpuson both architectures. A fatal path before calibration therefore runs on the only CPU, any holder is beneath its own frame, and no wait could end with the registers released.panic_console::seizeuses the same reasoning.No host test with an injected clock was added.
serial_lockno longer contains timing logic, and the wait isclock::settles, which is shared with every other bounded poll in the kernel. Injecting a clock intoclock.rsonly for this would be machinery for its own sake. The loom models now drivetry_seizewith their own bounded asks. The model that checkedwithin's exact count is deleted along with the count.Evidence
All run on the tree of
06a3a53a8(its commit adds only its message over the tested tree), macOS host. Logs, home and temp paths masked, are at evidence commit65c149b14d63238ea74fc1790454ed743e459b12onpr-946. The later head commit rewraps two issue paragraphs only, so no code, test or build input differs from the tested tree.cargo test --manifest-path kernel/loom/Cargo.toml --test serial_lock: EXIT=0, 8 passed (log).cargo run -- --ci host: EXIT=0, "Host: 86 step(s), all green" (includes clippy-D warningsfor both kernel arches and theserial-try-lock-then-somenegative control, which still redsserial_lock) (log).cargo run -- --build-only: EXIT=0 (log).cargo test --test toyos-build -- nested_nmi_is_loud: EXIT=0. x86-64 QEMU metal profile. A fatal path nested on a fatal path, with no "held through the bound" / "drained raw" line (faults::UNCLEAN) (log).cargo test --test toyos-build -- machine_shutdown_wire_kept virt_early_panic virt_fatal_halts_the_others_first: EXIT=0, 3 passed.virt_early_panicpanics beforearch::boot::clock, so it runspanic_registersthrough the uncalibrated one-ask path;virt_fatal_halts_the_others_firstis the multi-CPU AArch64 fatal path (log).No guest test holds the registers through the whole bound on another CPU. The one-second expiry itself is
settles' contract and is not exercised by a run.What is unsure
Anything a reader of
mainmust not missCloses
issues/the-panic-lock-spin-limit-is-a-count-its-comment-calls-a-second.md. Updates the citation inissues/a-syscall-panic-reset-the-guest-announced-and-qemu-never-saw.mdand thePANIC_LOCK_SPIN_LIMIT/seizenames inissues/a-fatal-path-inside-its-own-cpus-console-burst-waits-out-the-bound.md. Deletes the loom modelwithin_asks_a_silent_attempt_exactly_its_triesalong with the function it tested.