From 7019883a357235e877c653eec5d103ca5c499014 Mon Sep 17 00:00:00 2001 From: Marc Zyngier Date: Sat, 11 Jun 2022 11:50:23 +0100 Subject: [PATCH] ANDROID: KVM: arm64: Add vcpu flag copy primitive Contrary to vanilla KVM, pKVM not only deals with flags in a vcpu, but also synchronises them across host and hypervisor views of the same vcpu. Most of the time, this is about copying flags from one vcpu structure to another, so let's offer a primitive that does this. Signed-off-by: Marc Zyngier Signed-off-by: Will Deacon Bug: 233587962 Change-Id: Icd67b617c1cd69706ccd99739756458864b422bb --- arch/arm64/include/asm/kvm_host.h | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/arch/arm64/include/asm/kvm_host.h b/arch/arm64/include/asm/kvm_host.h index c8dd8d09b9eb..3026877e105e 100644 --- a/arch/arm64/include/asm/kvm_host.h +++ b/arch/arm64/include/asm/kvm_host.h @@ -547,9 +547,25 @@ struct kvm_vcpu_arch { *fset &= ~(m); \ } while (0) +#define __vcpu_copy_flag(vt, vs, flagset, f, m) \ + do { \ + typeof(vs->arch.flagset) tmp, val; \ + \ + __build_check_flag(vs, flagset, f, m); \ + \ + val = READ_ONCE(vs->arch.flagset); \ + val &= (m); \ + tmp = READ_ONCE(vt->arch.flagset); \ + tmp &= ~(m); \ + tmp |= val; \ + WRITE_ONCE(vt->arch.flagset, tmp); \ + } while (0) + + #define vcpu_get_flag(v, ...) __vcpu_get_flag((v), __VA_ARGS__) #define vcpu_set_flag(v, ...) __vcpu_set_flag((v), __VA_ARGS__) #define vcpu_clear_flag(v, ...) __vcpu_clear_flag((v), __VA_ARGS__) +#define vcpu_copy_flag(vt, vs,...) __vcpu_copy_flag((vt), (vs), __VA_ARGS__) /* SVE exposed to guest */ #define GUEST_HAS_SVE __vcpu_single_flag(cflags, BIT(0))