Skip to content

Commit 99996d5

Browse files
Quentin PerretMarc Zyngier
authored andcommitted
KVM: arm64: Add {get,put}_pkvm_hyp_vm() helpers
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 <[email protected]> Reviewed-by: Fuad Tabba <[email protected]> Signed-off-by: Quentin Perret <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Marc Zyngier <[email protected]>
1 parent c77e518 commit 99996d5

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

arch/arm64/kvm/hyp/include/nvhe/pkvm.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,4 +70,7 @@ struct pkvm_hyp_vcpu *pkvm_load_hyp_vcpu(pkvm_handle_t handle,
7070
unsigned int vcpu_idx);
7171
void pkvm_put_hyp_vcpu(struct pkvm_hyp_vcpu *hyp_vcpu);
7272

73+
struct pkvm_hyp_vm *get_pkvm_hyp_vm(pkvm_handle_t handle);
74+
void put_pkvm_hyp_vm(struct pkvm_hyp_vm *hyp_vm);
75+
7376
#endif /* __ARM64_KVM_NVHE_PKVM_H__ */

arch/arm64/kvm/hyp/nvhe/pkvm.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,26 @@ void pkvm_put_hyp_vcpu(struct pkvm_hyp_vcpu *hyp_vcpu)
327327
hyp_spin_unlock(&vm_table_lock);
328328
}
329329

330+
struct pkvm_hyp_vm *get_pkvm_hyp_vm(pkvm_handle_t handle)
331+
{
332+
struct pkvm_hyp_vm *hyp_vm;
333+
334+
hyp_spin_lock(&vm_table_lock);
335+
hyp_vm = get_vm_by_handle(handle);
336+
if (hyp_vm)
337+
hyp_page_ref_inc(hyp_virt_to_page(hyp_vm));
338+
hyp_spin_unlock(&vm_table_lock);
339+
340+
return hyp_vm;
341+
}
342+
343+
void put_pkvm_hyp_vm(struct pkvm_hyp_vm *hyp_vm)
344+
{
345+
hyp_spin_lock(&vm_table_lock);
346+
hyp_page_ref_dec(hyp_virt_to_page(hyp_vm));
347+
hyp_spin_unlock(&vm_table_lock);
348+
}
349+
330350
static void pkvm_init_features_from_host(struct pkvm_hyp_vm *hyp_vm, const struct kvm *host_kvm)
331351
{
332352
struct kvm *kvm = &hyp_vm->kvm;

0 commit comments

Comments
 (0)