Skip to content

Commit f4355d6

Browse files
x-y-zakpm00
authored andcommitted
mm/cma: move put_page_testzero() out of VM_WARN_ON in cma_release()
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. It restores the same check in free_contig_range() before commit e0c1326 ("mm: page_alloc: add alloc_contig_frozen_{range,pages}()"), the commit prior to the Fixes one. Link: https://lkml.kernel.org/r/20260225031231.2352011-1-ziy@nvidia.com Fixes: 9bda131 ("mm: cma: add cma_alloc_frozen{_compound}()") Signed-off-by: Zi Yan <ziy@nvidia.com> Reported-by: Ron Economos <re@w6rz.net> Closes: https://lore.kernel.org/all/1b17c38f-30d3-4bb4-a7e1-e74b19ada885@w6rz.net/ Suggested-by: Kefeng Wang <wangkefeng.wang@huawei.com> Reviewed-by: Vishal Moola (Oracle) <vishal.moola@gmail.com> Debugged-by: David Hildenbrand (Arm) <david@kernel.org> Acked-by: David Hildenbrand (Arm) <david@kernel.org> Tested-by: Ron Economos <re@w6rz.net> Reviewed-by: Kefeng Wang <wangkefeng.wang@huawei.com> Reviewed-by: Anshuman Khandual <anshuman.khandual@arm.com> Reviewed-by: SeongJae Park <sj@kernel.org> Cc: Liam Howlett <liam.howlett@oracle.com> Cc: Lorenzo Stoakes <lorenzo.stoakes@oracle.com> Cc: Michal Hocko <mhocko@suse.com> Cc: Mike Rapoport <rppt@kernel.org> Cc: Suren Baghdasaryan <surenb@google.com> Cc: Vlastimil Babka <vbabka@kernel.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
1 parent d210fdc commit f4355d6

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

mm/cma.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1013,6 +1013,7 @@ bool cma_release(struct cma *cma, const struct page *pages,
10131013
unsigned long count)
10141014
{
10151015
struct cma_memrange *cmr;
1016+
unsigned long ret = 0;
10161017
unsigned long i, pfn;
10171018

10181019
cmr = find_cma_memrange(cma, pages, count);
@@ -1021,7 +1022,9 @@ bool cma_release(struct cma *cma, const struct page *pages,
10211022

10221023
pfn = page_to_pfn(pages);
10231024
for (i = 0; i < count; i++, pfn++)
1024-
VM_WARN_ON(!put_page_testzero(pfn_to_page(pfn)));
1025+
ret += !put_page_testzero(pfn_to_page(pfn));
1026+
1027+
WARN(ret, "%lu pages are still in use!\n", ret);
10251028

10261029
__cma_release_frozen(cma, cmr, pages, count);
10271030

0 commit comments

Comments
 (0)