Repository navigation
avz: scheduler lock with a single holder, and the boot freeze it could cause - #377
Merged
Merged
Conversation
The paths of a domain's scheduler (its wake, its sleep, its unparking, a virq set pending, the scheduling decision itself) took the scheduler's lock unless it was held, taking "held" for "held by this CPU": a path entered with the lock held from an outer one on the same CPU must not take it again. But the lock is also taken by another CPU: the agency pauses a living capsule for an intermediate Delta snapshot from whichever of its CPUs the read runs on, and wakes it after, while the capsule CPU runs its scheduler every 30 ms as long as two capsules are runnable. When the two met, each went on without the lock, and whichever released it first released the other's: the capsule CPU could pick the capsule being paused after the pause had taken it off the runnable set, and keep it running with no scheduling timer, since one domain was left runnable, and no further event, since the agency CPU that would send one waited, with its interrupts off, for the capsule to leave the CPU. That CPU is the one the agency's interrupts go to: the agency fell silent whole, and the capsules with it. Each CPU now records the scheduler lock it holds: sched_lock() takes the lock unless this CPU holds it, and says so for sched_unlock(), which releases nothing the CPU does not hold; the context switch releases what the scheduling decision took or inherited. A CPU that finds the lock held by another waits for it, and counts the wait (sched_lock_contended()). The wait for a domain to leave its CPU is unchanged, and reports once, after 2 s, what each CPU is at, so that a stall of this kind, if any remains, says where it is. Seen once in 776 Delta snapshots over the campaigns: the mission's host in s4-delta-s8 (reports/eval-s4) fell silent 520 ms after the staging's Full was acknowledged, when the first Delta was read, with no snapshot line on the console and no exception; the earlier s2a event, a data abort in the scan under a concurrent reset, was another defect, closed by 5af2c78774.
…uler's lock comes Sending a virq took the scheduler's lock, then the event lock; sending an event over a channel takes the event lock, then, as the pending bit is set and the domain unparked, the scheduler's lock. Two orders of the same two locks: the capsule CPU sending a capsule its timer tick met an agency CPU notifying that capsule's ring, each holding the lock the other waited for. Before 1df511970b the second taker of the scheduler's lock went on without it, so the inversion never blocked; from 1df511970b on it waits, and the agency CPU hung in the hypercall with its interrupts off, so that the node's Linux reported the CPU stalled and the agency fell silent. The virq is now sent under the event lock alone: setting the event pending unparks the domain under the scheduler's lock itself, so the one order is the event lock first, the scheduler's lock after, on every path; the scheduler's lock covers only timer and softirq locks beneath it. Seen in every run of the first validation gate of 1df511970b (h1-*): the agency CPUs of most drones stalled within the first minutes, in Full runs as in Delta ones.
…ts off sched_lock() took the lock and then wrote the per-CPU mark of its holder; sched_unlock() cleared the mark and then released the lock. An interrupt between the two steps ran the scheduling softirq, which read the mark, concluded that the lock was not its own and waited for it on the CPU that held it: the CPU spun forever with interrupts masked. Seen at boot: the agency never printed after "unpausing the agency domain". A stopped guest showed CPU0 in spin_lock() on the agency scheduler's lock, called from domain_schedule() <- do_softirq() <- irq_handle(), the interrupt taken at the first instruction of spin_unlock() in sched_unlock() called by vcpu_wake() <- domain_unpause(); the lock word was 1 and CPU0's mark NULL. The other CPUs were idle. Frequency: about 1 guest boot in 4200 over the campaigns, once in 132 boots in a loop of bare boots. Both steps are now done with the local interrupts masked; waiting for the lock still happens with interrupts as the caller had them. Check: 400 loops of 11 bare boots (4400 guest boots) with the fix, no freeze. Limits: the same window existed for any caller with interrupts enabled, not only at boot; no such freeze was identified in a run. The check bounds the frequency and cannot prove absence: at the campaigns' rate of 1 in 4200, 4400 clean boots would occur by chance about one time in three; at the loop's own rate before the fix (one freeze in 132 boots, a single sample) they would not.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Three AVZ scheduler commits brought from soo-ng, where they were found and validated, plus the CHANGELOG line in the v6.4.0 entry.
sched_lock()/sched_unlock()).spin_lock()fromdomain_schedule <- do_softirq <- irq_handle, interrupted at the first instruction ofspin_unlock()insched_unlock(); lock word 1, CPU0's mark NULL.Checks
virt64_avz_soo_defconfigandvirt64_avz_defconfig, no warning in the touched files.Limits