From: "David Hildenbrand (Arm)" <david@kernel.org>
To: Breno Leitao <leitao@debian.org>
Cc: Ard Biesheuvel <ardb@kernel.org>,
Ilias Apalodimas <ilias.apalodimas@linaro.org>,
Miaohe Lin <linmiaohe@huawei.com>,
Naoya Horiguchi <nao.horiguchi@gmail.com>,
Andrew Morton <akpm@linux-foundation.org>,
kas@kernel.org, kexec@lists.infradead.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>, Thomas Gleixner <tglx@kernel.org>,
Ingo Molnar <mingo@redhat.com>, Borislav Petkov <bp@alien8.de>,
Dave Hansen <dave.hansen@linux.intel.com>,
x86@kernel.org, "H. Peter Anvin" <hpa@zytor.com>,
Brendan Jackman <brendan.jackman@linux.dev>,
Johannes Weiner <hannes@cmpxchg.org>, Zi Yan <ziy@nvidia.com>,
Oscar Salvador <osalvador@suse.de>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
"Rafael J. Wysocki" <rafael@kernel.org>,
Danilo Krummrich <dakr@kernel.org>,
hannes@cmpxchg.or, shakeel.butt@linux.dev,
linux-efi@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-mm@kvack.org, rmikey@meta.com, riel@surriel.com,
harry@kernel.org, linux-cxl@vger.kernel.org,
driver-core@lists.linux.dev, kernel-team@meta.com
Subject: Re: [PATCH v5 7/9] drivers/base/memory: count inherited poisoned frames into the block
Date: Thu, 24 Sep 2026 13:22:00 +0200 [thread overview]
Message-ID: <cf2fe0bb-a79a-420e-8b65-3c8dfa5fadbb@kernel.org> (raw)
In-Reply-To: <arJqVWN-prvI_0NP@gmail.com>
On 9/22/26 14:34, Breno Leitao wrote:
> Hello David,
>
> On Tue, Sep 22, 2026 at 01:33:51PM +0200, David Hildenbrand (Arm) wrote:
>> On 9/21/26 16:31, Breno Leitao wrote:
>>>
>>> The EFI table is only written when there is a memory failure. That is
>>> the only thing that writes to it:
>>>
>>> action_result() -> efi_hwpoison_record_pfn() -> set_bit()
>>>
>>> You can see it on patch "mm/memory-failure: efi: record
>>> hardware-poisoned frames into the poisoned-memory table"
>>>
>>> Then, when the kernel kexecs into a second kernel, the EFI config table
>>> is queried and the pages are poisoned from it at boot, as they are
>>> getting into the buddy allocator, in __free_pages_core().
>>
>> I am not sure that is really the right place. That means we only poison free
>> memory.
>
> Right, and that is a real gap. A frame only reaches __free_pages_core()
> if it is handed to the buddy allocator, so anything this kernel already
> took from memblock -- the memmap itself, early page tables, percpu --
> can be sitting on a recorded frame with nobody noticing.
>
>> Shouldn't we poison as soon as we initialize the memmap, and check
>> whether any memblock allocations ended up on that poisoned memory and bail out?
>
Thanks for the history on this.
>
> That is close to what I had until v2, where the bitmap was walked at EFI
> parse time and every set unit was memblock_reserve()d:
>
> for (off = 0; off < bitmap_size; off += PAGE_SIZE) {
> ...
> for_each_set_bit(bit, map, nbits) {
> u64 unit = off * BITS_PER_BYTE + bit;
>
> memblock_reserve(phys_base + unit * unit_size, unit_size);
> nr_units++;
> }
> ...
> }
Yes, that what I have in mind.
>
> Set the full v2 patch at
> https://lore.kernel.org/all/20260821-hwpoison-kho-v2-6-5743791e48e6@debian.org/
>
> Kiryl raised some concerns, such as x86 does not keep memblock past
> boot,
The memmap contains that information. If it's a scalability problem with
thousands of hwpoisoned 2M ranges, don't try to keep kernels running on utterly
broken systems, seriously.
> and kexec picks placement from iomem_resource via
> walk_system_ram_res(), which memblock_reserve() does not touch.
Where we could scan the memmap. If we find scalability problems with that they
should be addressed there.
> So the
> frames stay out of buddy, but the next image can still be placed on
> them, and since nothing sets PG_hwpoison none of the existing hwpoison
> users see them either.
Memblock knows which ranges were poisoned. It shouldn't hand these out, neither
to memblock users or the buddy.
And is it knows that these ranges are poisoned, it should be marking them as
hwpoisoned when we initialize the memmap.
Kiryl probably remembered the unaccepted-memory hammer and thought of hwpoison
of being just another nail. It's not. hwpoison is a proper kernel infrastructure.
>
> Most of the discussion happened here:
> https://lore.kernel.org/all/aog_uH5fTsJzXjjx@thinkstation/
>
> v3 then poisoned the frames from mm_core_init(), right after
> memblock_free_all(), taking them back off buddy.
They should have never been exposed to the buddy.
> That breaks with
> CONFIG_DEFERRED_STRUCT_PAGE_INIT, where the struct pages above
> first_deferred_pfn do not exist yet at that point, and Kiryl's other
> point was that the shape was wrong regardless: flag the frame on its
> first add to buddy, not after buddy is up.
The flags should be set earlier and pages never even handed to the buddy.
Handing out poisoned pages from one allocator to hide them from another
allocator is stupid.
>
> See the discussion at:
> https://lore.kernel.org/all/apGbDOnPm5VXP5ez@thinkstation/
>
> Which is how it ended up in __free_pages_core().
>>>> From that point on, the memmap should be our reliable source of information.
>
> Sure, is this approach better?
>
> - the bitmap is read as the struct pages are initialised, and the only
> thing it does there is SetPageHWPoison();
>
> - __free_pages_core() keeps the hook but tests PageHWPoison() instead
> of the table, so a recorded frame is still held back before it can
> enter buddy;
>
> - nothing else queries the table.
Why should we give pages we know are poisoned to the buddy? And why should we
let memblock hand out poisoned ranges?
I'm sorry, it's all hacky.
I see why we want a bitmap from kernel A to kernel B, but once the kernel is up
we have established infrastrcture to identify poisoned pages.
Just look at the mess in the patch here I replied to. Pairing bitmap scans with
memmap scans ... hacky.
>
> One caveat on "exactly once": if that means one pass at one point in
> boot, it is what v3[1] did -- hwpoison_init_boot() from mm_core_init(),
> right after memblock_free_all() -- and it does not work. With
> CONFIG_DEFERRED_STRUCT_PAGE_INIT the struct pages above
> first_deferred_pfn are not there yet at that point.
>
> Link: https://lore.kernel.org/all/20260826-hwpoison-kho-v3-5-6f79c4b605bc@debian.org/
>
> So I _think_ we want to do it once per frame, as that frame's struct
> page comes up. __init_single_page() is the single function they all pass
> through. Is __init_single_page() the right place to query the bitmap and
> mark is as poisoned?
That's what I originally had in mind, but I am not sure if it's the right time
to query it.
Assume we tell memblock about the poisoned ranges early and it would not hand
them out.
memblock_free_pages() would never get called in the first place.
All pages would look like they are simply allocated by memblock.
We'd have to traverse the poisoned ranges in memblock once to set the hwpoisoned
bits.
>
>> For this code here, just remember globally whether we hwpoisoned any page. If
>> so, just walk the memmap. If not (the 99.9999% of all systems, no need to scan
>> anything).
>
> Yes, and the counter already exists: num_poisoned_pages and we can query
> it. I am also planning to add something similar in the EFI table, like
> an ->empty field, which will be cleared when a bit is set, avoiding
> doing bitmap walk on the happy path (not a single poisoned page).
>
> Anyway, range_hwpoison() short-circuits on it today,
>
> if (!size || !atomic_long_read(&num_poisoned_pages))
> return poison;
>
> so memblk_nr_poison_init() can gate on the same thing and walk the
> memmap, with no EFI call left in drivers/base/memory.c at all. That
> disposes of the misleading name there too, which was where this
> started.
>
> Now, the half I am less sure about is checking whether a memblock
> allocation landed on a recorded frame. Poisoning at memmap init cannot
> prevent that -- the memmap is itself a memblock allocation, so the
> struct pages do not exist while the early allocations are being made --
> it can only detect it afterwards, as a pass over memblock.reserved
> before memblock_free_all().
>
> The alternative is to bring v2's memblock_reserve() back purely to keep
> the early allocator off those frames, and still poison at memmap init
> so the flag is there for everyone else. That gets both properties, at
> the cost of frames that are Reserved and HWPoison and never in buddy,
> which I have not thought through for unpoison.
Thanks for the history on this. I tried to summarize my thoughts above. I might
be wrong.
--
Cheers,
David
next prev parent reply other threads:[~2026-09-24 11:22 UTC|newest]
Thread overview: 48+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-15 12:53 [PATCH v5 0/9] mm/memory-failure: keep hardware-poisoned pages out of the next kexec Breno Leitao
2026-09-15 12:53 ` [PATCH v5 1/9] mm/page_alloc: factor out the accept-and-free tail of __free_pages_core() Breno Leitao
2026-09-15 12:57 ` sashiko-bot
2026-09-15 12:53 ` [PATCH v5 2/9] mm/memory-failure: efi: add the LINUX_EFI_POISONED_MEMORY configuration table Breno Leitao
2026-09-15 13:05 ` sashiko-bot
2026-09-15 12:53 ` [PATCH v5 3/9] mm/memory-failure: libstub: install the poisoned-memory EFI table Breno Leitao
2026-09-15 13:15 ` sashiko-bot
2026-09-15 14:00 ` Breno Leitao
2026-09-16 15:39 ` Usama Arif
2026-09-17 10:53 ` Breno Leitao
2026-09-15 12:53 ` [PATCH v5 4/9] mm/memory-failure: efi: adopt the inherited poisoned-memory table Breno Leitao
2026-09-15 13:24 ` sashiko-bot
2026-09-15 12:53 ` [PATCH v5 5/9] mm/memory-failure: efi: record hardware-poisoned frames into the " Breno Leitao
2026-09-15 13:36 ` sashiko-bot
2026-09-15 14:33 ` Breno Leitao
2026-09-15 12:53 ` [PATCH v5 6/9] mm/memory-failure: efi: answer whether a range is poisoned Breno Leitao
2026-09-15 13:45 ` sashiko-bot
2026-09-16 6:44 ` David Hildenbrand (Arm)
2026-09-18 15:27 ` Breno Leitao
2026-09-18 15:53 ` Harry Yoo
2026-09-18 20:02 ` David Hildenbrand (Arm)
2026-09-15 12:53 ` [PATCH v5 7/9] drivers/base/memory: count inherited poisoned frames into the block Breno Leitao
2026-09-15 13:59 ` sashiko-bot
2026-09-16 6:48 ` David Hildenbrand (Arm)
2026-09-16 9:35 ` Breno Leitao
2026-09-16 14:51 ` David Hildenbrand (Arm)
2026-09-17 13:01 ` Breno Leitao
2026-09-18 12:18 ` David Hildenbrand (Arm)
2026-09-18 15:22 ` Breno Leitao
2026-09-18 20:16 ` David Hildenbrand (Arm)
2026-09-21 14:31 ` Breno Leitao
2026-09-22 11:33 ` David Hildenbrand (Arm)
2026-09-22 12:34 ` Breno Leitao
2026-09-24 11:22 ` David Hildenbrand (Arm) [this message]
2026-09-22 12:51 ` Kiryl Shutsemau
2026-09-22 13:45 ` Harry Yoo
2026-09-22 13:53 ` David Hildenbrand (Arm)
2026-09-15 12:53 ` [PATCH v5 8/9] mm/memory-failure: add hwpoison_boot_page() to flag an inherited frame Breno Leitao
2026-09-15 14:11 ` sashiko-bot
2026-09-19 10:28 ` Shaikh Kamaluddin
2026-09-21 13:41 ` Breno Leitao
2026-09-15 12:53 ` [PATCH v5 9/9] mm/memory-failure: keep inherited poisoned frames out of the buddy allocator Breno Leitao
2026-09-15 14:25 ` sashiko-bot
2026-09-16 8:32 ` Vlastimil Babka (SUSE)
2026-09-22 6:27 ` [PATCH v5 0/9] mm/memory-failure: keep hardware-poisoned pages out of the next kexec Miaohe Lin
2026-09-22 9:14 ` Breno Leitao
2026-09-22 9:29 ` Miaohe Lin
2026-09-22 10:39 ` 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=cf2fe0bb-a79a-420e-8b65-3c8dfa5fadbb@kernel.org \
--to=david@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=ardb@kernel.org \
--cc=bp@alien8.de \
--cc=brendan.jackman@linux.dev \
--cc=dakr@kernel.org \
--cc=dave.hansen@linux.intel.com \
--cc=driver-core@lists.linux.dev \
--cc=gregkh@linuxfoundation.org \
--cc=hannes@cmpxchg.or \
--cc=hannes@cmpxchg.org \
--cc=harry@kernel.org \
--cc=hpa@zytor.com \
--cc=ilias.apalodimas@linaro.org \
--cc=kas@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-cxl@vger.kernel.org \
--cc=linux-efi@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=ljs@kernel.org \
--cc=mhocko@suse.com \
--cc=mingo@redhat.com \
--cc=nao.horiguchi@gmail.com \
--cc=osalvador@suse.de \
--cc=rafael@kernel.org \
--cc=riel@surriel.com \
--cc=rmikey@meta.com \
--cc=rppt@kernel.org \
--cc=shakeel.butt@linux.dev \
--cc=surenb@google.com \
--cc=tglx@kernel.org \
--cc=vbabka@kernel.org \
--cc=x86@kernel.org \
--cc=ziy@nvidia.com \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®