Re: [PATCH] mm: gup: fix the fast GUP race against THP collapse

From: John Hubbard
Date: Tue Sep 06 2022 - 17:28:26 EST


On 9/6/22 11:50, Yang Shi wrote:
>>> - if (unlikely(pte_val(pte) != pte_val(*ptep))) {
>>> + /*
>>> + * THP collapse conceptually does:
>>> + * 1. Clear and flush PMD
>>> + * 2. Check the base page refcount
>>> + * 3. Copy data to huge page
>>> + * 4. Clear PTE
>>> + * 5. Discard the base page
>>> + *
>>> + * So fast GUP may race with THP collapse then pin and
>>> + * return an old page since TLB flush is no longer sufficient
>>> + * to serialize against fast GUP.
>>> + *
>>> + * Check PMD, if it is changed just back off since it
>>> + * means there may be parallel THP collapse.
>>> + */
>>
>> As I mentioned in the other thread, it would be a nice touch to move
>> such discussion into the comment header.
>
> Sure, you mean the comment before gup_pte_range() so that the real
> code stays succinct, right?
Yes.

thanks,

--
John Hubbard
NVIDIA