BACKPORT: FROMGIT: hugetlb: pass vma into huge_pte_alloc() and huge_pmd_share()
Patch series "hugetlb: Disable huge pmd unshare for uffd-wp", v4. This series tries to disable huge pmd unshare of hugetlbfs backed memory for uffd-wp. Although uffd-wp of hugetlbfs is still during rfc stage, the idea of this series may be needed for multiple tasks (Axel's uffd minor fault series, and Mike's soft dirty series), so I picked it out from the larger series. This patch (of 4): It is a preparation work to be able to behave differently in the per architecture huge_pte_alloc() according to different VMA attributes. Pass it deeper into huge_pmd_share() so that we can avoid the find_vma() call. Link: https://lkml.kernel.org/r/20210218230633.15028-1-peterx@redhat.com Link: https://lkml.kernel.org/r/20210218230633.15028-2-peterx@redhat.com Signed-off-by: Peter Xu <peterx@redhat.com> Suggested-by: Mike Kravetz <mike.kravetz@oracle.com> Cc: Adam Ruprecht <ruprecht@google.com> Cc: Alexander Viro <viro@zeniv.linux.org.uk> Cc: Alexey Dobriyan <adobriyan@gmail.com> Cc: Andrea Arcangeli <aarcange@redhat.com> Cc: Anshuman Khandual <anshuman.khandual@arm.com> Cc: Axel Rasmussen <axelrasmussen@google.com> Cc: Cannon Matthews <cannonmatthews@google.com> Cc: Catalin Marinas <catalin.marinas@arm.com> Cc: Chinwen Chang <chinwen.chang@mediatek.com> Cc: David Rientjes <rientjes@google.com> Cc: "Dr . David Alan Gilbert" <dgilbert@redhat.com> Cc: Huang Ying <ying.huang@intel.com> Cc: Ingo Molnar <mingo@redhat.com> Cc: Jann Horn <jannh@google.com> Cc: Jerome Glisse <jglisse@redhat.com> Cc: Kirill A. Shutemov <kirill@shutemov.name> Cc: Lokesh Gidra <lokeshgidra@google.com> Cc: "Matthew Wilcox (Oracle)" <willy@infradead.org> Cc: Michael Ellerman <mpe@ellerman.id.au> Cc: "Michal Koutn" <mkoutny@suse.com> Cc: Michel Lespinasse <walken@google.com> Cc: Mike Rapoport <rppt@linux.vnet.ibm.com> Cc: Mina Almasry <almasrymina@google.com> Cc: Nicholas Piggin <npiggin@gmail.com> Cc: Oliver Upton <oupton@google.com> Cc: Shaohua Li <shli@fb.com> Cc: Shawn Anastasio <shawn@anastas.io> Cc: Steven Price <steven.price@arm.com> Cc: Steven Rostedt <rostedt@goodmis.org> Cc: Vlastimil Babka <vbabka@suse.cz> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Stephen Rothwell <sfr@canb.auug.org.au> (cherry picked from commit b92dc1bfd52ecf338c024815a7c1d44e37a507a1 https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git akpm) Link: https://lore.kernel.org/patchwork/patch/1382205/ Conflicts: arch/sparc/mm/hugetlbpage.c (1.Resolved by manual rebase) Signed-off-by: Lokesh Gidra <lokeshgidra@google.com> Bug: 160737021 Bug: 169683130 Change-Id: I50db4e27f2951a5ee01b0dfa22c1ece34e79f881
This commit is contained in:
15
mm/hugetlb.c
15
mm/hugetlb.c
@@ -3832,7 +3832,7 @@ int copy_hugetlb_page_range(struct mm_struct *dst, struct mm_struct *src,
|
||||
src_pte = huge_pte_offset(src, addr, sz);
|
||||
if (!src_pte)
|
||||
continue;
|
||||
dst_pte = huge_pte_alloc(dst, addr, sz);
|
||||
dst_pte = huge_pte_alloc(dst, vma, addr, sz);
|
||||
if (!dst_pte) {
|
||||
ret = -ENOMEM;
|
||||
break;
|
||||
@@ -4571,7 +4571,7 @@ vm_fault_t hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
|
||||
*/
|
||||
mapping = vma->vm_file->f_mapping;
|
||||
i_mmap_lock_read(mapping);
|
||||
ptep = huge_pte_alloc(mm, haddr, huge_page_size(h));
|
||||
ptep = huge_pte_alloc(mm, vma, haddr, huge_page_size(h));
|
||||
if (!ptep) {
|
||||
i_mmap_unlock_read(mapping);
|
||||
return VM_FAULT_OOM;
|
||||
@@ -5375,9 +5375,9 @@ void adjust_range_if_pmd_sharing_possible(struct vm_area_struct *vma,
|
||||
* if !vma_shareable check at the beginning of the routine. i_mmap_rwsem is
|
||||
* only required for subsequent processing.
|
||||
*/
|
||||
pte_t *huge_pmd_share(struct mm_struct *mm, unsigned long addr, pud_t *pud)
|
||||
pte_t *huge_pmd_share(struct mm_struct *mm, struct vm_area_struct *vma,
|
||||
unsigned long addr, pud_t *pud)
|
||||
{
|
||||
struct vm_area_struct *vma = find_vma(mm, addr);
|
||||
struct address_space *mapping = vma->vm_file->f_mapping;
|
||||
pgoff_t idx = ((addr - vma->vm_start) >> PAGE_SHIFT) +
|
||||
vma->vm_pgoff;
|
||||
@@ -5455,7 +5455,8 @@ int huge_pmd_unshare(struct mm_struct *mm, struct vm_area_struct *vma,
|
||||
}
|
||||
#define want_pmd_share() (1)
|
||||
#else /* !CONFIG_ARCH_WANT_HUGE_PMD_SHARE */
|
||||
pte_t *huge_pmd_share(struct mm_struct *mm, unsigned long addr, pud_t *pud)
|
||||
pte_t *huge_pmd_share(struct mm_struct *mm, struct vm_area_struct vma,
|
||||
unsigned long addr, pud_t *pud)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
@@ -5474,7 +5475,7 @@ void adjust_range_if_pmd_sharing_possible(struct vm_area_struct *vma,
|
||||
#endif /* CONFIG_ARCH_WANT_HUGE_PMD_SHARE */
|
||||
|
||||
#ifdef CONFIG_ARCH_WANT_GENERAL_HUGETLB
|
||||
pte_t *huge_pte_alloc(struct mm_struct *mm,
|
||||
pte_t *huge_pte_alloc(struct mm_struct *mm, struct vm_area_struct *vma,
|
||||
unsigned long addr, unsigned long sz)
|
||||
{
|
||||
pgd_t *pgd;
|
||||
@@ -5493,7 +5494,7 @@ pte_t *huge_pte_alloc(struct mm_struct *mm,
|
||||
} else {
|
||||
BUG_ON(sz != PMD_SIZE);
|
||||
if (want_pmd_share() && pud_none(*pud))
|
||||
pte = huge_pmd_share(mm, addr, pud);
|
||||
pte = huge_pmd_share(mm, vma, addr, pud);
|
||||
else
|
||||
pte = (pte_t *)pmd_alloc(mm, pud, addr);
|
||||
}
|
||||
|
Reference in New Issue
Block a user