Re: [PATCH v2 2/6] futex: Use RCU-based per-CPU reference counting instead of rcuref_t
From: Thomas Gleixner
Date: Wed Jul 30 2025 - 15:45:05 EST
On Wed, Jul 30 2025 at 13:20, André Draszik wrote:
> kmemleak complains about a new memleak with this commit:
>
> [ 680.179004][ T101] kmemleak: 1 new suspected memory leaks (see /sys/kernel/debug/kmemleak)
>
> $ cat /sys/kernel/debug/kmemleak
> unreferenced object (percpu) 0xc22ec0eface8 (size 4):
> comm "swapper/0", pid 1, jiffies 4294893115
> hex dump (first 4 bytes on cpu 7):
> 01 00 00 00 ....
> backtrace (crc b8bc6765):
> kmemleak_alloc_percpu+0x48/0xb8
> pcpu_alloc_noprof+0x6ac/0xb68
> futex_mm_init+0x60/0xe0
> mm_init+0x1e8/0x3c0
> mm_alloc+0x5c/0x78
> init_args+0x74/0x4b0
> debug_vm_pgtable+0x60/0x2d8
>
> Reverting this commit (and patches 3 and 4 in this series due to context),
> makes kmemleak happy again.
Unsurprisingly ...
debug_vm_pgtable() allocates it via mm_alloc() -> mm->init() and then
after the selftest it invokes mmdrop(), which does not free it, as it is
only freed in __mmput().
The patch below should fix it.
Thanks,
tglx
---
--- a/kernel/fork.c
+++ b/kernel/fork.c
@@ -686,6 +686,7 @@ void __mmdrop(struct mm_struct *mm)
mm_pasid_drop(mm);
mm_destroy_cid(mm);
percpu_counter_destroy_many(mm->rss_stat, NR_MM_COUNTERS);
+ futex_hash_free(mm);
free_mm(mm);
}
@@ -1133,7 +1134,6 @@ static inline void __mmput(struct mm_str
if (mm->binfmt)
module_put(mm->binfmt->module);
lru_gen_del_mm(mm);
- futex_hash_free(mm);
mmdrop(mm);
}