From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-ej1-f74.google.com (mail-ej1-f74.google.com [209.85.218.74]) (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 4E4033E1CE3 for ; Thu, 23 Apr 2026 12:25:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.74 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776947152; cv=none; b=LQo2AeTJHZ95IOC49mGhah8C1+GgpeaHqXdd3DWdjIbxidaLtIPomTv9vNFdwHex42KAx1xrJDiydIOSrEHDE1O8iCAmn+HBieIndzSFJ9twC8u9aXhOBnmGkmI62gCFA4wP2ZyDnb6mB9Q5pTPXeinvM6+arPEz+jv1uLN868k= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776947152; c=relaxed/simple; bh=yKbbh+GVWdXz2XMnsWvS0O1cZ1VqsU3bBCaO7GouAQA=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=g6xIFqierv1ePcNiid7YBhNa3pwXv+X0YlOVQQDw4M9Nv1cf5fI8rtX1UD9yw77N+vGmqZvRLeuZXyyUk6QbTAWXaJF+aCYkwPKLQTbK7AIq+C1UytL62Y6AhI3NG4chFUCXeSwlRnvHMYyV8HcLi4P2vrlnpTTPeUQf13XFV3M= 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=dcrY3dUS; arc=none smtp.client-ip=209.85.218.74 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="dcrY3dUS" Received: by mail-ej1-f74.google.com with SMTP id a640c23a62f3a-b8ff07df5e4so533152366b.3 for ; Thu, 23 Apr 2026 05:25:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1776947150; x=1777551950; 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=jpb9j7QMI3LnBirxCYRwTt7/Lt/BiQh7xQw1xaxHQCg=; b=dcrY3dUSw8HNHmwhM+UE4FCZGO/XsAkEo6n8T37bJsRA4Jf3a3FRUOVDHNGFRG1pLR l93iylDD5YLKQQ8c4qgXALNwvGqjB5pPbBOPmBqBSxuoyqUU+Bt1HAeFlLnJtibxuosT TMteympB1mFtyCIiwbsYJGdB0YIpO8GiFb8pFcrNB4dkTYpcZCFymUxi2O1tSpOxsNBX BViVZUe0qoQLI+0cCQYVxCLLLihUiydvsQJL8L3bv2ar92G9kovnyBeM4Eg3W4vcRdB1 Yino7LRFsI50AeNE4aZYTdmMjscG3rCmSt+6XScXyjxK9ezTZfldXU8I2oCBoALwm+cC Kr7A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1776947150; x=1777551950; 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=jpb9j7QMI3LnBirxCYRwTt7/Lt/BiQh7xQw1xaxHQCg=; b=YBdurtepnyJQ7LgLkVISRhRBqgs2foW/zXd6bNDI6RCLVAuPuRo7jGAUXUWnwrrNnQ eyXMkrn3g6c/Z9JmF2yWya1Te74/psusC9v6t8Vi8XCZMtEdSuLv3BmtD6UE1wqGX6oG wbj1HJC9dtGRwL85o0ZCUcXSUBsyzk7q+UTdjP22OvSf1EQFXRq+oZQxQDpi7UI9roSH VQWdfScRlDcZY7uekOb6iWFFL1LazZGWQOSV0UbE1iD22YI+dKMtuwEi8s8H3R/qALVt myft83lJx1C/iM/EkcG2sfSSF3fgdk1VKQq9gmams7PdFoMUzQrksZ8F28x0f0y+q4qy sRBA== X-Gm-Message-State: AOJu0YxGHREuwg7HBc9W90Ay508Yo9yh9I41Eh1ThK0dK2jmJWWvWY5b fzODVrji2gAAN8MFscu6OpGSn74x6JwFENSK9UiQaWj90cLoFaBvjGgB2k8zS0gvcf4g9WbDM4v kGKTMV5bCtiVW+DQd7QaAkg== X-Received: from edber5.prod.google.com ([2002:a05:6402:4485:b0:660:af38:c618]) (user=mclapinski job=prod-delivery.src-stubby-dispatcher) by 2002:a17:907:8e0e:b0:b9d:1a1c:a664 with SMTP id a640c23a62f3a-ba41a91e25bmr1360621266b.40.1776947149314; Thu, 23 Apr 2026 05:25:49 -0700 (PDT) Date: Thu, 23 Apr 2026 14:25:37 +0200 In-Reply-To: <20260423122538.140993-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: <20260423122538.140993-1-mclapinski@google.com> X-Mailer: git-send-email 2.54.0.rc2.533.g4f5dca5207-goog Message-ID: <20260423122538.140993-3-mclapinski@google.com> Subject: [PATCH v9 2/3] 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.rc2.533.g4f5dca5207-goog