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 8C165C55178 for ; Sat, 1 Aug 2026 08:49:30 +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=fB6QoJtOJWMJKT+tiRLfgRFEUeDku5eshXcZ+GMHx2c=; b=BDUy0DRZdLJQrOK75YYsaJ/r7L V7qsqZKjmSuARQwrL4q+fzTzd3YmxnIg0HstR2xzGz5Fpa0fiHM6DfTslHAzqSCBIeC+jJury2a7k hksLtIHtJCv+/Gzmt8UlXhvjqKQw1u7IycgePipZWykCR2k8Kx/S3Kp+jmKuEsXeYZBeVGovSHJuz mRPrmkbb2b39H3ErENcQg/MexGErm3VFuraeHdxw4OcD1p2/ooYogTzASe/xAFRdgHA4USeETuxZ+ xlwNnuXtBEnsIAE/c6H19d81Cqslqj7ka8yg5l2Wx1k9B52ma3HGr4andjSCGnT/4ue4956RjQMRH USkWBE6A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.99.1 #2 (Red Hat Linux)) id 1wq5PN-0000000E4qr-26PL; Sat, 01 Aug 2026 08:49:29 +0000 Received: from sea.source.kernel.org ([172.234.252.31]) by bombadil.infradead.org with esmtps (Exim 4.99.1 #2 (Red Hat Linux)) id 1wq5PM-0000000E4pM-2hxR for kexec@lists.infradead.org; Sat, 01 Aug 2026 08:49:28 +0000 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by sea.source.kernel.org (Postfix) with ESMTP id 7D5FC4527B; Sat, 1 Aug 2026 08:49:17 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 39ECA1F00ADE; Sat, 1 Aug 2026 08:49:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1785574157; bh=fB6QoJtOJWMJKT+tiRLfgRFEUeDku5eshXcZ+GMHx2c=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=k/5hdvIeEoz/uifaUAnG8jupHXEQhnD9Zo15v9weL5b539IURBmOQZNahkaICzMae TZIZjDeGNxjBhQ1WcfSIIYF/caM1KifDruuizZr8qOYdrmnVSdWc8+2tzFsw9P3jzb Fa21jbuUXhLg+YUJ97B9qX27sWmgdni6ZcmbnFBhxS76g0CyXJotLM1s82NHPzcMzD lbE+7lvFpqaXLXAw/CpyGth0hS6iVDm4VBGMkAXaiNv4oi3ihPbD/a+2llVonYowwF Mq38xr26vYrGJQ0rSV+rZTU1FqUu8HpdkjuPLuAguv9GqNObek93SB0c0c0adnN/Xz Q6DHEjtZXMxbg== 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 v6 10/22] kho: allow early-boot usage of the KHO radix tree Date: Sat, 1 Aug 2026 10:48:19 +0200 Message-ID: <20260801084833.1897543-11-pratyush@kernel.org> X-Mailer: git-send-email 2.55.0.571.g244d577d93-goog In-Reply-To: <20260801084833.1897543-1-pratyush@kernel.org> References: <20260801084833.1897543-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)" The KHO radix tree allocates memory for table pages from the buddy allocator using get_zeroed_page(). This is not available in early boot when memblock is still active. Using the radix tree in early boot is useful for KHO to track metadata about its memory. One such example is for tracking free blocks for memory allocation when scratch runs out of space. This feature will be added in the following commits. Add kho_radix_{alloc,free}_node() which allocate and free the table pages. They use slab_is_available() to decide which allocator to use. While slab_is_available() indicates availability of the slab allocator, it gets initialized right after buddy so it serves the same practical purpose. Reviewed-by: Pasha Tatashin Signed-off-by: Pratyush Yadav (Google) --- kernel/liveupdate/kexec_handover.c | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/kernel/liveupdate/kexec_handover.c b/kernel/liveupdate/kexec_handover.c index 3dd26d5d3c09..a5800b960cf6 100644 --- a/kernel/liveupdate/kexec_handover.c +++ b/kernel/liveupdate/kexec_handover.c @@ -146,6 +146,26 @@ static unsigned long kho_radix_get_table_index(unsigned long key, return (key >> s) % (1 << KHO_TABLE_SIZE_LOG2); } +static void __ref *kho_radix_alloc_node(void) +{ + struct kho_radix_node *node; + + if (slab_is_available()) + node = (struct kho_radix_node *)get_zeroed_page(GFP_KERNEL); + else + node = memblock_alloc(PAGE_SIZE, PAGE_SIZE); + + return node; +} + +static void __ref kho_radix_free_node(struct kho_radix_node *node) +{ + if (slab_is_available()) + free_page((unsigned long)node); + else + memblock_free(node, PAGE_SIZE); +} + /** * kho_radix_add_key - Add a key to the radix tree. * @tree: The KHO radix tree. @@ -194,7 +214,7 @@ int kho_radix_add_key(struct kho_radix_tree *tree, unsigned long key) } /* Next node is empty, create a new node for it */ - new_node = (struct kho_radix_node *)get_zeroed_page(GFP_KERNEL); + new_node = kho_radix_alloc_node(); if (!new_node) { err = -ENOMEM; goto err_free_nodes; @@ -225,7 +245,7 @@ int kho_radix_add_key(struct kho_radix_tree *tree, unsigned long key) err_free_nodes: for (i = KHO_TREE_MAX_DEPTH - 1; i > 0; i--) { if (intermediate_nodes[i]) - free_page((unsigned long)intermediate_nodes[i]); + kho_radix_free_node(intermediate_nodes[i]); } if (anchor_node) anchor_node->table[anchor_idx] = 0; -- 2.55.0.571.g244d577d93-goog