xen: arm: clear the exclusive monitor on exception return
PATCH 1/1 xen: arm: clear the exclusive monitor on exception return
Otherwise context switching between two vcpus which are contending the same lock can result in a spurious success.
This is not required on ARMv8 since eret implicitly clears the monitor.
--- xen/arch/arm/arm32/entry.S | 1 + 1 files changed, 1 insertions(+), 0 deletions(-)
xen/arch/arm/arm32/entry.S +1 -0
@@ -117,6 +117,7 @@ ENTRY(return_to_hypervisor) msr SPSR_hyp, r11 pop {r0-r12} add sp, #(UREGS_SP_usr - UREGS_sp); /* SP, LR, SPSR, PC */ + clrex eret /*
Signature · 1 line
1.7.2.5
Quoted 6 lines · Ian Campbell
Otherwise context switching between two vcpus which are contending the same lock can result in a spurious success.
This is not required on ARMv8 since eret implicitly clears the monitor.
Signed-off-by Ian Campbell <[email protected]>
Quoted 18 lines
xen/arch/arm/arm32/entry.S | 1 + 1 files changed, 1 insertions(+), 0 deletions(-)xen/arch/arm/arm32/entry.S +1
-0@@ -117,6 +117,7 @@ ENTRY(return_to_hypervisor) msr SPSR_hyp, r11 pop {r0-r12} add sp, #(UREGS_SP_usr - UREGS_sp); /* SP, LR, SPSR, PC */ + clrex eret /*Signature · 1 line
1.7.2.5
Quoted 2 lines · Ian Campbell
Otherwise context switching between two vcpus which are contending the same lock can result in a spurious success.
Shouldn't this go in ctxt_swicth_to(), then? I think any use that Xen itself makes of the monitor should end with it cleared.
Tim.
Quoted 27 lines
This is not required on ARMv8 since eret implicitly clears the monitor.
Signed-off-by Ian Campbell <[email protected]>--- xen/arch/arm/arm32/entry.S | 1 + 1 files changed, 1 insertions(+), 0 deletions(-)xen/arch/arm/arm32/entry.S +1
-0@@ -117,6 +117,7 @@ ENTRY(return_to_hypervisor) msr SPSR_hyp, r11 pop {r0-r12} add sp, #(UREGS_SP_usr - UREGS_sp); /* SP, LR, SPSR, PC */ + clrex eret /*Signature · 7 lines
1.7.2.5 _______________________________________________ Xen-devel mailing list [email protected] http://lists.xen.org/xen-devel
Quoted 6 lines · Tim Deegan
Quoted 2 lines · Ian Campbell
Otherwise context switching between two vcpus which are contending the same lock can result in a spurious success.
Shouldn't this go in
ctxt_swicth_to(), then? I think any use that Xen itself makes of the monitor should end with it cleared.
Our atomic read/set which we stole^Winherited from Linux relies on this behaviour (interlocking with atomic_add_and_blah stuff).
/*
* On ARM, ordinary assignment (str instruction) doesn't clear the local
* strex/ldrex monitor on some implementations. The reason we can use it for
* atomic_set() is the clrex or dummy strex done on every exception return. */
As well as atomics our spin unlock (also inherited) is just a plain store.
If nothing else it makes v7 and v8 consistent since the clrex is implicit in the eret on v8.
Quoted 30 lines
Tim.
Quoted 27 lines
This is not required on ARMv8 since eret implicitly clears the monitor.
Signed-off-by Ian Campbell <[email protected]>--- xen/arch/arm/arm32/entry.S | 1 + 1 files changed, 1 insertions(+), 0 deletions(-)xen/arch/arm/arm32/entry.S +1
-0@@ -117,6 +117,7 @@ ENTRY(return_to_hypervisor) msr SPSR_hyp, r11 pop {r0-r12} add sp, #(UREGS_SP_usr - UREGS_sp); /* SP, LR, SPSR, PC */ + clrex eret /*Signature · 7 lines
1.7.2.5 _______________________________________________ Xen-devel mailing list [email protected] http://lists.xen.org/xen-devel
Quoted 8 lines · Ian Campbell
Quoted 6 lines · Tim Deegan
Quoted 2 lines · Ian Campbell
Otherwise context switching between two vcpus which are contending the same lock can result in a spurious success.
Shouldn't this go in
ctxt_swicth_to(), then? I think any use that Xen itself makes of the monitor should end with it cleared.
Quoted 7 lines
Our atomic read/set which we stole^Winherited from Linux relies on this behaviour (interlocking with
atomic_add_and_blahstuff).
/*
* On ARM, ordinary assignment (str instruction) doesn't clear the local
* strex/ldrex monitor on some implementations. The reason we can use it for
*atomic_set()is the clrex or dummy strex done on every exception return. */
Ah, OK. So, Ack, but if it's not already committed can you edit the commit message to refer to this?
Quoted 2 lines
As well as atomics our spin unlock (also inherited) is just a plain store.
Well, we already avoid having locks shared between interrupt/exception handlers and plain code, but I guess it can't hurt.
Tim.
Quoted 17 lines · Tim Deegan
Quoted 8 lines · Ian Campbell
Quoted 6 lines · Tim Deegan
Quoted 2 lines · Ian Campbell
Otherwise context switching between two vcpus which are contending the same lock can result in a spurious success.
Shouldn't this go in
ctxt_swicth_to(), then? I think any use that Xen itself makes of the monitor should end with it cleared.Quoted 7 lines
Our atomic read/set which we stole^Winherited from Linux relies on this behaviour (interlocking with
atomic_add_and_blahstuff).
/*
* On ARM, ordinary assignment (str instruction) doesn't clear the local
* strex/ldrex monitor on some implementations. The reason we can use it for
*atomic_set()is the clrex or dummy strex done on every exception return. */
Quoted 2 lines
Ah, OK. So, Ack, but if it's not already committed can you edit the commit message to refer to this?
Thanks and Yes Sure.
Quoted 5 lines
Quoted 2 lines
As well as atomics our spin unlock (also inherited) is just a plain store.
Well, we already avoid having locks shared between interrupt/exception handlers and plain code,
We do? Plain code can use the irqsave/restore variants if it wants to coexist with irq handlers which take the same locks, can't they? e.g. the gic lock is handled this way... If that's not valid then we might have a problem ;-)
Quoted 3 lines
but I guess it can't hurt.
Tim.
Quoted 5 lines · Ian Campbell
Quoted 4 lines · Tim Deegan
Quoted 2 lines · Ian Campbell
As well as atomics our spin unlock (also inherited) is just a plain store.
Quoted 7 lines
Quoted 2 lines
Well, we already avoid having locks shared between interrupt/exception handlers and plain code,
We do? Plain code can use the irqsave/restore variants if it wants to coexist with irq handlers which take the same locks, can't they? e.g. the gic lock is handled this way... If that's not valid then we might have a problem ;-)
Yes, but the irqsave variants are there explicitly to avoid the case where irq-disabled code touches a spinlock that plain code might be spinning on. I guess officially there's nothing stopping irq-disabled code from _unlocking_ a plain-code spinlock, so this covers that case. :)
Tim.
Quoted 17 lines · Tim Deegan
Quoted 8 lines · Ian Campbell
Quoted 6 lines · Tim Deegan
Quoted 2 lines · Ian Campbell
Otherwise context switching between two vcpus which are contending the same lock can result in a spurious success.
Shouldn't this go in
ctxt_swicth_to(), then? I think any use that Xen itself makes of the monitor should end with it cleared.Quoted 7 lines
Our atomic read/set which we stole^Winherited from Linux relies on this behaviour (interlocking with
atomic_add_and_blahstuff).
/*
* On ARM, ordinary assignment (str instruction) doesn't clear the local
* strex/ldrex monitor on some implementations. The reason we can use it for
*atomic_set()is the clrex or dummy strex done on every exception return. */
Quoted 2 lines
Ah, OK. So, Ack, but if it's not already committed can you edit the commit message to refer to this?
Applied, thanks. Commit message is now:
xen: arm: clear the exclusive monitor on exception return
Otherwise context switching between two vcpus which are contending the same lock can result in a spurious success.
Our spinlock and atomics code (which we get from Linux) rely on this behaviour because they use non-exclusive stores for single instruction operations (e.g. spin_unlock or atomic_set).
This is not required on ARMv8 since eret implicitly clears the monitor.