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

mm: use vmem_altmap code without CONFIG_ZONE_DEVICE

vmem_altmap_free() and vmem_altmap_offset() could be utlized without
CONFIG_ZONE_DEVICE enabled. For example,
mm/memory_hotplug.c:__add_pages() relies on that. The altmap is no longer
restricted to ZONE_DEVICE handling, but instead depends on
CONFIG_SPARSEMEM_VMEMMAP.

When CONFIG_SPARSEMEM_VMEMMAP is disabled, these functions are defined as
inline stubs, ensuring compatibility with configurations that do not use
sparsemem vmemmap. Without it, lkp reported the following:

ld: arch/x86/mm/init_64.o: in function `remove_pagetable':
init_64.c:(.meminit.text+0xfc7): undefined reference to
`vmem_altmap_free'

Link: https://lkml.kernel.org/r/20231120145354.308999-4-sumanthk@linux.ibm.com
Signed-off-by: Sumanth Korikkar <sumanthk@linux.ibm.com>
Reported-by: kernel test robot <lkp@intel.com>
Closes: https://lore.kernel.org/oe-kbuild-all/202311180545.VeyRXEDq-lkp@intel.com/
Reviewed-by: Gerald Schaefer <gerald.schaefer@linux.ibm.com>
Acked-by: David Hildenbrand <david@redhat.com>
Cc: Alexander Gordeev <agordeev@linux.ibm.com>
Cc: Aneesh Kumar K.V <aneesh.kumar@linux.ibm.com>
Cc: Anshuman Khandual <anshuman.khandual@arm.com>
Cc: Heiko Carstens <hca@linux.ibm.com>
Cc: Michal Hocko <mhocko@suse.com>
Cc: Oscar Salvador <osalvador@suse.de>
Cc: Vasily Gorbik <gor@linux.ibm.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

Sumanth Korikkar and committed by
Andrew Morton
95a2ac93 bd9d9624

+27 -25
-12
include/linux/memremap.h
··· 196 196 struct dev_pagemap *pgmap); 197 197 bool pgmap_pfn_valid(struct dev_pagemap *pgmap, unsigned long pfn); 198 198 199 - unsigned long vmem_altmap_offset(struct vmem_altmap *altmap); 200 - void vmem_altmap_free(struct vmem_altmap *altmap, unsigned long nr_pfns); 201 199 unsigned long memremap_compat_align(void); 202 200 #else 203 201 static inline void *devm_memremap_pages(struct device *dev, ··· 224 226 static inline bool pgmap_pfn_valid(struct dev_pagemap *pgmap, unsigned long pfn) 225 227 { 226 228 return false; 227 - } 228 - 229 - static inline unsigned long vmem_altmap_offset(struct vmem_altmap *altmap) 230 - { 231 - return 0; 232 - } 233 - 234 - static inline void vmem_altmap_free(struct vmem_altmap *altmap, 235 - unsigned long nr_pfns) 236 - { 237 229 } 238 230 239 231 /* when memremap_pages() is disabled all archs can remap a single page */
+26
include/linux/mm.h
··· 3871 3871 struct vmem_altmap *altmap); 3872 3872 #endif 3873 3873 3874 + #ifdef CONFIG_SPARSEMEM_VMEMMAP 3875 + static inline unsigned long vmem_altmap_offset(struct vmem_altmap *altmap) 3876 + { 3877 + /* number of pfns from base where pfn_to_page() is valid */ 3878 + if (altmap) 3879 + return altmap->reserve + altmap->free; 3880 + return 0; 3881 + } 3882 + 3883 + static inline void vmem_altmap_free(struct vmem_altmap *altmap, 3884 + unsigned long nr_pfns) 3885 + { 3886 + altmap->alloc -= nr_pfns; 3887 + } 3888 + #else 3889 + static inline unsigned long vmem_altmap_offset(struct vmem_altmap *altmap) 3890 + { 3891 + return 0; 3892 + } 3893 + 3894 + static inline void vmem_altmap_free(struct vmem_altmap *altmap, 3895 + unsigned long nr_pfns) 3896 + { 3897 + } 3898 + #endif 3899 + 3874 3900 #define VMEMMAP_RESERVE_NR 2 3875 3901 #ifdef CONFIG_ARCH_WANT_OPTIMIZE_DAX_VMEMMAP 3876 3902 static inline bool __vmemmap_can_optimize(struct vmem_altmap *altmap,
+1 -13
mm/memremap.c
··· 7 7 #include <linux/memremap.h> 8 8 #include <linux/pfn_t.h> 9 9 #include <linux/swap.h> 10 + #include <linux/mm.h> 10 11 #include <linux/mmzone.h> 11 12 #include <linux/swapops.h> 12 13 #include <linux/types.h> ··· 422 421 devm_release_action(dev, devm_memremap_pages_release, pgmap); 423 422 } 424 423 EXPORT_SYMBOL_GPL(devm_memunmap_pages); 425 - 426 - unsigned long vmem_altmap_offset(struct vmem_altmap *altmap) 427 - { 428 - /* number of pfns from base where pfn_to_page() is valid */ 429 - if (altmap) 430 - return altmap->reserve + altmap->free; 431 - return 0; 432 - } 433 - 434 - void vmem_altmap_free(struct vmem_altmap *altmap, unsigned long nr_pfns) 435 - { 436 - altmap->alloc -= nr_pfns; 437 - } 438 424 439 425 /** 440 426 * get_dev_pagemap() - take a new live reference on the dev_pagemap for @pfn