From nobody Tue Dec 2 02:05:59 2025 Received: from m16.mail.163.com (m16.mail.163.com [117.135.210.4]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 31E61238C2F for ; Thu, 20 Nov 2025 14:43:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=117.135.210.4 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763649812; cv=none; b=EO/DARsMGFwfvfDq4+jLrPmVu6XWB3UdFwgcsbNzJbtJIumnbJ9O0ciiflZqXWXi/WFKKibJRsDgnfU35cY5JkLA6VtgBsZ7WgCe6tocEvH7rOJp3OlbZ4oLCHrTGQgYmcblO9WR9lzY5ynLY+hVeKJPMp5qG+L/5uKb9knZSEo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763649812; c=relaxed/simple; bh=n5mY52QbQINl75Lq+ReLEIZO/UC+CgvSTuEjIouVh0I=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=J4G4JVo75050ImzuqNm4W2omM0531BPQ5RBJatcC6DtkOnIaaeXHPtgx5A492hp75MwG5bAqgo0gAzKPhaBHwU81S8KihZ6wfs+/RTonrm2pKf3DP1eeKLThDgixJSTTZ+NAB84EGSYW7pfXC0KW6NNxzE0M7jgBKuemagWgxdQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=163.com; spf=pass smtp.mailfrom=163.com; dkim=pass (1024-bit key) header.d=163.com header.i=@163.com header.b=YFhlBDO+; arc=none smtp.client-ip=117.135.210.4 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=163.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=163.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=163.com header.i=@163.com header.b="YFhlBDO+" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:To:Subject:Date:Message-ID:MIME-Version; bh=C2 1VWiTFnCtjKUC3lRTNib5t5KU/n8R+0YWZGg6WN4c=; b=YFhlBDO+wGNN1bMmpY 2qb/OX6/Mho6hh50nJn0j4E+Yf5o2M/RCV8iDnbqUEQ4ys/Lc1AuUDKfwYQN792v zBkZRsZD938tJhpCzPqFBrylDLRy1XFGCUfoAqHFb1ywCa93l1kzzgzonMTKKQfO y/yg9YsUNLwblZTUiUr/Q2TUo= Received: from ubuntu24-z.. (unknown []) by gzga-smtp-mtada-g0-2 (Coremail) with SMTP id _____wA3yJmuKB9pTEQrBQ--.727S3; Thu, 20 Nov 2025 22:41:53 +0800 (CST) 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 Message-ID: <20251120144147.90508-2-ranxiaokai627@163.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20251120144147.90508-1-ranxiaokai627@163.com> References: <20251120144147.90508-1-ranxiaokai627@163.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: _____wA3yJmuKB9pTEQrBQ--.727S3 X-Coremail-Antispam: 1Uf129KBjvJXoWxZry8XF4rKrW5Wry7tF43Wrg_yoW5Zr47pF Z7Cry7GFW7Xa4Uua9Fva48Zw4DJws7GF1aya42kwnxZF90vFn7Aw4fCrZFyFy5Jr97Gr4Y vrWxtFZ0kr48J3JanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x0piXyCPUUUUU= X-CM-SenderInfo: xudq5x5drntxqwsxqiywtou0bp/xtbBEAcMTGkfJUZRigAAsZ Content-Type: text/plain; charset="utf-8" From: Ran Xiaokai 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=3Don. Signed-off-by: Ran Xiaokai --- 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; =20 - object =3D find_and_get_object(ptr, 0); + object =3D __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); =20 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); =20 +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 --=20 2.25.1 From nobody Tue Dec 2 02:05:59 2025 Received: from m16.mail.163.com (m16.mail.163.com [117.135.210.5]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E62162D29AA for ; Thu, 20 Nov 2025 14:43:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=117.135.210.5 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763649792; cv=none; b=SsUGWp8r2NsK+r27s4WZY2ujmWnwQUPwaLBRtIiQqEUinAf+AI0Eu7EddijU0/9t6SzSV/Zq4LzjEHlDY9AOyJ2Bc/+cMYb216IR9p2m6fz5qK07ZYy3We95y/6p4keR5mMIr9f6aSZ6KR7zsOr0R3BVblEbmGKYHdqVC7Cwqgg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763649792; c=relaxed/simple; bh=spV5L6H1+JkcT2bjV3bV6+NvN1FGjSO/RDMsckEXpuM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=JzZrnd3EGo2S0nTyQGguWkTkOdgbOTKsOuax++Fq2FZOuC2v5Yyl+733wPoklzpRZSOO38T5ZyqB51i8gXfV+6HBVlKahjUfOZVJTJ70nWJERIn8BHIBh5G3qAi8iNat9wVCmC28Y33PRvN3dtt6Bq2du5nT23zDAg/msmI73vM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=163.com; spf=pass smtp.mailfrom=163.com; dkim=pass (1024-bit key) header.d=163.com header.i=@163.com header.b=T6DiTPF0; arc=none smtp.client-ip=117.135.210.5 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=163.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=163.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=163.com header.i=@163.com header.b="T6DiTPF0" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:To:Subject:Date:Message-ID:MIME-Version; bh=Vq tJVjFf2VTiEsbahcHSK1+SUTx0HAzBAG6cy3z+p1Y=; b=T6DiTPF0QphyeJ6ynn rpY6XD2TiGV6q27qAf8VLfdX98bhKJJh+KtuE1Hrjnxm4LekyutigidujNaJZWUG r84wyEXl/6O4Z5VDNM9CPz8nx5HVZn7NGs0xkQwThGDFvJjgCC4iACP8KbFJO8vA U8CfGhL9bNzEy5/5EKKrUSi7E= Received: from ubuntu24-z.. (unknown []) by gzga-smtp-mtada-g0-2 (Coremail) with SMTP id _____wA3yJmuKB9pTEQrBQ--.727S4; Thu, 20 Nov 2025 22:41:55 +0800 (CST) 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 2/2] liveupdate: Fix boot failure due to kmemleak access to unmapped pages Date: Thu, 20 Nov 2025 14:41:47 +0000 Message-ID: <20251120144147.90508-3-ranxiaokai627@163.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20251120144147.90508-1-ranxiaokai627@163.com> References: <20251120144147.90508-1-ranxiaokai627@163.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: _____wA3yJmuKB9pTEQrBQ--.727S4 X-Coremail-Antispam: 1Uf129KBjvJXoW7Kr48CF43Jw4DKryfuFWktFb_yoW8tr4xpF yvkF1DCw4jy34jqFWxZa4v934Fga90kw17AFyj934avr9Fv3s3tws5ZryUtryUXrZ3KF4j vFWDK3yruw4UZFDanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x0zEs2-UUUUUU= X-CM-SenderInfo: xudq5x5drntxqwsxqiywtou0bp/xtbBEBwMTGkfJUZRjQABsE Content-Type: text/plain; charset="utf-8" From: Ran Xiaokai When booting with debug_pagealloc=3Don while having: CONFIG_KEXEC_HANDOVER_ENABLE_DEFAULT=3Dy CONFIG_DEBUG_KMEMLEAK_DEFAULT_OFF=3Dn the system fails to boot due to page faults during kmemleak scanning. This occurs because: With debug_pagealloc enabled, __free_pages() invokes debug_pagealloc_unmap_pages(), clearing the _PAGE_PRESENT bit for freed pages in the direct mapping. Commit 3dc92c311498 ("kexec: add Kexec HandOver (KHO) generation helpers") releases the KHO scratch region via init_cma_reserved_pageblock(), unmapping its physical pages. Subsequent kmemleak scanning accesses these unmapped pages, triggering fatal page faults. Call kmemleak_no_scan_phys() from kho_reserve_scratch() to exclude the reserved region from scanning before it is released to the buddy allocator. Fixes: 3dc92c311498 ("kexec: add Kexec HandOver (KHO) generation helpers") Signed-off-by: Ran Xiaokai --- kernel/liveupdate/kexec_handover.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/kernel/liveupdate/kexec_handover.c b/kernel/liveupdate/kexec_h= andover.c index 224bdf5becb6..dd4942d1d76c 100644 --- a/kernel/liveupdate/kexec_handover.c +++ b/kernel/liveupdate/kexec_handover.c @@ -11,6 +11,7 @@ =20 #include #include +#include #include #include #include @@ -654,6 +655,7 @@ static void __init kho_reserve_scratch(void) if (!addr) goto err_free_scratch_desc; =20 + kmemleak_no_scan_phys(addr); kho_scratch[i].addr =3D addr; kho_scratch[i].size =3D size; i++; @@ -664,6 +666,7 @@ static void __init kho_reserve_scratch(void) if (!addr) goto err_free_scratch_areas; =20 + kmemleak_no_scan_phys(addr); kho_scratch[i].addr =3D addr; kho_scratch[i].size =3D size; i++; @@ -676,6 +679,7 @@ static void __init kho_reserve_scratch(void) if (!addr) goto err_free_scratch_areas; =20 + kmemleak_no_scan_phys(addr); kho_scratch[i].addr =3D addr; kho_scratch[i].size =3D size; i++; --=20 2.25.1