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 957563B0AD1 for ; Wed, 29 Apr 2026 13:40:01 +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=1777470001; cv=none; b=MdnRerkrMBe4H6cNLo8EcLudc/e9QWQLSS9BPeSr80HcXbTXp8QHkQhLYS/mKBFnyycFNTSjAlCzCq3GKZUBJXVn1424MorRr4oj2ej5kqrqcFu+LhtkqbuhMkd/pQn3/4zuZWO6Z4CuhpsidE/pqoIzbnNcEDP0CzXxyvDOLjs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777470001; c=relaxed/simple; bh=HqMJ+mPvIVL4QAOFwn1zIYXnpFxqWfIvpXCdlh2p4qU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Y6/EOpJU71amOkNVnIL+FdkZUo+eEioJsgG/IjWxqMMzKw025S8oKBvXdWAZTiXAnlZIz4ZBhUD8J6fyjjrNaD8yi/6WJnPCfmmxNLuXawv2nLopqb8sdL3fWRI65Ba0bZa9kGmCUAsbHdeuqyukXmy15moJjOn0/t8JT8PYi4Q= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Ibdizt7x; 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="Ibdizt7x" Received: by smtp.kernel.org (Postfix) with ESMTPSA id CC26DC4AF0C; Wed, 29 Apr 2026 13:39:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1777470000; bh=HqMJ+mPvIVL4QAOFwn1zIYXnpFxqWfIvpXCdlh2p4qU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Ibdizt7xQYLkjEzH1nGZoM2Q2T4NkpbCLjWvPZ9hNm2X5NsnDPnvpqQBJjTlbT9dL QBe3QjWdKeP2QZTXoyeSAOChz4Ll1VBJkR2KJGURRTLWFjh52CBL46EvTTfoo/5JjE HVRm5PcCxAWD8IelTrmisEN0L6+GjArxEV+FojzkVcdhW2/ufSpz/qsQmv+nFjnIrV IbjcQXh8OhwLfVogeo1Tee4Iq9+WrlFVqFmMgxk+MJrbM1qNrRkLNTUtC8+WK+zFbV ToH5+gctoY9A9KQcAadyk685ODGF7asEt9cK90AvI82wN7ScbyPoPxYTScE9/q41TQ SoUy5n+oPnK6A== 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 07/12] kho: allow destroying KHO radix tree Date: Wed, 29 Apr 2026 15:39:09 +0200 Message-ID: <20260429133928.850721-8-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)" Add kho_radix_destroy_tree() which allows destroying the radix tree and freeing all its pages. Signed-off-by: Pratyush Yadav (Google) --- include/linux/kho_radix_tree.h | 3 +++ kernel/liveupdate/kexec_handover.c | 34 ++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/include/linux/kho_radix_tree.h b/include/linux/kho_radix_tree.h index 6c0f7d82716b..617395a6647a 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); +void kho_radix_destroy_tree(struct kho_radix_tree *tree); #else /* #ifdef CONFIG_KEXEC_HANDOVER */ @@ -71,6 +72,8 @@ static inline int kho_radix_walk_tree(struct kho_radix_tree *tree, return -EOPNOTSUPP; } +static inline void kho_radix_destroy_tree(struct kho_radix_tree *tree) { } + #endif /* #ifdef CONFIG_KEXEC_HANDOVER */ #endif /* _LINUX_KHO_RADIX_TREE_H */ diff --git a/kernel/liveupdate/kexec_handover.c b/kernel/liveupdate/kexec_handover.c index 47f7c4a2865e..29479534f65d 100644 --- a/kernel/liveupdate/kexec_handover.c +++ b/kernel/liveupdate/kexec_handover.c @@ -286,6 +286,40 @@ void kho_radix_del_key(struct kho_radix_tree *tree, unsigned long key) } EXPORT_SYMBOL_GPL(kho_radix_del_key); +static void __kho_radix_destroy_tree(struct kho_radix_node *root, + unsigned int level) +{ + unsigned long i; + + if (level == 0) { + kho_radix_free_node(root); + return; + } + + for (i = 0; i < PAGE_SIZE / sizeof(phys_addr_t); i++) { + if (root->table[i]) + __kho_radix_destroy_tree(phys_to_virt(root->table[i]), + level - 1); + } + + kho_radix_free_node(root); +} + +/** + * kho_radix_destroy_tree - Destroy the radix tree + * @tree: The radix tree to destroy + * + * Walk @tree and free all its nodes. + */ +void kho_radix_destroy_tree(struct kho_radix_tree *tree) +{ + if (!tree->root) + return; + + __kho_radix_destroy_tree(tree->root, KHO_TREE_MAX_DEPTH - 1); +} +EXPORT_SYMBOL_GPL(kho_radix_destroy_tree); + static int kho_radix_walk_leaf(struct kho_radix_leaf *leaf, unsigned long key, const struct kho_radix_walk_cb *cb, void *data) { -- 2.54.0.545.g6539524ca2-goog