From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (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 3666B3F6600 for ; Sat, 25 Jul 2026 17:22:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785000145; cv=none; b=sI64T4/bk1EEfOsSwZ2x3PC1oZg78W5LjizlWrna+nzrDEU40ChF3/XeiCUb5aWSBT7z/yC3dnsrENSyMeUZS8v4tiQrWtG088gJFIDnDEEV9w/BLfmyrDncS3h0nZ0oTSlxbiILG28Eho/P1LlqV75MU3J2+V2MKulAe3FlNys= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785000145; c=relaxed/simple; bh=ZYsRZat2T9K4otL5yXwRXXJ3PJUuNKG+T6skkLPKai0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=icoFTx9V5rsiOH2Rh7XKOlbmcmhAEwuNmJ7XHOstDIdiBDnTPzp8B6H8jkBcBGgUdSatjL/A9E4U0kGJt+xMJFCGg6do4u/OAn2m7lGVEAEAr2i1NbI5YtgeSIJP+fkHT3kRikRySSAS6jfbV02G5ERDWra7W+1gFfYPbAey6dg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=UiEmer6R; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="UiEmer6R" Received: by smtp.kernel.org (Postfix) with ESMTPSA id E9F181F00A3D; Sat, 25 Jul 2026 17:22:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1785000144; bh=cOry/3C0sQhuR8WsrEskkRmuT+9DYZ7XJJRg9834/9M=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=UiEmer6RtN5mLEUIGrwc4ZfCLTDOZ79dzuOz6xzhhJJSGQwMqikjSL+3Ni4FRm9Pl C8NcpvbgvW/ECnjNuFukH4ZAntOQ5zgEDQAnn9oRH/g1GtIKciEWmY5MdjJqpRaUT0 nQyo0O5SB/WiGwuy1LrQB9K0Gkf4FGl8lw3v55fLx1ZMu0gWnKvaPLBD2pTVMIt5OO 8C6akxCpcaDnjv2kJlYNdrmcB6QZvVJGr1buM3ju+qhWPvaGprTnnHz6isLnte5vLJ 2iQPtVADoBN+2fkW0CJ59aaRQ/ObpEPbVbVdXZii+j3Gf+pCJlVKumspDnDJdyWGOz YxeLazd+mzMnw== From: Pratyush Yadav To: Mike Rapoport , Pasha Tatashin , Pratyush Yadav , Alexander Graf , Muchun Song , Oscar Salvador , David Hildenbrand , Andrew Morton , Jason Miu , Jork Loeser Cc: kexec@lists.infradead.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH v4 15/21] kho: initialize preserved memory map radix tree earlier Date: Sat, 25 Jul 2026 19:21:15 +0200 Message-ID: <20260725172133.4018491-16-pratyush@kernel.org> X-Mailer: git-send-email 2.55.0.229.g6434b31f56-goog In-Reply-To: <20260725172133.4018491-1-pratyush@kernel.org> References: <20260725172133.4018491-1-pratyush@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: "Pratyush Yadav (Google)" Currently the preserved memory radix tree is initialized from kho_memory_init(), which happens relatively late in MM init. In a coming patch, the tree will be used from kho_memory_init_early(). Move the tree initialization there. Simplify some of the code in kho_mem_retrieve() by getting rid of the err variable and jumping to err directly. Signed-off-by: Pratyush Yadav (Google) --- kernel/liveupdate/kexec_handover.c | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/kernel/liveupdate/kexec_handover.c b/kernel/liveupdate/kexec_handover.c index 2ddfc804cdf7..6e8682469bd7 100644 --- a/kernel/liveupdate/kexec_handover.c +++ b/kernel/liveupdate/kexec_handover.c @@ -1531,20 +1531,8 @@ static void __init kho_mem_retrieve(void) const struct kho_radix_walk_cb cb = { .leaf = kho_preserved_memory_reserve, }; - const void *fdt = kho_get_fdt(); - int err; - /* - * kho_get_mem_map() should always succeed. If it fails, kho_populate() - * catches that and never sets kho_in.scratch_phys, which stops memory - * retrieval. - */ - err = kho_radix_init_tree(&kho_in.radix_tree, kho_get_mem_map(fdt)); - if (err) - goto err; - - err = kho_radix_walk_tree(&kho_in.radix_tree, &cb, NULL); - if (err) + if (kho_radix_walk_tree(&kho_in.radix_tree, &cb, NULL)) goto err; return; @@ -1756,6 +1744,8 @@ fs_initcall(kho_init); void __init kho_memory_init_early(void) { + const void *fdt = kho_get_fdt(); + if (!is_kho_boot()) return; @@ -1765,6 +1755,20 @@ void __init kho_memory_init_early(void) * early. */ kho_scratch = phys_to_virt(kho_in.scratch_phys); + + /* + * kho_get_mem_map() should always succeed. If it fails, kho_populate() + * catches that and never sets kho_in.fdt_phys. + */ + if (kho_radix_init_tree(&kho_in.radix_tree, kho_get_mem_map(fdt))) { + /* + * Failed to initialize preserved memory radix tree. Clear FDT + * and scratch so KHO users don't treat it as a KHO boot. + */ + kho_in.fdt_phys = 0; + kho_in.scratch_phys = 0; + return; + } } void __init kho_memory_init(void) -- 2.55.0.229.g6434b31f56-goog