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 80D3BC43458 for ; Thu, 9 Jul 2026 17:39: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=sn5jxIlLMIau4GifCV8YOHeAp5/QttEGk8CccgmzI9U=; b=OrnOywa6zUJYN3YJgZzzjTgsPd Cxs//rctwIwPiX26XGkxgi13gKBfFbLm6NC+3oOyGhcMk1Hmg1l5Xr+f7cubmrvhqbWWG6kETwDvf 5p94lksd0CmPxX8V1C7svKRf1/DF9rKyyYmV8kAPoHvOWLjIT4A7ABvxReuG0sDPI3k/R8NMP0JPI pRtxMxBi/rNfphzcNWkE+eTKlcSz1y9ZPLr32iCmEBC1iwSGuHw9i7nOkCH0aA3wA2M1aMgacjAON WFdSaOKODXQOKQ68M0duwiC4dI+7QzplDz9BuZyrrfbmrFEP/DhNTn0eAQVOqjtPGverTQcuG/zu1 2dfc7xfg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.99.1 #2 (Red Hat Linux)) id 1whsiE-000000038H4-1rhO; Thu, 09 Jul 2026 17:39:02 +0000 Received: from sea.source.kernel.org ([2600:3c0a:e001:78e:0:1991:8:25]) by bombadil.infradead.org with esmtps (Exim 4.99.1 #2 (Red Hat Linux)) id 1whsiC-000000038Fp-39x5 for kexec@lists.infradead.org; Thu, 09 Jul 2026 17:39:00 +0000 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by sea.source.kernel.org (Postfix) with ESMTP id 81E6F4169D; Thu, 9 Jul 2026 17:39:00 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3F1871F00A3D; Thu, 9 Jul 2026 17:38:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1783618740; bh=sn5jxIlLMIau4GifCV8YOHeAp5/QttEGk8CccgmzI9U=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=IyZn+n4oTykDT3NuNnSd0oHZSsVb13m5OHh6NioPTijvXAL53mRdYeaX/yrzRLmVU ycoXx4A+uUZmtZeUN5+brNVYDg7mTz1lu+riWs5zf2PP1TZ6pYcWysWH/jPVe0WVOM h/TkpOmD3r70Rzw3hthOVTegCejxjF+vNmJsqcsmN358OoO1k/jHPq+/DnKaZwyILk RRGhPH7SYYVrgFV81UlTehoIAMgMgikZpMfWji1V5kvmxj+0GsTjQAKaIqDH+8/8Kp jfVmqMkiFYcMBN8S+EQSJDUGMYhy6I32GWZDdsd+Pm0DVU1+35gyZxtAFbx5K5GI+e 1A/Ied3hRG1MQ== 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 v3 11/21] kho: allow destroying KHO radix tree Date: Thu, 9 Jul 2026 19:38:00 +0200 Message-ID: <20260709173821.429921-12-pratyush@kernel.org> X-Mailer: git-send-email 2.55.0.141.g00534a21ce-goog In-Reply-To: <20260709173821.429921-1-pratyush@kernel.org> References: <20260709173821.429921-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)" Add kho_radix_destroy_tree() which allows destroying the radix tree and freeing all its pages. This is will be used by the upcoming scratch extension mechanism. It creates a radix tree to track free blocks and then frees them after telling memblock about them. Reviewed-by: Pasha Tatashin Signed-off-by: Pratyush Yadav (Google) --- include/linux/kho_radix_tree.h | 3 +++ kernel/liveupdate/kexec_handover.c | 35 ++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/include/linux/kho_radix_tree.h b/include/linux/kho_radix_tree.h index 4138621e0e87..66ca936b3f06 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 a5800b960cf6..105dc0f3e691 100644 --- a/kernel/liveupdate/kexec_handover.c +++ b/kernel/liveupdate/kexec_handover.c @@ -301,6 +301,41 @@ 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); + tree->root = NULL; +} +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.55.0.141.g00534a21ce-goog