[v2] erofs: fix memory leak on short-lived bounced pages

Message ID 20231128180431.4116991-1-hsiangkao@linux.alibaba.com
State New
Headers
Series [v2] erofs: fix memory leak on short-lived bounced pages |

Commit Message

Gao Xiang Nov. 28, 2023, 6:04 p.m. UTC
  Both MicroLZMA and DEFLATE algorithms can use short-lived pages on
demand for overlap inplace I/O decompression.

However, those short-lived pages are actually added to
`be->compressed_pages`.  Thus, it should be checked instead of
`pcl->compressed_bvecs`.

The LZ4 algorithm doesn't work like this, so it won't be impacted.

Fixes: 67139e36d970 ("erofs: introduce `z_erofs_parse_in_bvecs'")
Signed-off-by: Gao Xiang <hsiangkao@linux.alibaba.com>
---
v2:
  - should be `be->compressed_pages`.

 fs/erofs/zdata.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
  

Comments

Yue Hu Nov. 29, 2023, 5:39 a.m. UTC | #1
On Wed, 29 Nov 2023 02:04:31 +0800
Gao Xiang <hsiangkao@linux.alibaba.com> wrote:

> Both MicroLZMA and DEFLATE algorithms can use short-lived pages on
> demand for overlap inplace I/O decompression.
> 
> However, those short-lived pages are actually added to
> `be->compressed_pages`.  Thus, it should be checked instead of
> `pcl->compressed_bvecs`.
> 
> The LZ4 algorithm doesn't work like this, so it won't be impacted.
> 
> Fixes: 67139e36d970 ("erofs: introduce `z_erofs_parse_in_bvecs'")
> Signed-off-by: Gao Xiang <hsiangkao@linux.alibaba.com>

Reviewed-by: Yue Hu <huyue2@coolpad.com>
  
Chao Yu Dec. 14, 2023, 3 p.m. UTC | #2
On 2023/11/29 2:04, Gao Xiang wrote:
> Both MicroLZMA and DEFLATE algorithms can use short-lived pages on
> demand for overlap inplace I/O decompression.
> 
> However, those short-lived pages are actually added to
> `be->compressed_pages`.  Thus, it should be checked instead of
> `pcl->compressed_bvecs`.
> 
> The LZ4 algorithm doesn't work like this, so it won't be impacted.
> 
> Fixes: 67139e36d970 ("erofs: introduce `z_erofs_parse_in_bvecs'")
> Signed-off-by: Gao Xiang <hsiangkao@linux.alibaba.com>

Reviewed-by: Chao Yu <chao@kernel.org>

Thanks,
  

Patch

diff --git a/fs/erofs/zdata.c b/fs/erofs/zdata.c
index a7e6847f6f8f..a33cd6757f98 100644
--- a/fs/erofs/zdata.c
+++ b/fs/erofs/zdata.c
@@ -1309,12 +1309,11 @@  static int z_erofs_decompress_pcluster(struct z_erofs_decompress_backend *be,
 		put_page(page);
 	} else {
 		for (i = 0; i < pclusterpages; ++i) {
-			page = pcl->compressed_bvecs[i].page;
+			/* consider shortlived pages added when decompressing */
+			page = be->compressed_pages[i];
 
 			if (erofs_page_is_managed(sbi, page))
 				continue;
-
-			/* recycle all individual short-lived pages */
 			(void)z_erofs_put_shortlivedpage(be->pagepool, page);
 			WRITE_ONCE(pcl->compressed_bvecs[i].page, NULL);
 		}