From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id F2369C43458 for ; Thu, 9 Jul 2026 17:38:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=aaLZ4qQHTWCpyDQ2KoikzM0c17LkOMu3nd+8SI8LJ7w=; b=rgLwdBtOmPSBT0n5UueIlLQk1Z dHeoFh2M2MaiqlZWHMgYN3ntt6s26KfMGZgvFOjAvMm+p+UU4TbWkug5MSLbRbB+B1expFrJkOd4B SQKRhQVI09FR2MIAu1ly/dQvRdaJIOVvaQbxsSHyWFLa0QeDWgHksYj+0tiQ51oWTq7VT17L3FAgu xVjldzXgeeLWBXoqgao7j/rS0M7ZD56IAPcDOQ49vB3k4ryiCGjhWzfiWJqgfVbVmfgldRSKaBQG9 djLcKUcWLlalsL5Mi0lAzLWSISC94y6ORxfC5KYIGBdv9xuPDyM/Dizr8pM4ial/e2PWU14U+G5d1 8GP2F+cw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.99.1 #2 (Red Hat Linux)) id 1whsi2-0000000386s-06zi; Thu, 09 Jul 2026 17:38:50 +0000 Received: from tor.source.kernel.org ([172.105.4.254]) by bombadil.infradead.org with esmtps (Exim 4.99.1 #2 (Red Hat Linux)) id 1whsi0-0000000385f-2A7h for kexec@lists.infradead.org; Thu, 09 Jul 2026 17:38:48 +0000 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by tor.source.kernel.org (Postfix) with ESMTP id F15DE6138D; Thu, 9 Jul 2026 17:38:47 +0000 (UTC) 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> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: kexec@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "kexec" Errors-To: kexec-bounces+kexec=archiver.kernel.org@lists.infradead.org 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