From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796325808; b=Xx4L8VS+xad2k8BqEywds8N86YtHh/aIxZGrOqgw8/GDkE6lBfq0U8JXXxVYDlSR4/pU 079kXSfuWe1onmen4jUFfUnguPKnZMZKEDYkW8ncWhcKo2mTNB6sh4EKCFq4QDk6WXFl8 k5mShP0OlZSo2Pet4kyi3nYh+hmxn70+zPv60yowHehEsSMs4j/lnbHgKf3BdcVvDRp7f 54w5b5GY4bMEgLoSIQJI1/tZTxKuUtyxNxyCTi5KWbqbN+nHAWj/re64nbmSBWN5dwfN6 LvFWy/T5QRRn5Icx1VpHboHncDAxJldAGoSg3QCudCNBuufXUUfbNh9UPWpVH6jYAzg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796325808; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:MIME-Version:Content-Transfer-Encoding; bh=9WwcAAvHkPt0JSc5mHpD1TkRunTmveqOIDnwWjJF0CI=; b=0CpZ5Tmvr/ULy0sVRlRwDTFFQv1UiPECGi/+uSaQkzQiaXFEIHCmSx107Dqd3EAB/wLV uZkliavFTEJFDCJJ2MH+Qg+0ayrfT3hlnk1vnQeghe3eaQm1xhIzNy4XjwCiFdNs7HaET 2YugPe2i8wwE3j8z8pKnDtLL8N3/eqyjQ642emDihArEDwm9Y1pGnSp4SJcnt6Y21TVU4 Irx6wyt1ikDv8HSg/OCtZQRHKE/T26G+uEKfgKR/ZIg7Yfwm0tsUThIQ678r/Tvjh96Jl VJnY7J9kv0ynjQt47vb4ujwwZJi7E6h8D+mkm7UuFSiRaiTL4kgOUU5ADSwM7O2fwtw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=iR6mcWAV; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3706A606A339 for ; Thu, 3 Dec 2026 19:23:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=iR6mcWAV Received: by smtp.kernel.org (Postfix) with ESMTPSA id 19AE61F00933; Thu, 3 Dec 2026 19:23:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796325807; bh=9WwcAAvHkPt0JSc5mHpD1TkRunTmveqOIDnwWjJF0CI=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=iR6mcWAV2LSlAiPhEkYAuTIyUHmahuBIfNpz2zMMcsqhbdCpOCpcqFo1Nv2qK0EAr s4MrAEVT4kkXXKgJA4jqPJY9L0KgWr/RCIZFF2ix5h84ZGeBrLdhI1C2KQrQofpQ7V hRJex0e+Z4XqKav/gBr7IcbIQPihSk6KQ8LdbxfESu428P1p0HP4pjy4ZpxDYZIHjh 6IDxZ+oSy5xZLS7Z/cEzEPOjCxlQUkG3Vj3KbuII3w/OS5cqb+WUkiAsXRLjFokqBv MCzPXsAJ505i30zIdxz/5BdMzFw7MKqhimGIosUHn/efRmH9gBRY4Tsk3SCWoy2vEh jzNKCsNZ1evBw== From: Sasha Levin To: stable@vger.kernel.org Cc: Marek Szyprowski , Sasha Levin Subject: [PATCH 6.12.y 2/2] dma-pool: release CMA pages on atomic_pool_expand() error path Date: Thu, 3 Dec 2026 14:23:24 -0500 Message-ID: <20261203192313.622519-2-sashal@kernel.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20261203192313.622519-1-sashal@kernel.org> References: <2026120205-villain-friend-b1d2@gregkh> <20261203192313.622519-1-sashal@kernel.org> X-Mailing-List: stable@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Marek Szyprowski [ 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 Signed-off-by: Sasha Levin --- 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