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 30B9F4E3772 for ; Thu, 9 Jul 2026 17:38:58 +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=1783618739; cv=none; b=Y3XTr1hdnXP2/PkUZ/9CkUgnBCQ9LDpLtwNp2nlkuGA7uHXERI4DaCvex7uyxb4RVs1skseqKXZ9H+u/vzL1d9YyB+hgoHz9DMkdGfqJSJywCNZkzqkYtjS1XcrBOJLnqhgU7ZnIiHRFZf1uvFiK5WYFMURDiR5BrOMuCokTzEs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783618739; c=relaxed/simple; bh=ZmEldgBb/PmpcttbDzri1F1qRjFXoTGi4rrYaWU5Q6o=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=oNrW36Qpx3m71zuz2sZETh66vA1ia6OFLpMXS0gHCFvAqBD8M8FyBmDGPo8pbMkrAsa2A1aXnVrMi9+mjwEJ8Rsv3cWUwmuTAQYOcokR9SsoAR2Hvpjq3UkGVYKWAcQyHbAsH61ONt8MCn2Q4tl4yesCnABTRkXvrpKUtdX2pO8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=TrJ2jtbR; 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="TrJ2jtbR" Received: by smtp.kernel.org (Postfix) with ESMTPSA id ADC4B1F00AC4; Thu, 9 Jul 2026 17:38:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1783618737; bh=TflEiF+P3v8r5QgzuLrXTOp/v+oCi2axdEmh9PuAiiA=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=TrJ2jtbRO8wG3jLnTy48C7Y4laN1CbOqa0+9hJCLpLadL0NNNR8AIK1TmJmhrtwxE bfOX48Oj5jN1nQV0YAzZfVpD+MWYQw7ME/PFUvPVUfq8wTxTYUMMW7QtCplM+rTFeE LpZvWpRsWMubDOL5m8w3jEXwlfNOMqSDTzxHf8lknOJJiB1T9UA3WI8y29rTsI7NGh N58AJKteu5aXhZI5rfSRWgAljIUahAR0oldOpBQIhstbvtUysh3vGRp8qEmxJrDVmg 8JqgI9W8AdmrnGUUCsSAwTIFO76fshDnCpv0x2rJcwO7WrnQptgWolFCPlE+NJd01J TQ9CQ093zvqQQ== 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 10/21] kho: allow early-boot usage of the KHO radix tree Date: Thu, 9 Jul 2026 19:37:59 +0200 Message-ID: <20260709173821.429921-11-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> 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.141.g00534a21ce-goog