On 7/26/23 2:34 PM, David Hildenbrand wrote: > >>>> /* >>>> @@ -1310,7 +1400,10 @@ int __ref add_memory_resource(int nid, struct >>>> resource *res, mhp_t mhp_flags) >>>> { >>>> struct mhp_params params = { .pgprot = pgprot_mhp(PAGE_KERNEL) }; >>>> enum memblock_flags memblock_flags = MEMBLOCK_NONE; >>>> - struct vmem_altmap mhp_altmap = {}; >>>> + struct vmem_altmap mhp_altmap = { >>>> + .base_pfn = PHYS_PFN(res->start), >>>> + .end_pfn = PHYS_PFN(res->end), >>> >>> Is it required to set .end_pfn, and if so, shouldn't we also set it to >>> base_pfn + memory_block_memmap_on_memory_pages()) ? >>> >> >> We use that in ppc64 for checking altmap boundary condition. As we >> discussed earlier, ppc64 due to vmemmap mapping size restrictions can't >> always allocate vmemmap pages from altmap area even if requested. We >> fallback to regular memory alocation in that case (only used now with >> pmem). We use altmap.end_pfn for that boundary check. You can refer to >> altmap_cross_boundary() for more details. > > But even then, setting the end to the end of the resource size is wrong, no? > We don't want anybody to allocate beyond base_pfn + > memory_block_memmap_on_memory_pages(). >
altmap.end is the end pfn of the resource __nvdimm_setup_pfn() ... resource_size_t end = nsio->res.end - end_trunc; struct vmem_altmap __altmap = { .base_pfn = init_altmap_base(base), .reserve = init_altmap_reserve(base), .end_pfn = PHYS_PFN(end), }; And we use it to find that the page_to_pfn mapping we use by allocating a page from altmap doesn't point to a pfn that is outside the resource range. -aneesh