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 0A0F822B594 for ; Tue, 3 Feb 2026 16:16:13 +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=1770135374; cv=none; b=uXsJPFRUcoeCh0faoxd8a7XCfy+X0/UvY/MV2sOt7AH7QmAHbKJn4kfvKqWOylRmxmB2xifglg9nyd25/hdUElNmxtVem0j7uv2FaRODwbKG9bfKX40/ik1ApS9x9xmkPkwWQLoE6O1h8yG8Asu4zd46nLxbTLJ+Oru2Hx1IY9A= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770135374; c=relaxed/simple; bh=Lggy4kALKLaV7O6fLdE4+3yPKrZNAb1hhE+tXBQafR4=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=ZJTEo/eCfUpRJ/a57XpFDXZaP3R1OQeG6ElAyl8MPB4KemVqmjvRuWHYUeKde0R+0luxgamDgh0ixu1MlW+EYDoPSHp/7jrkVvLTaQc5r76sqrGTEeJFOenWQVMPnqvLPafeAff4G6QHCr29nsJLU0jgxuFCh4dp3Ui4LSFBpMw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=hXLLC34H; 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="hXLLC34H" Received: by smtp.kernel.org (Postfix) with ESMTPSA id B490BC116D0; Tue, 3 Feb 2026 16:16:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1770135373; bh=Lggy4kALKLaV7O6fLdE4+3yPKrZNAb1hhE+tXBQafR4=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=hXLLC34Hyic6hTVqbQvX+x8C9ERdyKtNKrY6+MNR9b06xzRBHCvSqNkCZ7xinvGIP 7Hd3ieYzcbZvn2/LrBLyPiqnUxRcPP2niRSceJ/CsiaFC+sBVRcJgy71mcNUfrJEWD ybgZiWVweo9yd1pBfJaBZ3YTCNSAcqh6faYgv8maTRlfDqe+QH35iazzaOFGhxOxDY uR2PZJ6ZMlTK5ICJd2Zu+dP+hlT1PXeym14O7DAZlWFUSDhWxCRazeE/YpgthdUkEr iIW/x2hf4lsc9tNn5ZWyX8aZr7ZTTFzRRpyGBAmYJTy/7AMBs52RKuFtbp4DMymukR 6ml1F17rWEwRA== Date: Tue, 3 Feb 2026 18:16:05 +0200 From: Mike Rapoport To: Jason Miu Cc: Alexander Graf , Andrew Morton , Baoquan He , Changyuan Lyu , David Matlack , David Rientjes , Jason Gunthorpe , Pasha Tatashin , Pratyush Yadav , kexec@lists.infradead.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: Re: [PATCH v8 1/2] kho: Adopt radix tree for preserved memory tracking Message-ID: References: <20260130005739.3163049-1-jasonmiu@google.com> <20260130005739.3163049-2-jasonmiu@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20260130005739.3163049-2-jasonmiu@google.com> On Thu, Jan 29, 2026 at 04:57:38PM -0800, Jason Miu wrote: > Introduce a radix tree implementation for tracking preserved memory > pages and switch the KHO memory tracking mechanism to use it. This > lays the groundwork for a stateless KHO implementation that eliminates > the need for serialization and the associated "finalize" state. > > This patch introduces the core radix tree data structures and > constants to the KHO ABI. It adds the radix tree node and leaf > structures, along with documentation for the radix tree key encoding > scheme that combines a page's physical address and order. > > To support broader use by other kernel subsystems, such as hugetlb > preservation, the core radix tree manipulation functions are exported > as a public API. > > The xarray-based memory tracking is replaced with this new radix tree > implementation. The core KHO preservation and unpreservation functions > are wired up to use the radix tree helpers. On boot, the second kernel > restores the preserved memory map by walking the radix tree whose root > physical address is passed via the FDT. > > The ABI `compatible` version is bumped to "kho-v2" to reflect the > structural changes in the preserved memory map and sub-FDT property > names. This includes renaming "fdt" to "preserved-data" to better > reflect that preserved state may use formats other than FDT. > > Signed-off-by: Jason Miu With minor comments below Reviewed-by: Mike Rapoport (Microsoft) > --- ... > +static int __kho_radix_walk_tree(struct kho_radix_node *root, > + unsigned int level, unsigned long start, > + kho_radix_tree_walk_callback_t cb) > +{ > + struct kho_radix_node *node; > + struct kho_radix_leaf *leaf; > + unsigned long key, i; > + unsigned int shift; > + int err; > + > + for (i = 0; i < PAGE_SIZE / sizeof(phys_addr_t); i++) { > + if (!root->table[i]) > + continue; > + > + shift = ((level - 1) * KHO_TABLE_SIZE_LOG2) + > + KHO_BITMAP_SIZE_LOG2; > + key = start | (i << shift); > + > + node = phys_to_virt(root->table[i]); > + > + if (level == 1) { > + /* > + * we are at level 1, > + * node is pointing to the level 0 bitmap. > + */ > + leaf = (struct kho_radix_leaf *)node; > + err = kho_radix_walk_leaf(leaf, key, cb); > + if (err) > + return err; > + } else { > + err = __kho_radix_walk_tree(node, level - 1, > + key, cb); > + if (err) > + return err; Nit: if (err) can be moved outside if (level == 1) > + } > + } > + > + return 0; > +} > + > +/** > + * kho_radix_walk_tree - Traverses the radix tree and calls a callback for each preserved page. > + * @tree: A pointer to the KHO radix tree to walk. > + * @cb: A callback function of type kho_radix_tree_walk_callback_t that will be > + * invoked for each preserved page found in the tree. The callback receives > + * the physical address and order of the preserved page. > + * > + * This function walks the radix tree, searching from the specified top level > + * (@level) down to the lowest level (level 0). For each preserved page found, Hmm, why do we need @level here? Or it rather remained from the older versions? > + * it invokes the provided callback, passing the page's physical address and > + * order. > + * > + * Return: 0 if the walk completed the specified tree, or the non-zero return > + * value from the callback that stopped the walk. > + */ > +int kho_radix_walk_tree(struct kho_radix_tree *tree, > + kho_radix_tree_walk_callback_t cb) > +{ > + if (WARN_ON_ONCE(!tree->root)) > + return -EINVAL; > + > + guard(mutex)(&tree->lock); > + > + return __kho_radix_walk_tree(tree->root, KHO_TREE_MAX_DEPTH - 1, 0, cb); > +} > +EXPORT_SYMBOL_GPL(kho_radix_walk_tree); -- Sincerely yours, Mike.