From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-lf1-f73.google.com (mail-lf1-f73.google.com [209.85.167.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 975D33A640C for ; Thu, 16 Apr 2026 11:07:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.73 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776337632; cv=none; b=KHnOehwH2WnoB9MG5Bmy1Pjyvnhxh7YQ2TuoMwOhOgisCcbQmcS+zsmo+kImTRqN3Ub2u/xiFwqJDM8Yx70IjDpcSatTQkBG9W/AaPefOL7ZLd+JpRiDlWX9HWMzv/RM+d7eGYyG19WtCZoCQLLvU7mqzmya0k22jULqI1Ez4O0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776337632; c=relaxed/simple; bh=QGhcCCxRkl4V3MUrGT03VcZglC6D8UAjz0XhG0rEh3o=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=L13aHxJKKl5+i3DvtS8FGztTN+YoEV3d/TfhABY0htNFtsmSvKakEgsMNzIE+So8LuJH+RrkpnnAmkKHhtF5HjSvnnmgOf/rAGrj7Kve1incKIG+tjifg+rN127iXFeunORlpiDjXN4LtxEiqgTEQhVeiHijpEGZZyNKHEJpxi8= 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=n2LN0mbp; arc=none smtp.client-ip=209.85.167.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="n2LN0mbp" Received: by mail-lf1-f73.google.com with SMTP id 2adb3069b0e04-5a3fdf4491bso3426827e87.3 for ; Thu, 16 Apr 2026 04:07:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1776337628; x=1776942428; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=83G/JFf5TbAu/dcy7wbV8ZkTGlvEgBosGu//G/NV30c=; b=n2LN0mbpHcFEzEboi8cR5NSBb/WztnYvR/SABNEgYNV64laISZnZVqnOQMr5OqreN6 t1+eFNq5dtLnrd7liYUaBAwaHzo73vmRWnNvUPYmeftjwc2rYo+50GQvLtK4Ja2Wf+ne Zj/0T3/B9c8AZa7g1qFSXccL3GiSCAA6HM2Ugu5+G0U+4XCav/B7PdJZAIxBrFImuVId XJGRhl32NJyEdWSs+verr94fLv1QOr1D+UzhyJacoq7VaSVxVtmNPyHGUwhWrXZyg+b5 7ElsalThOVkuynRuhJRuHwbe8A26LnaXpv8NxiZdvpYxfkd/J/P3hRIxBsg3kqwpX05u ZZeg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1776337628; x=1776942428; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=83G/JFf5TbAu/dcy7wbV8ZkTGlvEgBosGu//G/NV30c=; b=N7iN+rIT3aaW4fCvgqs8YewWc1hgTwEdFuEWaqTRjTsTUBri7QCPg1mhlZGWB5sM4p kmtcQ8ETEPiWOctmHG2hbPZbLN9dlFMktSdQrFsQuS+bTUHEDO48H2vdt4fw9KhknlG3 GbhZQor1JZgdWbBF3oluobJLylhVylMchfrX4Dem/fQzi/V7nWzIhFmDLGgjMaUM51lM jaxy3pAJi31xlpmAjHn6P2R79DTChbBuHqZMojnN9PhPCX4SCeMUTwgEHeiDowLND4j2 1O2qu77Nc3Uz33/rT87N2XeiZxllSoL3Bu8DiBb6g8ilQAfcLG03/NuYbDWiwjF5zt8c 6SzA== X-Gm-Message-State: AOJu0YwOPSvFO7941GGom3BdwmqobY5htDxy1XYGNbWOncZhLvesPNUL f3wxtgjFhMsCLLo0GlojTUQMy9Nt+VX9/q1ymGXn35WDSusLp2nS7lzliN/+KxVpqdbts6Ev2we ckf2eMedW15gVv+tZXxKpSQ== X-Received: from lfaz26.prod.google.com ([2002:a05:6512:21fa:b0:5a4:5d2:9524]) (user=mclapinski job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6512:b99:b0:5a1:2332:68f with SMTP id 2adb3069b0e04-5a3ef6e2732mr7016523e87.0.1776337627236; Thu, 16 Apr 2026 04:07:07 -0700 (PDT) Date: Thu, 16 Apr 2026 13:06:54 +0200 In-Reply-To: <20260416110654.247398-1-mclapinski@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260416110654.247398-1-mclapinski@google.com> X-Mailer: git-send-email 2.54.0.rc1.555.g9c883467ad-goog Message-ID: <20260416110654.247398-3-mclapinski@google.com> Subject: [PATCH v8 2/2] kho: make preserved pages compatible with deferred struct page init From: Michal Clapinski To: Evangelos Petrongonas , Pasha Tatashin , Mike Rapoport , Pratyush Yadav , Alexander Graf , Samiullah Khawaja , kexec@lists.infradead.org, linux-mm@kvack.org Cc: linux-kernel@vger.kernel.org, Andrew Morton , Vlastimil Babka , Suren Baghdasaryan , Michal Hocko , Brendan Jackman , Johannes Weiner , Zi Yan , Michal Clapinski 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, kho_preserved_memory_reserve() 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 the struct page is already initialized. Signed-off-by: Evangelos Petrongonas Co-developed-by: Michal Clapinski Signed-off-by: Michal Clapinski Reviewed-by: Pratyush Yadav (Google) Reviewed-by: Pasha Tatashin Reviewed-by: Mike Rapoport (Microsoft) --- 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 menu "Live Update and Kexec HandOver" - depends on !DEFERRED_STRUCT_PAGE_INIT 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_handover.c index a507366a2cf9..d5718bef6d4d 100644 --- a/kernel/liveupdate/kexec_handover.c +++ b/kernel/liveupdate/kexec_handover.c @@ -473,6 +473,31 @@ struct page *kho_restore_pages(phys_addr_t phys, unsigned long nr_pages) } EXPORT_SYMBOL_GPL(kho_restore_pages); +/* + * With CONFIG_DEFERRED_STRUCT_PAGE_INIT, struct pages in higher memory regions + * may not be initialized yet at the time KHO deserializes preserved memory. + * KHO uses the struct page to store metadata and a later initialization would + * overwrite it. + * Ensure all the struct pages in the preservation are + * initialized. kho_preserved_memory_reserve() marks the reservation as noinit + * to make 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 = PHYS_PFN(phys); + int nid; + + if (!IS_ENABLED(CONFIG_DEFERRED_STRUCT_PAGE_INIT)) + return pfn_to_page(pfn); + + nid = early_pfn_to_nid(pfn); + for (unsigned long i = 0; i < (1UL << order); i++) + init_deferred_page(pfn + i, nid); + + return pfn_to_page(pfn); +} + static int __init kho_preserved_memory_reserve(phys_addr_t phys, unsigned int order) { @@ -481,7 +506,7 @@ static int __init kho_preserved_memory_reserve(phys_addr_t phys, u64 sz; sz = 1 << (order + PAGE_SHIFT); - page = phys_to_page(phys); + page = kho_get_preserved_page(phys, order); /* Reserve the memory preserved in KHO in memblock */ memblock_reserve(phys, sz); -- 2.54.0.rc1.555.g9c883467ad-goog