Skip to content

Commit 1bd14a6

Browse files
atishp04palmer-dabbelt
authored andcommitted
RISC-V: Remove any memblock representing unusable memory area
RISC-V limits the physical memory size by -PAGE_OFFSET. Any memory beyond that size from DRAM start is unusable. Just remove any memblock pointing to those memory region without worrying about computing the maximum size. Signed-off-by: Atish Patra <atish.patra@wdc.com> Reviewed-by: Mike Rapoport <rppt@linux.ibm.com> Signed-off-by: Palmer Dabbelt <palmerdabbelt@google.com>
1 parent 9d750c7 commit 1bd14a6

1 file changed

Lines changed: 7 additions & 11 deletions

File tree

arch/riscv/mm/init.c

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -154,31 +154,27 @@ static void __init setup_initrd(void)
154154

155155
void __init setup_bootmem(void)
156156
{
157-
phys_addr_t mem_size = 0;
158-
phys_addr_t total_mem = 0;
159-
phys_addr_t mem_start, start, end = 0;
157+
phys_addr_t mem_start = 0;
158+
phys_addr_t start, end = 0;
160159
phys_addr_t vmlinux_end = __pa_symbol(&_end);
161160
phys_addr_t vmlinux_start = __pa_symbol(&_start);
162161
u64 i;
163162

164163
/* Find the memory region containing the kernel */
165164
for_each_mem_range(i, &start, &end) {
166165
phys_addr_t size = end - start;
167-
if (!total_mem)
166+
if (!mem_start)
168167
mem_start = start;
169168
if (start <= vmlinux_start && vmlinux_end <= end)
170169
BUG_ON(size == 0);
171-
total_mem = total_mem + size;
172170
}
173171

174172
/*
175-
* Remove memblock from the end of usable area to the
176-
* end of region
173+
* The maximal physical memory size is -PAGE_OFFSET.
174+
* Make sure that any memory beyond mem_start + (-PAGE_OFFSET) is removed
175+
* as it is unusable by kernel.
177176
*/
178-
mem_size = min(total_mem, (phys_addr_t)-PAGE_OFFSET);
179-
if (mem_start + mem_size < end)
180-
memblock_remove(mem_start + mem_size,
181-
end - mem_start - mem_size);
177+
memblock_enforce_memory_limit(mem_start - PAGE_OFFSET);
182178

183179
/* Reserve from the start of the kernel to the end of the kernel */
184180
memblock_reserve(vmlinux_start, vmlinux_end - vmlinux_start);

0 commit comments

Comments
 (0)