Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 232aa407 authored by Michael Ellerman's avatar Michael Ellerman
Browse files

powerpc/mm/radix: Simplify split mapping logic



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: default avatarMichael Ellerman <mpe@ellerman.id.au>
parent 57306c66
Loading
Loading
Loading
Loading
+10 −22
Original line number Diff line number Diff line
@@ -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;