From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 19DBD363C7B for ; Thu, 20 Nov 2025 16:17:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763655452; cv=none; b=i9K4ayu4+5UvJYLgdqTtLnheVvN5Sdwp8BbTIXYRUC2p/Uec3RZeHJIhXJbRHo8fe+HQRMoU4KtRNopqM8qtnC2EY15decJX8DfUEXjgACP9QgxHYwKIhgmm0sKO3f2lWPJqzADHq6tuwmFOxTMq9iKPq/g2GhbX9ZvM/GLNbDw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763655452; c=relaxed/simple; bh=NxStlN0sykH1gh6u/oPgxyBdh3fqUB6K49dDrBU3dDY=; h=From:To:Cc:Subject:In-Reply-To:References:Date:Message-ID: MIME-Version:Content-Type; b=nIqK0iOuaaTAHXtFVXx4bcERNyq2jZPnDLOxxgRTdiwAsVZaUG1rZeedn6cp6fy0i+SMwEjAmgBLeU6xeE22Iiz2TUea/w5FMmcXh84uTOHGJz8r/zp7BNiVsdKJxZ2dj1TYSMPkjAuevghLZziLiLsobCf58wxAWW0c90AZH0g= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=aeotwaVP; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="aeotwaVP" Received: by smtp.kernel.org (Postfix) with ESMTPSA id ED8D9C116D0; Thu, 20 Nov 2025 16:17:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1763655451; bh=NxStlN0sykH1gh6u/oPgxyBdh3fqUB6K49dDrBU3dDY=; h=From:To:Cc:Subject:In-Reply-To:References:Date:From; b=aeotwaVP/quTK59YtQvEIkiP8/BGxEN9pfdawUrjnS7OkA05j2AJyR4Ra/g5VQSv5 UehQfPQbBNvFe4Nk6zt/Ny7nUGJFLrYk4ZX6FD1zR6Zxhu19BmdG1h5WDGqRP/I7E/ Kghk8ZEdsMQTqZUDbFhym+ftH4FtEVQvoikKhr5Or2WcufcL4kauCfQlf6O6onaBy5 gYpZP/5gEiXN/o59nqfT22nZgjQpRiIWLiNnmmcj4ufXfZdlv7nQ/FeTSTj8eV26Sb a32axiyrfZPbjLgueRCrAjQWV+iKHqBW0YXxyqvt/8f684TLg3o9rWW7gbQKL9PgZ+ To+wTcRhvXj5g== From: Pratyush Yadav To: ranxiaokai627@163.com Cc: catalin.marinas@arm.com, akpm@linux-foundation.org, graf@amazon.com, rppt@kernel.org, pasha.tatashin@soleen.com, pratyush@kernel.org, changyuanl@google.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org, kexec@lists.infradead.org, ran.xiaokai@zte.com.cn Subject: Re: [PATCH 2/2] liveupdate: Fix boot failure due to kmemleak access to unmapped pages In-Reply-To: <20251120144147.90508-3-ranxiaokai627@163.com> (ranxiaokai's message of "Thu, 20 Nov 2025 14:41:47 +0000") References: <20251120144147.90508-1-ranxiaokai627@163.com> <20251120144147.90508-3-ranxiaokai627@163.com> Date: Thu, 20 Nov 2025 17:17:28 +0100 Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain On Thu, Nov 20 2025, ranxiaokai627@163.com wrote: > From: Ran Xiaokai > > When booting with debug_pagealloc=on while having: > CONFIG_KEXEC_HANDOVER_ENABLE_DEFAULT=y > CONFIG_DEBUG_KMEMLEAK_DEFAULT_OFF=n > 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. I don't know how kmemleak works. Why does kmemleak access the unmapped pages? If pages are not mapped, it should learn to not access them, right? > > Call kmemleak_no_scan_phys() from kho_reserve_scratch() to > exclude the reserved region from scanning before > it is released to the buddy allocator. kho_reserve_scratch() is called on the first boot. It allocates the scratch areas for subsequent boots. On every KHO boot after this, kho_reserve_scratch() is not called and kho_release_scratch() is called instead since the scratch areas already exist from previous boot. Eventually both paths converge to kho_init() and call init_cma_reserved_pageblock(). So shouldn't you call kmemleak_no_scan_phys() from kho_init() instead? This would reduce code duplication and cover both paths. > > 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_handover.c > index 224bdf5becb6..dd4942d1d76c 100644 > --- a/kernel/liveupdate/kexec_handover.c > +++ b/kernel/liveupdate/kexec_handover.c > @@ -11,6 +11,7 @@ > > #include > #include > +#include > #include > #include > #include > @@ -654,6 +655,7 @@ static void __init kho_reserve_scratch(void) > if (!addr) > goto err_free_scratch_desc; > > + kmemleak_no_scan_phys(addr); > kho_scratch[i].addr = addr; > kho_scratch[i].size = size; > i++; > @@ -664,6 +666,7 @@ static void __init kho_reserve_scratch(void) > if (!addr) > goto err_free_scratch_areas; > > + kmemleak_no_scan_phys(addr); > kho_scratch[i].addr = addr; > kho_scratch[i].size = size; > i++; > @@ -676,6 +679,7 @@ static void __init kho_reserve_scratch(void) > if (!addr) > goto err_free_scratch_areas; > > + kmemleak_no_scan_phys(addr); > kho_scratch[i].addr = addr; > kho_scratch[i].size = size; > i++; -- Regards, Pratyush Yadav