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 67A2D944F for ; Thu, 26 Feb 2026 01:33:00 +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=1772069580; cv=none; b=eAsLbOTbLHEL9i574BsE+jLL8UkoFFJhYhbTTQlFVmWTKtVbyPRKROGYOOmLWMomSTZ7EMYVxCfp1/Ycn0+EyJPLeqKF7i6mzollqr22PmS44vdGSijwwlfqaAb2BklwpUe7fT36jmGfuav//sxm4WavMSerWA+UOMRemdsfsWo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772069580; c=relaxed/simple; bh=jz5yjUjM/f+IZwWRIgyYptE1sl+VBHPa3luymxuES4E=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=uIQgqkFv++WqU5GC8ccZJ56Sf62UDLf1pTa2zyFrK/AVyTvnsW6NSSgGtIOUBAaeeBXB30bha/PudKCC7K5QRPdD3is+zx44hSY7p+RYKOkdqZDjR2reyfWZ5rGzWfalgBcLtLtKSjZHuGCTDokElubH8BMDld2RE0cSVO4B93Y= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=jYkt5C4P; 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="jYkt5C4P" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7AB1EC116D0; Thu, 26 Feb 2026 01:32:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1772069580; bh=jz5yjUjM/f+IZwWRIgyYptE1sl+VBHPa3luymxuES4E=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jYkt5C4Pb2PTBmn20lPNS6ETyWWb4ivEIHjhGZl4xP1EcLCSnVaSadSTPdl4n8Zg0 RSsHdOYrMQRtOnMrsw/EDzN2XimpO5klwpSVhT/30jZs1eH9wjd673GwAhTOPUz0LD pQwiRxXp2CntgV3ii5HkCXyx9X/r9NGG2qB3iEvzvsCxohgIN13gk7ytRXtyb43x6f lJpMDxjVyTTI5fGKRL+OSZk9F2t6rQccbWLmOPPor3YHP4gRkeeaBpKJKW/cpPGupW a3JhsUJPbRh3ewmE8lzGwv6EBA+mx9kq129CMQs98jvs99dtmmTFWhwAaIEpjrSSpU AqJ60K8UAX7BA== From: SeongJae Park To: Zi Yan Cc: SeongJae Park , Andrew Morton , David Hildenbrand , Lorenzo Stoakes , "Liam R. Howlett" , Vlastimil Babka , Mike Rapoport , Suren Baghdasaryan , Michal Hocko , Kefeng Wang , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Ron Economos Subject: Re: [PATCH v2] mm/cma: move put_page_testzero() out of VM_WARN_ON in cma_release() Date: Wed, 25 Feb 2026 17:32:57 -0800 Message-ID: <20260226013258.8490-1-sj@kernel.org> X-Mailer: git-send-email 2.47.3 In-Reply-To: <7AAE3B00-627F-4F40-A383-7F5FDCBAC8F5@nvidia.com> References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit On Tue, 24 Feb 2026 22:04:15 -0500 Zi Yan wrote: > On 24 Feb 2026, at 21:54, SeongJae Park wrote: > > > On Tue, 24 Feb 2026 21:28:52 -0500 Zi Yan wrote: > > > >> When CONFIG_DEBUG_VM is not set, VM_WARN_ON is a NOP. Putting any statement > >> with side effect inside it is incorrect. Collect all put_page_testzero() > >> results and check the sum using WARN instead after the loop. > >> > >> Fixes: 9bda131c6093 ("mm: cma: add cma_alloc_frozen{_compound}()") > >> Reported-by: Ron Economos > >> Closes: https://lore.kernel.org/all/1b17c38f-30d3-4bb4-a7e1-e74b19ada885@w6rz.net/ > >> Suggested-by: Kefeng Wang > >> Signed-off-by: Zi Yan > >> --- > >>> From V1: > >> - Collect all put_page_testzero() results and do a single WARN after the > >> loop. > >> > >> mm/cma.c | 5 ++++- > >> 1 file changed, 4 insertions(+), 1 deletion(-) > >> > >> diff --git a/mm/cma.c b/mm/cma.c > >> index 94b5da468a7d..ea540d3f473c 100644 > >> --- a/mm/cma.c > >> +++ b/mm/cma.c > >> @@ -1013,6 +1013,7 @@ bool cma_release(struct cma *cma, const struct page *pages, > >> unsigned long count) > >> { > >> struct cma_memrange *cmr; > >> + unsigned long ret = 0; > >> unsigned long i, pfn; > >> > >> cmr = find_cma_memrange(cma, pages, count); > >> @@ -1021,7 +1022,9 @@ bool cma_release(struct cma *cma, const struct page *pages, > >> > >> pfn = page_to_pfn(pages); > >> for (i = 0; i < count; i++, pfn++) > >> - VM_WARN_ON(!put_page_testzero(pfn_to_page(pfn))); > >> + ret += put_page_testzero(pfn_to_page(pfn)); > > > > So, 'ret' will be incremented when put_page_testzero() returns 'true', right? > > Shouldn't 'ret' be inceremented only when put_page_testzero() returns 'false'? > > Good catch. Let me fix it. Thanks. > > > > >> + > >> + WARN(ret, "%lu pages are still in use!\n", ret); > > > > This will trigger the warning even if CONFIG_DEBUG_VM is unset. I'm fine with > > the changed behavior, but I'm curious if that is the real intention of this > > revision. > > It was in free_contig_range()[1], which was called by cma_release() before. Makes sense, thank you for clarifying, Zi :) > > [1] https://elixir.bootlin.com/linux/v6.19/source/mm/page_alloc.c#L7238 Thanks, SJ [...]