Re: [PATCH 6/8] hugetlb: add vma based lock for pmd sharing

Miaohe Lin
2022-09-08T02:04:32Z

On 2022/9/8 4:50, Mike Kravetz wrote:
> On 08/29/22 15:24, Mike Kravetz wrote:
>> On 08/27/22 17:30, Miaohe Lin wrote:
>>> On 2022/8/25 1:57, Mike Kravetz wrote:
>>>> Allocate a rw semaphore and hang off vm_private_data for
>>>> synchronization use by vmas that could be involved in pmd sharing. Only
>>>> add infrastructure for the new lock here. Actual use will be added in
>>>> subsequent patch.
>>>>
>>>> Signed-off-by: Mike Kravetz <mike.kravetz@oracle.com>
>>>
>>> <snip>
>>>
>>>> +static void hugetlb_vma_lock_free(struct vm_area_struct *vma)
>>>> +{
>>>> + /*
>>>> + * Only present in sharable vmas. See comment in
>>>> + * __unmap_hugepage_range_final about the neeed to check both
>>>
>>> s/neeed/need/
>>>
>>>> + * VM_SHARED and VM_MAYSHARE in free path
>>>
>>> I think there might be some wrong checks around this patch. As above comment said, we
>>> need to check both flags, so we should do something like below instead?
>>>
>>> if (!(vma->vm_flags & (VM_MAYSHARE | VM_SHARED) == (VM_MAYSHARE | VM_SHARED)))
>>>
>>>> + */
>>
>> Thanks. I will update.
>>
>>>> + if (!vma || !(vma->vm_flags & (VM_MAYSHARE | VM_SHARED)))
>>>> + return;
>
> I think you misunderstood the comment which I admit was not very clear. And,
> I misunderstood your suggestion. I believe the code is correct as it. Here
> is the proposed update comment/code:
>
> /*
> * Only present in sharable vmas. See comment in
> * __unmap_hugepage_range_final about how VM_SHARED could
> * be set without VM_MAYSHARE. As a result, we need to
> * check if either is set in the free path.
> */
> if (!vma || !(vma->vm_flags & (VM_MAYSHARE | VM_SHARED)))
> return;
>
> Hopefully, that makes more sense.

Somewhat confusing. Thanks for clarifying, Mike.

Thanks,
Miaohe Lin