Re: [PATCH 04/10] KVM: arm64: Use guard(hyp_spinlock) in mm.c
From: Jonathan Cameron
Date: Tue Mar 17 2026 - 13:44:42 EST
On Mon, 16 Mar 2026 17:35:25 +0000
Fuad Tabba <tabba@xxxxxxxxxx> wrote:
> Migrate manual hyp_spin_lock() and hyp_spin_unlock() calls managing
> pkvm_pgd_lock to use the guard(hyp_spinlock) macro.
>
> This eliminates manual unlock calls on return paths and simplifies
> error handling by replacing goto labels with direct returns.
> Note: hyp_fixblock_lock spans across hyp_fixblock_map/unmap functions,
> so it retains explicit lock/unlock semantics to avoid RAII violations.
>
> Change-Id: I6bb3f4105e95480269e5bf8289d084c8f9981730
> Signed-off-by: Fuad Tabba <tabba@xxxxxxxxxx>
> ---
> arch/arm64/kvm/hyp/nvhe/mm.c | 37 ++++++++++---------------------------
> 1 file changed, 10 insertions(+), 27 deletions(-)
>
> diff --git a/arch/arm64/kvm/hyp/nvhe/mm.c b/arch/arm64/kvm/hyp/nvhe/mm.c
> index 218976287d3f..7a15c9fc15e5 100644
> --- a/arch/arm64/kvm/hyp/nvhe/mm.c
> +++ b/arch/arm64/kvm/hyp/nvhe/mm.c
> @@ -35,13 +35,8 @@ static DEFINE_PER_CPU(struct hyp_fixmap_slot, fixmap_slots);
>
> static int __pkvm_alloc_private_va_range(unsigned long start, size_t size)
> @@ -80,10 +75,9 @@ int pkvm_alloc_private_va_range(size_t size, unsigned long *haddr)
> unsigned long addr;
> int ret;
>
> - hyp_spin_lock(&pkvm_pgd_lock);
> + guard(hyp_spinlock)(&pkvm_pgd_lock);
> addr = __io_map_base;
> ret = __pkvm_alloc_private_va_range(addr, size);
> - hyp_spin_unlock(&pkvm_pgd_lock);
>
> *haddr = addr;
Maybe it looses meaning but given this sets *haddr on error or not
can reorder and save a few lines.
addr = __iomap_base;
*haddr = addr;
return __pkvm_alloc_private_va_range(addr, size);