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 C7318C54F51 for ; Wed, 29 Jul 2026 14:57:03 +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=aKqc31TeZXFcHalUwtLT8t9WbNac7HeKnH2JgkerxJM=; b=wH5niTs+KkB5va4ypk+AidoGkN 5EKFHLXQCJHKWOICzysgJGBjzg4wumDoZcR98WFygkd8qnQXkjQNdSFIPF3E5I0fyW6uY3BqsTICY lAyK32vcVx52BqXD9QAczBuc9ROLVHSy74ZUMZUAj5RNwWV5QKrH4D5T9nOpADVNgBVT3sdLttZfr FRGlWm5WDTj6xzXAj0EKL68yXZb/rWsEnSu0HxZ4qwFRCUJg/PeGY5XuDsqNJ8qzBawiO/opVKbPK LM30Fzl3gSb/D6tgo4soc0mOTOI92HKSsDruj5rKSmxkUkWKYdT1aAfQc1g8RQf36tbiDz8GVF+dd y6XeXMoA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.99.1 #2 (Red Hat Linux)) id 1wp5iQ-00000008JNx-3V17; Wed, 29 Jul 2026 14:57:02 +0000 Received: from tor.source.kernel.org ([2600:3c04:e001:324:0:1991:8:25]) by bombadil.infradead.org with esmtps (Exim 4.99.1 #2 (Red Hat Linux)) id 1wp5iQ-00000008JMy-08bt for kexec@lists.infradead.org; Wed, 29 Jul 2026 14:57:02 +0000 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by tor.source.kernel.org (Postfix) with ESMTP id 751C560A72; Wed, 29 Jul 2026 14:57:01 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 004F31F000E9; Wed, 29 Jul 2026 14:56:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1785337021; bh=aKqc31TeZXFcHalUwtLT8t9WbNac7HeKnH2JgkerxJM=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=juQFDwcOSX/yMI2cIAoSl3nUUm1pmJ1ja+LUjuPw5tlGZaNZVtTqBKqRVOs3KodTl hMtQ69g6p6eJAxUi1KXWlYfz2KXCAhaDIwItbQAHmXda/w50XRhu9TaKDWUNehnno4 UUyeEGsf3sgT4mePV8gRDdoJ+EPaI+HbN2esnx2hcITv+Xa0YNw0hFRy7ezDZ0/4AL QYGk6j4Q5xkiqhTDCO6Qdk6jjlm77p80167CL1fabpW4aBOzNn0kLuZyEGzsntphsZ Fs2Q5zZDwnRJsipCAPbpLghO3BswhKKMIWK3GHPU6trV03b1NyFrnVuPIF2QmfBcYO orcHcE6jBh5ZA== 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 15/22] kho: initialize preserved memory map radix tree earlier Date: Wed, 29 Jul 2026 16:56:00 +0200 Message-ID: <20260729145610.2827231-16-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> 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)" Currently the preserved memory radix tree is initialized from kho_memory_init(), which happens relatively late in MM init. In a coming patch, the tree will be used from kho_memory_init_early(). Move the tree initialization there. Simplify some of the code in kho_mem_retrieve() by getting rid of the err variable and jumping to err directly. Signed-off-by: Pratyush Yadav (Google) --- kernel/liveupdate/kexec_handover.c | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/kernel/liveupdate/kexec_handover.c b/kernel/liveupdate/kexec_handover.c index 2ddfc804cdf7..6e8682469bd7 100644 --- a/kernel/liveupdate/kexec_handover.c +++ b/kernel/liveupdate/kexec_handover.c @@ -1531,20 +1531,8 @@ static void __init kho_mem_retrieve(void) const struct kho_radix_walk_cb cb = { .leaf = kho_preserved_memory_reserve, }; - const void *fdt = kho_get_fdt(); - int err; - /* - * kho_get_mem_map() should always succeed. If it fails, kho_populate() - * catches that and never sets kho_in.scratch_phys, which stops memory - * retrieval. - */ - err = kho_radix_init_tree(&kho_in.radix_tree, kho_get_mem_map(fdt)); - if (err) - goto err; - - err = kho_radix_walk_tree(&kho_in.radix_tree, &cb, NULL); - if (err) + if (kho_radix_walk_tree(&kho_in.radix_tree, &cb, NULL)) goto err; return; @@ -1756,6 +1744,8 @@ fs_initcall(kho_init); void __init kho_memory_init_early(void) { + const void *fdt = kho_get_fdt(); + if (!is_kho_boot()) return; @@ -1765,6 +1755,20 @@ void __init kho_memory_init_early(void) * early. */ 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.fdt_phys. + */ + if (kho_radix_init_tree(&kho_in.radix_tree, kho_get_mem_map(fdt))) { + /* + * Failed to initialize preserved memory radix tree. Clear FDT + * and scratch so KHO users don't treat it as a KHO boot. + */ + kho_in.fdt_phys = 0; + kho_in.scratch_phys = 0; + return; + } } void __init kho_memory_init(void) -- 2.55.0.508.g3f0d502094-goog