717. x86_64's double fault runs on a stack of its own
Overtaken by milestone 915 (NMI, double fault and machine check run on their own stacks):
kernel/src/arch/x86_64/ist.rs allocates the per-core stacks and calls set_interrupt_stack for
the double fault. The text below is the block as filed.
Title and slug are drafts.
Raised at calef's request, from the first of two findings in notes/ci.md. The second is the
sibling proposal
x86_64 names a kernel stack overflow the way aarch64 and riscv64 do.
Title and slug are drafts.
The finding
The double-fault safety net is documented, selected by the IDT, and never installed.
- The IDT gate for vector 8 selects IST slot 1:
let ist = if vector == 8 { IST_DOUBLE_FAULT } else { 0 };(kernel/src/arch/x86_64/exceptions.rs::initialize), withIST_DOUBLE_FAULT = 1(arch/x86_64/segments.rs). - The TSS has the seven entries (
ist: [u64; 7], a field of the task state segment insegments.rs) and zeroes them at init (newinsegments.rs). set_interrupt_stack(insegments.rs) is the only writer after init, andgrep -rn set_interrupt_stack kernel xtask cratesfinds no caller outside its own definition. The compiler agrees:notes/ci.mdon #1472 records thenever usedwarning as how this was found.
So a double fault today loads rsp from TSS.ist[0] == 0. The CPU cannot push its frame there,
and the result is a triple fault. The runner passes -no-reboot (NO_REBOOT in helpers/qemu-runner-x86_64.sh),
so under QEMU that is a silent exit with no report; on a real machine it is a reboot. The comment on
exceptions::initialize (its doc comment in exceptions.rs) states the intent exactly: a handler pushing
onto the same broken stack "triple-faults". The code does not deliver it.
The commonest trigger is the one the IST exists for: a kernel stack overflow whose exception frame push lands in the guard page (the 48-byte frame needs room the stack no longer has).
What the other two architectures do
Neither has a double fault, so neither can reset the machine for this. They fail differently and each is recorded:
- aarch64: a store into a guard page from the vector's own
SAVE_CONTEXTre-enters the same vector withspanother 272 bytes lower, repeatedly, until a frame fits in the slot below (kernel/src/stack.rs, doc onwarn_if_guard_page, "aarch64 has no double fault"). - riscv64: the entry stub does
addi sp, sp, -288and then stores (trap_entryinkernel/src/arch/riscv64/trap.s). I read that it can fault the same way; I did not run it, andkernel/src/interrupt_stack.rs's BUGS entry says an overflow whose first fault is the vector's own frame store "still cascades" on the ports that have the interrupt stack.
Both ports eventually print. x86_64 resets. That is the parity gap this closes (ยง19 (architectural parity is a tenet)).
Proposal
- Allocate one stack per core for the double fault, in its own region with an unmapped guard page
below it. It must not be the interrupt stack (
interrupt_stack.rs):set_interrupt_stack's Safety contract (insegments.rs) forbids two vectors sharing an IST stack, and a double fault taken while the interrupt-stack handler runs is exactly that case. - Call
set_interrupt_stack(IST_DOUBLE_FAULT, top)on every core, aftersegments::initializehas loaded that core's TSS (set_interrupt_stackindexes bycpu::id()). - Give vector 8 its own body that prints a fault report from that stack and halts. It prints the
frame (
rip,rsp,cs,ss,rflags; the error code is architecturally zero) and does not return. The report is deliberately minimal and takes no lock and no allocator. - Exempt vector 8 from
x86_trap_dispatch's interrupt-stack move, the way NMI is exempted (exceptions.rs::x86_trap_dispatch):interrupt_stack.rs::top_for_trapwould otherwise findrspoutside the interrupt-stack region and move the handler off the IST stack onto a different one. This is read from the code, not measured.
The guard-page naming (is the faulting rsp or address in a kernel stack's guard page, and whose)
belongs to the sibling proposal and is what makes this report useful rather than merely present.
Proof plan
- A kernel test that deliberately overflows a kernel stack on x86_64 under QEMU and must reach the
double-fault report. The runner already passes
-no-reboot, so a regression shows as an exit with no report line, which the test treats as failure. The harness piece is open: I found no existing expected-fatal-exit test (grepforshould_panic/expect_panicinkernel/src,xtask/srcandsystem_testsfound none), so the lane must say how a test passes by observing a fatal report. - Host-side: a test that the stack top handed to
set_interrupt_stackis per-core, distinct frominterrupt_stack::span(id), and 16-byte aligned. Pure arithmetic, so it belongs in a crate or a#[cfg(test)]module. - The
never usedwarning onset_interrupt_stackis the tripwire that found this; wiring the call ends it, so no allowance is added.
Prior art outside the tree
Read from source on 2026-10-03 (UTC):
- Linux,
arch/x86/kernel/cpu/common.c:tss->x86_tss.ist[IST_INDEX_DF] = __this_cpu_ist_top_va(DF);per CPU, andarch/x86/include/asm/cpu_entry_area.hlays out a separateDFexception stack with aDF_stack_guardbeside it, one per CPU.exc_double_faultinarch/x86/kernel/traps.creadsCR2, checks it against the guard-page info and callshandle_stack_overflow, then falls through toPANIC: double fault. Linux therefore does both halves this pair proposes, in one handler. - blog_os (phil-opp),
src/gdt.rsandsrc/interrupts.rsat tagpost-06: a statically allocated4096 * 5byte stack stored ininterrupt_stack_table[0]and selected with.set_stack_index(DOUBLE_FAULT_IST_INDEX). Note it has no guard page below that stack, and one static stack serves every core, which is fine for one core and not for this kernel.
Cost, risk, reversibility
- Cost: one small per-core region (blog_os uses 20 KiB, so that is a ceiling to measure against) and about 80 lines. This is an estimate, not a diff.
- Risk: low. The handler runs only after the machine was about to reset anyway, so a mistake in it
cannot make a working boot worse. The one live-path edit is the
x86_trap_dispatchexemption. - Reversibility: fully; all of it is code in
arch/x86_64/, and no wire format, name or system call is touched. The new region's linker symbol is a provisional name. - Would we choose this if both options cost the same? Yes. The alternative, leaving it, is the one case on this port where the kernel's own comment promises a report and delivers a reset.
What it unblocks
The sibling proposal's most common case. A kernel stack overflow with rsp near the bottom reaches
the double fault before it can reach the page-fault handler, so its report is only seen through this
stack.
Index row
x86_64's IDT gate for vector 8 selects IST slot 1, but the TSS entry is zero and never installed. Proposed: give the double fault a stack of its own so the safety net exists.