• Peter Xu's avatar
    mm/hugetlb: introduce hugetlb_walk() · 9c67a207
    Peter Xu authored
    huge_pte_offset() is the main walker function for hugetlb pgtables.  The
    name is not really representing what it does, though.
    
    Instead of renaming it, introduce a wrapper function called hugetlb_walk()
    which will use huge_pte_offset() inside.  Assert on the locks when walking
    the pgtable.
    
    Note, the vma lock assertion will be a no-op for private mappings.
    
    Document the last special case in the page_vma_mapped_walk() path where we
    don't need any more lock to call hugetlb_walk().
    
    Taking vma lock there is not needed because either: (1) potential callers
    of hugetlb pvmw holds i_mmap_rwsem already (from one rmap_walk()), or (2)
    the caller will not walk a hugetlb vma at all so the hugetlb code path not
    reachable (e.g.  in ksm or uprobe paths).
    
    It's slightly implicit for future page_vma_mapped_walk() callers on that
    lock requirement.  But anyway, when one day this rule breaks, one will get
    a straightforward warning in hugetlb_walk() with lockdep, then there'll be
    a way out.
    
    [akpm@linux-foundation.org: coding-style cleanups]
    Link: https://lkml.kernel.org/r/20221216155229.2043750-1-peterx@redhat.comSigned-off-by: default avatarPeter Xu <peterx@redhat.com>
    Reviewed-by: default avatarMike Kravetz <mike.kravetz@oracle.com>
    Reviewed-by: default avatarJohn Hubbard <jhubbard@nvidia.com>
    Reviewed-by: default avatarDavid Hildenbrand <david@redhat.com>
    Cc: Andrea Arcangeli <aarcange@redhat.com>
    Cc: James Houghton <jthoughton@google.com>
    Cc: Jann Horn <jannh@google.com>
    Cc: Miaohe Lin <linmiaohe@huawei.com>
    Cc: Muchun Song <songmuchun@bytedance.com>
    Cc: Nadav Amit <nadav.amit@gmail.com>
    Cc: Rik van Riel <riel@surriel.com>
    Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
    9c67a207
hugetlb.c 208 KB