mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH 0/3] mm/vmalloc: fix vmalloc_dump_obj VA lookup
@ 2026-09-16  8:25 Ye Liu
  2026-09-16  8:25 ` [PATCH 1/3] mm/vmalloc: fix vmalloc_dump_obj address alignment for last-page lookups Ye Liu
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Ye Liu @ 2026-09-16  8:25 UTC (permalink / raw)
  To: Andrew Morton, Uladzislau Rezki; +Cc: linux-mm, linux-kernel, Ye Liu

vmalloc_dump_obj() has two bugs that cause it to miss vmalloc
allocations, plus a minor optimization opportunity:

  1. PAGE_ALIGN() rounds up, pushing last-page addresses to va_end
     and outside the VA lookup range.

  2. The function searches only one vmap node, but allocations
     larger than 64 KiB may span multiple vmap zones whose VA
     is stored in a different node's rb-tree.

Patch 1 fixes the alignment, patch 2 fixes the cross-zone search,
patch 3 adds an early is_vmalloc_addr() check to skip non-vmalloc
addresses without traversing all nodes.

Signed-off-by: Ye Liu <liuye@kylinos.cn>
---
Ye Liu (3):
      mm/vmalloc: fix vmalloc_dump_obj address alignment for last-page lookups
      mm/vmalloc: fix vmalloc_dump_obj cross-zone VA lookup
      mm/vmalloc: skip vmalloc_dump_obj for non-vmalloc addresses

 mm/vmalloc.c | 29 ++++++++++++++++++++++-------
 1 file changed, 22 insertions(+), 7 deletions(-)
---
base-commit: e6e35979777d646fe3c7c94dca7dd32fb25d45f4
change-id: 20260916-vmalloc_dump_obj-d80908447369

Best regards,
-- 
Ye Liu <ye.liu@linux.dev>


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

* [PATCH 1/3] mm/vmalloc: fix vmalloc_dump_obj address alignment for last-page lookups
  2026-09-16  8:25 [PATCH 0/3] mm/vmalloc: fix vmalloc_dump_obj VA lookup Ye Liu
@ 2026-09-16  8:25 ` Ye Liu
  2026-09-16  8:25 ` [PATCH 2/3] mm/vmalloc: fix vmalloc_dump_obj cross-zone VA lookup Ye Liu
  2026-09-16  8:25 ` [PATCH 3/3] mm/vmalloc: skip vmalloc_dump_obj for non-vmalloc addresses Ye Liu
  2 siblings, 0 replies; 4+ messages in thread
From: Ye Liu @ 2026-09-16  8:25 UTC (permalink / raw)
  To: Andrew Morton, Uladzislau Rezki; +Cc: linux-mm, linux-kernel, Ye Liu

From: Ye Liu <liuye@kylinos.cn>

vmalloc_dump_obj() uses PAGE_ALIGN() to normalize the input address
before looking it up in the per-node busy tree.  PAGE_ALIGN() rounds
up, which can push an address in the last page of a vmalloc allocation
to va_end -- outside the [va_start, va_end) range that
__find_vmap_area() searches.  This causes the lookup to miss the VA
and return false, degrading diagnostic output in OOM dumps and KASAN
reports to the less informative "vmalloc memory" fallback.

The upward alignment can also change the addr_to_node() mapping when
the page boundary crosses a vmap zone boundary, causing the search to
hit the wrong node entirely.

Use PAGE_ALIGN_DOWN() instead, which rounds down to the page
containing the address.  This keeps the address within the VA range
and preserves the correct node mapping.

Signed-off-by: Ye Liu <liuye@kylinos.cn>
---
 mm/vmalloc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/mm/vmalloc.c b/mm/vmalloc.c
index 859e6d2d57a3..df42d8a6f058 100644
--- a/mm/vmalloc.c
+++ b/mm/vmalloc.c
@@ -5277,7 +5277,7 @@ bool vmalloc_dump_obj(void *object)
 	unsigned long addr;
 	unsigned long nr_pages;
 
-	addr = PAGE_ALIGN((unsigned long) object);
+	addr = PAGE_ALIGN_DOWN((unsigned long) object);
 	vn = addr_to_node(addr);
 
 	if (!spin_trylock(&vn->busy.lock))

-- 
2.25.1


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

* [PATCH 2/3] mm/vmalloc: fix vmalloc_dump_obj cross-zone VA lookup
  2026-09-16  8:25 [PATCH 0/3] mm/vmalloc: fix vmalloc_dump_obj VA lookup Ye Liu
  2026-09-16  8:25 ` [PATCH 1/3] mm/vmalloc: fix vmalloc_dump_obj address alignment for last-page lookups Ye Liu
@ 2026-09-16  8:25 ` Ye Liu
  2026-09-16  8:25 ` [PATCH 3/3] mm/vmalloc: skip vmalloc_dump_obj for non-vmalloc addresses Ye Liu
  2 siblings, 0 replies; 4+ messages in thread
From: Ye Liu @ 2026-09-16  8:25 UTC (permalink / raw)
  To: Andrew Morton, Uladzislau Rezki; +Cc: linux-mm, linux-kernel, Ye Liu

From: Ye Liu <liuye@kylinos.cn>

vmalloc_dump_obj() searches only one vmap node (addr_to_node(addr)),
but a vmalloc allocation may span multiple vmap zones.  The VA is
stored in only one node's rb-tree (addr_to_node(va_start)), so an
object pointer in a different zone than va_start maps to a different
node and the search misses.  This affects any allocation larger than
vmap_zone_size (64 KiB) on multi-CPU systems.

Iterate all vmap nodes using for_each_vmap_node, like find_vmap_area()
does, but with spin_trylock instead of spin_lock as this function can
be called from atomic dump contexts (OOM, KASAN, RCU).

Signed-off-by: Ye Liu <liuye@kylinos.cn>
---
 mm/vmalloc.c | 24 ++++++++++++++++++------
 1 file changed, 18 insertions(+), 6 deletions(-)

diff --git a/mm/vmalloc.c b/mm/vmalloc.c
index df42d8a6f058..30c610f678dc 100644
--- a/mm/vmalloc.c
+++ b/mm/vmalloc.c
@@ -5278,17 +5278,29 @@ bool vmalloc_dump_obj(void *object)
 	unsigned long nr_pages;
 
 	addr = PAGE_ALIGN_DOWN((unsigned long) object);
-	vn = addr_to_node(addr);
 
-	if (!spin_trylock(&vn->busy.lock))
-		return false;
+	/*
+	 * A vmalloc allocation may span multiple vmap zones, so the
+	 * node whose rb-tree holds the VA may differ from the node
+	 * the address maps to.  Search all nodes.  Use trylock as
+	 * this function can be called from atomic dump contexts.
+	 */
+	va = NULL;
+	for_each_vmap_node(vn) {
+		if (!spin_trylock(&vn->busy.lock))
+			continue;
+
+		va = __find_vmap_area(addr, &vn->busy.root);
+		if (va && va->vm)
+			break;
 
-	va = __find_vmap_area(addr, &vn->busy.root);
-	if (!va || !va->vm) {
 		spin_unlock(&vn->busy.lock);
-		return false;
+		va = NULL;
 	}
 
+	if (!va)
+		return false;
+
 	vm = va->vm;
 	addr = (unsigned long) vm->addr;
 	caller = vm->caller;

-- 
2.25.1


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

* [PATCH 3/3] mm/vmalloc: skip vmalloc_dump_obj for non-vmalloc addresses
  2026-09-16  8:25 [PATCH 0/3] mm/vmalloc: fix vmalloc_dump_obj VA lookup Ye Liu
  2026-09-16  8:25 ` [PATCH 1/3] mm/vmalloc: fix vmalloc_dump_obj address alignment for last-page lookups Ye Liu
  2026-09-16  8:25 ` [PATCH 2/3] mm/vmalloc: fix vmalloc_dump_obj cross-zone VA lookup Ye Liu
@ 2026-09-16  8:25 ` Ye Liu
  2 siblings, 0 replies; 4+ messages in thread
From: Ye Liu @ 2026-09-16  8:25 UTC (permalink / raw)
  To: Andrew Morton, Uladzislau Rezki; +Cc: linux-mm, linux-kernel, Ye Liu

From: Ye Liu <liuye@kylinos.cn>

vmalloc_dump_obj() unconditionally searches all vmap nodes even when
called with a non-vmalloc address (e.g. a slab or stack pointer from
mem_dump_obj()).  Add an is_vmalloc_addr() check at the entry to
avoid the unnecessary per-node trylock and rb-tree traversal.

The KASAN caller already gates on is_vmalloc_addr(), but mem_dump_obj()
calls vmalloc_dump_obj() before the fallback type check, so the guard
in the callee covers both paths without requiring caller changes.

Signed-off-by: Ye Liu <liuye@kylinos.cn>
---
 mm/vmalloc.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/mm/vmalloc.c b/mm/vmalloc.c
index 30c610f678dc..b3e706fde202 100644
--- a/mm/vmalloc.c
+++ b/mm/vmalloc.c
@@ -5277,6 +5277,9 @@ bool vmalloc_dump_obj(void *object)
 	unsigned long addr;
 	unsigned long nr_pages;
 
+	if (!is_vmalloc_addr(object))
+		return false;
+
 	addr = PAGE_ALIGN_DOWN((unsigned long) object);
 
 	/*

-- 
2.25.1


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

end of thread, other threads:[~2026-09-16  8:25 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-09-16  8:25 [PATCH 0/3] mm/vmalloc: fix vmalloc_dump_obj VA lookup Ye Liu
2026-09-16  8:25 ` [PATCH 1/3] mm/vmalloc: fix vmalloc_dump_obj address alignment for last-page lookups Ye Liu
2026-09-16  8:25 ` [PATCH 2/3] mm/vmalloc: fix vmalloc_dump_obj cross-zone VA lookup Ye Liu
2026-09-16  8:25 ` [PATCH 3/3] mm/vmalloc: skip vmalloc_dump_obj for non-vmalloc addresses Ye Liu

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®