LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
* [PATCH 1/2] f2fs: deallocate compressed pages when error happens
@ 2021-08-31  0:53 Jaegeuk Kim
  2021-08-31  0:53 ` [PATCH 2/2] f2fs: should put a page beyond EOF when preparing a write Jaegeuk Kim
  2021-08-31  1:57 ` [f2fs-dev] [PATCH 1/2] f2fs: deallocate compressed pages when error happens Chao Yu
  0 siblings, 2 replies; 4+ messages in thread
From: Jaegeuk Kim @ 2021-08-31  0:53 UTC (permalink / raw)
  To: linux-kernel, linux-f2fs-devel; +Cc: Jaegeuk Kim

In f2fs_write_multi_pages(), f2fs_compress_pages() allocates pages for
compression work in cc->cpages[]. Then, f2fs_write_compressed_pages() initiates
bio submission. But, if there's any error before submitting the IOs like early
f2fs_cp_error(), previously it didn't free cpages by f2fs_compress_free_page().
Let's fix memory leak by putting that just before deallocating cc->cpages.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
---
 fs/f2fs/compress.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/fs/f2fs/compress.c b/fs/f2fs/compress.c
index ec70a0a32327..c1bf9ad4c220 100644
--- a/fs/f2fs/compress.c
+++ b/fs/f2fs/compress.c
@@ -1394,12 +1394,6 @@ static int f2fs_write_compressed_pages(struct compress_ctx *cc,
 
 	for (--i; i >= 0; i--)
 		fscrypt_finalize_bounce_page(&cc->cpages[i]);
-	for (i = 0; i < cc->nr_cpages; i++) {
-		if (!cc->cpages[i])
-			continue;
-		f2fs_compress_free_page(cc->cpages[i]);
-		cc->cpages[i] = NULL;
-	}
 out_put_cic:
 	kmem_cache_free(cic_entry_slab, cic);
 out_put_dnode:
@@ -1410,6 +1404,12 @@ static int f2fs_write_compressed_pages(struct compress_ctx *cc,
 	else
 		f2fs_unlock_op(sbi);
 out_free:
+	for (i = 0; i < cc->nr_cpages; i++) {
+		if (!cc->cpages[i])
+			continue;
+		f2fs_compress_free_page(cc->cpages[i]);
+		cc->cpages[i] = NULL;
+	}
 	page_array_free(cc->inode, cc->cpages, cc->nr_cpages);
 	cc->cpages = NULL;
 	return -EAGAIN;
-- 
2.33.0.259.gc128427fd7-goog


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 2/2] f2fs: should put a page beyond EOF when preparing a write
  2021-08-31  0:53 [PATCH 1/2] f2fs: deallocate compressed pages when error happens Jaegeuk Kim
@ 2021-08-31  0:53 ` Jaegeuk Kim
  2021-08-31  2:04   ` [f2fs-dev] " Chao Yu
  2021-08-31  1:57 ` [f2fs-dev] [PATCH 1/2] f2fs: deallocate compressed pages when error happens Chao Yu
  1 sibling, 1 reply; 4+ messages in thread
From: Jaegeuk Kim @ 2021-08-31  0:53 UTC (permalink / raw)
  To: linux-kernel, linux-f2fs-devel; +Cc: Jaegeuk Kim

The prepare_compress_overwrite() gets/locks a page to prepare a read, and calls
f2fs_read_multi_pages() which checks EOF first. If there's any page beyond EOF,
we unlock the page and set cc->rpages[i] = NULL, which we can't put the page
anymore. This makes page leak, so let's fix by putting that page.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
---
 fs/f2fs/data.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c
index 8e8824605f83..41d29382eced 100644
--- a/fs/f2fs/data.c
+++ b/fs/f2fs/data.c
@@ -2183,6 +2183,8 @@ int f2fs_read_multi_pages(struct compress_ctx *cc, struct bio **bio_ret,
 			continue;
 		}
 		unlock_page(page);
+		if (for_write)
+			put_page(page);
 		cc->rpages[i] = NULL;
 		cc->nr_rpages--;
 	}
-- 
2.33.0.259.gc128427fd7-goog


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [f2fs-dev] [PATCH 1/2] f2fs: deallocate compressed pages when error happens
  2021-08-31  0:53 [PATCH 1/2] f2fs: deallocate compressed pages when error happens Jaegeuk Kim
  2021-08-31  0:53 ` [PATCH 2/2] f2fs: should put a page beyond EOF when preparing a write Jaegeuk Kim
@ 2021-08-31  1:57 ` Chao Yu
  1 sibling, 0 replies; 4+ messages in thread
From: Chao Yu @ 2021-08-31  1:57 UTC (permalink / raw)
  To: Jaegeuk Kim, linux-kernel, linux-f2fs-devel

On 2021/8/31 8:53, Jaegeuk Kim wrote:
> In f2fs_write_multi_pages(), f2fs_compress_pages() allocates pages for
> compression work in cc->cpages[]. Then, f2fs_write_compressed_pages() initiates
> bio submission. But, if there's any error before submitting the IOs like early
> f2fs_cp_error(), previously it didn't free cpages by f2fs_compress_free_page().
> Let's fix memory leak by putting that just before deallocating cc->cpages.
> 

Fixes: 4c8ff7095bef ("f2fs: support data compression")

> Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>

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

Thanks,

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [f2fs-dev] [PATCH 2/2] f2fs: should put a page beyond EOF when preparing a write
  2021-08-31  0:53 ` [PATCH 2/2] f2fs: should put a page beyond EOF when preparing a write Jaegeuk Kim
@ 2021-08-31  2:04   ` Chao Yu
  0 siblings, 0 replies; 4+ messages in thread
From: Chao Yu @ 2021-08-31  2:04 UTC (permalink / raw)
  To: Jaegeuk Kim, linux-kernel, linux-f2fs-devel

On 2021/8/31 8:53, Jaegeuk Kim wrote:
> The prepare_compress_overwrite() gets/locks a page to prepare a read, and calls
> f2fs_read_multi_pages() which checks EOF first. If there's any page beyond EOF,
> we unlock the page and set cc->rpages[i] = NULL, which we can't put the page
> anymore. This makes page leak, so let's fix by putting that page.
> 

Fixes: a949dc5f2c5c ("f2fs: compress: fix race condition of overwrite vs truncate")

> Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>

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

Thanks,

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-08-31  2:04 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-31  0:53 [PATCH 1/2] f2fs: deallocate compressed pages when error happens Jaegeuk Kim
2021-08-31  0:53 ` [PATCH 2/2] f2fs: should put a page beyond EOF when preparing a write Jaegeuk Kim
2021-08-31  2:04   ` [f2fs-dev] " Chao Yu
2021-08-31  1:57 ` [f2fs-dev] [PATCH 1/2] f2fs: deallocate compressed pages when error happens Chao Yu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).