Skip to content

Commit b4da918

Browse files
author
Marc Zyngier
committed
KVM: arm64: Move the handling of !FP outside of the fast path
We currently start by assuming that the host owns the FP unit at load time, then check again whether this is the case as we are about to run. Only at this point do we account for the fact that there is a (vanishingly small) chance that we're running on a system without a FPSIMD unit (yes, this is madness). We can actually move this FPSIMD check as early as load-time, and drop the check at run time. No intended change in behaviour. Suggested-by: Reiji Watanabe <[email protected]> Reviewed-by: Reiji Watanabe <[email protected]> Signed-off-by: Marc Zyngier <[email protected]>
1 parent 0fa4a31 commit b4da918

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

arch/arm64/kvm/arm.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,12 @@ int kvm_arch_vcpu_create(struct kvm_vcpu *vcpu)
328328

329329
vcpu->arch.mmu_page_cache.gfp_zero = __GFP_ZERO;
330330

331+
/*
332+
* Default value for the FP state, will be overloaded at load
333+
* time if we support FP (pretty likely)
334+
*/
335+
vcpu->arch.fp_state = FP_STATE_FREE;
336+
331337
/* Set up the timer */
332338
kvm_timer_vcpu_init(vcpu);
333339

arch/arm64/kvm/fpsimd.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,9 @@ void kvm_arch_vcpu_load_fp(struct kvm_vcpu *vcpu)
7777
BUG_ON(!current->mm);
7878
BUG_ON(test_thread_flag(TIF_SVE));
7979

80+
if (!system_supports_fpsimd())
81+
return;
82+
8083
vcpu->arch.fp_state = FP_STATE_HOST_OWNED;
8184

8285
vcpu_clear_flag(vcpu, HOST_SVE_ENABLED);
@@ -110,13 +113,10 @@ void kvm_arch_vcpu_load_fp(struct kvm_vcpu *vcpu)
110113
* FP while we were preemptible (such as off the back of an interrupt),
111114
* then neither the host nor the guest own the FP hardware (and it was the
112115
* responsibility of the code that used FP to save the existing state).
113-
*
114-
* Note that not supporting FP is basically the same thing as far as the
115-
* hypervisor is concerned (nothing to save).
116116
*/
117117
void kvm_arch_vcpu_ctxflush_fp(struct kvm_vcpu *vcpu)
118118
{
119-
if (!system_supports_fpsimd() || test_thread_flag(TIF_FOREIGN_FPSTATE))
119+
if (test_thread_flag(TIF_FOREIGN_FPSTATE))
120120
vcpu->arch.fp_state = FP_STATE_FREE;
121121
}
122122

0 commit comments

Comments
 (0)