Re: [PATCH -next] mm/hugetlb: Fix file_region entry allocations

From: Mike Kravetz
Date: Tue Feb 18 2020 - 18:43:22 EST


On 2/18/20 2:26 PM, Mina Almasry wrote:
> Commit a9e443086489e ("hugetlb: disable region_add file_region
> coalescing") introduced a bug with adding file_region entries
> that is fixed here:
>
> 1. Refactor file_region entry allocation logic into 1 function called
> from region_add and region_chg since the code is now identical.
> 2. region_chg only modifies resv->adds_in_progress after the regions
> have been allocated. In the past it used to increment
> adds_in_progress and then drop the lock, which would confuse racing
> region_add calls into thinking they need to allocate entries when
> they are not allowed.
> 3. In region_add, only try to allocate regions when
> actual_regions_needed > in_regions_needed. This is not causing a bug
> but is better for cleanliness and reasoning about the code.
>
> Tested using ltp hugemmap0* tests, and libhugetlbfs tests.
>
> Reported-by: Qian Cai <cai@xxxxxx>
> Signed-off-by: Mina Almasry <almasrymina@xxxxxxxxxx>
> Fixes: Commit a9e443086489e ("hugetlb: disable region_add file_region
> coalescing")
>
> ---
> mm/hugetlb.c | 149 +++++++++++++++++++++++++--------------------------
> 1 file changed, 74 insertions(+), 75 deletions(-)
>
> diff --git a/mm/hugetlb.c b/mm/hugetlb.c
> index 8171d2211be77..3d5b48ae8971f 100644
> --- a/mm/hugetlb.c
> +++ b/mm/hugetlb.c
> @@ -439,6 +439,66 @@ static long add_reservation_in_range(struct resv_map *resv, long f, long t,
> return add;
> }
>
> +/* Must be called with resv->lock acquired. Will drop lock to allocate entries.
> + */
> +static int allocate_file_region_entries(struct resv_map *resv,
> + int regions_needed)
> +{

I think this is going to need annotation for the lock or sparse is going
throw a warning. See,

https://lore.kernel.org/linux-mm/20200214204741.94112-7-jbi.octave@xxxxxxxxx/

Other than that, looks good. Sorry I missed that race in the review.
--
Mike Kravetz