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 DFF8D4DB57E for ; Thu, 9 Jul 2026 17:38:47 +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=1783618729; cv=none; b=j6sWU78ZBzBatnxMVy+65Jr7WPrqFq7i0GXR3v26+kgTgzp0/Pb/7lsX/9ZaeexjggMYWQxgqII9FaHKywMTViJVgwrLfQvah5GkGXYDyri+9uuKVMyfAuMx4h+kj/IU/tDmPIoZHwWPOkbkxFTkr0S14jr4ZBdHGAL6kP1PMHE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783618729; c=relaxed/simple; bh=UpLVi/ur1vL+rNCTKoopjJ7HXue+yyNzs7PF4uU3Z1s=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=PDEZ92SdKPkLfdDvq9TPl4NdhA4QqcxKgi9Z+mdCTOESGJMiO9H6hFLhdBeTFxqvCJNTQqrez4x0RPLiq5MJjeeupBtZMNLkCv02Yn4IlkBFeA5jbj4YCehmX9k5MvRE4KJl5NAaMWaLSBSkYm9yHgJ68Ny3IITA9Um48i9J+Jg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Q9MAZYgq; 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="Q9MAZYgq" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 84BB31F000E9; Thu, 9 Jul 2026 17:38:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1783618727; bh=aaLZ4qQHTWCpyDQ2KoikzM0c17LkOMu3nd+8SI8LJ7w=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=Q9MAZYgqd/AF604CZnJbZbLaFer6tRk0e5tGoqdHjCLaSAysygltdttOz7CHzvkP7 SZ0FJBKUmsa9vNn7xkkeR1Tn5w9OGZ1zmvNG7qMHgkEXhLzzO2tsFhKmDU2ce441h4 0flKgGKNWdUhW7xc62VFWrdhOjJUMfhI1LWOGn9/zH6oKISWTCOdpw3/0HWv083Alk QGq6kff+bWafVI8aQ+3Kgnj9xtWnEJ1kkwQH2AWrsMU/Pon/DPQ/RMSo0LXYuuehjK dPzye3KrTsbLWbjqIG1THpLI8L0C47Wk4IhMn+mYmG51aYunAJe8gbVR9tv/ritmVP d1ePOupxhseqg== 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 v3 06/21] kho: move all memory retrieval logic to kho_mem_retrieve() Date: Thu, 9 Jul 2026 19:37:55 +0200 Message-ID: <20260709173821.429921-7-pratyush@kernel.org> X-Mailer: git-send-email 2.55.0.141.g00534a21ce-goog In-Reply-To: <20260709173821.429921-1-pratyush@kernel.org> References: <20260709173821.429921-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.141.g00534a21ce-goog