From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 BB27F3FE656 for ; Wed, 29 Apr 2026 13:39:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777469998; cv=none; b=jzilawYmxAkiUY1zqzPFiaBPb/7E9bGtiuaxy04WkCiQq/KeJrpcobwv27fBL3+WSlOHD53/fsoKAsodhUsuQdYRY80ASp9EUzzzHlaI5OV/7+OEOZb+1Tfp3PoqYGdZoLGUouqL4J63QHWAMvz+rC0Znq3WVP3XElEi2OGXHw0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777469998; c=relaxed/simple; bh=ftYh4PDmonLl3Iz/lLsbB7jSCaV0uIwezkLhW0XcrsU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=q+X1/tQKfdep08WcM/dor7mxWx1l0JlPbh+3ZKW8X+8+8jGVsn6qlbvOcR1T6kHgNL+47lJLW6w6OIKFjeYcFiIwEfy3Hp5bcQ+7RA/hztLn32GPxVGW9Qca1enwyuSdVzfKrfEWagpiuFvsddmGNaJvxGKdSRDS9cLlVCv9eu0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=McyaYreL; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="McyaYreL" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 85475C19425; Wed, 29 Apr 2026 13:39:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1777469998; bh=ftYh4PDmonLl3Iz/lLsbB7jSCaV0uIwezkLhW0XcrsU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=McyaYreLK3DAy83VtxLXczaPdKXbJ4HsxCY/b9v9x1w2NecV2RKtxkEindaIvwik+ p9wBKf9QM9MTBS70oGS1alRF8VwfLKyQP0+4d4uw6cNVG9h69sTE8EtPEByQVfsCu8 bPwGaav1RIb9hzLQe+joacKt7Oj9LVM5So5sgyYR5v/fyMaRHdSvIJUMikGsmSJoit ypozQcdAlC8La2ma0Nyk9hasOZ+CYzl+xCTSYlqangq0cFXddwa8vUVg+pKe6XJB7m WpaGbUethsdpNbmnKIUkq1TSbAi/GEhivGoKeWQ+4L6mkxo8NeQ0jpK3aIA/Qzp8up EsGXhR/wQm11A== From: Pratyush Yadav To: Mike Rapoport , Pasha Tatashin , Pratyush Yadav , Alexander Graf , Muchun Song , Oscar Salvador , David Hildenbrand , Andrew Morton , Jason Miu Cc: kexec@lists.infradead.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH 06/12] kho: allow early-boot usage of the KHO radix tree Date: Wed, 29 Apr 2026 15:39:08 +0200 Message-ID: <20260429133928.850721-7-pratyush@kernel.org> X-Mailer: git-send-email 2.54.0.545.g6539524ca2-goog In-Reply-To: <20260429133928.850721-1-pratyush@kernel.org> References: <20260429133928.850721-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 before buddy so it serves the same practical purpose. 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 d0a4f78eccfe..47f7c4a2865e 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. @@ -183,7 +203,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; @@ -214,7 +234,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.545.g6539524ca2-goog