From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id C555DC677C4 for ; Wed, 11 Jun 2025 14:36:13 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 64F236B00A0; Wed, 11 Jun 2025 10:36:13 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 626FB6B00A2; Wed, 11 Jun 2025 10:36:13 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 53DBC6B00A3; Wed, 11 Jun 2025 10:36:13 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 337AB6B00A0 for ; Wed, 11 Jun 2025 10:36:13 -0400 (EDT) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id ACF6A140EAD for ; Wed, 11 Jun 2025 14:36:12 +0000 (UTC) X-FDA: 83543369784.11.55E2236 Received: from sea.source.kernel.org (sea.source.kernel.org [172.234.252.31]) by imf12.hostedemail.com (Postfix) with ESMTP id CA14B40018 for ; Wed, 11 Jun 2025 14:36:10 +0000 (UTC) Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=SOa0tr0M; spf=pass (imf12.hostedemail.com: domain of rppt@kernel.org designates 172.234.252.31 as permitted sender) smtp.mailfrom=rppt@kernel.org; dmarc=pass (policy=quarantine) header.from=kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1749652571; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=tQ/UxDHgzeuATrOg3yhOk1IwDk2MPYkl06v/k4Sv0iQ=; b=eigMhb8B3z3CYJ1Lxe0TFxbjk0ZAyEqlySt+9m+SN2u7Wixn9qEXQk5GqIAd2BOUnmHb3/ Q52s+ivAqls8sHzIOooXwCb9lQ09W0KhvFGJbTHteleUDDzALmH7uIZ7UkbwHyrAXAPIaJ 0fA7ozJD2r2S04YbMyryR4a7LsJ4axc= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=SOa0tr0M; spf=pass (imf12.hostedemail.com: domain of rppt@kernel.org designates 172.234.252.31 as permitted sender) smtp.mailfrom=rppt@kernel.org; dmarc=pass (policy=quarantine) header.from=kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1749652571; a=rsa-sha256; cv=none; b=6km61vnZQbf1SNT5x/bb13aU31+3pf5FfNbNJHe8Dd9tlsPw7ZUHnZkJGWBqUMK6iL8iZw iL1Au3S8gGezJUiAtCjC8hjaZ6wCNouvZO+9TA1MG2XsYFCPgCxWrba7c4E4K1ri1zX4Z2 wrahut+4aMNJcoioAATI3Oym0wPbVhU= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sea.source.kernel.org (Postfix) with ESMTP id AA68243C3B; Wed, 11 Jun 2025 14:36:09 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 89F58C4CEEA; Wed, 11 Jun 2025 14:36:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1749652569; bh=BwQApHN0G3pfvpqONIQ8shCNdyfSmev1VZcGPQpRZ34=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=SOa0tr0MZr22xzfLw6yG03FCfm3DAvZ66DbbNiM8el3S8oQYbxQMYfhtzZHQlNR2q lmSmDbHnHG1gXQRmpiLx5b1HR5ak/nq/HDoCttAfN+n0fwDTeMft5gl3tlWMaHBS3o +XXauGzxsJSluj/syCEdaiCaJ4DUgGPb6o0pXnh5I/PTD97ri5WGCgweRrfIkOWf8D Dyo4R3Yxr83cHU5IcXNBPZl7ASvgPrxLf2bthoyS/TYX6/Ws93Pj5HkrcBqLx6VXVm Bm9hEdL7KtEFqVaOjsQ8BVEb5nGEle3P7KlcPR4/QmlkZjAT5eS0jdDHIgQP0iudoZ qvWkLp1EUfR/g== Date: Wed, 11 Jun 2025 17:36:03 +0300 From: Mike Rapoport To: Pratyush Yadav Cc: Pasha Tatashin , Alexander Graf , Changyuan Lyu , Andrew Morton , Baoquan He , kexec@lists.infradead.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Michal Clapinski Subject: Re: [PATCH] kho: initialize tail pages for higher order folios properly Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: CA14B40018 X-Stat-Signature: cys7feyusnxuwk7ntyr4wtyp5if9e5k6 X-Rspam-User: X-HE-Tag: 1749652570-103892 X-HE-Meta: U2FsdGVkX1+3cVOahH5PpGRStkfIxvpwME1JEB4MoPlJI0w/T2dYvOSsO6aGkP+meo6dijuvUOG//OLJwsGR2iCYl0WGM/+7BQm5bypm6hjlc50crNrCYT9GR85tq1q4HNDZy6xqLG6JRyjyoUMD+hgf2jL0Jd88hRgk+2QXEFVyCZ1slS6RiOniPzQDXwTHDH87H3BPcwBkifyvswMawCnJGi0KqCo0FEuAnZZeElLEncIFxyZ85t/JmhhFvvCLfQnbIZoDrbPm8zrLgnL6DFOBDVXCUBgBFkMQySlnP1b0rBbQoc5ioV3l8WehLfK7kpzc30dmmm07jSFCRUNvw1aYuhYoAE8h9gpPD6bzYXFgAGV2ekZLrsOeL/ZCymgPs13mzXpEctRUjxP5WfYbfC9qcc5nvUkJT+xBiAW6vDiDx3+/CRq5v7G6HuDp+0gzIeHtwU4nsaru/xqHllJI+3arXdCVwuuEy3HacyGX5dtX3tLncAtKfjOPwc4sLqCSn3XU4Tmv8tP7oP/tdSnLWqwF7IAMwF8FzLyHE26CAWWQIxRqDz3GkWmcwdngqGB6NiBO7vyJVoWdHGtgjXnfZFR2glU2463SwhL97UbaoNZHizsRPx7s52l8pecjWNWLADoLiovTEyns8l5cNzFtKYHOdmQL7ksYJTKGk2A6wDcTeVtnc6lAmECM372qqgSv0xV1vkT3So23nKxRXkLeNMYU5dGUD2cv4DtaZp1psnigZCuervLzmHkRgb6b5/Cw6tcXbnfsGnR2pdQpsZ+Bhp3n9gl4LkA+AxLWQM+YBufLucpr78qN0xupi38GaR1gLqG+EHlfPuYNkJ7tLnqtmxumaQB3cUPexmqASTeTvkTwaRHl8hUY1ssdZU5lixC7GhKJ2S11XfBksS6tZFRfOYaWWoGOMmse2WWY5Hbw6Lzdsj9FKzzkso9WuUeXuUVJGJ5SAdiZspXQEsWsPuu T3OEdQ/o XnVccWXgATcEKV8synoO7SqQj2utgaiVw1LnzzKQ+WfB1Xws1NygudnW8QsNxFnUoeMeixg4ZBX2o6Ztngwjna3vR1uS7dad3zht40KRiEwba7iWQR+o88KE2JDS1MHTfGgWGN+R/dLHRts3JeMQL8awQCfh5J2YYNCkl6reoEs8qtP3psLig/XJim1VYHg7fHMfejIVhmnQkXNIdOKOFy8vmWh7EA+UjPJUx+Vkwfo9tPHaRYVdIedPEf13FgBIWwirjiR1JBmksbkVBRHiLq+3a1yUYjt3gfa7HNY8h4Q2/InU= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: On Wed, Jun 11, 2025 at 04:01:52PM +0200, Pratyush Yadav wrote: > On Wed, Jun 11 2025, Mike Rapoport wrote: > > > On Wed, Jun 11, 2025 at 09:14:55AM -0400, Pasha Tatashin wrote: > >> On Wed, Jun 11, 2025 at 9:06 AM Pratyush Yadav wrote: > >> > > >> > On Tue, Jun 10 2025, Pasha Tatashin wrote: > >> > > >> > >> > > I think it should be the other way around, KHO should depend on > >> > >> > > !DEFERRED_STRUCT_PAGE_INIT. > >> > >> > > >> > >> > Agreed, and this is what I first tried, but that does not work, there > >> > >> > is some circular dependency breaking the build. If you feel > >> > >> > adventurous you can try that :-) > >> > >> > >> > >> Hmm, weird, worked for me :/ > >> > > >> > Worked for me as well. > >> > > >> > > > >> > > I am super confused, it did not work for me over weekend, and now it > >> > > is working. Even `make menuconfig` would not work. Anyways, I will put > >> > > it in the appropriate place. > >> > > > >> > >> > >> > >> > > > We will need to teah KHO to work with deferred struct page init. I > >> > >> > > > suspect, we could init preserved struct pages and then skip over them > >> > >> > > > during deferred init. > >> > >> > > > >> > >> > > We could, but with that would mean we'll run this before SMP and it's not > >> > >> > > desirable. Also, init_deferred_page() for a random page requires > >> > >> > > >> > >> > We already run KHO init before smp_init: > >> > >> > start_kernel() -> mm_core_init() -> kho_memory_init() -> > >> > >> > kho_restore_folio() -> struct pages must be already initialized here! > >> > >> > > >> > >> > While deferred struct pages are initialized: > >> > >> > start_kernel() -> rest_init() -> kernel_init() -> > >> > >> > kernel_init_freeable() -> page_alloc_init_late() -> > >> > >> > deferred_init_memmap() > >> > >> > > >> > >> > If the number of preserved pages that is needed during early boot is > >> > >> > relatively small, that it should not be an issue to pre-initialize > >> > >> > struct pages for them before deferred struct pages are initialized. We > >> > >> > already pre-initialize some "struct pages" that are needed during > >> > >> > early boot before the reset are initialized, see deferred_grow_zone() > >> > >> > >> > >> deferred_grow_zone() takes a chunk in the beginning of uninitialized range, > >> > >> with kho we are talking about some random pages. If we preinit them early, > >> > >> deferred_init_memmap() will overwrite them. > >> > > > >> > > Yes, this is why I am saying that we would need to skip the KHO > >> > > initialized "struct pages" somehow during deferred initialization. If > >> > > we create an ordered by PFN list of early-initialized KHO struct > >> > > pages, skipping during deferred initialization could be done > >> > > efficiently. > >> > > >> > Or keep things simple and don't use any KHO struct pages during early > >> > init. You can access the page itself, just don't use its struct page. > >> > > >> > Currently the only user of kho_restore_folio() during init is > >> > kho_memory_init(). The FDT is accessed by doing > >> > phys_to_virt(kho_in.fdt_phys) anyway, so there is really no need for > >> > restoring the folio so early. It can be done later, for example when LUO > >> > does the finish event, to clean up and free the folio. > >> > >> Good suggestion, however, KHO does not have any sophisticated users > >> that we are going to be adding as part of the live update work in the > >> future: IR, KVM, early VCPU threads, and so on. So, while today, this > >> might work, in the future, I am not sure if we should expect struct > >> pages are not accessed until after deferred initialization or simply > >> fix it once and for all. > > > > KHO already accesses stuct page early and uses page->private for order. > > Since preserved memory is reserved in memblock, deferred init of struct > > pages won't touch those pages, we just need to make sure they are properly > > Not strictly true. Some of them might have been initialized from > free_area_init() -> memmap_init() (the ones not eligible for deferred > init), which happens before KHO makes its memblock reservations. > > > initialized at some point. If we don't expect many kho_restore_folio() > > before page_alloc_init_late() we can use init_deferred_page() for early > > accesses. > > I tried doing this when looking into this initially, but it doesn't work > for some reason. > > static void kho_restore_page(struct page *page, unsigned int order) > { > unsigned int i, nr_pages = (1 << order); > > /* Head page gets refcount of 1. */ > init_deferred_page(page_to_pfn(page), NUMA_NO_NODE); This would do if (early_page_initialised(pfn, nid)) return; __init_page_from_nid(pfn, nid); and I'm really surprised it didn't crash in early_page_initialised() because of NUMA_NO_NODE :) What might work here is pfn = page_to_pfn(page); __init_page_from_nid(pfn, early_pfn_to_nid(pfn)); > set_page_count(page, 1); > > /* For higher order folios, tail pages get a page count of zero. */ > for (i = 1; i < nr_pages; i++) { > init_deferred_page(page_to_pfn(page + i), NUMA_NO_NODE); > set_page_count(page + i, 0); > } > > [...] > > results in: > > [ 0.644032] page:(____ptrval____) is uninitialized and poisoned > [ 0.644679] page dumped because: VM_BUG_ON_PAGE(PagePoisoned(page)) > [ 0.645376] ------------[ cut here ]------------ > [ 0.645883] kernel BUG at ./include/linux/mm.h:1512! > [...] > [ 0.647924] RIP: 0010:__pageblock_pfn_to_page+0x166/0x180 > [...] > [ 0.647924] > [ 0.647924] set_zone_contiguous+0x6b/0x90 > [ 0.647924] page_alloc_init_late+0x356/0x370 > [ 0.647924] kernel_init_freeable+0x12d/0x190 > [ 0.647924] ? __pfx_kernel_init+0x10/0x10 > [ 0.647924] kernel_init+0x1a/0x130 > > didn't dig any deeper on why it happens... > > -- > Regards, > Pratyush Yadav -- Sincerely yours, Mike.