Skip to content

Commit c3901e7

Browse files
Naoya Horiguchitorvalds
Naoya Horiguchi
authored andcommitted
mm: hwpoison: fix thp split handling in memory_failure()
When memory_failure() runs on a thp tail page after pmd is split, we trigger the following VM_BUG_ON_PAGE(): page:ffffd7cd819b0040 count:0 mapcount:0 mapping: (null) index:0x1 flags: 0x1fffc000400000(hwpoison) page dumped because: VM_BUG_ON_PAGE(!page_count(p)) ------------[ cut here ]------------ kernel BUG at /src/linux-dev/mm/memory-failure.c:1132! memory_failure() passed refcount and page lock from tail page to head page, which is not needed because we can pass any subpage to split_huge_page(). Fixes: 61f5d69 ("mm: re-enable THP") Link: http://lkml.kernel.org/r/[email protected] Signed-off-by: Naoya Horiguchi <[email protected]> Cc: <[email protected]> [4.5+] Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent dd111be commit c3901e7

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

mm/memory-failure.c

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1112,10 +1112,10 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
11121112
}
11131113

11141114
if (!PageHuge(p) && PageTransHuge(hpage)) {
1115-
lock_page(hpage);
1116-
if (!PageAnon(hpage) || unlikely(split_huge_page(hpage))) {
1117-
unlock_page(hpage);
1118-
if (!PageAnon(hpage))
1115+
lock_page(p);
1116+
if (!PageAnon(p) || unlikely(split_huge_page(p))) {
1117+
unlock_page(p);
1118+
if (!PageAnon(p))
11191119
pr_err("Memory failure: %#lx: non anonymous thp\n",
11201120
pfn);
11211121
else
@@ -1126,9 +1126,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
11261126
put_hwpoison_page(p);
11271127
return -EBUSY;
11281128
}
1129-
unlock_page(hpage);
1130-
get_hwpoison_page(p);
1131-
put_hwpoison_page(hpage);
1129+
unlock_page(p);
11321130
VM_BUG_ON_PAGE(!page_count(p), p);
11331131
hpage = compound_head(p);
11341132
}

0 commit comments

Comments
 (0)