From: Kiryl Shutsemau <kas@kernel.org>
To: Breno Leitao <leitao@debian.org>
Cc: Andrew Morton <akpm@linux-foundation.org>,
David Hildenbrand <david@kernel.org>,
Lorenzo Stoakes <ljs@kernel.org>,
"Liam R. Howlett" <liam@infradead.org>,
Vlastimil Babka <vbabka@kernel.org>,
Mike Rapoport <rppt@kernel.org>,
Suren Baghdasaryan <surenb@google.com>,
Michal Hocko <mhocko@suse.com>,
Baoquan He <baoquan.he@linux.dev>,
Pasha Tatashin <pasha.tatashin@soleen.com>,
Pratyush Yadav <pratyush@kernel.org>,
Miaohe Lin <linmiaohe@huawei.com>,
Naoya Horiguchi <nao.horiguchi@gmail.com>,
linux-mm@kvack.org, linux-kernel@vger.kernel.org,
kexec@lists.infradead.org, rmikey@meta.com, riel@surriel.com,
kernel-team@meta.com
Subject: Re: [PATCH v4] kexec: keep the next kernel off hardware-poisoned pages
Date: Mon, 10 Aug 2026 10:49:16 +0100 [thread overview]
Message-ID: <anmb9FHMEMygENiO@thinkstation> (raw)
In-Reply-To: <20260807-kexec_posioned-v4-1-70d57f14625d@debian.org>
On Fri, Aug 07, 2026 at 07:05:09AM -0700, Breno Leitao wrote:
> diff --git a/kernel/kexec_core.c b/kernel/kexec_core.c
> index dc770b9a6d053..e097e980b1439 100644
> --- a/kernel/kexec_core.c
> +++ b/kernel/kexec_core.c
> @@ -212,6 +212,16 @@ int sanity_check_segment_list(struct kimage *image)
> }
> #endif
>
> + /*
> + * Reject destinations that land on hardware-poisoned memory: the
> + * relocation copy would machine-check on the bad frame.
> + */
> + for (i = 0; i < nr_segments; i++) {
> + if (range_first_hwpoison(image->segment[i].mem,
> + image->segment[i].memsz) != PHYS_ADDR_MAX)
> + return -EADDRNOTAVAIL;
Other -EADDRNOTAVAIL usage indicate error on user side. But this is not
a user fault. Maybe -EHWPOISON instead.
> + }
> +
> /*
> * The destination addresses are searched from system RAM rather than
> * being allocated from the buddy allocator, so they are not guaranteed
...
> diff --git a/mm/memory-failure.c b/mm/memory-failure.c
> index a8b03e2920ba8..c485e205fb633 100644
> --- a/mm/memory-failure.c
> +++ b/mm/memory-failure.c
> @@ -96,6 +96,78 @@ void num_poisoned_pages_sub(unsigned long pfn, long i)
> memblk_nr_poison_sub(pfn, i);
> }
>
> +/*
> + * Return the first or the last hardware-poisoned online page in [start,
> + * start + size), or PHYS_ADDR_MAX if the range is clean.
> + */
> +static phys_addr_t range_hwpoison(phys_addr_t start, unsigned long size,
> + bool first)
> +{
> + 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);
> + struct folio *folio;
> +
> + cond_resched();
> +
> + if (!page)
> + continue;
> +
> + folio = page_folio(page);
> + if (folio_test_hugetlb(folio)) {
> + /*
> + * hugetlbfs is a bit special, given the poison
> + * information is at the folio, not at the page
> + */
> + unsigned long folio_end;
> +
> + /*
> + * No hugetlb_lock: the scan is racy either way, a frame
> + * can be poisoned right after it. Just don't let a folio
> + * dissolved under us walk the scan backwards.
> + */
> + folio_end = folio_pfn(folio) + folio_nr_pages(folio) - 1;
> + folio_end = max(folio_end, pfn);
> +
> + if (folio_test_hwpoison(folio)) {
> + if (first)
> + return PFN_PHYS(pfn);
> + poison = PFN_PHYS(min(folio_end, end_pfn));
> + }
> + /* skip all the pfns that belong to hugetlb */
> + pfn = folio_end;
> + continue;
> + }
> +
> + if (!PageHWPoison(page))
> + /* page is good, let's go to the next one */
> + continue;
If you don't care about re-using clean part of poisoned hugetlb folio,
use is_page_hwpoison(page).
This would do:
if (!page || !is_page_hwpoison(page))
continue;
You would spin a bit on the same folio, but shouldn't be a big deal.
> +
> + if (first)
> + return PFN_PHYS(pfn);
> +
> + poison = PFN_PHYS(pfn);
> + }
> +
> + return poison;
> +}
--
Kiryl Shutsemau / Kirill A. Shutemov
next prev parent reply other threads:[~2026-08-10 9:49 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-07 14:05 [PATCH v4] kexec: keep the next kernel off hardware-poisoned pages Breno Leitao
2026-08-10 9:49 ` Kiryl Shutsemau [this message]
2026-08-10 12:19 ` Breno Leitao
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=anmb9FHMEMygENiO@thinkstation \
--to=kas@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=baoquan.he@linux.dev \
--cc=david@kernel.org \
--cc=kernel-team@meta.com \
--cc=kexec@lists.infradead.org \
--cc=leitao@debian.org \
--cc=liam@infradead.org \
--cc=linmiaohe@huawei.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=ljs@kernel.org \
--cc=mhocko@suse.com \
--cc=nao.horiguchi@gmail.com \
--cc=pasha.tatashin@soleen.com \
--cc=pratyush@kernel.org \
--cc=riel@surriel.com \
--cc=rmikey@meta.com \
--cc=rppt@kernel.org \
--cc=surenb@google.com \
--cc=vbabka@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.