From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C586B395D87 for ; Tue, 28 Apr 2026 07:30:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777361426; cv=none; b=hfUOtyF9Xyr9uX5TfE5YsbaAEtQIAvlUmea/CsO1RCarCAFa8gL/HIPMHCz3rrNN5QQvAALV6ZNO+vlTHxmzwIhaq79TCCOsLf9bqq6IeD2bCZ8saRayAnRfcegcnWNSv8yO0BICckz7B9yg2Kz8b2rlYXK47QzBc2k6pVNbCTk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777361426; c=relaxed/simple; bh=NUkahn2fQKcVscwh1ZNhP9Ux4hzuiTG9l+Ex0RnXqrI=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=gTIGno34wM++/1Z6jVTaH/lSpBmToU6o03R5dM3Cu3vqNU0LYR5q5EEOIW0Ai7XFbtCvKJdehQrauYiz20guHnuE+40/2W5bBe/SRMJJOOryQLSwQxnIEXuNdOKpClg5ry149k42ftwlY6BpJaVTdly/3pRKklgRIf3liNyjvVM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=DzAuyE4m; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="DzAuyE4m" Received: by smtp.kernel.org (Postfix) with ESMTPSA id AE594C2BCAF; Tue, 28 Apr 2026 07:30:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1777361426; bh=NUkahn2fQKcVscwh1ZNhP9Ux4hzuiTG9l+Ex0RnXqrI=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=DzAuyE4mHR73GXt0aEhL4Y1y83XCRo5dzQEP/Naos4y98wjCQ3+9aVHy87wYPKQm+ UyvY1H4A3aspMp0YlGRzaaUe5/YbbHn/YHN1tLdka8XMlHq9q0NvVois7IJSPXFSqK vMZv9CHHYxEQ9z8gIpmeOg0a2KgeizAFD5YSP1VeSjqtkkFjuFQ39sTC34VNvNDMiR BqN+HDCOHVr5miGYAw2BWbnMH+Ifcq3QUG9DctkZ8+uruJzCf6i6RnZ5o6wRH5DKtL sOpCO4BrNFXx4plg4ylgJhsiUBNjYKTXiPrwg9lfXVo+rqnvVWmE5jUYURupXpH4I9 KBsRCgfEo5Ebg== Date: Tue, 28 Apr 2026 09:30:13 +0200 From: Mike Rapoport To: Muchun Song Cc: Andrew Morton , David Hildenbrand , Muchun Song , Oscar Salvador , Michael Ellerman , Madhavan Srinivasan , Lorenzo Stoakes , "Liam R . Howlett" , Vlastimil Babka , Suren Baghdasaryan , Michal Hocko , Nicholas Piggin , Christophe Leroy , aneesh.kumar@linux.ibm.com, joao.m.martins@oracle.com, linux-mm@kvack.org, linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH 14/49] mm/cma: validate hugetlb CMA range by zone at reserve time Message-ID: References: <20260405125240.2558577-1-songmuchun@bytedance.com> <20260405125240.2558577-15-songmuchun@bytedance.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20260405125240.2558577-15-songmuchun@bytedance.com> On Sun, Apr 05, 2026 at 08:52:05PM +0800, Muchun Song wrote: > During hugetlb_cma_reserve() we already have access to zone information, so we > can validate that the reserved CMA range does not span multiple zones. > > Doing this check up front allows future hugetlb allocations from CMA to assume > zone-valid CMA areas, avoiding additional validity checks and potential > fallback/rollback paths, greatly simplifying the code. > > The pfn_valid() check is removed from cma_validate_zones() because mem_section is > not initialized at that stage and it can trigger false warnings; keep the > sanity check in cma_activate_area() instead. This is preparatory work for the > follow-up simplification. > > Signed-off-by: Muchun Song > --- > mm/cma.c | 3 ++- > mm/hugetlb_cma.c | 3 ++- > 2 files changed, 4 insertions(+), 2 deletions(-) > > diff --git a/mm/cma.c b/mm/cma.c > index 15cc0ae76c8e..dd046a23f467 100644 > --- a/mm/cma.c > +++ b/mm/cma.c > @@ -125,7 +125,6 @@ bool cma_validate_zones(struct cma *cma) > * to be in the same zone. Simplify by forcing the entire > * CMA resv range to be in the same zone. > */ > - WARN_ON_ONCE(!pfn_valid(base_pfn)); > if (pfn_range_intersects_zones(cma->nid, base_pfn, cmr->count)) { > set_bit(CMA_ZONES_INVALID, &cma->flags); > return false; > @@ -164,6 +163,8 @@ static void __init cma_activate_area(struct cma *cma) > bitmap_set(cmr->bitmap, 0, bitmap_count); > } > > + WARN_ON_ONCE(!pfn_valid(cmr->base_pfn)); > + > for (pfn = early_pfn[r]; pfn < cmr->base_pfn + cmr->count; > pfn += pageblock_nr_pages) > init_cma_reserved_pageblock(pfn_to_page(pfn)); > diff --git a/mm/hugetlb_cma.c b/mm/hugetlb_cma.c > index f83ae4998990..b068e9bf6537 100644 > --- a/mm/hugetlb_cma.c > +++ b/mm/hugetlb_cma.c > @@ -233,9 +233,10 @@ void __init hugetlb_cma_reserve(void) > res = cma_declare_contiguous_multi(size, PAGE_SIZE << order, > HUGETLB_PAGE_ORDER, name, > &hugetlb_cma[nid], nid); > - if (res) { > + if (res || !cma_validate_zones(hugetlb_cma[nid])) { > pr_warn("hugetlb_cma: reservation failed: err %d, node %d", > res, nid); The warning here should be updated as well. Other than that Acked-by: Mike Rapoport (Microsoft) > + hugetlb_cma[nid] = NULL; > continue; > } > > -- > 2.20.1 > -- Sincerely yours, Mike.