Linux Kernel Selftest development
 help / color / mirror / Atom feed
* [PATCH v3 0/2] mm/kmemleak: dedupe verbose scan output
@ 2026-05-06 12:58 Breno Leitao
  2026-05-06 12:58 ` [PATCH v3 1/2] mm/kmemleak: dedupe verbose scan output by allocation backtrace Breno Leitao
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Breno Leitao @ 2026-05-06 12:58 UTC (permalink / raw)
  To: Andrew Morton, David Hildenbrand, Lorenzo Stoakes,
	Vlastimil Babka, Mike Rapoport, Suren Baghdasaryan, Michal Hocko,
	Shuah Khan, Catalin Marinas, Liam R. Howlett, Liam R. Howlett
  Cc: linux-kernel, linux-mm, linux-kselftest, kernel-team,
	Breno Leitao

In this version, I am not touching the kernel code, but, just fixing
the selftest, as sashiko reported some issues, and I am addressing them
in here.

https://sashiko.dev/#/patchset/20260424-kmemleak_dedup-v2-0-8bea649b2a92%40debian.org

NOTE: Additional testing has revealed that lockdep detects a potential lock
inversion issue on kmemleak and legacy console.

The problem occurs because the function holds &object->lock (a raw spinlock)
while invoking printk to report the leak. This printk requires the legacy
console_owner lock, which remains in active use despite the ongoing transition
to the nbcon framework.

Concurrently, console drivers such as hvc (hypervisor virtual console) acquire
the console_owner lock and may subsequently free memory. This kfree() operation
calls into kmemleak's __delete_object(), which in turn acquires object->lock.

Although these code paths hold locks from different object instances, lockdep
operates on lock classes rather than individual instances. Since all
kmemleak_object->lock instances belong to the same lock class, lockdep
identifies this as a circular dependency, even though the actual deadlock
scenario cannot occur in practice (?!).

This problem was not introduced by this patchset/selftest, but, it is exposing
it. I plan to solve it once this patchset is done.

Breno Leitao (2):
  mm/kmemleak: dedupe verbose scan output by allocation backtrace
  selftests/mm: add kmemleak verbose dedup test

mm/kmemleak.c                                 | 102 +++++++++++++++++-
 .../selftests/mm/test_kmemleak_dedup.sh       |  78 ++++++++++++++
 2 files changed, 175 insertions(+), 5 deletions(-)
 create mode 100755 tools/testing/selftests/mm/test_kmemleak_dedup.sh
-- 
2.52.0

Signed-off-by: Breno Leitao <leitao@debian.org>

---
Changes in v3:
 - No changes to the first patch (Kernel changes). All changes below are
   for the selftest.
 - Pre-cleanup before modprobe — rmmod "$MODULE" 2>/dev/null added before
   modprobe so a stale load doesn't cause modprobe to be a no-op.
 - dmesg -C between the two scans — isolates printed count to the second
   (reporting) scan only.
- Link to v2: https://patch.msgid.link/20260424-kmemleak_dedup-v2-0-8bea649b2a92@debian.org

Changes in v2:
- Drop struct kmemleak_dedup_entry and its kmalloc. (Catalin)
- Handle trace_handle == 0 instead of dropping it.
- Skip hex dump for coalesced entries (dup_count > 1) — bytes would differ
  across objects sharing a trace anyway, and it removes the only
  object->pointer read left in the deferred path.
- Counter narrowed from unsigned long count to unsigned int dup_count.
- Link to v1: https://patch.msgid.link/20260421-kmemleak_dedup-v1-0-65e31c6cdf0c@debian.org

---
Breno Leitao (2):
      mm/kmemleak: dedupe verbose scan output by allocation backtrace
      selftests/mm: add kmemleak verbose dedup test

 mm/kmemleak.c                                     | 148 ++++++++++++++-
 tools/testing/selftests/mm/Makefile               |   1 +
 tools/testing/selftests/mm/ksft_kmemleak_dedup.sh | 222 ++++++++++++++++++++++
 3 files changed, 363 insertions(+), 8 deletions(-)
---
base-commit: 4cd074ae20bbcc293bbbce9163abe99d68ae6ae0
change-id: 20260420-kmemleak_dedup-bee54ffa65e7

Best regards,
--  
Breno Leitao <leitao@debian.org>


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-05-08 22:17 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-05-06 12:58 [PATCH v3 0/2] mm/kmemleak: dedupe verbose scan output Breno Leitao
2026-05-06 12:58 ` [PATCH v3 1/2] mm/kmemleak: dedupe verbose scan output by allocation backtrace Breno Leitao
2026-05-06 12:58 ` [PATCH v3 2/2] selftests/mm: add kmemleak verbose dedup test Breno Leitao
2026-05-08 22:17 ` [PATCH v3 0/2] mm/kmemleak: dedupe verbose scan output Andrew Morton

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox