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 D709FC678DC for ; Wed, 11 Jun 2025 14:02:00 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 796C76B00B3; Wed, 11 Jun 2025 10:02:00 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 76DA06B00B5; Wed, 11 Jun 2025 10:02:00 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6AAE06B00B6; Wed, 11 Jun 2025 10:02:00 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 4C5006B00B3 for ; Wed, 11 Jun 2025 10:02:00 -0400 (EDT) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id EA026120D8D for ; Wed, 11 Jun 2025 14:01:59 +0000 (UTC) X-FDA: 83543283558.30.8D45B85 Received: from sea.source.kernel.org (sea.source.kernel.org [172.234.252.31]) by imf12.hostedemail.com (Postfix) with ESMTP id 32D1940015 for ; Wed, 11 Jun 2025 14:01:56 +0000 (UTC) Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=LkVVIMiP; spf=pass (imf12.hostedemail.com: domain of pratyush@kernel.org designates 172.234.252.31 as permitted sender) smtp.mailfrom=pratyush@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=1749650518; 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=pjI2zrDixSfbKjy2J3M1Zn3AgAixxH2Pl5gpFoFjlag=; b=5cJvvhiipgQ6HHAnZgeUT3LZ47q2lsmjyqqt4dDdpSAsiFV1nijQnEgf2qc+yNujSIbVBc mhuz0zN8dC49GMoub+EUTAanvyVBrbGUMCHVctOl3oaHg1XxSyW4CBpfMEX29/S5Ott7fI Z0sBxgX3EEbuS0IxFolO3EHfTQfxlL0= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1749650518; a=rsa-sha256; cv=none; b=wY+mgxyCxcMm4rKFpGZrrRGYrIeKqaCTfIgCy3RDM6OwvGW+9H1XYGsYDYmewfopGHQjMF fyomHfIWWJxswKLuS7K0dheLXB+aQkaX5psgWHvMIR81aXM2PvfX8dKNj6LQec2BuwrxZl zOc0VU88aXulnb+I+qyy8GHUYd8G270= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=LkVVIMiP; spf=pass (imf12.hostedemail.com: domain of pratyush@kernel.org designates 172.234.252.31 as permitted sender) smtp.mailfrom=pratyush@kernel.org; dmarc=pass (policy=quarantine) header.from=kernel.org Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sea.source.kernel.org (Postfix) with ESMTP id 0B3C843D54; Wed, 11 Jun 2025 14:01:56 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1C5C1C4CEEA; Wed, 11 Jun 2025 14:01:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1749650515; bh=BAePymoebK5BBu7o01vZEw+cupxxDzaeyWOs5m+KQ88=; h=From:To:Cc:Subject:In-Reply-To:References:Date:From; b=LkVVIMiPzy53gbOuXhKkB5rkSfCB6l8PYd0O1935ufYN+sE6BR/l5ZtC8aRX+EBfp zYoEEYFmX15KBnpmwgjI8/CgvxJ5laOEhekSnSfUhKDNV7J9Xn2c4KU7ofEKZL4Ndu YHcR347Nr7dzll7S6ZtAA0BO7e0cUyrs5X4LJo5ErgCskyeA9p7Cde+iGGzeInSymH 6xlAff7qBC3TLFz00pINbaQLC9F10uUu4hXfmdh/QVRf8tLYRaGY2zjNcVdcea5p11 yblDWSKZOrThyD8FdUnTWw/KFM/dPoKO+HNMFAQ2M/zf3pf6ofWt5pBlADThokceIP 5ULBXZsx/q3Vw== From: Pratyush Yadav To: Mike Rapoport Cc: Pasha Tatashin , Pratyush Yadav , 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 In-Reply-To: References: Date: Wed, 11 Jun 2025 16:01:52 +0200 Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Rspam-User: X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: 32D1940015 X-Stat-Signature: ye8ih9h4h863znb4g6ehydpoyi6ptczr X-HE-Tag: 1749650516-966236 X-HE-Meta: U2FsdGVkX1840YW2/AYS9V6A38kxspy17r0UDEdspLtYpjQm3c2BtMnRceCaSVsxmAzcJwQZUAxfueJgbxVvUsc+9n/qVBSf4lynnwzo5ndaTLcyBuVTImItd90GN+IgWKyIER3ZFb9z7e/hbyBzbhHZSy8PAXv/DaYAVfMMisjsjqG3jmFEJNNA58gaFkbvCVv/zJ8lbeKJtTYL6HmwbRvszgpzgP67078Quy/X/NUr7+3rTzL4c63XMz40CgZwcKiUi1GD3hMfrcjGmNl4+MHBemUJCUoyhnvh62m8mc3QaCLm/UvUR1EAgPcvvKaxELkcM2QgmyPLQOXCrTdzn2Bvu9kKi70y5wWVMtYZ/EKq9CAoCFuPoBBIwI7uJELw/x+fy+tHerrfHkFYTq3NY/pQmdiQ+D59iUxZj2SHb/D6K39aJ1nfxXLNHQOMYqNmbWpjGHLidhzAarTSIBrtkZIMDDdha42YWXALJ4Wj7l/1c71i01O2oLJUPcYJ3EN2Xm5T8GxtYQFViWMtxJ/LKexEQ118XCUPLgMsNQTwoUVIcaSv3T6mCJQOKNofSxjcfr5NpaRZ2W1jaAEZLPILJPNUHs2f9hMaxsVvhL18hkVBzceY8G5pC8NUeaOmchJshj1rs3Bcdg4oXd9Sdvy1aIx8cxA94ZldPNrek+6BxfAchyCcT0j8aoVhf0+mtd1WCJ0fl0iM14mtz9O5747QUL5JENYU1woShsGniLqH4TZoifLmCtzGvv62ITcUQDF+dPJXc2BS4WhSJjBoA9b80v2ot8IFgCIYTxf1LvOBMmb+JZ6gUEYLSg4ZvjYhl/qOk9jw9OhGBecXZ/jKX0fiSNAsdcO8kHXJa+Pqq1X/7CTJG/rzBJVUXH0v5dnCExDyxEnMmBedSlXugKPmhVZbO46R2XfjUT0tF4oCcD0EPBAcIFr89Tnxwo+89/njaDIzBeaBe3316OA3pYiZ9E8 atd82eAr +nCKtKl17fc3r0NIMoU4u14xD+3U+sb/H0nd7ww4LHZdwadONq2C6t4hifD4DDZ3P9zQfLJm3OKPAhvdfiLP+Qs2voZqtD4fGtP/V8AXqKeRgbRlQyw/+i2LvPdIC6absHAzsEPY/bft3lAGkw0lsCO2KUUkSkRPc0Q561N0Z+DC2+tOEdqZf/1lNl3rx8VFR4mxzouwNBo9TQ5cxBPbuYtvkSp+wgIU2Ayx96SNonoNAGcvCyuqZkRZd2w== 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, Mike Rapoport wrote: > On Wed, Jun 11, 2025 at 09:14:55AM -0400, Pasha Tatashin wrote: >> On Wed, Jun 11, 2025 at 9:06=E2=80=AFAM 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, t= here >> > >> > 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 p= ut >> > > it in the appropriate place. >> > > >> > >> >> > >> > > > We will need to teah KHO to work with deferred struct page in= it. I >> > >> > > > suspect, we could init preserved struct pages and then skip o= ver them >> > >> > > > during deferred init. >> > >> > > >> > >> > > We could, but with that would mean we'll run this before SMP an= d 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 h= ere! >> > >> > >> > >> > 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 initialize= d. We >> > >> > already pre-initialize some "struct pages" that are needed during >> > >> > early boot before the reset are initialized, see deferred_grow_zo= ne() >> > >> >> > >> deferred_grow_zone() takes a chunk in the beginning of uninitialize= d 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 L= UO >> > does the finish event, to clean up and free the folio. >>=20 >> 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 properl= y=20 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 =3D (1 << order); =20=20=20=20 /* Head page gets refcount of 1. */ init_deferred_page(page_to_pfn(page), NUMA_NO_NODE); set_page_count(page, 1); =20=20=20=20 /* For higher order folios, tail pages get a page count of zero. */ for (i =3D 1; i < nr_pages; i++) { init_deferred_page(page_to_pfn(page + i), NUMA_NO_NODE); set_page_count(page + i, 0); } =20=20=20=20 [...] 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... --=20 Regards, Pratyush Yadav