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 90749C71148 for ; Fri, 13 Jun 2025 16:21:18 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id EE6FC6B0092; Fri, 13 Jun 2025 12:21:17 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id EBDA86B0093; Fri, 13 Jun 2025 12:21:17 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DFAB06B0095; Fri, 13 Jun 2025 12:21:17 -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 C15086B0092 for ; Fri, 13 Jun 2025 12:21:17 -0400 (EDT) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 4062BBDD0E for ; Fri, 13 Jun 2025 16:21:17 +0000 (UTC) X-FDA: 83550892194.14.6CCFBAB Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf23.hostedemail.com (Postfix) with ESMTP id 8C552140008 for ; Fri, 13 Jun 2025 16:21:15 +0000 (UTC) Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=gTZR9j5v; spf=pass (imf23.hostedemail.com: domain of rppt@kernel.org designates 139.178.84.217 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=1749831675; 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=SGhLWOxHdV6sOh+CP4q4BVhRcqejcc7YZHRrvZqSn2A=; b=tDjbNKom/LqdJi9amr+Yd48YwF3lv7+E5C1uQt2TR8OxWtRylIY1FpSkMJYGP/6StzFMXC nqL+VVFEtZOdA2J+L4ocQPhLtJxqvMEkPKlAaJfM0RRPnrdLCA0+G/xaSXC7UTHb8nXhOP S0ONcmCksbCu+n4rJXZI4U9nNLCDkvk= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=gTZR9j5v; spf=pass (imf23.hostedemail.com: domain of rppt@kernel.org designates 139.178.84.217 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=1749831675; a=rsa-sha256; cv=none; b=8iuyTcUvbe6ZRqnkUZ/+CvRSHrhuTq6d4vlAoYkJfHUkl6n6MD6x2GAFFG4Jyu/HYgqIUU KMTEItvyxHE8tMYn0hdQXrsVniTofn4N3gHT/eKP+BD/TnWbMBbYaYX9VvRVpxPvCWTinX WD6MAGsPXZNwp3UCKmjn0rwdbGENukE= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id BD91E5C58EE; Fri, 13 Jun 2025 16:18:57 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 04966C4CEE3; Fri, 13 Jun 2025 16:21:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1749831674; bh=uZe79v3PpuM209FTqzpTU2PdWlQToBmu2a+dDo0xnGw=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=gTZR9j5vUqxTX+FdLcZFAkTMOQfxstLgp22Cxmz9jWmrsYp/Q2QVv0q0NTu/1cVox upey4uHrvINKd8Fmd8BBQu5Rw6uDMc+wlBYYCI0G1Hqc13TFps7Sd3r0kG3x4nhG94 2vVSIH+6au2xFh9ZvPO3SlSEop0sRdZRyCqvSls/p0j4Uf4ssbIKr54+NvCeRePjVo Xyv7dnFhwAsDU54g7BoA7zB7YhhG+eqnw2knkrnjxNw+aWLqp5DlS1l8WAhAKDynSU oOG7JYhu6L82a+15Z/0v3xrKBGf0KdailLX2QNtpL7tYe8OvxZTAeudamFhjpbFT5v s1HITNvZrCOpg== Date: Fri, 13 Jun 2025 19:21:07 +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-Queue-Id: 8C552140008 X-Rspamd-Server: rspam03 X-Rspam-User: X-Stat-Signature: tq1ag6a83aaq69t9ojdiqyhc6y183wqx X-HE-Tag: 1749831675-996656 X-HE-Meta: U2FsdGVkX19JGpY0jiWDe74Dn9FgDUQfTX2afvBEULBVeac5cgwtDNNz3U9z2kBMk1BGBKC3KeonUpY78sZp9ZNB/1pQOwU4UTLykipw0CVBtslDWRFuzlmNBjZPRhg1+AY1NcsxhjGUSalzBAMvSD7yVoqeSON/dGLd7uNRNv8QQF/+ZOvcMZLx3/vY6XEvWgXAjteJtHyrZmhU4XHtCKodmGqeip9ZXmax6jKvLdUYjvSFqzOx3ii5TeqYOji3UlVx4CcDcGukkIZw+f8GnY1MAi4xz2KQdBdGTI5+84TqjLixdp+GWOnrZU3Y6+Ztx+5Br+S26N8m9EWUKfAV0j05d+vuW+3DLZOXo9FRT37sOssIXnTFGpzGbXbJWulK+CsRS7ZjsP0BAKtiUpAfMUW64FfdRvZo3cXyW77Ju5UnM7WiyggswWp9jsieCO/i9GvNdeC/4bj4TbaV+5DlG5BUZ2PSqA7DHklQ9VtiLmGITy1ewgBsoQ/avrWTZrvr3A6yBnJpf8gENYUUl8/PU1eOuLxi2H5EJrXurDfOMEKxJnTilq7Iv8hPUR/hPkFS5twgSBWO/BcxZARm8hglIwNxIVMkNvNruff5/L1veqo7qSsQqpf8G/nU+FVQLmuWWTZODH/Ws9c8HLvs2ujiveAJ94GoUs9JFnM4p//jOkW4BIAfa7RG05b5vi6PxpVn4Dz8aNvavGbQVMfngrBCj7V02nKTgJRyQ9RuF97yMcQclCHXsyI6dngYIfIfW0cQM1RDRjyUWZaKWlxFJ1Z0pIdwKk6T7DNFRbtBcAnBCziNRTPWWcbs/Ptaa9NZwokCWkbhhb+7poBwOet+KA7Cxq0w52ur3MrguPuDc8ck+8wgrNpWVwfJvLVjFoTLCwB4daiUNPihPg0+00XgmD4wCJ+oxrsz08N/CMpOmQWvTTvwLIXBIrutrfwSonuVkvMHFKV+Uqe2tAGnPldLmgX lT4IZPgw ALbgchXuhrEpRWGdreegvRLbL/FIvyD/B8+nqPo3iA3KPSP6staQms+LtxuhoOZSA92ZaS5Q24wiwkgncTUksWzvQZeEegEwdsWgMiE3u8ZpwdbZrG4JodTMyRMyOx//krfZy9bFregNnH8AQAnvoxiGDUthcsF8WOkMgwY4eTJprIlS7M4MGaiYRhcWYVElpuGz4UFbb9eEEZto8X1qLAICVC6ymxQociM4jOlX34v1MoEj4KxcoDoF7foax0YwhEpNVluUV6O138OInnl4YyQHefKNYU562O6vnqvR7VPTDJqA= 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 Fri, Jun 13, 2025 at 04:22:32PM +0200, Pratyush Yadav wrote: > On Wed, Jun 11 2025, Mike Rapoport wrote: > > > 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 :) > > Oh, right. Using the wrong node completely throws > early_page_initialised() off. > > > > > What might work here is > > > > pfn = page_to_pfn(page); > > __init_page_from_nid(pfn, early_pfn_to_nid(pfn)); > > Yep, that works. Although this would do early_pfn_to_nid() for each page > so it isn't very efficient. And we also need to make sure memblock does > not go away. Yeah, that's far from ideal. Let's just gate KHO on !CONFIG_DEFERRED_PAGE_STRUCT_INIT for now. > >> 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); > >> } > >> > >> [...] > >> > [...] > > -- > Regards, > Pratyush Yadav -- Sincerely yours, Mike.