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 57CE43F23C9 for ; Fri, 5 Jun 2026 18:35:37 +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=1780684541; cv=none; b=RDkZpO7a1gpXkiW3tbL8U3fC/tR1wDj9TgLCqDkUCGvH43qm38KZ9gvSF8lO4v+8lMbDnIRsNtQXieJhyOwWL6m+JMt5hZv5u3nCeNLyu1y9h93mDF1xf/5rE3N9NXvlf/tq6YQx2fVOdLOF/rvb5CAzTfSBD9Qw+AjKLJ6PGbM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780684541; c=relaxed/simple; bh=7WIR+aexSSPvq4UNHWiG9pWiz/TK26aFSuPVAtN9hE0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=X6zYDxYKDMCLBfoTwgWrwPQaonCcKPHUJ4b/oW+Myp9inMofBgL1AjIrV24lt40nBiNTbyybtJNMHIDA2jW/OHlVgRttPDUN39DkU1f2QUdNEhxjvC6nLnJd12EDBe3z/Lo0VXhUIZbJbxjFkV4iTMUZs27oNsddVg1HuTSB2VE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Ck4NKjcv; 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="Ck4NKjcv" Received: by smtp.kernel.org (Postfix) with ESMTPSA id EE3EB1F00898; Fri, 5 Jun 2026 18:35:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1780684537; bh=W+ieLiROXsrjmcbXie0/1ghO8w8NO2+45uMA2SUyf88=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=Ck4NKjcv6KT67E4X0JZGiF3AgMSytQ+F9NG1+2UKCsfDerJ/WrWzB/nS8VfyWK2Hw yFviIheKsUScGgvfY+ZYCjZUfgxyQZab2SzgqXHccaRDIwn/TlVb3uwq56Nf0Q5gWM syPLIRi6Q+OMHb8FveP9D7hHXSdLQtDmTRY2Vdxh7oGq5x20RMa3oRtxe//x2RpbFa YQHRhzgcHATS8y4uSmLtyimCqznQM++24sXBO1Q5wmbvG+J+8Ku/0XaAYJ8rovnvTS lndZjmCbXaR0SodxcsI8bTiW93QerK8HEPpzgxpUQZTsfFs/m5BD+uOg5Zi4UF5A1T 0hbWpEPKoKMXw== 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 10/18] kho: allow destroying KHO radix tree Date: Fri, 5 Jun 2026 20:34:43 +0200 Message-ID: <20260605183501.3884950-11-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)" 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 452b4dcdf2d2..df3f5eb01bf1 100644 --- a/kernel/liveupdate/kexec_handover.c +++ b/kernel/liveupdate/kexec_handover.c @@ -298,6 +298,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.54.0.1032.g2f8565e1d1-goog