Skip to content

Commit 469c471

Browse files
author
Marc Zyngier
committed
KVM: arm64: nv: Allocate VNCR page when required
If running a NV guest on an ARMv8.4-NV capable system, let's allocate an additional page that will be used by the hypervisor to fulfill system register accesses. Reviewed-by: Ganapatrao Kulkarni <gankulkarni@os.amperecomputing.com> Reviewed-by: Oliver Upton <oliver.upton@linux.dev> Link: https://lore.kernel.org/r/20250514103501.2225951-3-maz@kernel.org Signed-off-by: Marc Zyngier <maz@kernel.org>
1 parent fb30669 commit 469c471

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

arch/arm64/kvm/nested.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,13 @@ int kvm_vcpu_init_nested(struct kvm_vcpu *vcpu)
5555
!cpus_have_final_cap(ARM64_HAS_HCR_NV1))
5656
return -EINVAL;
5757

58+
if (!vcpu->arch.ctxt.vncr_array)
59+
vcpu->arch.ctxt.vncr_array = (u64 *)__get_free_page(GFP_KERNEL_ACCOUNT |
60+
__GFP_ZERO);
61+
62+
if (!vcpu->arch.ctxt.vncr_array)
63+
return -ENOMEM;
64+
5865
/*
5966
* Let's treat memory allocation failures as benign: If we fail to
6067
* allocate anything, return an error and keep the allocated array
@@ -85,6 +92,9 @@ int kvm_vcpu_init_nested(struct kvm_vcpu *vcpu)
8592
for (int i = kvm->arch.nested_mmus_size; i < num_mmus; i++)
8693
kvm_free_stage2_pgd(&kvm->arch.nested_mmus[i]);
8794

95+
free_page((unsigned long)vcpu->arch.ctxt.vncr_array);
96+
vcpu->arch.ctxt.vncr_array = NULL;
97+
8898
return ret;
8999
}
90100

arch/arm64/kvm/reset.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ void kvm_arm_vcpu_destroy(struct kvm_vcpu *vcpu)
158158
if (sve_state)
159159
kvm_unshare_hyp(sve_state, sve_state + vcpu_sve_state_size(vcpu));
160160
kfree(sve_state);
161+
free_page((unsigned long)vcpu->arch.ctxt.vncr_array);
161162
kfree(vcpu->arch.ccsidr);
162163
}
163164

0 commit comments

Comments
 (0)