Skip to content

Commit 0175ab6

Browse files
Hugh Dickinsakpm00
authored andcommitted
mm/khugepaged: fix conflicting mods to collapse_file()
Inserting Ivan Orlov's syzbot fix commit 2ce0bdf ("mm: khugepaged: fix kernel BUG in hpage_collapse_scan_file()") ahead of Jiaqi Yan's and David Stevens's commits 12904d9 ("mm/khugepaged: recover from poisoned file-backed memory") cae106d ("mm/khugepaged: refactor collapse_file control flow") ac492b9 ("mm/khugepaged: skip shmem with userfaultfd") (all of which restructure collapse_file()) did not work out well. xfstests generic/086 on huge tmpfs (with accelerated khugepaged) freezes (if not on the first attempt, then the 2nd or 3rd) in find_lock_entries() while doing drop_caches: the file's xarray seems to have been corrupted, with find_get_entry() returning nonsense which makes no progress. Bisection led to ac492b9; and diff against earlier working linux-next suggested that it's probably down to an errant xas_store(), which does not belong with the later changes (and nor does the positioning of warnings). The later changes look as if they fix the syzbot issue independently. Remove most of what's left of 2ce0bdf: just leave one WARN_ON_ONCE (xas_error) after the final xas_store() of the multi-index entry. Link: https://lkml.kernel.org/r/b6c881-c352-bb91-85a8-febeb09dfd71@google.com Signed-off-by: Hugh Dickins <hughd@google.com> Cc: David Stevens <stevensd@chromium.org> Cc: Ivan Orlov <ivan.orlov0322@gmail.com> Cc: Jiaqi Yan <jiaqiyan@google.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
1 parent f0ca8c2 commit 0175ab6

1 file changed

Lines changed: 1 addition & 22 deletions

File tree

mm/khugepaged.c

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1941,16 +1941,6 @@ static int collapse_file(struct mm_struct *mm, unsigned long addr,
19411941
result = SCAN_FAIL;
19421942
goto xa_locked;
19431943
}
1944-
xas_store(&xas, hpage);
1945-
if (xas_error(&xas)) {
1946-
/* revert shmem_charge performed
1947-
* in the previous condition
1948-
*/
1949-
mapping->nrpages--;
1950-
shmem_uncharge(mapping->host, 1);
1951-
result = SCAN_STORE_FAILED;
1952-
goto xa_locked;
1953-
}
19541944
nr_none++;
19551945
continue;
19561946
}
@@ -2105,13 +2095,6 @@ static int collapse_file(struct mm_struct *mm, unsigned long addr,
21052095
* Accumulate the pages that are being collapsed.
21062096
*/
21072097
list_add_tail(&page->lru, &pagelist);
2108-
2109-
/*
2110-
* We can't get an ENOMEM here (because the allocation happened
2111-
* before) but let's check for errors (XArray implementation
2112-
* can be changed in the future)
2113-
*/
2114-
WARN_ON_ONCE(xas_error(&xas));
21152098
continue;
21162099
out_unlock:
21172100
unlock_page(page);
@@ -2134,11 +2117,6 @@ static int collapse_file(struct mm_struct *mm, unsigned long addr,
21342117
}
21352118
}
21362119

2137-
/* Here we can't get an ENOMEM (because entries were
2138-
* previously allocated) But let's check for errors
2139-
* (XArray implementation can be changed in the future)
2140-
*/
2141-
WARN_ON_ONCE(xas_error(&xas));
21422120
xa_locked:
21432121
xas_unlock_irq(&xas);
21442122
xa_unlocked:
@@ -2259,6 +2237,7 @@ static int collapse_file(struct mm_struct *mm, unsigned long addr,
22592237
/* Join all the small entries into a single multi-index entry. */
22602238
xas_set_order(&xas, start, HPAGE_PMD_ORDER);
22612239
xas_store(&xas, hpage);
2240+
WARN_ON_ONCE(xas_error(&xas));
22622241
xas_unlock_irq(&xas);
22632242

22642243
/*

0 commit comments

Comments
 (0)