Re: [PATCH v5 8/9] mm/memory-failure: add hwpoison_boot_page() to flag an inherited frame
From: Breno Leitao
Date: Mon Sep 21 2026 - 10:13:44 EST
On Sat, Sep 19, 2026 at 03:58:25PM +0530, Shaikh Kamaluddin wrote:
> On Tue, Sep 15, 2026 at 05:53:42AM -0700, Breno Leitao wrote:
> > +
> > + /*
> > + * The per memory block half of num_poisoned_pages_inc() has no block to
> > + * find at boot, and divides by zero looking for one. A hotplugged block
> > + * is already there.
> > + */
> > + if (context == MEMINIT_HOTPLUG)
> > + num_poisoned_pages_inc(pfn);
> > + else
> > + atomic_long_inc(&num_poisoned_pages);
> > +}
>
> Hi Breno,
>
> num_poisoned_pages_inc() currently assumes that the supplied PFN can
> be used for per-memory-block accounting and therefore calls
> memblk_nr_poison_inc() unconditionally. The early-boot path needs
> global-only accounting because the memory-block infrastructure is not
> initialized yet.
>
> Could num_poisoned_pages_inc() treat -1UL as global-only accounting,
> matching num_poisoned_pages_sub()?
>
> Example as below:
>
> void num_poisoned_pages_inc(unsigned long pfn)
> {
> atomic_long_inc(&num_poisoned_pages);
>
> if (pfn != -1UL)
> memblk_nr_poison_inc(pfn);
> }
>
>
> The caller could then use:
>
> num_poisoned_pages_inc(context == MEMINIT_HOTPLUG ? pfn : -1UL);
>
> This would keep updates to `num_poisoned_pages` encapsulated rather than
> manipulating the counter directly here, while also making the increment
> and decrement interfaces consistent.
Good point, and it is a better fit than what I have.
-1UL already means "global only" on the sub side, and it is not just a
convention on paper: remove_memory_block_devices() calls
num_poisoned_pages_sub(-1UL, memblk_nr_poison(mem)) when a block goes
away. Teaching inc() the same thing costs a branch and keeps
num_poisoned_pages behind the two helpers instead of growing a third
place that pokes the atomic directly.
I will fold this into v6:
void num_poisoned_pages_inc(unsigned long pfn)
{
atomic_long_inc(&num_poisoned_pages);
if (pfn != -1UL)
memblk_nr_poison_inc(pfn);
}
Thanks for the review and suggestion,
--breno