[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20251120144147.90508-2-ranxiaokai627@163.com>
Date: Thu, 20 Nov 2025 14:41:46 +0000
From: ranxiaokai627@....com
To: catalin.marinas@....com,
akpm@...ux-foundation.org,
graf@...zon.com,
rppt@...nel.org,
pasha.tatashin@...een.com,
pratyush@...nel.org,
changyuanl@...gle.com
Cc: linux-kernel@...r.kernel.org,
linux-mm@...ck.org,
kexec@...ts.infradead.org,
ran.xiaokai@....com.cn,
ranxiaokai627@....com
Subject: [PATCH 1/2] mm: kmemleak: introduce kmemleak_no_scan_phys() helper
From: Ran Xiaokai <ran.xiaokai@....com.cn>
Introduce kmemleak_no_scan_phys(phys_addr_t), a physical-address
variant to kmemleak_no_scan(). This helper marks memory regions
as non-scanable using physical addresses directly.
It is specifically designed to prevent kmemleak from accessing pages
that have been unmapped by debug_pagealloc after being freed to
the buddy allocator. The kexec handover (KHO) subsystem will call
this helper to exclude the kho_scratch reservation region from scanning,
thereby avoiding fatal page faults during boot when debug_pagealloc=on.
Signed-off-by: Ran Xiaokai <ran.xiaokai@....com.cn>
---
include/linux/kmemleak.h | 4 ++++
mm/kmemleak.c | 15 ++++++++++++---
2 files changed, 16 insertions(+), 3 deletions(-)
diff --git a/include/linux/kmemleak.h b/include/linux/kmemleak.h
index fbd424b2abb1..e955ad441b8a 100644
--- a/include/linux/kmemleak.h
+++ b/include/linux/kmemleak.h
@@ -31,6 +31,7 @@ extern void kmemleak_ignore(const void *ptr) __ref;
extern void kmemleak_ignore_percpu(const void __percpu *ptr) __ref;
extern void kmemleak_scan_area(const void *ptr, size_t size, gfp_t gfp) __ref;
extern void kmemleak_no_scan(const void *ptr) __ref;
+extern void kmemleak_no_scan_phys(phys_addr_t phys) __ref;
extern void kmemleak_alloc_phys(phys_addr_t phys, size_t size,
gfp_t gfp) __ref;
extern void kmemleak_free_part_phys(phys_addr_t phys, size_t size) __ref;
@@ -113,6 +114,9 @@ static inline void kmemleak_erase(void **ptr)
static inline void kmemleak_no_scan(const void *ptr)
{
}
+static inline void kmemleak_no_scan_phys(phys_addr_t phys)
+{
+}
static inline void kmemleak_alloc_phys(phys_addr_t phys, size_t size,
gfp_t gfp)
{
diff --git a/mm/kmemleak.c b/mm/kmemleak.c
index 1ac56ceb29b6..b2b8374e19c3 100644
--- a/mm/kmemleak.c
+++ b/mm/kmemleak.c
@@ -1058,12 +1058,12 @@ static void object_set_excess_ref(unsigned long ptr, unsigned long excess_ref)
* pointer. Such object will not be scanned by kmemleak but references to it
* are searched.
*/
-static void object_no_scan(unsigned long ptr)
+static void object_no_scan_flags(unsigned long ptr, unsigned long objflags)
{
unsigned long flags;
struct kmemleak_object *object;
- object = find_and_get_object(ptr, 0);
+ object = __find_and_get_object(ptr, 0, objflags);
if (!object) {
kmemleak_warn("Not scanning unknown object at 0x%08lx\n", ptr);
return;
@@ -1328,10 +1328,19 @@ void __ref kmemleak_no_scan(const void *ptr)
pr_debug("%s(0x%px)\n", __func__, ptr);
if (kmemleak_enabled && ptr && !IS_ERR(ptr))
- object_no_scan((unsigned long)ptr);
+ object_no_scan_flags((unsigned long)ptr, 0);
}
EXPORT_SYMBOL(kmemleak_no_scan);
+void __ref kmemleak_no_scan_phys(phys_addr_t phys)
+{
+ pr_debug("%s(%pap)\n", __func__, &phys);
+
+ if (kmemleak_enabled)
+ object_no_scan_flags((unsigned long)phys, OBJECT_PHYS);
+}
+EXPORT_SYMBOL(kmemleak_no_scan_phys);
+
/**
* kmemleak_alloc_phys - similar to kmemleak_alloc but taking a physical
* address argument
--
2.25.1
Powered by blists - more mailing lists