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 48F084D8DBD for ; Wed, 29 Jul 2026 14:56:38 +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=1785336999; cv=none; b=tRM//+PX5aWx8P7zACvcMmTxXT0ge0I4WnuXKg+rGgtniikEA75o2fTunqin4Hhs9S8m78tjP5VoejBHU9ct0Cq68LdntEgEXfXo6DIWnvi5kTPD9m626qLXRMBIzT1ZHP9txVIvOEChvcLM48apLHsmts3F7iGfAaWBjZUbIUc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785336999; c=relaxed/simple; bh=5qPPVWddtQxPKitcsHJEBQ0N9HROuSjaHXna/RlUxwY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=S66Gi6tjLDhWk+lHWYqHkJfEIfaT87MzLVQ+UR/O8UkQxU3dEhR8aFIyVRsX9Vnwm7lblKusB9QnbbDDE6Idl2VbK5iARcFZqZiK67QD7bXJD5dxK1Bb9hT03PTRW73iNXT1lx2tWUk9a7h0zWxOT1OCj1b+08E3FhgoXtKKvsU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=eZiJysUw; 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="eZiJysUw" Received: by smtp.kernel.org (Postfix) with ESMTPSA id E81211F00A3A; Wed, 29 Jul 2026 14:56:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1785336998; bh=0oSBVDvJVhrS8ulDeZlNQQxyRW9eRLFb9CyP3FfzZyU=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=eZiJysUwogklnynCVt8wR3BtC2dUOduHvdoCdY/cT5ZxzeTR7BuquI//AGnwADH7E J8xoxKzIIS59SVEZEM8D3h2XruK+PFkxeGkBv8o9ktM8teqWncAMoWjMdB32pUbTWk 1wSkDW4wqYWxlb+ASQsM67wDaUK3FWNcj8mmS7XYc2xmUpEGQrTD0vcaD4r1jj3NAj f8Pz+Y2QrQujD0BQiiKeUTdzPbqG7Y/DU8+d+mBFU3c8qFFNVA4zmWPTJa7GOz4R42 YRV8lDVodKYhSctsXEd1VVDFl3q46+bFqCjZxP3OkUT7a0w+AKgSkT2r/sHtSdB5yS U7yyXXY+hlJmQ== 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 v5 06/22] kho: move all memory retrieval logic to kho_mem_retrieve() Date: Wed, 29 Jul 2026 16:55:51 +0200 Message-ID: <20260729145610.2827231-7-pratyush@kernel.org> X-Mailer: git-send-email 2.55.0.508.g3f0d502094-goog In-Reply-To: <20260729145610.2827231-1-pratyush@kernel.org> References: <20260729145610.2827231-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.508.g3f0d502094-goog