Subject: Re: [RFC 1/7] powerpc/mm: Make vmemmap_populate accommodate ZONE_DEVICE memory

From: Balbir Singh <[email-masked]>
Date: Tue, 3 May 2016 18:04:00 +1000

On 03/05/16 16:29, Anshuman Khandual wrote:
> Change the vmemmap_populate function to detect device memory through
> to_vmemmap_altmap and then call generic the __vmmemap_alloc_block_buf
> function instead of vmemmap_alloc_block as the earlier can allocate
> physical memory from the device range instead of the system RAM.
> 
> Signed-off-by: Anshuman Khandual <[email-masked]>
> ---
>  arch/powerpc/mm/init_64.c | 6 +++++-
>  1 file changed, 5 insertions(+), 1 deletion(-)
> 
> diff --git a/arch/powerpc/mm/init_64.c b/arch/powerpc/mm/init_64.c
> index ba65566..db73708 100644
> --- a/arch/powerpc/mm/init_64.c
> +++ b/arch/powerpc/mm/init_64.c
> @@ -42,6 +42,7 @@
>  #include <linux/memblock.h>
>  #include <linux/hugetlb.h>
>  #include <linux/slab.h>
> +#include <linux/memremap.h>
>  
>  #include <asm/pgalloc.h>
>  #include <asm/page.h>
> @@ -312,6 +313,7 @@ static __meminit void vmemmap_list_populate(unsigned long phys,
>  int __meminit vmemmap_populate(unsigned long start, unsigned long end, int node)
>  {
>  	unsigned long page_size = 1 << mmu_psize_defs[mmu_vmemmap_psize].shift;
> +	unsigned long orig = start;

I would much rather do struct vmem_altmap *altmap = to_vmem_altmap(start);

>  
>  	/* Align to the page size of the linear mapping. */
>  	start = _ALIGN_DOWN(start, page_size);
> @@ -319,13 +321,15 @@ int __meminit vmemmap_populate(unsigned long start, unsigned long end, int node)
>  	pr_debug("vmemmap_populate %lx..%lx, node %d\n", start, end, node);
>  
>  	for (; start < end; start += page_size) {
> +		struct vmem_altmap *altmap;
>  		void *p;
>  		int rc;
>  
>  		if (vmemmap_populated(start, page_size))
>  			continue;
>  
> -		p = vmemmap_alloc_block(page_size, node);
> +		altmap = to_vmem_altmap((unsigned long) orig);
> +		p = __vmemmap_alloc_block_buf(page_size, node, altmap);
>  		if (!p)
>  			return -ENOMEM;
>  
>