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 <m...@ellerman.id.au>
---
 arch/powerpc/mm/pgtable-radix.c | 32 ++++++++++----------------------
 1 file changed, 10 insertions(+), 22 deletions(-)

diff --git a/arch/powerpc/mm/pgtable-radix.c b/arch/powerpc/mm/pgtable-radix.c
index 030543451229..0e87733eed80 100644
--- a/arch/powerpc/mm/pgtable-radix.c
+++ b/arch/powerpc/mm/pgtable-radix.c
@@ -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;
-- 
2.17.2

Reply via email to