Skip to content

Commit 524fca1

Browse files
Naoya Horiguchitorvalds
Naoya Horiguchi
authored andcommitted
HWPOISON: fix misjudgement of page_action() for errors on mlocked pages
memory_failure() can't handle memory errors on mlocked pages correctly, because page_action() judges such errors as ones on "unknown pages" instead of ones on "unevictable LRU page" or "mlocked LRU page". In order to determine page_state page_action() checks page flags at the timing of the judgement, but such page flags are not the same with those just after memory_failure() is called, because memory_failure() does unmapping of the error pages before doing page_action(). This unmapping changes the page state, especially page_remove_rmap() (called from try_to_unmap_one()) clears PG_mlocked, so page_action() can't catch mlocked pages after that. With this patch, we store the page flag of the error page before doing unmap, and (only) if the first check with page flags at the time decided the error page is unknown, we do the second check with the stored page flag. This implementation doesn't change error handling for the page types for which the first check can determine the page state correctly. [akpm@linux-foundation.org: tweak comments] Signed-off-by: Naoya Horiguchi <n-horiguchi@ah.jp.nec.com> Cc: Andi Kleen <andi@firstfloor.org> Cc: Tony Luck <tony.luck@intel.com> Cc: Chen Gong <gong.chen@linux.intel.com> Cc: Wu Fengguang <fengguang.wu@intel.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 6d04399 commit 524fca1

File tree

1 file changed

+22
-5
lines changed

1 file changed

+22
-5
lines changed

mm/memory-failure.c

+22-5
Original file line numberDiff line numberDiff line change
@@ -1021,6 +1021,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
10211021
struct page *hpage;
10221022
int res;
10231023
unsigned int nr_pages;
1024+
unsigned long page_flags;
10241025

10251026
if (!sysctl_memory_failure_recovery)
10261027
panic("Memory failure from trap %d on page %lx", trapno, pfn);
@@ -1128,6 +1129,15 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
11281129
*/
11291130
lock_page(hpage);
11301131

1132+
/*
1133+
* We use page flags to determine what action should be taken, but
1134+
* the flags can be modified by the error containment action. One
1135+
* example is an mlocked page, where PG_mlocked is cleared by
1136+
* page_remove_rmap() in try_to_unmap_one(). So to determine page status
1137+
* correctly, we save a copy of the page flags at this time.
1138+
*/
1139+
page_flags = p->flags;
1140+
11311141
/*
11321142
* unpoison always clear PG_hwpoison inside page lock
11331143
*/
@@ -1186,12 +1196,19 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
11861196
}
11871197

11881198
res = -EBUSY;
1189-
for (ps = error_states;; ps++) {
1190-
if ((p->flags & ps->mask) == ps->res) {
1191-
res = page_action(ps, p, pfn);
1199+
/*
1200+
* The first check uses the current page flags which may not have any
1201+
* relevant information. The second check with the saved page flagss is
1202+
* carried out only if the first check can't determine the page status.
1203+
*/
1204+
for (ps = error_states;; ps++)
1205+
if ((p->flags & ps->mask) == ps->res)
11921206
break;
1193-
}
1194-
}
1207+
if (!ps->mask)
1208+
for (ps = error_states;; ps++)
1209+
if ((page_flags & ps->mask) == ps->res)
1210+
break;
1211+
res = page_action(ps, p, pfn);
11951212
out:
11961213
unlock_page(hpage);
11971214
return res;

0 commit comments

Comments
 (0)