]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
KVM: arm64: Introduce flag shadowing TIF_FOREIGN_FPSTATE
authorMarc Zyngier <maz@kernel.org>
Thu, 21 Oct 2021 13:10:35 +0000 (14:10 +0100)
committerMarc Zyngier <maz@kernel.org>
Mon, 22 Nov 2021 16:01:39 +0000 (16:01 +0000)
We currently have to maintain a mapping the thread_info structure
at EL2 in order to be able to check the TIF_FOREIGN_FPSTATE flag.

In order to eventually get rid of this, start with a vcpu flag that
shadows the thread flag on each entry into the hypervisor.

Reviewed-by: Mark Brown <broonie@kernel.org>
Signed-off-by: Marc Zyngier <maz@kernel.org>
arch/arm64/include/asm/kvm_host.h
arch/arm64/kvm/arm.c
arch/arm64/kvm/fpsimd.c
arch/arm64/kvm/hyp/include/hyp/switch.h

index 3ccfc3e3e436690625380a7f980033ac943b2786..9f1703ebae1536d1997a4de8828788829f56a43f 100644 (file)
@@ -441,6 +441,7 @@ struct kvm_vcpu_arch {
 
 #define KVM_ARM64_DEBUG_STATE_SAVE_SPE (1 << 12) /* Save SPE context if active  */
 #define KVM_ARM64_DEBUG_STATE_SAVE_TRBE        (1 << 13) /* Save TRBE context if active  */
+#define KVM_ARM64_FP_FOREIGN_FPSTATE   (1 << 14)
 
 #define KVM_GUESTDBG_VALID_MASK (KVM_GUESTDBG_ENABLE | \
                                 KVM_GUESTDBG_USE_SW_BP | \
@@ -736,6 +737,7 @@ long kvm_vm_ioctl_mte_copy_tags(struct kvm *kvm,
 /* Guest/host FPSIMD coordination helpers */
 int kvm_arch_vcpu_run_map_fp(struct kvm_vcpu *vcpu);
 void kvm_arch_vcpu_load_fp(struct kvm_vcpu *vcpu);
+void kvm_arch_vcpu_ctxflush_fp(struct kvm_vcpu *vcpu);
 void kvm_arch_vcpu_ctxsync_fp(struct kvm_vcpu *vcpu);
 void kvm_arch_vcpu_put_fp(struct kvm_vcpu *vcpu);
 
index e4727dc771bf3a75dbce8384f23313cf623c7c36..d1b93dc8d63900e47548674c7f38180832c9adcd 100644 (file)
@@ -849,6 +849,7 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu)
                }
 
                kvm_arm_setup_debug(vcpu);
+               kvm_arch_vcpu_ctxflush_fp(vcpu);
 
                /**************************************************************
                 * Enter the guest
index 2d15e1d6e2141b25edf97a5426a139353eacee48..a18b9c1744d5848968da1b286b4c116b884cf310 100644 (file)
@@ -79,6 +79,14 @@ void kvm_arch_vcpu_load_fp(struct kvm_vcpu *vcpu)
                vcpu->arch.flags |= KVM_ARM64_HOST_SVE_ENABLED;
 }
 
+void kvm_arch_vcpu_ctxflush_fp(struct kvm_vcpu *vcpu)
+{
+       if (test_thread_flag(TIF_FOREIGN_FPSTATE))
+               vcpu->arch.flags |= KVM_ARM64_FP_FOREIGN_FPSTATE;
+       else
+               vcpu->arch.flags &= ~KVM_ARM64_FP_FOREIGN_FPSTATE;
+}
+
 /*
  * If the guest FPSIMD state was loaded, update the host's context
  * tracking data mark the CPU FPSIMD regs as dirty and belonging to vcpu
index e65c2956b881e249f030320e59a67c2a29e5d29d..a243a2a821319a53d357516df14ac8f83c45f515 100644 (file)
@@ -49,7 +49,7 @@ static inline bool update_fp_enabled(struct kvm_vcpu *vcpu)
         * trap the accesses.
         */
        if (!system_supports_fpsimd() ||
-           vcpu->arch.host_thread_info->flags & _TIF_FOREIGN_FPSTATE)
+           vcpu->arch.flags & KVM_ARM64_FP_FOREIGN_FPSTATE)
                vcpu->arch.flags &= ~(KVM_ARM64_FP_ENABLED |
                                      KVM_ARM64_FP_HOST);