Skip to content

Commit 9113eaf

Browse files
pizhenweiakpm00
authored andcommitted
mm/memory-failure.c: add hwpoison_filter for soft offline
hwpoison_filter is missing in the soft offline path, this leads an issue: after enabling the corrupt filter, the user process still has a chance to inject hwpoison fault by madvise(addr, len, MADV_SOFT_OFFLINE) at PFN which is expected to reject. Also do a minor change in comment of memory_failure(). Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: zhenwei pi <[email protected]> Acked-by: Naoya Horiguchi <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent c8bd84f commit 9113eaf

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

mm/memory-failure.c

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1751,7 +1751,7 @@ static DEFINE_MUTEX(mf_mutex);
17511751
* enabled and no spinlocks hold.
17521752
*
17531753
* Return: 0 for successfully handled the memory error,
1754-
* -EOPNOTSUPP for memory_filter() filtered the error event,
1754+
* -EOPNOTSUPP for hwpoison_filter() filtered the error event,
17551755
* < 0(except -EOPNOTSUPP) on failure.
17561756
*/
17571757
int memory_failure(unsigned long pfn, int flags)
@@ -2308,7 +2308,9 @@ static void put_ref_page(struct page *page)
23082308
* @pfn: pfn to soft-offline
23092309
* @flags: flags. Same as memory_failure().
23102310
*
2311-
* Returns 0 on success, otherwise negated errno.
2311+
* Returns 0 on success
2312+
* -EOPNOTSUPP for hwpoison_filter() filtered the error event
2313+
* < 0 otherwise negated errno.
23122314
*
23132315
* Soft offline a page, by migration or invalidation,
23142316
* without killing anything. This is for the case when
@@ -2359,6 +2361,16 @@ int soft_offline_page(unsigned long pfn, int flags)
23592361
ret = get_hwpoison_page(page, flags | MF_SOFT_OFFLINE);
23602362
put_online_mems();
23612363

2364+
if (hwpoison_filter(page)) {
2365+
if (ret > 0)
2366+
put_page(page);
2367+
else
2368+
put_ref_page(ref_page);
2369+
2370+
mutex_unlock(&mf_mutex);
2371+
return -EOPNOTSUPP;
2372+
}
2373+
23622374
if (ret > 0) {
23632375
ret = soft_offline_in_use_page(page);
23642376
} else if (ret == 0) {

0 commit comments

Comments
 (0)