[PATCH v14 02/12] powerpc/irq: use memblock functions returning virtual address

Mike Rapoport rppt at linux.ibm.com
Fri Jan 25 04:25:53 AEDT 2019


On Thu, Jan 24, 2019 at 04:51:53PM +0000, Mark Rutland wrote:
> On Thu, Jan 24, 2019 at 04:19:33PM +0000, Christophe Leroy wrote:
> > Since only the virtual address of allocated blocks is used,
> > lets use functions returning directly virtual address.
> > 
> > Those functions have the advantage of also zeroing the block.
> > 
> > Suggested-by: Mike Rapoport <rppt at linux.ibm.com>
> > Acked-by: Mike Rapoport <rppt at linux.ibm.com>
> > Signed-off-by: Christophe Leroy <christophe.leroy at c-s.fr>
> 
> [...]
> 
> > +static void *__init alloc_stack(void)
> > +{
> > +	void *ptr = memblock_alloc(THREAD_SIZE, THREAD_SIZE);
> > +
> > +	if (!ptr)
> > +		panic("cannot allocate stacks");
> > +
> > +	return ptr;
> > +}
> 
> I believe memblock_alloc() will panic() if it cannot allocate memory,
> since that goes:
> 
>  memblock_alloc()
>  -> memblock_alloc_try_nid()
>     -> panic()
> 
> So you can get rid of the panic() here, or if you want a custom panic
> message, you can use memblock_alloc_nopanic().

As we've already discussed it in [1], I'm working on removing the
_nopanic() versions and dropping the panic() calls from memblock_alloc()
and friends.

I've posted v2 of the patches earlier this week [2].
 
> [...]

[1] https://lore.kernel.org/lkml/20190108143428.GB14063@rapoport-lnx/ 
[2] https://lore.kernel.org/lkml/1548057848-15136-1-git-send-email-rppt@linux.ibm.com/

> >  static void *__init alloc_stack(unsigned long limit, int cpu)
> >  {
> > -	unsigned long pa;
> > +	void *ptr;
> >  
> >  	BUILD_BUG_ON(STACK_INT_FRAME_SIZE % 16);
> >  
> > -	pa = memblock_alloc_base_nid(THREAD_SIZE, THREAD_SIZE, limit,
> > -					early_cpu_to_node(cpu), MEMBLOCK_NONE);
> > -	if (!pa) {
> > -		pa = memblock_alloc_base(THREAD_SIZE, THREAD_SIZE, limit);
> > -		if (!pa)
> > -			panic("cannot allocate stacks");
> > -	}
> > +	ptr = memblock_alloc_try_nid(THREAD_SIZE, THREAD_SIZE,
> > +				     MEMBLOCK_LOW_LIMIT, limit,
> > +				     early_cpu_to_node(cpu));
> > +	if (!ptr)
> > +		panic("cannot allocate stacks");
> 
> The same applies here -- memblock_alloc_try_nid() will panic itself
> rather than returning NULL.
> 
> Otherwise, this looks like a nice cleanup. With the panics removed (or
> using the _nopanic() allocators), feel free to add:
> 
> Acked-by: Mark Rutland <mark.rutland at arm.com>
> 
> Thanks,
> Mark.
> 

-- 
Sincerely yours,
Mike.



More information about the Linuxppc-dev mailing list