Skip to content

Commit 61d99e3

Browse files
willdeaconMarc Zyngier
authored andcommitted
KVM: arm64: Introduce wrappers for host and hyp spin lock accessors
In preparation for adding additional locked sections for manipulating page-tables at EL2, introduce some simple wrappers around the host and hypervisor locks so that it's a bit easier to read and bit more difficult to take the wrong lock (or even take them in the wrong order). Signed-off-by: Will Deacon <[email protected]> Signed-off-by: Quentin Perret <[email protected]> Signed-off-by: Marc Zyngier <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 3d467f7 commit 61d99e3

File tree

1 file changed

+26
-6
lines changed

1 file changed

+26
-6
lines changed

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

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,26 @@ static struct hyp_pool host_s2_pool;
2727

2828
const u8 pkvm_hyp_id = 1;
2929

30+
static void host_lock_component(void)
31+
{
32+
hyp_spin_lock(&host_kvm.lock);
33+
}
34+
35+
static void host_unlock_component(void)
36+
{
37+
hyp_spin_unlock(&host_kvm.lock);
38+
}
39+
40+
static void hyp_lock_component(void)
41+
{
42+
hyp_spin_lock(&pkvm_pgd_lock);
43+
}
44+
45+
static void hyp_unlock_component(void)
46+
{
47+
hyp_spin_unlock(&pkvm_pgd_lock);
48+
}
49+
3050
static void *host_s2_zalloc_pages_exact(size_t size)
3151
{
3252
void *addr = hyp_alloc_pages(&host_s2_pool, get_order(size));
@@ -338,14 +358,14 @@ static int host_stage2_idmap(u64 addr)
338358

339359
prot = is_memory ? PKVM_HOST_MEM_PROT : PKVM_HOST_MMIO_PROT;
340360

341-
hyp_spin_lock(&host_kvm.lock);
361+
host_lock_component();
342362
ret = host_stage2_adjust_range(addr, &range);
343363
if (ret)
344364
goto unlock;
345365

346366
ret = host_stage2_idmap_locked(range.start, range.end - range.start, prot);
347367
unlock:
348-
hyp_spin_unlock(&host_kvm.lock);
368+
host_unlock_component();
349369

350370
return ret;
351371
}
@@ -369,8 +389,8 @@ int __pkvm_host_share_hyp(u64 pfn)
369389
if (!addr_is_memory(addr))
370390
return -EINVAL;
371391

372-
hyp_spin_lock(&host_kvm.lock);
373-
hyp_spin_lock(&pkvm_pgd_lock);
392+
host_lock_component();
393+
hyp_lock_component();
374394

375395
ret = kvm_pgtable_get_leaf(&host_kvm.pgt, addr, &pte, NULL);
376396
if (ret)
@@ -432,8 +452,8 @@ int __pkvm_host_share_hyp(u64 pfn)
432452
BUG_ON(ret);
433453

434454
unlock:
435-
hyp_spin_unlock(&pkvm_pgd_lock);
436-
hyp_spin_unlock(&host_kvm.lock);
455+
hyp_unlock_component();
456+
host_unlock_component();
437457

438458
return ret;
439459
}

0 commit comments

Comments
 (0)