[PATCH v2 3/4] KVM: arm64: Factor out pKVM hyp vcpu creation to separate function
Quentin Perret
qperret at google.com
Fri Feb 28 11:44:47 PST 2025
On Wednesday 26 Feb 2025 at 21:55:19 (+0000), Fuad Tabba wrote:
> static int __pkvm_create_hyp_vm(struct kvm *host_kvm)
> {
> - size_t pgd_sz, hyp_vm_sz, hyp_vcpu_sz;
> + size_t pgd_sz, hyp_vm_sz;
> struct kvm_vcpu *host_vcpu;
> - pkvm_handle_t handle;
> void *pgd, *hyp_vm;
> unsigned long idx;
> int ret;
> @@ -161,33 +178,12 @@ static int __pkvm_create_hyp_vm(struct kvm *host_kvm)
> if (ret < 0)
> goto free_vm;
>
> - handle = ret;
> + WRITE_ONCE(host_kvm->arch.pkvm.handle, ret);
What's the reason to make this a WRITE_ONCE? Does it mean we should
update the readers to be READ_ONCE()?
> - host_kvm->arch.pkvm.handle = handle;
> -
> - /* Donate memory for the vcpus at hyp and initialize it. */
> - hyp_vcpu_sz = PAGE_ALIGN(PKVM_HYP_VCPU_SIZE);
> kvm_for_each_vcpu(idx, host_vcpu, host_kvm) {
> - void *hyp_vcpu;
> -
> - /* Indexing of the vcpus to be sequential starting at 0. */
> - if (WARN_ON(host_vcpu->vcpu_idx != idx)) {
> - ret = -EINVAL;
> - goto destroy_vm;
> - }
> -
> - hyp_vcpu = alloc_pages_exact(hyp_vcpu_sz, GFP_KERNEL_ACCOUNT);
> - if (!hyp_vcpu) {
> - ret = -ENOMEM;
> - goto destroy_vm;
> - }
> -
> - ret = kvm_call_hyp_nvhe(__pkvm_init_vcpu, handle, host_vcpu,
> - hyp_vcpu);
> - if (ret) {
> - free_pages_exact(hyp_vcpu, hyp_vcpu_sz);
> + ret = __pkvm_create_hyp_vcpu(host_vcpu);
> + if (ret)
> goto destroy_vm;
> - }
> }
>
> return 0;
> --
> 2.48.1.711.g2feabab25a-goog
>
More information about the linux-arm-kernel
mailing list