* [PATCH] mm/page_owner: fix double decrement of stack count on unpoison
@ 2026-11-18 21:28 Nilay Vaish
2026-11-19 11:53 ` Jose A. Perez de Azpillaga
2026-11-19 13:23 ` Oscar Salvador (SUSE)
0 siblings, 2 replies; 3+ messages in thread
From: Nilay Vaish @ 2026-11-18 21:28 UTC (permalink / raw)
To: Andrew Morton, Vlastimil Babka, Oscar Salvador
Cc: Johannes Weiner, Suren Baghdasaryan, Michal Hocko,
Brendan Jackman, Zi Yan, Marco Elver, Andrey Konovalov,
Miaohe Lin, Naoya Horiguchi, linux-mm, linux-kernel, Nilay Vaish,
stable
page_owner counts, for each allocation stack, how many pages allocated
from that stack are still in use. The count is incremented when a page
is allocated and decremented in __reset_page_owner() when it is freed.
A page that is hwpoisoned while in use and later unpoisoned passes
through free_pages_prepare() twice:
1. On poisoning, the last reference is dropped. free_pages_prepare()
calls reset_page_owner() but, because the page is PageHWPoison(),
keeps it off the free lists.
2. On unpoisoning, unpoison_memory() drops the poison reference and
free_pages_prepare() calls reset_page_owner() again, this time
really freeing the page.
__reset_page_owner() decrements the stack count both times, although
the page was allocated only once. The first call clears
PAGE_EXT_OWNER_ALLOCATED, but the second call never checks it.
If this drives the count to zero while the stack is still in use,
stackdepot treats the record as freed and warns on every later
allocation or free that uses the same stack:
dec_stack_record_count: refcount went to 0 for 92274844 handle
WARNING: lib/stackdepot.c:517 at depot_fetch_stack+0x5c/0x70
Call Trace:
__set_page_owner+0x110/0x290
get_page_from_freelist+0x1225/0x1440
__alloc_frozen_pages_noprof+0x1fc/0x1b00
__folio_alloc_noprof+0x12/0xa0
alloc_migration_target+0x81/0x1e0
migrate_pages_batch+0x1f2/0x14c0
migrate_pages+0x9c3/0xca0
soft_offline_page+0x189/0x570
A single soft offline followed by an unpoison is enough to trigger it,
because the migration-target stack that the offlined page is accounted
to usually has very few pages.
Fix it by decrementing the stack count only if PAGE_EXT_OWNER_ALLOCATED
was still set, i.e. only the first time the page is freed.
To reproduce, boot with page_owner=on and CONFIG_HWPOISON_INJECT, soft
offline anonymous pages with madvise(MADV_SOFT_OFFLINE), and unpoison
each old PFN through debugfs hwpoison/unpoison-pfn. Without this patch
the first cycle prints the message above and 2200 cycles produce 6597
warnings. With it, the same run is clean and all stack counts return
to their initial values.
Fixes: 217b2119b9e2 ("mm,page_owner: implement the tracking of the stacks count")
Cc: stable@vger.kernel.org
Signed-off-by: Nilay Vaish <nilayvaish@google.com>
---
mm/page_owner.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/mm/page_owner.c b/mm/page_owner.c
index 02bb304b53cf..0793a460d615 100644
--- a/mm/page_owner.c
+++ b/mm/page_owner.c
@@ -320,11 +320,13 @@ void __reset_page_owner(struct page *page, unsigned short order)
depot_stack_handle_t alloc_handle;
struct page_owner *page_owner;
u64 free_ts_nsec = local_clock();
+ bool allocated;
page_ext = page_ext_get(page);
if (unlikely(!page_ext))
return;
+ allocated = test_bit(PAGE_EXT_OWNER_ALLOCATED, &page_ext->flags);
page_owner = get_page_owner(page_ext);
alloc_handle = page_owner->handle;
page_ext_put(page_ext);
@@ -339,7 +341,7 @@ void __reset_page_owner(struct page *page, unsigned short order)
__update_page_owner_free_handle(page, handle, order, current->pid,
current->tgid, free_ts_nsec);
- if (alloc_handle != early_handle)
+ if (allocated && alloc_handle != early_handle) {
/*
* early_handle is being set as a handle for all those
* early allocated pages. See init_pages_in_zone().
@@ -348,6 +350,7 @@ void __reset_page_owner(struct page *page, unsigned short order)
* their refcount either.
*/
dec_stack_record_count(alloc_handle, 1 << order);
+ }
}
noinline void __set_page_owner(struct page *page, unsigned short order,
--
2.56.1.708.g77570a6a1d-goog
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] mm/page_owner: fix double decrement of stack count on unpoison
2026-11-18 21:28 [PATCH] mm/page_owner: fix double decrement of stack count on unpoison Nilay Vaish
@ 2026-11-19 11:53 ` Jose A. Perez de Azpillaga
2026-11-19 13:23 ` Oscar Salvador (SUSE)
1 sibling, 0 replies; 3+ messages in thread
From: Jose A. Perez de Azpillaga @ 2026-11-19 11:53 UTC (permalink / raw)
To: Nilay Vaish, Andrew Morton, Vlastimil Babka, Oscar Salvador
Cc: Johannes Weiner, Suren Baghdasaryan, Michal Hocko,
Brendan Jackman, Zi Yan, Marco Elver, Andrey Konovalov,
Miaohe Lin, Naoya Horiguchi, linux-mm, linux-kernel, stable
On 11/18/26 10:28 PM, Nilay Vaish wrote:
> page_owner counts, for each allocation stack, how many pages allocated
> from that stack are still in use. The count is incremented when a page
> is allocated and decremented in __reset_page_owner() when it is freed.
>
> A page that is hwpoisoned while in use and later unpoisoned passes
> through free_pages_prepare() twice:
>
> 1. On poisoning, the last reference is dropped. free_pages_prepare()
> calls reset_page_owner() but, because the page is PageHWPoison(),
> keeps it off the free lists.
>
> 2. On unpoisoning, unpoison_memory() drops the poison reference and
> free_pages_prepare() calls reset_page_owner() again, this time
> really freeing the page.
>
> __reset_page_owner() decrements the stack count both times, although
> the page was allocated only once. The first call clears
> PAGE_EXT_OWNER_ALLOCATED, but the second call never checks it.
>
> If this drives the count to zero while the stack is still in use,
> stackdepot treats the record as freed and warns on every later
> allocation or free that uses the same stack:
>
> dec_stack_record_count: refcount went to 0 for 92274844 handle
> WARNING: lib/stackdepot.c:517 at depot_fetch_stack+0x5c/0x70
> Call Trace:
> __set_page_owner+0x110/0x290
> get_page_from_freelist+0x1225/0x1440
> __alloc_frozen_pages_noprof+0x1fc/0x1b00
> __folio_alloc_noprof+0x12/0xa0
> alloc_migration_target+0x81/0x1e0
> migrate_pages_batch+0x1f2/0x14c0
> migrate_pages+0x9c3/0xca0
> soft_offline_page+0x189/0x570
>
> A single soft offline followed by an unpoison is enough to trigger it,
> because the migration-target stack that the offlined page is accounted
> to usually has very few pages.
>
> Fix it by decrementing the stack count only if PAGE_EXT_OWNER_ALLOCATED
> was still set, i.e. only the first time the page is freed.
>
> To reproduce, boot with page_owner=on and CONFIG_HWPOISON_INJECT, soft
> offline anonymous pages with madvise(MADV_SOFT_OFFLINE), and unpoison
> each old PFN through debugfs hwpoison/unpoison-pfn. Without this patch
> the first cycle prints the message above and 2200 cycles produce 6597
> warnings. With it, the same run is clean and all stack counts return
> to their initial values.
>
> Fixes: 217b2119b9e2 ("mm,page_owner: implement the tracking of the stacks count")
> Cc: stable@vger.kernel.org
> Signed-off-by: Nilay Vaish <nilayvaish@google.com>
LGTM:
Reviewed-by: Jose A. Perez de Azpillaga <azpijr@gmail.com>
--
cheers,
jose a. p-a
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] mm/page_owner: fix double decrement of stack count on unpoison
2026-11-18 21:28 [PATCH] mm/page_owner: fix double decrement of stack count on unpoison Nilay Vaish
2026-11-19 11:53 ` Jose A. Perez de Azpillaga
@ 2026-11-19 13:23 ` Oscar Salvador (SUSE)
1 sibling, 0 replies; 3+ messages in thread
From: Oscar Salvador (SUSE) @ 2026-11-19 13:23 UTC (permalink / raw)
To: Nilay Vaish
Cc: Andrew Morton, Vlastimil Babka, Oscar Salvador, Johannes Weiner,
Suren Baghdasaryan, Michal Hocko, Brendan Jackman, Zi Yan,
Marco Elver, Andrey Konovalov, Miaohe Lin, Naoya Horiguchi,
linux-mm, linux-kernel, stable
On Wed, Nov 18, 2026 at 01:28:19PM -0800, Nilay Vaish wrote:
> page_owner counts, for each allocation stack, how many pages allocated
> from that stack are still in use. The count is incremented when a page
> is allocated and decremented in __reset_page_owner() when it is freed.
>
> A page that is hwpoisoned while in use and later unpoisoned passes
> through free_pages_prepare() twice:
>
> 1. On poisoning, the last reference is dropped. free_pages_prepare()
> calls reset_page_owner() but, because the page is PageHWPoison(),
> keeps it off the free lists.
>
> 2. On unpoisoning, unpoison_memory() drops the poison reference and
> free_pages_prepare() calls reset_page_owner() again, this time
> really freeing the page.
>
> __reset_page_owner() decrements the stack count both times, although
> the page was allocated only once. The first call clears
> PAGE_EXT_OWNER_ALLOCATED, but the second call never checks it.
>
> If this drives the count to zero while the stack is still in use,
> stackdepot treats the record as freed and warns on every later
> allocation or free that uses the same stack:
>
> dec_stack_record_count: refcount went to 0 for 92274844 handle
> WARNING: lib/stackdepot.c:517 at depot_fetch_stack+0x5c/0x70
> Call Trace:
> __set_page_owner+0x110/0x290
> get_page_from_freelist+0x1225/0x1440
> __alloc_frozen_pages_noprof+0x1fc/0x1b00
> __folio_alloc_noprof+0x12/0xa0
> alloc_migration_target+0x81/0x1e0
> migrate_pages_batch+0x1f2/0x14c0
> migrate_pages+0x9c3/0xca0
> soft_offline_page+0x189/0x570
>
> A single soft offline followed by an unpoison is enough to trigger it,
> because the migration-target stack that the offlined page is accounted
> to usually has very few pages.
>
> Fix it by decrementing the stack count only if PAGE_EXT_OWNER_ALLOCATED
> was still set, i.e. only the first time the page is freed.
>
> To reproduce, boot with page_owner=on and CONFIG_HWPOISON_INJECT, soft
> offline anonymous pages with madvise(MADV_SOFT_OFFLINE), and unpoison
> each old PFN through debugfs hwpoison/unpoison-pfn. Without this patch
> the first cycle prints the message above and 2200 cycles produce 6597
> warnings. With it, the same run is clean and all stack counts return
> to their initial values.
>
> Fixes: 217b2119b9e2 ("mm,page_owner: implement the tracking of the stacks count")
> Cc: stable@vger.kernel.org
> Signed-off-by: Nilay Vaish <nilayvaish@google.com>
Reviewed-by: Oscar Salvador (SUSE) <osalvador@kernel.org>
Nit below:
> ---
> mm/page_owner.c | 5 ++++-
> 1 file changed, 4 insertions(+), 1 deletion(-)
>
> diff --git a/mm/page_owner.c b/mm/page_owner.c
> index 02bb304b53cf..0793a460d615 100644
> --- a/mm/page_owner.c
> +++ b/mm/page_owner.c
> @@ -320,11 +320,13 @@ void __reset_page_owner(struct page *page, unsigned short order)
> depot_stack_handle_t alloc_handle;
> struct page_owner *page_owner;
> u64 free_ts_nsec = local_clock();
> + bool allocated;
>
> page_ext = page_ext_get(page);
> if (unlikely(!page_ext))
> return;
>
> + allocated = test_bit(PAGE_EXT_OWNER_ALLOCATED, &page_ext->flags);
> page_owner = get_page_owner(page_ext);
> alloc_handle = page_owner->handle;
> page_ext_put(page_ext);
> @@ -339,7 +341,7 @@ void __reset_page_owner(struct page *page, unsigned short order)
> __update_page_owner_free_handle(page, handle, order, current->pid,
> current->tgid, free_ts_nsec);
>
> - if (alloc_handle != early_handle)
> + if (allocated && alloc_handle != early_handle) {
> /*
> * early_handle is being set as a handle for all those
> * early allocated pages. See init_pages_in_zone().
> @@ -348,6 +350,7 @@ void __reset_page_owner(struct page *page, unsigned short order)
> * their refcount either.
> */
I would expand this comment to integrate the allocated logic.
Because someone might think that every page hitting this function should have
been previously allocated.
--
Oscar Salvador
SUSE Labs
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-11-19 13:23 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-18 21:28 [PATCH] mm/page_owner: fix double decrement of stack count on unpoison Nilay Vaish
2026-11-19 11:53 ` Jose A. Perez de Azpillaga
2026-11-19 13:23 ` Oscar Salvador (SUSE)
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®