Skip to content

Commit bff01a6

Browse files
author
Marc Zyngier
committed
KVM: arm64: Move SVE state mapping at HYP to finalize-time
We currently map the SVE state to HYP on detection of a PID change. Although this matches what we do for FPSIMD, this is pretty pointless for SVE, as the buffer is per-vcpu and has nothing to do with the thread that is being run. Move the mapping of the SVE state to finalize-time, which is where we allocate the state memory, and thus the most logical place to do this. Reviewed-by: Andrew Jones <[email protected]> Signed-off-by: Marc Zyngier <[email protected]>
1 parent d58071a commit bff01a6

File tree

2 files changed

+10
-12
lines changed

2 files changed

+10
-12
lines changed

arch/arm64/kvm/fpsimd.c

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -43,17 +43,6 @@ int kvm_arch_vcpu_run_map_fp(struct kvm_vcpu *vcpu)
4343
if (ret)
4444
goto error;
4545

46-
if (vcpu->arch.sve_state) {
47-
void *sve_end;
48-
49-
sve_end = vcpu->arch.sve_state + vcpu_sve_state_size(vcpu);
50-
51-
ret = create_hyp_mappings(vcpu->arch.sve_state, sve_end,
52-
PAGE_HYP);
53-
if (ret)
54-
goto error;
55-
}
56-
5746
vcpu->arch.host_thread_info = kern_hyp_va(ti);
5847
vcpu->arch.host_fpsimd_state = kern_hyp_va(fpsimd);
5948
error:

arch/arm64/kvm/reset.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,8 @@ static int kvm_vcpu_finalize_sve(struct kvm_vcpu *vcpu)
9494
{
9595
void *buf;
9696
unsigned int vl;
97+
size_t reg_sz;
98+
int ret;
9799

98100
vl = vcpu->arch.sve_max_vl;
99101

@@ -106,10 +108,17 @@ static int kvm_vcpu_finalize_sve(struct kvm_vcpu *vcpu)
106108
vl > SVE_VL_ARCH_MAX))
107109
return -EIO;
108110

109-
buf = kzalloc(SVE_SIG_REGS_SIZE(sve_vq_from_vl(vl)), GFP_KERNEL_ACCOUNT);
111+
reg_sz = vcpu_sve_state_size(vcpu);
112+
buf = kzalloc(reg_sz, GFP_KERNEL_ACCOUNT);
110113
if (!buf)
111114
return -ENOMEM;
112115

116+
ret = create_hyp_mappings(buf, buf + reg_sz, PAGE_HYP);
117+
if (ret) {
118+
kfree(buf);
119+
return ret;
120+
}
121+
113122
vcpu->arch.sve_state = buf;
114123
vcpu->arch.flags |= KVM_ARM64_VCPU_SVE_FINALIZED;
115124
return 0;

0 commit comments

Comments
 (0)