From: Miaohe Lin <linmiaohe@huawei.com>
To: Breno Leitao <leitao@debian.org>
Cc: <linux-efi@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
<linux-mm@kvack.org>, <linux-cxl@vger.kernel.org>,
<driver-core@lists.linux.dev>,
<linux-arm-kernel@lists.infradead.org>, <rmikey@meta.com>,
<riel@surriel.com>, <harry@kernel.org>, <kernel-team@meta.com>,
Ard Biesheuvel <ardb@kernel.org>,
Ilias Apalodimas <ilias.apalodimas@linaro.org>,
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>,
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>,
Naoya Horiguchi <nao.horiguchi@gmail.com>,
Oscar Salvador <osalvador@suse.de>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
"Rafael J. Wysocki" <rafael@kernel.org>,
Danilo Krummrich <dakr@kernel.org>,
Catalin Marinas <catalin.marinas@arm.com>,
Will Deacon <will@kernel.org>,
Mark Rutland <mark.rutland@arm.com>, <kas@kernel.org>,
<kexec@lists.infradead.org>,
Brendan Jackman <brendan.jackman@linux.dev>,
Johannes Weiner <hannes@cmpxchg.org>, Zi Yan <ziy@nvidia.com>,
<shakeel.butt@linux.dev>
Subject: Re: [PATCH v6 5/7] drivers/base/memory: count the poison a block already holds when creating it
Date: Wed, 18 Nov 2026 15:00:39 +0800 [thread overview]
Message-ID: <f0f5e60a-819e-68e7-09b2-4080f4716e9e@huawei.com> (raw)
In-Reply-To: <20261016-hwpoison-kho-v6-5-f304255147da@debian.org>
On 2026/10/16 20:15, Breno Leitao wrote:
> A frame flagged poisoned before memory_dev_init() runs cannot be counted
> on its memory block. memblk_nr_poison_inc() divides by sections_per_block,
> which memory_dev_init() sets, and the block does not exist yet. The block
> is then created reading zero, however many of its frames are poisoned.
>
> Until now nothing could poison a frame that early. It becomes possible
> once a kernel flags the frames it inherits from the one that kexeced into
> it, as it initializes its memmap.
>
> memory_block_online() refuses a block that holds a poisoned frame, and a
> counter stuck at zero lets one through.
>
> Count what a block holds when it is created at boot. The walk sits behind
> num_poisoned_pages, so a machine with no poison does not pay for it.
>
> Signed-off-by: Breno Leitao <leitao@debian.org>
> ---
> drivers/base/memory.c | 30 ++++++++++++++++++++++++++++++
> 1 file changed, 30 insertions(+)
>
> diff --git a/drivers/base/memory.c b/drivers/base/memory.c
> index 5eead3346f1e32..77481f375c2206 100644
> --- a/drivers/base/memory.c
> +++ b/drivers/base/memory.c
> @@ -220,11 +220,16 @@ int memory_notify(enum memory_block_state state, void *v)
>
> #if defined(CONFIG_MEMORY_FAILURE) && defined(CONFIG_MEMORY_HOTPLUG)
> static unsigned long memblk_nr_poison(struct memory_block *mem);
> +static void memblk_nr_poison_init(struct memory_block *mem);
> #else
> static inline unsigned long memblk_nr_poison(struct memory_block *mem)
> {
> return 0;
> }
> +
> +static inline void memblk_nr_poison_init(struct memory_block *mem)
> +{
> +}
If defined(CONFIG_MEMORY_FAILURE) but CONFIG_MEMORY_HOTPLUG is not defined, memory block
created at boot time will lose nr_hwpoison count. Is this expected?
> #endif
>
> /*
> @@ -807,6 +812,7 @@ static int add_memory_block(unsigned long block_id, int nid, unsigned long state
> mem->state = state;
> mem->nid = nid;
> INIT_LIST_HEAD(&mem->group_next);
> + memblk_nr_poison_init(mem);
>
> #ifndef CONFIG_NUMA
> if (state == MEM_ONLINE)
> @@ -1251,4 +1257,28 @@ static unsigned long memblk_nr_poison(struct memory_block *mem)
> {
> return atomic_long_read(&mem->nr_hwpoison);
> }
> +
> +/*
> + * Frames poisoned before the block existed were never counted on it. Count
> + * them now, or the first unpoison takes the counter below zero.
> + */
> +static void memblk_nr_poison_init(struct memory_block *mem)
> +{
> + unsigned long pfn = section_nr_to_pfn(mem->start_section_nr);
> + unsigned long end = pfn + PAGES_PER_SECTION * sections_per_block;
> + unsigned long nr = 0;
> +
> + /* A hotplugged block is created before its pages are online. */
> + if (mem->state != MEM_ONLINE || !atomic_long_read(&num_poisoned_pages))
> + return;
> +
> + for (; pfn < end; pfn++) {
> + struct page *page = pfn_to_online_page(pfn);
Above comment says the pages of this memory block are not online. So pfn_to_online_page
here will return the wanted page?
> +
> + if (page && PageHWPoison(page))
> + nr++;
Now that the table is a bitmap with one bit per 2MB of physical memory, would it be more
appropriate to process it at 2 MB granularity?
Thanks.
.
next prev parent reply other threads:[~2026-11-18 7:00 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-16 12:15 [PATCH v6 0/7] mm/memory-failure: keep hardware-poisoned pages out of the next kexec Breno Leitao
2026-10-16 12:15 ` [PATCH v6 1/7] mm/memory-failure: efi: add the LINUX_EFI_POISONED_MEMORY configuration table Breno Leitao
2026-10-16 12:15 ` [PATCH v6 2/7] mm/memory-failure: libstub: install the poisoned-memory EFI table Breno Leitao
2026-10-16 12:15 ` [PATCH v6 3/7] mm/memory-failure: add hwpoison_boot_page() to flag an inherited frame Breno Leitao
2026-11-03 9:48 ` Mike Rapoport
2026-11-03 10:06 ` Breno Leitao
2026-11-03 18:59 ` Mike Rapoport
2026-11-03 19:49 ` Breno Leitao
2026-11-04 10:40 ` Mike Rapoport
2026-11-04 11:28 ` Breno Leitao
2026-11-17 9:21 ` Miaohe Lin
2026-10-16 12:15 ` [PATCH v6 4/7] mm/memblock: add a reserved-region flag for poisoned frames Breno Leitao
2026-10-22 16:33 ` Mike Rapoport
2026-10-28 8:39 ` David Hildenbrand (Arm)
2026-10-28 13:49 ` Breno Leitao
2026-10-28 17:13 ` Mike Rapoport
2026-10-16 12:15 ` [PATCH v6 5/7] drivers/base/memory: count the poison a block already holds when creating it Breno Leitao
2026-11-18 7:00 ` Miaohe Lin [this message]
2026-10-16 12:15 ` [PATCH v6 6/7] mm/memory-failure: efi: reserve the inherited poisoned-memory units Breno Leitao
2026-10-16 12:15 ` [PATCH v6 7/7] mm/memory-failure: efi: record hardware-poisoned frames into the poisoned-memory table Breno Leitao
2026-11-18 7:24 ` Miaohe Lin
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=f0f5e60a-819e-68e7-09b2-4080f4716e9e@huawei.com \
--to=linmiaohe@huawei.com \
--cc=akpm@linux-foundation.org \
--cc=ardb@kernel.org \
--cc=bp@alien8.de \
--cc=brendan.jackman@linux.dev \
--cc=catalin.marinas@arm.com \
--cc=dakr@kernel.org \
--cc=dave.hansen@linux.intel.com \
--cc=david@kernel.org \
--cc=driver-core@lists.linux.dev \
--cc=gregkh@linuxfoundation.org \
--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=linux-arm-kernel@lists.infradead.org \
--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=mark.rutland@arm.com \
--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=will@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®