xen/rwlock: Add missing memory barrier in the unlock path of rwlock
authorJulien Grall <jgrall@amazon.com>
Tue, 14 Apr 2020 13:03:28 +0000 (15:03 +0200)
committerJan Beulich <jbeulich@suse.com>
Tue, 14 Apr 2020 13:03:28 +0000 (15:03 +0200)
commitd430e15e021b81f1f6c3e35d703a6f195a9b2e5c
treec02c474eb63c496c5b65b4487fa0249704984bfd
parent7900cb7c18b5ec5d379884166b0db35ebe3846e0
xen/rwlock: Add missing memory barrier in the unlock path of rwlock

The rwlock unlock paths are using atomic_sub() to release the lock.
However the implementation of atomic_sub() rightfully doesn't contain a
memory barrier. On Arm, this means a processor is allowed to re-order
the memory access with the preceeding access.

In other words, the unlock may be seen by another processor before all
the memory accesses within the "critical" section.

The rwlock paths already contains barrier indirectly, but they are not
very useful without the counterpart in the unlock paths.

The memory barriers are not necessary on x86 because loads/stores are
not re-ordered with lock instructions.

So add arch_lock_release_barrier() in the unlock paths that will only
add memory barrier on Arm.

Take the opportunity to document each lock paths explaining why a
barrier is not necessary.

This is XSA-314.

Signed-off-by: Julien Grall <jgrall@amazon.com>
Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
Acked-by: Jan Beulich <jbeulich@suse.com>
master commit: 6890a04072e664c25447a297fe663b45ecfd6398
master date: 2020-04-14 14:37:11 +0200
xen/include/xen/rwlock.h