Skip to contentSkip to conversation

f2fs: fix error path handling in f2fs_read_data_large_folio()

PATCH Superseded Chao Yu 2 participants 3 messages Jan 8 – Jan 9 F2FS file system

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Chao Yu

author maintainer
#0 lore raw

PATCH 1/1 f2fs: fix error path handling in f2fs_read_data_large_folio()

In error path of f2fs_read_data_large_folio(), if bio is valid, it may submit bio twice, fix it.

---
 fs/f2fs/data.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)
fs/f2fs/data.c +2 -5
index cabaeeb436bd..386d9adfd4bd 100644
@@ -2568,17 +2568,14 @@ static int f2fs_read_data_large_folio(struct inode *inode,
 		folio_unlock(folio);
 		return ret;
 	}
-
+out:
+	f2fs_submit_read_bio(F2FS_I_SB(inode), bio, DATA);
 	if (ret) {
-		f2fs_submit_read_bio(F2FS_I_SB(inode), bio, DATA);
-
 		/* Wait bios and clear uptodate. */
 		folio_lock(folio);
 		folio_clear_uptodate(folio);
 		folio_unlock(folio);
 	}
-out:
-	f2fs_submit_read_bio(F2FS_I_SB(inode), bio, DATA);
 	return ret;
 }
 
Signature · 1 line
2.40.1
#1 lore raw
Quoted 2 lines · On Thu, 8 Jan 2026 05:42:31 +0800 Chao Yu <[email protected]> wrote:

In error path of f2fs_read_data_large_folio(), if bio is valid, it may submit bio twice, fix it.

That isn't the only bug at the bottom of that function.
I think I've unravelled the strange loops on the copy in linux-next. The 'goto got_it' could be a normal conditional.

The top has:

	if (rac)
		folio = readahead_folio(rac);
next_folio:
	if (!folio)
		goto out:

which means you can 'goto out' before setting up a pending 'bio'.

I'm sure that could be made a proper loop - although it would cost an indentation. Would certainly be better with only one call to readahead_foilio(), perhaps:
next_folio:

	if (rac) {
		folio = readahead_folio(rac);
		if (!folio)
			goto out:
	}
with just:
	if (rac)
		goto next_folio;

at the bottom.

Quoted 12 lines
---
 fs/f2fs/data.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)
fs/f2fs/data.c +0 -0
index cabaeeb436bd..386d9adfd4bd 100644
@@ -2568,17 +2568,14 @@ static int f2fs_read_data_large_folio(struct inode *inode,
 		folio_unlock(folio);

fs/f2fs/data.c static int f2fs_read_data_large_folio(struct inode *inode, · line 2575

Quoted 10 lines
fs/f2fs/data.c +2 -3
 		return ret;
 	}
-
+out:
+	f2fs_submit_read_bio(F2FS_I_SB(inode), bio, DATA);
 	if (ret) {
-		f2fs_submit_read_bio(F2FS_I_SB(inode), bio, DATA);
-
 		/* Wait bios and clear uptodate. */
 		folio_lock(folio);

If I've read the code correctly the 'bio' can contain transfers for a previous folio(s), and might have transfers for this folio, but might not. So relocking the folio may just deadlock.
(I've not found the unlock at the end of transfer...)
Quite which 'bio' need the flag changed is another question.

David

Quoted 8 lines
fs/f2fs/data.c +0 -2
 		folio_clear_uptodate(folio);
 		folio_unlock(folio);
 	}
-out:
-	f2fs_submit_read_bio(F2FS_I_SB(inode), bio, DATA);
 	return ret;
 }
 
author maintainer
#2 lore raw
Quoted 29 lines · David Laight
Quoted 2 lines · On Thu, 8 Jan 2026 05:42:31 +0800 Chao Yu <[email protected]> wrote:

In error path of f2fs_read_data_large_folio(), if bio is valid, it may submit bio twice, fix it.

That isn't the only bug at the bottom of that function.
I think I've unravelled the strange loops on the copy in linux-next. The 'goto got_it' could be a normal conditional.

The top has:

	if (rac)
		folio = readahead_folio(rac);
next_folio:
	if (!folio)
		goto out:

which means you can 'goto out' before setting up a pending 'bio'.

I'm sure that could be made a proper loop - although it would cost an indentation. Would certainly be better with only one call to readahead_foilio(), perhaps:
next_folio:

	if (rac) {
		folio = readahead_folio(rac);
		if (!folio)
			goto out:
	}
with just:
	if (rac)
		goto next_folio;
Quoted 1 line

at the bottom.

It could be, maybe you can clean up w/ a separated patch?

Quoted 20 lines
Quoted 20 lines
---
  fs/f2fs/data.c | 7 ++-----
  1 file changed, 2 insertions(+), 5 deletions(-)
fs/f2fs/data.c +2 -1
index cabaeeb436bd..386d9adfd4bd 100644
@@ -2568,17 +2568,14 @@ static int f2fs_read_data_large_folio(struct inode *inode,
  		folio_unlock(folio);
  		return ret;
  	}
-
+out:
+	f2fs_submit_read_bio(F2FS_I_SB(inode), bio, DATA);
  	if (ret) {
Quoted 8 lines

fs/f2fs/data.c static int f2fs_read_data_large_folio(struct inode *inode, · line 2575

Quoted 4 lines
fs/f2fs/data.c +0 -2
-		f2fs_submit_read_bio(F2FS_I_SB(inode), bio, DATA);
-
  		/* Wait bios and clear uptodate. */
  		folio_lock(folio);

If I've read the code correctly the 'bio' can contain transfers for a previous folio(s), and might have transfers for this folio, but might not. So relocking the folio may just deadlock.

The bio may contain last folio which has not been committed to device, as you said the folio has been locked, and after IO completion, we will unlock the folio in f2fs_finish_read_bio(), so no deadlock?

Thanks,

Quoted 14 lines

(I've not found the unlock at the end of transfer...) Quite which 'bio' need the flag changed is another question.

David

Quoted 8 lines
fs/f2fs/data.c +0 -2
  		folio_clear_uptodate(folio);
  		folio_unlock(folio);
  	}
-out:
-	f2fs_submit_read_bio(F2FS_I_SB(inode), bio, DATA);
  	return ret;
  }