Skip to content

Commit 51e09b5

Browse files
author
Marc Zyngier
committed
KVM: arm64: Exclude host_fpsimd_state pointer from kvm_vcpu_arch
As the name of the field indicates, host_fpsimd_state is strictly a host piece of data, and we reset this pointer on each PID change. So let's move it where it belongs, and set it at load-time. Although this is slightly more often, it is a well defined life-cycle which matches other pieces of data. Reviewed-by: Mark Brown <[email protected]> Signed-off-by: Marc Zyngier <[email protected]>
1 parent 4bacd72 commit 51e09b5

File tree

4 files changed

+3
-5
lines changed

4 files changed

+3
-5
lines changed

arch/arm64/include/asm/kvm_host.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -543,6 +543,7 @@ struct kvm_cpu_context {
543543
*/
544544
struct kvm_host_data {
545545
struct kvm_cpu_context host_ctxt;
546+
struct user_fpsimd_state *fpsimd_state; /* hyp VA */
546547

547548
/*
548549
* host_debug_state contains the host registers which are
@@ -662,7 +663,6 @@ struct kvm_vcpu_arch {
662663
struct kvm_guest_debug_arch vcpu_debug_state;
663664
struct kvm_guest_debug_arch external_debug_state;
664665

665-
struct user_fpsimd_state *host_fpsimd_state; /* hyp VA */
666666
struct task_struct *parent_task;
667667

668668
/* VGIC state */

arch/arm64/kvm/fpsimd.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,6 @@ int kvm_arch_vcpu_run_map_fp(struct kvm_vcpu *vcpu)
4949
if (ret)
5050
return ret;
5151

52-
vcpu->arch.host_fpsimd_state = kern_hyp_va(fpsimd);
53-
5452
/*
5553
* We need to keep current's task_struct pinned until its data has been
5654
* unshared with the hypervisor to make sure it is not re-used by the
@@ -87,6 +85,7 @@ void kvm_arch_vcpu_load_fp(struct kvm_vcpu *vcpu)
8785
* FP_STATE_FREE if the flag set.
8886
*/
8987
vcpu->arch.fp_state = FP_STATE_HOST_OWNED;
88+
*host_data_ptr(fpsimd_state) = kern_hyp_va(&current->thread.uw.fpsimd_state);
9089

9190
vcpu_clear_flag(vcpu, HOST_SVE_ENABLED);
9291
if (read_sysreg(cpacr_el1) & CPACR_EL1_ZEN_EL0EN)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,7 @@ static bool kvm_hyp_handle_fpsimd(struct kvm_vcpu *vcpu, u64 *exit_code)
377377

378378
/* Write out the host state if it's in the registers */
379379
if (vcpu->arch.fp_state == FP_STATE_HOST_OWNED)
380-
__fpsimd_save_state(vcpu->arch.host_fpsimd_state);
380+
__fpsimd_save_state(*host_data_ptr(fpsimd_state));
381381

382382
/* Restore the guest state */
383383
if (sve_guest)

arch/arm64/kvm/hyp/nvhe/hyp-main.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ static void flush_hyp_vcpu(struct pkvm_hyp_vcpu *hyp_vcpu)
4242
hyp_vcpu->vcpu.arch.fp_state = host_vcpu->arch.fp_state;
4343

4444
hyp_vcpu->vcpu.arch.debug_ptr = kern_hyp_va(host_vcpu->arch.debug_ptr);
45-
hyp_vcpu->vcpu.arch.host_fpsimd_state = host_vcpu->arch.host_fpsimd_state;
4645

4746
hyp_vcpu->vcpu.arch.vsesr_el2 = host_vcpu->arch.vsesr_el2;
4847

0 commit comments

Comments
 (0)