From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795981737; b=0BA4ZAdy3wxt7dwd+fEhJDc5lb2Fl+u7teqon6ZR3FFZ8zGdXEYp5C1kUrhONM2uwK5y jildFywxdco0COuxVUIYnELMGaPI6LoXDS5dUMBuR5oTWF8eXW2KnFoPP1S8HZq4TOa3P WcH5SZS1lJbt78zKW7DrlGS6MtCtmIKaGTsLTpNrdLoVKbR3nMxSFu2cTn5oKj2244Smb yTXG3Yiaaqe8a/Kr2Rj1BYctbBFyax2j7qkCJ5oI6g6wL2tq+03L1AFpVawWyCjgqJUSa zxWMe3WIrdLtrw+uUqP4mD48907lQ/04hB5kIHY9/8MyR181YE/jHgvUNflUV3e/oTg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795981737; h=Received:DKIM-Signature:Date:From:To:Cc:Subject:Message-ID: References:MIME-Version:Content-Type:Content-Disposition:In-Reply-To; bh=R3Ve4QyxY+phXEH5iBcIBo/0RFaduPiV1250yCJyQis=; b=RjgkD1aS8eu4atQDioODzsG/TqbwXoVPSFbQCkFcqehOmR2SlGyxvAFkl6AJhEj0dDMi hPUleXcHAmCrdhn01VRwTq3j8arMD4rbBX2UYR8xgN4zrlWPo+6cqnLBgmV4NmAYs44Ru 2OZ/w3duohhZAA8wkf3E2r6+wn4+CAf9IJT5sgRUuzJmyZzKtQHdaNmJuddwpT7MukvMw Q2Yt6a73I4WK3Ew7JPWZu0w78qHxaN0a0rfloJ/J9XOKKsR3h+OKhYA6qEbkgEv3a9fDE yNwVUBEiGWnMGcLDsLCa4ka7xgRyjVuoaRGQLEqjdvbLHMmXthCrRxDNWbh6k9ecHwg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=Fyaw8MuN; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 20F82606A325 for ; Sun, 29 Nov 2026 19:48:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=Fyaw8MuN Received: by smtp.kernel.org (Postfix) with ESMTPSA id D6DEB1F00898; Sun, 29 Nov 2026 19:48:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1795981736; bh=R3Ve4QyxY+phXEH5iBcIBo/0RFaduPiV1250yCJyQis=; h=Date:From:To:Cc:Subject:References:In-Reply-To; b=Fyaw8MuNOq4gvgXe+8aYFs24BrZhsdNqEwPVeK0kW8OTOOECq7KUz55AFQmFBBIb8 OCRz8cUxHlk+kGNMD/G4ujxkYDPI4ZV9TM+9i564A0yGRaxIjycv2B4w06A4zb/kyW 7YlXaqMNF4FEsU6bkqI8NLmoRXRuRD8wLG7ZDwpsI0RMmwUAV9jIbnFIwxSyPx6uFF MPlL+BiA3CZFco84XKS7Mx9/u12UArmFDHV3twtlHEB1SWyCp8cFRccl5HSgykugBB aEQ/h5/yhRdPcgL8ADcoNojS6WvKEe8uoCUZWXRTy9ijCwWUf7dsl4Uo2rZk2f45Hi hWI9awYbqj+kw== Date: Sun, 29 Nov 2026 21:48:50 +0200 From: Mike Rapoport To: Chris Down Cc: Pasha Tatashin , Pratyush Yadav , Alexander Graf , kexec@lists.infradead.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, David Hildenbrand Subject: Re: [PATCH 1/2] kho: count bootmem in zoneinfo's cma after a KHO kexec Message-ID: References: <435620830fafd0b7458b583485967cdbbb848d3f.1795928397.git.chris@chrisdown.name> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <435620830fafd0b7458b583485967cdbbb848d3f.1795928397.git.chris@chrisdown.name> Hi Chris, Overall LGTM, just a few nits below. On Sat, Nov 28, 2026 at 09:01:48PM -0800, Chris Down wrote: > On a cold boot, kho_init() releases bootmem to the buddy allocator with > init_cma_reserved_pageblock(), which adds each pageblock to > zone->cma_pages. > > A KHO boot takes a different path, because bootmem isn't reserved in > memblock: > > 1. kho_bootmem_migratetype() makes its pageblocks MIGRATE_CMA during > memmap init. > 2. memblock_free_all() releases the free pages. > 3. kho_init() returns before it gets to the bootmem loop. I'd say it bypasses bootmem initialization. > Nothing adds bootmem to zone->cma_pages, so the cma line in > /proc/zoneinfo goes to 0 after a KHO kexec, even though the memory is > still MIGRATE_CMA and its free pages are still counted in CmaFree. For > example, with 4 GiB over two nodes and kho_bootmem=32M,512M,256M, in > pages: > > cold boot after KHO kexec > Node 0, DMA32 65536 0 > Node 1, DMA32 8192 0 > Node 1, Normal 196608 0 It would be great to see "before" and "after" tables. > zone->cma_pages is also what the auto-movable memory onlining policy > treats as movable memory, so after a KHO kexec it counts bootmem as > kernel memory instead. > > Let's count the MIGRATE_CMA pageblocks in bootmem from kho_init() on a > KHO boot. > > You might wonder why we don't count pageblocks as they are made > MIGRATE_CMA in pageblock_migratetype_init_range() and > __init_deferred_page(). The reason is that, with deferred struct page > init, __init_deferred_page() makes bootmem MIGRATE_CMA on a cold boot > too, where init_cma_reserved_pageblock() then counts it again. > deferred_free_pages() also runs in several padata threads at once, which > would race on the counter. > > Fixes: c609c144b0e8 ("kexec: add KHO parsing support") > Signed-off-by: Chris Down > --- > kernel/liveupdate/kexec_handover.c | 33 ++++++++++++++++++++++++++++++ > 1 file changed, 33 insertions(+) > > diff --git a/kernel/liveupdate/kexec_handover.c b/kernel/liveupdate/kexec_handover.c > index 38e65d210cb9..7cc87338df24 100644 > --- a/kernel/liveupdate/kexec_handover.c > +++ b/kernel/liveupdate/kexec_handover.c > @@ -1860,12 +1860,45 @@ static int __init kho_kexec_metadata_init(const void *fdt) > return err; > } > > +static int __init kho_cma_area_intersects(struct cma *cma, void *data) > +{ > + phys_addr_t start = *(phys_addr_t *)data; > + > + return cma_intersects(cma, start, > + start + pageblock_nr_pages * PAGE_SIZE - 1); > +} > + > +static void __init kho_account_incoming_bootmem(void) > +{ > + for (int i = 0; i < kho_bootmem_cnt; i++) { > + unsigned long base_pfn = PHYS_PFN(kho_bootmem[i].addr); > + unsigned long count = kho_bootmem[i].size >> PAGE_SHIFT; > + unsigned long pfn; > + > + for (pfn = base_pfn; pfn < base_pfn + count; > + pfn += pageblock_nr_pages) { > + struct page *page = pfn_to_page(pfn); > + phys_addr_t start = PFN_PHYS(pfn); > + > + if (!is_migrate_cma_page(page)) > + continue; > + if (cma_for_each_area(kho_cma_area_intersects, &start)) > + continue; A curious reader may also wonder why we need this check ;-) A short comment would be nice. > + > + page_zone(page)->cma_pages += pageblock_nr_pages; > + } > + } > +} > + > static __init int kho_init(void) > { > struct kho_radix_tree *tree = &kho_out.radix_tree; > const void *fdt = kho_get_fdt(); > int err = 0; > > + if (is_kho_boot()) > + kho_account_incoming_bootmem(); > + > if (!kho_enable) > return 0; > > -- > 2.56.1 > -- Sincerely yours, Mike.