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 DB1823ECBD9 for ; Fri, 5 Jun 2026 18:35:34 +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=1780684537; cv=none; b=STbhORQO8YJTmrOXrVzGhhNSVTRZYiN+ypi6G1VNf0sxjdxf+BGYtJrDAHByMkgWepQ5nI+GxmjK9Ge2vI8v1OD2ImGfSc6H+7cJf5Wm1o/+HXFKAdl9FEwKkKQTz43jJH9VeXwfvTZImzW+x1P/b9YeUo3pF3roNfHvqfgQI0s= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780684537; c=relaxed/simple; bh=ZMus/+BO2Pl/1YIYSzuEuwEsLxaTcyn5kzeUqNBgxic=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=O3CTxkDSfPykzjeFO+ebfuuv7Qe42sCKwJ5lJ7w5ZjlhWj0z5I4tDY+8mU5UwCmqGz+6mqpXT2P9BgKcZtuynoOC+r7VENaNNaiYwf2gCwzaf7PzI7HghJRGW9A/IEMAwu/4zJ1QgZx5X3rX2c/CvyvAHuW591UFuj9VQCUVXcs= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=CsY8nuFv; 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="CsY8nuFv" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7D1E61F00893; Fri, 5 Jun 2026 18:35:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1780684534; bh=qTphUicBGxw+ljeZ1ORDyDZbANnd1GB5XieWEaaUYI4=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=CsY8nuFvQ+DgMmh65ei90bv2MYJd/hBWXIrE9XLIGEI3BzPrS55ccke1KugAEMr2q fsdWabsyi+i/ee4Z8u2T9dKUwYd58AyFTYmr8UnT42taM0KChOZBTjJOdeQQi6jlFC 3EsQ31i+xm4ZWUiNYAUZfxIQ9gGyeaX3srtIp1duNND4yxhs38ecdPxADjb0OQ53iW jqRJKAnYn9hBvxXyDSO7OaF5gChGb97hTvdJLZq8vTswF3ve9ZfWZpDjeyMBalUmEq P+h7YcomJuRpKPQ/Np5eVsDVoF2nrAmnq1Wvqelv8Fas9UhoJi+Xw/UPi/z1DMoFtZ ABTaW9NCd4zXQ== 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 09/18] kho: allow early-boot usage of the KHO radix tree Date: Fri, 5 Jun 2026 20:34:42 +0200 Message-ID: <20260605183501.3884950-10-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)" 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 b890a69bddd5..452b4dcdf2d2 100644 --- a/kernel/liveupdate/kexec_handover.c +++ b/kernel/liveupdate/kexec_handover.c @@ -143,6 +143,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. @@ -191,7 +211,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; @@ -222,7 +242,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.54.0.1032.g2f8565e1d1-goog