[PATCH v3] kexec: keep the next kernel off hardware-poisoned pages
Kiryl Shutsemau
kas at kernel.org
Tue Aug 4 07:36:47 PDT 2026
On Mon, Aug 03, 2026 at 05:41:10AM -0700, Breno Leitao wrote:
> @@ -504,6 +505,15 @@ static int locate_mem_hole_top_down(unsigned long start, unsigned long end,
> continue;
> }
>
> + poison = range_last_hwpoison(temp_start, kbuf->memsz);
> + if (poison != PHYS_ADDR_MAX) {
> + /* we hit a poisoned page */
> + if (poison < kbuf->memsz)
> + return 0;
> + temp_start = poison - kbuf->memsz;
> + continue;
> + }
> +
Hm. Don't we want range_first_hwpoison() for top-down walk? Otherwise
the end of range would land on poison.
> /* We found a suitable memory range */
> break;
> } while (1);
...
> diff --git a/mm/memory-failure.c b/mm/memory-failure.c
> index a8b03e2920ba8..ef0e989c25d93 100644
> --- a/mm/memory-failure.c
> +++ b/mm/memory-failure.c
> @@ -96,6 +96,31 @@ void num_poisoned_pages_sub(unsigned long pfn, long i)
> memblk_nr_poison_sub(pfn, i);
> }
>
> +/*
> + * Return the address of the last hardware-poisoned online page in
> + * [start, start + size), or PHYS_ADDR_MAX if the range is clean.
> + */
> +phys_addr_t range_last_hwpoison(phys_addr_t start, unsigned long size)
> +{
> + phys_addr_t poison = PHYS_ADDR_MAX;
> + unsigned long pfn, end_pfn;
> +
> + if (!size || !atomic_long_read(&num_poisoned_pages))
> + return poison;
> +
> + end_pfn = PHYS_PFN(start + size - 1);
> + for (pfn = PHYS_PFN(start); pfn <= end_pfn; pfn++) {
> + struct page *page = pfn_to_online_page(pfn);
> +
> + if (page && PageHWPoison(page))
> + poison = PFN_PHYS(pfn);
Oh... I think it will not work for hugetlb pages. It will give
false-negative.
We cannot just set the bit hugetlb pages as we don't always have memory
for tail page -- look at HugeTLB Vmemmap Optimization (HVO). Hugetlb
uses a trick to encode poison page. See code that uses _hugetlb_hwpoison
in struct folio.
I think we need special-case hugetlb here. (One more reminder why I hate
HugeTLB).
> +
> + cond_resched();
> + }
> +
> + return poison;
> +}
> +
> /**
> * MF_ATTR_RO - Create sysfs entry for each memory failure statistics.
> * @_name: name of the file in the per NUMA sysfs directory.
>
--
Kiryl Shutsemau / Kirill A. Shutemov
More information about the kexec
mailing list