Issue #3475 has been updated by tuxillo.

File cpustop03-xinval.diff added
Status changed from New to In Progress

I tested cpustop03.patch on master d23da7dd7d in an 8-vCPU QEMU guest (nvmm) 
under tlbchurn.c, with the same tests as E1-3 above and no dump change. It 
builds without warnings.

It defers the stop only when intr_nesting_level is set, so a cpu answering a 
shootdown in Xinvltlb is no longer stopped there. The originator isn't covered: 
pmap_inval_smp() and pmap_inval_smp_cmpset() run smp_invlpg() -> 
smp_inval_intr() from thread context, with interrupts enabled in its loop and 
intr_nesting_level 0, so Xcpustop stops it halfway through its own command. Its 
targets wait for it inside Xinvltlb and refuse every reissue, so stop_cpus() 
never returns. In the guest, stop/restart rounds with no shootdown hung in 
round 0: cpu 1 waited in Xinvltlb for stopped cpu 3 ("cpus=1->3 mode=1" every 
second) while cpu 0 reissued in stop_cpus(). ddb could not be entered: the same 
deadlock, with cpu 6 waiting on cpu 2. One of five panic dumps stalled in 
smp_invltlb() and gave up after 60 s, as on master.

The attached cpustop03-xinval.diff also refuses while gd_xinvaltlb is set 
(exported to assembly as in E1). It also removes the @while 
(CPUMASK_CMPMASKNEQ(mask, map));@ after the @for (;;)@ loop in stop_cpus(): 
that is a separate empty loop, so after the "Unable to stop some cpus" break it 
spins forever (@cmp %r12,%rbx; jne@ to itself in the built kernel). With both, 
5000 stop/restart rounds passed with and without smp_invltlb() while stopped 
(max 20 ms, no warnings), ddb continue came back 20 of 20 times and 6 of 6 
panic dumps completed with no TLB warnings. That covers what E1-3 did without 
changing what a stopped cpu does.

Still open with both: a cpu parked in Xcpustop has intr_nesting_level 1. A 
second stop_cpus() while cpus are stopped makes them refuse, and the 
started_cpus bit they set restarts them. With debug.debugger_on_panic=0, typing 
panic at db> left the panicking cpu in stop_cpus() for good while the others 
ran (one went back to user mode, faulted and entered ddb again). On master the 
same test gets to the dump. Leaving cpus already in stopped_cpus out of 
stop_cpus()'s map might avoid it; I haven't tested that.

The give-up in stop_cpus() comes after 100000 reissues, about 5e10 pause 
instructions in total. A TSC deadline would be easier to reason about.

----------------------------------------
Bug #3475: x86_64: a crash dump can stall in smp_invltlb() and never finish
http://bugs.dragonflybsd.org/issues/3475#change-14982

* Author: tuxillo
* Status: In Progress
* Priority: Normal
* Target version: 6.6
* Start date: 2026-11-21
----------------------------------------
As of master e2619a112f, a crash dump on x86_64 can stop making progress and 
never finish. The minidump (blk_write() in minidump_machdep.c) and the full 
dump (cb_dumpdata() in dump_machdep.c) both call smp_invltlb() after mapping 
each chunk into crashdumpmap. The other cpus are stopped for the panic, and 
when one of them doesn't answer the IPI, smp_invltlb() waits invlpg_timeout 
seconds (10, or 60 in a VM), prints "smp_invltlb: giving up", and the next 
chunk waits again. In a QEMU guest that was a minute per chunk, so a 570 MB 
dump would have taken more than a day.

The cross-cpu flush isn't needed: pmap_kenter_quick() already does invlpg on 
the current cpu, and only the dumping cpu reads crashdumpmap. The calls came in 
with fb8345e665 (2011) to replace pmap_kenter()'s IPI-queue invalidation. 
FreeBSD's amd64 dump code doesn't flush there at all.

The attached patch flushes only the dumping cpu (cpu_invltlb()) in both places, 
and fixes the pmap_kenter_temporary() comment that told callers to use 
smp_invltlb().

To test it I panicked with sysctl debug.panic=1 while other processes kept the 
cpus busy with TLB shootdowns. In a 4-vCPU QEMU guest, 2 of 6 minidumps stalled 
before the patch and 10 of 10 completed after it. On a 12-thread machine with 
32 GB, with the attached tlbchurn.c as the load, 5 of 5 minidumps and 3 of 3 
full dumps completed with the patch; I didn't run an unpatched kernel there. In 
two of those minidumps another cpu spent the whole dump in smp_inval_intr() 
waiting for a cpu that never answered, which is what the old code would have 
waited on.

>From reading the code, the cpu that never answers probably took the stop IPI 
>while inside smp_inval_intr() and parked there. That's a separate problem, and 
>this patch doesn't touch it.

---Files--------------------------------
tlbchurn.c (3.64 KB)
cpustop-complete.diff (1.77 KB)
cpustop-xinvltlb.diff (3.68 KB)
cpustop03-xinval.diff (2.42 KB)


-- 
You have received this notification because you have either subscribed to it, 
or are involved in it.
To change your notification preferences, please click here: 
http://bugs.dragonflybsd.org/my/account

Reply via email to