Skip to content

Commit 3149c79

Browse files
rikvanrieltorvalds
authored andcommitted
mm,hwpoison: unmap poisoned page before invalidation
In some cases it appears the invalidation of a hwpoisoned page fails because the page is still mapped in another process. This can cause a program to be continuously restarted and die when it page faults on the page that was not invalidated. Avoid that problem by unmapping the hwpoisoned page when we find it. Another issue is that sometimes we end up oopsing in finish_fault, if the code tries to do something with the now-NULL vmf->page. I did not hit this error when submitting the previous patch because there are several opportunities for alloc_set_pte to bail out before accessing vmf->page, and that apparently happened on those systems, and most of the time on other systems, too. However, across several million systems that error does occur a handful of times a day. It can be avoided by returning VM_FAULT_NOPAGE which will cause do_read_fault to return before calling finish_fault. Link: https://lkml.kernel.org/r/20220325161428.5068d97e@imladris.surriel.com Fixes: e53ac73 ("mm: invalidate hwpoison page cache page in fault path") Signed-off-by: Rik van Riel <riel@surriel.com> Reviewed-by: Miaohe Lin <linmiaohe@huawei.com> Tested-by: Naoya Horiguchi <naoya.horiguchi@nec.com> Reviewed-by: Oscar Salvador <osalvador@suse.de> Cc: Mel Gorman <mgorman@suse.de> Cc: Johannes Weiner <hannes@cmpxchg.org> Cc: <stable@vger.kernel.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 4f1f969 commit 3149c79

1 file changed

Lines changed: 8 additions & 4 deletions

File tree

mm/memory.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3918,14 +3918,18 @@ static vm_fault_t __do_fault(struct vm_fault *vmf)
39183918
return ret;
39193919

39203920
if (unlikely(PageHWPoison(vmf->page))) {
3921+
struct page *page = vmf->page;
39213922
vm_fault_t poisonret = VM_FAULT_HWPOISON;
39223923
if (ret & VM_FAULT_LOCKED) {
3924+
if (page_mapped(page))
3925+
unmap_mapping_pages(page_mapping(page),
3926+
page->index, 1, false);
39233927
/* Retry if a clean page was removed from the cache. */
3924-
if (invalidate_inode_page(vmf->page))
3925-
poisonret = 0;
3926-
unlock_page(vmf->page);
3928+
if (invalidate_inode_page(page))
3929+
poisonret = VM_FAULT_NOPAGE;
3930+
unlock_page(page);
39273931
}
3928-
put_page(vmf->page);
3932+
put_page(page);
39293933
vmf->page = NULL;
39303934
return poisonret;
39313935
}

0 commit comments

Comments
 (0)