Re: [PATCH] mm/gup: stop leaking pinned pages in low memory conditions

John Hubbard
2024-10-16T22:23:14Z

On 10/16/24 3:13 PM, Alistair Popple wrote:
> John Hubbard <jhubbard@nvidia.com> writes:
...
>> diff --git a/mm/gup.c b/mm/gup.c
>> index a82890b46a36..24acf53c8294 100644
>> --- a/mm/gup.c
>> +++ b/mm/gup.c
>> @@ -2492,6 +2492,17 @@ static long __gup_longterm_locked(struct mm_struct *mm,
>>
>> /* FOLL_LONGTERM implies FOLL_PIN */
>> rc = check_and_migrate_movable_pages(nr_pinned_pages, pages);
>> +
>> + /*
>> + * The __get_user_pages_locked() call happens before we know
>> + * that whether it's possible to successfully complete the whole
>> + * operation. To compensate for this, if we get an unexpected
>> + * error (such as -ENOMEM) then we must unpin everything, before
>> + * erroring out.
>> + */
>> + if (rc != -EAGAIN && rc != 0)
>> + unpin_user_pages(pages, nr_pinned_pages);
>
> I know this is going to fall out of the loop in the next line but given
> this is an error handling case it would be nice if this was made
> explicit here with a break statement. It looks correct to me though so:

Yes, I'm not sure that adding another line of code for cosmetics really
makes this better. At this point, smaller is better IMHO, and then the
next step should be something bigger, such as refactoring to avoid the
tri-state return codes.

>
> Reviewed-by: Alistair Popple <apopple@nvidia.com>

Thanks for the super fast response and the review!

thanks,
--
John Hubbard