public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/2] f2fs: Constrain the modification range of dir_level in the sysfs
@ 2023-12-22  3:29 Yongpeng Yang
  2023-12-22  3:29 ` [PATCH 2/2] f2fs: Add error handling for negative returns from do_garbage_collect Yongpeng Yang
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Yongpeng Yang @ 2023-12-22  3:29 UTC (permalink / raw)
  To: Jaegeuk Kim, Chao Yu; +Cc: linux-f2fs-devel, linux-kernel, Yongpeng Yang

The {struct f2fs_sb_info}->dir_level can be modified through the sysfs
interface, but its value range is not limited. If the value exceeds
MAX_DIR_HASH_DEPTH and the mount options include "noinline_dentry",
the following error will occur:
[root@fedora ~]# mount -o noinline_dentry /dev/sdb  /mnt/sdb/
[root@fedora ~]# echo 128 > /sys/fs/f2fs/sdb/dir_level
[root@fedora ~]# cd /mnt/sdb/
[root@fedora sdb]# mkdir test
[root@fedora sdb]# cd test/
[root@fedora test]# mkdir test
mkdir: cannot create directory 'test': Argument list too long

Signed-off-by: Yongpeng Yang <yangyongpeng1@oppo.com>
---
 fs/f2fs/sysfs.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/fs/f2fs/sysfs.c b/fs/f2fs/sysfs.c
index 7099ffa57299..8c8424b05fc7 100644
--- a/fs/f2fs/sysfs.c
+++ b/fs/f2fs/sysfs.c
@@ -741,6 +741,13 @@ static ssize_t __sbi_store(struct f2fs_attr *a,
 		return count;
 	}
 
+	if (!strcmp(a->attr.name, "dir_level")) {
+		if (t > MAX_DIR_HASH_DEPTH)
+			return -EINVAL;
+		sbi->dir_level = t;
+		return count;
+	}
+
 	*ui = (unsigned int)t;
 
 	return count;
-- 
2.40.1


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

* [PATCH 2/2] f2fs: Add error handling for negative returns from do_garbage_collect
  2023-12-22  3:29 [PATCH 1/2] f2fs: Constrain the modification range of dir_level in the sysfs Yongpeng Yang
@ 2023-12-22  3:29 ` Yongpeng Yang
  2023-12-22  9:42   ` Chao Yu
  2023-12-22  9:42 ` [PATCH 1/2] f2fs: Constrain the modification range of dir_level in the sysfs Chao Yu
  2023-12-29 19:10 ` [f2fs-dev] " patchwork-bot+f2fs
  2 siblings, 1 reply; 5+ messages in thread
From: Yongpeng Yang @ 2023-12-22  3:29 UTC (permalink / raw)
  To: Jaegeuk Kim, Chao Yu; +Cc: linux-f2fs-devel, linux-kernel, Yongpeng Yang

The function do_garbage_collect can return a value less than 0 due
to f2fs_cp_error being true or page allocation failure, as a result
of calling f2fs_get_sum_page. However, f2fs_gc does not account for
such cases, which could potentially lead to an abnormal total_freed
and thus cause subsequent code to behave unexpectedly. Given that
an f2fs_cp_error is irrecoverable, and considering that
do_garbage_collect already retries page allocation errors through
its call to f2fs_get_sum_page->f2fs_get_meta_page_retry, any error
reported by do_garbage_collect should immediately terminate the
current GC.

Signed-off-by: Yongpeng Yang <yangyongpeng1@oppo.com>
---
 fs/f2fs/gc.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/fs/f2fs/gc.c b/fs/f2fs/gc.c
index 405a6077bd83..771d56b0bfb8 100644
--- a/fs/f2fs/gc.c
+++ b/fs/f2fs/gc.c
@@ -1865,6 +1865,9 @@ int f2fs_gc(struct f2fs_sb_info *sbi, struct f2fs_gc_control *gc_control)
 
 	seg_freed = do_garbage_collect(sbi, segno, &gc_list, gc_type,
 				gc_control->should_migrate_blocks);
+	if (seg_freed < 0)
+		goto stop;
+
 	total_freed += seg_freed;
 
 	if (seg_freed == f2fs_usable_segs_in_sec(sbi, segno)) {
-- 
2.40.1


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

* Re: [PATCH 1/2] f2fs: Constrain the modification range of dir_level in the sysfs
  2023-12-22  3:29 [PATCH 1/2] f2fs: Constrain the modification range of dir_level in the sysfs Yongpeng Yang
  2023-12-22  3:29 ` [PATCH 2/2] f2fs: Add error handling for negative returns from do_garbage_collect Yongpeng Yang
@ 2023-12-22  9:42 ` Chao Yu
  2023-12-29 19:10 ` [f2fs-dev] " patchwork-bot+f2fs
  2 siblings, 0 replies; 5+ messages in thread
From: Chao Yu @ 2023-12-22  9:42 UTC (permalink / raw)
  To: Yongpeng Yang, Jaegeuk Kim; +Cc: linux-f2fs-devel, linux-kernel

On 2023/12/22 11:29, Yongpeng Yang wrote:
> The {struct f2fs_sb_info}->dir_level can be modified through the sysfs
> interface, but its value range is not limited. If the value exceeds
> MAX_DIR_HASH_DEPTH and the mount options include "noinline_dentry",
> the following error will occur:
> [root@fedora ~]# mount -o noinline_dentry /dev/sdb  /mnt/sdb/
> [root@fedora ~]# echo 128 > /sys/fs/f2fs/sdb/dir_level
> [root@fedora ~]# cd /mnt/sdb/
> [root@fedora sdb]# mkdir test
> [root@fedora sdb]# cd test/
> [root@fedora test]# mkdir test
> mkdir: cannot create directory 'test': Argument list too long
> 
> Signed-off-by: Yongpeng Yang <yangyongpeng1@oppo.com>

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

Thanks,

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

* Re: [PATCH 2/2] f2fs: Add error handling for negative returns from do_garbage_collect
  2023-12-22  3:29 ` [PATCH 2/2] f2fs: Add error handling for negative returns from do_garbage_collect Yongpeng Yang
@ 2023-12-22  9:42   ` Chao Yu
  0 siblings, 0 replies; 5+ messages in thread
From: Chao Yu @ 2023-12-22  9:42 UTC (permalink / raw)
  To: Yongpeng Yang, Jaegeuk Kim; +Cc: linux-f2fs-devel, linux-kernel

On 2023/12/22 11:29, Yongpeng Yang wrote:
> The function do_garbage_collect can return a value less than 0 due
> to f2fs_cp_error being true or page allocation failure, as a result
> of calling f2fs_get_sum_page. However, f2fs_gc does not account for
> such cases, which could potentially lead to an abnormal total_freed
> and thus cause subsequent code to behave unexpectedly. Given that
> an f2fs_cp_error is irrecoverable, and considering that
> do_garbage_collect already retries page allocation errors through
> its call to f2fs_get_sum_page->f2fs_get_meta_page_retry, any error
> reported by do_garbage_collect should immediately terminate the
> current GC.
> 
> Signed-off-by: Yongpeng Yang <yangyongpeng1@oppo.com>

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

Thanks,

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

* Re: [f2fs-dev] [PATCH 1/2] f2fs: Constrain the modification range of dir_level in the sysfs
  2023-12-22  3:29 [PATCH 1/2] f2fs: Constrain the modification range of dir_level in the sysfs Yongpeng Yang
  2023-12-22  3:29 ` [PATCH 2/2] f2fs: Add error handling for negative returns from do_garbage_collect Yongpeng Yang
  2023-12-22  9:42 ` [PATCH 1/2] f2fs: Constrain the modification range of dir_level in the sysfs Chao Yu
@ 2023-12-29 19:10 ` patchwork-bot+f2fs
  2 siblings, 0 replies; 5+ messages in thread
From: patchwork-bot+f2fs @ 2023-12-29 19:10 UTC (permalink / raw)
  To: Yongpeng Yang; +Cc: jaegeuk, chao, linux-kernel, linux-f2fs-devel

Hello:

This series was applied to jaegeuk/f2fs.git (dev)
by Jaegeuk Kim <jaegeuk@kernel.org>:

On Fri, 22 Dec 2023 11:29:00 +0800 you wrote:
> The {struct f2fs_sb_info}->dir_level can be modified through the sysfs
> interface, but its value range is not limited. If the value exceeds
> MAX_DIR_HASH_DEPTH and the mount options include "noinline_dentry",
> the following error will occur:
> [root@fedora ~]# mount -o noinline_dentry /dev/sdb  /mnt/sdb/
> [root@fedora ~]# echo 128 > /sys/fs/f2fs/sdb/dir_level
> [root@fedora ~]# cd /mnt/sdb/
> [root@fedora sdb]# mkdir test
> [root@fedora sdb]# cd test/
> [root@fedora test]# mkdir test
> mkdir: cannot create directory 'test': Argument list too long
> 
> [...]

Here is the summary with links:
  - [f2fs-dev,1/2] f2fs: Constrain the modification range of dir_level in the sysfs
    https://git.kernel.org/jaegeuk/f2fs/c/0145eed6ed32
  - [f2fs-dev,2/2] f2fs: Add error handling for negative returns from do_garbage_collect
    https://git.kernel.org/jaegeuk/f2fs/c/19ec1d31fa56

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



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

end of thread, other threads:[~2023-12-29 19:10 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-12-22  3:29 [PATCH 1/2] f2fs: Constrain the modification range of dir_level in the sysfs Yongpeng Yang
2023-12-22  3:29 ` [PATCH 2/2] f2fs: Add error handling for negative returns from do_garbage_collect Yongpeng Yang
2023-12-22  9:42   ` Chao Yu
2023-12-22  9:42 ` [PATCH 1/2] f2fs: Constrain the modification range of dir_level in the sysfs Chao Yu
2023-12-29 19:10 ` [f2fs-dev] " patchwork-bot+f2fs

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox