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 7AFCB3EEAF4 for ; Sat, 25 Jul 2026 17:22:11 +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=1785000132; cv=none; b=L/u77+fCeG4k4Sm91I3isaFJEwixu5oQbM+6EvRL7c3/VDjHRRFNNqFMm0Y3mJ0C4ucU6Kot9wNN54aGZl2i7OXhiF5cOWJxihjcQGlGqq4zWvgH2fCeVo1ejLt6TRMG4kuxUN0/MtMt0Mr86/QmgD+rPyqMcPP82g27GjpwZuY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785000132; c=relaxed/simple; bh=8O6BZbQkezhXCMiPfEaAnB1Arsd3aJWkMgwwGnjA8Gg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=N1YRivQd8UO3ru8Xxzu60cCU4LbGx70ORdt/ndqQpC4k/PxyaD2wR+HBzH0u2vkUQnSEToci2uh5b/fdeupP7UqXZbCbVsqLTBbak9l0ZPPpgT9qrliYJlDbEVn2Q+Gknpn+vrNv1Eva3cyeS8jbthYP67kKtJJ7mcDOAplydz0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=jPzE14Zk; 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="jPzE14Zk" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2D0181F00A3F; Sat, 25 Jul 2026 17:22:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1785000131; bh=zqWvu3rJ4q6SWyTwb1yssAigbiaL27CwXelRSKXkxk8=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=jPzE14ZkYfFAOVgTfnslHwy9S9FuMOPjZ8g18fVJW1Bwx2E0BUT1f/0bYnVFYqJKZ uF+9QFbwuhPBeF+c/icia5FeA3cp4zXfSsK1i1hc8YA5UbJDIHmGwGQ7CETNTpiv3K aI2w1BSVC2KpnGJ/pHndXpDYUFVQmiw7vH/0JKGm3yd2Dj1YLBHNBicVKBkEJ0Ebxt prdhdBwIxfrg2ahSvrQyC+a3O6tXV4JvJw3KwUMXP39U9J1F+r8leHMBssqm/6gwvT jr5SpNLLmMmqqltd5TS5EQc2xT1kunuThHld3SGIzmTzFImgzDUrorpusQB5LMHIE3 NFI7GnZpAnjBg== 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 v4 10/21] kho: allow early-boot usage of the KHO radix tree Date: Sat, 25 Jul 2026 19:21:10 +0200 Message-ID: <20260725172133.4018491-11-pratyush@kernel.org> X-Mailer: git-send-email 2.55.0.229.g6434b31f56-goog In-Reply-To: <20260725172133.4018491-1-pratyush@kernel.org> References: <20260725172133.4018491-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)" 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.229.g6434b31f56-goog