From 6a8b1d493466c545e2fa0400562d986a38112dc4 Mon Sep 17 00:00:00 2001 From: Fuad Tabba Date: Mon, 13 Mar 2023 15:00:56 +0000 Subject: [PATCH] ANDROID: KVM: arm64: Allocate memory at hyp for host sve state Allocate memory and donate it to hyp at setup time for tracking the host sve state at hyp in protected mode. This memory is used in the subsequent patch. Signed-off-by: Fuad Tabba Bug: 267291591 Change-Id: If07eec9ea9c7b216d02e2d1ea69bd62d99f08081 --- arch/arm64/include/asm/kvm_pkvm.h | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/arch/arm64/include/asm/kvm_pkvm.h b/arch/arm64/include/asm/kvm_pkvm.h index 983997757037..9e63160e6519 100644 --- a/arch/arm64/include/asm/kvm_pkvm.h +++ b/arch/arm64/include/asm/kvm_pkvm.h @@ -13,6 +13,23 @@ #include #include +/* + * Stores the sve state for the host in protected mode. + */ +struct kvm_host_sve_state { + u64 zcr_el1; + + /* + * Ordering is important since __sve_save_state/__sve_restore_state + * relies on it. + */ + u32 fpsr; + u32 fpcr; + + /* Must be SVE_VQ_BYTES (128 bit) aligned. */ + char sve_regs[]; +}; + /* Maximum number of VMs that can co-exist under pKVM. */ #define KVM_MAX_PVMS 255 @@ -385,10 +402,19 @@ static inline unsigned long hyp_ffa_proxy_pages(void) return (2 * KVM_FFA_MBOX_NR_PAGES) + DIV_ROUND_UP(desc_max, PAGE_SIZE); } +static inline size_t pkvm_host_fp_state_size(void) +{ + if (system_supports_sve()) + return size_add(sizeof(struct kvm_host_sve_state), + SVE_SIG_REGS_SIZE(sve_vq_from_vl(kvm_host_sve_max_vl))); + else + return sizeof(struct user_fpsimd_state); +} + static inline unsigned long hyp_host_fp_pages(unsigned long nr_cpus) { - return PAGE_ALIGN(nr_cpus * sizeof(struct user_fpsimd_state)) >> - PAGE_SHIFT; + return PAGE_ALIGN(size_mul(nr_cpus, pkvm_host_fp_state_size())) >> + PAGE_SHIFT; } #endif /* __ARM64_KVM_PKVM_H__ */