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

From: Miaohe Lin
Date: Sat Sep 24 2022 - 09:12:26 EST


On 2022/9/15 6:18, Mike Kravetz wrote:
> Allocate a new hugetlb_vma_lock structure and hang off vm_private_data
> for synchronization use by vmas that could be involved in pmd sharing.
> This data structure contains a rw semaphore that is the primary tool
> used for synchronization.
>
> This new structure is ref counted, so that it can exist when NOT attached
> to a vma. This is only helpful in resolving lock ordering issues where
> code may need to obtain the vma_lock while there are no guarantees the
> vma may go away. By obtaining a ref on the structure, it can be
> guaranteed that at least the rw semaphore will not go away.
>
> Only add infrastructure for the new lock here. Actual use will be added
> in subsequent patches.
>
> Signed-off-by: Mike Kravetz <mike.kravetz@xxxxxxxxxx>

LGTM with some nits below. Thanks for your work, Mike.

Reviewed-by: Miaohe Lin <linmiaohe@xxxxxxxxxx>

> -/* Reset counters to 0 and clear all HPAGE_RESV_* flags */
> -void reset_vma_resv_huge_pages(struct vm_area_struct *vma)
> +void hugetlb_dup_vma_private(struct vm_area_struct *vma)
> {
> VM_BUG_ON_VMA(!is_vm_hugetlb_page(vma), vma);
> + /*
> + * Clear vm_private_data
> + * - For MAP_PRIVATE mappings, this is the reserve map which does
> + * not apply to children. Faults generated by the children are
> + * not guaranteed to succeed, even if read-only.
> + * - For shared mappings this is a per-vma semaphore that may be
> + * allocated in a subsequent call to hugetlb_vm_op_open.
> + */
> + vma->vm_private_data = (void *)0;
> if (!(vma->vm_flags & VM_MAYSHARE))
> - vma->vm_private_data = (void *)0;
> + return;

This if block can be deleted ? It doesn't do anything here.

> }
>
> /*

<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 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;
> +
> + if (vma->vm_private_data) {
> + struct hugetlb_vma_lock *vma_lock = vma->vm_private_data;
> +
> + /*
> + * vma_lock structure may or not be released, but it

may or not be released?

Thanks,
Miaohe Lin