From: Sasha Levin <sashal@kernel.org>
To: stable@vger.kernel.org
Cc: Marek Szyprowski <m.szyprowski@samsung.com>,
Sasha Levin <sashal@kernel.org>
Subject: [PATCH 6.18.y 2/2] dma-pool: release CMA pages on atomic_pool_expand() error path
Date: Thu, 3 Dec 2026 14:09:53 -0500 [thread overview]
Message-ID: <20261203190941.605191-2-sashal@kernel.org> (raw)
In-Reply-To: <20261203190941.605191-1-sashal@kernel.org>
From: Marek Szyprowski <m.szyprowski@samsung.com>
[ Upstream commit ca010d38da7bf05a4572a54c2c16d6d64a758c3a ]
atomic_pool_expand() may allocate the pool backing pages from CMA via
dma_alloc_from_contiguous(), but the error path unconditionally frees
them with __free_pages(). This hands CMA pages to the buddy allocator
while leaving them marked as allocated in the CMA bitmap, permanently
leaking CMA capacity on every failed expansion.
Try dma_release_from_contiguous() first and fall back to __free_pages()
only for pages that did not come from CMA, as the code did before CMA
allocation was temporarily removed from the pool.
Fixes: d7e673ec2c8e ("dma-pool: Only allocate from CMA when in same memory zone")
Closes: https://sashiko.dev/#/bug/linux-fdfc6e83-15e4-4980-9818-691b034397e7
Cc: stable@vger.kernel.org
Link: https://lore.kernel.org/r/20261026095423.966856-5-m.szyprowski@samsung.com
Signed-off-by: Marek Szyprowski <m.szyprowski@samsung.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
kernel/dma/pool.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/kernel/dma/pool.c b/kernel/dma/pool.c
index c7bbf32adeacf..eeac181dcc4f4 100644
--- a/kernel/dma/pool.c
+++ b/kernel/dma/pool.c
@@ -140,7 +140,8 @@ static int atomic_pool_expand(struct gen_pool *pool, size_t pool_size,
dma_common_free_remap(addr, pool_size);
free_page:
#endif
- if (!leak_pages)
+ if (!leak_pages &&
+ !dma_release_from_contiguous(NULL, page, 1 << order))
__free_pages(page, order);
out:
return ret;
--
2.53.0
prev parent reply other threads:[~2026-12-03 19:09 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-02 13:00 FAILED: patch "[PATCH] dma-pool: release CMA pages on atomic_pool_expand() error" failed to apply to 6.18-stable tree gregkh
2026-12-03 19:09 ` [PATCH 6.18.y 1/2] dma-pool: fix page leak in atomic_pool_expand() cleanup Sasha Levin
2026-12-03 19:09 ` Sasha Levin [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261203190941.605191-2-sashal@kernel.org \
--to=sashal@kernel.org \
--cc=m.szyprowski@samsung.com \
--cc=stable@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.