mm/cma: move put_page_testzero() out of VM_WARN_ON in cma_release()
Subsystems (2)
PATCH v2 1/1 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.
---
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(-)
mm/cma.c +4 -1
@@ -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);
Signature · 1 line
2.51.0
Quoted 30 lines · On Tue, 24 Feb 2026 21:28:52 -0500 Zi Yan <[email protected]> wrote:
When
CONFIG_DEBUG_VMis not set,VM_WARN_ONis a NOP. Putting any statement with side effect inside it is incorrect. Collect allput_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 <[email protected]>Suggested-by Kefeng Wang <[email protected]>Signed-off-by Zi Yan <[email protected]>---
Quoted 1 line
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(-)mm/cma.c +1
-0@@ -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);
mm/cma.c bool cma_release(struct cma *cma, const struct page *pages, · line 1025
Quoted 5 lines
mm/cma.c +1
-1@@ -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'?
mm/cma.c bool cma_release(struct cma *cma, const struct page *pages, · line 1027
Quoted 2 lines
mm/cma.c +2
-0+ +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.
Thanks,
SJ
[...]
Quoted 33 lines · SeongJae Park
Quoted 31 lines · On Tue, 24 Feb 2026 21:28:52 -0500 Zi Yan <[email protected]> wrote:
When
CONFIG_DEBUG_VMis not set,VM_WARN_ONis a NOP. Putting any statement with side effect inside it is incorrect. Collect allput_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 <[email protected]>Suggested-by Kefeng Wang <[email protected]>Signed-off-by Zi Yan <[email protected]>---
Quoted 1 line
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(-)mm/cma.c +1
-0@@ -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,
Quoted 7 lines
mm/cma.c bool cma_release(struct cma *cma, const struct page *pages, · line 1025
Quoted 4 lines
mm/cma.c +1
-1pfn =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 whenput_page_testzero()returns 'false'?
Good catch. Let me fix it. Thanks.
Quoted 7 lines
mm/cma.c bool cma_release(struct cma *cma, const struct page *pages, · line 1027
Quoted 3 lines
mm/cma.c +2
-0+ +WARN (ret,"%lu pages are still in use!\n" , ret);This will trigger the warning even if
CONFIG_DEBUG_VMis 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.
[1] https://elixir.bootlin.com/linux/v6.19/source/mm/page_alloc.c#L7238
--
Best Regards,
Yan, Zi
Quoted 46 lines · On Tue, 24 Feb 2026 22:04:15 -0500 Zi Yan <[email protected]> wrote:
Quoted 33 lines · SeongJae Park
Quoted 31 lines · On Tue, 24 Feb 2026 21:28:52 -0500 Zi Yan <[email protected]> wrote:
When
CONFIG_DEBUG_VMis not set,VM_WARN_ONis a NOP. Putting any statement with side effect inside it is incorrect. Collect allput_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 <[email protected]>Suggested-by Kefeng Wang <[email protected]>Signed-off-by Zi Yan <[email protected]>---
Quoted 1 line
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(-)mm/cma.c +1
-0@@ -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,Quoted 7 lines
mm/cma.c bool cma_release(struct cma *cma, const struct page *pages, · line 1025
Quoted 4 lines
mm/cma.c +1
-1pfn =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 whenput_page_testzero()returns 'false'?Good catch. Let me fix it. Thanks.
Quoted 1 line
Quoted 8 lines
Quoted 6 lines
mm/cma.c bool cma_release(struct cma *cma, const struct page *pages, · line 1027
Quoted 2 lines
mm/cma.c +2
-0+ +WARN (ret,"%lu pages are still in use!\n" , ret);This will trigger the warning even if
CONFIG_DEBUG_VMis 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 :)
Quoted 2 lines
[1] https://elixir.bootlin.com/linux/v6.19/source/mm/page_alloc.c#L7238
Thanks,
SJ
[...]