Skip to content

Commit af9a0e2

Browse files
author
Marc Zyngier
committed
KVM: arm64: Introduce flag shadowing TIF_FOREIGN_FPSTATE
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 <[email protected]> Signed-off-by: Marc Zyngier <[email protected]>
1 parent e66425f commit af9a0e2

File tree

4 files changed

+12
-1
lines changed

4 files changed

+12
-1
lines changed

arch/arm64/include/asm/kvm_host.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -441,6 +441,7 @@ struct kvm_vcpu_arch {
441441

442442
#define KVM_ARM64_DEBUG_STATE_SAVE_SPE (1 << 12) /* Save SPE context if active */
443443
#define KVM_ARM64_DEBUG_STATE_SAVE_TRBE (1 << 13) /* Save TRBE context if active */
444+
#define KVM_ARM64_FP_FOREIGN_FPSTATE (1 << 14)
444445

445446
#define KVM_GUESTDBG_VALID_MASK (KVM_GUESTDBG_ENABLE | \
446447
KVM_GUESTDBG_USE_SW_BP | \
@@ -736,6 +737,7 @@ long kvm_vm_ioctl_mte_copy_tags(struct kvm *kvm,
736737
/* Guest/host FPSIMD coordination helpers */
737738
int kvm_arch_vcpu_run_map_fp(struct kvm_vcpu *vcpu);
738739
void kvm_arch_vcpu_load_fp(struct kvm_vcpu *vcpu);
740+
void kvm_arch_vcpu_ctxflush_fp(struct kvm_vcpu *vcpu);
739741
void kvm_arch_vcpu_ctxsync_fp(struct kvm_vcpu *vcpu);
740742
void kvm_arch_vcpu_put_fp(struct kvm_vcpu *vcpu);
741743

arch/arm64/kvm/arm.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -849,6 +849,7 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu)
849849
}
850850

851851
kvm_arm_setup_debug(vcpu);
852+
kvm_arch_vcpu_ctxflush_fp(vcpu);
852853

853854
/**************************************************************
854855
* Enter the guest

arch/arm64/kvm/fpsimd.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,14 @@ void kvm_arch_vcpu_load_fp(struct kvm_vcpu *vcpu)
7979
vcpu->arch.flags |= KVM_ARM64_HOST_SVE_ENABLED;
8080
}
8181

82+
void kvm_arch_vcpu_ctxflush_fp(struct kvm_vcpu *vcpu)
83+
{
84+
if (test_thread_flag(TIF_FOREIGN_FPSTATE))
85+
vcpu->arch.flags |= KVM_ARM64_FP_FOREIGN_FPSTATE;
86+
else
87+
vcpu->arch.flags &= ~KVM_ARM64_FP_FOREIGN_FPSTATE;
88+
}
89+
8290
/*
8391
* If the guest FPSIMD state was loaded, update the host's context
8492
* tracking data mark the CPU FPSIMD regs as dirty and belonging to vcpu

arch/arm64/kvm/hyp/include/hyp/switch.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ static inline bool update_fp_enabled(struct kvm_vcpu *vcpu)
4949
* trap the accesses.
5050
*/
5151
if (!system_supports_fpsimd() ||
52-
vcpu->arch.host_thread_info->flags & _TIF_FOREIGN_FPSTATE)
52+
vcpu->arch.flags & KVM_ARM64_FP_FOREIGN_FPSTATE)
5353
vcpu->arch.flags &= ~(KVM_ARM64_FP_ENABLED |
5454
KVM_ARM64_FP_HOST);
5555

0 commit comments

Comments
 (0)