Revert "ANDROID: KVM: arm64: Pin host structs for pVMs"

This reverts commit 3401cd27ad.

Bug: 233587962
Signed-off-by: Will Deacon <willdeacon@google.com>
Change-Id: Ibdec9f01629130f13665c20a07a2c4d3175fa80c
This commit is contained in:
Will Deacon
2022-07-07 15:51:36 +01:00
parent 486bbd0ccb
commit be2a4c8d6b

View File

@@ -312,21 +312,10 @@ static void copy_features(struct kvm_vcpu *shadow_vcpu, struct kvm_vcpu *host_vc
allowed_features, KVM_VCPU_MAX_FEATURES);
}
static void unpin_host_vcpus(struct kvm_shadow_vm *vm)
static void init_shadow_structs(struct kvm *kvm, struct kvm_shadow_vm *vm, int nr_vcpus)
{
int i;
for (i = 0; i < vm->created_vcpus; i++) {
struct kvm_vcpu *vcpu = vm->vcpus[i]->arch.pkvm.host_vcpu;
hyp_unpin_shared_mem(vcpu, vcpu + 1);
}
}
static int init_shadow_structs(struct kvm *kvm, struct kvm_shadow_vm *vm, int nr_vcpus)
{
int i;
int ret;
/* TODO: initialize the protected MMU. For now, use the host's. */
vm->mmu = &kvm->arch.mmu;
vm->host_kvm = kvm;
@@ -337,12 +326,6 @@ static int init_shadow_structs(struct kvm *kvm, struct kvm_shadow_vm *vm, int nr
struct shadow_vcpu_state *shadow_state = &vm->shadow_vcpus[i];
struct kvm_vcpu *shadow_vcpu = &shadow_state->vcpu;
ret = hyp_pin_shared_mem(host_vcpu, host_vcpu + 1);
if (ret)
return -EBUSY;
vm->created_vcpus++;
shadow_vcpu->kvm = kvm;
shadow_vcpu->vcpu_id = host_vcpu->vcpu_id;
shadow_vcpu->vcpu_idx = i;
@@ -364,9 +347,9 @@ static int init_shadow_structs(struct kvm *kvm, struct kvm_shadow_vm *vm, int nr
shadow_vcpu->arch.pkvm.shadow_handle = vm->shadow_handle;
shadow_vcpu->arch.pkvm.host_vcpu = host_vcpu;
shadow_vcpu->arch.pkvm.shadow_vm = vm;
}
return 0;
vm->created_vcpus++;
}
}
static bool exists_shadow(struct kvm *host_kvm)
@@ -503,10 +486,6 @@ int __pkvm_init_shadow(struct kvm *kvm,
kvm = kern_hyp_va(kvm);
ret = hyp_pin_shared_mem(kvm, kvm + 1);
if (ret)
return ret;
/* Ensure the host has donated enough memory for the shadow structs. */
nr_vcpus = kvm->created_vcpus;
ret = check_shadow_size(nr_vcpus, shadow_size);
@@ -525,20 +504,16 @@ int __pkvm_init_shadow(struct kvm *kvm,
if (ret < 0)
goto err_clear_shadow;
ret = init_shadow_structs(kvm, vm, nr_vcpus);
if (ret < 0)
goto err_clear_shadow;
init_shadow_structs(kvm, vm, nr_vcpus);
return vm->shadow_handle;
err_clear_shadow:
unpin_host_vcpus(vm);
/* Clear the donated shadow memory on failure to avoid data leaks. */
memset(vm, 0, shadow_size);
WARN_ON(__pkvm_hyp_donate_host(pfn, nr_pages));
err:
hyp_unpin_shared_mem(kvm, kvm + 1);
return ret;
}
@@ -561,8 +536,6 @@ int __pkvm_teardown_shadow(struct kvm *kvm)
shadow_size = vm->shadow_area_size;
unpin_host_vcpus(vm);
hyp_unpin_shared_mem(vm->host_kvm, vm->host_kvm + 1);
remove_shadow_table(shadow_handle);
/* Clear the shadow memory since hyp is releasing it back to host. */