Skip to contentSkip to conversation

f2fs: fix to tag STATX_DIOALIGN only if inode support dio

PATCH In review Chao Yu 2 participants 4 messages Sep 10, 2024 – Sep 11, 2024 F2FS file system

lore
Share & tools
lore

Chao Yu

author maintainer
#0 lore raw

PATCH 1/1 f2fs: fix to tag STATX_DIOALIGN only if inode support dio

After commit 5c8764f8679e ("f2fs: fix to force buffered IO on inline_data inode"), f2fs starts to force using buffered IO on inline_data inode.

And also, it will cause f2fs_getattr() returning invalid zeroed value on .dio_mem_align and .dio_offset_align fields, however, STATX_DIOALIGN flag was been tagged. User may use zeroed .stx_dio_offset_align value since STATX_DIOALIGN was been tagged, then it causes a deadloop during generic/465 test due to below logic:

align=stx_dio_offset_align(it equals to zero)
page_size=4096
while [ $align -le $page_size ]; do
echo "$AIO_TEST -a $align -d $testfile.$align" >> $seqres.full $AIO_TEST -a $align -d $testfile.$align 2>&1 | tee -a $seqres.full align=$((align * 2))
done

Quoted from description of statx manual:

" If a filesystem does not support a field or if it has an
unrepresentable value (for instance, a file with an exotic type), then the mask bit corresponding to that field will be cleared in stx_mask even if the user asked for it and a dummy value will be filled in for compatibility purposes if one is available (e.g., a dummy UID and GID may be specified to mount under some circumstances)."

We should not set STATX_DIOALIGN flag in kstat.stx_mask if inode does not support DIO, so that it can indicate related fields contain dummy value, and avoid following incorrect use of them.

Fixes c8c02272a9f7 ("f2fs: support STATX_DIOALIGN")
---
 fs/f2fs/file.c | 11 ++++-------
 1 file changed, 4 insertions(+), 7 deletions(-)
fs/f2fs/file.c +4 -7
index 99903eafa7fe..f0b8b77e93ba 100644
@@ -906,14 +906,11 @@ int f2fs_getattr(struct mnt_idmap *idmap, const struct path *path,
 	 * f2fs sometimes supports DIO reads but not DIO writes.  STATX_DIOALIGN
 	 * cannot represent that, so in that case we report no DIO support.
 	 */
-	if ((request_mask & STATX_DIOALIGN) && S_ISREG(inode->i_mode)) {
-		unsigned int bsize = i_blocksize(inode);
-
+	if ((request_mask & STATX_DIOALIGN) && S_ISREG(inode->i_mode) &&
+				!f2fs_force_buffered_io(inode, WRITE)) {
+		stat->dio_mem_align = F2FS_BLKSIZE;
+		stat->dio_offset_align = F2FS_BLKSIZE;
 		stat->result_mask |= STATX_DIOALIGN;
-		if (!f2fs_force_buffered_io(inode, WRITE)) {
-			stat->dio_mem_align = bsize;
-			stat->dio_offset_align = bsize;
-		}
 	}
 
 	flags = fi->i_flags;
Signature · 1 line
2.40.1
#1 lore raw
Quoted 27 lines · On Tue, Sep 10, 2024 at 08:57:53PM +0800, Chao Yu via Linux-f2fs-devel wrote:

After commit 5c8764f8679e ("f2fs: fix to force buffered IO on inline_data inode"), f2fs starts to force using buffered IO on inline_data inode.

And also, it will cause f2fs_getattr() returning invalid zeroed value on .dio_mem_align and .dio_offset_align fields, however, STATX_DIOALIGN flag was been tagged. User may use zeroed .stx_dio_offset_align value since STATX_DIOALIGN was been tagged, then it causes a deadloop during generic/465 test due to below logic:

align=stx_dio_offset_align(it equals to zero)
page_size=4096
while [ $align -le $page_size ]; do
echo "$AIO_TEST -a $align -d $testfile.$align" >> $seqres.full $AIO_TEST -a $align -d $testfile.$align 2>&1 | tee -a $seqres.full align=$((align * 2))
done

Quoted from description of statx manual:

" If a filesystem does not support a field or if it has an
unrepresentable value (for instance, a file with an exotic type), then the mask bit corresponding to that field will be cleared in stx_mask even if the user asked for it and a dummy value will be filled in for compatibility purposes if one is available (e.g., a dummy UID and GID may be specified to mount under some circumstances)."

Quoted 5 lines

We should not set STATX_DIOALIGN flag in kstat.stx_mask if inode does not support DIO, so that it can indicate related fields contain dummy value, and avoid following incorrect use of them.

Fixes c8c02272a9f7 ("f2fs: support STATX_DIOALIGN")

When claiming to be Fixing a commit, please make sure to Cc the author of that commit.

Quoted 18 lines
---
 fs/f2fs/file.c | 11 ++++-------
 1 file changed, 4 insertions(+), 7 deletions(-)
fs/f2fs/file.c +2 -3
index 99903eafa7fe..f0b8b77e93ba 100644
@@ -906,14 +906,11 @@ int f2fs_getattr(struct mnt_idmap *idmap, const struct path *path,
 	 * f2fs sometimes supports DIO reads but not DIO writes.  STATX_DIOALIGN
 	 * cannot represent that, so in that case we report no DIO support.
 	 */
-	if ((request_mask & STATX_DIOALIGN) && S_ISREG(inode->i_mode)) {
-		unsigned int bsize = i_blocksize(inode);
-
+	if ((request_mask & STATX_DIOALIGN) && S_ISREG(inode->i_mode) &&
+				!f2fs_force_buffered_io(inode, WRITE)) {

fs/f2fs/file.c int f2fs_getattr(struct mnt_idmap *idmap, const struct path *path, · line 916

Quoted 10 lines
fs/f2fs/file.c +2 -4
+		stat->dio_mem_align = F2FS_BLKSIZE;
+		stat->dio_offset_align = F2FS_BLKSIZE;
 		stat->result_mask |= STATX_DIOALIGN;
-		if (!f2fs_force_buffered_io(inode, WRITE)) {
-			stat->dio_mem_align = bsize;
-			stat->dio_offset_align = bsize;
-		}
 	}
 
 	flags = fi->i_flags;

No, this patch is wrong and the existing code is correct. The cases are:

STATX_DIOALIGN set and stx_dio_*_align nonzero:
File supports DIO.

STATX_DIOALIGN set and stx_dio_*_align zero:
File doesn't support DIO.

STATX_DIOALIGN unset:
Filesystem doesn't support STATX_DIOALIGN, so it's unknown whether the file supports DIO or not.

Please see the statx(2) manual page which explains this too.

- Eric

author maintainer
#2 lore raw
Quoted 28 lines · Eric Biggers
Quoted 27 lines · On Tue, Sep 10, 2024 at 08:57:53PM +0800, Chao Yu via Linux-f2fs-devel wrote:

After commit 5c8764f8679e ("f2fs: fix to force buffered IO on inline_data inode"), f2fs starts to force using buffered IO on inline_data inode.

And also, it will cause f2fs_getattr() returning invalid zeroed value on .dio_mem_align and .dio_offset_align fields, however, STATX_DIOALIGN flag was been tagged. User may use zeroed .stx_dio_offset_align value since STATX_DIOALIGN was been tagged, then it causes a deadloop during generic/465 test due to below logic:

align=stx_dio_offset_align(it equals to zero)
page_size=4096
while [ $align -le $page_size ]; do
echo "$AIO_TEST -a $align -d $testfile.$align" >> $seqres.full $AIO_TEST -a $align -d $testfile.$align 2>&1 | tee -a $seqres.full align=$((align * 2))
done

Quoted from description of statx manual:

" If a filesystem does not support a field or if it has an
unrepresentable value (for instance, a file with an exotic type), then the mask bit corresponding to that field will be cleared in stx_mask even if the user asked for it and a dummy value will be filled in for compatibility purposes if one is available (e.g., a dummy UID and GID may be specified to mount under some circumstances)."

Quoted 8 lines
Quoted 5 lines

We should not set STATX_DIOALIGN flag in kstat.stx_mask if inode does not support DIO, so that it can indicate related fields contain dummy value, and avoid following incorrect use of them.

Fixes c8c02272a9f7 ("f2fs: support STATX_DIOALIGN")

When claiming to be Fixing a commit, please make sure to Cc the author of that commit.

No problem, will make sure they were Cced.

Quoted 28 lines
Quoted 28 lines
---
  fs/f2fs/file.c | 11 ++++-------
  1 file changed, 4 insertions(+), 7 deletions(-)
fs/f2fs/file.c +4 -7
index 99903eafa7fe..f0b8b77e93ba 100644
@@ -906,14 +906,11 @@ int f2fs_getattr(struct mnt_idmap *idmap, const struct path *path,
  	 * f2fs sometimes supports DIO reads but not DIO writes.  STATX_DIOALIGN
  	 * cannot represent that, so in that case we report no DIO support.
  	 */
-	if ((request_mask & STATX_DIOALIGN) && S_ISREG(inode->i_mode)) {
-		unsigned int bsize = i_blocksize(inode);
-
+	if ((request_mask & STATX_DIOALIGN) && S_ISREG(inode->i_mode) &&
+				!f2fs_force_buffered_io(inode, WRITE)) {
+		stat->dio_mem_align = F2FS_BLKSIZE;
+		stat->dio_offset_align = F2FS_BLKSIZE;
  		stat->result_mask |= STATX_DIOALIGN;
-		if (!f2fs_force_buffered_io(inode, WRITE)) {
-			stat->dio_mem_align = bsize;
-			stat->dio_offset_align = bsize;
-		}
  	}
 
Quoted 3 lines

fs/f2fs/file.c int f2fs_getattr(struct mnt_idmap *idmap, const struct path *path, · line 916

Quoted 1 line
fs/f2fs/file.c +0 -0
  	flags = fi->i_flags;

No, this patch is wrong and the existing code is correct. The cases are:

Yes, you're right, thanks for pointing out this!

Quoted 10 lines

STATX_DIOALIGN set and stx_dio_*_align nonzero:
File supports DIO.

STATX_DIOALIGN set and stx_dio_*_align zero:
File doesn't support DIO.

STATX_DIOALIGN unset:
Filesystem doesn't support STATX_DIOALIGN, so it's unknown whether the file supports DIO or not.

Above description is clear to me.

Quoted 2 lines

Please see the statx(2) manual page which explains this too.

However, below manual seems not very clear about explaining what does it mean about STATX_DIOALIGN is set or not? At least not so clear like above description.

stx_dio_mem_align
The alignment (in bytes) required for user memory buffers for direct I/O (O_DIRECT) on this file, or 0 if direct I/O is not supported on this file.

STATX_DIOALIGN (stx_dio_mem_align and stx_dio_offset_align) is supported on block devices since Linux 6.1. The support on regular files varies by filesystem; it is supported by ext4, f2fs, and xfs since Linux 6.1.

stx_dio_offset_align
The alignment (in bytes) required for file offsets and I/O segment lengths for direct I/O (O_DIRECT) on this file, or 0 if direct I/O is not supported on this file. This will only be nonzero if stx_dio_mem_align is nonzero, and vice versa.

Thanks,

Quoted 2 lines

- Eric

#3 lore raw
Quoted 84 lines · Chao Yu
Quoted 28 lines · Eric Biggers
Quoted 27 lines · On Tue, Sep 10, 2024 at 08:57:53PM +0800, Chao Yu via Linux-f2fs-devel wrote:

After commit 5c8764f8679e ("f2fs: fix to force buffered IO on inline_data inode"), f2fs starts to force using buffered IO on inline_data inode.

And also, it will cause f2fs_getattr() returning invalid zeroed value on .dio_mem_align and .dio_offset_align fields, however, STATX_DIOALIGN flag was been tagged. User may use zeroed .stx_dio_offset_align value since STATX_DIOALIGN was been tagged, then it causes a deadloop during generic/465 test due to below logic:

align=stx_dio_offset_align(it equals to zero)
page_size=4096
while [ $align -le $page_size ]; do
echo "$AIO_TEST -a $align -d $testfile.$align" >> $seqres.full $AIO_TEST -a $align -d $testfile.$align 2>&1 | tee -a $seqres.full align=$((align * 2))
done

Quoted from description of statx manual:

" If a filesystem does not support a field or if it has an
unrepresentable value (for instance, a file with an exotic type), then the mask bit corresponding to that field will be cleared in stx_mask even if the user asked for it and a dummy value will be filled in for compatibility purposes if one is available (e.g., a dummy UID and GID may be specified to mount under some circumstances)."

Quoted 8 lines
Quoted 5 lines

We should not set STATX_DIOALIGN flag in kstat.stx_mask if inode does not support DIO, so that it can indicate related fields contain dummy value, and avoid following incorrect use of them.

Fixes c8c02272a9f7 ("f2fs: support STATX_DIOALIGN")

When claiming to be Fixing a commit, please make sure to Cc the author of that commit.

No problem, will make sure they were Cced.

Quoted 22 lines
Quoted 22 lines
---
  fs/f2fs/file.c | 11 ++++-------
  1 file changed, 4 insertions(+), 7 deletions(-)
fs/f2fs/file.c +4 -3
index 99903eafa7fe..f0b8b77e93ba 100644
@@ -906,14 +906,11 @@ int f2fs_getattr(struct mnt_idmap *idmap, const struct path *path,
  	 * f2fs sometimes supports DIO reads but not DIO writes.  STATX_DIOALIGN
  	 * cannot represent that, so in that case we report no DIO support.
  	 */
-	if ((request_mask & STATX_DIOALIGN) && S_ISREG(inode->i_mode)) {
-		unsigned int bsize = i_blocksize(inode);
-
+	if ((request_mask & STATX_DIOALIGN) && S_ISREG(inode->i_mode) &&
+				!f2fs_force_buffered_io(inode, WRITE)) {
+		stat->dio_mem_align = F2FS_BLKSIZE;
+		stat->dio_offset_align = F2FS_BLKSIZE;
  		stat->result_mask |= STATX_DIOALIGN;
Quoted 8 lines

fs/f2fs/file.c int f2fs_getattr(struct mnt_idmap *idmap, const struct path *path, · line 916

Quoted 6 lines
fs/f2fs/file.c +0 -4
-		if (!f2fs_force_buffered_io(inode, WRITE)) {
-			stat->dio_mem_align = bsize;
-			stat->dio_offset_align = bsize;
-		}
  	}
  	flags = fi->i_flags;

No, this patch is wrong and the existing code is correct. The cases are:

Yes, you're right, thanks for pointing out this!

Quoted 10 lines

STATX_DIOALIGN set and stx_dio_*_align nonzero:
File supports DIO.

STATX_DIOALIGN set and stx_dio_*_align zero:
File doesn't support DIO.

STATX_DIOALIGN unset:
Filesystem doesn't support STATX_DIOALIGN, so it's unknown whether the file supports DIO or not.

Quoted 9 lines

Above description is clear to me.

Quoted 2 lines

Please see the statx(2) manual page which explains this too.

However, below manual seems not very clear about explaining what does it mean about STATX_DIOALIGN is set or not? At least not so clear like above description.

It just works the same way that the other statx mask bits work. See the following paragraph:

If a filesystem does not support a field or if it has an unrepresentable value (for instance, a file with an exotic type), then the mask bit corresponding to that field will be cleared in stx_mask even if the user asked for it and a dummy value will be filled in for compatibility purposes if one is available (e.g., a dummy UID and GID may be specified to mount under some circumstances).

It might be worth an explicit note in the documentation for stx_dio_mem_align, but I considered it to be covered by the above.

- Eric