Re: [PATCH] lib/genalloc: Set chunk size to real size which gen_pool managed.

From: Andrew Morton
Date: Mon Jun 13 2022 - 15:44:02 EST


On Sun, 12 Jun 2022 18:59:37 +0800 wuchi <wuchi.zero@xxxxxxxxx> wrote:

> The demand size (chunk->avail > size > round_down(chunk->avail)) will
> lead to meaningless algo calls in gen_pool_alloc_algo_owner without the
> patch, alse move the follow code:
> size = nbits << order
> out of read-side critical section.
>

Nobody has seriously worked on this code in a long time :(

Please expand more on the flaw. What are "algo calls"? Why are they
meaningless, etc? What are the runtime effects of this error?

> --- a/lib/genalloc.c
> +++ b/lib/genalloc.c
> @@ -193,6 +193,7 @@ int gen_pool_add_owner(struct gen_pool *pool, unsigned long virt, phys_addr_t ph
> if (unlikely(chunk == NULL))
> return -ENOMEM;
>
> + size = nbits << pool->min_alloc_order;

If we're going to do this then gen_pool_add_owner() no longer needs its
`size' argument.