mm/cma.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
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
e0c1326779cc ("mm: page_alloc: add alloc_contig_frozen_{range,pages}()"),
the commit prior to the Fixes one.
Fixes: 9bda131c6093 ("mm: cma: add cma_alloc_frozen{_compound}()")
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>
Signed-off-by: Zi Yan <ziy@nvidia.com>
---
From V2:
- Collect !put_page_testzero() to get the right result.
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..15cc0ae76c8e 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));
+
+ WARN(ret, "%lu pages are still in use!\n", ret);
__cma_release_frozen(cma, cmr, pages, count);
--
2.51.0
On 25/02/2026 03:12, 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. It restores
> the same check in free_contig_range() before commit
> e0c1326779cc ("mm: page_alloc: add alloc_contig_frozen_{range,pages}()"),
> the commit prior to the Fixes one.
>
> Fixes: 9bda131c6093 ("mm: cma: add cma_alloc_frozen{_compound}()")
> 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>
> Signed-off-by: Zi Yan <ziy@nvidia.com>
> ---
>>From V2:
> - Collect !put_page_testzero() to get the right result.
>
>>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..15cc0ae76c8e 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));
> +
> + WARN(ret, "%lu pages are still in use!\n", ret);
>
> __cma_release_frozen(cma, cmr, pages, count);
>
This fixes a regression I was seeing on Tegra. So ...
Tested-by: Jon Hunter <jonathanh@nvidia.com>
Thanks!
Jon
--
nvpublic
On Tue, 24 Feb 2026 22:12:31 -0500 Zi Yan <ziy@nvidia.com> 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. It restores
> the same check in free_contig_range() before commit
> e0c1326779cc ("mm: page_alloc: add alloc_contig_frozen_{range,pages}()"),
> the commit prior to the Fixes one.
>
> Fixes: 9bda131c6093 ("mm: cma: add cma_alloc_frozen{_compound}()")
> 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>
> Signed-off-by: Zi Yan <ziy@nvidia.com>
Reviewed-by: SeongJae Park <sj@kernel.org>
Thanks,
SJ
[...]
On Tue, Feb 24, 2026 at 10:12:31PM -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. It restores
> the same check in free_contig_range() before commit
> e0c1326779cc ("mm: page_alloc: add alloc_contig_frozen_{range,pages}()"),
> the commit prior to the Fixes one.
LGTM.
Reviewed-by: Vishal Moola (Oracle) <vishal.moola@gmail.com>
On 2/25/26 04:12, 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. It restores
> the same check in free_contig_range() before commit
> e0c1326779cc ("mm: page_alloc: add alloc_contig_frozen_{range,pages}()"),
> the commit prior to the Fixes one.
>
> Fixes: 9bda131c6093 ("mm: cma: add cma_alloc_frozen{_compound}()")
> 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>
> Signed-off-by: Zi Yan <ziy@nvidia.com>
> ---
> From V2:
> - Collect !put_page_testzero() to get the right result.
>
> 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..15cc0ae76c8e 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));
> +
> + WARN(ret, "%lu pages are still in use!\n", ret);
>
> __cma_release_frozen(cma, cmr, pages, count);
>
Thanks for taking care of the fix.
Debugged-by: David Hildenbrand (Arm) <david@kernel.org>
Acked-by: David Hildenbrand (Arm) <david@kernel.org>
--
Cheers,
David
On 2/24/26 19:12, 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. It restores
> the same check in free_contig_range() before commit
> e0c1326779cc ("mm: page_alloc: add alloc_contig_frozen_{range,pages}()"),
> the commit prior to the Fixes one.
>
> Fixes: 9bda131c6093 ("mm: cma: add cma_alloc_frozen{_compound}()")
> 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>
> Signed-off-by: Zi Yan <ziy@nvidia.com>
> ---
> From V2:
> - Collect !put_page_testzero() to get the right result.
>
> 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..15cc0ae76c8e 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));
> +
> + WARN(ret, "%lu pages are still in use!\n", ret);
>
> __cma_release_frozen(cma, cmr, pages, count);
Tested-by: Ron Economos <re@w6rz.net>
On 2/24/26 19:12, 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. It restores
> the same check in free_contig_range() before commit
> e0c1326779cc ("mm: page_alloc: add alloc_contig_frozen_{range,pages}()"),
> the commit prior to the Fixes one.
>
> Fixes: 9bda131c6093 ("mm: cma: add cma_alloc_frozen{_compound}()")
> 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>
> Signed-off-by: Zi Yan <ziy@nvidia.com>
> ---
> From V2:
> - Collect !put_page_testzero() to get the right result.
>
> 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..15cc0ae76c8e 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));
> +
> + WARN(ret, "%lu pages are still in use!\n", ret);
>
> __cma_release_frozen(cma, cmr, pages, count);
Tested-by: Ron Economos <re@w6rz>
On 2026/2/25 11:12, 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. It restores
> the same check in free_contig_range() before commit
> e0c1326779cc ("mm: page_alloc: add alloc_contig_frozen_{range,pages}()"),
> the commit prior to the Fixes one.
>
> Fixes: 9bda131c6093 ("mm: cma: add cma_alloc_frozen{_compound}()")
> 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>
> Signed-off-by: Zi Yan <ziy@nvidia.com>
> ---
> From V2:
> - Collect !put_page_testzero() to get the right result.
>
> From V1:
> - Collect all put_page_testzero() results and do a single WARN after the
> loop.
>
Reviewed-by: Kefeng Wang <wangkefeng.wang@huawei.com>
> mm/cma.c | 5 ++++-
> 1 file changed, 4 insertions(+), 1 deletion(-)
>
> diff --git a/mm/cma.c b/mm/cma.c
> index 94b5da468a7d..15cc0ae76c8e 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));
> +
> + WARN(ret, "%lu pages are still in use!\n", ret);
>
> __cma_release_frozen(cma, cmr, pages, count);
>
On 25/02/26 8:42 AM, 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. It restores
> the same check in free_contig_range() before commit
> e0c1326779cc ("mm: page_alloc: add alloc_contig_frozen_{range,pages}()"),
> the commit prior to the Fixes one.
>
> Fixes: 9bda131c6093 ("mm: cma: add cma_alloc_frozen{_compound}()")
> 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>
> Signed-off-by: Zi Yan <ziy@nvidia.com>
> ---
> From V2:
> - Collect !put_page_testzero() to get the right result.
>
> 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..15cc0ae76c8e 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));
> +
> + WARN(ret, "%lu pages are still in use!\n", ret);
>
> __cma_release_frozen(cma, cmr, pages, count);
>
Makes sense to make the above warning unconditional regardless of CONFIG_DEBUG_VM.
Reviewed-by: Anshuman Khandual <anshuman.khandual@arm.com>
© 2016 - 2026 Red Hat, Inc.