From nobody Thu Apr 2 17:38:56 2026 Received: from mail-ej1-f73.google.com (mail-ej1-f73.google.com [209.85.218.73]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 76F932D877F for ; Wed, 11 Feb 2026 17:40:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.73 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770831603; cv=none; b=RCpsRSeP1ulwfGM/EUxOOMAyz8+um73K7PDeZEM7JGkInCEwmNJkQWZae+i7cTOjSd2YypOI7kdWDD6VoHKOh+IZeqQ7+0y00s+CsimQAimFKZ9IY2x2DROYiQYjW8SrpZCYBeLLInYMwydtzce+3yBhTSXPHuJa/bH5oBuWvmE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770831603; c=relaxed/simple; bh=90+FEIYnPDvOZF8Cozi4/J3cZ5aaENlCbMaolQg1VHw=; h=Date:Mime-Version:Message-ID:Subject:From:To:Cc:Content-Type; b=nA0rESSU2UboHffl693lpMzdK8RReQoFkaLY8TVEwujujWrkWTofvnRSmPEpwY4L3enfRhCp4BZ8nITrwhj0hgiOuINBYgDm00AJjp6Bj49TiRH+t85ILe0XlngRIhkxgqyVjyKSvbAvaCvMTRE5IR/diTVh9vxli8YEJruFrZQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--mclapinski.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=u4/B0M2L; arc=none smtp.client-ip=209.85.218.73 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--mclapinski.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="u4/B0M2L" Received: by mail-ej1-f73.google.com with SMTP id a640c23a62f3a-b88649b11d2so839692666b.3 for ; Wed, 11 Feb 2026 09:40:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1770831600; x=1771436400; darn=vger.kernel.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=dlNHJZ4DB/YIFPcTP8iAwpEYyWUng6cE6zKvxjI6tZ8=; b=u4/B0M2LTLQGpkMcMTczwqYfzWVoDaIyydIpCSg9hHfEvycBUKfDd1dCfCw9D6c3Fm c8n+YE9CmELhIT8TwPoW0AzjPW9X43j9Q0L8idecV/4LN65PEpj6lT6UcJQTwvqVYM3o D3HFmv5utw7Jk4SOKNV2GEqBZf9oVAMW09xvx60E0knicdagy85l9U/slXNLqeOFpJem nadok+cqAbVRHQbRRYKFCvhMrFIrZHgDlKbfNG42nMrj51wGRA1M9olG9998m84MKKIl h/xshN/SjVI5tfmN6/egJTHeV2z/ZuDVuP6wTVNDPy/nKqWDVC+7YNzkGArx9gZnXmzC +dHg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1770831600; x=1771436400; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=dlNHJZ4DB/YIFPcTP8iAwpEYyWUng6cE6zKvxjI6tZ8=; b=lRf5geC9TeTtKZzsXCdBGTl6y1fN0kZmZb78AmgDn1eFAJXe+vDMHigQeprpjLMRPC PZHqM6WyhoE82+OmuoQOLBqsgZHYstOgRApYgDPYRXYYHFU7bhT/Emz2hB5m3fFTQfz4 6fqDpCIc7xKdjShkMk6v14RqKqioSN+UECKY9eOt3XtuiAnRZbcmyLN7vdIGxfRrAUry Y2GAZVo0hbJ8HKR29UfL2tS89kq9Te5NyaYt5aOqo3VR7Ih+JkVwkXj46YCWYc5vKab0 6MmItphSNU1MhV8h/iwTHoJmhp2nTCkPylRNv36Tk6hTbJVcAkoOJzKU1IeHyc5kvxPa aBDQ== X-Gm-Message-State: AOJu0Yz/pwzbxtqE5mwqccWs3Efkkfe2PlynuHiH4IRc780oqFg7lsw/ 2KX+973AeYk2glCWXNlEpufJDVawYB8sOWS8zL8MLcAVZqcfvnd2fTTkcyFePQBy7ZRxEvTqEDY Ix5GrH1fcW52Wr76742fgTg== X-Received: from edvj14.prod.google.com ([2002:aa7:de8e:0:b0:64b:aad7:d741]) (user=mclapinski job=prod-delivery.src-stubby-dispatcher) by 2002:a17:907:930a:b0:b88:463e:b55f with SMTP id a640c23a62f3a-b8f6a8e08c2mr193618466b.6.1770831599663; Wed, 11 Feb 2026 09:39:59 -0800 (PST) Date: Wed, 11 Feb 2026 18:39:54 +0100 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 X-Mailer: git-send-email 2.53.0.239.g8d8fc8a987-goog Message-ID: <20260211173954.2091119-1-mclapinski@google.com> Subject: [PATCH v3] kho: add support for deferred struct page init From: Michal Clapinski To: Evangelos Petrongonas , Pasha Tatashin , Mike Rapoport , Pratyush Yadav , Alexander Graf , kexec@lists.infradead.org, linux-mm@kvack.org Cc: linux-kernel@vger.kernel.org, Andrew Morton , Michal Clapinski Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Evangelos Petrongonas When CONFIG_DEFERRED_STRUCT_PAGE_INIT is enabled, struct page 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. Signed-off-by: Evangelos Petrongonas Signed-off-by: Michal Clapinski Reviewed-by: Pratyush Yadav (Google) Reviewed-by: Mike Rapoport (Microsoft) Reviewed-by: Pasha Tatashin --- v3: - changed commit msg - don't invoke early_pfn_to_nid if CONFIG_DEFERRED_STRUCT_PAGE_INIT=3Dn v2: - updated a comment I think we can't initialize those struct pages in kho_restore_page. I encountered this stack: page_zone(start_page) __pageblock_pfn_to_page set_zone_contiguous page_alloc_init_late So, at the end of page_alloc_init_late struct pages are expected to be already initialized. set_zone_contiguous() looks at the first and last struct page of each pageblock in each populated zone to figure out if the zone is contiguous. If a kho page lands on a pageblock boundary, this will lead to access of an uninitialized struct page. There is also page_ext_init that invokes pfn_to_nid, which calls page_to_nid for each section-aligned page. There might be other places that do something similar. Therefore, it's a good idea to initialize all struct pages by the end of deferred struct page init. That's why I'm resending Evangelos's patch. I also tried to implement Pratyush's idea, i.e. iterate over zones, then get node from zone. I didn't notice any performance difference even with 8GB of kho. I repeated Evangelos's testing: In order to test the fix, I modified the KHO selftest, to allocate more memory and do so from higher memory to trigger the incompatibility. The branch with those changes can be found in: https://git.infradead.org/?p=3Dusers/vpetrog/linux.git;a=3Dshortlog;h=3Dref= s/heads/kho-deferred-struct-page-init --- kernel/liveupdate/Kconfig | 2 -- kernel/liveupdate/kexec_handover.c | 27 ++++++++++++++++++++++++++- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/kernel/liveupdate/Kconfig b/kernel/liveupdate/Kconfig index 1a8513f16ef7..c13af38ba23a 100644 --- a/kernel/liveupdate/Kconfig +++ b/kernel/liveupdate/Kconfig @@ -1,12 +1,10 @@ # SPDX-License-Identifier: GPL-2.0-only =20 menu "Live Update and Kexec HandOver" - depends on !DEFERRED_STRUCT_PAGE_INIT =20 config KEXEC_HANDOVER bool "kexec handover" depends on ARCH_SUPPORTS_KEXEC_HANDOVER && ARCH_SUPPORTS_KEXEC_FILE - depends on !DEFERRED_STRUCT_PAGE_INIT select MEMBLOCK_KHO_SCRATCH select KEXEC_FILE select LIBFDT diff --git a/kernel/liveupdate/kexec_handover.c b/kernel/liveupdate/kexec_h= andover.c index b851b09a8e99..3bc14f3d7690 100644 --- a/kernel/liveupdate/kexec_handover.c +++ b/kernel/liveupdate/kexec_handover.c @@ -457,6 +457,31 @@ static int kho_mem_serialize(struct kho_out *kho_out) return err; } =20 +/* + * With CONFIG_DEFERRED_STRUCT_PAGE_INIT, struct pages in higher memory re= gions + * may not be initialized yet at the time KHO deserializes preserved memor= y. + * KHO uses the struct page to store metadata and a later initialization w= ould + * overwrite it. + * Ensure all the struct pages in the preservation are + * initialized. deserialize_bitmap() marks the reservation as noinit to ma= ke + * sure they don't get re-initialized later. + */ +static struct page *__init kho_get_preserved_page(phys_addr_t phys, + unsigned int order) +{ + unsigned long pfn =3D PHYS_PFN(phys); + int nid; + + if (!IS_ENABLED(CONFIG_DEFERRED_STRUCT_PAGE_INIT)) + return pfn_to_page(pfn); + + nid =3D early_pfn_to_nid(pfn); + for (int i =3D 0; i < (1 << order); i++) + init_deferred_page(pfn + i, nid); + + return pfn_to_page(pfn); +} + static void __init deserialize_bitmap(unsigned int order, struct khoser_mem_bitmap_ptr *elm) { @@ -467,7 +492,7 @@ static void __init deserialize_bitmap(unsigned int orde= r, int sz =3D 1 << (order + PAGE_SHIFT); phys_addr_t phys =3D elm->phys_start + (bit << (order + PAGE_SHIFT)); - struct page *page =3D phys_to_page(phys); + struct page *page =3D kho_get_preserved_page(phys, order); union kho_page_info info; =20 memblock_reserve(phys, sz); --=20 2.53.0.239.g8d8fc8a987-goog