LinuxPPC-Dev Archive on lore.kernel.org
 help / color / mirror / Atom feed
* Re: [RFC PATCH 11/29] memblock: replace alloc_bootmem_pages_nopanic with memblock_alloc_nopanic
From: Michal Hocko @ 2018-09-06  7:53 UTC (permalink / raw)
  To: Mike Rapoport
  Cc: linux-mm, Andrew Morton, David S. Miller, Greg Kroah-Hartman,
	Ingo Molnar, Michael Ellerman, Paul Burton, Thomas Gleixner,
	Tony Luck, linux-ia64, linux-mips, linuxppc-dev, sparclinux,
	linux-kernel
In-Reply-To: <1536163184-26356-12-git-send-email-rppt@linux.vnet.ibm.com>

On Wed 05-09-18 18:59:26, Mike Rapoport wrote:
> The alloc_bootmem_pages_nopanic(size) is a shortcut for
> __alloc_bootmem_nopanic(x, PAGE_SIZE, BOOTMEM_LOW_LIMIT) and can be
> replaced by memblock_alloc_nopanic(size, PAGE_SIZE)

It is not so straightforward because you really have to go deep down the
callpath to see they are doing the same thing essentially.

> Signed-off-by: Mike Rapoport <rppt@linux.vnet.ibm.com>

Acked-by: Michal Hocko <mhocko@suse.com>

> ---
>  drivers/usb/early/xhci-dbc.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/usb/early/xhci-dbc.c b/drivers/usb/early/xhci-dbc.c
> index e15e896..16df968 100644
> --- a/drivers/usb/early/xhci-dbc.c
> +++ b/drivers/usb/early/xhci-dbc.c
> @@ -94,7 +94,7 @@ static void * __init xdbc_get_page(dma_addr_t *dma_addr)
>  {
>  	void *virt;
>  
> -	virt = alloc_bootmem_pages_nopanic(PAGE_SIZE);
> +	virt = memblock_alloc_nopanic(PAGE_SIZE, PAGE_SIZE);
>  	if (!virt)
>  		return NULL;
>  
> -- 
> 2.7.4
> 

-- 
Michal Hocko
SUSE Labs

^ permalink raw reply

* Re: [RFC PATCH 12/29] memblock: replace alloc_bootmem_low with memblock_alloc_low
From: Michal Hocko @ 2018-09-06  7:55 UTC (permalink / raw)
  To: Mike Rapoport
  Cc: linux-mm, Andrew Morton, David S. Miller, Greg Kroah-Hartman,
	Ingo Molnar, Michael Ellerman, Paul Burton, Thomas Gleixner,
	Tony Luck, linux-ia64, linux-mips, linuxppc-dev, sparclinux,
	linux-kernel
In-Reply-To: <1536163184-26356-13-git-send-email-rppt@linux.vnet.ibm.com>

On Wed 05-09-18 18:59:27, Mike Rapoport wrote:
> The alloc_bootmem_low(size) allocates low memory with default alignement
> and can be replcaed by memblock_alloc_low(size, 0)
> 
> Signed-off-by: Mike Rapoport <rppt@linux.vnet.ibm.com>

Again _virt renaming thing...
Acked-by: Michal Hocko <mhocko@suse.com>

> ---
>  arch/arm64/kernel/setup.c     | 2 +-
>  arch/unicore32/kernel/setup.c | 2 +-
>  2 files changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/arch/arm64/kernel/setup.c b/arch/arm64/kernel/setup.c
> index 5b4fac4..cf7a7b7 100644
> --- a/arch/arm64/kernel/setup.c
> +++ b/arch/arm64/kernel/setup.c
> @@ -213,7 +213,7 @@ static void __init request_standard_resources(void)
>  	kernel_data.end     = __pa_symbol(_end - 1);
>  
>  	for_each_memblock(memory, region) {
> -		res = alloc_bootmem_low(sizeof(*res));
> +		res = memblock_alloc_low(sizeof(*res), 0);
>  		if (memblock_is_nomap(region)) {
>  			res->name  = "reserved";
>  			res->flags = IORESOURCE_MEM;
> diff --git a/arch/unicore32/kernel/setup.c b/arch/unicore32/kernel/setup.c
> index c2bffa5..9f163f9 100644
> --- a/arch/unicore32/kernel/setup.c
> +++ b/arch/unicore32/kernel/setup.c
> @@ -207,7 +207,7 @@ request_standard_resources(struct meminfo *mi)
>  		if (mi->bank[i].size == 0)
>  			continue;
>  
> -		res = alloc_bootmem_low(sizeof(*res));
> +		res = memblock_alloc_low(sizeof(*res), 0);
>  		res->name  = "System RAM";
>  		res->start = mi->bank[i].start;
>  		res->end   = mi->bank[i].start + mi->bank[i].size - 1;
> -- 
> 2.7.4
> 

-- 
Michal Hocko
SUSE Labs

^ permalink raw reply

* Re: [RFC PATCH 13/29] memblock: replace __alloc_bootmem_nopanic with memblock_alloc_from_nopanic
From: Michal Hocko @ 2018-09-06  7:57 UTC (permalink / raw)
  To: Mike Rapoport
  Cc: linux-mm, Andrew Morton, David S. Miller, Greg Kroah-Hartman,
	Ingo Molnar, Michael Ellerman, Paul Burton, Thomas Gleixner,
	Tony Luck, linux-ia64, linux-mips, linuxppc-dev, sparclinux,
	linux-kernel
In-Reply-To: <1536163184-26356-14-git-send-email-rppt@linux.vnet.ibm.com>

On Wed 05-09-18 18:59:28, Mike Rapoport wrote:
> Signed-off-by: Mike Rapoport <rppt@linux.vnet.ibm.com>

The translation is simpler here but still a word or two would be nice.
Empty changelogs suck.

To the change
Acked-by: Michal Hocko <mhocko@suse.com>

> ---
>  arch/arc/kernel/unwind.c       | 4 ++--
>  arch/x86/kernel/setup_percpu.c | 4 ++--
>  2 files changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/arch/arc/kernel/unwind.c b/arch/arc/kernel/unwind.c
> index 183391d..2a01dd1 100644
> --- a/arch/arc/kernel/unwind.c
> +++ b/arch/arc/kernel/unwind.c
> @@ -181,8 +181,8 @@ static void init_unwind_hdr(struct unwind_table *table,
>   */
>  static void *__init unw_hdr_alloc_early(unsigned long sz)
>  {
> -	return __alloc_bootmem_nopanic(sz, sizeof(unsigned int),
> -				       MAX_DMA_ADDRESS);
> +	return memblock_alloc_from_nopanic(sz, sizeof(unsigned int),
> +					   MAX_DMA_ADDRESS);
>  }
>  
>  static void *unw_hdr_alloc(unsigned long sz)
> diff --git a/arch/x86/kernel/setup_percpu.c b/arch/x86/kernel/setup_percpu.c
> index 67d48e26..041663a 100644
> --- a/arch/x86/kernel/setup_percpu.c
> +++ b/arch/x86/kernel/setup_percpu.c
> @@ -106,7 +106,7 @@ static void * __init pcpu_alloc_bootmem(unsigned int cpu, unsigned long size,
>  	void *ptr;
>  
>  	if (!node_online(node) || !NODE_DATA(node)) {
> -		ptr = __alloc_bootmem_nopanic(size, align, goal);
> +		ptr = memblock_alloc_from_nopanic(size, align, goal);
>  		pr_info("cpu %d has no node %d or node-local memory\n",
>  			cpu, node);
>  		pr_debug("per cpu data for cpu%d %lu bytes at %016lx\n",
> @@ -121,7 +121,7 @@ static void * __init pcpu_alloc_bootmem(unsigned int cpu, unsigned long size,
>  	}
>  	return ptr;
>  #else
> -	return __alloc_bootmem_nopanic(size, align, goal);
> +	return memblock_alloc_from_nopanic(size, align, goal);
>  #endif
>  }
>  
> -- 
> 2.7.4
> 

-- 
Michal Hocko
SUSE Labs

^ permalink raw reply

* Re: [RFC PATCH 14/29] memblock: add align parameter to memblock_alloc_node()
From: Michal Hocko @ 2018-09-06  8:06 UTC (permalink / raw)
  To: Mike Rapoport
  Cc: linux-mm, Andrew Morton, David S. Miller, Greg Kroah-Hartman,
	Ingo Molnar, Michael Ellerman, Paul Burton, Thomas Gleixner,
	Tony Luck, linux-ia64, linux-mips, linuxppc-dev, sparclinux,
	linux-kernel
In-Reply-To: <1536163184-26356-15-git-send-email-rppt@linux.vnet.ibm.com>

On Wed 05-09-18 18:59:29, Mike Rapoport wrote:
> With the align parameter memblock_alloc_node() can be used as drop in
> replacement for alloc_bootmem_pages_node().

Why do we need an additional translation later? Sparse code which is the
only one to use it already uses memblock_alloc_try_nid elsewhere
(sparse_mem_map_populate).
 
> Signed-off-by: Mike Rapoport <rppt@linux.vnet.ibm.com>
> ---
>  include/linux/bootmem.h | 4 ++--
>  mm/sparse.c             | 2 +-
>  2 files changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/include/linux/bootmem.h b/include/linux/bootmem.h
> index 7d91f0f..3896af2 100644
> --- a/include/linux/bootmem.h
> +++ b/include/linux/bootmem.h
> @@ -157,9 +157,9 @@ static inline void * __init memblock_alloc_from_nopanic(
>  }
>  
>  static inline void * __init memblock_alloc_node(
> -						phys_addr_t size, int nid)
> +		phys_addr_t size, phys_addr_t align, int nid)
>  {
> -	return memblock_alloc_try_nid(size, 0, BOOTMEM_LOW_LIMIT,
> +	return memblock_alloc_try_nid(size, align, BOOTMEM_LOW_LIMIT,
>  					    BOOTMEM_ALLOC_ACCESSIBLE, nid);
>  }
>  
> diff --git a/mm/sparse.c b/mm/sparse.c
> index 04e97af..509828f 100644
> --- a/mm/sparse.c
> +++ b/mm/sparse.c
> @@ -68,7 +68,7 @@ static noinline struct mem_section __ref *sparse_index_alloc(int nid)
>  	if (slab_is_available())
>  		section = kzalloc_node(array_size, GFP_KERNEL, nid);
>  	else
> -		section = memblock_alloc_node(array_size, nid);
> +		section = memblock_alloc_node(array_size, 0, nid);
>  
>  	return section;
>  }
> -- 
> 2.7.4
> 

-- 
Michal Hocko
SUSE Labs

^ permalink raw reply

* Re: [RFC PATCH 15/29] memblock: replace alloc_bootmem_pages_node with memblock_alloc_node
From: Michal Hocko @ 2018-09-06  8:08 UTC (permalink / raw)
  To: Mike Rapoport
  Cc: linux-mm, Andrew Morton, David S. Miller, Greg Kroah-Hartman,
	Ingo Molnar, Michael Ellerman, Paul Burton, Thomas Gleixner,
	Tony Luck, linux-ia64, linux-mips, linuxppc-dev, sparclinux,
	linux-kernel
In-Reply-To: <1536163184-26356-16-git-send-email-rppt@linux.vnet.ibm.com>

On Wed 05-09-18 18:59:30, Mike Rapoport wrote:
> Signed-off-by: Mike Rapoport <rppt@linux.vnet.ibm.com>

again a short work of wisdom please.

The change itself looks good.
Acked-by: Michal Hocko <mhocko@suse.com>

> ---
>  arch/ia64/mm/init.c | 8 ++++----
>  1 file changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/arch/ia64/mm/init.c b/arch/ia64/mm/init.c
> index 3b85c3e..ffcc358 100644
> --- a/arch/ia64/mm/init.c
> +++ b/arch/ia64/mm/init.c
> @@ -447,19 +447,19 @@ int __init create_mem_map_page_table(u64 start, u64 end, void *arg)
>  	for (address = start_page; address < end_page; address += PAGE_SIZE) {
>  		pgd = pgd_offset_k(address);
>  		if (pgd_none(*pgd))
> -			pgd_populate(&init_mm, pgd, alloc_bootmem_pages_node(NODE_DATA(node), PAGE_SIZE));
> +			pgd_populate(&init_mm, pgd, memblock_alloc_node(PAGE_SIZE, PAGE_SIZE, node));
>  		pud = pud_offset(pgd, address);
>  
>  		if (pud_none(*pud))
> -			pud_populate(&init_mm, pud, alloc_bootmem_pages_node(NODE_DATA(node), PAGE_SIZE));
> +			pud_populate(&init_mm, pud, memblock_alloc_node(PAGE_SIZE, PAGE_SIZE, node));
>  		pmd = pmd_offset(pud, address);
>  
>  		if (pmd_none(*pmd))
> -			pmd_populate_kernel(&init_mm, pmd, alloc_bootmem_pages_node(NODE_DATA(node), PAGE_SIZE));
> +			pmd_populate_kernel(&init_mm, pmd, memblock_alloc_node(PAGE_SIZE, PAGE_SIZE, node));
>  		pte = pte_offset_kernel(pmd, address);
>  
>  		if (pte_none(*pte))
> -			set_pte(pte, pfn_pte(__pa(alloc_bootmem_pages_node(NODE_DATA(node), PAGE_SIZE)) >> PAGE_SHIFT,
> +			set_pte(pte, pfn_pte(__pa(memblock_alloc_node(PAGE_SIZE, PAGE_SIZE, node))) >> PAGE_SHIFT,
>  					     PAGE_KERNEL));
>  	}
>  	return 0;
> -- 
> 2.7.4
> 

-- 
Michal Hocko
SUSE Labs

^ permalink raw reply

* Re: [RFC PATCH 04/29] mm: remove bootmem allocator implementation.
From: Michal Hocko @ 2018-09-06  8:31 UTC (permalink / raw)
  To: Mike Rapoport
  Cc: linux-mm, Andrew Morton, David S. Miller, Greg Kroah-Hartman,
	Ingo Molnar, Michael Ellerman, Paul Burton, Thomas Gleixner,
	Tony Luck, linux-ia64, linux-mips, linuxppc-dev, sparclinux,
	linux-kernel
In-Reply-To: <20180906073023.GO14951@dhcp22.suse.cz>

On Thu 06-09-18 09:30:23, Michal Hocko wrote:
> Is there any reason to keep
> 
> ifdef CONFIG_NO_BOOTMEM
> 	obj-y		+= nobootmem.o
> else
> 	obj-y		+= bootmem.o
> endif
> 
> behind?

I can see you have done so in an earlier patch. I have missed that.
-- 
Michal Hocko
SUSE Labs

^ permalink raw reply

* Re: [RFC PATCH 16/29] memblock: replace __alloc_bootmem_node with appropriate memblock_ API
From: Michal Hocko @ 2018-09-06  8:38 UTC (permalink / raw)
  To: Mike Rapoport
  Cc: linux-mm, Andrew Morton, David S. Miller, Greg Kroah-Hartman,
	Ingo Molnar, Michael Ellerman, Paul Burton, Thomas Gleixner,
	Tony Luck, linux-ia64, linux-mips, linuxppc-dev, sparclinux,
	linux-kernel
In-Reply-To: <1536163184-26356-17-git-send-email-rppt@linux.vnet.ibm.com>

On Wed 05-09-18 18:59:31, Mike Rapoport wrote:
> Use memblock_alloc_try_nid whenever goal (i.e. mininal address is
> specified) and memblock_alloc_node otherwise.

I suspect you wanted to say (i.e. minimal address) is specified

> Signed-off-by: Mike Rapoport <rppt@linux.vnet.ibm.com>

Acked-by: Michal Hocko <mhocko@suse.com>

One note below

> ---
>  arch/ia64/mm/discontig.c       |  6 ++++--
>  arch/ia64/mm/init.c            |  2 +-
>  arch/powerpc/kernel/setup_64.c |  6 ++++--
>  arch/sparc/kernel/setup_64.c   | 10 ++++------
>  arch/sparc/kernel/smp_64.c     |  4 ++--
>  5 files changed, 15 insertions(+), 13 deletions(-)
> 
> diff --git a/arch/ia64/mm/discontig.c b/arch/ia64/mm/discontig.c
> index 1928d57..918dda9 100644
> --- a/arch/ia64/mm/discontig.c
> +++ b/arch/ia64/mm/discontig.c
> @@ -451,8 +451,10 @@ static void __init *memory_less_node_alloc(int nid, unsigned long pernodesize)
>  	if (bestnode == -1)
>  		bestnode = anynode;
>  
> -	ptr = __alloc_bootmem_node(pgdat_list[bestnode], pernodesize,
> -		PERCPU_PAGE_SIZE, __pa(MAX_DMA_ADDRESS));
> +	ptr = memblock_alloc_try_nid(pernodesize, PERCPU_PAGE_SIZE,
> +				     __pa(MAX_DMA_ADDRESS),
> +				     BOOTMEM_ALLOC_ACCESSIBLE,
> +				     bestnode);
>  
>  	return ptr;
>  }
> diff --git a/arch/ia64/mm/init.c b/arch/ia64/mm/init.c
> index ffcc358..2169ca5 100644
> --- a/arch/ia64/mm/init.c
> +++ b/arch/ia64/mm/init.c
> @@ -459,7 +459,7 @@ int __init create_mem_map_page_table(u64 start, u64 end, void *arg)
>  		pte = pte_offset_kernel(pmd, address);
>  
>  		if (pte_none(*pte))
> -			set_pte(pte, pfn_pte(__pa(memblock_alloc_node(PAGE_SIZE, PAGE_SIZE, node))) >> PAGE_SHIFT,
> +			set_pte(pte, pfn_pte(__pa(memblock_alloc_node(PAGE_SIZE, PAGE_SIZE, node)) >> PAGE_SHIFT,
>  					     PAGE_KERNEL));

This doesn't seem to belong to the patch, right?

>  	}
>  	return 0;
-- 
Michal Hocko
SUSE Labs

^ permalink raw reply

* Re: [RFC PATCH 17/29] memblock: replace alloc_bootmem_node with memblock_alloc_node
From: Michal Hocko @ 2018-09-06  8:41 UTC (permalink / raw)
  To: Mike Rapoport
  Cc: linux-mm, Andrew Morton, David S. Miller, Greg Kroah-Hartman,
	Ingo Molnar, Michael Ellerman, Paul Burton, Thomas Gleixner,
	Tony Luck, linux-ia64, linux-mips, linuxppc-dev, sparclinux,
	linux-kernel
In-Reply-To: <1536163184-26356-18-git-send-email-rppt@linux.vnet.ibm.com>

On Wed 05-09-18 18:59:32, Mike Rapoport wrote:
> Signed-off-by: Mike Rapoport <rppt@linux.vnet.ibm.com>

ENOCHAGELOG again

The conversion itself looks good to me
Acked-by: Michal Hocko <mhocko@suse.com>

> ---
>  arch/alpha/kernel/pci_iommu.c   | 4 ++--
>  arch/ia64/sn/kernel/io_common.c | 7 ++-----
>  arch/ia64/sn/kernel/setup.c     | 4 ++--
>  3 files changed, 6 insertions(+), 9 deletions(-)
> 
> diff --git a/arch/alpha/kernel/pci_iommu.c b/arch/alpha/kernel/pci_iommu.c
> index 6923b0d..b52d76f 100644
> --- a/arch/alpha/kernel/pci_iommu.c
> +++ b/arch/alpha/kernel/pci_iommu.c
> @@ -74,7 +74,7 @@ iommu_arena_new_node(int nid, struct pci_controller *hose, dma_addr_t base,
>  
>  #ifdef CONFIG_DISCONTIGMEM
>  
> -	arena = alloc_bootmem_node(NODE_DATA(nid), sizeof(*arena));
> +	arena = memblock_alloc_node(sizeof(*arena), align, nid);
>  	if (!NODE_DATA(nid) || !arena) {
>  		printk("%s: couldn't allocate arena from node %d\n"
>  		       "    falling back to system-wide allocation\n",
> @@ -82,7 +82,7 @@ iommu_arena_new_node(int nid, struct pci_controller *hose, dma_addr_t base,
>  		arena = alloc_bootmem(sizeof(*arena));
>  	}
>  
> -	arena->ptes = __alloc_bootmem_node(NODE_DATA(nid), mem_size, align, 0);
> +	arena->ptes = memblock_alloc_node(sizeof(*arena), align, nid);
>  	if (!NODE_DATA(nid) || !arena->ptes) {
>  		printk("%s: couldn't allocate arena ptes from node %d\n"
>  		       "    falling back to system-wide allocation\n",
> diff --git a/arch/ia64/sn/kernel/io_common.c b/arch/ia64/sn/kernel/io_common.c
> index 102aaba..8b05d55 100644
> --- a/arch/ia64/sn/kernel/io_common.c
> +++ b/arch/ia64/sn/kernel/io_common.c
> @@ -385,16 +385,13 @@ void __init hubdev_init_node(nodepda_t * npda, cnodeid_t node)
>  {
>  	struct hubdev_info *hubdev_info;
>  	int size;
> -	pg_data_t *pg;
>  
>  	size = sizeof(struct hubdev_info);
>  
>  	if (node >= num_online_nodes())	/* Headless/memless IO nodes */
> -		pg = NODE_DATA(0);
> -	else
> -		pg = NODE_DATA(node);
> +		node = 0;
>  
> -	hubdev_info = (struct hubdev_info *)alloc_bootmem_node(pg, size);
> +	hubdev_info = (struct hubdev_info *)memblock_alloc_node(size, 0, node);
>  
>  	npda->pdinfo = (void *)hubdev_info;
>  }
> diff --git a/arch/ia64/sn/kernel/setup.c b/arch/ia64/sn/kernel/setup.c
> index 5f6b6b4..ab2564f 100644
> --- a/arch/ia64/sn/kernel/setup.c
> +++ b/arch/ia64/sn/kernel/setup.c
> @@ -511,7 +511,7 @@ static void __init sn_init_pdas(char **cmdline_p)
>  	 */
>  	for_each_online_node(cnode) {
>  		nodepdaindr[cnode] =
> -		    alloc_bootmem_node(NODE_DATA(cnode), sizeof(nodepda_t));
> +		    memblock_alloc_node(sizeof(nodepda_t), 0, cnode);
>  		memset(nodepdaindr[cnode]->phys_cpuid, -1,
>  		    sizeof(nodepdaindr[cnode]->phys_cpuid));
>  		spin_lock_init(&nodepdaindr[cnode]->ptc_lock);
> @@ -522,7 +522,7 @@ static void __init sn_init_pdas(char **cmdline_p)
>  	 */
>  	for (cnode = num_online_nodes(); cnode < num_cnodes; cnode++)
>  		nodepdaindr[cnode] =
> -		    alloc_bootmem_node(NODE_DATA(0), sizeof(nodepda_t));
> +		    memblock_alloc_node(sizeof(nodepda_t), 0, 0);
>  
>  	/*
>  	 * Now copy the array of nodepda pointers to each nodepda.
> -- 
> 2.7.4
> 

-- 
Michal Hocko
SUSE Labs

^ permalink raw reply

* Re: [RFC PATCH 18/29] memblock: replace alloc_bootmem_low_pages with memblock_alloc_low
From: Michal Hocko @ 2018-09-06  8:43 UTC (permalink / raw)
  To: Mike Rapoport
  Cc: linux-mm, Andrew Morton, David S. Miller, Greg Kroah-Hartman,
	Ingo Molnar, Michael Ellerman, Paul Burton, Thomas Gleixner,
	Tony Luck, linux-ia64, linux-mips, linuxppc-dev, sparclinux,
	linux-kernel
In-Reply-To: <1536163184-26356-19-git-send-email-rppt@linux.vnet.ibm.com>

On Wed 05-09-18 18:59:33, Mike Rapoport wrote:
> The conversion is done using the following semantic patch:
> 
> @@
> expression e;
> @@
> - alloc_bootmem_low_pages(e)
> + memblock_alloc_low(e, PAGE_SIZE)
> 
> Signed-off-by: Mike Rapoport <rppt@linux.vnet.ibm.com>

Again, I trust Coccinelle to do the right thing and from a quick glance
it looks sane (modulo _virt naming)

Acked-by: Michal Hocko <mhocko@suse.com>

> ---
>  arch/arc/mm/highmem.c                |  2 +-
>  arch/m68k/atari/stram.c              |  3 ++-
>  arch/m68k/mm/motorola.c              |  5 +++--
>  arch/mips/cavium-octeon/dma-octeon.c |  2 +-
>  arch/mips/mm/init.c                  |  3 ++-
>  arch/um/kernel/mem.c                 | 10 ++++++----
>  arch/xtensa/mm/mmu.c                 |  2 +-
>  7 files changed, 16 insertions(+), 11 deletions(-)
> 
> diff --git a/arch/arc/mm/highmem.c b/arch/arc/mm/highmem.c
> index 77ff64a..f582dc8 100644
> --- a/arch/arc/mm/highmem.c
> +++ b/arch/arc/mm/highmem.c
> @@ -123,7 +123,7 @@ static noinline pte_t * __init alloc_kmap_pgtable(unsigned long kvaddr)
>  	pud_k = pud_offset(pgd_k, kvaddr);
>  	pmd_k = pmd_offset(pud_k, kvaddr);
>  
> -	pte_k = (pte_t *)alloc_bootmem_low_pages(PAGE_SIZE);
> +	pte_k = (pte_t *)memblock_alloc_low(PAGE_SIZE, PAGE_SIZE);
>  	pmd_populate_kernel(&init_mm, pmd_k, pte_k);
>  	return pte_k;
>  }
> diff --git a/arch/m68k/atari/stram.c b/arch/m68k/atari/stram.c
> index c83d664..1089d67 100644
> --- a/arch/m68k/atari/stram.c
> +++ b/arch/m68k/atari/stram.c
> @@ -95,7 +95,8 @@ void __init atari_stram_reserve_pages(void *start_mem)
>  {
>  	if (kernel_in_stram) {
>  		pr_debug("atari_stram pool: kernel in ST-RAM, using alloc_bootmem!\n");
> -		stram_pool.start = (resource_size_t)alloc_bootmem_low_pages(pool_size);
> +		stram_pool.start = (resource_size_t)memblock_alloc_low(pool_size,
> +								       PAGE_SIZE);
>  		stram_pool.end = stram_pool.start + pool_size - 1;
>  		request_resource(&iomem_resource, &stram_pool);
>  		stram_virt_offset = 0;
> diff --git a/arch/m68k/mm/motorola.c b/arch/m68k/mm/motorola.c
> index 4e17ecb..8bcf57e 100644
> --- a/arch/m68k/mm/motorola.c
> +++ b/arch/m68k/mm/motorola.c
> @@ -55,7 +55,7 @@ static pte_t * __init kernel_page_table(void)
>  {
>  	pte_t *ptablep;
>  
> -	ptablep = (pte_t *)alloc_bootmem_low_pages(PAGE_SIZE);
> +	ptablep = (pte_t *)memblock_alloc_low(PAGE_SIZE, PAGE_SIZE);
>  
>  	clear_page(ptablep);
>  	__flush_page_to_ram(ptablep);
> @@ -95,7 +95,8 @@ static pmd_t * __init kernel_ptr_table(void)
>  
>  	last_pgtable += PTRS_PER_PMD;
>  	if (((unsigned long)last_pgtable & ~PAGE_MASK) == 0) {
> -		last_pgtable = (pmd_t *)alloc_bootmem_low_pages(PAGE_SIZE);
> +		last_pgtable = (pmd_t *)memblock_alloc_low(PAGE_SIZE,
> +							   PAGE_SIZE);
>  
>  		clear_page(last_pgtable);
>  		__flush_page_to_ram(last_pgtable);
> diff --git a/arch/mips/cavium-octeon/dma-octeon.c b/arch/mips/cavium-octeon/dma-octeon.c
> index 236833b..c44c1a6 100644
> --- a/arch/mips/cavium-octeon/dma-octeon.c
> +++ b/arch/mips/cavium-octeon/dma-octeon.c
> @@ -244,7 +244,7 @@ void __init plat_swiotlb_setup(void)
>  	swiotlb_nslabs = ALIGN(swiotlb_nslabs, IO_TLB_SEGSIZE);
>  	swiotlbsize = swiotlb_nslabs << IO_TLB_SHIFT;
>  
> -	octeon_swiotlb = alloc_bootmem_low_pages(swiotlbsize);
> +	octeon_swiotlb = memblock_alloc_low(swiotlbsize, PAGE_SIZE);
>  
>  	if (swiotlb_init_with_tbl(octeon_swiotlb, swiotlb_nslabs, 1) == -ENOMEM)
>  		panic("Cannot allocate SWIOTLB buffer");
> diff --git a/arch/mips/mm/init.c b/arch/mips/mm/init.c
> index 400676c..a010fba7 100644
> --- a/arch/mips/mm/init.c
> +++ b/arch/mips/mm/init.c
> @@ -244,7 +244,8 @@ void __init fixrange_init(unsigned long start, unsigned long end,
>  			pmd = (pmd_t *)pud;
>  			for (; (k < PTRS_PER_PMD) && (vaddr < end); pmd++, k++) {
>  				if (pmd_none(*pmd)) {
> -					pte = (pte_t *) alloc_bootmem_low_pages(PAGE_SIZE);
> +					pte = (pte_t *) memblock_alloc_low(PAGE_SIZE,
> +									   PAGE_SIZE);
>  					set_pmd(pmd, __pmd((unsigned long)pte));
>  					BUG_ON(pte != pte_offset_kernel(pmd, 0));
>  				}
> diff --git a/arch/um/kernel/mem.c b/arch/um/kernel/mem.c
> index 3c0e470..185f6bb 100644
> --- a/arch/um/kernel/mem.c
> +++ b/arch/um/kernel/mem.c
> @@ -64,7 +64,8 @@ void __init mem_init(void)
>  static void __init one_page_table_init(pmd_t *pmd)
>  {
>  	if (pmd_none(*pmd)) {
> -		pte_t *pte = (pte_t *) alloc_bootmem_low_pages(PAGE_SIZE);
> +		pte_t *pte = (pte_t *) memblock_alloc_low(PAGE_SIZE,
> +							  PAGE_SIZE);
>  		set_pmd(pmd, __pmd(_KERNPG_TABLE +
>  					   (unsigned long) __pa(pte)));
>  		if (pte != pte_offset_kernel(pmd, 0))
> @@ -75,7 +76,7 @@ static void __init one_page_table_init(pmd_t *pmd)
>  static void __init one_md_table_init(pud_t *pud)
>  {
>  #ifdef CONFIG_3_LEVEL_PGTABLES
> -	pmd_t *pmd_table = (pmd_t *) alloc_bootmem_low_pages(PAGE_SIZE);
> +	pmd_t *pmd_table = (pmd_t *) memblock_alloc_low(PAGE_SIZE, PAGE_SIZE);
>  	set_pud(pud, __pud(_KERNPG_TABLE + (unsigned long) __pa(pmd_table)));
>  	if (pmd_table != pmd_offset(pud, 0))
>  		BUG();
> @@ -124,7 +125,7 @@ static void __init fixaddr_user_init( void)
>  		return;
>  
>  	fixrange_init( FIXADDR_USER_START, FIXADDR_USER_END, swapper_pg_dir);
> -	v = (unsigned long) alloc_bootmem_low_pages(size);
> +	v = (unsigned long) memblock_alloc_low(size, PAGE_SIZE);
>  	memcpy((void *) v , (void *) FIXADDR_USER_START, size);
>  	p = __pa(v);
>  	for ( ; size > 0; size -= PAGE_SIZE, vaddr += PAGE_SIZE,
> @@ -143,7 +144,8 @@ void __init paging_init(void)
>  	unsigned long zones_size[MAX_NR_ZONES], vaddr;
>  	int i;
>  
> -	empty_zero_page = (unsigned long *) alloc_bootmem_low_pages(PAGE_SIZE);
> +	empty_zero_page = (unsigned long *) memblock_alloc_low(PAGE_SIZE,
> +							       PAGE_SIZE);
>  	for (i = 0; i < ARRAY_SIZE(zones_size); i++)
>  		zones_size[i] = 0;
>  
> diff --git a/arch/xtensa/mm/mmu.c b/arch/xtensa/mm/mmu.c
> index 9d1ecfc..f33a1ff 100644
> --- a/arch/xtensa/mm/mmu.c
> +++ b/arch/xtensa/mm/mmu.c
> @@ -31,7 +31,7 @@ static void * __init init_pmd(unsigned long vaddr, unsigned long n_pages)
>  	pr_debug("%s: vaddr: 0x%08lx, n_pages: %ld\n",
>  		 __func__, vaddr, n_pages);
>  
> -	pte = alloc_bootmem_low_pages(n_pages * sizeof(pte_t));
> +	pte = memblock_alloc_low(n_pages * sizeof(pte_t), PAGE_SIZE);
>  
>  	for (i = 0; i < n_pages; ++i)
>  		pte_clear(NULL, 0, pte + i);
> -- 
> 2.7.4
> 

-- 
Michal Hocko
SUSE Labs

^ permalink raw reply

* Re: [RFC PATCH 19/29] memblock: replace alloc_bootmem_pages with memblock_alloc
From: Michal Hocko @ 2018-09-06  8:44 UTC (permalink / raw)
  To: Mike Rapoport
  Cc: linux-mm, Andrew Morton, David S. Miller, Greg Kroah-Hartman,
	Ingo Molnar, Michael Ellerman, Paul Burton, Thomas Gleixner,
	Tony Luck, linux-ia64, linux-mips, linuxppc-dev, sparclinux,
	linux-kernel
In-Reply-To: <1536163184-26356-20-git-send-email-rppt@linux.vnet.ibm.com>

On Wed 05-09-18 18:59:34, Mike Rapoport wrote:
> The conversion is done using the following semantic patch:
> 
> @@
> expression e;
> @@
> - alloc_bootmem_pages(e)
> + memblock_alloc(e, PAGE_SIZE)
> 
> Signed-off-by: Mike Rapoport <rppt@linux.vnet.ibm.com>

Same as the previous patch

Acked-by: Michal Hocko <mhocko@suse.com>

> ---
>  arch/c6x/mm/init.c             | 3 ++-
>  arch/h8300/mm/init.c           | 2 +-
>  arch/m68k/mm/init.c            | 2 +-
>  arch/m68k/mm/mcfmmu.c          | 4 ++--
>  arch/m68k/mm/motorola.c        | 2 +-
>  arch/m68k/mm/sun3mmu.c         | 4 ++--
>  arch/sh/mm/init.c              | 4 ++--
>  arch/x86/kernel/apic/io_apic.c | 3 ++-
>  arch/x86/mm/init_64.c          | 2 +-
>  drivers/xen/swiotlb-xen.c      | 3 ++-
>  10 files changed, 16 insertions(+), 13 deletions(-)
> 
> diff --git a/arch/c6x/mm/init.c b/arch/c6x/mm/init.c
> index 4cc72b0..dc369ad 100644
> --- a/arch/c6x/mm/init.c
> +++ b/arch/c6x/mm/init.c
> @@ -38,7 +38,8 @@ void __init paging_init(void)
>  	struct pglist_data *pgdat = NODE_DATA(0);
>  	unsigned long zones_size[MAX_NR_ZONES] = {0, };
>  
> -	empty_zero_page      = (unsigned long) alloc_bootmem_pages(PAGE_SIZE);
> +	empty_zero_page      = (unsigned long) memblock_alloc(PAGE_SIZE,
> +							      PAGE_SIZE);
>  	memset((void *)empty_zero_page, 0, PAGE_SIZE);
>  
>  	/*
> diff --git a/arch/h8300/mm/init.c b/arch/h8300/mm/init.c
> index 015287a..5d31ac9 100644
> --- a/arch/h8300/mm/init.c
> +++ b/arch/h8300/mm/init.c
> @@ -67,7 +67,7 @@ void __init paging_init(void)
>  	 * Initialize the bad page table and bad page to point
>  	 * to a couple of allocated pages.
>  	 */
> -	empty_zero_page = (unsigned long)alloc_bootmem_pages(PAGE_SIZE);
> +	empty_zero_page = (unsigned long)memblock_alloc(PAGE_SIZE, PAGE_SIZE);
>  	memset((void *)empty_zero_page, 0, PAGE_SIZE);
>  
>  	/*
> diff --git a/arch/m68k/mm/init.c b/arch/m68k/mm/init.c
> index 38e2b27..977363e 100644
> --- a/arch/m68k/mm/init.c
> +++ b/arch/m68k/mm/init.c
> @@ -93,7 +93,7 @@ void __init paging_init(void)
>  
>  	high_memory = (void *) end_mem;
>  
> -	empty_zero_page = alloc_bootmem_pages(PAGE_SIZE);
> +	empty_zero_page = memblock_alloc(PAGE_SIZE, PAGE_SIZE);
>  
>  	/*
>  	 * Set up SFC/DFC registers (user data space).
> diff --git a/arch/m68k/mm/mcfmmu.c b/arch/m68k/mm/mcfmmu.c
> index f5453d9..38a1d92 100644
> --- a/arch/m68k/mm/mcfmmu.c
> +++ b/arch/m68k/mm/mcfmmu.c
> @@ -44,7 +44,7 @@ void __init paging_init(void)
>  	enum zone_type zone;
>  	int i;
>  
> -	empty_zero_page = (void *) alloc_bootmem_pages(PAGE_SIZE);
> +	empty_zero_page = (void *) memblock_alloc(PAGE_SIZE, PAGE_SIZE);
>  	memset((void *) empty_zero_page, 0, PAGE_SIZE);
>  
>  	pg_dir = swapper_pg_dir;
> @@ -52,7 +52,7 @@ void __init paging_init(void)
>  
>  	size = num_pages * sizeof(pte_t);
>  	size = (size + PAGE_SIZE) & ~(PAGE_SIZE-1);
> -	next_pgtable = (unsigned long) alloc_bootmem_pages(size);
> +	next_pgtable = (unsigned long) memblock_alloc(size, PAGE_SIZE);
>  
>  	bootmem_end = (next_pgtable + size + PAGE_SIZE) & PAGE_MASK;
>  	pg_dir += PAGE_OFFSET >> PGDIR_SHIFT;
> diff --git a/arch/m68k/mm/motorola.c b/arch/m68k/mm/motorola.c
> index 8bcf57e..2113eec 100644
> --- a/arch/m68k/mm/motorola.c
> +++ b/arch/m68k/mm/motorola.c
> @@ -276,7 +276,7 @@ void __init paging_init(void)
>  	 * initialize the bad page table and bad page to point
>  	 * to a couple of allocated pages
>  	 */
> -	empty_zero_page = alloc_bootmem_pages(PAGE_SIZE);
> +	empty_zero_page = memblock_alloc(PAGE_SIZE, PAGE_SIZE);
>  
>  	/*
>  	 * Set up SFC/DFC registers
> diff --git a/arch/m68k/mm/sun3mmu.c b/arch/m68k/mm/sun3mmu.c
> index 4a99799..19c05ab 100644
> --- a/arch/m68k/mm/sun3mmu.c
> +++ b/arch/m68k/mm/sun3mmu.c
> @@ -45,7 +45,7 @@ void __init paging_init(void)
>  	unsigned long zones_size[MAX_NR_ZONES] = { 0, };
>  	unsigned long size;
>  
> -	empty_zero_page = alloc_bootmem_pages(PAGE_SIZE);
> +	empty_zero_page = memblock_alloc(PAGE_SIZE, PAGE_SIZE);
>  
>  	address = PAGE_OFFSET;
>  	pg_dir = swapper_pg_dir;
> @@ -55,7 +55,7 @@ void __init paging_init(void)
>  	size = num_pages * sizeof(pte_t);
>  	size = (size + PAGE_SIZE) & ~(PAGE_SIZE-1);
>  
> -	next_pgtable = (unsigned long)alloc_bootmem_pages(size);
> +	next_pgtable = (unsigned long)memblock_alloc(size, PAGE_SIZE);
>  	bootmem_end = (next_pgtable + size + PAGE_SIZE) & PAGE_MASK;
>  
>  	/* Map whole memory from PAGE_OFFSET (0x0E000000) */
> diff --git a/arch/sh/mm/init.c b/arch/sh/mm/init.c
> index 7713c08..c884b76 100644
> --- a/arch/sh/mm/init.c
> +++ b/arch/sh/mm/init.c
> @@ -128,7 +128,7 @@ static pmd_t * __init one_md_table_init(pud_t *pud)
>  	if (pud_none(*pud)) {
>  		pmd_t *pmd;
>  
> -		pmd = alloc_bootmem_pages(PAGE_SIZE);
> +		pmd = memblock_alloc(PAGE_SIZE, PAGE_SIZE);
>  		pud_populate(&init_mm, pud, pmd);
>  		BUG_ON(pmd != pmd_offset(pud, 0));
>  	}
> @@ -141,7 +141,7 @@ static pte_t * __init one_page_table_init(pmd_t *pmd)
>  	if (pmd_none(*pmd)) {
>  		pte_t *pte;
>  
> -		pte = alloc_bootmem_pages(PAGE_SIZE);
> +		pte = memblock_alloc(PAGE_SIZE, PAGE_SIZE);
>  		pmd_populate_kernel(&init_mm, pmd, pte);
>  		BUG_ON(pte != pte_offset_kernel(pmd, 0));
>  	}
> diff --git a/arch/x86/kernel/apic/io_apic.c b/arch/x86/kernel/apic/io_apic.c
> index ff0d14c..e25118f 100644
> --- a/arch/x86/kernel/apic/io_apic.c
> +++ b/arch/x86/kernel/apic/io_apic.c
> @@ -2621,7 +2621,8 @@ void __init io_apic_init_mappings(void)
>  #ifdef CONFIG_X86_32
>  fake_ioapic_page:
>  #endif
> -			ioapic_phys = (unsigned long)alloc_bootmem_pages(PAGE_SIZE);
> +			ioapic_phys = (unsigned long)memblock_alloc(PAGE_SIZE,
> +								    PAGE_SIZE);
>  			ioapic_phys = __pa(ioapic_phys);
>  		}
>  		set_fixmap_nocache(idx, ioapic_phys);
> diff --git a/arch/x86/mm/init_64.c b/arch/x86/mm/init_64.c
> index dd519f3..f39b512 100644
> --- a/arch/x86/mm/init_64.c
> +++ b/arch/x86/mm/init_64.c
> @@ -197,7 +197,7 @@ static __ref void *spp_getpage(void)
>  	if (after_bootmem)
>  		ptr = (void *) get_zeroed_page(GFP_ATOMIC);
>  	else
> -		ptr = alloc_bootmem_pages(PAGE_SIZE);
> +		ptr = memblock_alloc(PAGE_SIZE, PAGE_SIZE);
>  
>  	if (!ptr || ((unsigned long)ptr & ~PAGE_MASK)) {
>  		panic("set_pte_phys: cannot allocate page data %s\n",
> diff --git a/drivers/xen/swiotlb-xen.c b/drivers/xen/swiotlb-xen.c
> index a6f9ba8..8d849b4 100644
> --- a/drivers/xen/swiotlb-xen.c
> +++ b/drivers/xen/swiotlb-xen.c
> @@ -217,7 +217,8 @@ int __ref xen_swiotlb_init(int verbose, bool early)
>  	 * Get IO TLB memory from any location.
>  	 */
>  	if (early)
> -		xen_io_tlb_start = alloc_bootmem_pages(PAGE_ALIGN(bytes));
> +		xen_io_tlb_start = memblock_alloc(PAGE_ALIGN(bytes),
> +						  PAGE_SIZE);
>  	else {
>  #define SLABS_PER_PAGE (1 << (PAGE_SHIFT - IO_TLB_SHIFT))
>  #define IO_TLB_MIN_SLABS ((1<<20) >> IO_TLB_SHIFT)
> -- 
> 2.7.4
> 

-- 
Michal Hocko
SUSE Labs

^ permalink raw reply

* [PATCH v2 1/2] powerpc/process: fix interleaved output in show_user_instructions()
From: Christophe Leroy @ 2018-09-06  8:51 UTC (permalink / raw)
  To: Benjamin Herrenschmidt, Paul Mackerras, Michael Ellerman, muriloo
  Cc: linux-kernel, linuxppc-dev

When two processes crash at the same time, we sometimes encounter
interleaving in the middle of a line:

[    4.365317] init[1]: segfault (11) at 0 nip 0 lr 0 code 1
[    4.370452] init[1]: code: XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX
[    4.372042] init[74]: segfault (11) at 10a74 nip 1000c198 lr 100078c8 code 1 in sh[10000000+14000]
[    4.386829] XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX
[    4.391542] init[1]: code: XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX
[    4.400863] init[74]: code: 90010024 bf61000c 91490a7c 3fa01002 3be00000 7d3e4b78 3bbd0c20 3b600000
[    4.409867] init[74]: code: 3b9d0040 7c7fe02e 2f830000 419e0028 <89230000> 2f890000 41be001c 4b7f6e79

This patch fixes it by preparing complete lines in a buffer and
printing it at once.

Fixes: 88b0fe1757359 ("powerpc: Add show_user_instructions()")
Cc: Murilo Opsfelder Araujo <muriloo@linux.ibm.com>
Signed-off-by: Christophe Leroy <christophe.leroy@c-s.fr>
---
 v2: Using seq_buf and reworked the loop to avoid redundant prints.

 arch/powerpc/kernel/process.c | 37 +++++++++++++++++++------------------
 1 file changed, 19 insertions(+), 18 deletions(-)

diff --git a/arch/powerpc/kernel/process.c b/arch/powerpc/kernel/process.c
index 913c5725cdb2..31d5d8a2ead6 100644
--- a/arch/powerpc/kernel/process.c
+++ b/arch/powerpc/kernel/process.c
@@ -43,6 +43,7 @@
 #include <linux/uaccess.h>
 #include <linux/elf-randomize.h>
 #include <linux/pkeys.h>
+#include <linux/seq_buf.h>
 
 #include <asm/pgtable.h>
 #include <asm/io.h>
@@ -1302,33 +1303,33 @@ static void show_instructions(struct pt_regs *regs)
 void show_user_instructions(struct pt_regs *regs)
 {
 	unsigned long pc;
-	int i;
+	int n = instructions_to_print;
+	struct seq_buf s;
+	char buf[96]; /* enough for 8 times 9 + 2 chars */
 
 	pc = regs->nip - (instructions_to_print * 3 / 4 * sizeof(int));
 
-	pr_info("%s[%d]: code: ", current->comm, current->pid);
+	seq_buf_init(&s, buf, sizeof(buf));
 
-	for (i = 0; i < instructions_to_print; i++) {
-		int instr;
+	while (n) {
+		int i;
 
-		if (!(i % 8) && (i > 0)) {
-			pr_cont("\n");
-			pr_info("%s[%d]: code: ", current->comm, current->pid);
-		}
+		seq_buf_clear(&s);
 
-		if (probe_kernel_address((unsigned int __user *)pc, instr)) {
-			pr_cont("XXXXXXXX ");
-		} else {
-			if (regs->nip == pc)
-				pr_cont("<%08x> ", instr);
-			else
-				pr_cont("%08x ", instr);
+		for (i = 0; i < 8 && n; i++, n--, pc += sizeof(int)) {
+			int instr;
+
+			if (probe_kernel_address((unsigned int __user *)pc, instr)) {
+				seq_buf_puts(&s, "XXXXXXXX ");
+				continue;
+			}
+			seq_buf_printf(&s, regs->nip == pc ? "<%08x> " : "%08x ", instr);
 		}
 
-		pc += sizeof(int);
+		if (!seq_buf_has_overflowed(&s))
+			pr_info("%s[%d]: code: %s\n", current->comm,
+				current->pid, s.buffer);
 	}
-
-	pr_cont("\n");
 }
 
 struct regbit {
-- 
2.13.3

^ permalink raw reply related

* [PATCH v2 2/2] powerpc/process: Constify the number of insns printed by show instructions functions.
From: Christophe Leroy @ 2018-09-06  8:51 UTC (permalink / raw)
  To: Benjamin Herrenschmidt, Paul Mackerras, Michael Ellerman, muriloo
  Cc: linux-kernel, linuxppc-dev
In-Reply-To: <02de5baec443d7c6f96cb2d197e08058c435c40a.1536180109.git.christophe.leroy@c-s.fr>

instructions_to_print var is assigned value 16 and there is no
way to change it.

This patch replaces it by a constant.

Signed-off-by: Christophe Leroy <christophe.leroy@c-s.fr>
---
 arch/powerpc/kernel/process.c | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)

diff --git a/arch/powerpc/kernel/process.c b/arch/powerpc/kernel/process.c
index 31d5d8a2ead6..c9a77512d0a8 100644
--- a/arch/powerpc/kernel/process.c
+++ b/arch/powerpc/kernel/process.c
@@ -1260,17 +1260,16 @@ struct task_struct *__switch_to(struct task_struct *prev,
 	return last;
 }
 
-static int instructions_to_print = 16;
+#define NR_INSN_TO_PRINT	16
 
 static void show_instructions(struct pt_regs *regs)
 {
 	int i;
-	unsigned long pc = regs->nip - (instructions_to_print * 3 / 4 *
-			sizeof(int));
+	unsigned long pc = regs->nip - (NR_INSN_TO_PRINT * 3 / 4 * sizeof(int));
 
 	printk("Instruction dump:");
 
-	for (i = 0; i < instructions_to_print; i++) {
+	for (i = 0; i < NR_INSN_TO_PRINT; i++) {
 		int instr;
 
 		if (!(i % 8))
@@ -1303,11 +1302,11 @@ static void show_instructions(struct pt_regs *regs)
 void show_user_instructions(struct pt_regs *regs)
 {
 	unsigned long pc;
-	int n = instructions_to_print;
+	int n = NR_INSN_TO_PRINT;
 	struct seq_buf s;
 	char buf[96]; /* enough for 8 times 9 + 2 chars */
 
-	pc = regs->nip - (instructions_to_print * 3 / 4 * sizeof(int));
+	pc = regs->nip - (NR_INSN_TO_PRINT * 3 / 4 * sizeof(int));
 
 	seq_buf_init(&s, buf, sizeof(buf));
 
-- 
2.13.3

^ permalink raw reply related

* Re: [RFC PATCH 20/29] memblock: replace __alloc_bootmem with memblock_alloc_from
From: Michal Hocko @ 2018-09-06  8:52 UTC (permalink / raw)
  To: Mike Rapoport
  Cc: linux-mm, Andrew Morton, David S. Miller, Greg Kroah-Hartman,
	Ingo Molnar, Michael Ellerman, Paul Burton, Thomas Gleixner,
	Tony Luck, linux-ia64, linux-mips, linuxppc-dev, sparclinux,
	linux-kernel
In-Reply-To: <1536163184-26356-21-git-send-email-rppt@linux.vnet.ibm.com>

On Wed 05-09-18 18:59:35, Mike Rapoport wrote:
> The conversion is done using the following semantic patch:
> 
> @@
> expression e1, e2, e3;
> @@
> - __alloc_bootmem(e1, e2, e3)
> + memblock_alloc(e1, e2, e3)

This is not that straightforward. memblock_virt_alloc with 0 alignment
uses SMP_CACHE_BYTES implicitly. I do not see this being handled here.
I do not expect this should cause any problems, it would be worse other
way around, but it should be at least documented.
 
> Signed-off-by: Mike Rapoport <rppt@linux.vnet.ibm.com>
> ---
>  arch/alpha/kernel/core_cia.c  |  2 +-
>  arch/alpha/kernel/pci_iommu.c |  4 ++--
>  arch/alpha/kernel/setup.c     |  2 +-
>  arch/ia64/kernel/mca.c        |  4 ++--
>  arch/ia64/mm/contig.c         |  5 +++--
>  arch/mips/kernel/traps.c      |  2 +-
>  arch/sparc/kernel/prom_32.c   |  2 +-
>  arch/sparc/kernel/smp_64.c    | 10 +++++-----
>  arch/sparc/mm/init_32.c       |  2 +-
>  arch/sparc/mm/init_64.c       |  9 ++++++---
>  arch/sparc/mm/srmmu.c         | 10 +++++-----
>  include/linux/bootmem.h       |  8 ++++++++
>  12 files changed, 36 insertions(+), 24 deletions(-)
> 
> diff --git a/arch/alpha/kernel/core_cia.c b/arch/alpha/kernel/core_cia.c
> index 4b38386..026ee95 100644
> --- a/arch/alpha/kernel/core_cia.c
> +++ b/arch/alpha/kernel/core_cia.c
> @@ -331,7 +331,7 @@ cia_prepare_tbia_workaround(int window)
>  	long i;
>  
>  	/* Use minimal 1K map. */
> -	ppte = __alloc_bootmem(CIA_BROKEN_TBIA_SIZE, 32768, 0);
> +	ppte = memblock_alloc_from(CIA_BROKEN_TBIA_SIZE, 32768, 0);
>  	pte = (virt_to_phys(ppte) >> (PAGE_SHIFT - 1)) | 1;
>  
>  	for (i = 0; i < CIA_BROKEN_TBIA_SIZE / sizeof(unsigned long); ++i)
> diff --git a/arch/alpha/kernel/pci_iommu.c b/arch/alpha/kernel/pci_iommu.c
> index b52d76f..0c05493 100644
> --- a/arch/alpha/kernel/pci_iommu.c
> +++ b/arch/alpha/kernel/pci_iommu.c
> @@ -87,13 +87,13 @@ iommu_arena_new_node(int nid, struct pci_controller *hose, dma_addr_t base,
>  		printk("%s: couldn't allocate arena ptes from node %d\n"
>  		       "    falling back to system-wide allocation\n",
>  		       __func__, nid);
> -		arena->ptes = __alloc_bootmem(mem_size, align, 0);
> +		arena->ptes = memblock_alloc_from(mem_size, align, 0);
>  	}
>  
>  #else /* CONFIG_DISCONTIGMEM */
>  
>  	arena = alloc_bootmem(sizeof(*arena));
> -	arena->ptes = __alloc_bootmem(mem_size, align, 0);
> +	arena->ptes = memblock_alloc_from(mem_size, align, 0);
>  
>  #endif /* CONFIG_DISCONTIGMEM */
>  
> diff --git a/arch/alpha/kernel/setup.c b/arch/alpha/kernel/setup.c
> index 4f0d944..64c06a0 100644
> --- a/arch/alpha/kernel/setup.c
> +++ b/arch/alpha/kernel/setup.c
> @@ -294,7 +294,7 @@ move_initrd(unsigned long mem_limit)
>  	unsigned long size;
>  
>  	size = initrd_end - initrd_start;
> -	start = __alloc_bootmem(PAGE_ALIGN(size), PAGE_SIZE, 0);
> +	start = memblock_alloc_from(PAGE_ALIGN(size), PAGE_SIZE, 0);
>  	if (!start || __pa(start) + size > mem_limit) {
>  		initrd_start = initrd_end = 0;
>  		return NULL;
> diff --git a/arch/ia64/kernel/mca.c b/arch/ia64/kernel/mca.c
> index 6115464..5586926 100644
> --- a/arch/ia64/kernel/mca.c
> +++ b/arch/ia64/kernel/mca.c
> @@ -1835,8 +1835,8 @@ format_mca_init_stack(void *mca_data, unsigned long offset,
>  /* Caller prevents this from being called after init */
>  static void * __ref mca_bootmem(void)
>  {
> -	return __alloc_bootmem(sizeof(struct ia64_mca_cpu),
> -	                    KERNEL_STACK_SIZE, 0);
> +	return memblock_alloc_from(sizeof(struct ia64_mca_cpu),
> +				   KERNEL_STACK_SIZE, 0);
>  }
>  
>  /* Do per-CPU MCA-related initialization.  */
> diff --git a/arch/ia64/mm/contig.c b/arch/ia64/mm/contig.c
> index e2e40bb..9e5c23a 100644
> --- a/arch/ia64/mm/contig.c
> +++ b/arch/ia64/mm/contig.c
> @@ -85,8 +85,9 @@ void *per_cpu_init(void)
>  static inline void
>  alloc_per_cpu_data(void)
>  {
> -	cpu_data = __alloc_bootmem(PERCPU_PAGE_SIZE * num_possible_cpus(),
> -				   PERCPU_PAGE_SIZE, __pa(MAX_DMA_ADDRESS));
> +	cpu_data = memblock_alloc_from(PERCPU_PAGE_SIZE * num_possible_cpus(),
> +				       PERCPU_PAGE_SIZE,
> +				       __pa(MAX_DMA_ADDRESS));
>  }
>  
>  /**
> diff --git a/arch/mips/kernel/traps.c b/arch/mips/kernel/traps.c
> index 576aeef..31566d5 100644
> --- a/arch/mips/kernel/traps.c
> +++ b/arch/mips/kernel/traps.c
> @@ -2261,7 +2261,7 @@ void __init trap_init(void)
>  		phys_addr_t ebase_pa;
>  
>  		ebase = (unsigned long)
> -			__alloc_bootmem(size, 1 << fls(size), 0);
> +			memblock_alloc_from(size, 1 << fls(size), 0);
>  
>  		/*
>  		 * Try to ensure ebase resides in KSeg0 if possible.
> diff --git a/arch/sparc/kernel/prom_32.c b/arch/sparc/kernel/prom_32.c
> index b51cbb9..4389944 100644
> --- a/arch/sparc/kernel/prom_32.c
> +++ b/arch/sparc/kernel/prom_32.c
> @@ -32,7 +32,7 @@ void * __init prom_early_alloc(unsigned long size)
>  {
>  	void *ret;
>  
> -	ret = __alloc_bootmem(size, SMP_CACHE_BYTES, 0UL);
> +	ret = memblock_alloc_from(size, SMP_CACHE_BYTES, 0UL);
>  	if (ret != NULL)
>  		memset(ret, 0, size);
>  
> diff --git a/arch/sparc/kernel/smp_64.c b/arch/sparc/kernel/smp_64.c
> index 83ff88d..337febd 100644
> --- a/arch/sparc/kernel/smp_64.c
> +++ b/arch/sparc/kernel/smp_64.c
> @@ -1588,7 +1588,7 @@ static void * __init pcpu_alloc_bootmem(unsigned int cpu, size_t size,
>  	void *ptr;
>  
>  	if (!node_online(node) || !NODE_DATA(node)) {
> -		ptr = __alloc_bootmem(size, align, goal);
> +		ptr = memblock_alloc_from(size, align, goal);
>  		pr_info("cpu %d has no node %d or node-local memory\n",
>  			cpu, node);
>  		pr_debug("per cpu data for cpu%d %lu bytes at %016lx\n",
> @@ -1601,7 +1601,7 @@ static void * __init pcpu_alloc_bootmem(unsigned int cpu, size_t size,
>  	}
>  	return ptr;
>  #else
> -	return __alloc_bootmem(size, align, goal);
> +	return memblock_alloc_from(size, align, goal);
>  #endif
>  }
>  
> @@ -1627,7 +1627,7 @@ static void __init pcpu_populate_pte(unsigned long addr)
>  	if (pgd_none(*pgd)) {
>  		pud_t *new;
>  
> -		new = __alloc_bootmem(PAGE_SIZE, PAGE_SIZE, PAGE_SIZE);
> +		new = memblock_alloc_from(PAGE_SIZE, PAGE_SIZE, PAGE_SIZE);
>  		pgd_populate(&init_mm, pgd, new);
>  	}
>  
> @@ -1635,7 +1635,7 @@ static void __init pcpu_populate_pte(unsigned long addr)
>  	if (pud_none(*pud)) {
>  		pmd_t *new;
>  
> -		new = __alloc_bootmem(PAGE_SIZE, PAGE_SIZE, PAGE_SIZE);
> +		new = memblock_alloc_from(PAGE_SIZE, PAGE_SIZE, PAGE_SIZE);
>  		pud_populate(&init_mm, pud, new);
>  	}
>  
> @@ -1643,7 +1643,7 @@ static void __init pcpu_populate_pte(unsigned long addr)
>  	if (!pmd_present(*pmd)) {
>  		pte_t *new;
>  
> -		new = __alloc_bootmem(PAGE_SIZE, PAGE_SIZE, PAGE_SIZE);
> +		new = memblock_alloc_from(PAGE_SIZE, PAGE_SIZE, PAGE_SIZE);
>  		pmd_populate_kernel(&init_mm, pmd, new);
>  	}
>  }
> diff --git a/arch/sparc/mm/init_32.c b/arch/sparc/mm/init_32.c
> index 92634d4..885dd38 100644
> --- a/arch/sparc/mm/init_32.c
> +++ b/arch/sparc/mm/init_32.c
> @@ -265,7 +265,7 @@ void __init mem_init(void)
>  	i = last_valid_pfn >> ((20 - PAGE_SHIFT) + 5);
>  	i += 1;
>  	sparc_valid_addr_bitmap = (unsigned long *)
> -		__alloc_bootmem(i << 2, SMP_CACHE_BYTES, 0UL);
> +		memblock_alloc_from(i << 2, SMP_CACHE_BYTES, 0UL);
>  
>  	if (sparc_valid_addr_bitmap == NULL) {
>  		prom_printf("mem_init: Cannot alloc valid_addr_bitmap.\n");
> diff --git a/arch/sparc/mm/init_64.c b/arch/sparc/mm/init_64.c
> index 578ec3d..51cd583 100644
> --- a/arch/sparc/mm/init_64.c
> +++ b/arch/sparc/mm/init_64.c
> @@ -1810,7 +1810,8 @@ static unsigned long __ref kernel_map_range(unsigned long pstart,
>  		if (pgd_none(*pgd)) {
>  			pud_t *new;
>  
> -			new = __alloc_bootmem(PAGE_SIZE, PAGE_SIZE, PAGE_SIZE);
> +			new = memblock_alloc_from(PAGE_SIZE, PAGE_SIZE,
> +						  PAGE_SIZE);
>  			alloc_bytes += PAGE_SIZE;
>  			pgd_populate(&init_mm, pgd, new);
>  		}
> @@ -1822,7 +1823,8 @@ static unsigned long __ref kernel_map_range(unsigned long pstart,
>  				vstart = kernel_map_hugepud(vstart, vend, pud);
>  				continue;
>  			}
> -			new = __alloc_bootmem(PAGE_SIZE, PAGE_SIZE, PAGE_SIZE);
> +			new = memblock_alloc_from(PAGE_SIZE, PAGE_SIZE,
> +						  PAGE_SIZE);
>  			alloc_bytes += PAGE_SIZE;
>  			pud_populate(&init_mm, pud, new);
>  		}
> @@ -1835,7 +1837,8 @@ static unsigned long __ref kernel_map_range(unsigned long pstart,
>  				vstart = kernel_map_hugepmd(vstart, vend, pmd);
>  				continue;
>  			}
> -			new = __alloc_bootmem(PAGE_SIZE, PAGE_SIZE, PAGE_SIZE);
> +			new = memblock_alloc_from(PAGE_SIZE, PAGE_SIZE,
> +						  PAGE_SIZE);
>  			alloc_bytes += PAGE_SIZE;
>  			pmd_populate_kernel(&init_mm, pmd, new);
>  		}
> diff --git a/arch/sparc/mm/srmmu.c b/arch/sparc/mm/srmmu.c
> index be9cb00..b48fea5 100644
> --- a/arch/sparc/mm/srmmu.c
> +++ b/arch/sparc/mm/srmmu.c
> @@ -303,13 +303,13 @@ static void __init srmmu_nocache_init(void)
>  
>  	bitmap_bits = srmmu_nocache_size >> SRMMU_NOCACHE_BITMAP_SHIFT;
>  
> -	srmmu_nocache_pool = __alloc_bootmem(srmmu_nocache_size,
> -		SRMMU_NOCACHE_ALIGN_MAX, 0UL);
> +	srmmu_nocache_pool = memblock_alloc_from(srmmu_nocache_size,
> +						 SRMMU_NOCACHE_ALIGN_MAX, 0UL);
>  	memset(srmmu_nocache_pool, 0, srmmu_nocache_size);
>  
>  	srmmu_nocache_bitmap =
> -		__alloc_bootmem(BITS_TO_LONGS(bitmap_bits) * sizeof(long),
> -				SMP_CACHE_BYTES, 0UL);
> +		memblock_alloc_from(BITS_TO_LONGS(bitmap_bits) * sizeof(long),
> +				    SMP_CACHE_BYTES, 0UL);
>  	bit_map_init(&srmmu_nocache_map, srmmu_nocache_bitmap, bitmap_bits);
>  
>  	srmmu_swapper_pg_dir = __srmmu_get_nocache(SRMMU_PGD_TABLE_SIZE, SRMMU_PGD_TABLE_SIZE);
> @@ -467,7 +467,7 @@ static void __init sparc_context_init(int numctx)
>  	unsigned long size;
>  
>  	size = numctx * sizeof(struct ctx_list);
> -	ctx_list_pool = __alloc_bootmem(size, SMP_CACHE_BYTES, 0UL);
> +	ctx_list_pool = memblock_alloc_from(size, SMP_CACHE_BYTES, 0UL);
>  
>  	for (ctx = 0; ctx < numctx; ctx++) {
>  		struct ctx_list *clist;
> diff --git a/include/linux/bootmem.h b/include/linux/bootmem.h
> index 3896af2..c97c105 100644
> --- a/include/linux/bootmem.h
> +++ b/include/linux/bootmem.h
> @@ -122,6 +122,14 @@ static inline void * __init memblock_alloc_raw(
>  					    NUMA_NO_NODE);
>  }
>  
> +static inline void * __init memblock_alloc_from(
> +		phys_addr_t size, phys_addr_t align, phys_addr_t min_addr)
> +{
> +	return memblock_alloc_try_nid(size, align, min_addr,
> +				      BOOTMEM_ALLOC_ACCESSIBLE,
> +				      NUMA_NO_NODE);
> +}
> +
>  static inline void * __init memblock_alloc_nopanic(
>  					phys_addr_t size, phys_addr_t align)
>  {
> -- 
> 2.7.4
> 

-- 
Michal Hocko
SUSE Labs

^ permalink raw reply

* Re: [RFC PATCH 21/29] memblock: replace alloc_bootmem with memblock_alloc
From: Michal Hocko @ 2018-09-06  8:55 UTC (permalink / raw)
  To: Mike Rapoport
  Cc: linux-mm, Andrew Morton, David S. Miller, Greg Kroah-Hartman,
	Ingo Molnar, Michael Ellerman, Paul Burton, Thomas Gleixner,
	Tony Luck, linux-ia64, linux-mips, linuxppc-dev, sparclinux,
	linux-kernel
In-Reply-To: <1536163184-26356-22-git-send-email-rppt@linux.vnet.ibm.com>

On Wed 05-09-18 18:59:36, Mike Rapoport wrote:
> The conversion is done using the following semantic patch:
> 
> @@
> expression e;
> @@
> - __alloc_bootmem(e)

Did you mean alloc_bottmem? Anyway the only difference from
_alloc_bootmem is SMP_CACHE_BYTES and so you can use 0 alignment for
memblock_virt_alloc. Why do we need memblock_alloc_from at all?

> + memblock_alloc_from(e, 0)

> 
> Signed-off-by: Mike Rapoport <rppt@linux.vnet.ibm.com>
> ---
>  arch/alpha/kernel/core_marvel.c     | 4 ++--
>  arch/alpha/kernel/pci-noop.c        | 4 ++--
>  arch/alpha/kernel/pci.c             | 4 ++--
>  arch/alpha/kernel/pci_iommu.c       | 4 ++--
>  arch/ia64/kernel/mca.c              | 4 ++--
>  arch/ia64/mm/tlb.c                  | 4 ++--
>  arch/m68k/sun3/sun3dvma.c           | 3 ++-
>  arch/microblaze/mm/init.c           | 2 +-
>  arch/mips/kernel/setup.c            | 2 +-
>  arch/um/drivers/net_kern.c          | 2 +-
>  arch/um/drivers/vector_kern.c       | 2 +-
>  arch/um/kernel/initrd.c             | 2 +-
>  arch/x86/kernel/acpi/boot.c         | 3 ++-
>  arch/x86/kernel/apic/io_apic.c      | 2 +-
>  arch/x86/kernel/e820.c              | 2 +-
>  arch/x86/platform/olpc/olpc_dt.c    | 2 +-
>  arch/xtensa/platforms/iss/network.c | 2 +-
>  arch/xtensa/platforms/iss/setup.c   | 4 ++--
>  drivers/macintosh/smu.c             | 2 +-
>  init/main.c                         | 4 ++--
>  20 files changed, 30 insertions(+), 28 deletions(-)
> 
> diff --git a/arch/alpha/kernel/core_marvel.c b/arch/alpha/kernel/core_marvel.c
> index bdebb8c2..1f00c94 100644
> --- a/arch/alpha/kernel/core_marvel.c
> +++ b/arch/alpha/kernel/core_marvel.c
> @@ -82,7 +82,7 @@ mk_resource_name(int pe, int port, char *str)
>  	char *name;
>  	
>  	sprintf(tmp, "PCI %s PE %d PORT %d", str, pe, port);
> -	name = alloc_bootmem(strlen(tmp) + 1);
> +	name = memblock_alloc(strlen(tmp) + 1, 0);
>  	strcpy(name, tmp);
>  
>  	return name;
> @@ -117,7 +117,7 @@ alloc_io7(unsigned int pe)
>  		return NULL;
>  	}
>  
> -	io7 = alloc_bootmem(sizeof(*io7));
> +	io7 = memblock_alloc(sizeof(*io7), 0);
>  	io7->pe = pe;
>  	raw_spin_lock_init(&io7->irq_lock);
>  
> diff --git a/arch/alpha/kernel/pci-noop.c b/arch/alpha/kernel/pci-noop.c
> index c7c5879..59cbfc2 100644
> --- a/arch/alpha/kernel/pci-noop.c
> +++ b/arch/alpha/kernel/pci-noop.c
> @@ -33,7 +33,7 @@ alloc_pci_controller(void)
>  {
>  	struct pci_controller *hose;
>  
> -	hose = alloc_bootmem(sizeof(*hose));
> +	hose = memblock_alloc(sizeof(*hose), 0);
>  
>  	*hose_tail = hose;
>  	hose_tail = &hose->next;
> @@ -44,7 +44,7 @@ alloc_pci_controller(void)
>  struct resource * __init
>  alloc_resource(void)
>  {
> -	return alloc_bootmem(sizeof(struct resource));
> +	return memblock_alloc(sizeof(struct resource), 0);
>  }
>  
>  SYSCALL_DEFINE3(pciconfig_iobase, long, which, unsigned long, bus,
> diff --git a/arch/alpha/kernel/pci.c b/arch/alpha/kernel/pci.c
> index c668c3b..4cc3eb9 100644
> --- a/arch/alpha/kernel/pci.c
> +++ b/arch/alpha/kernel/pci.c
> @@ -392,7 +392,7 @@ alloc_pci_controller(void)
>  {
>  	struct pci_controller *hose;
>  
> -	hose = alloc_bootmem(sizeof(*hose));
> +	hose = memblock_alloc(sizeof(*hose), 0);
>  
>  	*hose_tail = hose;
>  	hose_tail = &hose->next;
> @@ -403,7 +403,7 @@ alloc_pci_controller(void)
>  struct resource * __init
>  alloc_resource(void)
>  {
> -	return alloc_bootmem(sizeof(struct resource));
> +	return memblock_alloc(sizeof(struct resource), 0);
>  }
>  
>  
> diff --git a/arch/alpha/kernel/pci_iommu.c b/arch/alpha/kernel/pci_iommu.c
> index 0c05493..5d178c7 100644
> --- a/arch/alpha/kernel/pci_iommu.c
> +++ b/arch/alpha/kernel/pci_iommu.c
> @@ -79,7 +79,7 @@ iommu_arena_new_node(int nid, struct pci_controller *hose, dma_addr_t base,
>  		printk("%s: couldn't allocate arena from node %d\n"
>  		       "    falling back to system-wide allocation\n",
>  		       __func__, nid);
> -		arena = alloc_bootmem(sizeof(*arena));
> +		arena = memblock_alloc(sizeof(*arena), 0);
>  	}
>  
>  	arena->ptes = memblock_alloc_node(sizeof(*arena), align, nid);
> @@ -92,7 +92,7 @@ iommu_arena_new_node(int nid, struct pci_controller *hose, dma_addr_t base,
>  
>  #else /* CONFIG_DISCONTIGMEM */
>  
> -	arena = alloc_bootmem(sizeof(*arena));
> +	arena = memblock_alloc(sizeof(*arena), 0);
>  	arena->ptes = memblock_alloc_from(mem_size, align, 0);
>  
>  #endif /* CONFIG_DISCONTIGMEM */
> diff --git a/arch/ia64/kernel/mca.c b/arch/ia64/kernel/mca.c
> index 5586926..7120976 100644
> --- a/arch/ia64/kernel/mca.c
> +++ b/arch/ia64/kernel/mca.c
> @@ -361,9 +361,9 @@ static ia64_state_log_t ia64_state_log[IA64_MAX_LOG_TYPES];
>  
>  #define IA64_LOG_ALLOCATE(it, size) \
>  	{ia64_state_log[it].isl_log[IA64_LOG_CURR_INDEX(it)] = \
> -		(ia64_err_rec_t *)alloc_bootmem(size); \
> +		(ia64_err_rec_t *)memblock_alloc(size, 0); \
>  	ia64_state_log[it].isl_log[IA64_LOG_NEXT_INDEX(it)] = \
> -		(ia64_err_rec_t *)alloc_bootmem(size);}
> +		(ia64_err_rec_t *)memblock_alloc(size, 0);}
>  #define IA64_LOG_LOCK_INIT(it) spin_lock_init(&ia64_state_log[it].isl_lock)
>  #define IA64_LOG_LOCK(it)      spin_lock_irqsave(&ia64_state_log[it].isl_lock, s)
>  #define IA64_LOG_UNLOCK(it)    spin_unlock_irqrestore(&ia64_state_log[it].isl_lock,s)
> diff --git a/arch/ia64/mm/tlb.c b/arch/ia64/mm/tlb.c
> index acf10eb..5554863 100644
> --- a/arch/ia64/mm/tlb.c
> +++ b/arch/ia64/mm/tlb.c
> @@ -59,8 +59,8 @@ struct ia64_tr_entry *ia64_idtrs[NR_CPUS];
>  void __init
>  mmu_context_init (void)
>  {
> -	ia64_ctx.bitmap = alloc_bootmem((ia64_ctx.max_ctx+1)>>3);
> -	ia64_ctx.flushmap = alloc_bootmem((ia64_ctx.max_ctx+1)>>3);
> +	ia64_ctx.bitmap = memblock_alloc((ia64_ctx.max_ctx + 1) >> 3, 0);
> +	ia64_ctx.flushmap = memblock_alloc((ia64_ctx.max_ctx + 1) >> 3, 0);
>  }
>  
>  /*
> diff --git a/arch/m68k/sun3/sun3dvma.c b/arch/m68k/sun3/sun3dvma.c
> index 8546922..72d9458 100644
> --- a/arch/m68k/sun3/sun3dvma.c
> +++ b/arch/m68k/sun3/sun3dvma.c
> @@ -267,7 +267,8 @@ void __init dvma_init(void)
>  
>  	list_add(&(hole->list), &hole_list);
>  
> -	iommu_use = alloc_bootmem(IOMMU_TOTAL_ENTRIES * sizeof(unsigned long));
> +	iommu_use = memblock_alloc(IOMMU_TOTAL_ENTRIES * sizeof(unsigned long),
> +				   0);
>  
>  	dvma_unmap_iommu(DVMA_START, DVMA_SIZE);
>  
> diff --git a/arch/microblaze/mm/init.c b/arch/microblaze/mm/init.c
> index df6de7c..8c7f074 100644
> --- a/arch/microblaze/mm/init.c
> +++ b/arch/microblaze/mm/init.c
> @@ -377,7 +377,7 @@ void * __ref zalloc_maybe_bootmem(size_t size, gfp_t mask)
>  	if (mem_init_done)
>  		p = kzalloc(size, mask);
>  	else {
> -		p = alloc_bootmem(size);
> +		p = memblock_alloc(size, 0);
>  		if (p)
>  			memset(p, 0, size);
>  	}
> diff --git a/arch/mips/kernel/setup.c b/arch/mips/kernel/setup.c
> index 08f8251..419dfc42 100644
> --- a/arch/mips/kernel/setup.c
> +++ b/arch/mips/kernel/setup.c
> @@ -901,7 +901,7 @@ static void __init resource_init(void)
>  		if (end >= HIGHMEM_START)
>  			end = HIGHMEM_START - 1;
>  
> -		res = alloc_bootmem(sizeof(struct resource));
> +		res = memblock_alloc(sizeof(struct resource), 0);
>  
>  		res->start = start;
>  		res->end = end;
> diff --git a/arch/um/drivers/net_kern.c b/arch/um/drivers/net_kern.c
> index 3ef1b48..ef19a39 100644
> --- a/arch/um/drivers/net_kern.c
> +++ b/arch/um/drivers/net_kern.c
> @@ -650,7 +650,7 @@ static int __init eth_setup(char *str)
>  		return 1;
>  	}
>  
> -	new = alloc_bootmem(sizeof(*new));
> +	new = memblock_alloc(sizeof(*new), 0);
>  
>  	INIT_LIST_HEAD(&new->list);
>  	new->index = n;
> diff --git a/arch/um/drivers/vector_kern.c b/arch/um/drivers/vector_kern.c
> index c84133c..9d77579 100644
> --- a/arch/um/drivers/vector_kern.c
> +++ b/arch/um/drivers/vector_kern.c
> @@ -1575,7 +1575,7 @@ static int __init vector_setup(char *str)
>  				 str, error);
>  		return 1;
>  	}
> -	new = alloc_bootmem(sizeof(*new));
> +	new = memblock_alloc(sizeof(*new), 0);
>  	INIT_LIST_HEAD(&new->list);
>  	new->unit = n;
>  	new->arguments = str;
> diff --git a/arch/um/kernel/initrd.c b/arch/um/kernel/initrd.c
> index 6f6e789..844056c 100644
> --- a/arch/um/kernel/initrd.c
> +++ b/arch/um/kernel/initrd.c
> @@ -36,7 +36,7 @@ int __init read_initrd(void)
>  		return 0;
>  	}
>  
> -	area = alloc_bootmem(size);
> +	area = memblock_alloc(size, 0);
>  
>  	if (load_initrd(initrd, area, size) == -1)
>  		return 0;
> diff --git a/arch/x86/kernel/acpi/boot.c b/arch/x86/kernel/acpi/boot.c
> index 3b20607..fd887c1 100644
> --- a/arch/x86/kernel/acpi/boot.c
> +++ b/arch/x86/kernel/acpi/boot.c
> @@ -932,7 +932,8 @@ static int __init acpi_parse_hpet(struct acpi_table_header *table)
>  	 * the resource tree during the lateinit timeframe.
>  	 */
>  #define HPET_RESOURCE_NAME_SIZE 9
> -	hpet_res = alloc_bootmem(sizeof(*hpet_res) + HPET_RESOURCE_NAME_SIZE);
> +	hpet_res = memblock_alloc(sizeof(*hpet_res) + HPET_RESOURCE_NAME_SIZE,
> +				  0);
>  
>  	hpet_res->name = (void *)&hpet_res[1];
>  	hpet_res->flags = IORESOURCE_MEM;
> diff --git a/arch/x86/kernel/apic/io_apic.c b/arch/x86/kernel/apic/io_apic.c
> index e25118f..8c74509 100644
> --- a/arch/x86/kernel/apic/io_apic.c
> +++ b/arch/x86/kernel/apic/io_apic.c
> @@ -2578,7 +2578,7 @@ static struct resource * __init ioapic_setup_resources(void)
>  	n = IOAPIC_RESOURCE_NAME_SIZE + sizeof(struct resource);
>  	n *= nr_ioapics;
>  
> -	mem = alloc_bootmem(n);
> +	mem = memblock_alloc(n, 0);
>  	res = (void *)mem;
>  
>  	mem += sizeof(struct resource) * nr_ioapics;
> diff --git a/arch/x86/kernel/e820.c b/arch/x86/kernel/e820.c
> index c88c23c..7ea8748 100644
> --- a/arch/x86/kernel/e820.c
> +++ b/arch/x86/kernel/e820.c
> @@ -1094,7 +1094,7 @@ void __init e820__reserve_resources(void)
>  	struct resource *res;
>  	u64 end;
>  
> -	res = alloc_bootmem(sizeof(*res) * e820_table->nr_entries);
> +	res = memblock_alloc(sizeof(*res) * e820_table->nr_entries, 0);
>  	e820_res = res;
>  
>  	for (i = 0; i < e820_table->nr_entries; i++) {
> diff --git a/arch/x86/platform/olpc/olpc_dt.c b/arch/x86/platform/olpc/olpc_dt.c
> index d6ee929..140cd76 100644
> --- a/arch/x86/platform/olpc/olpc_dt.c
> +++ b/arch/x86/platform/olpc/olpc_dt.c
> @@ -141,7 +141,7 @@ void * __init prom_early_alloc(unsigned long size)
>  		 * fast enough on the platforms we care about while minimizing
>  		 * wasted bootmem) and hand off chunks of it to callers.
>  		 */
> -		res = alloc_bootmem(chunk_size);
> +		res = memblock_alloc(chunk_size, 0);
>  		BUG_ON(!res);
>  		prom_early_allocated += chunk_size;
>  		memset(res, 0, chunk_size);
> diff --git a/arch/xtensa/platforms/iss/network.c b/arch/xtensa/platforms/iss/network.c
> index d027ddd..206b9d4 100644
> --- a/arch/xtensa/platforms/iss/network.c
> +++ b/arch/xtensa/platforms/iss/network.c
> @@ -646,7 +646,7 @@ static int __init iss_net_setup(char *str)
>  		return 1;
>  	}
>  
> -	new = alloc_bootmem(sizeof(*new));
> +	new = memblock_alloc(sizeof(*new), 0);
>  	if (new == NULL) {
>  		pr_err("Alloc_bootmem failed\n");
>  		return 1;
> diff --git a/arch/xtensa/platforms/iss/setup.c b/arch/xtensa/platforms/iss/setup.c
> index f4bbb28..a922511 100644
> --- a/arch/xtensa/platforms/iss/setup.c
> +++ b/arch/xtensa/platforms/iss/setup.c
> @@ -82,8 +82,8 @@ void __init platform_setup(char **p_cmdline)
>  	int argv_size = simc_argv_size();
>  
>  	if (argc > 1) {
> -		void **argv = alloc_bootmem(argv_size);
> -		char *cmdline = alloc_bootmem(argv_size);
> +		void **argv = memblock_alloc(argv_size, 0);
> +		char *cmdline = memblock_alloc(argv_size, 0);
>  		int i;
>  
>  		cmdline[0] = 0;
> diff --git a/drivers/macintosh/smu.c b/drivers/macintosh/smu.c
> index e8ae2e5..332fcca 100644
> --- a/drivers/macintosh/smu.c
> +++ b/drivers/macintosh/smu.c
> @@ -493,7 +493,7 @@ int __init smu_init (void)
>  		goto fail_np;
>  	}
>  
> -	smu = alloc_bootmem(sizeof(struct smu_device));
> +	smu = memblock_alloc(sizeof(struct smu_device), 0);
>  
>  	spin_lock_init(&smu->lock);
>  	INIT_LIST_HEAD(&smu->cmd_list);
> diff --git a/init/main.c b/init/main.c
> index d0b92bd..99a9e99 100644
> --- a/init/main.c
> +++ b/init/main.c
> @@ -768,8 +768,8 @@ static int __init initcall_blacklist(char *str)
>  		str_entry = strsep(&str, ",");
>  		if (str_entry) {
>  			pr_debug("blacklisting initcall %s\n", str_entry);
> -			entry = alloc_bootmem(sizeof(*entry));
> -			entry->buf = alloc_bootmem(strlen(str_entry) + 1);
> +			entry = memblock_alloc(sizeof(*entry), 0);
> +			entry->buf = memblock_alloc(strlen(str_entry) + 1, 0);
>  			strcpy(entry->buf, str_entry);
>  			list_add(&entry->next, &blacklisted_initcalls);
>  		}
> -- 
> 2.7.4
> 

-- 
Michal Hocko
SUSE Labs

^ permalink raw reply

* Re: [RFC PATCH 22/29] mm: nobootmem: remove bootmem allocation APIs
From: Michal Hocko @ 2018-09-06  8:56 UTC (permalink / raw)
  To: Mike Rapoport
  Cc: linux-mm, Andrew Morton, David S. Miller, Greg Kroah-Hartman,
	Ingo Molnar, Michael Ellerman, Paul Burton, Thomas Gleixner,
	Tony Luck, linux-ia64, linux-mips, linuxppc-dev, sparclinux,
	linux-kernel
In-Reply-To: <1536163184-26356-23-git-send-email-rppt@linux.vnet.ibm.com>

On Wed 05-09-18 18:59:37, Mike Rapoport wrote:
> The bootmem compatibility APIs are not used and can be removed.
> 
> Signed-off-by: Mike Rapoport <rppt@linux.vnet.ibm.com>

I am happy to see this finally go
Acked-by: Michal Hocko <mhocko@suse.com>

> ---
>  include/linux/bootmem.h |  47 ----------
>  mm/nobootmem.c          | 224 ------------------------------------------------
>  2 files changed, 271 deletions(-)
> 
> diff --git a/include/linux/bootmem.h b/include/linux/bootmem.h
> index c97c105..73f1272 100644
> --- a/include/linux/bootmem.h
> +++ b/include/linux/bootmem.h
> @@ -36,33 +36,6 @@ extern void free_bootmem_node(pg_data_t *pgdat,
>  extern void free_bootmem(unsigned long physaddr, unsigned long size);
>  extern void free_bootmem_late(unsigned long physaddr, unsigned long size);
>  
> -extern void *__alloc_bootmem(unsigned long size,
> -			     unsigned long align,
> -			     unsigned long goal);
> -extern void *__alloc_bootmem_nopanic(unsigned long size,
> -				     unsigned long align,
> -				     unsigned long goal) __malloc;
> -extern void *__alloc_bootmem_node(pg_data_t *pgdat,
> -				  unsigned long size,
> -				  unsigned long align,
> -				  unsigned long goal) __malloc;
> -void *__alloc_bootmem_node_high(pg_data_t *pgdat,
> -				  unsigned long size,
> -				  unsigned long align,
> -				  unsigned long goal) __malloc;
> -extern void *__alloc_bootmem_node_nopanic(pg_data_t *pgdat,
> -				  unsigned long size,
> -				  unsigned long align,
> -				  unsigned long goal) __malloc;
> -void *___alloc_bootmem_node_nopanic(pg_data_t *pgdat,
> -				  unsigned long size,
> -				  unsigned long align,
> -				  unsigned long goal,
> -				  unsigned long limit) __malloc;
> -extern void *__alloc_bootmem_low(unsigned long size,
> -				 unsigned long align,
> -				 unsigned long goal) __malloc;
> -
>  /* We are using top down, so it is safe to use 0 here */
>  #define BOOTMEM_LOW_LIMIT 0
>  
> @@ -70,26 +43,6 @@ extern void *__alloc_bootmem_low(unsigned long size,
>  #define ARCH_LOW_ADDRESS_LIMIT  0xffffffffUL
>  #endif
>  
> -#define alloc_bootmem(x) \
> -	__alloc_bootmem(x, SMP_CACHE_BYTES, BOOTMEM_LOW_LIMIT)
> -#define alloc_bootmem_align(x, align) \
> -	__alloc_bootmem(x, align, BOOTMEM_LOW_LIMIT)
> -#define alloc_bootmem_pages(x) \
> -	__alloc_bootmem(x, PAGE_SIZE, BOOTMEM_LOW_LIMIT)
> -#define alloc_bootmem_pages_nopanic(x) \
> -	__alloc_bootmem_nopanic(x, PAGE_SIZE, BOOTMEM_LOW_LIMIT)
> -#define alloc_bootmem_node(pgdat, x) \
> -	__alloc_bootmem_node(pgdat, x, SMP_CACHE_BYTES, BOOTMEM_LOW_LIMIT)
> -#define alloc_bootmem_node_nopanic(pgdat, x) \
> -	__alloc_bootmem_node_nopanic(pgdat, x, SMP_CACHE_BYTES, BOOTMEM_LOW_LIMIT)
> -#define alloc_bootmem_pages_node(pgdat, x) \
> -	__alloc_bootmem_node(pgdat, x, PAGE_SIZE, BOOTMEM_LOW_LIMIT)
> -
> -#define alloc_bootmem_low(x) \
> -	__alloc_bootmem_low(x, SMP_CACHE_BYTES, 0)
> -#define alloc_bootmem_low_pages(x) \
> -	__alloc_bootmem_low(x, PAGE_SIZE, 0)
> -
>  /* FIXME: use MEMBLOCK_ALLOC_* variants here */
>  #define BOOTMEM_ALLOC_ACCESSIBLE	0
>  #define BOOTMEM_ALLOC_ANYWHERE		(~(phys_addr_t)0)
> diff --git a/mm/nobootmem.c b/mm/nobootmem.c
> index 44ce7de..bc38e56 100644
> --- a/mm/nobootmem.c
> +++ b/mm/nobootmem.c
> @@ -33,41 +33,6 @@ unsigned long min_low_pfn;
>  unsigned long max_pfn;
>  unsigned long long max_possible_pfn;
>  
> -static void * __init __alloc_memory_core_early(int nid, u64 size, u64 align,
> -					u64 goal, u64 limit)
> -{
> -	void *ptr;
> -	u64 addr;
> -	enum memblock_flags flags = choose_memblock_flags();
> -
> -	if (limit > memblock.current_limit)
> -		limit = memblock.current_limit;
> -
> -again:
> -	addr = memblock_find_in_range_node(size, align, goal, limit, nid,
> -					   flags);
> -	if (!addr && (flags & MEMBLOCK_MIRROR)) {
> -		flags &= ~MEMBLOCK_MIRROR;
> -		pr_warn("Could not allocate %pap bytes of mirrored memory\n",
> -			&size);
> -		goto again;
> -	}
> -	if (!addr)
> -		return NULL;
> -
> -	if (memblock_reserve(addr, size))
> -		return NULL;
> -
> -	ptr = phys_to_virt(addr);
> -	memset(ptr, 0, size);
> -	/*
> -	 * The min_count is set to 0 so that bootmem allocated blocks
> -	 * are never reported as leaks.
> -	 */
> -	kmemleak_alloc(ptr, size, 0, 0);
> -	return ptr;
> -}
> -
>  /**
>   * free_bootmem_late - free bootmem pages directly to page allocator
>   * @addr: starting address of the range
> @@ -215,192 +180,3 @@ void __init free_bootmem(unsigned long addr, unsigned long size)
>  {
>  	memblock_free(addr, size);
>  }
> -
> -static void * __init ___alloc_bootmem_nopanic(unsigned long size,
> -					unsigned long align,
> -					unsigned long goal,
> -					unsigned long limit)
> -{
> -	void *ptr;
> -
> -	if (WARN_ON_ONCE(slab_is_available()))
> -		return kzalloc(size, GFP_NOWAIT);
> -
> -restart:
> -
> -	ptr = __alloc_memory_core_early(NUMA_NO_NODE, size, align, goal, limit);
> -
> -	if (ptr)
> -		return ptr;
> -
> -	if (goal != 0) {
> -		goal = 0;
> -		goto restart;
> -	}
> -
> -	return NULL;
> -}
> -
> -/**
> - * __alloc_bootmem_nopanic - allocate boot memory without panicking
> - * @size: size of the request in bytes
> - * @align: alignment of the region
> - * @goal: preferred starting address of the region
> - *
> - * The goal is dropped if it can not be satisfied and the allocation will
> - * fall back to memory below @goal.
> - *
> - * Allocation may happen on any node in the system.
> - *
> - * Return: address of the allocated region or %NULL on failure.
> - */
> -void * __init __alloc_bootmem_nopanic(unsigned long size, unsigned long align,
> -					unsigned long goal)
> -{
> -	unsigned long limit = -1UL;
> -
> -	return ___alloc_bootmem_nopanic(size, align, goal, limit);
> -}
> -
> -static void * __init ___alloc_bootmem(unsigned long size, unsigned long align,
> -					unsigned long goal, unsigned long limit)
> -{
> -	void *mem = ___alloc_bootmem_nopanic(size, align, goal, limit);
> -
> -	if (mem)
> -		return mem;
> -	/*
> -	 * Whoops, we cannot satisfy the allocation request.
> -	 */
> -	pr_alert("bootmem alloc of %lu bytes failed!\n", size);
> -	panic("Out of memory");
> -	return NULL;
> -}
> -
> -/**
> - * __alloc_bootmem - allocate boot memory
> - * @size: size of the request in bytes
> - * @align: alignment of the region
> - * @goal: preferred starting address of the region
> - *
> - * The goal is dropped if it can not be satisfied and the allocation will
> - * fall back to memory below @goal.
> - *
> - * Allocation may happen on any node in the system.
> - *
> - * The function panics if the request can not be satisfied.
> - *
> - * Return: address of the allocated region.
> - */
> -void * __init __alloc_bootmem(unsigned long size, unsigned long align,
> -			      unsigned long goal)
> -{
> -	unsigned long limit = -1UL;
> -
> -	return ___alloc_bootmem(size, align, goal, limit);
> -}
> -
> -void * __init ___alloc_bootmem_node_nopanic(pg_data_t *pgdat,
> -						   unsigned long size,
> -						   unsigned long align,
> -						   unsigned long goal,
> -						   unsigned long limit)
> -{
> -	void *ptr;
> -
> -again:
> -	ptr = __alloc_memory_core_early(pgdat->node_id, size, align,
> -					goal, limit);
> -	if (ptr)
> -		return ptr;
> -
> -	ptr = __alloc_memory_core_early(NUMA_NO_NODE, size, align,
> -					goal, limit);
> -	if (ptr)
> -		return ptr;
> -
> -	if (goal) {
> -		goal = 0;
> -		goto again;
> -	}
> -
> -	return NULL;
> -}
> -
> -void * __init __alloc_bootmem_node_nopanic(pg_data_t *pgdat, unsigned long size,
> -				   unsigned long align, unsigned long goal)
> -{
> -	if (WARN_ON_ONCE(slab_is_available()))
> -		return kzalloc_node(size, GFP_NOWAIT, pgdat->node_id);
> -
> -	return ___alloc_bootmem_node_nopanic(pgdat, size, align, goal, 0);
> -}
> -
> -static void * __init ___alloc_bootmem_node(pg_data_t *pgdat, unsigned long size,
> -				    unsigned long align, unsigned long goal,
> -				    unsigned long limit)
> -{
> -	void *ptr;
> -
> -	ptr = ___alloc_bootmem_node_nopanic(pgdat, size, align, goal, limit);
> -	if (ptr)
> -		return ptr;
> -
> -	pr_alert("bootmem alloc of %lu bytes failed!\n", size);
> -	panic("Out of memory");
> -	return NULL;
> -}
> -
> -/**
> - * __alloc_bootmem_node - allocate boot memory from a specific node
> - * @pgdat: node to allocate from
> - * @size: size of the request in bytes
> - * @align: alignment of the region
> - * @goal: preferred starting address of the region
> - *
> - * The goal is dropped if it can not be satisfied and the allocation will
> - * fall back to memory below @goal.
> - *
> - * Allocation may fall back to any node in the system if the specified node
> - * can not hold the requested memory.
> - *
> - * The function panics if the request can not be satisfied.
> - *
> - * Return: address of the allocated region.
> - */
> -void * __init __alloc_bootmem_node(pg_data_t *pgdat, unsigned long size,
> -				   unsigned long align, unsigned long goal)
> -{
> -	if (WARN_ON_ONCE(slab_is_available()))
> -		return kzalloc_node(size, GFP_NOWAIT, pgdat->node_id);
> -
> -	return ___alloc_bootmem_node(pgdat, size, align, goal, 0);
> -}
> -
> -void * __init __alloc_bootmem_node_high(pg_data_t *pgdat, unsigned long size,
> -				   unsigned long align, unsigned long goal)
> -{
> -	return __alloc_bootmem_node(pgdat, size, align, goal);
> -}
> -
> -
> -/**
> - * __alloc_bootmem_low - allocate low boot memory
> - * @size: size of the request in bytes
> - * @align: alignment of the region
> - * @goal: preferred starting address of the region
> - *
> - * The goal is dropped if it can not be satisfied and the allocation will
> - * fall back to memory below @goal.
> - *
> - * Allocation may happen on any node in the system.
> - *
> - * The function panics if the request can not be satisfied.
> - *
> - * Return: address of the allocated region.
> - */
> -void * __init __alloc_bootmem_low(unsigned long size, unsigned long align,
> -				  unsigned long goal)
> -{
> -	return ___alloc_bootmem(size, align, goal, ARCH_LOW_ADDRESS_LIMIT);
> -}
> -- 
> 2.7.4
> 

-- 
Michal Hocko
SUSE Labs

^ permalink raw reply

* Re: [RFC PATCH 23/29] memblock: replace free_bootmem{_node} with memblock_free
From: Michal Hocko @ 2018-09-06  8:57 UTC (permalink / raw)
  To: Mike Rapoport
  Cc: linux-mm, Andrew Morton, David S. Miller, Greg Kroah-Hartman,
	Ingo Molnar, Michael Ellerman, Paul Burton, Thomas Gleixner,
	Tony Luck, linux-ia64, linux-mips, linuxppc-dev, sparclinux,
	linux-kernel
In-Reply-To: <1536163184-26356-24-git-send-email-rppt@linux.vnet.ibm.com>

On Wed 05-09-18 18:59:38, Mike Rapoport wrote:
> The free_bootmem and free_bootmem_node are merely wrappers for
> memblock_free. Replace their usage with a call to memblock_free using the
> following semantic patch:
> 
> @@
> expression e1, e2, e3;
> @@
> (
> - free_bootmem(e1, e2)
> + memblock_free(e1, e2)
> |
> - free_bootmem_node(e1, e2, e3)
> + memblock_free(e2, e3)
> )
> 
> Signed-off-by: Mike Rapoport <rppt@linux.vnet.ibm.com>

Acked-by: Michal Hocko <mhocko@suse.com>

> ---
>  arch/alpha/kernel/core_irongate.c |  3 +--
>  arch/arm64/mm/init.c              |  2 +-
>  arch/mips/kernel/setup.c          |  2 +-
>  arch/powerpc/kernel/setup_64.c    |  2 +-
>  arch/sparc/kernel/smp_64.c        |  2 +-
>  arch/um/kernel/mem.c              |  3 ++-
>  arch/unicore32/mm/init.c          |  2 +-
>  arch/x86/kernel/setup_percpu.c    |  3 ++-
>  arch/x86/kernel/tce_64.c          |  3 ++-
>  arch/x86/xen/p2m.c                |  3 ++-
>  drivers/macintosh/smu.c           |  2 +-
>  drivers/usb/early/xhci-dbc.c      | 11 ++++++-----
>  drivers/xen/swiotlb-xen.c         |  4 +++-
>  include/linux/bootmem.h           |  4 ----
>  mm/nobootmem.c                    | 30 ------------------------------
>  15 files changed, 24 insertions(+), 52 deletions(-)
> 
> diff --git a/arch/alpha/kernel/core_irongate.c b/arch/alpha/kernel/core_irongate.c
> index f709866..35572be 100644
> --- a/arch/alpha/kernel/core_irongate.c
> +++ b/arch/alpha/kernel/core_irongate.c
> @@ -234,8 +234,7 @@ albacore_init_arch(void)
>  			unsigned long size;
>  
>  			size = initrd_end - initrd_start;
> -			free_bootmem_node(NODE_DATA(0), __pa(initrd_start),
> -					  PAGE_ALIGN(size));
> +			memblock_free(__pa(initrd_start), PAGE_ALIGN(size));
>  			if (!move_initrd(pci_mem))
>  				printk("irongate_init_arch: initrd too big "
>  				       "(%ldK)\ndisabling initrd\n",
> diff --git a/arch/arm64/mm/init.c b/arch/arm64/mm/init.c
> index 787e279..e335452 100644
> --- a/arch/arm64/mm/init.c
> +++ b/arch/arm64/mm/init.c
> @@ -538,7 +538,7 @@ static inline void free_memmap(unsigned long start_pfn, unsigned long end_pfn)
>  	 * memmap array.
>  	 */
>  	if (pg < pgend)
> -		free_bootmem(pg, pgend - pg);
> +		memblock_free(pg, pgend - pg);
>  }
>  
>  /*
> diff --git a/arch/mips/kernel/setup.c b/arch/mips/kernel/setup.c
> index 419dfc42..6d8d0c7 100644
> --- a/arch/mips/kernel/setup.c
> +++ b/arch/mips/kernel/setup.c
> @@ -561,7 +561,7 @@ static void __init bootmem_init(void)
>  		extern void show_kernel_relocation(const char *level);
>  
>  		offset = __pa_symbol(_text) - __pa_symbol(VMLINUX_LOAD_ADDRESS);
> -		free_bootmem(__pa_symbol(VMLINUX_LOAD_ADDRESS), offset);
> +		memblock_free(__pa_symbol(VMLINUX_LOAD_ADDRESS), offset);
>  
>  #if defined(CONFIG_DEBUG_KERNEL) && defined(CONFIG_DEBUG_INFO)
>  		/*
> diff --git a/arch/powerpc/kernel/setup_64.c b/arch/powerpc/kernel/setup_64.c
> index 6add560..e564b27 100644
> --- a/arch/powerpc/kernel/setup_64.c
> +++ b/arch/powerpc/kernel/setup_64.c
> @@ -765,7 +765,7 @@ static void * __init pcpu_fc_alloc(unsigned int cpu, size_t size, size_t align)
>  
>  static void __init pcpu_fc_free(void *ptr, size_t size)
>  {
> -	free_bootmem(__pa(ptr), size);
> +	memblock_free(__pa(ptr), size);
>  }
>  
>  static int pcpu_cpu_distance(unsigned int from, unsigned int to)
> diff --git a/arch/sparc/kernel/smp_64.c b/arch/sparc/kernel/smp_64.c
> index 337febd..a087a6a 100644
> --- a/arch/sparc/kernel/smp_64.c
> +++ b/arch/sparc/kernel/smp_64.c
> @@ -1607,7 +1607,7 @@ static void * __init pcpu_alloc_bootmem(unsigned int cpu, size_t size,
>  
>  static void __init pcpu_free_bootmem(void *ptr, size_t size)
>  {
> -	free_bootmem(__pa(ptr), size);
> +	memblock_free(__pa(ptr), size);
>  }
>  
>  static int __init pcpu_cpu_distance(unsigned int from, unsigned int to)
> diff --git a/arch/um/kernel/mem.c b/arch/um/kernel/mem.c
> index 185f6bb..3555c13 100644
> --- a/arch/um/kernel/mem.c
> +++ b/arch/um/kernel/mem.c
> @@ -6,6 +6,7 @@
>  #include <linux/stddef.h>
>  #include <linux/module.h>
>  #include <linux/bootmem.h>
> +#include <linux/memblock.h>
>  #include <linux/highmem.h>
>  #include <linux/mm.h>
>  #include <linux/swap.h>
> @@ -46,7 +47,7 @@ void __init mem_init(void)
>  	 */
>  	brk_end = (unsigned long) UML_ROUND_UP(sbrk(0));
>  	map_memory(brk_end, __pa(brk_end), uml_reserved - brk_end, 1, 1, 0);
> -	free_bootmem(__pa(brk_end), uml_reserved - brk_end);
> +	memblock_free(__pa(brk_end), uml_reserved - brk_end);
>  	uml_reserved = brk_end;
>  
>  	/* this will put all low memory onto the freelists */
> diff --git a/arch/unicore32/mm/init.c b/arch/unicore32/mm/init.c
> index 44ccc15..4c572ab 100644
> --- a/arch/unicore32/mm/init.c
> +++ b/arch/unicore32/mm/init.c
> @@ -241,7 +241,7 @@ free_memmap(unsigned long start_pfn, unsigned long end_pfn)
>  	 * free the section of the memmap array.
>  	 */
>  	if (pg < pgend)
> -		free_bootmem(pg, pgend - pg);
> +		memblock_free(pg, pgend - pg);
>  }
>  
>  /*
> diff --git a/arch/x86/kernel/setup_percpu.c b/arch/x86/kernel/setup_percpu.c
> index 041663a..a006f1b 100644
> --- a/arch/x86/kernel/setup_percpu.c
> +++ b/arch/x86/kernel/setup_percpu.c
> @@ -5,6 +5,7 @@
>  #include <linux/export.h>
>  #include <linux/init.h>
>  #include <linux/bootmem.h>
> +#include <linux/memblock.h>
>  #include <linux/percpu.h>
>  #include <linux/kexec.h>
>  #include <linux/crash_dump.h>
> @@ -135,7 +136,7 @@ static void * __init pcpu_fc_alloc(unsigned int cpu, size_t size, size_t align)
>  
>  static void __init pcpu_fc_free(void *ptr, size_t size)
>  {
> -	free_bootmem(__pa(ptr), size);
> +	memblock_free(__pa(ptr), size);
>  }
>  
>  static int __init pcpu_cpu_distance(unsigned int from, unsigned int to)
> diff --git a/arch/x86/kernel/tce_64.c b/arch/x86/kernel/tce_64.c
> index 54c9b5a..75730ce 100644
> --- a/arch/x86/kernel/tce_64.c
> +++ b/arch/x86/kernel/tce_64.c
> @@ -31,6 +31,7 @@
>  #include <linux/pci.h>
>  #include <linux/dma-mapping.h>
>  #include <linux/bootmem.h>
> +#include <linux/memblock.h>
>  #include <asm/tce.h>
>  #include <asm/calgary.h>
>  #include <asm/proto.h>
> @@ -186,5 +187,5 @@ void __init free_tce_table(void *tbl)
>  	size = table_size_to_number_of_entries(specified_table_size);
>  	size *= TCE_ENTRY_SIZE;
>  
> -	free_bootmem(__pa(tbl), size);
> +	memblock_free(__pa(tbl), size);
>  }
> diff --git a/arch/x86/xen/p2m.c b/arch/x86/xen/p2m.c
> index 68c0f14..3cedc0b 100644
> --- a/arch/x86/xen/p2m.c
> +++ b/arch/x86/xen/p2m.c
> @@ -66,6 +66,7 @@
>  #include <linux/sched.h>
>  #include <linux/seq_file.h>
>  #include <linux/bootmem.h>
> +#include <linux/memblock.h>
>  #include <linux/slab.h>
>  #include <linux/vmalloc.h>
>  
> @@ -188,7 +189,7 @@ static void * __ref alloc_p2m_page(void)
>  static void __ref free_p2m_page(void *p)
>  {
>  	if (unlikely(!slab_is_available())) {
> -		free_bootmem((unsigned long)p, PAGE_SIZE);
> +		memblock_free((unsigned long)p, PAGE_SIZE);
>  		return;
>  	}
>  
> diff --git a/drivers/macintosh/smu.c b/drivers/macintosh/smu.c
> index 332fcca..0069f90 100644
> --- a/drivers/macintosh/smu.c
> +++ b/drivers/macintosh/smu.c
> @@ -569,7 +569,7 @@ int __init smu_init (void)
>  fail_db_node:
>  	of_node_put(smu->db_node);
>  fail_bootmem:
> -	free_bootmem(__pa(smu), sizeof(struct smu_device));
> +	memblock_free(__pa(smu), sizeof(struct smu_device));
>  	smu = NULL;
>  fail_np:
>  	of_node_put(np);
> diff --git a/drivers/usb/early/xhci-dbc.c b/drivers/usb/early/xhci-dbc.c
> index 16df968..4411404 100644
> --- a/drivers/usb/early/xhci-dbc.c
> +++ b/drivers/usb/early/xhci-dbc.c
> @@ -13,6 +13,7 @@
>  #include <linux/pci_regs.h>
>  #include <linux/pci_ids.h>
>  #include <linux/bootmem.h>
> +#include <linux/memblock.h>
>  #include <linux/io.h>
>  #include <asm/pci-direct.h>
>  #include <asm/fixmap.h>
> @@ -191,7 +192,7 @@ static void __init xdbc_free_ring(struct xdbc_ring *ring)
>  	if (!seg)
>  		return;
>  
> -	free_bootmem(seg->dma, PAGE_SIZE);
> +	memblock_free(seg->dma, PAGE_SIZE);
>  	ring->segment = NULL;
>  }
>  
> @@ -675,10 +676,10 @@ int __init early_xdbc_setup_hardware(void)
>  		xdbc_free_ring(&xdbc.in_ring);
>  
>  		if (xdbc.table_dma)
> -			free_bootmem(xdbc.table_dma, PAGE_SIZE);
> +			memblock_free(xdbc.table_dma, PAGE_SIZE);
>  
>  		if (xdbc.out_dma)
> -			free_bootmem(xdbc.out_dma, PAGE_SIZE);
> +			memblock_free(xdbc.out_dma, PAGE_SIZE);
>  
>  		xdbc.table_base = NULL;
>  		xdbc.out_buf = NULL;
> @@ -1000,8 +1001,8 @@ static int __init xdbc_init(void)
>  	xdbc_free_ring(&xdbc.evt_ring);
>  	xdbc_free_ring(&xdbc.out_ring);
>  	xdbc_free_ring(&xdbc.in_ring);
> -	free_bootmem(xdbc.table_dma, PAGE_SIZE);
> -	free_bootmem(xdbc.out_dma, PAGE_SIZE);
> +	memblock_free(xdbc.table_dma, PAGE_SIZE);
> +	memblock_free(xdbc.out_dma, PAGE_SIZE);
>  	writel(0, &xdbc.xdbc_reg->control);
>  	early_iounmap(xdbc.xhci_base, xdbc.xhci_length);
>  
> diff --git a/drivers/xen/swiotlb-xen.c b/drivers/xen/swiotlb-xen.c
> index 8d849b4..6c13ff4 100644
> --- a/drivers/xen/swiotlb-xen.c
> +++ b/drivers/xen/swiotlb-xen.c
> @@ -36,6 +36,7 @@
>  #define pr_fmt(fmt) "xen:" KBUILD_MODNAME ": " fmt
>  
>  #include <linux/bootmem.h>
> +#include <linux/memblock.h>
>  #include <linux/dma-direct.h>
>  #include <linux/export.h>
>  #include <xen/swiotlb-xen.h>
> @@ -248,7 +249,8 @@ int __ref xen_swiotlb_init(int verbose, bool early)
>  			       xen_io_tlb_nslabs);
>  	if (rc) {
>  		if (early)
> -			free_bootmem(__pa(xen_io_tlb_start), PAGE_ALIGN(bytes));
> +			memblock_free(__pa(xen_io_tlb_start),
> +				      PAGE_ALIGN(bytes));
>  		else {
>  			free_pages((unsigned long)xen_io_tlb_start, order);
>  			xen_io_tlb_start = NULL;
> diff --git a/include/linux/bootmem.h b/include/linux/bootmem.h
> index 73f1272..706cf8e 100644
> --- a/include/linux/bootmem.h
> +++ b/include/linux/bootmem.h
> @@ -30,10 +30,6 @@ extern unsigned long free_all_bootmem(void);
>  extern void reset_node_managed_pages(pg_data_t *pgdat);
>  extern void reset_all_zones_managed_pages(void);
>  
> -extern void free_bootmem_node(pg_data_t *pgdat,
> -			      unsigned long addr,
> -			      unsigned long size);
> -extern void free_bootmem(unsigned long physaddr, unsigned long size);
>  extern void free_bootmem_late(unsigned long physaddr, unsigned long size);
>  
>  /* We are using top down, so it is safe to use 0 here */
> diff --git a/mm/nobootmem.c b/mm/nobootmem.c
> index bc38e56..85e1822 100644
> --- a/mm/nobootmem.c
> +++ b/mm/nobootmem.c
> @@ -150,33 +150,3 @@ unsigned long __init free_all_bootmem(void)
>  
>  	return pages;
>  }
> -
> -/**
> - * free_bootmem_node - mark a page range as usable
> - * @pgdat: node the range resides on
> - * @physaddr: starting physical address of the range
> - * @size: size of the range in bytes
> - *
> - * Partial pages will be considered reserved and left as they are.
> - *
> - * The range must reside completely on the specified node.
> - */
> -void __init free_bootmem_node(pg_data_t *pgdat, unsigned long physaddr,
> -			      unsigned long size)
> -{
> -	memblock_free(physaddr, size);
> -}
> -
> -/**
> - * free_bootmem - mark a page range as usable
> - * @addr: starting physical address of the range
> - * @size: size of the range in bytes
> - *
> - * Partial pages will be considered reserved and left as they are.
> - *
> - * The range must be contiguous but may span node boundaries.
> - */
> -void __init free_bootmem(unsigned long addr, unsigned long size)
> -{
> -	memblock_free(addr, size);
> -}
> -- 
> 2.7.4
> 

-- 
Michal Hocko
SUSE Labs

^ permalink raw reply

* Re: [RFC PATCH 24/29] memblock: replace free_bootmem_late with memblock_free_late
From: Michal Hocko @ 2018-09-06  9:02 UTC (permalink / raw)
  To: Mike Rapoport
  Cc: linux-mm, Andrew Morton, David S. Miller, Greg Kroah-Hartman,
	Ingo Molnar, Michael Ellerman, Paul Burton, Thomas Gleixner,
	Tony Luck, linux-ia64, linux-mips, linuxppc-dev, sparclinux,
	linux-kernel
In-Reply-To: <1536163184-26356-25-git-send-email-rppt@linux.vnet.ibm.com>

On Wed 05-09-18 18:59:39, Mike Rapoport wrote:
> The free_bootmem_late and memblock_free_late do exactly the same thing:
> they iterate over a range and give pages to the page allocator.
> 
> Replace calls to free_bootmem_late with calls to memblock_free_late and
> remove the bootmem variant.
> 
> Signed-off-by: Mike Rapoport <rppt@linux.vnet.ibm.com>

Acked-by: Michal Hocko <mhocko@suse.com>

> ---
>  arch/sparc/kernel/mdesc.c               |  3 ++-
>  arch/x86/platform/efi/quirks.c          |  6 +++---
>  drivers/firmware/efi/apple-properties.c |  2 +-
>  include/linux/bootmem.h                 |  2 --
>  mm/nobootmem.c                          | 24 ------------------------
>  5 files changed, 6 insertions(+), 31 deletions(-)
> 
> diff --git a/arch/sparc/kernel/mdesc.c b/arch/sparc/kernel/mdesc.c
> index 59131e7..a41526b 100644
> --- a/arch/sparc/kernel/mdesc.c
> +++ b/arch/sparc/kernel/mdesc.c
> @@ -12,6 +12,7 @@
>  #include <linux/mm.h>
>  #include <linux/miscdevice.h>
>  #include <linux/bootmem.h>
> +#include <linux/memblock.h>
>  #include <linux/export.h>
>  #include <linux/refcount.h>
>  
> @@ -190,7 +191,7 @@ static void __init mdesc_memblock_free(struct mdesc_handle *hp)
>  
>  	alloc_size = PAGE_ALIGN(hp->handle_size);
>  	start = __pa(hp);
> -	free_bootmem_late(start, alloc_size);
> +	memblock_free_late(start, alloc_size);
>  }
>  
>  static struct mdesc_mem_ops memblock_mdesc_ops = {
> diff --git a/arch/x86/platform/efi/quirks.c b/arch/x86/platform/efi/quirks.c
> index 844d31c..7b4854c 100644
> --- a/arch/x86/platform/efi/quirks.c
> +++ b/arch/x86/platform/efi/quirks.c
> @@ -332,7 +332,7 @@ void __init efi_reserve_boot_services(void)
>  
>  		/*
>  		 * Because the following memblock_reserve() is paired
> -		 * with free_bootmem_late() for this region in
> +		 * with memblock_free_late() for this region in
>  		 * efi_free_boot_services(), we must be extremely
>  		 * careful not to reserve, and subsequently free,
>  		 * critical regions of memory (like the kernel image) or
> @@ -363,7 +363,7 @@ void __init efi_reserve_boot_services(void)
>  		 * doesn't make sense as far as the firmware is
>  		 * concerned, but it does provide us with a way to tag
>  		 * those regions that must not be paired with
> -		 * free_bootmem_late().
> +		 * memblock_free_late().
>  		 */
>  		md->attribute |= EFI_MEMORY_RUNTIME;
>  	}
> @@ -413,7 +413,7 @@ void __init efi_free_boot_services(void)
>  			size -= rm_size;
>  		}
>  
> -		free_bootmem_late(start, size);
> +		memblock_free_late(start, size);
>  	}
>  
>  	if (!num_entries)
> diff --git a/drivers/firmware/efi/apple-properties.c b/drivers/firmware/efi/apple-properties.c
> index 60a9571..2b675f7 100644
> --- a/drivers/firmware/efi/apple-properties.c
> +++ b/drivers/firmware/efi/apple-properties.c
> @@ -235,7 +235,7 @@ static int __init map_properties(void)
>  		 */
>  		data->len = 0;
>  		memunmap(data);
> -		free_bootmem_late(pa_data + sizeof(*data), data_len);
> +		memblock_free_late(pa_data + sizeof(*data), data_len);
>  
>  		return ret;
>  	}
> diff --git a/include/linux/bootmem.h b/include/linux/bootmem.h
> index 706cf8e..bcc7e2f 100644
> --- a/include/linux/bootmem.h
> +++ b/include/linux/bootmem.h
> @@ -30,8 +30,6 @@ extern unsigned long free_all_bootmem(void);
>  extern void reset_node_managed_pages(pg_data_t *pgdat);
>  extern void reset_all_zones_managed_pages(void);
>  
> -extern void free_bootmem_late(unsigned long physaddr, unsigned long size);
> -
>  /* We are using top down, so it is safe to use 0 here */
>  #define BOOTMEM_LOW_LIMIT 0
>  
> diff --git a/mm/nobootmem.c b/mm/nobootmem.c
> index 85e1822..ee0f7fc 100644
> --- a/mm/nobootmem.c
> +++ b/mm/nobootmem.c
> @@ -33,30 +33,6 @@ unsigned long min_low_pfn;
>  unsigned long max_pfn;
>  unsigned long long max_possible_pfn;
>  
> -/**
> - * free_bootmem_late - free bootmem pages directly to page allocator
> - * @addr: starting address of the range
> - * @size: size of the range in bytes
> - *
> - * This is only useful when the bootmem allocator has already been torn
> - * down, but we are still initializing the system.  Pages are given directly
> - * to the page allocator, no bootmem metadata is updated because it is gone.
> - */
> -void __init free_bootmem_late(unsigned long addr, unsigned long size)
> -{
> -	unsigned long cursor, end;
> -
> -	kmemleak_free_part_phys(addr, size);
> -
> -	cursor = PFN_UP(addr);
> -	end = PFN_DOWN(addr + size);
> -
> -	for (; cursor < end; cursor++) {
> -		__free_pages_bootmem(pfn_to_page(cursor), cursor, 0);
> -		totalram_pages++;
> -	}
> -}
> -
>  static void __init __free_pages_memory(unsigned long start, unsigned long end)
>  {
>  	int order;
> -- 
> 2.7.4
> 

-- 
Michal Hocko
SUSE Labs

^ permalink raw reply

* Re: [RFC PATCH 25/29] memblock: rename free_all_bootmem to memblock_free_all
From: Michal Hocko @ 2018-09-06  9:04 UTC (permalink / raw)
  To: Mike Rapoport
  Cc: linux-mm, Andrew Morton, David S. Miller, Greg Kroah-Hartman,
	Ingo Molnar, Michael Ellerman, Paul Burton, Thomas Gleixner,
	Tony Luck, linux-ia64, linux-mips, linuxppc-dev, sparclinux,
	linux-kernel
In-Reply-To: <1536163184-26356-26-git-send-email-rppt@linux.vnet.ibm.com>

On Wed 05-09-18 18:59:40, Mike Rapoport wrote:
> The conversion is done using
> 
> sed -i 's@free_all_bootmem@memblock_free_all@' \
>     $(git grep -l free_all_bootmem)
> 
> Signed-off-by: Mike Rapoport <rppt@linux.vnet.ibm.com>

Acked-by: Michal Hocko <mhocko@suse.com>
-- 
Michal Hocko
SUSE Labs

^ permalink raw reply

* Re: [PATCH 1/2] powerpc/process: fix nested output in show_user_instructions()
From: Christophe LEROY @ 2018-09-06  9:04 UTC (permalink / raw)
  To: Michael Ellerman, Benjamin Herrenschmidt, Paul Mackerras, muriloo
  Cc: linux-kernel, linuxppc-dev
In-Reply-To: <877ekkmdy7.fsf@concordia.ellerman.id.au>



Le 21/08/2018 à 08:27, Michael Ellerman a écrit :
> Christophe Leroy <christophe.leroy@c-s.fr> writes:
> 
>> When two processes crash at the same time, we sometimes encounter
>> nesting in the middle of a line:
> 
> I think "interleaved" is the right word, rather than "nesting".
> 
> They're actually (potentially) completely unrelated segfaults, that just
> happen to occur at the same time.
> 
> And in fact any output that happens simultaneously will mess things up,
> it doesn't have to be another segfault.

Ok, i reworded in v2.

> 
>> [    4.365317] init[1]: segfault (11) at 0 nip 0 lr 0 code 1
>> [    4.370452] init[1]: code: XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX
>> [    4.372042] init[74]: segfault (11) at 10a74 nip 1000c198 lr 100078c8 code 1 in sh[10000000+14000]
>> [    4.386829] XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX
>> [    4.391542] init[1]: code: XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX
>> [    4.400863] init[74]: code: 90010024 bf61000c 91490a7c 3fa01002 3be00000 7d3e4b78 3bbd0c20 3b600000
>> [    4.409867] init[74]: code: 3b9d0040 7c7fe02e 2f830000 419e0028 <89230000> 2f890000 41be001c 4b7f6e79
>>
>> This patch fixes it by preparing complete lines in a buffer and
>> printing it at once.
>>
>> Fixes: 88b0fe1757359 ("powerpc: Add show_user_instructions()")
>> Cc: Murilo Opsfelder Araujo <muriloo@linux.ibm.com>
>> Signed-off-by: Christophe Leroy <christophe.leroy@c-s.fr>
>> ---
>>   arch/powerpc/kernel/process.c | 17 +++++++++--------
>>   1 file changed, 9 insertions(+), 8 deletions(-)
>>
>> diff --git a/arch/powerpc/kernel/process.c b/arch/powerpc/kernel/process.c
>> index 913c5725cdb2..c722ce4ca1c0 100644
>> --- a/arch/powerpc/kernel/process.c
>> +++ b/arch/powerpc/kernel/process.c
>> @@ -1303,32 +1303,33 @@ void show_user_instructions(struct pt_regs *regs)
>>   {
>>   	unsigned long pc;
>>   	int i;
>> +	char buf[96]; /* enough for 8 times 9 + 2 chars */
>> +	int l = 0;
> 
> I'm sure your math is right, but still an on-stack buffer with sprintf()
> is a bit scary.
> 
> Can you try using seq_buf instead? It is safe against overflow.
> 
> eg, something like:
> 
> struct seq_buf s;
> char buf[96];
> 
> seq_buf_init(&s, buf, sizeof(buf));
> ...
> seq_buf_printf(&s, ...);

Ok, I did that in v2. In the meantime I reworked the loop to avoid this 
uggly test against i % 8 and this duplication of the pr_info() of the 
code line.

Christophe

^ permalink raw reply

* Re: [RFC PATCH 26/29] memblock: rename __free_pages_bootmem to memblock_free_pages
From: Michal Hocko @ 2018-09-06  9:06 UTC (permalink / raw)
  To: Mike Rapoport
  Cc: linux-mm, Andrew Morton, David S. Miller, Greg Kroah-Hartman,
	Ingo Molnar, Michael Ellerman, Paul Burton, Thomas Gleixner,
	Tony Luck, linux-ia64, linux-mips, linuxppc-dev, sparclinux,
	linux-kernel
In-Reply-To: <1536163184-26356-27-git-send-email-rppt@linux.vnet.ibm.com>

On Wed 05-09-18 18:59:41, Mike Rapoport wrote:
> The conversion is done using
> 
> sed -i 's@__free_pages_bootmem@memblock_free_pages@' \
>     $(git grep -l __free_pages_bootmem)
> 
> Signed-off-by: Mike Rapoport <rppt@linux.vnet.ibm.com>

Acked-by: Michal Hocko <mhocko@suse.com>

> ---
>  mm/internal.h   | 2 +-
>  mm/memblock.c   | 2 +-
>  mm/nobootmem.c  | 2 +-
>  mm/page_alloc.c | 2 +-
>  4 files changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/mm/internal.h b/mm/internal.h
> index 87256ae..291eb2b 100644
> --- a/mm/internal.h
> +++ b/mm/internal.h
> @@ -161,7 +161,7 @@ static inline struct page *pageblock_pfn_to_page(unsigned long start_pfn,
>  }
>  
>  extern int __isolate_free_page(struct page *page, unsigned int order);
> -extern void __free_pages_bootmem(struct page *page, unsigned long pfn,
> +extern void memblock_free_pages(struct page *page, unsigned long pfn,
>  					unsigned int order);
>  extern void prep_compound_page(struct page *page, unsigned int order);
>  extern void post_alloc_hook(struct page *page, unsigned int order,
> diff --git a/mm/memblock.c b/mm/memblock.c
> index 63df68b..55d7d50 100644
> --- a/mm/memblock.c
> +++ b/mm/memblock.c
> @@ -1639,7 +1639,7 @@ void __init __memblock_free_late(phys_addr_t base, phys_addr_t size)
>  	end = PFN_DOWN(base + size);
>  
>  	for (; cursor < end; cursor++) {
> -		__free_pages_bootmem(pfn_to_page(cursor), cursor, 0);
> +		memblock_free_pages(pfn_to_page(cursor), cursor, 0);
>  		totalram_pages++;
>  	}
>  }
> diff --git a/mm/nobootmem.c b/mm/nobootmem.c
> index bb64b09..9608bc5 100644
> --- a/mm/nobootmem.c
> +++ b/mm/nobootmem.c
> @@ -43,7 +43,7 @@ static void __init __free_pages_memory(unsigned long start, unsigned long end)
>  		while (start + (1UL << order) > end)
>  			order--;
>  
> -		__free_pages_bootmem(pfn_to_page(start), start, order);
> +		memblock_free_pages(pfn_to_page(start), start, order);
>  
>  		start += (1UL << order);
>  	}
> diff --git a/mm/page_alloc.c b/mm/page_alloc.c
> index 33c9e27..e143fae 100644
> --- a/mm/page_alloc.c
> +++ b/mm/page_alloc.c
> @@ -1333,7 +1333,7 @@ meminit_pfn_in_nid(unsigned long pfn, int node,
>  #endif
>  
>  
> -void __init __free_pages_bootmem(struct page *page, unsigned long pfn,
> +void __init memblock_free_pages(struct page *page, unsigned long pfn,
>  							unsigned int order)
>  {
>  	if (early_page_uninitialised(pfn))
> -- 
> 2.7.4
> 

-- 
Michal Hocko
SUSE Labs

^ permalink raw reply

* Re: [RFC PATCH 27/29] mm: remove nobootmem
From: Michal Hocko @ 2018-09-06  9:08 UTC (permalink / raw)
  To: Mike Rapoport
  Cc: linux-mm, Andrew Morton, David S. Miller, Greg Kroah-Hartman,
	Ingo Molnar, Michael Ellerman, Paul Burton, Thomas Gleixner,
	Tony Luck, linux-ia64, linux-mips, linuxppc-dev, sparclinux,
	linux-kernel
In-Reply-To: <1536163184-26356-28-git-send-email-rppt@linux.vnet.ibm.com>

On Wed 05-09-18 18:59:42, Mike Rapoport wrote:
> Move a few remaining functions from nobootmem.c to memblock.c and remove
> nobootmem
> 
> Signed-off-by: Mike Rapoport <rppt@linux.vnet.ibm.com>

Acked-by: Michal Hocko <mhocko@suse.com>

> ---
>  mm/Makefile    |   1 -
>  mm/memblock.c  | 104 ++++++++++++++++++++++++++++++++++++++++++++++
>  mm/nobootmem.c | 128 ---------------------------------------------------------
>  3 files changed, 104 insertions(+), 129 deletions(-)
>  delete mode 100644 mm/nobootmem.c
> 
> diff --git a/mm/Makefile b/mm/Makefile
> index 0a3e72e..fb96c45 100644
> --- a/mm/Makefile
> +++ b/mm/Makefile
> @@ -42,7 +42,6 @@ obj-y			:= filemap.o mempool.o oom_kill.o fadvise.o \
>  			   debug.o $(mmu-y)
>  
>  obj-y += init-mm.o
> -obj-y += nobootmem.o
>  obj-y += memblock.o
>  
>  ifdef CONFIG_MMU
> diff --git a/mm/memblock.c b/mm/memblock.c
> index 55d7d50..3f76d40 100644
> --- a/mm/memblock.c
> +++ b/mm/memblock.c
> @@ -82,6 +82,16 @@
>   * initialization compltes.
>   */
>  
> +#ifndef CONFIG_NEED_MULTIPLE_NODES
> +struct pglist_data __refdata contig_page_data;
> +EXPORT_SYMBOL(contig_page_data);
> +#endif
> +
> +unsigned long max_low_pfn;
> +unsigned long min_low_pfn;
> +unsigned long max_pfn;
> +unsigned long long max_possible_pfn;
> +
>  static struct memblock_region memblock_memory_init_regions[INIT_MEMBLOCK_REGIONS] __initdata_memblock;
>  static struct memblock_region memblock_reserved_init_regions[INIT_MEMBLOCK_REGIONS] __initdata_memblock;
>  #ifdef CONFIG_HAVE_MEMBLOCK_PHYS_MAP
> @@ -1959,6 +1969,100 @@ static int __init early_memblock(char *p)
>  }
>  early_param("memblock", early_memblock);
>  
> +static void __init __free_pages_memory(unsigned long start, unsigned long end)
> +{
> +	int order;
> +
> +	while (start < end) {
> +		order = min(MAX_ORDER - 1UL, __ffs(start));
> +
> +		while (start + (1UL << order) > end)
> +			order--;
> +
> +		memblock_free_pages(pfn_to_page(start), start, order);
> +
> +		start += (1UL << order);
> +	}
> +}
> +
> +static unsigned long __init __free_memory_core(phys_addr_t start,
> +				 phys_addr_t end)
> +{
> +	unsigned long start_pfn = PFN_UP(start);
> +	unsigned long end_pfn = min_t(unsigned long,
> +				      PFN_DOWN(end), max_low_pfn);
> +
> +	if (start_pfn >= end_pfn)
> +		return 0;
> +
> +	__free_pages_memory(start_pfn, end_pfn);
> +
> +	return end_pfn - start_pfn;
> +}
> +
> +static unsigned long __init free_low_memory_core_early(void)
> +{
> +	unsigned long count = 0;
> +	phys_addr_t start, end;
> +	u64 i;
> +
> +	memblock_clear_hotplug(0, -1);
> +
> +	for_each_reserved_mem_region(i, &start, &end)
> +		reserve_bootmem_region(start, end);
> +
> +	/*
> +	 * 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
> +	 *  low ram will be on Node1
> +	 */
> +	for_each_free_mem_range(i, NUMA_NO_NODE, MEMBLOCK_NONE, &start, &end,
> +				NULL)
> +		count += __free_memory_core(start, end);
> +
> +	return count;
> +}
> +
> +static int reset_managed_pages_done __initdata;
> +
> +void reset_node_managed_pages(pg_data_t *pgdat)
> +{
> +	struct zone *z;
> +
> +	for (z = pgdat->node_zones; z < pgdat->node_zones + MAX_NR_ZONES; z++)
> +		z->managed_pages = 0;
> +}
> +
> +void __init reset_all_zones_managed_pages(void)
> +{
> +	struct pglist_data *pgdat;
> +
> +	if (reset_managed_pages_done)
> +		return;
> +
> +	for_each_online_pgdat(pgdat)
> +		reset_node_managed_pages(pgdat);
> +
> +	reset_managed_pages_done = 1;
> +}
> +
> +/**
> + * memblock_free_all - release free pages to the buddy allocator
> + *
> + * Return: the number of pages actually released.
> + */
> +unsigned long __init memblock_free_all(void)
> +{
> +	unsigned long pages;
> +
> +	reset_all_zones_managed_pages();
> +
> +	pages = free_low_memory_core_early();
> +	totalram_pages += pages;
> +
> +	return pages;
> +}
> +
>  #if defined(CONFIG_DEBUG_FS) && !defined(CONFIG_ARCH_DISCARD_MEMBLOCK)
>  
>  static int memblock_debug_show(struct seq_file *m, void *private)
> diff --git a/mm/nobootmem.c b/mm/nobootmem.c
> deleted file mode 100644
> index 9608bc5..0000000
> --- a/mm/nobootmem.c
> +++ /dev/null
> @@ -1,128 +0,0 @@
> -// SPDX-License-Identifier: GPL-2.0
> -/*
> - *  bootmem - A boot-time physical memory allocator and configurator
> - *
> - *  Copyright (C) 1999 Ingo Molnar
> - *                1999 Kanoj Sarcar, SGI
> - *                2008 Johannes Weiner
> - *
> - * Access to this subsystem has to be serialized externally (which is true
> - * for the boot process anyway).
> - */
> -#include <linux/init.h>
> -#include <linux/pfn.h>
> -#include <linux/slab.h>
> -#include <linux/export.h>
> -#include <linux/kmemleak.h>
> -#include <linux/range.h>
> -#include <linux/memblock.h>
> -#include <linux/bootmem.h>
> -
> -#include <asm/bug.h>
> -#include <asm/io.h>
> -
> -#include "internal.h"
> -
> -#ifndef CONFIG_NEED_MULTIPLE_NODES
> -struct pglist_data __refdata contig_page_data;
> -EXPORT_SYMBOL(contig_page_data);
> -#endif
> -
> -unsigned long max_low_pfn;
> -unsigned long min_low_pfn;
> -unsigned long max_pfn;
> -unsigned long long max_possible_pfn;
> -
> -static void __init __free_pages_memory(unsigned long start, unsigned long end)
> -{
> -	int order;
> -
> -	while (start < end) {
> -		order = min(MAX_ORDER - 1UL, __ffs(start));
> -
> -		while (start + (1UL << order) > end)
> -			order--;
> -
> -		memblock_free_pages(pfn_to_page(start), start, order);
> -
> -		start += (1UL << order);
> -	}
> -}
> -
> -static unsigned long __init __free_memory_core(phys_addr_t start,
> -				 phys_addr_t end)
> -{
> -	unsigned long start_pfn = PFN_UP(start);
> -	unsigned long end_pfn = min_t(unsigned long,
> -				      PFN_DOWN(end), max_low_pfn);
> -
> -	if (start_pfn >= end_pfn)
> -		return 0;
> -
> -	__free_pages_memory(start_pfn, end_pfn);
> -
> -	return end_pfn - start_pfn;
> -}
> -
> -static unsigned long __init free_low_memory_core_early(void)
> -{
> -	unsigned long count = 0;
> -	phys_addr_t start, end;
> -	u64 i;
> -
> -	memblock_clear_hotplug(0, -1);
> -
> -	for_each_reserved_mem_region(i, &start, &end)
> -		reserve_bootmem_region(start, end);
> -
> -	/*
> -	 * 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
> -	 *  low ram will be on Node1
> -	 */
> -	for_each_free_mem_range(i, NUMA_NO_NODE, MEMBLOCK_NONE, &start, &end,
> -				NULL)
> -		count += __free_memory_core(start, end);
> -
> -	return count;
> -}
> -
> -static int reset_managed_pages_done __initdata;
> -
> -void reset_node_managed_pages(pg_data_t *pgdat)
> -{
> -	struct zone *z;
> -
> -	for (z = pgdat->node_zones; z < pgdat->node_zones + MAX_NR_ZONES; z++)
> -		z->managed_pages = 0;
> -}
> -
> -void __init reset_all_zones_managed_pages(void)
> -{
> -	struct pglist_data *pgdat;
> -
> -	if (reset_managed_pages_done)
> -		return;
> -
> -	for_each_online_pgdat(pgdat)
> -		reset_node_managed_pages(pgdat);
> -
> -	reset_managed_pages_done = 1;
> -}
> -
> -/**
> - * memblock_free_all - release free pages to the buddy allocator
> - *
> - * Return: the number of pages actually released.
> - */
> -unsigned long __init memblock_free_all(void)
> -{
> -	unsigned long pages;
> -
> -	reset_all_zones_managed_pages();
> -
> -	pages = free_low_memory_core_early();
> -	totalram_pages += pages;
> -
> -	return pages;
> -}
> -- 
> 2.7.4
> 

-- 
Michal Hocko
SUSE Labs

^ permalink raw reply

* Re: [RFC PATCH 28/29] memblock: replace BOOTMEM_ALLOC_* with MEMBLOCK variants
From: Michal Hocko @ 2018-09-06  9:08 UTC (permalink / raw)
  To: Mike Rapoport
  Cc: linux-mm, Andrew Morton, David S. Miller, Greg Kroah-Hartman,
	Ingo Molnar, Michael Ellerman, Paul Burton, Thomas Gleixner,
	Tony Luck, linux-ia64, linux-mips, linuxppc-dev, sparclinux,
	linux-kernel
In-Reply-To: <1536163184-26356-29-git-send-email-rppt@linux.vnet.ibm.com>

On Wed 05-09-18 18:59:43, Mike Rapoport wrote:
> Drop BOOTMEM_ALLOC_ACCESSIBLE and BOOTMEM_ALLOC_ANYWHERE in favor of
> identical MEMBLOCK definitions.
> 
> Signed-off-by: Mike Rapoport <rppt@linux.vnet.ibm.com>

Acked-by: Michal Hocko <mhocko@suse.com>

> ---
>  arch/ia64/mm/discontig.c       | 2 +-
>  arch/powerpc/kernel/setup_64.c | 2 +-
>  arch/sparc/kernel/smp_64.c     | 2 +-
>  arch/x86/kernel/setup_percpu.c | 2 +-
>  arch/x86/mm/kasan_init_64.c    | 4 ++--
>  mm/hugetlb.c                   | 3 ++-
>  mm/kasan/kasan_init.c          | 2 +-
>  mm/memblock.c                  | 8 ++++----
>  mm/page_ext.c                  | 2 +-
>  mm/sparse-vmemmap.c            | 3 ++-
>  mm/sparse.c                    | 5 +++--
>  11 files changed, 19 insertions(+), 16 deletions(-)
> 
> diff --git a/arch/ia64/mm/discontig.c b/arch/ia64/mm/discontig.c
> index 918dda9..70609f8 100644
> --- a/arch/ia64/mm/discontig.c
> +++ b/arch/ia64/mm/discontig.c
> @@ -453,7 +453,7 @@ static void __init *memory_less_node_alloc(int nid, unsigned long pernodesize)
>  
>  	ptr = memblock_alloc_try_nid(pernodesize, PERCPU_PAGE_SIZE,
>  				     __pa(MAX_DMA_ADDRESS),
> -				     BOOTMEM_ALLOC_ACCESSIBLE,
> +				     MEMBLOCK_ALLOC_ACCESSIBLE,
>  				     bestnode);
>  
>  	return ptr;
> diff --git a/arch/powerpc/kernel/setup_64.c b/arch/powerpc/kernel/setup_64.c
> index e564b27..b3e70cc 100644
> --- a/arch/powerpc/kernel/setup_64.c
> +++ b/arch/powerpc/kernel/setup_64.c
> @@ -758,7 +758,7 @@ void __init emergency_stack_init(void)
>  static void * __init pcpu_fc_alloc(unsigned int cpu, size_t size, size_t align)
>  {
>  	return memblock_alloc_try_nid(size, align, __pa(MAX_DMA_ADDRESS),
> -				      BOOTMEM_ALLOC_ACCESSIBLE,
> +				      MEMBLOCK_ALLOC_ACCESSIBLE,
>  				      early_cpu_to_node(cpu));
>  
>  }
> diff --git a/arch/sparc/kernel/smp_64.c b/arch/sparc/kernel/smp_64.c
> index a087a6a..6cc80d0 100644
> --- a/arch/sparc/kernel/smp_64.c
> +++ b/arch/sparc/kernel/smp_64.c
> @@ -1595,7 +1595,7 @@ static void * __init pcpu_alloc_bootmem(unsigned int cpu, size_t size,
>  			 cpu, size, __pa(ptr));
>  	} else {
>  		ptr = memblock_alloc_try_nid(size, align, goal,
> -					     BOOTMEM_ALLOC_ACCESSIBLE, node);
> +					     MEMBLOCK_ALLOC_ACCESSIBLE, node);
>  		pr_debug("per cpu data for cpu%d %lu bytes on node%d at "
>  			 "%016lx\n", cpu, size, node, __pa(ptr));
>  	}
> diff --git a/arch/x86/kernel/setup_percpu.c b/arch/x86/kernel/setup_percpu.c
> index a006f1b..483412f 100644
> --- a/arch/x86/kernel/setup_percpu.c
> +++ b/arch/x86/kernel/setup_percpu.c
> @@ -114,7 +114,7 @@ static void * __init pcpu_alloc_bootmem(unsigned int cpu, unsigned long size,
>  			 cpu, size, __pa(ptr));
>  	} else {
>  		ptr = memblock_alloc_try_nid_nopanic(size, align, goal,
> -						     BOOTMEM_ALLOC_ACCESSIBLE,
> +						     MEMBLOCK_ALLOC_ACCESSIBLE,
>  						     node);
>  
>  		pr_debug("per cpu data for cpu%d %lu bytes on node%d at %016lx\n",
> diff --git a/arch/x86/mm/kasan_init_64.c b/arch/x86/mm/kasan_init_64.c
> index 77b857c..8f87499 100644
> --- a/arch/x86/mm/kasan_init_64.c
> +++ b/arch/x86/mm/kasan_init_64.c
> @@ -29,10 +29,10 @@ static __init void *early_alloc(size_t size, int nid, bool panic)
>  {
>  	if (panic)
>  		return memblock_alloc_try_nid(size, size,
> -			__pa(MAX_DMA_ADDRESS), BOOTMEM_ALLOC_ACCESSIBLE, nid);
> +			__pa(MAX_DMA_ADDRESS), MEMBLOCK_ALLOC_ACCESSIBLE, nid);
>  	else
>  		return memblock_alloc_try_nid_nopanic(size, size,
> -			__pa(MAX_DMA_ADDRESS), BOOTMEM_ALLOC_ACCESSIBLE, nid);
> +			__pa(MAX_DMA_ADDRESS), MEMBLOCK_ALLOC_ACCESSIBLE, nid);
>  }
>  
>  static void __init kasan_populate_pmd(pmd_t *pmd, unsigned long addr,
> diff --git a/mm/hugetlb.c b/mm/hugetlb.c
> index 3f5419c..ee0b140 100644
> --- a/mm/hugetlb.c
> +++ b/mm/hugetlb.c
> @@ -16,6 +16,7 @@
>  #include <linux/cpuset.h>
>  #include <linux/mutex.h>
>  #include <linux/bootmem.h>
> +#include <linux/memblock.h>
>  #include <linux/sysfs.h>
>  #include <linux/slab.h>
>  #include <linux/mmdebug.h>
> @@ -2102,7 +2103,7 @@ int __alloc_bootmem_huge_page(struct hstate *h)
>  
>  		addr = memblock_alloc_try_nid_raw(
>  				huge_page_size(h), huge_page_size(h),
> -				0, BOOTMEM_ALLOC_ACCESSIBLE, node);
> +				0, MEMBLOCK_ALLOC_ACCESSIBLE, node);
>  		if (addr) {
>  			/*
>  			 * Use the beginning of the huge page to store the
> diff --git a/mm/kasan/kasan_init.c b/mm/kasan/kasan_init.c
> index 24d734b..785a970 100644
> --- a/mm/kasan/kasan_init.c
> +++ b/mm/kasan/kasan_init.c
> @@ -84,7 +84,7 @@ static inline bool kasan_zero_page_entry(pte_t pte)
>  static __init void *early_alloc(size_t size, int node)
>  {
>  	return memblock_alloc_try_nid(size, size, __pa(MAX_DMA_ADDRESS),
> -					BOOTMEM_ALLOC_ACCESSIBLE, node);
> +					MEMBLOCK_ALLOC_ACCESSIBLE, node);
>  }
>  
>  static void __ref zero_pte_populate(pmd_t *pmd, unsigned long addr,
> diff --git a/mm/memblock.c b/mm/memblock.c
> index 3f76d40..6061914 100644
> --- a/mm/memblock.c
> +++ b/mm/memblock.c
> @@ -1417,7 +1417,7 @@ phys_addr_t __init memblock_phys_alloc_try_nid(phys_addr_t size, phys_addr_t ali
>   * hold the requested memory.
>   *
>   * The allocation is performed from memory region limited by
> - * memblock.current_limit if @max_addr == %BOOTMEM_ALLOC_ACCESSIBLE.
> + * memblock.current_limit if @max_addr == %MEMBLOCK_ALLOC_ACCESSIBLE.
>   *
>   * The memory block is aligned on %SMP_CACHE_BYTES if @align == 0.
>   *
> @@ -1504,7 +1504,7 @@ static void * __init memblock_alloc_internal(
>   * @min_addr: the lower bound of the memory region from where the allocation
>   *	  is preferred (phys address)
>   * @max_addr: the upper bound of the memory region from where the allocation
> - *	      is preferred (phys address), or %BOOTMEM_ALLOC_ACCESSIBLE to
> + *	      is preferred (phys address), or %MEMBLOCK_ALLOC_ACCESSIBLE to
>   *	      allocate only from memory limited by memblock.current_limit value
>   * @nid: nid of the free area to find, %NUMA_NO_NODE for any node
>   *
> @@ -1542,7 +1542,7 @@ void * __init memblock_alloc_try_nid_raw(
>   * @min_addr: the lower bound of the memory region from where the allocation
>   *	  is preferred (phys address)
>   * @max_addr: the upper bound of the memory region from where the allocation
> - *	      is preferred (phys address), or %BOOTMEM_ALLOC_ACCESSIBLE to
> + *	      is preferred (phys address), or %MEMBLOCK_ALLOC_ACCESSIBLE to
>   *	      allocate only from memory limited by memblock.current_limit value
>   * @nid: nid of the free area to find, %NUMA_NO_NODE for any node
>   *
> @@ -1577,7 +1577,7 @@ void * __init memblock_alloc_try_nid_nopanic(
>   * @min_addr: the lower bound of the memory region from where the allocation
>   *	  is preferred (phys address)
>   * @max_addr: the upper bound of the memory region from where the allocation
> - *	      is preferred (phys address), or %BOOTMEM_ALLOC_ACCESSIBLE to
> + *	      is preferred (phys address), or %MEMBLOCK_ALLOC_ACCESSIBLE to
>   *	      allocate only from memory limited by memblock.current_limit value
>   * @nid: nid of the free area to find, %NUMA_NO_NODE for any node
>   *
> diff --git a/mm/page_ext.c b/mm/page_ext.c
> index e77c0f0..5323c2a 100644
> --- a/mm/page_ext.c
> +++ b/mm/page_ext.c
> @@ -163,7 +163,7 @@ static int __init alloc_node_page_ext(int nid)
>  
>  	base = memblock_alloc_try_nid_nopanic(
>  			table_size, PAGE_SIZE, __pa(MAX_DMA_ADDRESS),
> -			BOOTMEM_ALLOC_ACCESSIBLE, nid);
> +			MEMBLOCK_ALLOC_ACCESSIBLE, nid);
>  	if (!base)
>  		return -ENOMEM;
>  	NODE_DATA(nid)->node_page_ext = base;
> diff --git a/mm/sparse-vmemmap.c b/mm/sparse-vmemmap.c
> index 91c2c3d..7408cab 100644
> --- a/mm/sparse-vmemmap.c
> +++ b/mm/sparse-vmemmap.c
> @@ -21,6 +21,7 @@
>  #include <linux/mm.h>
>  #include <linux/mmzone.h>
>  #include <linux/bootmem.h>
> +#include <linux/memblock.h>
>  #include <linux/memremap.h>
>  #include <linux/highmem.h>
>  #include <linux/slab.h>
> @@ -43,7 +44,7 @@ static void * __ref __earlyonly_bootmem_alloc(int node,
>  				unsigned long goal)
>  {
>  	return memblock_alloc_try_nid_raw(size, align, goal,
> -					       BOOTMEM_ALLOC_ACCESSIBLE, node);
> +					       MEMBLOCK_ALLOC_ACCESSIBLE, node);
>  }
>  
>  void * __meminit vmemmap_alloc_block(unsigned long size, int node)
> diff --git a/mm/sparse.c b/mm/sparse.c
> index 509828f..0dcc306 100644
> --- a/mm/sparse.c
> +++ b/mm/sparse.c
> @@ -6,6 +6,7 @@
>  #include <linux/slab.h>
>  #include <linux/mmzone.h>
>  #include <linux/bootmem.h>
> +#include <linux/memblock.h>
>  #include <linux/compiler.h>
>  #include <linux/highmem.h>
>  #include <linux/export.h>
> @@ -393,7 +394,7 @@ struct page __init *sparse_mem_map_populate(unsigned long pnum, int nid,
>  
>  	map = memblock_alloc_try_nid(size,
>  					  PAGE_SIZE, __pa(MAX_DMA_ADDRESS),
> -					  BOOTMEM_ALLOC_ACCESSIBLE, nid);
> +					  MEMBLOCK_ALLOC_ACCESSIBLE, nid);
>  	return map;
>  }
>  #endif /* !CONFIG_SPARSEMEM_VMEMMAP */
> @@ -407,7 +408,7 @@ static void __init sparse_buffer_init(unsigned long size, int nid)
>  	sparsemap_buf =
>  		memblock_alloc_try_nid_raw(size, PAGE_SIZE,
>  						__pa(MAX_DMA_ADDRESS),
> -						BOOTMEM_ALLOC_ACCESSIBLE, nid);
> +						MEMBLOCK_ALLOC_ACCESSIBLE, nid);
>  	sparsemap_buf_end = sparsemap_buf + size;
>  }
>  
> -- 
> 2.7.4
> 

-- 
Michal Hocko
SUSE Labs

^ permalink raw reply

* Re: [RFC PATCH 00/29] mm: remove bootmem allocator
From: Michal Hocko @ 2018-09-06  9:15 UTC (permalink / raw)
  To: Mike Rapoport
  Cc: linux-mm, Andrew Morton, David S. Miller, Greg Kroah-Hartman,
	Ingo Molnar, Michael Ellerman, Paul Burton, Thomas Gleixner,
	Tony Luck, linux-ia64, linux-mips, linuxppc-dev, sparclinux,
	linux-kernel
In-Reply-To: <1536163184-26356-1-git-send-email-rppt@linux.vnet.ibm.com>

On Wed 05-09-18 18:59:15, Mike Rapoport wrote:
[...]
>  325 files changed, 846 insertions(+), 2478 deletions(-)
>  delete mode 100644 include/linux/bootmem.h
>  delete mode 100644 mm/bootmem.c
>  delete mode 100644 mm/nobootmem.c

This is really impressive! Thanks a lot for working on this. I wish we
could simplify the memblock API as well. There are just too many public
functions with subtly different semantic and barely any useful
documentation.

But even this is a great step forward!
-- 
Michal Hocko
SUSE Labs

^ permalink raw reply

* [RFC PATCH kernel v2] KVM: PPC: Avoid marking DMA-mapped pages dirty in real mode
From: Alexey Kardashevskiy @ 2018-09-06  9:49 UTC (permalink / raw)
  To: linuxppc-dev
  Cc: Alexey Kardashevskiy, David Gibson, kvm-ppc, Aneesh Kumar K.V,
	Alex Williamson, Nicholas Piggin, Paul Mackerras

At the moment the real mode handler of H_PUT_TCE calls iommu_tce_xchg_rm()
which in turn reads the old TCE and if it was a valid entry - marks
the physical page dirty if it was mapped for writing. Since it is
the real mode, realmode_pfn_to_page() is used instead of pfn_to_page()
to get the page struct. However SetPageDirty() itself reads the compound
page head and returns a virtual address for the head page struct and
setting dirty bit for that kills the system.

This adds a dirty bit tracking into the MM/IOMMU API:
- this uses the lowest bit of the cached host phys address to carry
the dirty bit;
- this marks pages dirty when they are unpinned which happens when
the preregistered memory is released which always happens in virtual
mode;
- this changes mm_iommu_ua_to_hpa{_rm} to take DMA direction parameter so
the bit is set when just about to map a page. This might seem rather early
as there is a chance of failure after the translation. The other way
of doing this would be adding a new mm_iommu_ua_mark_dirty() helper
which would have to do the useraddr->hpa lookup again which seems
suboptimal as we normally:
- do not see mapping errors;
- map the entire guest so it is TCE_WRITE;
- consequences of a page being marked dirty are not worth of the extra
lookup.

This moves dirty bit setting away from iommu_tce_xchg{_rm} to the callers
which are KVM and VFIO. KVM requires the memory preregistration; VFIO
uses the same mechanism which KVM does when VFIO_SPAPR_TCE_v2_IOMMU
or explicitly marks pages dirty when VFIO_SPAPR_TCE_IOMMU.

This removes realmode_pfn_to_page() as it is not used anymore.

Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
---

v1 was here: https://www.spinics.net/lists/kvm-ppc/msg14218.html
This is based on top of (it does not really depend on this but rebase does not just work):
[PATCH kernel 0/4] KVM: PPC: Some error handling rework
  KVM: PPC: Validate all tces before updating tables
  KVM: PPC: Inform the userspace about TCE update failures
  KVM: PPC: Validate TCEs against preregistered memory page sizes
  KVM: PPC: Propagate errors to the guest when failed instead of
    ignoring



---
 arch/powerpc/include/asm/book3s/64/pgtable.h |  1 -
 arch/powerpc/include/asm/mmu_context.h       |  7 ++--
 arch/powerpc/kernel/iommu.c                  | 16 ---------
 arch/powerpc/kvm/book3s_64_vio.c             |  5 +--
 arch/powerpc/kvm/book3s_64_vio_hv.c          |  7 ++--
 arch/powerpc/mm/init_64.c                    | 49 ----------------------------
 arch/powerpc/mm/mmu_context_iommu.c          | 23 ++++++++++---
 drivers/vfio/vfio_iommu_spapr_tce.c          | 26 +++++++++++----
 8 files changed, 50 insertions(+), 84 deletions(-)

diff --git a/arch/powerpc/include/asm/book3s/64/pgtable.h b/arch/powerpc/include/asm/book3s/64/pgtable.h
index 13a688f..2fdc865 100644
--- a/arch/powerpc/include/asm/book3s/64/pgtable.h
+++ b/arch/powerpc/include/asm/book3s/64/pgtable.h
@@ -1051,7 +1051,6 @@ static inline void vmemmap_remove_mapping(unsigned long start,
 	return hash__vmemmap_remove_mapping(start, page_size);
 }
 #endif
-struct page *realmode_pfn_to_page(unsigned long pfn);
 
 static inline pte_t pmd_pte(pmd_t pmd)
 {
diff --git a/arch/powerpc/include/asm/mmu_context.h b/arch/powerpc/include/asm/mmu_context.h
index b2f89b6..ebafa43 100644
--- a/arch/powerpc/include/asm/mmu_context.h
+++ b/arch/powerpc/include/asm/mmu_context.h
@@ -7,6 +7,7 @@
 #include <linux/mm.h>
 #include <linux/sched.h>
 #include <linux/spinlock.h>
+#include <linux/dma-direction.h>
 #include <asm/mmu.h>	
 #include <asm/cputable.h>
 #include <asm/cputhreads.h>
@@ -35,9 +36,11 @@ extern struct mm_iommu_table_group_mem_t *mm_iommu_lookup_rm(
 extern struct mm_iommu_table_group_mem_t *mm_iommu_find(struct mm_struct *mm,
 		unsigned long ua, unsigned long entries);
 extern long mm_iommu_ua_to_hpa(struct mm_iommu_table_group_mem_t *mem,
-		unsigned long ua, unsigned int pageshift, unsigned long *hpa);
+		unsigned long ua, unsigned int pageshift,
+		enum dma_data_direction dir, unsigned long *hpa);
 extern long mm_iommu_ua_to_hpa_rm(struct mm_iommu_table_group_mem_t *mem,
-		unsigned long ua, unsigned int pageshift, unsigned long *hpa);
+		unsigned long ua, unsigned int pageshift,
+		enum dma_data_direction dir, unsigned long *hpa);
 extern long mm_iommu_mapped_inc(struct mm_iommu_table_group_mem_t *mem);
 extern void mm_iommu_mapped_dec(struct mm_iommu_table_group_mem_t *mem);
 #endif
diff --git a/arch/powerpc/kernel/iommu.c b/arch/powerpc/kernel/iommu.c
index af7a20d..1540e7f 100644
--- a/arch/powerpc/kernel/iommu.c
+++ b/arch/powerpc/kernel/iommu.c
@@ -1000,10 +1000,6 @@ long iommu_tce_xchg(struct iommu_table *tbl, unsigned long entry,
 
 	ret = tbl->it_ops->exchange(tbl, entry, hpa, direction);
 
-	if (!ret && ((*direction == DMA_FROM_DEVICE) ||
-			(*direction == DMA_BIDIRECTIONAL)))
-		SetPageDirty(pfn_to_page(*hpa >> PAGE_SHIFT));
-
 	/* if (unlikely(ret))
 		pr_err("iommu_tce: %s failed on hwaddr=%lx ioba=%lx kva=%lx ret=%d\n",
 			__func__, hwaddr, entry << tbl->it_page_shift,
@@ -1021,18 +1017,6 @@ long iommu_tce_xchg_rm(struct iommu_table *tbl, unsigned long entry,
 
 	ret = tbl->it_ops->exchange_rm(tbl, entry, hpa, direction);
 
-	if (!ret && ((*direction == DMA_FROM_DEVICE) ||
-			(*direction == DMA_BIDIRECTIONAL))) {
-		struct page *pg = realmode_pfn_to_page(*hpa >> PAGE_SHIFT);
-
-		if (likely(pg)) {
-			SetPageDirty(pg);
-		} else {
-			tbl->it_ops->exchange_rm(tbl, entry, hpa, direction);
-			ret = -EFAULT;
-		}
-	}
-
 	return ret;
 }
 EXPORT_SYMBOL_GPL(iommu_tce_xchg_rm);
diff --git a/arch/powerpc/kvm/book3s_64_vio.c b/arch/powerpc/kvm/book3s_64_vio.c
index 5e3151b..174299d 100644
--- a/arch/powerpc/kvm/book3s_64_vio.c
+++ b/arch/powerpc/kvm/book3s_64_vio.c
@@ -391,7 +391,7 @@ static long kvmppc_tce_validate(struct kvmppc_spapr_tce_table *stt,
 		if (!mem)
 			return H_TOO_HARD;
 
-		if (mm_iommu_ua_to_hpa(mem, ua, shift, &hpa))
+		if (mm_iommu_ua_to_hpa(mem, ua, shift, DMA_NONE, &hpa))
 			return H_TOO_HARD;
 	}
 
@@ -483,7 +483,8 @@ long kvmppc_tce_iommu_do_map(struct kvm *kvm, struct iommu_table *tbl,
 		/* This only handles v2 IOMMU type, v1 is handled via ioctl() */
 		return H_TOO_HARD;
 
-	if (WARN_ON_ONCE(mm_iommu_ua_to_hpa(mem, ua, tbl->it_page_shift, &hpa)))
+	if (WARN_ON_ONCE(mm_iommu_ua_to_hpa(mem, ua, tbl->it_page_shift, dir,
+			&hpa)))
 		return H_TOO_HARD;
 
 	if (mm_iommu_mapped_inc(mem))
diff --git a/arch/powerpc/kvm/book3s_64_vio_hv.c b/arch/powerpc/kvm/book3s_64_vio_hv.c
index 8d82133..5f810dc 100644
--- a/arch/powerpc/kvm/book3s_64_vio_hv.c
+++ b/arch/powerpc/kvm/book3s_64_vio_hv.c
@@ -123,7 +123,7 @@ static long kvmppc_rm_tce_validate(struct kvmppc_spapr_tce_table *stt,
 		if (!mem)
 			return H_TOO_HARD;
 
-		if (mm_iommu_ua_to_hpa_rm(mem, ua, shift, &hpa))
+		if (mm_iommu_ua_to_hpa_rm(mem, ua, shift, DMA_NONE, &hpa))
 			return H_TOO_HARD;
 	}
 
@@ -292,7 +292,7 @@ static long kvmppc_rm_tce_iommu_do_map(struct kvm *kvm, struct iommu_table *tbl,
 		return H_TOO_HARD;
 
 	if (WARN_ON_ONCE_RM(mm_iommu_ua_to_hpa_rm(mem, ua, tbl->it_page_shift,
-			&hpa)))
+			dir, &hpa)))
 		return H_TOO_HARD;
 
 	if (WARN_ON_ONCE_RM(mm_iommu_mapped_inc(mem)))
@@ -475,7 +475,8 @@ long kvmppc_rm_h_put_tce_indirect(struct kvm_vcpu *vcpu,
 		mem = mm_iommu_lookup_rm(vcpu->kvm->mm, ua, IOMMU_PAGE_SIZE_4K);
 		if (mem)
 			prereg = mm_iommu_ua_to_hpa_rm(mem, ua,
-					IOMMU_PAGE_SHIFT_4K, &tces) == 0;
+					IOMMU_PAGE_SHIFT_4K, DMA_NONE,
+					&tces) == 0;
 	}
 
 	if (!prereg) {
diff --git a/arch/powerpc/mm/init_64.c b/arch/powerpc/mm/init_64.c
index 51ce091..7a9886f 100644
--- a/arch/powerpc/mm/init_64.c
+++ b/arch/powerpc/mm/init_64.c
@@ -308,55 +308,6 @@ void register_page_bootmem_memmap(unsigned long section_nr,
 {
 }
 
-/*
- * We do not have access to the sparsemem vmemmap, so we fallback to
- * walking the list of sparsemem blocks which we already maintain for
- * the sake of crashdump. In the long run, we might want to maintain
- * a tree if performance of that linear walk becomes a problem.
- *
- * realmode_pfn_to_page functions can fail due to:
- * 1) As real sparsemem blocks do not lay in RAM continously (they
- * are in virtual address space which is not available in the real mode),
- * the requested page struct can be split between blocks so get_page/put_page
- * may fail.
- * 2) When huge pages are used, the get_page/put_page API will fail
- * in real mode as the linked addresses in the page struct are virtual
- * too.
- */
-struct page *realmode_pfn_to_page(unsigned long pfn)
-{
-	struct vmemmap_backing *vmem_back;
-	struct page *page;
-	unsigned long page_size = 1 << mmu_psize_defs[mmu_vmemmap_psize].shift;
-	unsigned long pg_va = (unsigned long) pfn_to_page(pfn);
-
-	for (vmem_back = vmemmap_list; vmem_back; vmem_back = vmem_back->list) {
-		if (pg_va < vmem_back->virt_addr)
-			continue;
-
-		/* After vmemmap_list entry free is possible, need check all */
-		if ((pg_va + sizeof(struct page)) <=
-				(vmem_back->virt_addr + page_size)) {
-			page = (struct page *) (vmem_back->phys + pg_va -
-				vmem_back->virt_addr);
-			return page;
-		}
-	}
-
-	/* Probably that page struct is split between real pages */
-	return NULL;
-}
-EXPORT_SYMBOL_GPL(realmode_pfn_to_page);
-
-#else
-
-struct page *realmode_pfn_to_page(unsigned long pfn)
-{
-	struct page *page = pfn_to_page(pfn);
-	return page;
-}
-EXPORT_SYMBOL_GPL(realmode_pfn_to_page);
-
 #endif /* CONFIG_SPARSEMEM_VMEMMAP */
 
 #ifdef CONFIG_PPC_BOOK3S_64
diff --git a/arch/powerpc/mm/mmu_context_iommu.c b/arch/powerpc/mm/mmu_context_iommu.c
index c9ee9e2..bc59a73 100644
--- a/arch/powerpc/mm/mmu_context_iommu.c
+++ b/arch/powerpc/mm/mmu_context_iommu.c
@@ -18,11 +18,15 @@
 #include <linux/migrate.h>
 #include <linux/hugetlb.h>
 #include <linux/swap.h>
+#include <linux/sizes.h>
 #include <asm/mmu_context.h>
 #include <asm/pte-walk.h>
 
 static DEFINE_MUTEX(mem_list_mutex);
 
+#define MM_IOMMU_TABLE_GROUP_PAGE_DIRTY	0x1
+#define MM_IOMMU_TABLE_GROUP_PAGE_MASK	(SZ_4K - 1)
+
 struct mm_iommu_table_group_mem_t {
 	struct list_head next;
 	struct rcu_head rcu;
@@ -263,6 +267,9 @@ static void mm_iommu_unpin(struct mm_iommu_table_group_mem_t *mem)
 		if (!page)
 			continue;
 
+		if (mem->hpas[i] & MM_IOMMU_TABLE_GROUP_PAGE_DIRTY)
+			SetPageDirty(page);
+
 		put_page(page);
 		mem->hpas[i] = 0;
 	}
@@ -379,7 +386,8 @@ struct mm_iommu_table_group_mem_t *mm_iommu_find(struct mm_struct *mm,
 EXPORT_SYMBOL_GPL(mm_iommu_find);
 
 long mm_iommu_ua_to_hpa(struct mm_iommu_table_group_mem_t *mem,
-		unsigned long ua, unsigned int pageshift, unsigned long *hpa)
+		unsigned long ua, unsigned int pageshift,
+		enum dma_data_direction dir, unsigned long *hpa)
 {
 	const long entry = (ua - mem->ua) >> PAGE_SHIFT;
 	u64 *va = &mem->hpas[entry];
@@ -390,14 +398,18 @@ long mm_iommu_ua_to_hpa(struct mm_iommu_table_group_mem_t *mem,
 	if (pageshift > mem->pageshift)
 		return -EFAULT;
 
-	*hpa = *va | (ua & ~PAGE_MASK);
+	if (dir == DMA_FROM_DEVICE || dir == DMA_BIDIRECTIONAL)
+		*va |= MM_IOMMU_TABLE_GROUP_PAGE_DIRTY;
+
+	*hpa = (*va & ~MM_IOMMU_TABLE_GROUP_PAGE_MASK) | (ua & ~PAGE_MASK);
 
 	return 0;
 }
 EXPORT_SYMBOL_GPL(mm_iommu_ua_to_hpa);
 
 long mm_iommu_ua_to_hpa_rm(struct mm_iommu_table_group_mem_t *mem,
-		unsigned long ua, unsigned int pageshift, unsigned long *hpa)
+		unsigned long ua, unsigned int pageshift,
+		enum dma_data_direction dir, unsigned long *hpa)
 {
 	const long entry = (ua - mem->ua) >> PAGE_SHIFT;
 	void *va = &mem->hpas[entry];
@@ -413,7 +425,10 @@ long mm_iommu_ua_to_hpa_rm(struct mm_iommu_table_group_mem_t *mem,
 	if (!pa)
 		return -EFAULT;
 
-	*hpa = *pa | (ua & ~PAGE_MASK);
+	if (dir == DMA_FROM_DEVICE || dir == DMA_BIDIRECTIONAL)
+		*pa |= MM_IOMMU_TABLE_GROUP_PAGE_DIRTY;
+
+	*hpa = (*pa & ~MM_IOMMU_TABLE_GROUP_PAGE_MASK) | (ua & ~PAGE_MASK);
 
 	return 0;
 }
diff --git a/drivers/vfio/vfio_iommu_spapr_tce.c b/drivers/vfio/vfio_iommu_spapr_tce.c
index 96721b1..8fea7cd1 100644
--- a/drivers/vfio/vfio_iommu_spapr_tce.c
+++ b/drivers/vfio/vfio_iommu_spapr_tce.c
@@ -410,16 +410,21 @@ static void tce_iommu_release(void *iommu_data)
 }
 
 static void tce_iommu_unuse_page(struct tce_container *container,
-		unsigned long hpa)
+		unsigned long hpa, enum dma_data_direction dir)
 {
 	struct page *page;
 
 	page = pfn_to_page(hpa >> PAGE_SHIFT);
+
+	if (dir == DMA_FROM_DEVICE || dir == DMA_BIDIRECTIONAL)
+		SetPageDirty(page);
+
 	put_page(page);
 }
 
 static int tce_iommu_prereg_ua_to_hpa(struct tce_container *container,
 		unsigned long tce, unsigned long shift,
+		enum dma_data_direction dir,
 		unsigned long *phpa, struct mm_iommu_table_group_mem_t **pmem)
 {
 	long ret = 0;
@@ -429,7 +434,7 @@ static int tce_iommu_prereg_ua_to_hpa(struct tce_container *container,
 	if (!mem)
 		return -EINVAL;
 
-	ret = mm_iommu_ua_to_hpa(mem, tce, shift, phpa);
+	ret = mm_iommu_ua_to_hpa(mem, tce, shift, dir, phpa);
 	if (ret)
 		return -EINVAL;
 
@@ -450,10 +455,17 @@ static void tce_iommu_unuse_page_v2(struct tce_container *container,
 		return;
 
 	ret = tce_iommu_prereg_ua_to_hpa(container, be64_to_cpu(*pua),
-			tbl->it_page_shift, &hpa, &mem);
+			tbl->it_page_shift, DMA_NONE, &hpa, &mem);
 	if (ret)
 		pr_debug("%s: tce %llx at #%lx was not cached, ret=%d\n",
 				__func__, be64_to_cpu(*pua), entry, ret);
+
+	/*
+	 * VFIO_SPAPR_TCE_v2_IOMMU requires preregistered memory which
+	 * keeps track of dirty pages separately so we do not call
+	 * SetPageDirty(page) here unlike tce_iommu_unuse_page() does.
+	 */
+
 	if (mem)
 		mm_iommu_mapped_dec(mem);
 
@@ -485,7 +497,7 @@ static int tce_iommu_clear(struct tce_container *container,
 			continue;
 		}
 
-		tce_iommu_unuse_page(container, oldhpa);
+		tce_iommu_unuse_page(container, oldhpa, direction);
 	}
 
 	return 0;
@@ -532,7 +544,7 @@ static long tce_iommu_build(struct tce_container *container,
 		dirtmp = direction;
 		ret = iommu_tce_xchg(tbl, entry + i, &hpa, &dirtmp);
 		if (ret) {
-			tce_iommu_unuse_page(container, hpa);
+			tce_iommu_unuse_page(container, hpa, dirtmp);
 			pr_err("iommu_tce: %s failed ioba=%lx, tce=%lx, ret=%ld\n",
 					__func__, entry << tbl->it_page_shift,
 					tce, ret);
@@ -540,7 +552,7 @@ static long tce_iommu_build(struct tce_container *container,
 		}
 
 		if (dirtmp != DMA_NONE)
-			tce_iommu_unuse_page(container, hpa);
+			tce_iommu_unuse_page(container, hpa, dirtmp);
 
 		tce += IOMMU_PAGE_SIZE(tbl);
 	}
@@ -566,7 +578,7 @@ static long tce_iommu_build_v2(struct tce_container *container,
 		__be64 *pua = IOMMU_TABLE_USERSPACE_ENTRY(tbl, entry + i);
 
 		ret = tce_iommu_prereg_ua_to_hpa(container,
-				tce, tbl->it_page_shift, &hpa, &mem);
+				tce, tbl->it_page_shift, direction, &hpa, &mem);
 		if (ret)
 			break;
 
-- 
2.11.0

^ permalink raw reply related

* [PATCH kernel] KVM: PPC: Remove redundand permission bits removal
From: Alexey Kardashevskiy @ 2018-09-06  9:51 UTC (permalink / raw)
  To: linuxppc-dev; +Cc: Alexey Kardashevskiy, David Gibson, kvm-ppc, Paul Mackerras

The kvmppc_gpa_to_ua() helper itself takes care of the permission
bits in the TCE and yet every single caller removes them.

This changes semantics of kvmppc_gpa_to_ua() so it takes TCEs
(which are GPAs + TCE permission bits) to make the callers simpler.

This should cause no behavioural change.

Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
---

This is not related to any bug, just noticed this while doing other things.

I can also rename kvmppc_gpa_to_ua() if it makes more sense, does not it?

---
 arch/powerpc/kvm/book3s_64_vio.c    | 10 +++-------
 arch/powerpc/kvm/book3s_64_vio_hv.c | 16 ++++++----------
 2 files changed, 9 insertions(+), 17 deletions(-)

diff --git a/arch/powerpc/kvm/book3s_64_vio.c b/arch/powerpc/kvm/book3s_64_vio.c
index 174299d..7207481 100644
--- a/arch/powerpc/kvm/book3s_64_vio.c
+++ b/arch/powerpc/kvm/book3s_64_vio.c
@@ -378,8 +378,7 @@ static long kvmppc_tce_validate(struct kvmppc_spapr_tce_table *stt,
 	if (iommu_tce_check_gpa(stt->page_shift, gpa))
 		return H_TOO_HARD;
 
-	if (kvmppc_gpa_to_ua(stt->kvm, tce & ~(TCE_PCI_READ | TCE_PCI_WRITE),
-				&ua, NULL))
+	if (kvmppc_gpa_to_ua(stt->kvm, tce, &ua, NULL))
 		return H_TOO_HARD;
 
 	list_for_each_entry_rcu(stit, &stt->iommu_tables, next) {
@@ -553,8 +552,7 @@ long kvmppc_h_put_tce(struct kvm_vcpu *vcpu, unsigned long liobn,
 
 	idx = srcu_read_lock(&vcpu->kvm->srcu);
 
-	if ((dir != DMA_NONE) && kvmppc_gpa_to_ua(vcpu->kvm,
-			tce & ~(TCE_PCI_READ | TCE_PCI_WRITE), &ua, NULL)) {
+	if ((dir != DMA_NONE) && kvmppc_gpa_to_ua(vcpu->kvm, tce, &ua, NULL)) {
 		ret = H_PARAMETER;
 		goto unlock_exit;
 	}
@@ -647,9 +645,7 @@ long kvmppc_h_put_tce_indirect(struct kvm_vcpu *vcpu,
 		}
 		tce = be64_to_cpu(tce);
 
-		if (kvmppc_gpa_to_ua(vcpu->kvm,
-				tce & ~(TCE_PCI_READ | TCE_PCI_WRITE),
-				&ua, NULL))
+		if (kvmppc_gpa_to_ua(vcpu->kvm, tce, &ua, NULL))
 			return H_PARAMETER;
 
 		list_for_each_entry_lockless(stit, &stt->iommu_tables, next) {
diff --git a/arch/powerpc/kvm/book3s_64_vio_hv.c b/arch/powerpc/kvm/book3s_64_vio_hv.c
index 5f810dc..a03cd93 100644
--- a/arch/powerpc/kvm/book3s_64_vio_hv.c
+++ b/arch/powerpc/kvm/book3s_64_vio_hv.c
@@ -110,8 +110,7 @@ static long kvmppc_rm_tce_validate(struct kvmppc_spapr_tce_table *stt,
 	if (iommu_tce_check_gpa(stt->page_shift, gpa))
 		return H_PARAMETER;
 
-	if (kvmppc_gpa_to_ua(stt->kvm, tce & ~(TCE_PCI_READ | TCE_PCI_WRITE),
-				&ua, NULL))
+	if (kvmppc_gpa_to_ua(stt->kvm, tce, &ua, NULL))
 		return H_TOO_HARD;
 
 	list_for_each_entry_lockless(stit, &stt->iommu_tables, next) {
@@ -180,10 +179,10 @@ void kvmppc_tce_put(struct kvmppc_spapr_tce_table *stt,
 }
 EXPORT_SYMBOL_GPL(kvmppc_tce_put);
 
-long kvmppc_gpa_to_ua(struct kvm *kvm, unsigned long gpa,
+long kvmppc_gpa_to_ua(struct kvm *kvm, unsigned long tce,
 		unsigned long *ua, unsigned long **prmap)
 {
-	unsigned long gfn = gpa >> PAGE_SHIFT;
+	unsigned long gfn = tce >> PAGE_SHIFT;
 	struct kvm_memory_slot *memslot;
 
 	memslot = search_memslots(kvm_memslots(kvm), gfn);
@@ -191,7 +190,7 @@ long kvmppc_gpa_to_ua(struct kvm *kvm, unsigned long gpa,
 		return -EINVAL;
 
 	*ua = __gfn_to_hva_memslot(memslot, gfn) |
-		(gpa & ~(PAGE_MASK | TCE_PCI_READ | TCE_PCI_WRITE));
+		(tce & ~(PAGE_MASK | TCE_PCI_READ | TCE_PCI_WRITE));
 
 #ifdef CONFIG_KVM_BOOK3S_HV_POSSIBLE
 	if (prmap)
@@ -366,8 +365,7 @@ long kvmppc_rm_h_put_tce(struct kvm_vcpu *vcpu, unsigned long liobn,
 		return ret;
 
 	dir = iommu_tce_direction(tce);
-	if ((dir != DMA_NONE) && kvmppc_gpa_to_ua(vcpu->kvm,
-			tce & ~(TCE_PCI_READ | TCE_PCI_WRITE), &ua, NULL))
+	if ((dir != DMA_NONE) && kvmppc_gpa_to_ua(vcpu->kvm, tce, &ua, NULL))
 		return H_PARAMETER;
 
 	entry = ioba >> stt->page_shift;
@@ -520,9 +518,7 @@ long kvmppc_rm_h_put_tce_indirect(struct kvm_vcpu *vcpu,
 		unsigned long tce = be64_to_cpu(((u64 *)tces)[i]);
 
 		ua = 0;
-		if (kvmppc_gpa_to_ua(vcpu->kvm,
-				tce & ~(TCE_PCI_READ | TCE_PCI_WRITE),
-				&ua, NULL))
+		if (kvmppc_gpa_to_ua(vcpu->kvm, tce, &ua, NULL))
 			return H_PARAMETER;
 
 		list_for_each_entry_lockless(stit, &stt->iommu_tables, next) {
-- 
2.11.0

^ permalink raw reply related


This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox