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 0F8133557E8 for ; Tue, 16 Dec 2025 11:57:26 +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=1765886247; cv=none; b=aHyHmJ1a5SacmGepmBZ5Cqlc/MitFluAAsb0MaJNUbfQfAVGhJKhz5m3EjcDWhPsoqjT2SdkdV5zEduP6k5/3IY8MQHtzbt14xIKeaJOq1n5mN2/fHgJzqohcz4CbKPGTHdwiIAnGa4xb+Z5K5y5RlP2wXLcOZXCU/9HBowePWU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765886247; c=relaxed/simple; bh=7ZFdnmw31SZNpKwCbTn3VwLXjfFQMOPztHlF9Mj4Qrc=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=XBSiuDE3y9Fip5NfrbCdmSXxfns/B4PzM5Bgt+VwTc7b9nJTfp7MCg1LDziDV49aB69ijDZqvmQX0w2xTx6hEj+zVevKeaTY39RhfMt/F1o8meaeDvrqoDx+ptyiibB9be7cVCQGDg4aXOKjc7rGa8KShu9WkXHb9Cq4e5xQ7qY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=levK1FBG; 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="levK1FBG" Received: by smtp.kernel.org (Postfix) with ESMTPSA id B6FCAC4CEF1; Tue, 16 Dec 2025 11:57:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1765886246; bh=7ZFdnmw31SZNpKwCbTn3VwLXjfFQMOPztHlF9Mj4Qrc=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=levK1FBGpysdmLQOMdTo0qNcTtB0s7RX0y4zTPIEcUboIVYrPZOuGFhUa6bo1W/fU Pkek4dlakV/QjzQcJYVYOoV/eRv457Rq1NkDVdejTSJwEFwt+UxkCc1PWpnmJO80LY OL/lhVJqjN+0W60eOuJJgkdiDtXm+r/RhggI5M/bwpZsNd03GHw3XpSEsQwOWig4A3 gBVT33D3IxuFbVGr9FbnmTvRhBd1ELZKiTNHPGscDsPTuppGV24iZQyq64K8sk0rYj SIdtnuzpZ8U/M8KggrJqRCjAmPMIXZl7O824bvxFkO6Vj/GpuSPgGhJSrKDsxcmuzD JbumRAVzfWYHg== Date: Tue, 16 Dec 2025 13:57:19 +0200 From: Mike Rapoport To: Evangelos Petrongonas Cc: Pasha Tatashin , Pratyush Yadav , Alexander Graf , Andrew Morton , Jason Miu , linux-kernel@vger.kernel.org, kexec@lists.infradead.org, linux-mm@kvack.org, nh-open-source@amazon.com Subject: Re: [PATCH] kho: add support for deferred struct page init Message-ID: References: <20251216084913.86342-1-epetron@amazon.de> 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: <20251216084913.86342-1-epetron@amazon.de> Hi Evangelos, On Tue, Dec 16, 2025 at 08:49:12AM +0000, Evangelos Petrongonas wrote: > When `CONFIG_DEFERRED_STRUCT_PAGE_INIT` is enabled, struct page No need for markup formatting in the changelog. > initialization is deferred to parallel kthreads that run later > in the boot process. > > During KHO restoration, `deserialize_bitmap()` writes metadata for > each preserved memory region. However, if the struct page has not been > initialized, this write targets uninitialized memory, potentially > leading to errors like: > ``` > BUG: unable to handle page fault for address: ... > ``` > > Fix this by introducing `kho_get_preserved_page()`, which ensures > all struct pages in a preserved region are initialized by calling > `init_deferred_page()` which is a no-op when deferred init is disabled > or when the struct page is already initialized. > > Fixes: 8b66ed2c3f42 ("kho: mm: don't allow deferred struct page with KHO") > Signed-off-by: Evangelos Petrongonas > --- ... > +static struct page *__init kho_get_preserved_page(phys_addr_t phys, > + unsigned int order) > +{ > + unsigned long pfn = PHYS_PFN(phys); > + int nid = early_pfn_to_nid(pfn); > + > + for (int i = 0; i < (1 << order); i++) > + init_deferred_page(pfn + i, nid); This will skip pages below node->first_deferred_pfn, we need to use __init_page_from_nid() here. > + > + return pfn_to_page(pfn); > +} > + > static void __init deserialize_bitmap(unsigned int order, > struct khoser_mem_bitmap_ptr *elm) > { > @@ -449,7 +466,7 @@ static void __init deserialize_bitmap(unsigned int order, > int sz = 1 << (order + PAGE_SHIFT); > phys_addr_t phys = > elm->phys_start + (bit << (order + PAGE_SHIFT)); > - struct page *page = phys_to_page(phys); > + struct page *page = kho_get_preserved_page(phys, order); I think it's better to initialize deferred struct pages later in kho_restore_page. deserialize_bitmap() runs before SMP and it already does heavy lifting of memblock_reserve()s. Delaying struct page initialization until restore makes it at least run in parallel with other initialization tasks. I started to work on this just before plumbers and I have something untested here: https://git.kernel.org/pub/scm/linux/kernel/git/rppt/linux.git/log/?h=kho/deferred-page/v0.1 > union kho_page_info info; > > memblock_reserve(phys, sz); > -- > 2.43.0 > > > > > Amazon Web Services Development Center Germany GmbH > Tamara-Danz-Str. 13 > 10243 Berlin > Geschaeftsfuehrung: Christof Hellmis, Andreas Stieger > Eingetragen am Amtsgericht Charlottenburg unter HRB 257764 B > Sitz: Berlin > Ust-ID: DE 365 538 597 > -- Sincerely yours, Mike.