From: ranxiaokai627@163.com
To: catalin.marinas@arm.com, akpm@linux-foundation.org,
graf@amazon.com, rppt@kernel.org, pasha.tatashin@soleen.com,
pratyush@kernel.org, changyuanl@google.com
Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org,
kexec@lists.infradead.org, ran.xiaokai@zte.com.cn,
ranxiaokai627@163.com
Subject: [PATCH 1/2] mm: kmemleak: introduce kmemleak_no_scan_phys() helper
Date: Thu, 20 Nov 2025 14:41:46 +0000 [thread overview]
Message-ID: <20251120144147.90508-2-ranxiaokai627@163.com> (raw)
In-Reply-To: <20251120144147.90508-1-ranxiaokai627@163.com>
From: Ran Xiaokai <ran.xiaokai@zte.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@zte.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
next prev parent reply other threads:[~2025-11-20 14:42 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-11-20 14:41 [PATCH 0/2] liveupdate: Fix boot failure due to kmemleak access to unmapped pages ranxiaokai627
2025-11-20 14:41 ` ranxiaokai627 [this message]
2025-11-20 14:41 ` [PATCH 2/2] " ranxiaokai627
2025-11-20 16:17 ` Pratyush Yadav
2025-11-22 17:57 ` ranxiaokai627
2025-11-21 13:36 ` Mike Rapoport
2025-11-22 18:07 ` ranxiaokai627
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20251120144147.90508-2-ranxiaokai627@163.com \
--to=ranxiaokai627@163.com \
--cc=akpm@linux-foundation.org \
--cc=catalin.marinas@arm.com \
--cc=changyuanl@google.com \
--cc=graf@amazon.com \
--cc=kexec@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=pasha.tatashin@soleen.com \
--cc=pratyush@kernel.org \
--cc=ran.xiaokai@zte.com.cn \
--cc=rppt@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox