]> www.infradead.org Git - users/dwmw2/linux.git/commitdiff
KVM: arm64: Add {get,put}_pkvm_hyp_vm() helpers
authorQuentin Perret <qperret@google.com>
Wed, 18 Dec 2024 19:40:49 +0000 (19:40 +0000)
committerMarc Zyngier <maz@kernel.org>
Fri, 20 Dec 2024 09:44:00 +0000 (09:44 +0000)
In preparation for accessing pkvm_hyp_vm structures at EL2 in a context
where we can't always expect a vCPU to be loaded (e.g. MMU notifiers),
introduce get/put helpers to get temporary references to hyp VMs from
any context.

Tested-by: Fuad Tabba <tabba@google.com>
Reviewed-by: Fuad Tabba <tabba@google.com>
Signed-off-by: Quentin Perret <qperret@google.com>
Link: https://lore.kernel.org/r/20241218194059.3670226-9-qperret@google.com
Signed-off-by: Marc Zyngier <maz@kernel.org>
arch/arm64/kvm/hyp/include/nvhe/pkvm.h
arch/arm64/kvm/hyp/nvhe/pkvm.c

index 24a9a8330d190396e90abc7202e6b7e86ea1de63..f361d8b91930da5927701fb68a5955a1df61c142 100644 (file)
@@ -70,4 +70,7 @@ struct pkvm_hyp_vcpu *pkvm_load_hyp_vcpu(pkvm_handle_t handle,
                                         unsigned int vcpu_idx);
 void pkvm_put_hyp_vcpu(struct pkvm_hyp_vcpu *hyp_vcpu);
 
+struct pkvm_hyp_vm *get_pkvm_hyp_vm(pkvm_handle_t handle);
+void put_pkvm_hyp_vm(struct pkvm_hyp_vm *hyp_vm);
+
 #endif /* __ARM64_KVM_NVHE_PKVM_H__ */
index 071993c16de81ca0b0181c56d0598b1b026ae018..d46a02e24e4aa14de6a6ed24ca6aec64be8dd0fb 100644 (file)
@@ -327,6 +327,26 @@ void pkvm_put_hyp_vcpu(struct pkvm_hyp_vcpu *hyp_vcpu)
        hyp_spin_unlock(&vm_table_lock);
 }
 
+struct pkvm_hyp_vm *get_pkvm_hyp_vm(pkvm_handle_t handle)
+{
+       struct pkvm_hyp_vm *hyp_vm;
+
+       hyp_spin_lock(&vm_table_lock);
+       hyp_vm = get_vm_by_handle(handle);
+       if (hyp_vm)
+               hyp_page_ref_inc(hyp_virt_to_page(hyp_vm));
+       hyp_spin_unlock(&vm_table_lock);
+
+       return hyp_vm;
+}
+
+void put_pkvm_hyp_vm(struct pkvm_hyp_vm *hyp_vm)
+{
+       hyp_spin_lock(&vm_table_lock);
+       hyp_page_ref_dec(hyp_virt_to_page(hyp_vm));
+       hyp_spin_unlock(&vm_table_lock);
+}
+
 static void pkvm_init_features_from_host(struct pkvm_hyp_vm *hyp_vm, const struct kvm *host_kvm)
 {
        struct kvm *kvm = &hyp_vm->kvm;