arm/arm64: KVM: Check that IDMAP doesn't intersect with VA range
authorMarc Zyngier <marc.zyngier@arm.com>
Thu, 30 Jun 2016 17:40:50 +0000 (18:40 +0100)
committerChristoffer Dall <christoffer.dall@linaro.org>
Sun, 3 Jul 2016 21:41:27 +0000 (23:41 +0200)
This is more of a safety measure than anything else: If we end-up
with an idmap page that intersect with the range picked for the
the HYP VA space, abort the KVM setup, as it is unsafe to go
further.

I cannot imagine it happening on 64bit (we have a mechanism to
work around it), but could potentially occur on a 32bit system with
the kernel loaded high enough in memory so that in conflicts with
the kernel VA.

Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>
Signed-off-by: Christoffer Dall <christoffer.dall@linaro.org>
arch/arm/kvm/mmu.c

index 0b36dd52af62b11d9c49407070b0b9e818a802b2..8a0aa37605c55e73054010f1e700ec7461c3ced1 100644 (file)
@@ -1709,6 +1709,21 @@ int kvm_mmu_init(void)
         */
        BUG_ON((hyp_idmap_start ^ (hyp_idmap_end - 1)) & PAGE_MASK);
 
+       kvm_info("IDMAP page: %lx\n", hyp_idmap_start);
+       kvm_info("HYP VA range: %lx:%lx\n",
+                KERN_TO_HYP(PAGE_OFFSET), KERN_TO_HYP(~0UL));
+
+       if (hyp_idmap_start >= KERN_TO_HYP(PAGE_OFFSET) &&
+           hyp_idmap_start <  KERN_TO_HYP(~0UL)) {
+               /*
+                * The idmap page is intersecting with the VA space,
+                * it is not safe to continue further.
+                */
+               kvm_err("IDMAP intersecting with HYP VA, unable to continue\n");
+               err = -EINVAL;
+               goto out;
+       }
+
        hyp_pgd = (pgd_t *)__get_free_pages(GFP_KERNEL | __GFP_ZERO, hyp_pgd_order);
        if (!hyp_pgd) {
                kvm_err("Hyp mode PGD not allocated\n");