[PATCH v3 02/13] KVM: arm64: Take host-registered MMIO regions at pKVM finalisation
Fuad Tabba
fuad.tabba at linux.dev
Mon Nov 2 05:01:22 PST 2026
From: Sebastian Ene <sebastianene at google.com>
To mediate a device, the protected KVM hypervisor has to own its
registers, so that a host access to them takes a stage-2 abort rather
than reaching the device.
Let the host register MMIO regions before the hypervisor initialises,
and have __pkvm_init_finalise() donate each one and record where it's
mapped in the hypervisor's private range. The donation runs before
pkvm_check_host_ownership(), which then covers those mappings too. A
failed donation fails the hypervisor's initialisation before the host
stage 2 is installed, so nothing is given back.
Nothing registers a region yet.
Signed-off-by: Sebastian Ene <sebastianene at google.com>
Co-developed-by: Fuad Tabba <fuad.tabba at linux.dev>
Signed-off-by: Fuad Tabba <fuad.tabba at linux.dev>
---
Notes:
Changes since v2 (v2 patches 02 and 03, merged):
- The trap handling moved to patch 9, which calls the ITS emulation
directly (was a per-region callback)
- Each region records its hypervisor VA
- A failed donation is no longer unwound
arch/arm64/include/asm/kvm_pkvm.h | 12 ++++++++++++
arch/arm64/kvm/hyp/nvhe/mem_protect.c | 3 +++
arch/arm64/kvm/hyp/nvhe/setup.c | 22 ++++++++++++++++++++++
3 files changed, 37 insertions(+)
diff --git a/arch/arm64/include/asm/kvm_pkvm.h b/arch/arm64/include/asm/kvm_pkvm.h
index fd042d2b54624..4695c35b31e1a 100644
--- a/arch/arm64/include/asm/kvm_pkvm.h
+++ b/arch/arm64/include/asm/kvm_pkvm.h
@@ -17,6 +17,18 @@
#define HYP_MEMBLOCK_REGIONS 128
+/* MMIO regions the host registers for the hypervisor to take at finalisation. */
+#define PKVM_PROTECTED_REGS_NUM 8
+
+struct pkvm_protected_reg {
+ u64 pfn;
+ u64 nr_pages;
+ void __iomem *hyp_va;
+};
+
+extern struct pkvm_protected_reg kvm_nvhe_sym(pkvm_protected_regs)[];
+extern unsigned int kvm_nvhe_sym(num_protected_reg);
+
int pkvm_init_host_vm(struct kvm *kvm);
int pkvm_create_hyp_vm(struct kvm *kvm);
bool pkvm_hyp_vm_is_created(struct kvm *kvm);
diff --git a/arch/arm64/kvm/hyp/nvhe/mem_protect.c b/arch/arm64/kvm/hyp/nvhe/mem_protect.c
index a6dacaca77610..8d45f45d30e6a 100644
--- a/arch/arm64/kvm/hyp/nvhe/mem_protect.c
+++ b/arch/arm64/kvm/hyp/nvhe/mem_protect.c
@@ -28,6 +28,9 @@ struct host_mmu host_mmu;
static struct hyp_pool host_s2_pool;
+unsigned int num_protected_reg;
+struct pkvm_protected_reg pkvm_protected_regs[PKVM_PROTECTED_REGS_NUM];
+
static DEFINE_PER_CPU(struct pkvm_hyp_vm *, __current_vm);
#define current_vm (*this_cpu_ptr(&__current_vm))
diff --git a/arch/arm64/kvm/hyp/nvhe/setup.c b/arch/arm64/kvm/hyp/nvhe/setup.c
index 7bbc26b28faa5..18f348d1331a8 100644
--- a/arch/arm64/kvm/hyp/nvhe/setup.c
+++ b/arch/arm64/kvm/hyp/nvhe/setup.c
@@ -295,6 +295,24 @@ static int fix_hyp_pgtable_refcnt(void)
&walker);
}
+static int donate_protected_mmio_regions(void)
+{
+ struct pkvm_protected_reg *region;
+ unsigned long haddr;
+ int ret, i;
+
+ for (i = 0; i < num_protected_reg; i++) {
+ region = &pkvm_protected_regs[i];
+ ret = __pkvm_host_donate_hyp_mmio(region->pfn, region->nr_pages, &haddr);
+ if (ret)
+ return ret;
+
+ region->hyp_va = (void __iomem *)haddr;
+ }
+
+ return 0;
+}
+
void __noreturn __pkvm_init_finalise(void)
{
struct kvm_cpu_context *host_ctxt = host_data_ptr(host_ctxt);
@@ -335,6 +353,10 @@ void __noreturn __pkvm_init_finalise(void)
if (ret)
goto out;
+ ret = donate_protected_mmio_regions();
+ if (ret)
+ goto out;
+
ret = pkvm_check_host_ownership();
if (ret)
goto out;
--
2.47.3
More information about the linux-arm-kernel
mailing list