Skip to content

Commit 888af27

Browse files
MiaoheLintorvalds
authored andcommitted
mm/memory-failure.c: fix race with changing page compound again
Patch series "A few fixup patches for memory failure", v2. This series contains a few patches to fix the race with changing page compound page, make non-LRU movable pages unhandlable and so on. More details can be found in the respective changelogs. There is a race window where we got the compound_head, the hugetlb page could be freed to buddy, or even changed to another compound page just before we try to get hwpoison page. Think about the below race window: CPU 1 CPU 2 memory_failure_hugetlb struct page *head = compound_head(p); hugetlb page might be freed to buddy, or even changed to another compound page. get_hwpoison_page -- page is not what we want now... If this race happens, just bail out. Also MF_MSG_DIFFERENT_PAGE_SIZE is introduced to record this event. [[email protected]: s@/**@/*@, per Naoya Horiguchi] Link: https://lkml.kernel.org/r/[email protected] Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Miaohe Lin <[email protected]> Acked-by: Naoya Horiguchi <[email protected]> Cc: Tony Luck <[email protected]> Cc: Borislav Petkov <[email protected]> Cc: Mike Kravetz <[email protected]> Cc: Yang Shi <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent a06ad3c commit 888af27

File tree

3 files changed

+14
-0
lines changed

3 files changed

+14
-0
lines changed

include/linux/mm.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3239,6 +3239,7 @@ enum mf_action_page_type {
32393239
MF_MSG_BUDDY,
32403240
MF_MSG_DAX,
32413241
MF_MSG_UNSPLIT_THP,
3242+
MF_MSG_DIFFERENT_PAGE_SIZE,
32423243
MF_MSG_UNKNOWN,
32433244
};
32443245

include/ras/ras_event.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,7 @@ TRACE_EVENT(aer_event,
374374
EM ( MF_MSG_BUDDY, "free buddy page" ) \
375375
EM ( MF_MSG_DAX, "dax page" ) \
376376
EM ( MF_MSG_UNSPLIT_THP, "unsplit thp" ) \
377+
EM ( MF_MSG_DIFFERENT_PAGE_SIZE, "different page size" ) \
377378
EMe ( MF_MSG_UNKNOWN, "unknown page" )
378379

379380
/*

mm/memory-failure.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -732,6 +732,7 @@ static const char * const action_page_types[] = {
732732
[MF_MSG_BUDDY] = "free buddy page",
733733
[MF_MSG_DAX] = "dax page",
734734
[MF_MSG_UNSPLIT_THP] = "unsplit thp",
735+
[MF_MSG_DIFFERENT_PAGE_SIZE] = "different page size",
735736
[MF_MSG_UNKNOWN] = "unknown page",
736737
};
737738

@@ -1532,6 +1533,17 @@ static int memory_failure_hugetlb(unsigned long pfn, int flags)
15321533
}
15331534

15341535
lock_page(head);
1536+
1537+
/*
1538+
* The page could have changed compound pages due to race window.
1539+
* If this happens just bail out.
1540+
*/
1541+
if (!PageHuge(p) || compound_head(p) != head) {
1542+
action_result(pfn, MF_MSG_DIFFERENT_PAGE_SIZE, MF_IGNORED);
1543+
res = -EBUSY;
1544+
goto out;
1545+
}
1546+
15351547
page_flags = head->flags;
15361548

15371549
if (hwpoison_filter(p)) {

0 commit comments

Comments
 (0)