* [PATCH V2] mm/page_alloc: skip debug_check_no_{obj,locks}_freed with FPI_TRYLOCK
@ 2026-02-09 6:26 Harry Yoo
2026-02-09 10:51 ` Vlastimil Babka
2026-02-09 16:37 ` Zi Yan
0 siblings, 2 replies; 3+ messages in thread
From: Harry Yoo @ 2026-02-09 6:26 UTC (permalink / raw)
To: Andrew Morton
Cc: Vlastimil Babka, Suren Baghdasaryan, Michal Hocko,
Brendan Jackman, Johannes Weiner, Zi Yan, Alexei Starovoitov,
Sebastian Andrzej Siewior, Shakeel Butt, linux-mm, Harry Yoo,
stable
When CONFIG_DEBUG_OBJECTS_FREE is enabled,
debug_check_no_{obj,locks}_freed() functions are called.
Since both of them spin on a lock, they are not safe to be called
if the FPI_TRYLOCK flag is specified. This leads to a lockdep splat:
================================
WARNING: inconsistent lock state
6.19.0-rc5-slab-for-next+ #326 Tainted: G N
--------------------------------
inconsistent {INITIAL USE} -> {IN-NMI} usage.
kunit_try_catch/9046 [HC2[2]:SC0[0]:HE0:SE1] takes:
ffffffff84ed6bf8 (&obj_hash[i].lock){-.-.}-{2:2}, at: __debug_check_no_obj_freed+0xe0/0x300
{INITIAL USE} state was registered at:
lock_acquire+0xd9/0x2f0
_raw_spin_lock_irqsave+0x4c/0x80
__debug_object_init+0x9d/0x1f0
debug_object_init+0x34/0x50
__init_work+0x28/0x40
init_cgroup_housekeeping+0x151/0x210
init_cgroup_root+0x3d/0x140
cgroup_init_early+0x30/0x240
start_kernel+0x3e/0xcd0
x86_64_start_reservations+0x18/0x30
x86_64_start_kernel+0xf3/0x140
common_startup_64+0x13e/0x148
irq event stamp: 2998
hardirqs last enabled at (2997): [<ffffffff8298b77a>] exc_nmi+0x11a/0x240
hardirqs last disabled at (2998): [<ffffffff8298b991>] sysvec_irq_work+0x11/0x110
softirqs last enabled at (1416): [<ffffffff813c1f72>] __irq_exit_rcu+0x132/0x1c0
softirqs last disabled at (1303): [<ffffffff813c1f72>] __irq_exit_rcu+0x132/0x1c0
other info that might help us debug this:
Possible unsafe locking scenario:
CPU0
----
lock(&obj_hash[i].lock);
<Interrupt>
lock(&obj_hash[i].lock);
*** DEADLOCK ***
Rename free_pages_prepare() to __free_pages_prepare(), add an fpi_t
parameter, and skip those checks if FPI_TRYLOCK is set. To keep the
fpi_t definition in mm/page_alloc.c, add a wrapper function
free_pages_prepare() that always passes FPI_NONE and use it in
mm/compaction.c.
Fixes: 8c57b687e833 ("mm, bpf: Introduce free_pages_nolock()")
Cc: <stable@vger.kernel.org>
Signed-off-by: Harry Yoo <harry.yoo@oracle.com>
---
V1 -> v2:
Per Vlastimil's suggestion, rename free_pages_prepare() to
__free_pages_prepare() instead of moving the fpi_t definition to
mm/internal.h. __free_pages_prepare() takes fpi_t as parameter,
free_pages_prepare() always passes FPI_NONE to __free_pages_prepare().
mm/page_alloc.c | 17 +++++++++++------
1 file changed, 11 insertions(+), 6 deletions(-)
diff --git a/mm/page_alloc.c b/mm/page_alloc.c
index cbf758e27aa2..1513084d7507 100644
--- a/mm/page_alloc.c
+++ b/mm/page_alloc.c
@@ -1340,8 +1340,8 @@ static inline void pgalloc_tag_sub_pages(struct alloc_tag *tag, unsigned int nr)
#endif /* CONFIG_MEM_ALLOC_PROFILING */
-__always_inline bool free_pages_prepare(struct page *page,
- unsigned int order)
+__always_inline bool __free_pages_prepare(struct page *page,
+ unsigned int order, fpi_t fpi_flags)
{
int bad = 0;
bool skip_kasan_poison = should_skip_kasan_poison(page);
@@ -1434,7 +1434,7 @@ __always_inline bool free_pages_prepare(struct page *page,
page_table_check_free(page, order);
pgalloc_tag_sub(page, 1 << order);
- if (!PageHighMem(page)) {
+ if (!PageHighMem(page) && !(fpi_flags & FPI_TRYLOCK)) {
debug_check_no_locks_freed(page_address(page),
PAGE_SIZE << order);
debug_check_no_obj_freed(page_address(page),
@@ -1473,6 +1473,11 @@ __always_inline bool free_pages_prepare(struct page *page,
return true;
}
+bool free_pages_prepare(struct page *page, unsigned int order)
+{
+ return __free_pages_prepare(page, order, FPI_NONE);
+}
+
/*
* Frees a number of pages from the PCP lists
* Assumes all pages on list are in same zone.
@@ -1606,7 +1611,7 @@ static void __free_pages_ok(struct page *page, unsigned int order,
unsigned long pfn = page_to_pfn(page);
struct zone *zone = page_zone(page);
- if (free_pages_prepare(page, order))
+ if (__free_pages_prepare(page, order, fpi_flags))
free_one_page(zone, page, pfn, order, fpi_flags);
}
@@ -2970,7 +2975,7 @@ static void __free_frozen_pages(struct page *page, unsigned int order,
return;
}
- if (!free_pages_prepare(page, order))
+ if (!__free_pages_prepare(page, order, fpi_flags))
return;
/*
@@ -3027,7 +3032,7 @@ void free_unref_folios(struct folio_batch *folios)
unsigned long pfn = folio_pfn(folio);
unsigned int order = folio_order(folio);
- if (!free_pages_prepare(&folio->page, order))
+ if (!__free_pages_prepare(&folio->page, order, FPI_NONE))
continue;
/*
* Free orders not handled on the PCP directly to the
--
2.43.0
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH V2] mm/page_alloc: skip debug_check_no_{obj,locks}_freed with FPI_TRYLOCK
2026-02-09 6:26 [PATCH V2] mm/page_alloc: skip debug_check_no_{obj,locks}_freed with FPI_TRYLOCK Harry Yoo
@ 2026-02-09 10:51 ` Vlastimil Babka
2026-02-09 16:37 ` Zi Yan
1 sibling, 0 replies; 3+ messages in thread
From: Vlastimil Babka @ 2026-02-09 10:51 UTC (permalink / raw)
To: Harry Yoo, Andrew Morton
Cc: Suren Baghdasaryan, Michal Hocko, Brendan Jackman,
Johannes Weiner, Zi Yan, Alexei Starovoitov,
Sebastian Andrzej Siewior, Shakeel Butt, linux-mm, stable
On 2/9/26 07:26, Harry Yoo wrote:
> When CONFIG_DEBUG_OBJECTS_FREE is enabled,
> debug_check_no_{obj,locks}_freed() functions are called.
>
> Since both of them spin on a lock, they are not safe to be called
> if the FPI_TRYLOCK flag is specified. This leads to a lockdep splat:
>
> ================================
> WARNING: inconsistent lock state
> 6.19.0-rc5-slab-for-next+ #326 Tainted: G N
> --------------------------------
> inconsistent {INITIAL USE} -> {IN-NMI} usage.
> kunit_try_catch/9046 [HC2[2]:SC0[0]:HE0:SE1] takes:
> ffffffff84ed6bf8 (&obj_hash[i].lock){-.-.}-{2:2}, at: __debug_check_no_obj_freed+0xe0/0x300
> {INITIAL USE} state was registered at:
> lock_acquire+0xd9/0x2f0
> _raw_spin_lock_irqsave+0x4c/0x80
> __debug_object_init+0x9d/0x1f0
> debug_object_init+0x34/0x50
> __init_work+0x28/0x40
> init_cgroup_housekeeping+0x151/0x210
> init_cgroup_root+0x3d/0x140
> cgroup_init_early+0x30/0x240
> start_kernel+0x3e/0xcd0
> x86_64_start_reservations+0x18/0x30
> x86_64_start_kernel+0xf3/0x140
> common_startup_64+0x13e/0x148
> irq event stamp: 2998
> hardirqs last enabled at (2997): [<ffffffff8298b77a>] exc_nmi+0x11a/0x240
> hardirqs last disabled at (2998): [<ffffffff8298b991>] sysvec_irq_work+0x11/0x110
> softirqs last enabled at (1416): [<ffffffff813c1f72>] __irq_exit_rcu+0x132/0x1c0
> softirqs last disabled at (1303): [<ffffffff813c1f72>] __irq_exit_rcu+0x132/0x1c0
>
> other info that might help us debug this:
> Possible unsafe locking scenario:
>
> CPU0
> ----
> lock(&obj_hash[i].lock);
> <Interrupt>
> lock(&obj_hash[i].lock);
>
> *** DEADLOCK ***
>
> Rename free_pages_prepare() to __free_pages_prepare(), add an fpi_t
> parameter, and skip those checks if FPI_TRYLOCK is set. To keep the
> fpi_t definition in mm/page_alloc.c, add a wrapper function
> free_pages_prepare() that always passes FPI_NONE and use it in
> mm/compaction.c.
>
> Fixes: 8c57b687e833 ("mm, bpf: Introduce free_pages_nolock()")
> Cc: <stable@vger.kernel.org>
> Signed-off-by: Harry Yoo <harry.yoo@oracle.com>
Reviewed-by: Vlastimil Babka <vbabka@suse.cz>
Thanks!
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH V2] mm/page_alloc: skip debug_check_no_{obj,locks}_freed with FPI_TRYLOCK
2026-02-09 6:26 [PATCH V2] mm/page_alloc: skip debug_check_no_{obj,locks}_freed with FPI_TRYLOCK Harry Yoo
2026-02-09 10:51 ` Vlastimil Babka
@ 2026-02-09 16:37 ` Zi Yan
1 sibling, 0 replies; 3+ messages in thread
From: Zi Yan @ 2026-02-09 16:37 UTC (permalink / raw)
To: Harry Yoo
Cc: Andrew Morton, Vlastimil Babka, Suren Baghdasaryan, Michal Hocko,
Brendan Jackman, Johannes Weiner, Alexei Starovoitov,
Sebastian Andrzej Siewior, Shakeel Butt, linux-mm, stable
On 9 Feb 2026, at 1:26, Harry Yoo wrote:
> When CONFIG_DEBUG_OBJECTS_FREE is enabled,
> debug_check_no_{obj,locks}_freed() functions are called.
>
> Since both of them spin on a lock, they are not safe to be called
> if the FPI_TRYLOCK flag is specified. This leads to a lockdep splat:
>
> ================================
> WARNING: inconsistent lock state
> 6.19.0-rc5-slab-for-next+ #326 Tainted: G N
> --------------------------------
> inconsistent {INITIAL USE} -> {IN-NMI} usage.
> kunit_try_catch/9046 [HC2[2]:SC0[0]:HE0:SE1] takes:
> ffffffff84ed6bf8 (&obj_hash[i].lock){-.-.}-{2:2}, at: __debug_check_no_obj_freed+0xe0/0x300
> {INITIAL USE} state was registered at:
> lock_acquire+0xd9/0x2f0
> _raw_spin_lock_irqsave+0x4c/0x80
> __debug_object_init+0x9d/0x1f0
> debug_object_init+0x34/0x50
> __init_work+0x28/0x40
> init_cgroup_housekeeping+0x151/0x210
> init_cgroup_root+0x3d/0x140
> cgroup_init_early+0x30/0x240
> start_kernel+0x3e/0xcd0
> x86_64_start_reservations+0x18/0x30
> x86_64_start_kernel+0xf3/0x140
> common_startup_64+0x13e/0x148
> irq event stamp: 2998
> hardirqs last enabled at (2997): [<ffffffff8298b77a>] exc_nmi+0x11a/0x240
> hardirqs last disabled at (2998): [<ffffffff8298b991>] sysvec_irq_work+0x11/0x110
> softirqs last enabled at (1416): [<ffffffff813c1f72>] __irq_exit_rcu+0x132/0x1c0
> softirqs last disabled at (1303): [<ffffffff813c1f72>] __irq_exit_rcu+0x132/0x1c0
>
> other info that might help us debug this:
> Possible unsafe locking scenario:
>
> CPU0
> ----
> lock(&obj_hash[i].lock);
> <Interrupt>
> lock(&obj_hash[i].lock);
>
> *** DEADLOCK ***
>
> Rename free_pages_prepare() to __free_pages_prepare(), add an fpi_t
> parameter, and skip those checks if FPI_TRYLOCK is set. To keep the
> fpi_t definition in mm/page_alloc.c, add a wrapper function
> free_pages_prepare() that always passes FPI_NONE and use it in
> mm/compaction.c.
>
> Fixes: 8c57b687e833 ("mm, bpf: Introduce free_pages_nolock()")
> Cc: <stable@vger.kernel.org>
> Signed-off-by: Harry Yoo <harry.yoo@oracle.com>
> ---
>
> V1 -> v2:
>
> Per Vlastimil's suggestion, rename free_pages_prepare() to
> __free_pages_prepare() instead of moving the fpi_t definition to
> mm/internal.h. __free_pages_prepare() takes fpi_t as parameter,
> free_pages_prepare() always passes FPI_NONE to __free_pages_prepare().
>
> mm/page_alloc.c | 17 +++++++++++------
> 1 file changed, 11 insertions(+), 6 deletions(-)
>
Thanks.
Acked-by: Zi Yan <ziy@nvidia.com>
Best Regards,
Yan, Zi
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-02-09 16:38 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-02-09 6:26 [PATCH V2] mm/page_alloc: skip debug_check_no_{obj,locks}_freed with FPI_TRYLOCK Harry Yoo
2026-02-09 10:51 ` Vlastimil Babka
2026-02-09 16:37 ` Zi Yan
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox