Skip to content

Commit 7b6ec18

Browse files
VMoolaakpm00
authored andcommitted
hugetlb: convert hugetlb_no_page() to use struct vm_fault
hugetlb_no_page() can use the struct vm_fault passed in from hugetlb_fault(). This alleviates the stack by consolidating 7 variables into a single struct. [[email protected]: simplify hugetlb_no_page() arguments] Link: https://lkml.kernel.org/r/ZhQtN8y5zud8iI1u@fedora Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Vishal Moola (Oracle) <[email protected]> Reviewed-by: Oscar Salvador <[email protected]> Cc: Matthew Wilcox (Oracle) <[email protected]> Cc: Muchun Song <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent 9b42fa1 commit 7b6ec18

File tree

1 file changed

+31
-32
lines changed

1 file changed

+31
-32
lines changed

mm/hugetlb.c

Lines changed: 31 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -6188,23 +6188,19 @@ static bool hugetlb_pte_stable(struct hstate *h, struct mm_struct *mm,
61886188
return same;
61896189
}
61906190

6191-
static vm_fault_t hugetlb_no_page(struct mm_struct *mm,
6192-
struct vm_area_struct *vma,
6193-
struct address_space *mapping, pgoff_t idx,
6194-
unsigned long address, pte_t *ptep,
6195-
pte_t old_pte, unsigned int flags,
6191+
static vm_fault_t hugetlb_no_page(struct address_space *mapping,
61966192
struct vm_fault *vmf)
61976193
{
6194+
struct vm_area_struct *vma = vmf->vma;
6195+
struct mm_struct *mm = vma->vm_mm;
61986196
struct hstate *h = hstate_vma(vma);
61996197
vm_fault_t ret = VM_FAULT_SIGBUS;
62006198
int anon_rmap = 0;
62016199
unsigned long size;
62026200
struct folio *folio;
62036201
pte_t new_pte;
6204-
spinlock_t *ptl;
6205-
unsigned long haddr = address & huge_page_mask(h);
62066202
bool new_folio, new_pagecache_folio = false;
6207-
u32 hash = hugetlb_fault_mutex_hash(mapping, idx);
6203+
u32 hash = hugetlb_fault_mutex_hash(mapping, vmf->pgoff);
62086204

62096205
/*
62106206
* Currently, we are forced to kill the process in the event the
@@ -6223,10 +6219,10 @@ static vm_fault_t hugetlb_no_page(struct mm_struct *mm,
62236219
* before we get page_table_lock.
62246220
*/
62256221
new_folio = false;
6226-
folio = filemap_lock_hugetlb_folio(h, mapping, idx);
6222+
folio = filemap_lock_hugetlb_folio(h, mapping, vmf->pgoff);
62276223
if (IS_ERR(folio)) {
62286224
size = i_size_read(mapping->host) >> huge_page_shift(h);
6229-
if (idx >= size)
6225+
if (vmf->pgoff >= size)
62306226
goto out;
62316227
/* Check for page in userfault range */
62326228
if (userfaultfd_missing(vma)) {
@@ -6247,7 +6243,7 @@ static vm_fault_t hugetlb_no_page(struct mm_struct *mm,
62476243
* never happen on the page after UFFDIO_COPY has
62486244
* correctly installed the page and returned.
62496245
*/
6250-
if (!hugetlb_pte_stable(h, mm, ptep, old_pte)) {
6246+
if (!hugetlb_pte_stable(h, mm, vmf->pte, vmf->orig_pte)) {
62516247
ret = 0;
62526248
goto out;
62536249
}
@@ -6262,7 +6258,7 @@ static vm_fault_t hugetlb_no_page(struct mm_struct *mm,
62626258
goto out;
62636259
}
62646260

6265-
folio = alloc_hugetlb_folio(vma, haddr, 0);
6261+
folio = alloc_hugetlb_folio(vma, vmf->address, 0);
62666262
if (IS_ERR(folio)) {
62676263
/*
62686264
* Returning error will result in faulting task being
@@ -6276,18 +6272,20 @@ static vm_fault_t hugetlb_no_page(struct mm_struct *mm,
62766272
* here. Before returning error, get ptl and make
62776273
* sure there really is no pte entry.
62786274
*/
6279-
if (hugetlb_pte_stable(h, mm, ptep, old_pte))
6275+
if (hugetlb_pte_stable(h, mm, vmf->pte, vmf->orig_pte))
62806276
ret = vmf_error(PTR_ERR(folio));
62816277
else
62826278
ret = 0;
62836279
goto out;
62846280
}
6285-
clear_huge_page(&folio->page, address, pages_per_huge_page(h));
6281+
clear_huge_page(&folio->page, vmf->real_address,
6282+
pages_per_huge_page(h));
62866283
__folio_mark_uptodate(folio);
62876284
new_folio = true;
62886285

62896286
if (vma->vm_flags & VM_MAYSHARE) {
6290-
int err = hugetlb_add_to_page_cache(folio, mapping, idx);
6287+
int err = hugetlb_add_to_page_cache(folio, mapping,
6288+
vmf->pgoff);
62916289
if (err) {
62926290
/*
62936291
* err can't be -EEXIST which implies someone
@@ -6296,7 +6294,8 @@ static vm_fault_t hugetlb_no_page(struct mm_struct *mm,
62966294
* to the page cache. So it's safe to call
62976295
* restore_reserve_on_error() here.
62986296
*/
6299-
restore_reserve_on_error(h, vma, haddr, folio);
6297+
restore_reserve_on_error(h, vma, vmf->address,
6298+
folio);
63006299
folio_put(folio);
63016300
ret = VM_FAULT_SIGBUS;
63026301
goto out;
@@ -6323,7 +6322,7 @@ static vm_fault_t hugetlb_no_page(struct mm_struct *mm,
63236322
folio_unlock(folio);
63246323
folio_put(folio);
63256324
/* See comment in userfaultfd_missing() block above */
6326-
if (!hugetlb_pte_stable(h, mm, ptep, old_pte)) {
6325+
if (!hugetlb_pte_stable(h, mm, vmf->pte, vmf->orig_pte)) {
63276326
ret = 0;
63286327
goto out;
63296328
}
@@ -6338,23 +6337,23 @@ static vm_fault_t hugetlb_no_page(struct mm_struct *mm,
63386337
* any allocations necessary to record that reservation occur outside
63396338
* the spinlock.
63406339
*/
6341-
if ((flags & FAULT_FLAG_WRITE) && !(vma->vm_flags & VM_SHARED)) {
6342-
if (vma_needs_reservation(h, vma, haddr) < 0) {
6340+
if ((vmf->flags & FAULT_FLAG_WRITE) && !(vma->vm_flags & VM_SHARED)) {
6341+
if (vma_needs_reservation(h, vma, vmf->address) < 0) {
63436342
ret = VM_FAULT_OOM;
63446343
goto backout_unlocked;
63456344
}
63466345
/* Just decrements count, does not deallocate */
6347-
vma_end_reservation(h, vma, haddr);
6346+
vma_end_reservation(h, vma, vmf->address);
63486347
}
63496348

6350-
ptl = huge_pte_lock(h, mm, ptep);
6349+
vmf->ptl = huge_pte_lock(h, mm, vmf->pte);
63516350
ret = 0;
63526351
/* If pte changed from under us, retry */
6353-
if (!pte_same(huge_ptep_get(ptep), old_pte))
6352+
if (!pte_same(huge_ptep_get(vmf->pte), vmf->orig_pte))
63546353
goto backout;
63556354

63566355
if (anon_rmap)
6357-
hugetlb_add_new_anon_rmap(folio, vma, haddr);
6356+
hugetlb_add_new_anon_rmap(folio, vma, vmf->address);
63586357
else
63596358
hugetlb_add_file_rmap(folio);
63606359
new_pte = make_huge_pte(vma, &folio->page, ((vma->vm_flags & VM_WRITE)
@@ -6363,17 +6362,18 @@ static vm_fault_t hugetlb_no_page(struct mm_struct *mm,
63636362
* If this pte was previously wr-protected, keep it wr-protected even
63646363
* if populated.
63656364
*/
6366-
if (unlikely(pte_marker_uffd_wp(old_pte)))
6365+
if (unlikely(pte_marker_uffd_wp(vmf->orig_pte)))
63676366
new_pte = huge_pte_mkuffd_wp(new_pte);
6368-
set_huge_pte_at(mm, haddr, ptep, new_pte, huge_page_size(h));
6367+
set_huge_pte_at(mm, vmf->address, vmf->pte, new_pte, huge_page_size(h));
63696368

63706369
hugetlb_count_add(pages_per_huge_page(h), mm);
6371-
if ((flags & FAULT_FLAG_WRITE) && !(vma->vm_flags & VM_SHARED)) {
6370+
if ((vmf->flags & FAULT_FLAG_WRITE) && !(vma->vm_flags & VM_SHARED)) {
63726371
/* Optimization, do the COW without a second fault */
6373-
ret = hugetlb_wp(mm, vma, address, ptep, flags, folio, ptl, vmf);
6372+
ret = hugetlb_wp(mm, vma, vmf->real_address, vmf->pte,
6373+
vmf->flags, folio, vmf->ptl, vmf);
63746374
}
63756375

6376-
spin_unlock(ptl);
6376+
spin_unlock(vmf->ptl);
63776377

63786378
/*
63796379
* Only set hugetlb_migratable in newly allocated pages. Existing pages
@@ -6390,10 +6390,10 @@ static vm_fault_t hugetlb_no_page(struct mm_struct *mm,
63906390
return ret;
63916391

63926392
backout:
6393-
spin_unlock(ptl);
6393+
spin_unlock(vmf->ptl);
63946394
backout_unlocked:
63956395
if (new_folio && !new_pagecache_folio)
6396-
restore_reserve_on_error(h, vma, haddr, folio);
6396+
restore_reserve_on_error(h, vma, vmf->address, folio);
63976397

63986398
folio_unlock(folio);
63996399
folio_put(folio);
@@ -6489,8 +6489,7 @@ vm_fault_t hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
64896489
* hugetlb_no_page will drop vma lock and hugetlb fault
64906490
* mutex internally, which make us return immediately.
64916491
*/
6492-
return hugetlb_no_page(mm, vma, mapping, vmf.pgoff, address,
6493-
vmf.pte, vmf.orig_pte, flags, &vmf);
6492+
return hugetlb_no_page(mapping, &vmf);
64946493
}
64956494

64966495
ret = 0;

0 commit comments

Comments
 (0)