Message ID | 20231213000452.88295-3-graf@amazon.com (mailing list archive) |
---|---|
State | Superseded |
Headers | show |
Series | kexec: Allow preservation of ftrace buffers | expand |
Hi Alexander, kernel test robot noticed the following build warnings: [auto build test WARNING on tip/x86/core] [also build test WARNING on arm64/for-next/core akpm-mm/mm-everything linus/master v6.7-rc5 next-20231213] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in https://git-scm.com/docs/git-format-patch#_base_tree_information] url: https://github.com/intel-lab-lkp/linux/commits/Alexander-Graf/mm-memblock-Add-support-for-scratch-memory/20231213-080941 base: tip/x86/core patch link: https://lore.kernel.org/r/20231213000452.88295-3-graf%40amazon.com patch subject: [PATCH 02/15] memblock: Declare scratch memory as CMA config: arc-allnoconfig (https://download.01.org/0day-ci/archive/20231213/202312131930.gMiphjju-lkp@intel.com/config) compiler: arc-elf-gcc (GCC) 13.2.0 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20231213/202312131930.gMiphjju-lkp@intel.com/reproduce) If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags | Reported-by: kernel test robot <lkp@intel.com> | Closes: https://lore.kernel.org/oe-kbuild-all/202312131930.gMiphjju-lkp@intel.com/ All warnings (new ones prefixed by >>): >> mm/memblock.c:2153:13: warning: 'reserve_scratch_mem' defined but not used [-Wunused-function] 2153 | static void reserve_scratch_mem(phys_addr_t start, phys_addr_t end) | ^~~~~~~~~~~~~~~~~~~ vim +/reserve_scratch_mem +2153 mm/memblock.c 2152 > 2153 static void reserve_scratch_mem(phys_addr_t start, phys_addr_t end) 2154 { 2155 #ifdef CONFIG_MEMBLOCK_SCRATCH 2156 ulong start_pfn = pageblock_start_pfn(PFN_DOWN(start)); 2157 ulong end_pfn = pageblock_align(PFN_UP(end)); 2158 ulong pfn; 2159 2160 for (pfn = start_pfn; pfn < end_pfn; pfn += pageblock_nr_pages) { 2161 /* Mark as CMA to prevent kernel allocations in it */ 2162 set_pageblock_migratetype(pfn_to_page(pfn), MIGRATE_CMA); 2163 } 2164 #endif 2165 } 2166
diff --git a/mm/memblock.c b/mm/memblock.c index e89e6c8f9d75..44741424dab7 100644 --- a/mm/memblock.c +++ b/mm/memblock.c @@ -16,6 +16,7 @@ #include <linux/kmemleak.h> #include <linux/seq_file.h> #include <linux/memblock.h> +#include <linux/page-isolation.h> #include <asm/sections.h> #include <linux/io.h> @@ -1100,10 +1101,6 @@ static bool should_skip_region(struct memblock_type *type, if ((flags & MEMBLOCK_SCRATCH) && !memblock_is_scratch(m)) return true; - /* Leave scratch memory alone after scratch-only phase */ - if (!(flags & MEMBLOCK_SCRATCH) && memblock_is_scratch(m)) - return true; - return false; } @@ -2153,6 +2150,20 @@ static void __init __free_pages_memory(unsigned long start, unsigned long end) } } +static void reserve_scratch_mem(phys_addr_t start, phys_addr_t end) +{ +#ifdef CONFIG_MEMBLOCK_SCRATCH + ulong start_pfn = pageblock_start_pfn(PFN_DOWN(start)); + ulong end_pfn = pageblock_align(PFN_UP(end)); + ulong pfn; + + for (pfn = start_pfn; pfn < end_pfn; pfn += pageblock_nr_pages) { + /* Mark as CMA to prevent kernel allocations in it */ + set_pageblock_migratetype(pfn_to_page(pfn), MIGRATE_CMA); + } +#endif +} + static unsigned long __init __free_memory_core(phys_addr_t start, phys_addr_t end) { @@ -2214,6 +2225,17 @@ static unsigned long __init free_low_memory_core_early(void) memmap_init_reserved_pages(); +#ifdef CONFIG_MEMBLOCK_SCRATCH + /* + * Mark scratch mem as CMA before we return it. That way we ensure that + * no kernel allocations happen on it. That means we can reuse it as + * scratch memory again later. + */ + __for_each_mem_range(i, &memblock.memory, NULL, NUMA_NO_NODE, + MEMBLOCK_SCRATCH, &start, &end, NULL) + reserve_scratch_mem(start, end); +#endif + /* * We need to use NUMA_NO_NODE instead of NODE_DATA(0)->node_id * because in some case like Node0 doesn't have RAM installed
When we finish populating our memory, we don't want to lose the scratch region as memory we can use for useful data. Do do that, we mark it as CMA memory. That means that any allocation within it only happens with movable memory which we can then happily discard for the next kexec. That way we don't lose the scratch region's memory anymore for allocations after boot. Signed-off-by: Alexander Graf <graf@amazon.com> --- mm/memblock.c | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-)