Skip to content

Commit ae9fd76

Browse files
MiaoheLinakpm00
authored andcommitted
mm/memory-failure: reject unsupported non-folio compound page
When !CONFIG_TRANSPARENT_HUGEPAGE, a non-folio compound page can appear in a userspace mapping via either vm_insert_*() functions or vm_operatios_struct->fault(). They are not folios, thus should not be considered for folio operations like split. To reject these pages, make sure get_hwpoison_page() is always called as HWPoisonHandlable() will do the right work. [Some commit log borrowed from Zi Yan. Thanks.] Link: https://lkml.kernel.org/r/20260205075328.523211-1-linmiaohe@huawei.com Fixes: 689b898 ("mm/memory-failure: improve large block size folio handling") Signed-off-by: Miaohe Lin <linmiaohe@huawei.com> Reported-by: 是参差 <shicenci@gmail.com> Closes: https://lore.kernel.org/all/PS1PPF7E1D7501F1E4F4441E7ECD056DEADAB98A@PS1PPF7E1D7501F.apcprd02.prod.outlook.com/ Reviewed-by: Zi Yan <ziy@nvidia.com> Tested-by: Zi Yan <ziy@nvidia.com> Cc: David Hildenbrand <david@kernel.org> Cc: Jane Chu <jane.chu@oracle.com> Cc: Miaohe Lin <linmiaohe@huawei.com> Cc: Naoya Horiguchi <nao.horiguchi@gmail.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
1 parent b5cbacd commit ae9fd76

1 file changed

Lines changed: 20 additions & 22 deletions

File tree

mm/memory-failure.c

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2411,31 +2411,29 @@ int memory_failure(unsigned long pfn, int flags)
24112411
* In fact it's dangerous to directly bump up page count from 0,
24122412
* that may make page_ref_freeze()/page_ref_unfreeze() mismatch.
24132413
*/
2414-
if (!(flags & MF_COUNT_INCREASED)) {
2415-
res = get_hwpoison_page(p, flags);
2416-
if (!res) {
2417-
if (is_free_buddy_page(p)) {
2418-
if (take_page_off_buddy(p)) {
2419-
page_ref_inc(p);
2420-
res = MF_RECOVERED;
2421-
} else {
2422-
/* We lost the race, try again */
2423-
if (retry) {
2424-
ClearPageHWPoison(p);
2425-
retry = false;
2426-
goto try_again;
2427-
}
2428-
res = MF_FAILED;
2429-
}
2430-
res = action_result(pfn, MF_MSG_BUDDY, res);
2414+
res = get_hwpoison_page(p, flags);
2415+
if (!res) {
2416+
if (is_free_buddy_page(p)) {
2417+
if (take_page_off_buddy(p)) {
2418+
page_ref_inc(p);
2419+
res = MF_RECOVERED;
24312420
} else {
2432-
res = action_result(pfn, MF_MSG_KERNEL_HIGH_ORDER, MF_IGNORED);
2421+
/* We lost the race, try again */
2422+
if (retry) {
2423+
ClearPageHWPoison(p);
2424+
retry = false;
2425+
goto try_again;
2426+
}
2427+
res = MF_FAILED;
24332428
}
2434-
goto unlock_mutex;
2435-
} else if (res < 0) {
2436-
res = action_result(pfn, MF_MSG_GET_HWPOISON, MF_IGNORED);
2437-
goto unlock_mutex;
2429+
res = action_result(pfn, MF_MSG_BUDDY, res);
2430+
} else {
2431+
res = action_result(pfn, MF_MSG_KERNEL_HIGH_ORDER, MF_IGNORED);
24382432
}
2433+
goto unlock_mutex;
2434+
} else if (res < 0) {
2435+
res = action_result(pfn, MF_MSG_GET_HWPOISON, MF_IGNORED);
2436+
goto unlock_mutex;
24392437
}
24402438

24412439
folio = page_folio(p);

0 commit comments

Comments
 (0)