Skip to contentSkip to conversation

mm/cma: move put_page_testzero() out of VM_WARN_ON in cma_release()

PATCH Superseded Zi Yan 2 participants 6 messages Feb 24 – Feb 25

Subsystems (2)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Zi Yan

author
#0 lore raw

PATCH 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. Move put_page_testzero() out and check its return value in VM_WARN_ON. Add __maybe_unused to the return value for when CONFIG_DEBUG_VM is not set.

Fixes 9bda131c6093 ("mm: cma: add cma_alloc_frozen{_compound}()")

---
Alternatively, we can use WARN_ON instead. Let me know.

 mm/cma.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
mm/cma.c +5 -2
index 94b5da468a7d..a9fe6e9a9215 100644
@@ -1020,8 +1020,11 @@ bool cma_release(struct cma *cma, const struct page *pages,
 		return false;
 
 	pfn = page_to_pfn(pages);
-	for (i = 0; i < count; i++, pfn++)
-		VM_WARN_ON(!put_page_testzero(pfn_to_page(pfn)));
+	for (i = 0; i < count; i++, pfn++) {
+		int __maybe_unused ret = put_page_testzero(pfn_to_page(pfn));
+
+		VM_WARN_ON(!ret);
+	}
 
 	__cma_release_frozen(cma, cmr, pages, count);
 
Signature · 1 line
2.51.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 9 lines · On Tue, 24 Feb 2026 16:39:46 -0500 Zi Yan <[email protected]> wrote:

When CONFIG_DEBUG_VM is not set, VM_WARN_ON is a NOP. Putting any statement with side effect inside it is incorrect. Move put_page_testzero() out and check its return value in VM_WARN_ON. Add __maybe_unused to the return value for when CONFIG_DEBUG_VM is not set.

Fixes 9bda131c6093 ("mm: cma: add cma_alloc_frozen{_compound}()")

Thanks,
SJ

[...]

#2 lore raw
Quoted 10 lines · On Tue, 24 Feb 2026 18:18:44 -0800 SeongJae Park <[email protected]> wrote:
Quoted 8 lines · On Tue, 24 Feb 2026 16:39:46 -0500 Zi Yan <[email protected]> wrote:

When CONFIG_DEBUG_VM is not set, VM_WARN_ON is a NOP. Putting any statement with side effect inside it is incorrect. Move put_page_testzero() out and check its return value in VM_WARN_ON. Add __maybe_unused to the return value for when CONFIG_DEBUG_VM is not set.

Fixes 9bda131c6093 ("mm: cma: add cma_alloc_frozen{_compound}()")

I forgot asking this, sorry.

Should we Cc stable@ ?

Thanks,
SJ

[...]

author
#3 lore raw
Quoted 9 lines · SeongJae Park
Quoted 7 lines · On Tue, 24 Feb 2026 18:18:44 -0800 SeongJae Park <[email protected]> wrote:
Quoted 5 lines · On Tue, 24 Feb 2026 16:39:46 -0500 Zi Yan <[email protected]> wrote:

When CONFIG_DEBUG_VM is not set, VM_WARN_ON is a NOP. Putting any statement with side effect inside it is incorrect. Move put_page_testzero() out and check its return value in VM_WARN_ON. Add __maybe_unused to the return value for when CONFIG_DEBUG_VM is not set.

Quoted 7 lines
Quoted 3 lines
Quoted 3 lines
Fixes 9bda131c6093 ("mm: cma: add cma_alloc_frozen{_compound}()")

I forgot asking this, sorry.

Should we Cc stable@ ?

The commit is just in 7.0-rc1. Nothing is needed for stable.

Best Regards,
Yan, Zi

#4 lore raw
Quoted 15 lines · On Tue, 24 Feb 2026 21:21:55 -0500 Zi Yan <[email protected]> wrote:
Quoted 13 lines · SeongJae Park
Quoted 10 lines · On Tue, 24 Feb 2026 18:18:44 -0800 SeongJae Park <[email protected]> wrote:
Quoted 8 lines · On Tue, 24 Feb 2026 16:39:46 -0500 Zi Yan <[email protected]> wrote:

When CONFIG_DEBUG_VM is not set, VM_WARN_ON is a NOP. Putting any statement with side effect inside it is incorrect. Move put_page_testzero() out and check its return value in VM_WARN_ON. Add __maybe_unused to the return value for when CONFIG_DEBUG_VM is not set.

Fixes 9bda131c6093 ("mm: cma: add cma_alloc_frozen{_compound}()")
Quoted 5 lines
Quoted 3 lines

I forgot asking this, sorry.

Should we Cc stable@ ?

The commit is just in 7.0-rc1. Nothing is needed for stable.

Ack.

Thanks,
SJ

[...]

author
#5 lore raw
In reply to Zi Yan
Quoted 9 lines · Zi Yan

When CONFIG_DEBUG_VM is not set, VM_WARN_ON is a NOP. Putting any statement with side effect inside it is incorrect. Move put_page_testzero() out and check its return value in VM_WARN_ON. Add __maybe_unused to the return value for when CONFIG_DEBUG_VM is not set.

Fixes 9bda131c6093 ("mm: cma: add cma_alloc_frozen{_compound}()")
Quoted 6 lines

---
Alternatively, we can use WARN_ON instead. Let me know.

 mm/cma.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

Kefeng suggested a better solution[1]. Will update this one soon.

[1] https://lore.kernel.org/all/[email protected]

Best Regards,
Yan, Zi