xen/bitops: Provide helpers to safely modify guest memory atomically
authorJulien Grall <julien.grall@arm.com>
Mon, 29 Apr 2019 14:05:26 +0000 (15:05 +0100)
committerJulien Grall <julien.grall@arm.com>
Fri, 14 Jun 2019 13:27:32 +0000 (14:27 +0100)
commit6a5f01a57a662565e6aa63fc9f3081fa69e54465
tree7a46f9f7a050a63faaf74d4da08156f5a0b6616b
parentcb8e0d28e8df97adc4ba2721f75824acdd3702b7
xen/bitops: Provide helpers to safely modify guest memory atomically

On Arm, exclusive load-store atomics should only be used between trusted
thread. As not all the guests are trusted, it may be possible to DoS Xen
when updating shared memory with guest atomically.

This patch adds a new set of helper that will update the guest memory
safely. For x86, it is already possible to use the current helpers
safely. So just wrap them.

For Arm, we will first attempt to update the guest memory with the loop
bounded by a maximum number of iterations. If it fails, we will pause the
domain and try again.

Note that this heuristics assumes that a page can only be shared between
Xen and one domain. Not Xen and multiple domain.

The maximum number of iterations is based on how many times a simple
load-store atomic operation can be executed in 1uS. The maximum value is
per-CPU to cater big.LITTLE and calculated when the CPU is booting. The
heuristic was randomly chosen and can be modified if impact too much
good-behaving guest.

Note, while test_bit does not requires to use atomic operation, a
wrapper for test_bit was added for completeness. In this case, the
domain stays constified to avoid major rework in the caller for the
time-being.

This is part of XSA-295.

Signed-of-by: Julien Grall <julien.grall@arm.com>
Acked-by: Jan Beulich <jbeulich@suse.com>
Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
xen/arch/arm/Makefile
xen/arch/arm/guest_atomics.c [new file with mode: 0644]
xen/include/asm-arm/guest_atomics.h [new file with mode: 0644]
xen/include/asm-x86/guest_atomics.h [new file with mode: 0644]