KVM: arm/arm64: Move ioremap calls to create_hyp_io_mappings
authorMarc Zyngier <marc.zyngier@arm.com>
Mon, 4 Dec 2017 16:26:09 +0000 (16:26 +0000)
committerMarc Zyngier <marc.zyngier@arm.com>
Mon, 19 Mar 2018 13:03:47 +0000 (13:03 +0000)
Both HYP io mappings call ioremap, followed by create_hyp_io_mappings.
Let's move the ioremap call into create_hyp_io_mappings itself, which
simplifies the code a bit and allows for further refactoring.

Reviewed-by: Christoffer Dall <christoffer.dall@linaro.org>
Acked-by: Catalin Marinas <catalin.marinas@arm.com>
Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>
arch/arm/include/asm/kvm_mmu.h
arch/arm64/include/asm/kvm_mmu.h
virt/kvm/arm/mmu.c
virt/kvm/arm/vgic/vgic-v2.c

index 93395b7c2322ce9e16df59eb9631cbb164ca6a98..bf17ad83d2f0976057b857a610380cc85dfc7e70 100644 (file)
@@ -50,7 +50,8 @@
 #include <asm/stage2_pgtable.h>
 
 int create_hyp_mappings(void *from, void *to, pgprot_t prot);
-int create_hyp_io_mappings(void *from, void *to, phys_addr_t);
+int create_hyp_io_mappings(phys_addr_t phys_addr, size_t size,
+                          void __iomem **kaddr);
 void free_hyp_pgds(void);
 
 void stage2_unmap_vm(struct kvm *kvm);
index 021d3a8117a8b0e915fda54412f37349eb4f3c39..8d5f9934d8197331d7da81b780f3f7e9913e8f19 100644 (file)
@@ -140,7 +140,8 @@ static inline unsigned long __kern_hyp_va(unsigned long v)
 #include <asm/stage2_pgtable.h>
 
 int create_hyp_mappings(void *from, void *to, pgprot_t prot);
-int create_hyp_io_mappings(void *from, void *to, phys_addr_t);
+int create_hyp_io_mappings(phys_addr_t phys_addr, size_t size,
+                          void __iomem **kaddr);
 void free_hyp_pgds(void);
 
 void stage2_unmap_vm(struct kvm *kvm);
index 3eaf46828caaf3606bb530ef026a30e8b404d1bf..2bc32bdf932acf3baca7392a0018d9db472eac09 100644 (file)
@@ -709,26 +709,30 @@ int create_hyp_mappings(void *from, void *to, pgprot_t prot)
 }
 
 /**
- * create_hyp_io_mappings - duplicate a kernel IO mapping into Hyp mode
- * @from:      The kernel start VA of the range
- * @to:                The kernel end VA of the range (exclusive)
+ * create_hyp_io_mappings - Map IO into both kernel and HYP
  * @phys_addr: The physical start address which gets mapped
+ * @size:      Size of the region being mapped
+ * @kaddr:     Kernel VA for this mapping
  *
  * The resulting HYP VA is the same as the kernel VA, modulo
  * HYP_PAGE_OFFSET.
  */
-int create_hyp_io_mappings(void *from, void *to, phys_addr_t phys_addr)
+int create_hyp_io_mappings(phys_addr_t phys_addr, size_t size,
+                          void __iomem **kaddr)
 {
-       unsigned long start = kern_hyp_va((unsigned long)from);
-       unsigned long end = kern_hyp_va((unsigned long)to);
+       unsigned long start, end;
 
-       if (is_kernel_in_hyp_mode())
+       *kaddr = ioremap(phys_addr, size);
+       if (!*kaddr)
+               return -ENOMEM;
+
+       if (is_kernel_in_hyp_mode()) {
                return 0;
+       }
 
-       /* Check for a valid kernel IO mapping */
-       if (!is_vmalloc_addr(from) || !is_vmalloc_addr(to - 1))
-               return -EINVAL;
 
+       start = kern_hyp_va((unsigned long)*kaddr);
+       end = kern_hyp_va((unsigned long)*kaddr + size);
        return __create_hyp_mappings(hyp_pgd, PTRS_PER_PGD, start, end,
                                     __phys_to_pfn(phys_addr), PAGE_HYP_DEVICE);
 }
index ca7cfee9f35342b0ba2c2b53b5f6fcd44d65966c..66532f2f0e40de00717b5aa52a3d2c5cbb52cc58 100644 (file)
@@ -360,16 +360,10 @@ int vgic_v2_probe(const struct gic_kvm_info *info)
        if (!PAGE_ALIGNED(info->vcpu.start) ||
            !PAGE_ALIGNED(resource_size(&info->vcpu))) {
                kvm_info("GICV region size/alignment is unsafe, using trapping (reduced performance)\n");
-               kvm_vgic_global_state.vcpu_base_va = ioremap(info->vcpu.start,
-                                                            resource_size(&info->vcpu));
-               if (!kvm_vgic_global_state.vcpu_base_va) {
-                       kvm_err("Cannot ioremap GICV\n");
-                       return -ENOMEM;
-               }
 
-               ret = create_hyp_io_mappings(kvm_vgic_global_state.vcpu_base_va,
-                                            kvm_vgic_global_state.vcpu_base_va + resource_size(&info->vcpu),
-                                            info->vcpu.start);
+               ret = create_hyp_io_mappings(info->vcpu.start,
+                                            resource_size(&info->vcpu),
+                                            &kvm_vgic_global_state.vcpu_base_va);
                if (ret) {
                        kvm_err("Cannot map GICV into hyp\n");
                        goto out;
@@ -378,26 +372,17 @@ int vgic_v2_probe(const struct gic_kvm_info *info)
                static_branch_enable(&vgic_v2_cpuif_trap);
        }
 
-       kvm_vgic_global_state.vctrl_base = ioremap(info->vctrl.start,
-                                                  resource_size(&info->vctrl));
-       if (!kvm_vgic_global_state.vctrl_base) {
-               kvm_err("Cannot ioremap GICH\n");
-               ret = -ENOMEM;
+       ret = create_hyp_io_mappings(info->vctrl.start,
+                                    resource_size(&info->vctrl),
+                                    &kvm_vgic_global_state.vctrl_base);
+       if (ret) {
+               kvm_err("Cannot map VCTRL into hyp\n");
                goto out;
        }
 
        vtr = readl_relaxed(kvm_vgic_global_state.vctrl_base + GICH_VTR);
        kvm_vgic_global_state.nr_lr = (vtr & 0x3f) + 1;
 
-       ret = create_hyp_io_mappings(kvm_vgic_global_state.vctrl_base,
-                                    kvm_vgic_global_state.vctrl_base +
-                                        resource_size(&info->vctrl),
-                                    info->vctrl.start);
-       if (ret) {
-               kvm_err("Cannot map VCTRL into hyp\n");
-               goto out;
-       }
-
        ret = kvm_register_vgic_device(KVM_DEV_TYPE_ARM_VGIC_V2);
        if (ret) {
                kvm_err("Cannot register GICv2 KVM device\n");