Skip to content

avz: scheduler lock with a single holder, and the boot freeze it could cause - #377

Merged
daniel-rossier merged 5 commits into
mainfrom
fix/avz-scheduler-lock
Nov 14, 2026
Merged

daniel-rossier merged 5 commits into
mainfrom
fix/avz-scheduler-lock

Conversation

@daniel-rossier

Copy link
Copy Markdown
Contributor

Three AVZ scheduler commits brought from soo-ng, where they were found and validated, plus the CHANGELOG line in the v6.4.0 entry.

  1. A scheduler's lock is held by one CPU, and the others wait for it. The paths used to skip the lock when it was already taken, whoever held it; a per-CPU mark now says whether this CPU holds it (sched_lock() / sched_unlock()).
  2. A virq is sent under the event lock alone. One lock order on every path: the event lock first, the scheduler's lock after.
  3. The lock and its holder mark change together, interrupts masked. An interrupt between the two steps ran the scheduling softirq, which did not recognise the lock as its own and waited for it on the CPU holding it. Seen as a freeze after "unpausing the agency domain": CPU0 in spin_lock() from domain_schedule <- do_softirq <- irq_handle, interrupted at the first instruction of spin_unlock() in sched_unlock(); lock word 1, CPU0's mark NULL.

Checks

  • The four files touched are identical to those of soo-ng.
  • AVZ builds for virt64_avz_soo_defconfig and virt64_avz_defconfig, no warning in the touched files.
  • In soo-ng: freeze seen about once in 4200 guest boots, once in 132 in a loop of bare boots; 4400 guest boots with the fix, none.

Limits

  • No boot was done with AVZ built from this tree: the validation is that of soo-ng, whose AVZ carries more (checkpoint, extended injector).
  • The boot loop bounds the frequency and cannot prove absence.
  • The messages of the first two commits name soo-ng commits and runs, unknown here.

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.
@daniel-rossier
daniel-rossier merged commit 69b543e into main Nov 14, 2026
6 checks passed
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.

1 participant