Re: [PATCH v6 2/2] kexec: keep the next kernel off hardware-poisoned pages

From: Miaohe Lin

Date: Tue Aug 18 2026 - 08:16:19 EST


On 2026/8/12 19:31, Breno Leitao wrote:
> Memory failures (such as unrecoverable ECCs errors) are getting more and
> more common. The kernel knows how to handle it while running, marking it
> as poisoned (and SIGBUS user tasks).
>
> Poisoned memory is removed from the buddy allocator, but, not from
> other places. A current problem is that kexec will load new kernel
> on top of a bad/poisoned memory, which is undesirable.
>
> If the next kernel's image, initrd or purgatory lands on a poisoned
> frame, the relocation copy puts it on memory that is known bad. The
> error happens on the first read from a bad page, and that is what we
> want to avoid.
>
> Skip hardware-poisoned frames that were detected by the memory failure
> subsystem earlier when placing kexec segments.
>
> To do so, add a helper that reports the first or the last poisoned page
> in a range: memory is walked top-down by locate_mem_hole_top_down() and
> bottom-up by locate_mem_hole_bottom_up(), so each direction needs a
> different answer to stay clear of the poison.
>
> kexec_load() gets its destinations from userspace and cannot move them,
> so there sanity_check_segment_list() just rejects a segment that happens
> to have a poisoned page.
>
> is_page_hwpoison() also covers hugetlb, so a poisoned hugetlb folio is
> skipped as a whole.
>
> Suggested-by: Kiryl Shutsemau <kas@xxxxxxxxxx>
> Signed-off-by: Breno Leitao <leitao@xxxxxxxxxx>
> Reviewed-by: Kiryl Shutsemau (Meta) <kas@xxxxxxxxxx>
> Reviewed-by: Pratyush Yadav <pratyush@xxxxxxxxxx>
> Reviewed-by: Bradley Morgan <include@xxxxxxxxx>

Reviewed-by: Miaohe Lin <linmiaohe@xxxxxxxxxx>

Thanks.
.