Commit 07aabe8f authored by Jisheng Zhang's avatar Jisheng Zhang Committed by Palmer Dabbelt

riscv: mm: init: try best to use IS_ENABLED(CONFIG_64BIT) instead of #ifdef

Try our best to replace the conditional compilation using
"#ifdef CONFIG_64BIT" by a check for "IS_ENABLED(CONFIG_64BIT)", to
simplify the code and to increase compile coverage.

Now we can also remove the __maybe_unused used in max_mapped_addr
declaration.

We also remove the BUG_ON check of mapping the last 4K bytes of the
addressable memory since this is always true for every kernel actually.
Signed-off-by: default avatarJisheng Zhang <jszhang@kernel.org>
Reviewed-by: default avatarAlexandre Ghiti <alex@ghiti.fr>
Signed-off-by: default avatarPalmer Dabbelt <palmer@rivosinc.com>
parent 902d6364
...@@ -102,10 +102,9 @@ static void __init print_vm_layout(void) ...@@ -102,10 +102,9 @@ static void __init print_vm_layout(void)
(unsigned long)VMALLOC_END); (unsigned long)VMALLOC_END);
print_mlm("lowmem", (unsigned long)PAGE_OFFSET, print_mlm("lowmem", (unsigned long)PAGE_OFFSET,
(unsigned long)high_memory); (unsigned long)high_memory);
#ifdef CONFIG_64BIT if (IS_ENABLED(CONFIG_64BIT))
print_mlm("kernel", (unsigned long)KERNEL_LINK_ADDR, print_mlm("kernel", (unsigned long)KERNEL_LINK_ADDR,
(unsigned long)ADDRESS_SPACE_END); (unsigned long)ADDRESS_SPACE_END);
#endif
} }
#else #else
static void print_vm_layout(void) { } static void print_vm_layout(void) { }
...@@ -163,7 +162,7 @@ static void __init setup_bootmem(void) ...@@ -163,7 +162,7 @@ static void __init setup_bootmem(void)
{ {
phys_addr_t vmlinux_end = __pa_symbol(&_end); phys_addr_t vmlinux_end = __pa_symbol(&_end);
phys_addr_t vmlinux_start = __pa_symbol(&_start); phys_addr_t vmlinux_start = __pa_symbol(&_start);
phys_addr_t __maybe_unused max_mapped_addr; phys_addr_t max_mapped_addr;
phys_addr_t phys_ram_end; phys_addr_t phys_ram_end;
#ifdef CONFIG_XIP_KERNEL #ifdef CONFIG_XIP_KERNEL
...@@ -172,17 +171,16 @@ static void __init setup_bootmem(void) ...@@ -172,17 +171,16 @@ static void __init setup_bootmem(void)
memblock_enforce_memory_limit(memory_limit); memblock_enforce_memory_limit(memory_limit);
/*
* Reserve from the start of the kernel to the end of the kernel
*/
#if defined(CONFIG_64BIT) && defined(CONFIG_STRICT_KERNEL_RWX)
/* /*
* Make sure we align the reservation on PMD_SIZE since we will * Make sure we align the reservation on PMD_SIZE since we will
* map the kernel in the linear mapping as read-only: we do not want * map the kernel in the linear mapping as read-only: we do not want
* any allocation to happen between _end and the next pmd aligned page. * any allocation to happen between _end and the next pmd aligned page.
*/ */
vmlinux_end = (vmlinux_end + PMD_SIZE - 1) & PMD_MASK; if (IS_ENABLED(CONFIG_64BIT) && IS_ENABLED(CONFIG_STRICT_KERNEL_RWX))
#endif vmlinux_end = (vmlinux_end + PMD_SIZE - 1) & PMD_MASK;
/*
* Reserve from the start of the kernel to the end of the kernel
*/
memblock_reserve(vmlinux_start, vmlinux_end - vmlinux_start); memblock_reserve(vmlinux_start, vmlinux_end - vmlinux_start);
...@@ -190,7 +188,6 @@ static void __init setup_bootmem(void) ...@@ -190,7 +188,6 @@ static void __init setup_bootmem(void)
#ifndef CONFIG_XIP_KERNEL #ifndef CONFIG_XIP_KERNEL
phys_ram_base = memblock_start_of_DRAM(); phys_ram_base = memblock_start_of_DRAM();
#endif #endif
#ifndef CONFIG_64BIT
/* /*
* memblock allocator is not aware of the fact that last 4K bytes of * memblock allocator is not aware of the fact that last 4K bytes of
* the addressable memory can not be mapped because of IS_ERR_VALUE * the addressable memory can not be mapped because of IS_ERR_VALUE
...@@ -200,10 +197,11 @@ static void __init setup_bootmem(void) ...@@ -200,10 +197,11 @@ static void __init setup_bootmem(void)
* address space is occupied by the kernel mapping then this check must * address space is occupied by the kernel mapping then this check must
* be done as soon as the kernel mapping base address is determined. * be done as soon as the kernel mapping base address is determined.
*/ */
max_mapped_addr = __pa(~(ulong)0); if (!IS_ENABLED(CONFIG_64BIT)) {
if (max_mapped_addr == (phys_ram_end - 1)) max_mapped_addr = __pa(~(ulong)0);
memblock_set_current_limit(max_mapped_addr - 4096); if (max_mapped_addr == (phys_ram_end - 1))
#endif memblock_set_current_limit(max_mapped_addr - 4096);
}
min_low_pfn = PFN_UP(phys_ram_base); min_low_pfn = PFN_UP(phys_ram_base);
max_low_pfn = max_pfn = PFN_DOWN(phys_ram_end); max_low_pfn = max_pfn = PFN_DOWN(phys_ram_end);
...@@ -617,14 +615,6 @@ asmlinkage void __init setup_vm(uintptr_t dtb_pa) ...@@ -617,14 +615,6 @@ asmlinkage void __init setup_vm(uintptr_t dtb_pa)
BUG_ON((PAGE_OFFSET % PGDIR_SIZE) != 0); BUG_ON((PAGE_OFFSET % PGDIR_SIZE) != 0);
BUG_ON((kernel_map.phys_addr % PMD_SIZE) != 0); BUG_ON((kernel_map.phys_addr % PMD_SIZE) != 0);
#ifdef CONFIG_64BIT
/*
* The last 4K bytes of the addressable memory can not be mapped because
* of IS_ERR_VALUE macro.
*/
BUG_ON((kernel_map.virt_addr + kernel_map.size) > ADDRESS_SPACE_END - SZ_4K);
#endif
pt_ops.alloc_pte = alloc_pte_early; pt_ops.alloc_pte = alloc_pte_early;
pt_ops.get_pte_virt = get_pte_virt_early; pt_ops.get_pte_virt = get_pte_virt_early;
#ifndef __PAGETABLE_PMD_FOLDED #ifndef __PAGETABLE_PMD_FOLDED
...@@ -736,10 +726,9 @@ static void __init setup_vm_final(void) ...@@ -736,10 +726,9 @@ static void __init setup_vm_final(void)
} }
} }
#ifdef CONFIG_64BIT
/* Map the kernel */ /* Map the kernel */
create_kernel_page_table(swapper_pg_dir, false); if (IS_ENABLED(CONFIG_64BIT))
#endif create_kernel_page_table(swapper_pg_dir, false);
/* Clear fixmap PTE and PMD mappings */ /* Clear fixmap PTE and PMD mappings */
clear_fixmap(FIX_PTE); clear_fixmap(FIX_PTE);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment