powerpc/mm/radix: Simplify split mapping logic
authorMichael Ellerman <mpe@ellerman.id.au>
Tue, 14 Aug 2018 12:37:32 +0000 (22:37 +1000)
committerMichael Ellerman <mpe@ellerman.id.au>
Sat, 20 Oct 2018 02:26:47 +0000 (13:26 +1100)
If we look closely at the logic in create_physical_mapping(), when
we're doing STRICT_KERNEL_RWX, we do the following steps:
  - determine the gap from where we are to the end of the range
  - choose an appropriate mapping_size based on the gap
  - check if that mapping_size would overlap the __init_begin
    boundary, and if not choose an appropriate mapping_size

We can simplify the logic by taking the __init_begin boundary into
account when we calculate the initial gap.

So add a next_boundary() function which tells us what the next
boundary is, either the __init_begin boundary or end. In future we can
add more boundaries.

Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
arch/powerpc/mm/pgtable-radix.c

index 0305434512291bdb824c208c8de6f7a88fc5080f..0e87733eed80d63f85faf8a923b6b06c962df1cb 100644 (file)
@@ -255,17 +255,21 @@ static inline void __meminit print_mapping(unsigned long start,
        pr_info("Mapped 0x%016lx-0x%016lx with %s pages\n", start, end, buf);
 }
 
+static unsigned long next_boundary(unsigned long addr, unsigned long end)
+{
+#ifdef CONFIG_STRICT_KERNEL_RWX
+       if (addr < __pa_symbol(__init_begin))
+               return __pa_symbol(__init_begin);
+#endif
+       return end;
+}
+
 static int __meminit create_physical_mapping(unsigned long start,
                                             unsigned long end,
                                             int nid)
 {
        unsigned long vaddr, addr, mapping_size = 0;
        pgprot_t prot;
-#ifdef CONFIG_STRICT_KERNEL_RWX
-       int split_text_mapping = 1;
-#else
-       int split_text_mapping = 0;
-#endif
        int psize;
 
        start = _ALIGN_UP(start, PAGE_SIZE);
@@ -273,7 +277,7 @@ static int __meminit create_physical_mapping(unsigned long start,
                unsigned long gap, previous_size;
                int rc;
 
-               gap = end - addr;
+               gap = next_boundary(addr, end) - addr;
                previous_size = mapping_size;
 
                if (IS_ALIGNED(addr, PUD_SIZE) && gap >= PUD_SIZE &&
@@ -289,22 +293,6 @@ static int __meminit create_physical_mapping(unsigned long start,
                        psize = mmu_virtual_psize;
                }
 
-               if (split_text_mapping && (mapping_size == PUD_SIZE) &&
-                       (addr < __pa_symbol(__init_begin)) &&
-                       (addr + mapping_size) > __pa_symbol(__init_begin)) {
-                       if (mmu_psize_defs[MMU_PAGE_2M].shift)
-                               mapping_size = PMD_SIZE;
-                       else
-                               mapping_size = PAGE_SIZE;
-               }
-
-               if (split_text_mapping && (mapping_size == PMD_SIZE) &&
-                   (addr < __pa_symbol(__init_begin)) &&
-                   (addr + mapping_size) > __pa_symbol(__init_begin)) {
-                       mapping_size = PAGE_SIZE;
-                       psize = mmu_virtual_psize;
-               }
-
                if (mapping_size != previous_size) {
                        print_mapping(start, addr, previous_size);
                        start = addr;