Re: [PATCH mm-unstable 8/8] mm/memory-failure: convert unpoison_memory() to folios

From: Matthew Wilcox
Date: Sat Jul 15 2023 - 00:07:10 EST


On Thu, Jan 12, 2023 at 02:46:08PM -0600, Sidhartha Kumar wrote:
> @@ -2348,7 +2347,6 @@ int unpoison_memory(unsigned long pfn)
> return -ENXIO;
>
> p = pfn_to_page(pfn);
> - page = compound_head(p);
> folio = page_folio(p);
>
> mutex_lock(&mf_mutex);
> @@ -2360,31 +2358,31 @@ int unpoison_memory(unsigned long pfn)
> goto unlock_mutex;
> }
>
> - if (!PageHWPoison(p)) {
> + if (!folio_test_hwpoison(folio)) {

This is wrong. You need to test the individual page for PageHWPoison()
instead of testing the folio. I understand that this will work for
hugetlbfs pages, but for THP, it's the individual pages that get poisoned,
and folio_test_hwpoison() on a THP actually only tests the head page.

Ideas for preventing this mistake in the future gratefully received.