Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

memblock: update initialization of reserved pages

The struct pages representing a reserved memory region are initialized
using reserve_bootmem_range() function. This function is called for each
reserved region just before the memory is freed from memblock to the buddy
page allocator.

The struct pages for MEMBLOCK_NOMAP regions are kept with the default
values set by the memory map initialization which makes it necessary to
have a special treatment for such pages in pfn_valid() and
pfn_valid_within().

Split out initialization of the reserved pages to a function with a
meaningful name and treat the MEMBLOCK_NOMAP regions the same way as the
reserved regions and mark struct pages for the NOMAP regions as
PageReserved.

Link: https://lkml.kernel.org/r/20210511100550.28178-3-rppt@kernel.org
Signed-off-by: Mike Rapoport <rppt@linux.ibm.com>
Reviewed-by: David Hildenbrand <david@redhat.com>
Reviewed-by: Anshuman Khandual <anshuman.khandual@arm.com>
Acked-by: Ard Biesheuvel <ardb@kernel.org>
Reviewed-by: Kefeng Wang <wangkefeng.wang@huawei.com>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Marc Zyngier <maz@kernel.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Will Deacon <will@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by

Mike Rapoport and committed by
Linus Torvalds
9092d4f7 51c656ae

+29 -3
+3 -1
include/linux/memblock.h
··· 30 30 * @MEMBLOCK_NONE: no special request 31 31 * @MEMBLOCK_HOTPLUG: hotpluggable region 32 32 * @MEMBLOCK_MIRROR: mirrored region 33 - * @MEMBLOCK_NOMAP: don't add to kernel direct mapping 33 + * @MEMBLOCK_NOMAP: don't add to kernel direct mapping and treat as 34 + * reserved in the memory map; refer to memblock_mark_nomap() description 35 + * for further details 34 36 */ 35 37 enum memblock_flags { 36 38 MEMBLOCK_NONE = 0x0, /* No special request */
+26 -2
mm/memblock.c
··· 906 906 * @base: the base phys addr of the region 907 907 * @size: the size of the region 908 908 * 909 + * The memory regions marked with %MEMBLOCK_NOMAP will not be added to the 910 + * direct mapping of the physical memory. These regions will still be 911 + * covered by the memory map. The struct page representing NOMAP memory 912 + * frames in the memory map will be PageReserved() 913 + * 909 914 * Return: 0 on success, -errno on failure. 910 915 */ 911 916 int __init_memblock memblock_mark_nomap(phys_addr_t base, phys_addr_t size) ··· 2007 2002 return end_pfn - start_pfn; 2008 2003 } 2009 2004 2005 + static void __init memmap_init_reserved_pages(void) 2006 + { 2007 + struct memblock_region *region; 2008 + phys_addr_t start, end; 2009 + u64 i; 2010 + 2011 + /* initialize struct pages for the reserved regions */ 2012 + for_each_reserved_mem_range(i, &start, &end) 2013 + reserve_bootmem_region(start, end); 2014 + 2015 + /* and also treat struct pages for the NOMAP regions as PageReserved */ 2016 + for_each_mem_region(region) { 2017 + if (memblock_is_nomap(region)) { 2018 + start = region->base; 2019 + end = start + region->size; 2020 + reserve_bootmem_region(start, end); 2021 + } 2022 + } 2023 + } 2024 + 2010 2025 static unsigned long __init free_low_memory_core_early(void) 2011 2026 { 2012 2027 unsigned long count = 0; ··· 2035 2010 2036 2011 memblock_clear_hotplug(0, -1); 2037 2012 2038 - for_each_reserved_mem_range(i, &start, &end) 2039 - reserve_bootmem_region(start, end); 2013 + memmap_init_reserved_pages(); 2040 2014 2041 2015 /* 2042 2016 * We need to use NUMA_NO_NODE instead of NODE_DATA(0)->node_id