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 784DC3A960A for ; Sat, 25 Jul 2026 17:22:01 +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=1785000122; cv=none; b=KFwL34wCTdIFvMfaLu99a13fQwtTZAdNMPZbHgpDv+eoeHE62QVZ5qRrRdAZvJv1KpaJST/PB3RGJyPZsLdqn/ajOgBeKYVhleghv0H9qpt1XUaWZ1XXzV8vy5Q+3VbEyO9l8HBdL2q5j5LHGRXGD4bjbnIXwZxF6tfUAnKkUE0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785000122; c=relaxed/simple; bh=YkfTTpEWWFekTxFxxka2tNXXzqfmTM2npTKpnC1vztE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=pr7GtM0t6AQWir2kh+kf3mmEeWf2UzV1VyvfvKipcvuhcNH24QwY83pcSoMJV4eK1CWY/604vjFjPyeefo70CGtqL0vQumVB0qxCLqT4l6xX22u8xdcjtsuZ0yF4SdE/jbsO1tde8+L7n7iipFHj5mO7dJOC1duxM+8IE3CkblU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=JW2WQPUH; 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="JW2WQPUH" Received: by smtp.kernel.org (Postfix) with ESMTPSA id E893F1F00A3E; Sat, 25 Jul 2026 17:21:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1785000121; bh=MiZwROqV6W7eFtc2tbetOC+Vk2IDYu0WCKkwIdfUuFU=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=JW2WQPUHtTN4/4mKaKNJvigwz60iQPO3wM4+2u8D6piNH+j/z7R63JvijCcR9KRrK 8u2lUUwUcHq57p9ruG19nUAia4BRE+btAJIEFe5NWUBV4H9OGX86Kgs38y4l+w2h6g UqCHJQSAk3JvCgVWleKmPQGCSN3T38uXprcGhR3arnjCQqMr57J0MmnYCEnrrlg0kg JAF677oubw7A0U8+QkXieraGd15ReXneNZhsf1unYExNyO1bhheqcMJ6zTXMT9uiMR lS4cVSgGQ3gHCvkWNz7K5Szf8kvKnKjolT2qp5IB2Lp/9tm/1L4dmMdZxgNISgXlwM Mfx9M46xLEOTw== 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 06/21] kho: move all memory retrieval logic to kho_mem_retrieve() Date: Sat, 25 Jul 2026 19:21:06 +0200 Message-ID: <20260725172133.4018491-7-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)" The memory retrieval logic is spread out across kho_mem_retrieve() and kho_memory_init(). The incoming scratch area is initialized at kho_memory_init(), and the error handling is done there too. Consolidate all this logic into kho_mem_retrieve() to make the code cleaner. Signed-off-by: Pratyush Yadav (Google) --- kernel/liveupdate/kexec_handover.c | 31 ++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/kernel/liveupdate/kexec_handover.c b/kernel/liveupdate/kexec_handover.c index b53ae68ca087..e3408e1844dc 100644 --- a/kernel/liveupdate/kexec_handover.c +++ b/kernel/liveupdate/kexec_handover.c @@ -1415,8 +1415,13 @@ int kho_retrieve_subtree(const char *name, phys_addr_t *phys, size_t *size) } EXPORT_SYMBOL_GPL(kho_retrieve_subtree); -static int __init kho_mem_retrieve(const void *fdt) +static void __init kho_mem_retrieve(void) { + const void *fdt = kho_get_fdt(); + int err; + + 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.scratch_phys, which stops memory @@ -1424,8 +1429,16 @@ static int __init kho_mem_retrieve(const void *fdt) */ kho_in.radix_tree.root = kho_get_mem_map(fdt); mutex_init(&kho_in.radix_tree.lock); - return kho_radix_walk_tree(&kho_in.radix_tree, - kho_preserved_memory_reserve); + + err = kho_radix_walk_tree(&kho_in.radix_tree, kho_preserved_memory_reserve); + if (err) { + /* + * Failed to initialize preserved memory. Clear FDT and radix + * so KHO users don't treat it as a KHO boot. + */ + kho_in.fdt_phys = 0; + kho_in.radix_tree.root = NULL; + } } static __init int kho_out_fdt_setup(void) @@ -1629,16 +1642,10 @@ fs_initcall(kho_init); void __init kho_memory_init(void) { - if (kho_in.scratch_phys) { - kho_scratch = phys_to_virt(kho_in.scratch_phys); - - if (kho_mem_retrieve(kho_get_fdt())) { - kho_in.fdt_phys = 0; - kho_in.radix_tree.root = NULL; - } - } else { + if (kho_in.scratch_phys) + kho_mem_retrieve(); + else kho_reserve_scratch(); - } } void __init kho_populate(phys_addr_t fdt_phys, u64 fdt_len, -- 2.55.0.229.g6434b31f56-goog