[PATCH 10/10] KVM: arm64: Use guard(mutex) in pkvm.c

Fuad Tabba
2026-03-16T17:35:41Z

Migrate manual mutex_lock() and mutex_unlock() calls managing
kvm->arch.config_lock to use the guard(mutex) macro.

This eliminates manual unlock calls on early return paths, ensuring
the mutex is safely released during early pKVM host-side VM initialization.

Change-Id: I902ab100f2deb4de7d6fbf0340d4aec30cf49e56
Signed-off-by: Fuad Tabba <tabba@google.com>
---
arch/arm64/kvm/pkvm.c | 19 +++++++------------
1 file changed, 7 insertions(+), 12 deletions(-)

diff --git a/arch/arm64/kvm/pkvm.c b/arch/arm64/kvm/pkvm.c
index d7a0f69a9982..4a4a9d0699c8 100644
--- a/arch/arm64/kvm/pkvm.c
+++ b/arch/arm64/kvm/pkvm.c
@@ -190,33 +190,28 @@ bool pkvm_hyp_vm_is_created(struct kvm *kvm)

int pkvm_create_hyp_vm(struct kvm *kvm)
{
- int ret = 0;
+ guard(mutex)(&kvm->arch.config_lock);

- mutex_lock(&kvm->arch.config_lock);
if (!pkvm_hyp_vm_is_created(kvm))
- ret = __pkvm_create_hyp_vm(kvm);
- mutex_unlock(&kvm->arch.config_lock);
+ return __pkvm_create_hyp_vm(kvm);

- return ret;
+ return 0;
}

int pkvm_create_hyp_vcpu(struct kvm_vcpu *vcpu)
{
- int ret = 0;
+ guard(mutex)(&vcpu->kvm->arch.config_lock);

- mutex_lock(&vcpu->kvm->arch.config_lock);
if (!vcpu_get_flag(vcpu, VCPU_PKVM_FINALIZED))
- ret = __pkvm_create_hyp_vcpu(vcpu);
- mutex_unlock(&vcpu->kvm->arch.config_lock);
+ return __pkvm_create_hyp_vcpu(vcpu);

- return ret;
+ return 0;
}

void pkvm_destroy_hyp_vm(struct kvm *kvm)
{
- mutex_lock(&kvm->arch.config_lock);
+ guard(mutex)(&kvm->arch.config_lock);
__pkvm_destroy_hyp_vm(kvm);
- mutex_unlock(&kvm->arch.config_lock);
}

int pkvm_init_host_vm(struct kvm *kvm)

--
2.53.0.851.ga537e3e6e9-goog