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 D76263E3DA2 for ; Fri, 5 Jun 2026 18:35: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=1780684527; cv=none; b=OiWs+kFR1C27BjN69Lc6+PqcbIk5LAbvdIogO6gCqULdbmzBDXiQrXG+Ht11IzUx+/RGkC7eU99LCcIm9/uIJ6LJuYoZKMpdKWgPEjL7UVEok2RM28kp405AooKCVcrO5eOVXo/hmgaFlesWHe2T/ZSSSQ5TVyHCz1F8IrV+sVk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780684527; c=relaxed/simple; bh=Vnz++hGyFXtvQzIid6rIMpI4W5uPiUspW+qvtBe/yrM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=L13Vim+bQMFzO1EplXxs5mVgy1pMBb9ZWqI2ouMZ9h3cnASSTvxUt8LMX5FKKUIzr1k4RswpIW8Ky7OCICGCxgy93GB45XaDbA36Ct/8eE6i2k2gugsZeBla7DZOdMjPBQDR65orcfbnKMnsCgaxvX07wrK6S2ZaToJ+5wjKf8I= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=gmowAtOv; 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="gmowAtOv" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9F7341F00898; Fri, 5 Jun 2026 18:35:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1780684524; bh=alS6uT4DTp+WwL7sso5ivBySgAZ17Nint0mun5DyoD4=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=gmowAtOvxTzKu9ncHNPpRCnzGA8aVRacUBa9izDlXmH8W4c2eEeVmTQbE3rGtjedw 9ua31Na8GiOZ1dansxYyc4ww00X4kERyhigsjMj//6tPpR1dT8ta5FAYuC9rLTEbY6 clH238G1imQE2lF4pz4yqmu2Olzn6gfL3cS4YKiSBIBQxOkulAuY7RUm42r8PIKhIl AWQ4DPyn4eD0GIIoepvbCSkRashG4zd8VlKWBU/q5j/RtQ430n6KVgFAiCgEclekwd +GSPWHJEw/TboqaF5GTuSVNhantMko73vA//MVGrF5uImhBihA8fQztwHqDoFvqgWB zbxK+H2/vhaqQ== 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 v2 05/18] kho: move all memory retrieval logic to kho_mem_retrieve() Date: Fri, 5 Jun 2026 20:34:38 +0200 Message-ID: <20260605183501.3884950-6-pratyush@kernel.org> X-Mailer: git-send-email 2.54.0.1032.g2f8565e1d1-goog In-Reply-To: <20260605183501.3884950-1-pratyush@kernel.org> References: <20260605183501.3884950-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 61e436f5077e..7e556afae283 100644 --- a/kernel/liveupdate/kexec_handover.c +++ b/kernel/liveupdate/kexec_handover.c @@ -1412,8 +1412,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 @@ -1421,8 +1426,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) @@ -1626,16 +1639,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.54.0.1032.g2f8565e1d1-goog