Commit e77cbe2a authored by Matthew Wilcox (Oracle)'s avatar Matthew Wilcox (Oracle) Committed by sanglipeng1
Browse files

mm/memory-failure: check the mapcount of the precise page

stable inclusion
from stable-v5.10.208
commit 70168fdc743b9b27ada2f8b4f3047a43a8220724
category: bugfix
bugzilla: https://gitee.com/openeuler/kernel/issues/I9T22K

Reference: https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?id=70168fdc743b9b27ada2f8b4f3047a43a8220724

--------------------------------

[ Upstream commit c79c5a0a00a9457718056b588f312baadf44e471 ]

A process may map only some of the pages in a folio, and might be missed
if it maps the poisoned page but not the head page.  Or it might be
unnecessarily hit if it maps the head page, but not the poisoned page.

Link: https://lkml.kernel.org/r/20231218135837.3310403-3-willy@infradead.org


Fixes: 7af446a8 ("HWPOISON, hugetlb: enable error handling path for hugepage")
Signed-off-by: default avatarMatthew Wilcox (Oracle) <willy@infradead.org>
Cc: Dan Williams <dan.j.williams@intel.com>
Cc: Naoya Horiguchi <n-horiguchi@ah.jp.nec.com>
Cc: <stable@vger.kernel.org>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
Signed-off-by: default avatarsanglipeng1 <sanglipeng1@jd.com>
parent 56f49bc1
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -1197,7 +1197,7 @@ static bool hwpoison_user_mappings(struct page *p, unsigned long pfn,
	 * This check implies we don't kill processes if their pages
	 * are in the swap cache early. Those are always late kills.
	 */
	if (!page_mapped(hpage))
	if (!page_mapped(p))
		return true;

	if (PageKsm(p)) {
@@ -1262,12 +1262,12 @@ static bool hwpoison_user_mappings(struct page *p, unsigned long pfn,
				unmap_success = false;
			}
		} else {
			unmap_success = try_to_unmap(hpage, ttu);
			unmap_success = try_to_unmap(p, ttu);
		}
	}
	if (!unmap_success)
		pr_err("Memory failure: %#lx: failed to unmap page (mapcount=%d)\n",
		       pfn, page_mapcount(hpage));
		       pfn, page_mapcount(p));

	/*
	 * try_to_unmap() might put mlocked page in lru cache, so call