Skip to contentSkip to conversation

xen: Send spinlock IPI to all waiters

PATCH In review Stefan Bader 4 participants 8 messages Feb 15, 2013

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 xen: Send spinlock IPI to all waiters

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

Quoted 1 line

From 7e042a253b06da96409a0e059744c217f396a17f Mon 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 waiters

There 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 a spin_lock_irqsave in softirq context, interrupts will be re-enabled for the duration of the poll_irq hypercall 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 still on_cpu, so try_to_wake_up goes 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.

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.

---
 arch/x86/xen/spinlock.c |    1 -
 1 file changed, 1 deletion(-)
arch/x86/xen/spinlock.c +0 -1
index 83e866d..f7a080e 100644
@@ -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;
 		}
 	}
 }
Signature · 1 line
1.7.9.5
#1 lore raw

arch/x86/xen/spinlock.c static noinline void xen_spin_unlock_slow(struct xen_spinlock *xl) · line 331

Quoted 9 lines · Stefan Bader
arch/x86/xen/spinlock.c +0 -1
index 83e866d..f7a080e 100644
@@ -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;

It would be more efficient to build a mask and use xen_send_IPI_mask().

Ian.

#2 lore raw
Quoted 8 lines
Quoted 1 line
Quoted 1 line · Ian Campbell

arch/x86/xen/spinlock.c static noinline void xen_spin_unlock_slow(struct

Quoted 5 lines · Stefan Bader
arch/x86/xen/spinlock.c +0 -0
index 83e866d..f7a080e 100644
@@ -328,7 +328,6 @@ static noinline void xen_spin_unlock_slow(struct 

xen_spinlock *xl)

Quoted 6 lines

arch/x86/xen/spinlock.c static noinline void xen_spin_unlock_slow(struct xen_spinlock *xl) · line 331

Quoted 4 lines
arch/x86/xen/spinlock.c +0 -1
 		if (per_cpu(lock_spinners, cpu) == xl) {
 			ADD_STATS(released_slow_kicked, 1);
 			xen_send_IPI_one(cpu, XEN_SPIN_UNLOCK_VECTOR);
-			break;

It would be more efficient to build a mask and use xen_send_IPI_mask().

In order for __xen_send_IPI_mask() to then take the list apart again and call xen_send_IPI_one()? There's no batching implemented currently...

Jan

#3 lore raw
Quoted 15 lines · Jan Beulich
Quoted 8 lines
Quoted 1 line
Quoted 1 line · Ian Campbell

arch/x86/xen/spinlock.c static noinline void xen_spin_unlock_slow(struct

Quoted 5 lines · Stefan Bader
arch/x86/xen/spinlock.c +0 -0
index 83e866d..f7a080e 100644
@@ -328,7 +328,6 @@ static noinline void xen_spin_unlock_slow(struct 

xen_spinlock *xl)

Quoted 6 lines

arch/x86/xen/spinlock.c static noinline void xen_spin_unlock_slow(struct xen_spinlock *xl) · line 331

Quoted 4 lines
arch/x86/xen/spinlock.c +0 -1
 		if (per_cpu(lock_spinners, cpu) == xl) {
 			ADD_STATS(released_slow_kicked, 1);
 			xen_send_IPI_one(cpu, XEN_SPIN_UNLOCK_VECTOR);
-			break;

It would be more efficient to build a mask and use xen_send_IPI_mask().

Quoted 3 lines

In order for __xen_send_IPI_mask() to then take the list apart again and call xen_send_IPI_one()? There's no batching implemented currently...

Oh, I simply assumed it must obviously do that!

Ian.

#4 lore raw
Quoted 16 lines · Ian Campbell
Quoted 15 lines · Jan Beulich
Quoted 14 lines
Quoted 1 line
Quoted 1 line · Ian Campbell

arch/x86/xen/spinlock.c static noinline void xen_spin_unlock_slow(struct

Quoted 5 lines · Stefan Bader
arch/x86/xen/spinlock.c +0 -0
index 83e866d..f7a080e 100644
@@ -328,7 +328,6 @@ static noinline void xen_spin_unlock_slow(struct 

xen_spinlock *xl)

arch/x86/xen/spinlock.c static noinline void xen_spin_unlock_slow(struct xen_spinlock *xl) · line 331

Quoted 4 lines
arch/x86/xen/spinlock.c +0 -1
 		if (per_cpu(lock_spinners, cpu) == xl) {
 			ADD_STATS(released_slow_kicked, 1);
 			xen_send_IPI_one(cpu, XEN_SPIN_UNLOCK_VECTOR);
-			break;

It would be more efficient to build a mask and use xen_send_IPI_mask().

Quoted 5 lines
Quoted 3 lines

In order for __xen_send_IPI_mask() to then take the list apart again and call xen_send_IPI_one()? There's no batching implemented currently...

Oh, I simply assumed it must obviously do that!

Perhaps if it was done via a multicall? We could batch then things up. But I recall you saying that for homogeneous calls it is silly to use multicalls.

Quoted 3 lines

Ian.

#5 lore raw
Quoted 18 lines
Quoted 1 line
Quoted 1 line · Konrad Rzeszutek Wilk
Quoted 16 lines · Ian Campbell
Quoted 15 lines · Jan Beulich
Quoted 14 lines
Quoted 1 line
Quoted 1 line · Ian Campbell

arch/x86/xen/spinlock.c static noinline void xen_spin_unlock_slow(struct

Quoted 5 lines · Stefan Bader
arch/x86/xen/spinlock.c +0 -0
index 83e866d..f7a080e 100644
@@ -328,7 +328,6 @@ static noinline void xen_spin_unlock_slow(struct 

xen_spinlock *xl)

arch/x86/xen/spinlock.c static noinline void xen_spin_unlock_slow(struct xen_spinlock *xl) · line 331

Quoted 4 lines
arch/x86/xen/spinlock.c +0 -1
 		if (per_cpu(lock_spinners, cpu) == xl) {
 			ADD_STATS(released_slow_kicked, 1);
 			xen_send_IPI_one(cpu, XEN_SPIN_UNLOCK_VECTOR);
-			break;

It would be more efficient to build a mask and use xen_send_IPI_mask().

Quoted 8 lines
Quoted 5 lines
Quoted 3 lines

In order for __xen_send_IPI_mask() to then take the list apart again and call xen_send_IPI_one()? There's no batching implemented currently...

Oh, I simply assumed it must obviously do that!

Perhaps if it was done via a multicall? We could batch then things up. But I recall you saying that for homogeneous calls it is silly to use multicalls.

Aren't you mixing this up with it being pointless to use multicalls for things that already allow for batching, like grant table ops?

Jan

#6 lore raw
Quoted 22 lines · Jan Beulich
Quoted 22 lines
Quoted 1 line
Quoted 1 line · Konrad Rzeszutek Wilk
Quoted 20 lines · Ian Campbell
Quoted 18 lines · Jan Beulich
Quoted 8 lines
Quoted 1 line
Quoted 1 line · Ian Campbell

arch/x86/xen/spinlock.c static noinline void xen_spin_unlock_slow(struct

Quoted 5 lines · Stefan Bader
arch/x86/xen/spinlock.c +0 -0
index 83e866d..f7a080e 100644
@@ -328,7 +328,6 @@ static noinline void xen_spin_unlock_slow(struct 

xen_spinlock *xl)

Quoted 6 lines

arch/x86/xen/spinlock.c static noinline void xen_spin_unlock_slow(struct xen_spinlock *xl) · line 331

Quoted 4 lines
arch/x86/xen/spinlock.c +0 -1
 		if (per_cpu(lock_spinners, cpu) == xl) {
 			ADD_STATS(released_slow_kicked, 1);
 			xen_send_IPI_one(cpu, XEN_SPIN_UNLOCK_VECTOR);
-			break;

It would be more efficient to build a mask and use xen_send_IPI_mask().

In order for __xen_send_IPI_mask() to then take the list apart again and call xen_send_IPI_one()? There's no batching implemented currently...

Quoted 7 lines
Quoted 4 lines
Quoted 1 line

Oh, I simply assumed it must obviously do that!

Perhaps if it was done via a multicall? We could batch then things up. But I recall you saying that for homogeneous calls it is silly to use multicalls.

Aren't you mixing this up with it being pointless to use multicalls for things that already allow for batching, like grant table ops?

Right, it is only silly to use multicalls for homogeneous calls which already natively support batching.

Ian.

#7 lore raw
In reply to Stefan Bader
Quoted 21 lines · 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

Quoted 1 line

From 7e042a253b06da96409a0e059744c217f396a17f Mon 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 waiters

There 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):

Quoted 15 lines

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 a spin_lock_irqsave in softirq context, interrupts will be re-enabled for the duration of the poll_irq hypercall 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 still on_cpu, so try_to_wake_up goes 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.

Just for completness:

5. The 3) (so CPU n-1) sits in its tight loop and never exits as nothing ever interrupted it.

Quoted 35 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.

---
 arch/x86/xen/spinlock.c |    1 -
 1 file changed, 1 deletion(-)
arch/x86/xen/spinlock.c +0 -1
index 83e866d..f7a080e 100644
@@ -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;
 		}
 	}
 }
Signature · 7 lines
1.7.9.5


_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel