powerpc/mm/radix: Remove the retry in the split mapping logic
authorMichael Ellerman <mpe@ellerman.id.au>
Tue, 14 Aug 2018 12:01:44 +0000 (22:01 +1000)
committerMichael Ellerman <mpe@ellerman.id.au>
Sat, 20 Oct 2018 02:26:47 +0000 (13:26 +1100)
When we have CONFIG_STRICT_KERNEL_RWX enabled, we want to split the
linear mapping at the text/data boundary so we can map the kernel
text read only.

The current logic uses a goto inside the for loop, which works, but is
hard to reason about.

When we hit the goto retry case we set max_mapping_size to PMD_SIZE
and go back to the start.

Setting max_mapping_size means we skip the PUD case and go to the PMD
case.

We know we will pass the alignment and gap checks because the only
reason we are there is we hit the goto retry, and that is guarded by
mapping_size == PUD_SIZE, which means addr is PUD aligned and gap is
greater or equal to PUD_SIZE.

So the only part of the check that can fail is the mmu_psize_defs
check for the 2M page size.

If we just duplicate that check we can avoid the goto, and we get the
same result.

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

index 7a44ec2762902caa572a40a4948aa3568fefd4e5..0305434512291bdb824c208c8de6f7a88fc5080f 100644 (file)
@@ -261,7 +261,6 @@ static int __meminit create_physical_mapping(unsigned long start,
 {
        unsigned long vaddr, addr, mapping_size = 0;
        pgprot_t prot;
-       unsigned long max_mapping_size;
 #ifdef CONFIG_STRICT_KERNEL_RWX
        int split_text_mapping = 1;
 #else
@@ -276,12 +275,9 @@ static int __meminit create_physical_mapping(unsigned long start,
 
                gap = end - addr;
                previous_size = mapping_size;
-               max_mapping_size = PUD_SIZE;
 
-retry:
                if (IS_ALIGNED(addr, PUD_SIZE) && gap >= PUD_SIZE &&
-                   mmu_psize_defs[MMU_PAGE_1G].shift &&
-                   PUD_SIZE <= max_mapping_size) {
+                   mmu_psize_defs[MMU_PAGE_1G].shift) {
                        mapping_size = PUD_SIZE;
                        psize = MMU_PAGE_1G;
                } else if (IS_ALIGNED(addr, PMD_SIZE) && gap >= PMD_SIZE &&
@@ -296,8 +292,10 @@ retry:
                if (split_text_mapping && (mapping_size == PUD_SIZE) &&
                        (addr < __pa_symbol(__init_begin)) &&
                        (addr + mapping_size) > __pa_symbol(__init_begin)) {
-                       max_mapping_size = PMD_SIZE;
-                       goto retry;
+                       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) &&