From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 2FB8C3FF891 for ; Wed, 29 Apr 2026 13:40:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777470004; cv=none; b=CwZL3W9QhX5JyZXHSegPbDBSavI4j0N2PpldwEmb5/ckalWy6/SI4wKTG2uSj/h2SvGhNtpalD00jhGQtkL0YpdiMRo9BE1K69gZdZxH7CT7lPYYfQlML11HSRPJsm1dhNN7gDTdzTcfVO5MlhOH3KQgKUL1PM95hgairdLmq6Q= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777470004; c=relaxed/simple; bh=7g0JJiONXBOw45AyCeb07Wo1XFWVqN+yfQgV92Bji6Y=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=B9gDAk/W0cULW7JMumq4MIetQ+1fmzd4yiaTsq+iuePxWO9o3Z1jwXuPtWxQBqk94U4seV1R3kot8S31AdJHV66qUJQAO5imcW/ngOvF2qp7ShUFlfZ+/PSugWJNJ9JHNti5dVqxcOtu7NDt9Oq0EfKg1BA2a/97792tUtSS/R0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=CVvITovv; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="CVvITovv" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1E45BC2BCB8; Wed, 29 Apr 2026 13:40:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1777470003; bh=7g0JJiONXBOw45AyCeb07Wo1XFWVqN+yfQgV92Bji6Y=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CVvITovv0rPTsRIckne33fhWAqIvJ6CkT/vfyng+WOTzPKF2ue9p2YU9OD2nkxcFG fth0V8NRUAtRGk8QRFXdp6fCF0L7vLSEBo0jOV3YoKh8HmxQfbxUNlrg1qmzWSRMat 4T6MZ03v7IWk6RQx8JLhpmMqvHA8ch14S6AuBok4JO/g0NKI3CacRHxV8AqZwp+160 mcyN3E3n4S4kbrcwE9RDz+/Mv0Ia/q2QMomCmePKcGpUTX6omL55T356NyAODrmIry yVR+XcutobkssLARvkmMLlnPWEU7gDkM7fR6AqyiRkvGmHrGhyVX11rqttaKEc6k4Z a07k8GPJUfwjQ== From: Pratyush Yadav To: Mike Rapoport , Pasha Tatashin , Pratyush Yadav , Alexander Graf , Muchun Song , Oscar Salvador , David Hildenbrand , Andrew Morton , Jason Miu Cc: kexec@lists.infradead.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH 08/12] kho: add kho_radix_init_tree() Date: Wed, 29 Apr 2026 15:39:10 +0200 Message-ID: <20260429133928.850721-9-pratyush@kernel.org> X-Mailer: git-send-email 2.54.0.545.g6539524ca2-goog In-Reply-To: <20260429133928.850721-1-pratyush@kernel.org> References: <20260429133928.850721-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)" Move the initialization logic of the radix tree into kho_radix_init_tree() instead of having users open-code it. Makes the boundaries cleaner and reduces code duplication when a new user of the radix tree will be added in a future commit. Signed-off-by: Pratyush Yadav (Google) --- include/linux/kho_radix_tree.h | 7 ++++++ kernel/liveupdate/kexec_handover.c | 37 ++++++++++++++++++++++++++++-- 2 files changed, 42 insertions(+), 2 deletions(-) diff --git a/include/linux/kho_radix_tree.h b/include/linux/kho_radix_tree.h index 617395a6647a..c0840ecb230c 100644 --- a/include/linux/kho_radix_tree.h +++ b/include/linux/kho_radix_tree.h @@ -54,6 +54,7 @@ int kho_radix_add_key(struct kho_radix_tree *tree, unsigned long key); void kho_radix_del_key(struct kho_radix_tree *tree, unsigned long key); int kho_radix_walk_tree(struct kho_radix_tree *tree, const struct kho_radix_walk_cb *cb, void *data); +int kho_radix_init_tree(struct kho_radix_tree *tree, struct kho_radix_node *root); void kho_radix_destroy_tree(struct kho_radix_tree *tree); #else /* #ifdef CONFIG_KEXEC_HANDOVER */ @@ -72,6 +73,12 @@ static inline int kho_radix_walk_tree(struct kho_radix_tree *tree, return -EOPNOTSUPP; } +static inline int kho_radix_init_tree(struct kho_radix_tree *tree, + struct kho_radix_node *root) +{ + return 0; +} + static inline void kho_radix_destroy_tree(struct kho_radix_tree *tree) { } #endif /* #ifdef CONFIG_KEXEC_HANDOVER */ diff --git a/kernel/liveupdate/kexec_handover.c b/kernel/liveupdate/kexec_handover.c index 29479534f65d..1a04e089f779 100644 --- a/kernel/liveupdate/kexec_handover.c +++ b/kernel/liveupdate/kexec_handover.c @@ -305,6 +305,34 @@ static void __kho_radix_destroy_tree(struct kho_radix_node *root, kho_radix_free_node(root); } +/** + * kho_radix_init_tree - initialize the radix tree. + * @tree: the tree to initialize. + * @root: root table of the radix tree. + * + * Initialize the radix tree with the given root node. If root is %NULL, an + * empty root table is allocated. If root is not %NULL, it is the caller's + * responsibility to make sure the root is valid and in the correct format. + * + * Return: 0 on success, -errno on failure. + */ +int kho_radix_init_tree(struct kho_radix_tree *tree, struct kho_radix_node *root) +{ + /* Already initialized. */ + if (tree->root) + return 0; + + if (!root) + root = kho_radix_alloc_node(); + if (!root) + return -ENOMEM; + + tree->root = root; + mutex_init(&tree->lock); + return 0; +} +EXPORT_SYMBOL_GPL(kho_radix_init_tree); + /** * kho_radix_destroy_tree - Destroy the radix tree * @tree: The radix tree to destroy @@ -1445,9 +1473,14 @@ static int __init kho_mem_retrieve(const void *fdt) const struct kho_radix_walk_cb cb = { .key = kho_preserved_memory_reserve, }; + phys_addr_t mem_map_phys; + int err; + + mem_map_phys = kho_get_mem_map_phys(fdt); + err = kho_radix_init_tree(&kho_in.radix_tree, phys_to_virt(mem_map_phys)); + if (err) + return err; - kho_in.radix_tree.root = phys_to_virt(kho_get_mem_map_phys(fdt)); - mutex_init(&kho_in.radix_tree.lock); return kho_radix_walk_tree(&kho_in.radix_tree, &cb, NULL); } -- 2.54.0.545.g6539524ca2-goog