Skip to content

Commit db6b84a

Browse files
AlexGhitipalmer-dabbelt
authored andcommitted
riscv: Make sure the kernel mapping does not overlap with IS_ERR_VALUE
The check that is done in setup_bootmem currently only works for 32-bit kernel since the kernel mapping has been moved outside of the linear mapping for 64-bit kernel. So make sure that for 64-bit kernel, the kernel mapping does not overlap with the last 4K of the addressable memory. Signed-off-by: Alexandre Ghiti <[email protected]> Fixes: 2bfc6cd ("riscv: Move kernel mapping outside of linear mapping") Signed-off-by: Palmer Dabbelt <[email protected]>
1 parent c99127c commit db6b84a

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

arch/riscv/mm/init.c

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ static void __init setup_bootmem(void)
159159
{
160160
phys_addr_t vmlinux_end = __pa_symbol(&_end);
161161
phys_addr_t vmlinux_start = __pa_symbol(&_start);
162-
phys_addr_t max_mapped_addr = __pa(~(ulong)0);
162+
phys_addr_t __maybe_unused max_mapped_addr;
163163
phys_addr_t dram_end;
164164

165165
#ifdef CONFIG_XIP_KERNEL
@@ -183,14 +183,20 @@ static void __init setup_bootmem(void)
183183

184184
dram_end = memblock_end_of_DRAM();
185185

186+
#ifndef CONFIG_64BIT
186187
/*
187188
* memblock allocator is not aware of the fact that last 4K bytes of
188189
* the addressable memory can not be mapped because of IS_ERR_VALUE
189190
* macro. Make sure that last 4k bytes are not usable by memblock
190-
* if end of dram is equal to maximum addressable memory.
191+
* if end of dram is equal to maximum addressable memory. For 64-bit
192+
* kernel, this problem can't happen here as the end of the virtual
193+
* address space is occupied by the kernel mapping then this check must
194+
* be done in create_kernel_page_table.
191195
*/
196+
max_mapped_addr = __pa(~(ulong)0);
192197
if (max_mapped_addr == (dram_end - 1))
193198
memblock_set_current_limit(max_mapped_addr - 4096);
199+
#endif
194200

195201
min_low_pfn = PFN_UP(memblock_start_of_DRAM());
196202
max_low_pfn = max_pfn = PFN_DOWN(dram_end);
@@ -578,6 +584,14 @@ asmlinkage void __init setup_vm(uintptr_t dtb_pa)
578584
BUG_ON((PAGE_OFFSET % PGDIR_SIZE) != 0);
579585
BUG_ON((kernel_map.phys_addr % map_size) != 0);
580586

587+
#ifdef CONFIG_64BIT
588+
/*
589+
* The last 4K bytes of the addressable memory can not be mapped because
590+
* of IS_ERR_VALUE macro.
591+
*/
592+
BUG_ON((kernel_map.virt_addr + kernel_map.size) > ADDRESS_SPACE_END - SZ_4K);
593+
#endif
594+
581595
pt_ops.alloc_pte = alloc_pte_early;
582596
pt_ops.get_pte_virt = get_pte_virt_early;
583597
#ifndef __PAGETABLE_PMD_FOLDED

0 commit comments

Comments
 (0)