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 83540C677C4 for ; Wed, 11 Jun 2025 13:15:37 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 122866B008A; Wed, 11 Jun 2025 09:15:37 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 0D3FC6B008C; Wed, 11 Jun 2025 09:15:37 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id F2C7A6B0092; Wed, 11 Jun 2025 09:15:36 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id D5E796B008A for ; Wed, 11 Jun 2025 09:15:36 -0400 (EDT) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 4F8C81D6C42 for ; Wed, 11 Jun 2025 13:15:36 +0000 (UTC) X-FDA: 83543166672.08.50ABF04 Received: from mail-qt1-f172.google.com (mail-qt1-f172.google.com [209.85.160.172]) by imf11.hostedemail.com (Postfix) with ESMTP id 5B24940009 for ; Wed, 11 Jun 2025 13:15:34 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=soleen-com.20230601.gappssmtp.com header.s=20230601 header.b=ToDoTknS; dmarc=pass (policy=none) header.from=soleen.com; spf=pass (imf11.hostedemail.com: domain of pasha.tatashin@soleen.com designates 209.85.160.172 as permitted sender) smtp.mailfrom=pasha.tatashin@soleen.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1749647734; a=rsa-sha256; cv=none; b=SHjd7d305QSlNlP0qf0j06Bc5Xu0/4KBQWdVw/fmW+7LgO1MzoMLxLsN0Bc/u3FIGkPc34 gFw7XdShhjN2z39Sa+IEJ1ihKSof11J3ycOt82MxH5JiEfNNJVKYXSaEbiDbCP927MTxQ3 PtLIJfvekryFYoad5CdyWhJOYxem94k= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=soleen-com.20230601.gappssmtp.com header.s=20230601 header.b=ToDoTknS; dmarc=pass (policy=none) header.from=soleen.com; spf=pass (imf11.hostedemail.com: domain of pasha.tatashin@soleen.com designates 209.85.160.172 as permitted sender) smtp.mailfrom=pasha.tatashin@soleen.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1749647734; 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=Bx+QJSwdqHmxmjJfWKsN6eCcQk7vmKe/DJTvo5pGcrg=; b=Etp1IhYxlARkgP1O3RD2+BhDbtOTio4VTUPKaE+Tp9OsTEfWKotgrmSQAyWAprr88I1VeK VuxrbIGnBshBfif2vLS1l+A4bsG/oaaWDV/HFnz5yM9E/pFLg/8dDxbfwZrSq9feasaq+O XRHFCc+Jbv+XuZZht2PK/yQXsX60148= Received: by mail-qt1-f172.google.com with SMTP id d75a77b69052e-4a442a3a2bfso117085721cf.1 for ; Wed, 11 Jun 2025 06:15:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=soleen-com.20230601.gappssmtp.com; s=20230601; t=1749647733; x=1750252533; darn=kvack.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=Bx+QJSwdqHmxmjJfWKsN6eCcQk7vmKe/DJTvo5pGcrg=; b=ToDoTknSMcKeb6NW7wjfCKEv9AlBoE7zp+deAxDoHhrTxKKeNT9b4seV9SV633Njb3 d4MuSjtPzKUiJpPZgJJWhKh1nemjktudO27xl/S5HeU3w8nnNMDKuS+ZlG3+HSWTQFZR nBn5lVfl/ta84mnHrLoSx1zFKq8DlRtCx0KnhQl3WgLGhF8wC8LK02SiKU8FQKJQEFo5 39JFxZYSE3bPn9aWWSLOS6UngAR119NQUBW29h+YSei7V64YA7dkAWC9B3XwG+rCALTc joYZxiPh0FCtCC/dsfE/Wduo7k78qVvXod2mdsXEgqvMegZbiF8iltD/uWIGiEQJYTPk IK/g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1749647733; x=1750252533; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Bx+QJSwdqHmxmjJfWKsN6eCcQk7vmKe/DJTvo5pGcrg=; b=TFUs7tRV0foyW+UEgEufJHd4ir4I3DOga21OomUOX7skqGBnlHukHiFoileZ16RXwn aGruPJnFnX8/13LnQakIX1ClK5pDEfUQorJB1+hCjJwJy8mStzJ3UBcz2iXaYpAQ8N7n GHdp8pnJLtMrzJtn5knJORYriZge4J6MqrVVslXREAChmmCIquJRigBOeCSE1TRw6yIY /WoI3zf9PLKDksPoD4WBBkEipEXRorZSaWEpsxyuEsIKhtx2AnLDsY/evJ4JqksHi5dw dcI0MGCsaWRJekHkipsfRGuphL7WEU62KBOW3WK6pCWg7E3tTU52tqQGXieoPgXSBoFl a4hA== X-Forwarded-Encrypted: i=1; AJvYcCXc4oc451J6CtL20/taU7xIBcKdfqIRwhJpOcTbZoGqTRadQ0C3f4UtyCWFKfp32NBYmutjbIV3fA==@kvack.org X-Gm-Message-State: AOJu0YwbKqVXeFRcAW8Zx4OFCb0BOCQ0tHAXNk36NgHAoIFlHqz1Wkpm jpKbxt9WXx32B9NoEXHnyxLeMZTEcpQvZjVmS03y++/GHh8xZ+pPwTbcAncvq1/YL3tAqWUeDEL u37GUBoRfxY8zdSWz3RKOPJd6aPL0ywGS92IYRlb1Nw== X-Gm-Gg: ASbGnct+GHyoR3YXXX+Cc5YDBiBGle7QuX9isS3FDmyk/zfJ7kV/g+b24FqwckkpCoW 6X7FrSiam/TJx2KUuY85dXclLbVsfZOyHDKiAgIIMzOLWiAVo08B0+sXxP3Byumsx7DMTQJhpw/ 7HPq54c825AmiGGd6usYk4AzSPBvuTfV02ZzAAWccN X-Google-Smtp-Source: AGHT+IHkj+/aNhbEvJ86/UIGCIx4gF59E2n+BXlPkeJ7OIUIHWfiwDNSQWWRAB99p0osoYKzpjGZCD42Uxr3WOr2ynM= X-Received: by 2002:ac8:6904:0:b0:4a3:d015:38ae with SMTP id d75a77b69052e-4a714bc0ca3mr46790171cf.23.1749647733254; Wed, 11 Jun 2025 06:15:33 -0700 (PDT) MIME-Version: 1.0 References: <20250605171143.76963-1-pratyush@kernel.org> In-Reply-To: From: Pasha Tatashin Date: Wed, 11 Jun 2025 09:14:55 -0400 X-Gm-Features: AX0GCFvQtpuz31GBIWBQSIsnOG-xC0O1tIo1gpevWjl4XB1iep4R0wvTpWnG7zw Message-ID: Subject: Re: [PATCH] kho: initialize tail pages for higher order folios properly To: Pratyush Yadav Cc: Mike Rapoport , Alexander Graf , Changyuan Lyu , Andrew Morton , Baoquan He , kexec@lists.infradead.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Michal Clapinski Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Rspamd-Server: rspam01 X-Stat-Signature: goh4jxbr87o9ozqa5hamrrzaonqfrict X-Rspamd-Queue-Id: 5B24940009 X-Rspam-User: X-HE-Tag: 1749647734-87458 X-HE-Meta: U2FsdGVkX1/YOumOo4KJbLlP7NGwQGTVBAWabtyDGTVyUEHaLpm5BenT6n5N85dYYkozIRs4RaYBrLaRgEhs0VhevHc2TMIvax3RL4HT1UWbJvorf2+yN0rlPP3vNziOHfua5LAYB6bpgWRett++efsJRFyAd6QlNbA2Negi63xTyG0sTt+Dqp1eof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KhlgeA== 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 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, ther= e > >> > 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 i= t'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 r= ange, > >> with kho we are talking about some random pages. If we preinit them ea= rly, > >> 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. Pasha > > -- > Regards, > Pratyush Yadav