Re: [PATCH] hugetlb: detect race if fail to COW

From: Hillf Danton
Date: Fri Nov 18 2011 - 09:47:03 EST


On Fri, Nov 18, 2011 at 10:21 PM, John Kacur <jkacur@xxxxxxxxxx> wrote:
> On Fri, Nov 18, 2011 at 3:16 PM, John Kacur <jkacur@xxxxxxxxxx> wrote:
>> On Fri, Nov 18, 2011 at 3:04 PM, Hillf Danton <dhillf@xxxxxxxxx> wrote:
>>> In the error path that we fail to allocate new huge page, before try again, we
>>> have to check race since page_table_lock is re-acquired.
>>>
>>> If racing, our job is done.
>>>
>>> Signed-off-by: Hillf Danton <dhillf@xxxxxxxxx>
>>> ---
>>>
>>> --- a/mm/hugetlb.c   ÂFri Nov 18 21:38:30 2011
>>> +++ b/mm/hugetlb.c   ÂFri Nov 18 21:48:15 2011
>>> @@ -2407,7 +2407,14 @@ retry_avoidcopy:
>>> Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â ÂBUG_ON(page_count(old_page) != 1);
>>> Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â ÂBUG_ON(huge_pte_none(pte));
>>> Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Âspin_lock(&mm->page_table_lock);
>>> - Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â goto retry_avoidcopy;
>>> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â ptep = huge_pte_offset(mm, address & huge_page_mask(h));
>>> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â if (likely(pte_same(huge_ptep_get(ptep), pte)))
>>> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â goto retry_avoidcopy;
>>> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â /*
>>> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â* race occurs while re-acquiring page_table_lock, and
>>> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â* our job is done.
>>> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â*/
>>> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â return 0;
>>> Â Â Â Â Â Â Â Â Â Â Â Â}
>>> Â Â Â Â Â Â Â Â Â Â Â ÂWARN_ON_ONCE(1);
>>> Â Â Â Â Â Â Â Â}
>>
>>
>> I'm not sure about the veracity of the race condition, but you better
>> do spin_unlock before you return.
>>
>
> Ugh, sorry for the noise, I see that's not how it works here.

Welcome:)
èº{.nÇ+‰·Ÿ®‰­†+%ŠËlzwm…ébëæìr¸›zX§»®w¥Š{ayºÊÚë,j­¢f£¢·hš‹àz¹®w¥¢¸ ¢·¦j:+v‰¨ŠwèjØm¶Ÿÿ¾«‘êçzZ+ƒùšŽŠÝj"ú!¶iO•æ¬z·švØ^¶m§ÿðà nÆàþY&—