xen/rwlock: Add missing memory barrier in the unlock path of rwlock
authorJulien Grall <jgrall@amazon.com>
Thu, 20 Feb 2020 20:54:40 +0000 (20:54 +0000)
committerJan Beulich <jbeulich@suse.com>
Tue, 14 Apr 2020 12:37:11 +0000 (14:37 +0200)
commit6890a04072e664c25447a297fe663b45ecfd6398
treee79a23d47326a7ca86b087ef751f1f171c6d6a2c
parent50ef9a3cb26e2f9383f6fdfbed361d8f174bae9f
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>
Acked-by: Jan Beulich <jbeulich@suse.com>
xen/include/xen/rwlock.h