From nobody Thu Jun 11 00:35:07 2026 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 32A6A3ED118 for ; Thu, 23 Apr 2026 12:25:47 +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=1776947150; cv=none; b=qVVQrA5AtxTL2lx7Hn8F0URc0lKidwS6Qbm3NpPFYA9knToDf7x08brP3PEijY8I3MKjiDVQRwrNb2mnywcTOWZicrcfW7n9+PAYYy/kXDKVhnsIzNb/wXmL9EmGHKPGFo4psUlsHA+Q84KSTuxYBmvk+mffclMg7Zqe9Z1xylg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776947150; c=relaxed/simple; bh=gizuOtFOdoA2AhfjYidXNAlj09VnnUm+FYgL8jnZqT4=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=U9iUPURM7q5yXCQG+WGFjgar/7bVn8c9bxwmyAbVaqFyKV8FTFjgfgJy5WemFUavmRk8l33X2zdoWnU4QcnPbw/VFiFkXQCDEV8+TPZk9hiVxWATrEDnZMCZk6r5A7CGBgT36hXd40U3TTgik+n00M7riiPXnp5WT2CAV6uZa/I= 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=VL6uq0B3; 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="VL6uq0B3" Received: by mail-ej1-f74.google.com with SMTP id a640c23a62f3a-ba7eadca2f1so315619466b.0 for ; Thu, 23 Apr 2026 05:25:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1776947146; x=1777551946; 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=n+Dh7KSlcp6Lw1KRHGg/D7cc8wD+JiYC9HaMh3gpNxs=; b=VL6uq0B3ibzMoXubF6z8aBofqzQQ5zvQg/ivUjA3eUnkY+LXXJ0aSKJoJpdRg8hYHp 6R0Yqk7PC4n9rBFnytsMN51bZuIt8ocvsNgkugb4BBtBOJ+eIJ1rU5iIfwQaivUOxgIv JnvwNn9QGNgTaQrkSMG9VS5KQiNyvb4wBQCfMj3xgjXsZpXWF3QqJYEPPvGukqnEsfsk LUvYtXmAyUKH/DlJpjZCnQOHamY9hCpZYVex+J/GRym6qCyo8uCXpnzvaxWLFVShqNhf i8KmWdTSfXKldswKuE5Ibr+shLb5nKf9atNLG8aLS4tRtm4isxwp0IWhH74xo9GDO8dK 2kaw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1776947146; x=1777551946; 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=n+Dh7KSlcp6Lw1KRHGg/D7cc8wD+JiYC9HaMh3gpNxs=; b=L9nT/yMIJ9dt9GSJuvI0wHtpeb0+x2eQtkYobFlggFzcOnQc28Db9LRd0Ogj/tiox7 1D32jTaObxXd54aqSw7Fjp3zu/j6P15CC3MkV1G8/ClOvDoE+QMYK6emCFOGTTqY+BFO gW0+6GG6bFwu808l/x1zMOilaYm6/NgS9d9+shZgD1rTVgbAPtK7TP+DnzSN1gA6GNEo i6PjROmKVDgc92yHENyybwyUczOw9ZWNCmltfFiKYmGRoC7zb9MStYuAmuwcACvp3FoK 5ae4yMBQ9JQaVD+S7WXOrjeY3cX1rp0UQkAdhtWW6Td+p9Bni9om84BxHS0+jlaaifMK T3Wg== X-Gm-Message-State: AOJu0Yxy0Fdyq0K9NPQ2ATpNUC/6XmU0Hqguk3vwPFF8/sB3zwbitafQ 8+HXooiIqS21FWQ6hjT7o6QqSRaeTv3bvV3/hyNwmcaeW5ro1Uotsmac0wQ8QtzWN8swVuoAlv/ Mz0oVGJ9874L3/U/8AaKv1g== X-Received: from ejchd40.prod.google.com ([2002:a17:907:96a8:b0:b9c:3f30:f4d9]) (user=mclapinski job=prod-delivery.src-stubby-dispatcher) by 2002:a17:907:d03:b0:baa:2d37:cbf9 with SMTP id a640c23a62f3a-baa2d37ce1bmr465780066b.1.1776947145985; Thu, 23 Apr 2026 05:25:45 -0700 (PDT) Date: Thu, 23 Apr 2026 14:25:36 +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-2-mclapinski@google.com> Subject: [PATCH v9 1/3] kho: fix deferred initialization of scratch areas 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-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Currently, if CONFIG_DEFERRED_STRUCT_PAGE_INIT is enabled, kho_release_scratch() will initialize the struct pages and set migratetype of KHO scratch. Unless the whole scratch fits below first_deferred_pfn, some of that will be overwritten either by deferred_init_pages() or memmap_init_reserved_range(). To fix it, make memmap_init_range(), deferred_init_memmap_chunk() and __init_page_from_nid() recognize KHO scratch regions and set migratetype of pageblocks in those regions to MIGRATE_CMA. Co-developed-by: Mike Rapoport (Microsoft) Signed-off-by: Mike Rapoport (Microsoft) Signed-off-by: Michal Clapinski Reviewed-by: Mike Rapoport (Microsoft) Reviewed-by: Pasha Tatashin Reviewed-by: Pratyush Yadav (Google) --- include/linux/memblock.h | 21 +++++++++-- kernel/liveupdate/kexec_handover.c | 25 ------------- mm/memblock.c | 56 ++++++++++++------------------ mm/mm_init.c | 30 +++++++++------- 4 files changed, 58 insertions(+), 74 deletions(-) diff --git a/include/linux/memblock.h b/include/linux/memblock.h index b0f750d22a7b..5afcd99aa8c1 100644 --- a/include/linux/memblock.h +++ b/include/linux/memblock.h @@ -613,11 +613,28 @@ static inline void memtest_report_meminfo(struct seq_= file *m) { } #ifdef CONFIG_MEMBLOCK_KHO_SCRATCH void memblock_set_kho_scratch_only(void); void memblock_clear_kho_scratch_only(void); -void memmap_init_kho_scratch_pages(void); +bool memblock_is_kho_scratch_memory(phys_addr_t addr); + +static inline enum migratetype kho_scratch_migratetype(unsigned long pfn, + enum migratetype mt) +{ + if (memblock_is_kho_scratch_memory(PFN_PHYS(pfn))) + return MIGRATE_CMA; + return mt; +} #else static inline void memblock_set_kho_scratch_only(void) { } static inline void memblock_clear_kho_scratch_only(void) { } -static inline void memmap_init_kho_scratch_pages(void) {} +static inline bool memblock_is_kho_scratch_memory(phys_addr_t addr) +{ + return false; +} + +static inline enum migratetype kho_scratch_migratetype(unsigned long pfn, + enum migratetype mt) +{ + return mt; +} #endif =20 #endif /* _LINUX_MEMBLOCK_H */ diff --git a/kernel/liveupdate/kexec_handover.c b/kernel/liveupdate/kexec_h= andover.c index 18509d8082ea..a507366a2cf9 100644 --- a/kernel/liveupdate/kexec_handover.c +++ b/kernel/liveupdate/kexec_handover.c @@ -1576,35 +1576,10 @@ static __init int kho_init(void) } fs_initcall(kho_init); =20 -static void __init kho_release_scratch(void) -{ - phys_addr_t start, end; - u64 i; - - memmap_init_kho_scratch_pages(); - - /* - * Mark scratch mem as CMA before we return it. That way we - * ensure that no kernel allocations happen on it. That means - * we can reuse it as scratch memory again later. - */ - __for_each_mem_range(i, &memblock.memory, NULL, NUMA_NO_NODE, - MEMBLOCK_KHO_SCRATCH, &start, &end, NULL) { - ulong start_pfn =3D pageblock_start_pfn(PFN_DOWN(start)); - ulong end_pfn =3D pageblock_align(PFN_UP(end)); - ulong pfn; - - for (pfn =3D start_pfn; pfn < end_pfn; pfn +=3D pageblock_nr_pages) - init_pageblock_migratetype(pfn_to_page(pfn), - MIGRATE_CMA, false); - } -} - void __init kho_memory_init(void) { if (kho_in.scratch_phys) { kho_scratch =3D phys_to_virt(kho_in.scratch_phys); - kho_release_scratch(); =20 if (kho_mem_retrieve(kho_get_fdt())) kho_in.fdt_phys =3D 0; diff --git a/mm/memblock.c b/mm/memblock.c index a6a1c91e276d..01a962681726 100644 --- a/mm/memblock.c +++ b/mm/memblock.c @@ -1026,40 +1026,6 @@ int __init_memblock memblock_physmem_add(phys_addr_t= base, phys_addr_t size) } #endif =20 -#ifdef CONFIG_MEMBLOCK_KHO_SCRATCH -__init void memblock_set_kho_scratch_only(void) -{ - kho_scratch_only =3D true; -} - -__init void memblock_clear_kho_scratch_only(void) -{ - kho_scratch_only =3D false; -} - -__init void memmap_init_kho_scratch_pages(void) -{ - phys_addr_t start, end; - unsigned long pfn; - int nid; - u64 i; - - if (!IS_ENABLED(CONFIG_DEFERRED_STRUCT_PAGE_INIT)) - return; - - /* - * Initialize struct pages for free scratch memory. - * The struct pages for reserved scratch memory will be set up in - * memmap_init_reserved_pages() - */ - __for_each_mem_range(i, &memblock.memory, NULL, NUMA_NO_NODE, - MEMBLOCK_KHO_SCRATCH, &start, &end, &nid) { - for (pfn =3D PFN_UP(start); pfn < PFN_DOWN(end); pfn++) - init_deferred_page(pfn, nid); - } -} -#endif - /** * memblock_setclr_flag - set or clear flag for a memory region * @type: memblock type to set/clear flag for @@ -2533,6 +2499,28 @@ int reserve_mem_release_by_name(const char *name) return 1; } =20 +#ifdef CONFIG_MEMBLOCK_KHO_SCRATCH +__init void memblock_set_kho_scratch_only(void) +{ + kho_scratch_only =3D true; +} + +__init void memblock_clear_kho_scratch_only(void) +{ + kho_scratch_only =3D false; +} + +bool __init_memblock memblock_is_kho_scratch_memory(phys_addr_t addr) +{ + int i =3D memblock_search(&memblock.memory, addr); + + if (i =3D=3D -1) + return false; + + return memblock_is_kho_scratch(&memblock.memory.regions[i]); +} +#endif + #ifdef CONFIG_KEXEC_HANDOVER =20 static int __init reserved_mem_preserve(void) diff --git a/mm/mm_init.c b/mm/mm_init.c index f9f8e1af921c..eddc0f03a779 100644 --- a/mm/mm_init.c +++ b/mm/mm_init.c @@ -692,9 +692,11 @@ void __meminit __init_page_from_nid(unsigned long pfn,= int nid) } __init_single_page(pfn_to_page(pfn), pfn, zid, nid); =20 - if (pageblock_aligned(pfn)) - init_pageblock_migratetype(pfn_to_page(pfn), MIGRATE_MOVABLE, - false); + if (pageblock_aligned(pfn)) { + enum migratetype mt =3D + kho_scratch_migratetype(pfn, MIGRATE_MOVABLE); + init_pageblock_migratetype(pfn_to_page(pfn), mt, false); + } } =20 #ifdef CONFIG_DEFERRED_STRUCT_PAGE_INIT @@ -927,7 +929,8 @@ void __meminit memmap_init_range(unsigned long size, in= t nid, unsigned long zone static void __init memmap_init_zone_range(struct zone *zone, unsigned long start_pfn, unsigned long end_pfn, - unsigned long *hole_pfn) + unsigned long *hole_pfn, + enum migratetype mt) { unsigned long zone_start_pfn =3D zone->zone_start_pfn; unsigned long zone_end_pfn =3D zone_start_pfn + zone->spanned_pages; @@ -940,8 +943,7 @@ static void __init memmap_init_zone_range(struct zone *= zone, return; =20 memmap_init_range(end_pfn - start_pfn, nid, zone_id, start_pfn, - zone_end_pfn, MEMINIT_EARLY, NULL, MIGRATE_MOVABLE, - false); + zone_end_pfn, MEMINIT_EARLY, NULL, mt, false); =20 if (*hole_pfn < start_pfn) init_unavailable_range(*hole_pfn, start_pfn, zone_id, nid); @@ -957,6 +959,8 @@ static void __init memmap_init(void) =20 for_each_mem_pfn_range(i, MAX_NUMNODES, &start_pfn, &end_pfn, &nid) { struct pglist_data *node =3D NODE_DATA(nid); + enum migratetype mt =3D + kho_scratch_migratetype(start_pfn, MIGRATE_MOVABLE); =20 for (j =3D 0; j < MAX_NR_ZONES; j++) { struct zone *zone =3D node->node_zones + j; @@ -965,7 +969,7 @@ static void __init memmap_init(void) continue; =20 memmap_init_zone_range(zone, start_pfn, end_pfn, - &hole_pfn); + &hole_pfn, mt); zone_id =3D j; } } @@ -1970,7 +1974,7 @@ unsigned long __init node_map_pfn_alignment(void) =20 #ifdef CONFIG_DEFERRED_STRUCT_PAGE_INIT static void __init deferred_free_pages(unsigned long pfn, - unsigned long nr_pages) + unsigned long nr_pages, enum migratetype mt) { struct page *page; unsigned long i; @@ -1983,8 +1987,7 @@ static void __init deferred_free_pages(unsigned long = pfn, /* Free a large naturally-aligned chunk if possible */ if (nr_pages =3D=3D MAX_ORDER_NR_PAGES && IS_MAX_ORDER_ALIGNED(pfn)) { for (i =3D 0; i < nr_pages; i +=3D pageblock_nr_pages) - init_pageblock_migratetype(page + i, MIGRATE_MOVABLE, - false); + init_pageblock_migratetype(page + i, mt, false); __free_pages_core(page, MAX_PAGE_ORDER, MEMINIT_EARLY); return; } @@ -1994,8 +1997,7 @@ static void __init deferred_free_pages(unsigned long = pfn, =20 for (i =3D 0; i < nr_pages; i++, page++, pfn++) { if (pageblock_aligned(pfn)) - init_pageblock_migratetype(page, MIGRATE_MOVABLE, - false); + init_pageblock_migratetype(page, mt, false); __free_pages_core(page, 0, MEMINIT_EARLY); } } @@ -2053,6 +2055,8 @@ deferred_init_memmap_chunk(unsigned long start_pfn, u= nsigned long end_pfn, for_each_free_mem_range(i, nid, 0, &start, &end, NULL) { unsigned long spfn =3D PFN_UP(start); unsigned long epfn =3D PFN_DOWN(end); + enum migratetype mt =3D + kho_scratch_migratetype(spfn, MIGRATE_MOVABLE); =20 if (spfn >=3D end_pfn) break; @@ -2065,7 +2069,7 @@ deferred_init_memmap_chunk(unsigned long start_pfn, u= nsigned long end_pfn, unsigned long chunk_end =3D min(mo_pfn, epfn); =20 nr_pages +=3D deferred_init_pages(zone, spfn, chunk_end); - deferred_free_pages(spfn, chunk_end - spfn); + deferred_free_pages(spfn, chunk_end - spfn, mt); =20 spfn =3D chunk_end; =20 --=20 2.54.0.rc2.533.g4f5dca5207-goog From nobody Thu Jun 11 00:35:07 2026 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-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, 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 =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 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, unsig= ned long nr_pages) } EXPORT_SYMBOL_GPL(kho_restore_pages); =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. kho_preserved_memory_reserve() marks the reservation as no= init + * 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 =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 (unsigned long i =3D 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_add= r_t phys, u64 sz; =20 sz =3D 1 << (order + PAGE_SHIFT); - page =3D phys_to_page(phys); + page =3D kho_get_preserved_page(phys, order); =20 /* Reserve the memory preserved in KHO in memblock */ memblock_reserve(phys, sz); --=20 2.54.0.rc2.533.g4f5dca5207-goog From nobody Thu Jun 11 00:35:07 2026 Received: from mail-wm1-f74.google.com (mail-wm1-f74.google.com [209.85.128.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 96A6F3ED118 for ; Thu, 23 Apr 2026 12:25:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.74 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776947156; cv=none; b=ogosrbQSS8jAAg+TjaWj+zLNI74TPHo2Pe9FOlU4IhRUFJS3hlc7a/8n7VYmH6pZjNg4DPxi1MRkO1bU3YbeIZRjeCGfHEAgXuqMjhpLR6tD7Q4eslx28NxrE1WH+8wgp7Ya3OuBGhDDdmxV2l1o7xFKWGetpc3fVHfaJpKCpiA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776947156; c=relaxed/simple; bh=qTsqYd4k09OgY5atr8dJ7pYGsoe6Ap4oaGnyLEuQt94=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=l1FB6cdnKDwEFb2aebathIWSXEzm46R04O3NbBPSnRk1UHkVQ8EiPR1KTxsJ7Ci1jrKs+VXDkjCgaOykhjmSveAbynstbxntvJM2i6L8bpvKeOhNVslFsyg2A4nb5GcsRoJe/nouO2+41leWHRfsG0LZh1MmcvDPQUqpn2rZd7M= 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=f1XxkDAV; arc=none smtp.client-ip=209.85.128.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="f1XxkDAV" Received: by mail-wm1-f74.google.com with SMTP id 5b1f17b1804b1-4837b6f6b93so73789585e9.3 for ; Thu, 23 Apr 2026 05:25:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1776947153; x=1777551953; 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=oCWWahIemX4BzZi3Pb2z29oKLrHnKRsi0RRUy/lRLsk=; b=f1XxkDAVDeKbD2YY/kD3pbGlqCTPkZ/ZKuO6TaI50Z61EFpk1k84D0/ApJf/wycsDh lcq6Rq0cFaQ2b0fawu/O2xocUp6m0msiTw8TUnBWmIubZYh2BE0lvC2zHCSoXmODuCEN kyNVAIK27Kw+7r41gwoO3J+dh3obcAJ+QrdGOzk/5tqgO0v5fnKrwlurs3mf8l2xU8kv D/zNukW9T9lrZZ1b6wCb0jJwqReZVSAj0EiqoV0szTi2SYEvD53I4Blz+XH3m3awkDUy scBL2t7nzWSWnKrk4Gtk3yFCZpIwJ2NjjKBsXgbnuDcPMxWpwGs1DGWVh0hL/IbOlw5/ MrMA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1776947153; x=1777551953; 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=oCWWahIemX4BzZi3Pb2z29oKLrHnKRsi0RRUy/lRLsk=; b=D9sZeKfrMfycThHk1mAecEpdQ/Vn3HhJRncqKfPCpuRxKPesRcxjvBRAD/R4T6wANd zj768kzxnlNU8GQPzC4p3KSPf/2CJl6wk/3Y78dKrPHgN3Z6nTjHam/DCfpI1Z7mnGuf BUUFvCBp0XzUd4qZ5FTxzjGNO2PeAKUoHabYqLPVLd8yUgXhqiQVNIYVSWMQo/Q6gubH VqU4locs7F1IcT1bdQRFrvBQ2vIoC9T6QbrrEgrtiBGbQJNA+xRlWCu15Q+SVxMZcUDU FBsXz6r2KtqL01u38r4J+k0ZfE/RwXdCcb8+ptV52CdwxDY5tGR+IXptfvk56aBrJTCN XU9g== X-Gm-Message-State: AOJu0Ywe6aJ4b4cc93T8z51J/uWtQrTi9RMBe2/NaSKUC+WbWAuc1oUy etVTHL3/Yi7Rt/TZTMjtuV9zDeHqa3ijNg9Szooa/gjYdKPwSAdqWy6fgQINk1H4UzJ2Ietd/wh CeQsyya8LjOWUZYnlOrGPvA== X-Received: from wmbdx21.prod.google.com ([2002:a05:600c:63d5:b0:485:2f1e:2ed5]) (user=mclapinski job=prod-delivery.src-stubby-dispatcher) by 2002:a05:600c:a103:b0:48a:58e1:6d17 with SMTP id 5b1f17b1804b1-48a58e16ee0mr105282075e9.20.1776947152925; Thu, 23 Apr 2026 05:25:52 -0700 (PDT) Date: Thu, 23 Apr 2026 14:25:38 +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-4-mclapinski@google.com> Subject: [PATCH v9 3/3] selftests: kho: test 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-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Enable DEFERRED_STRUCT_PAGE_INIT which depends on SMP. Also enable additional debugging options. Signed-off-by: Michal Clapinski Acked-by: Pasha Tatashin =20 Reviewed-by: Mike Rapoport (Microsoft) Reviewed-by: Pratyush Yadav (Google) --- tools/testing/selftests/kho/vmtest.sh | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tools/testing/selftests/kho/vmtest.sh b/tools/testing/selftest= s/kho/vmtest.sh index 49fdac8e8b15..0014bd76e88d 100755 --- a/tools/testing/selftests/kho/vmtest.sh +++ b/tools/testing/selftests/kho/vmtest.sh @@ -59,10 +59,14 @@ function build_kernel() { tee "$kconfig" > "$kho_config" <