xen: Send spinlock IPI to all waiters
Jan Beulich
Acked-by(resending with proper list address)
Quoted 38 lines
Quoted 1 line
Quoted 1 line · Stefan Bader
Hopefully not mis-parsing Jan's last comments on the other thread, this would be the fix covering things until a better implementation is done.
This also prevents the hang on older kernels, where it could be re- produced reliably.-Stefan
From
7e042a253b06da96409a0e059744c217f396a17fMon Sep 17 00:00:00 2001
From: Stefan Bader <[email protected]>
Date: Fri, 15 Feb 2013 09:48:52 +0100
Subject: [PATCH] xen: Send spinlock IPI to all waitersThere is a loophole between Xen's current implementation of pv-spinlocks and the scheduler. This was triggerable through a testcase until v3.6 changed the TLB flushing code. The problem potentially is still there just not observable in the same way.
What could happen was (is):
1. CPU n tries to schedule task x away and goes into a slow wait for the runq lock of CPU n-# (must be one with a lower number).
2. CPU n-#, while processing softirqs, tries to balance domains and goes into a slow wait for its own runq lock (for updating some records). Since this is aspin_lock_irqsavein softirq context, interrupts will be re-enabled for the duration of thepoll_irqhypercall used by Xen.
3. Before the runq lock of CPU n-# is unlocked, CPU n-1 receives an interrupt (e.g. endio) and when processing the interrupt, tries to wake up task x. But that is in schedule and stillon_cpu, sotry_to_wake_upgoes into a tight loop.
4. The runq lock of CPU n-# gets unlocked, but the message only gets sent to the first waiter, which is CPU n-# and that is busily stuck.
Quoted 8 lines
To avoid this and since the unlocking code has no real sense of which waiter is best suited to grab the lock, just send the IPI to all of them. This causes the waiters to return from the hyper- call (those not interrupted at least) and do active spinlocking.
Signed-off-by Stefan Bader <[email protected]>
(but see below)
Quoted 1 line
(back to 3.0; earlier kernels shouldn't be affected)
Quoted 9 lines
--- arch/x86/xen/spinlock.c | 1 - 1 file changed, 1 deletion(-)arch/x86/xen/spinlock.c +0
-0
arch/x86/xen/spinlock.c static noinline void xen_spin_unlock_slow(struct · line 332
Quoted 5 lines
arch/x86/xen/spinlock.c +0
-1@@ -328,7 +328,6 @@ static noinline void xen_spin_unlock_slow(struct xen_spinlock *xl)if (per_cpu (lock_spinners, cpu) == xl) {ADD_STATS (released_slow_kicked,1 );xen_send_IPI_one (cpu,XEN_SPIN_UNLOCK_VECTOR ); -break ;
Of course that's the minimal fix. Would be nice if this could be done as a batch, since even if congestion on locks might be rare, it's specifically that case where the biggest gain from doing things quickly can be had.
But of course, as said earlier, switching to ticket locks should be the real goal.
Jan