Skip to contentSkip to conversation

f2fs: remove unreachable code in f2fs_encrypt_one_page()

PATCH In review Eric Biggers via Linux-f2fs-devel 2 participants 4 messages Feb 21 – Mar 4

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 f2fs: remove unreachable code in f2fs_encrypt_one_page()

Since commit 52e7e0d88933 ("fscrypt: Switch to sync_skcipher and on-stack requests") eliminated the dynamic allocation of crypto requests, the only remaining dynamic memory allocation done by fscrypt_encrypt_pagecache_blocks() is the bounce page allocation.

The bounce page is allocated from a mempool. Mempool allocations with GFP_NOFS never fail. Therefore, fscrypt_encrypt_pagecache_blocks() can no longer return -ENOMEM when passed GFP_NOFS.

Remove the now-unreachable code from f2fs_encrypt_one_page().

---
 fs/f2fs/data.c | 14 ++------------
 1 file changed, 2 insertions(+), 12 deletions(-)
fs/f2fs/data.c +2 -12
index 338df7a2aea6..400f0400e13d 100644
@@ -2785,33 +2785,23 @@ static void f2fs_readahead(struct readahead_control *rac)
 int f2fs_encrypt_one_page(struct f2fs_io_info *fio)
 {
 	struct inode *inode = fio_inode(fio);
 	struct folio *mfolio;
 	struct page *page;
-	gfp_t gfp_flags = GFP_NOFS;
 
 	if (!f2fs_encrypted_file(inode))
 		return 0;
 
 	page = fio->compressed_page ? fio->compressed_page : fio->page;
 
 	if (fscrypt_inode_uses_inline_crypto(inode))
 		return 0;
 
-retry_encrypt:
 	fio->encrypted_page = fscrypt_encrypt_pagecache_blocks(page_folio(page),
-					PAGE_SIZE, 0, gfp_flags);
-	if (IS_ERR(fio->encrypted_page)) {
-		/* flush pending IOs and wait for a while in the ENOMEM case */
-		if (PTR_ERR(fio->encrypted_page) == -ENOMEM) {
-			f2fs_flush_merged_writes(fio->sbi);
-			memalloc_retry_wait(GFP_NOFS);
-			gfp_flags |= __GFP_NOFAIL;
-			goto retry_encrypt;
-		}
+					PAGE_SIZE, 0, GFP_NOFS);
+	if (IS_ERR(fio->encrypted_page))
 		return PTR_ERR(fio->encrypted_page);
-	}
 
 	mfolio = filemap_lock_folio(META_MAPPING(fio->sbi), fio->old_blkaddr);
 	if (!IS_ERR(mfolio)) {
 		if (folio_test_uptodate(mfolio))
 			memcpy(folio_address(mfolio),

base-commit: 8934827db5403eae57d4537114a9ff88b0a8460f

Signature · 1 line
2.53.0
author Acked-by Vlastimil Babka (SUSE) on v1 1/1
#2 lore raw
In reply to Eric Biggers via Linux-f2fs-devel
Quoted 9 lines · Eric Biggers

Since commit 52e7e0d88933 ("fscrypt: Switch to sync_skcipher and on-stack requests") eliminated the dynamic allocation of crypto requests, the only remaining dynamic memory allocation done by fscrypt_encrypt_pagecache_blocks() is the bounce page allocation.

The bounce page is allocated from a mempool. Mempool allocations with GFP_NOFS never fail. Therefore, fscrypt_encrypt_pagecache_blocks() can no longer return -ENOMEM when passed GFP_NOFS.

Quoted 5 lines

Remove the now-unreachable code from f2fs_encrypt_one_page().

Thanks!

Quoted 46 lines
---
 fs/f2fs/data.c | 14 ++------------
 1 file changed, 2 insertions(+), 12 deletions(-)
fs/f2fs/data.c +2 -12
index 338df7a2aea6..400f0400e13d 100644
@@ -2785,33 +2785,23 @@ static void f2fs_readahead(struct readahead_control *rac)
 int f2fs_encrypt_one_page(struct f2fs_io_info *fio)
 {
 	struct inode *inode = fio_inode(fio);
 	struct folio *mfolio;
 	struct page *page;
-	gfp_t gfp_flags = GFP_NOFS;
 
 	if (!f2fs_encrypted_file(inode))
 		return 0;
 
 	page = fio->compressed_page ? fio->compressed_page : fio->page;
 
 	if (fscrypt_inode_uses_inline_crypto(inode))
 		return 0;
 
-retry_encrypt:
 	fio->encrypted_page = fscrypt_encrypt_pagecache_blocks(page_folio(page),
-					PAGE_SIZE, 0, gfp_flags);
-	if (IS_ERR(fio->encrypted_page)) {
-		/* flush pending IOs and wait for a while in the ENOMEM case */
-		if (PTR_ERR(fio->encrypted_page) == -ENOMEM) {
-			f2fs_flush_merged_writes(fio->sbi);
-			memalloc_retry_wait(GFP_NOFS);
-			gfp_flags |= __GFP_NOFAIL;
-			goto retry_encrypt;
-		}
+					PAGE_SIZE, 0, GFP_NOFS);
+	if (IS_ERR(fio->encrypted_page))
 		return PTR_ERR(fio->encrypted_page);
-	}
 
 	mfolio = filemap_lock_folio(META_MAPPING(fio->sbi), fio->old_blkaddr);
 	if (!IS_ERR(mfolio)) {
 		if (folio_test_uptodate(mfolio))
 			memcpy(folio_address(mfolio),

base-commit: 8934827db5403eae57d4537114a9ff88b0a8460f

author Reviewed-by Chao Yu on v1 1/1
#3 lore raw
In reply to Eric Biggers via Linux-f2fs-devel
Quoted 9 lines · Eric Biggers

Since commit 52e7e0d88933 ("fscrypt: Switch to sync_skcipher and on-stack requests") eliminated the dynamic allocation of crypto requests, the only remaining dynamic memory allocation done by fscrypt_encrypt_pagecache_blocks() is the bounce page allocation.

The bounce page is allocated from a mempool. Mempool allocations with GFP_NOFS never fail. Therefore, fscrypt_encrypt_pagecache_blocks() can no longer return -ENOMEM when passed GFP_NOFS.

Quoted 5 lines

Remove the now-unreachable code from f2fs_encrypt_one_page().

Thanks,