f2fs: Fix data consistency in f2fs_move_file_range()
PATCH 1/1 f2fs: Fix data consistency in f2fs_move_file_range()
In the following case:
process 1 process 2
->open A
->mmap
->read # the first time
->ioctl w/h F2FS_IOC_MOVE_RANGE
# (range A->B)
->read # the second time
We will read old data at the second time. The root cause is that user still can see the previous source data after being moved. We fix it by adding truncating after __exchange_data_block.
---
v2:
- moving truncating to the range of f2fs_lock_op()
v3:
- modify the title and commit message
--- fs/f2fs/file.c | 3 +++ 1 file changed, 3 insertions(+)
fs/f2fs/file.c +3 -0
@@ -2824,6 +2824,7 @@ static int f2fs_move_file_range(struct file *file_in, loff_t pos_in, goto out_src; } +filemap_invalidate_lock (src->i_mapping);f2fs_lock_op (sbi); ret = __exchange_data_block(src, dst, pos_in >> F2FS_BLKSIZE_BITS, pos_out >> F2FS_BLKSIZE_BITS,
@@ -2835,7 +2836,9 @@ static int f2fs_move_file_range(struct file *file_in, loff_t pos_in,else if (dst_osize != dst->i_size)f2fs_i_size_write (dst, dst_osize); } +truncate_pagecache_range (src, pos_in, pos_in + len -1 );f2fs_unlock_op (sbi); +filemap_invalidate_unlock (src->i_mapping);if (src != dst)f2fs_up_write (&F2FS_I (dst)->i_gc_rwsem[WRITE ]);
Signature · 8 lines
2.25.1 _______________________________________________ Linux-f2fs-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
PATCH 1/1 f2fs: Fix the race condition of resize flag between resizefs
Because the set/clear SBI_IS_RESIZEFS flag not between any locks, In the following case:
thread1 thread2
->ioctl(resizefs)
->set RESIZEFS flag ->ioctl(resizefs)
... ->set RESIZEFS flag
->clear RESIZEFS flag
->resizefs stream
# No RESIZEFS flag in the streamAlso before freeze_super, the resizefs not started, we should not set the SBI_IS_RESIZEFS flag.
So move the set/clear SBI_IS_RESIZEFS flag between the cp_mutex and gc_lock.
---
v2:
- modify commit message
--- fs/f2fs/gc.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
fs/f2fs/gc.c +2 -3
@@ -2133,8 +2133,6 @@ int f2fs_resize_fs(struct f2fs_sb_info *sbi, __u64 block_count)if (err)return err; -set_sbi_flag (sbi,SBI_IS_RESIZEFS ); -freeze_super (sbi->sb);f2fs_down_write (&sbi->gc_lock);f2fs_down_write (&sbi->cp_global_sem);
@@ -2150,6 +2148,7 @@ int f2fs_resize_fs(struct f2fs_sb_info *sbi, __u64 block_count)if (err) goto out_err; +set_sbi_flag (sbi,SBI_IS_RESIZEFS ); err =free_segment_range (sbi, secs, false);if (err) goto recover_out;
@@ -2173,6 +2172,7 @@ int f2fs_resize_fs(struct f2fs_sb_info *sbi, __u64 block_count)f2fs_commit_super (sbi, false); } recover_out: +clear_sbi_flag (sbi,SBI_IS_RESIZEFS );if (err) {set_sbi_flag (sbi,SBI_NEED_FSCK );f2fs_err (sbi,"resize_fs failed, should run fsck to repair!" );
@@ -2185,6 +2185,5 @@ int f2fs_resize_fs(struct f2fs_sb_info *sbi, __u64 block_count)f2fs_up_write (&sbi->cp_global_sem);f2fs_up_write (&sbi->gc_lock);thaw_super (sbi->sb); -clear_sbi_flag (sbi,SBI_IS_RESIZEFS );return err; }
Signature · 8 lines
2.25.1 _______________________________________________ Linux-f2fs-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
Re: [f2fs-dev] [PATCH] f2fs: Fix the race condition of resize flag between resizefs
Quoted 13 lines · Zhang Qilong
Because the set/clear
SBI_IS_RESIZEFSflag not between any locks, In the following case:thread1 thread2 ->ioctl(resizefs) ->set RESIZEFS flag ->ioctl(resizefs) ... ->set RESIZEFS flag ->clear RESIZEFS flag ->resizefs stream # No RESIZEFS flag in the streamAlso before
freeze_super, the resizefs not started, we should not set theSBI_IS_RESIZEFSflag.
Quoted 6 lines
So move the set/clear
SBI_IS_RESIZEFSflag between thecp_mutexandgc_lock.Fixes b4b10061ef98 ("f2fs: refactor resize_fs to avoid meta updates in progress")Signed-off-by Zhang Xiaoxu <[email protected]>Signed-off-by Zhang Qilong <[email protected]>
Thanks,
_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
Chao Yu
maintainerQuoted 8 lines · Zhang Qilong
In the following case:
process 1 process 2
->open A
->mmap->read # the first time ->ioctl w/h F2FS_IOC_MOVE_RANGE # (range A->B) ->read # the second time
How about checking B as well? Previous mapped data can still be accessed after F2FS_IOC_MOVE_RANGE?
Thanks,
Quoted 30 lines
We will read old data at the second time. The root cause is that user still can see the previous source data after being moved. We fix it by adding truncating after
__exchange_data_block.Fixes 4dd6f977fc77 ("f2fs: support an ioctl to move a range of data blocks")Signed-off-by Zhang Qilong <[email protected]>---
v2:
- moving truncating to the range off2fs_lock_op()v3:
- modify the title and commit message--- fs/f2fs/file.c | 3 +++ 1 file changed, 3 insertions(+)fs/f2fs/file.c +1
-0@@ -2824,6 +2824,7 @@ static int f2fs_move_file_range(struct file *file_in, loff_t pos_in, goto out_src; } +filemap_invalidate_lock (src->i_mapping);f2fs_lock_op (sbi); ret = __exchange_data_block(src, dst, pos_in >> F2FS_BLKSIZE_BITS, pos_out >> F2FS_BLKSIZE_BITS,
fs/f2fs/file.c static int f2fs_move_file_range(struct file *file_in, loff_t pos_in, · line 2844
Quoted 9 lines
fs/f2fs/file.c +2
-0@@ -2835,7 +2836,9 @@ static int f2fs_move_file_range(struct file *file_in, loff_t pos_in,else if (dst_osize != dst->i_size)f2fs_i_size_write (dst, dst_osize); } +truncate_pagecache_range (src, pos_in, pos_in + len -1 );f2fs_unlock_op (sbi); +filemap_invalidate_unlock (src->i_mapping);if (src != dst)f2fs_up_write (&F2FS_I (dst)->i_gc_rwsem[WRITE ]);
_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
Quoted 10 lines · Zhang Qilong
Quoted 8 lines
In the following case:
process 1 process 2
->open A
->mmap->read # the first time ->ioctl w/h F2FS_IOC_MOVE_RANGE # (range A->B) ->read # the second time
Quoted 3 lines
How about checking B as well? Previous mapped data can still be accessed after
F2FS_IOC_MOVE_RANGE?
Hi
I have checked B as well. Previous mapped data can't be accessed after F2FS_IOC_MOVE_RANGE.
In addition, this patch could be applied to mainline if possible?
Thanks
Quoted 42 lines
Thanks,
fs/f2fs/file.c static int f2fs_move_file_range(struct file *file_in,
Quoted 23 lines
We will read old data at the second time. The root cause is that user still can see the previous source data after being moved. We fix it by adding truncating after
__exchange_data_block.Fixes 4dd6f977fc77 ("f2fs: support an ioctl to move a range of datablocks")
Signed-off-by Zhang Qilong <[email protected]>---
v2:
- moving truncating to the range off2fs_lock_op()v3:
- modify the title and commit message--- fs/f2fs/file.c | 3 +++ 1 file changed, 3 insertions(+)fs/f2fs/file.c index renamed from fs/f2fs/file.c +0
-0
82cda1258227..e9dfa41baf9e100644fs/f2fs/file.c +0
-0@@ -2824,6 +2824,7 @@ static int f2fs_move_file_range(struct file *file_in,
loff_tpos_in,fs/f2fs/file.c static int f2fs_move_file_range(struct file *file_in,
Quoted 8 lines
fs/f2fs/file.c +1
-0goto out_src; } +filemap_invalidate_lock (src->i_mapping);f2fs_lock_op (sbi); ret = __exchange_data_block(src, dst, pos_in >> F2FS_BLKSIZE_BITS, pos_out >> F2FS_BLKSIZE_BITS,@@ -2835,7 +2836,9 @@ static int f2fs_move_file_range(struct file *file_in,
loff_tpos_in,Quoted 7 lines
fs/f2fs/file.c +2
-0else if (dst_osize != dst->i_size)f2fs_i_size_write (dst, dst_osize); } +truncate_pagecache_range (src, pos_in, pos_in + len -1 );f2fs_unlock_op (sbi); +filemap_invalidate_unlock (src->i_mapping);
Quoted 2 lines
fs/f2fs/file.c static int f2fs_move_file_range(struct file *file_in, loff_t pos_in, · line 2844
Quoted 2 lines
fs/f2fs/file.c +0
-0if (src != dst)f2fs_up_write (&F2FS_I (dst)->i_gc_rwsem[WRITE ]);
_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
Chao Yu
maintainerQuoted 10 lines · On 2022/10/20 15:27, zhangqilong via Linux-f2fs-devel wrote:
Quoted 10 lines · Zhang Qilong
Quoted 8 lines
In the following case:
process 1 process 2
->open A->mmap ->read # the first time ->ioctl w/h F2FS_IOC_MOVE_RANGE # (range A->B) ->read # the second time
Quoted 8 lines
Quoted 3 lines
How about checking B as well? Previous mapped data can still be accessed after
F2FS_IOC_MOVE_RANGE?Hi
I have checked B as well. Previous mapped data can't be accessed after
F2FS_IOC_MOVE_RANGE.
I doubt that we didn't call flush_dcache_page() in below branch, so user may see stall data after F2FS_IOC_MOVE_RANGE? Am I missing something?
__clone_blkaddrs()
{
...
} else {
struct page *psrc, *pdst;
psrc = f2fs_get_lock_data_page(src_inode,
src + i, true);
if (IS_ERR(psrc))
return PTR_ERR(psrc);
pdst = f2fs_get_new_data_page(dst_inode, NULL, dst + i,
true);
if (IS_ERR(pdst)) {
f2fs_put_page(psrc, 1);
return PTR_ERR(pdst);
}
memcpy_page(pdst, 0, psrc, 0, PAGE_SIZE);
set_page_dirty(pdst);
f2fs_put_page(pdst, 1);
f2fs_put_page(psrc, 1);
ret = f2fs_truncate_hole(src_inode,
src + i, src + i + 1);
if (ret)
return ret;
i++;
}...
}
Thanks,
Quoted 47 lines
In addition, this patch could be applied to mainline if possible?
Thanks
Quoted 42 lines
Thanks,
fs/f2fs/file.c static int f2fs_move_file_range(struct file *file_in,
Quoted 23 lines
We will read old data at the second time. The root cause is that user still can see the previous source data after being moved. We fix it by adding truncating after
__exchange_data_block.Fixes 4dd6f977fc77 ("f2fs: support an ioctl to move a range of datablocks")
Signed-off-by Zhang Qilong <[email protected]>---
v2:
- moving truncating to the range off2fs_lock_op()v3:
- modify the title and commit message--- fs/f2fs/file.c | 3 +++ 1 file changed, 3 insertions(+)fs/f2fs/file.c index renamed from fs/f2fs/file.c +0
-0
82cda1258227..e9dfa41baf9e100644fs/f2fs/file.c +0
-0@@ -2824,6 +2824,7 @@ static int f2fs_move_file_range(struct file *file_in,
loff_tpos_in,fs/f2fs/file.c static int f2fs_move_file_range(struct file *file_in,
Quoted 8 lines
fs/f2fs/file.c +1
-0goto out_src; } +filemap_invalidate_lock (src->i_mapping);f2fs_lock_op (sbi); ret = __exchange_data_block(src, dst, pos_in >> F2FS_BLKSIZE_BITS, pos_out >> F2FS_BLKSIZE_BITS,@@ -2835,7 +2836,9 @@ static int f2fs_move_file_range(struct file *file_in,
loff_tpos_in,Quoted 7 lines
fs/f2fs/file.c +2
-0else if (dst_osize != dst->i_size)f2fs_i_size_write (dst, dst_osize); } +truncate_pagecache_range (src, pos_in, pos_in + len -1 );f2fs_unlock_op (sbi); +filemap_invalidate_unlock (src->i_mapping);
Quoted 7 lines
Quoted 2 lines
fs/f2fs/file.c static int f2fs_move_file_range(struct file *file_in, loff_t pos_in, · line 2844
Quoted 2 lines
fs/f2fs/file.c +0
-0if (src != dst)f2fs_up_write (&F2FS_I (dst)->i_gc_rwsem[WRITE ]);_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
Quoted 15 lines · On 2022/10/20 15:27, zhangqilong via Linux-f2fs-devel wrote:
Quoted 14 lines
Quoted 13 lines · Zhang Qilong
Quoted 8 lines
In the following case:
process 1 process 2
->open A->mmap ->read # the first time ->ioctl w/h F2FS_IOC_MOVE_RANGE # (range A->B) ->read # the second timeHow about checking B as well? Previous mapped data can still be accessed after
F2FS_IOC_MOVE_RANGE?
Quoted 8 lines
Quoted 4 lines
Hi
I have checked B as well. Previous mapped data can't be accessed after
F2FS_IOC_MOVE_RANGE.I doubt that we didn't call
flush_dcache_page()in below branch, so user may see stall data afterF2FS_IOC_MOVE_RANGE? Am I missing something?
Hi,
You are right, it needs flush_dcache_page, but it is unnecessary here, the __clone_blkaddrs() is called by FALLOC_FL_COLLAPSE_RANGE/ FALLOC_FL_INSERT_RANGE /F2FS_IOC_MOVE_RANGE. ->__exchange_data_block()
->__clone_blkaddrs()
f2fs_do_collapse() and f2fs_insert_range() have truncate_pagecache after __exchange_data_block() It seem we have analyzed before. So we only need to add a truncate operation for F2FS_IOC_MOVE_RANGE.
Quoted 65 lines
__clone_blkaddrs()
{
...} else { struct page *psrc, *pdst; psrc = f2fs_get_lock_data_page(src_inode, src + i, true); if (IS_ERR(psrc)) return PTR_ERR(psrc); pdst = f2fs_get_new_data_page(dst_inode, NULL, dst + i, true); if (IS_ERR(pdst)) { f2fs_put_page(psrc, 1); return PTR_ERR(pdst); } memcpy_page(pdst, 0, psrc, 0, PAGE_SIZE); set_page_dirty(pdst); f2fs_put_page(pdst, 1); f2fs_put_page(psrc, 1); ret = f2fs_truncate_hole(src_inode, src + i, src + i + 1); if (ret) return ret; i++; }...
}Thanks,
Quoted 32 lines
In addition, this patch could be applied to mainline if possible?
Thanks
Quoted 27 lines
Thanks,
Quoted 23 lines
We will read old data at the second time. The root cause is that user still can see the previous source data after being moved. We fix it by adding truncating after
__exchange_data_block.Fixes 4dd6f977fc77 ("f2fs: support an ioctl to move a range of datablocks")
Signed-off-by Zhang Qilong <[email protected]>---
v2:
- moving truncating to the range off2fs_lock_op()v3:
- modify the title and commit message--- fs/f2fs/file.c | 3 +++ 1 file changed, 3 insertions(+)fs/f2fs/file.c index renamed from fs/f2fs/file.c +0
-0
82cda1258227..e9dfa41baf9e100644fs/f2fs/file.c static int f2fs_move_file_range(struct file · line 2824
Quoted 1 line
fs/f2fs/file.c +0
-0@@ -2824,6 +2824,7 @@ static int f2fs_move_file_range(struct file *file_in,
loff_tpos_in,
Quoted 24 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
fs/f2fs/file.c +1
-0goto out_src; } +filemap_invalidate_lock (src->i_mapping);f2fs_lock_op (sbi); ret = __exchange_data_block(src, dst, pos_in >> F2FS_BLKSIZE_BITS,pos_out >> F2FS_BLKSIZE_BITS, @@ -2835,7+2836,9 @@ static
Quoted 16 lines
Quoted 11 lines
Quoted 1 line
int f2fs_move_file_range(struct file
*file_in,
loff_tpos_in,fs/f2fs/file.c static int f2fs_move_file_range(struct file *file_in, loff_t pos_in, · line 2844
Quoted 9 lines
else if (dst_osize != dst->i_size) f2fs_i_size_write(dst, dst_osize); }fs/f2fs/file.c +2
-0+truncate_pagecache_range (src, pos_in, pos_in + len -1 );f2fs_unlock_op (sbi); +filemap_invalidate_unlock (src->i_mapping);if (src != dst)f2fs_up_write (&F2FS_I (dst)->i_gc_rwsem[WRITE ]);_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
Chao Yu
maintainerQuoted 26 lines · zhangqilong
Quoted 15 lines · On 2022/10/20 15:27, zhangqilong via Linux-f2fs-devel wrote:
Quoted 14 lines
Quoted 13 lines · Zhang Qilong
Quoted 8 lines
In the following case:
process 1 process 2->open A ->mmap ->read # the first time ->ioctl w/h F2FS_IOC_MOVE_RANGE # (range A->B) ->read # the second timeHow about checking B as well? Previous mapped data can still be accessed after
F2FS_IOC_MOVE_RANGE?Quoted 8 lines
Quoted 4 lines
Hi
I have checked B as well. Previous mapped data can't be accessed after
F2FS_IOC_MOVE_RANGE.I doubt that we didn't call
flush_dcache_page()in below branch, so user may see stall data afterF2FS_IOC_MOVE_RANGE? Am I missing something?Hi,
Quoted 7 lines
You are right, it needs
flush_dcache_page, but it is unnecessary here, the__clone_blkaddrs()is called by FALLOC_FL_COLLAPSE_RANGE/FALLOC_FL_INSERT_RANGE/F2FS_IOC_MOVE_RANGE. ->__exchange_data_block()
->__clone_blkaddrs()
f2fs_do_collapse()andf2fs_insert_range()havetruncate_pagecacheafter__exchange_data_block()It seem we have analyzed before. So we only need to add a truncate operation forF2FS_IOC_MOVE_RANGE.
I mean it needs to call truncate_pagecache_range(dst, ...) in f2fs_move_file_range() as well, right?
Thanks,
Quoted 83 lines
Quoted 83 lines
__clone_blkaddrs()
{
...} else { struct page *psrc, *pdst; psrc = f2fs_get_lock_data_page(src_inode, src + i, true); if (IS_ERR(psrc)) return PTR_ERR(psrc); pdst = f2fs_get_new_data_page(dst_inode, NULL, dst + i, true); if (IS_ERR(pdst)) { f2fs_put_page(psrc, 1); return PTR_ERR(pdst); } memcpy_page(pdst, 0, psrc, 0, PAGE_SIZE); set_page_dirty(pdst); f2fs_put_page(pdst, 1); f2fs_put_page(psrc, 1); ret = f2fs_truncate_hole(src_inode, src + i, src + i + 1); if (ret) return ret; i++; }...
}Thanks,
Quoted 32 lines
In addition, this patch could be applied to mainline if possible?
Thanks
Quoted 27 lines
Thanks,
Quoted 23 lines
We will read old data at the second time. The root cause is that user still can see the previous source data after being moved. We fix it by adding truncating after
__exchange_data_block.Fixes 4dd6f977fc77 ("f2fs: support an ioctl to move a range of datablocks")
Signed-off-by Zhang Qilong <[email protected]>---
v2:
- moving truncating to the range off2fs_lock_op()v3:
- modify the title and commit message--- fs/f2fs/file.c | 3 +++ 1 file changed, 3 insertions(+)fs/f2fs/file.c index renamed from fs/f2fs/file.c +0
-0
82cda1258227..e9dfa41baf9e100644fs/f2fs/file.c static int f2fs_move_file_range(struct file · line 2824
Quoted 1 line
fs/f2fs/file.c +0
-0@@ -2824,6 +2824,7 @@ static int f2fs_move_file_range(struct file *file_in,
loff_tpos_in,Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
fs/f2fs/file.c +1
-0goto out_src; } +filemap_invalidate_lock (src->i_mapping);f2fs_lock_op (sbi); ret = __exchange_data_block(src, dst, pos_in >> F2FS_BLKSIZE_BITS,pos_out >> F2FS_BLKSIZE_BITS, @@ -2835,7+2836,9 @@ static
Quoted 9 lines
Quoted 9 lines
Quoted 1 line
int f2fs_move_file_range(struct file
*file_in,
loff_tpos_in,Quoted 7 lines
else if (dst_osize != dst->i_size) f2fs_i_size_write(dst, dst_osize); }fs/f2fs/file.c +2
-0+truncate_pagecache_range (src, pos_in, pos_in + len -1 );f2fs_unlock_op (sbi); +filemap_invalidate_unlock (src->i_mapping);
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 2 lines
Quoted 2 lines
if (src != dst) f2fs_up_write(&F2FS_I(dst)->i_gc_rwsem[WRITE]);_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
Quoted 34 lines · zhangqilong
Quoted 15 lines
Quoted 15 lines · On 2022/10/20 15:27, zhangqilong via Linux-f2fs-devel wrote:
Quoted 14 lines
Quoted 13 lines · Zhang Qilong
Quoted 8 lines
In the following case:
process 1 process 2->open A ->mmap ->read # the first time ->ioctl w/h F2FS_IOC_MOVE_RANGE # (range A->B) ->read # the second timeHow about checking B as well? Previous mapped data can still be accessed after
F2FS_IOC_MOVE_RANGE?Quoted 7 lines
Quoted 7 lines
Quoted 4 lines
Hi
I have checked B as well. Previous mapped data can't be accessed after
F2FS_IOC_MOVE_RANGE.I doubt that we didn't call
flush_dcache_page()in below branch, so user may see stall data afterF2FS_IOC_MOVE_RANGE? Am I missingsomething?
Quoted 6 lines
Quoted 1 line
Hi,
You are right, it needs
flush_dcache_page, but it is unnecessary here, the__clone_blkaddrs()is called by FALLOC_FL_COLLAPSE_RANGE/
FALLOC_FL_INSERT_RANGE/F2FS_IOC_MOVE_RANGE.Quoted 3 lines
->__exchange_data_block()
->__clone_blkaddrs()
Quoted 6 lines
Quoted 2 lines
f2fs_do_collapse()andf2fs_insert_range()havetruncate_pagecacheafter__exchange_data_block()It seem we have analyzed before. So weonly need to add a truncate operation for
F2FS_IOC_MOVE_RANGE.I mean it needs to call
truncate_pagecache_range(dst, ...)inf2fs_move_file_range()as well, right?
Yes, I think it should call truncate_pagecache_range(dst, ...) or flush_dcache_page() here. I submitted a patch before, it seems to be forgetten.
https://lore.kernel.org/linux-f2fs-devel/[email protected]/
But, I test it w/o truncate_pagecache_range(dst, ...) or flush_dcache_page(), user can not see stall dst data, maybe It is a bit difficult to construct the scene for me.
Thanks,
Quoted 73 lines
Thanks,
Quoted 7 lines
Quoted 7 lines
__clone_blkaddrs()
{
...} else { struct page *psrc, *pdst;Quoted 5 lines
Quoted 5 lines
psrc = f2fs_get_lock_data_page(src_inode, src + i, true); if (IS_ERR(psrc)) return PTR_ERR(psrc); pdst = f2fs_get_new_data_page(dst_inode, NULL,dst + i,
Quoted 57 lines
Quoted 57 lines
true); if (IS_ERR(pdst)) { f2fs_put_page(psrc, 1); return PTR_ERR(pdst); } memcpy_page(pdst, 0, psrc, 0, PAGE_SIZE); set_page_dirty(pdst); f2fs_put_page(pdst, 1); f2fs_put_page(psrc, 1); ret = f2fs_truncate_hole(src_inode, src + i, src + i + 1); if (ret) return ret; i++; }...
}Thanks,
Quoted 36 lines
In addition, this patch could be applied to mainline if possible?
Thanks
Quoted 31 lines
Thanks,
Quoted 24 lines
We will read old data at the second time. The root cause is that user still can see the previous source data after being moved. We fix it by adding truncating after
__exchange_data_block.Fixes 4dd6f977fc77 ("f2fs: support an ioctl to move a range ofdata
blocks")Signed-off-by Zhang Qilong <[email protected]>---
v2:
- moving truncating to the range off2fs_lock_op()v3:
- modify the title and commit message--- fs/f2fs/file.c | 3 +++ 1 file changed, 3 insertions(+)fs/f2fs/file.c index renamed from fs/f2fs/file.c +0
-0
82cda1258227..e9dfa41baf9e100644fs/f2fs/file.c static int f2fs_move_file_range(struct file · line 2824
Quoted 1 line
fs/f2fs/file.c +0
-0@@ -2824,6 +2824,7 @@ static int f2fs_move_file_range(struct file *file_in,
loff_tpos_in,Quoted 3 lines
fs/f2fs/file.c +0
-0goto out_src; }
Quoted 23 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
fs/f2fs/file.c static int f2fs_move_file_range(struct file *file_in, loff_t pos_in,
Quoted 3 lines
fs/f2fs/file.c +1
-0+filemap_invalidate_lock (src->i_mapping);f2fs_lock_op (sbi); ret = __exchange_data_block(src, dst, pos_in >>
F2FS_BLKSIZE_BITS,Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
pos_out >> F2FS_BLKSIZE_BITS, @@-2835,7
Quoted 17 lines
Quoted 17 lines
+2836,9 @@ static
Quoted 16 lines
Quoted 11 lines
Quoted 1 line
int f2fs_move_file_range(struct file
*file_in,
loff_tpos_in,fs/f2fs/file.c static int f2fs_move_file_range(struct file *file_in, loff_t pos_in, · line 2844
Quoted 9 lines
else if (dst_osize != dst->i_size) f2fs_i_size_write(dst, dst_osize); }fs/f2fs/file.c +2
-0+truncate_pagecache_range (src, pos_in, pos_in + len -1 );f2fs_unlock_op (sbi); +filemap_invalidate_unlock (src->i_mapping);if (src != dst)f2fs_up_write (&F2FS_I (dst)->i_gc_rwsem[WRITE ]);_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
Chao Yu
maintainerQuoted 41 lines · zhangqilong
Quoted 34 lines · zhangqilong
Quoted 15 lines
Quoted 15 lines · On 2022/10/20 15:27, zhangqilong via Linux-f2fs-devel wrote:
Quoted 14 lines
Quoted 13 lines · Zhang Qilong
Quoted 8 lines
In the following case:
process 1 process 2->open A ->mmap ->read # the first time ->ioctl w/h F2FS_IOC_MOVE_RANGE # (range A->B) ->read # the second timeHow about checking B as well? Previous mapped data can still be accessed after
F2FS_IOC_MOVE_RANGE?Quoted 7 lines
Quoted 7 lines
Quoted 4 lines
Hi
I have checked B as well. Previous mapped data can't be accessed after
F2FS_IOC_MOVE_RANGE.I doubt that we didn't call
flush_dcache_page()in below branch, so user may see stall data afterF2FS_IOC_MOVE_RANGE? Am I missingsomething?
Quoted 6 lines
Quoted 1 line
Hi,
You are right, it needs
flush_dcache_page, but it is unnecessary here, the__clone_blkaddrs()is called by FALLOC_FL_COLLAPSE_RANGE/
FALLOC_FL_INSERT_RANGE/F2FS_IOC_MOVE_RANGE.Quoted 3 lines
->__exchange_data_block()
->__clone_blkaddrs()Quoted 6 lines
Quoted 2 lines
f2fs_do_collapse()andf2fs_insert_range()havetruncate_pagecacheafter__exchange_data_block()It seem we have analyzed before. So weonly need to add a truncate operation for
F2FS_IOC_MOVE_RANGE.I mean it needs to call
truncate_pagecache_range(dst, ...)inf2fs_move_file_range()as well, right?
Quoted 7 lines
Yes, I think it should call
truncate_pagecache_range(dst, ...)orflush_dcache_page()here. I submitted a patch before, it seems to be forgetten.https://lore.kernel.org/linux-f2fs-devel/[email protected]/
But, I test it w/o
truncate_pagecache_range(dst, ...)orflush_dcache_page(), user can not see stall dst data, maybe It is a bit difficult to construct the scene for me.
Please check the condition how can we run into below else branch. I guess you need to persist data blocks of src into a checkpoint w/ SYNC(2), then __clone_blkaddrs() will copy data from page cache directly instead of exchanging metadatas.
Thanks,
Quoted 98 lines
Thanks,
Quoted 96 lines
Thanks,
Quoted 7 lines
Quoted 7 lines
__clone_blkaddrs()
{
...} else { struct page *psrc, *pdst;Quoted 5 lines
Quoted 5 lines
psrc = f2fs_get_lock_data_page(src_inode, src + i, true); if (IS_ERR(psrc)) return PTR_ERR(psrc); pdst = f2fs_get_new_data_page(dst_inode, NULL,dst + i,
Quoted 54 lines
Quoted 54 lines
true); if (IS_ERR(pdst)) { f2fs_put_page(psrc, 1); return PTR_ERR(pdst); } memcpy_page(pdst, 0, psrc, 0, PAGE_SIZE); set_page_dirty(pdst); f2fs_put_page(pdst, 1); f2fs_put_page(psrc, 1); ret = f2fs_truncate_hole(src_inode, src + i, src + i + 1); if (ret) return ret; i++; }...
}Thanks,
Quoted 33 lines
In addition, this patch could be applied to mainline if possible?
Thanks
Quoted 28 lines
Thanks,
Quoted 24 lines
We will read old data at the second time. The root cause is that user still can see the previous source data after being moved. We fix it by adding truncating after
__exchange_data_block.Fixes 4dd6f977fc77 ("f2fs: support an ioctl to move a range ofdata
blocks")Signed-off-by Zhang Qilong <[email protected]>---
v2:
- moving truncating to the range off2fs_lock_op()v3:
- modify the title and commit message--- fs/f2fs/file.c | 3 +++ 1 file changed, 3 insertions(+)fs/f2fs/file.c index renamed from fs/f2fs/file.c +0
-0
82cda1258227..e9dfa41baf9e100644fs/f2fs/file.c static int f2fs_move_file_range(struct file · line 2824
Quoted 1 line
fs/f2fs/file.c +0
-0@@ -2824,6 +2824,7 @@ static int f2fs_move_file_range(struct file *file_in,
loff_tpos_in,Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
fs/f2fs/file.c static int f2fs_move_file_range(struct file · line 2830
Quoted 6 lines
fs/f2fs/file.c +1
-0goto out_src; } +filemap_invalidate_lock (src->i_mapping);f2fs_lock_op (sbi); ret = __exchange_data_block(src, dst, pos_in >>
F2FS_BLKSIZE_BITS,Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
pos_out >> F2FS_BLKSIZE_BITS, @@-2835,7
Quoted 17 lines
Quoted 17 lines
+2836,9 @@ static
Quoted 16 lines
Quoted 11 lines
Quoted 1 line
int f2fs_move_file_range(struct file
*file_in,
loff_tpos_in,fs/f2fs/file.c
Quoted 9 lines
else if (dst_osize != dst->i_size) f2fs_i_size_write(dst, dst_osize); }fs/f2fs/file.c +2
-0+truncate_pagecache_range (src, pos_in, pos_in + len -1 );f2fs_unlock_op (sbi); +filemap_invalidate_unlock (src->i_mapping);if (src != dst)f2fs_up_write (&F2FS_I (dst)->i_gc_rwsem[WRITE ]);_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
Quoted 50 lines · zhangqilong
Quoted 23 lines
Quoted 23 lines · zhangqilong
Quoted 22 lines
Quoted 22 lines · On 2022/10/20 15:27, zhangqilong via Linux-f2fs-devel wrote:
Quoted 10 lines
Quoted 10 lines · Zhang Qilong
Quoted 8 lines
In the following case:
process 1 process 2->open A ->mmap ->read # the first time ->ioctl w/h F2FS_IOC_MOVE_RANGE # (range A->B) ->read # the second timeQuoted 8 lines
Quoted 3 lines
How about checking B as well? Previous mapped data can still be accessed after
F2FS_IOC_MOVE_RANGE?Hi
I have checked B as well. Previous mapped data can't be accessed after
F2FS_IOC_MOVE_RANGE.I doubt that we didn't call
flush_dcache_page()in below branch, so user may see stall data afterF2FS_IOC_MOVE_RANGE? Am I missingQuoted 7 lines
Quoted 7 lines
something?
Quoted 6 lines
Quoted 1 line
Hi,
You are right, it needs
flush_dcache_page, but it is unnecessary here, the__clone_blkaddrs()is called byFALLOC_FL_COLLAPSE_RANGE/
Quoted 4 lines
Quoted 4 lines
FALLOC_FL_INSERT_RANGE/F2FS_IOC_MOVE_RANGE.Quoted 3 lines
->__exchange_data_block()
->__clone_blkaddrs()Quoted 8 lines
Quoted 6 lines
Quoted 2 lines
f2fs_do_collapse()andf2fs_insert_range()havetruncate_pagecacheafter__exchange_data_block()It seem we have analyzed before. So weonly need to add a truncate operation for
F2FS_IOC_MOVE_RANGE.I mean it needs to call
truncate_pagecache_range(dst, ...)inf2fs_move_file_range()as well, right?Yes, I think it should call
truncate_pagecache_range(dst, ...)or
flush_dcache_page()here.Quoted 5 lines
I submitted a patch before, it seems to be forgetten.
https://lore.kernel.org/linux-f2fs-devel/20220825024102.120651-1-zhang
[email protected]/
Quoted 9 lines
Quoted 2 lines
But, I test it w/o
truncate_pagecache_range(dst, ...)orflush_dcache_page(), user can not see stall dst data, maybe It is a bitdifficult to construct the scene for me.
Please check the condition how can we run into below else branch. I guess you need to persist data blocks of src into a checkpoint w/ SYNC(2), then
__clone_blkaddrs()will copy data from page cache directly instead of exchanging metadatas.
Thanks for your suggestion, I try it later for this point. If I have any progress, I will notify you immediately.
Do you have any suggestion for this patch? :)
f2fs: Fix data consistency in f2fs_move_file_range()
Thanks,
Quoted 101 lines
Thanks,
Quoted 98 lines
Thanks,
Quoted 96 lines
Thanks,
Quoted 7 lines
Quoted 7 lines
__clone_blkaddrs()
{
...} else { struct page *psrc, *pdst;Quoted 5 lines
Quoted 5 lines
psrc = f2fs_get_lock_data_page(src_inode, src + i, true); if (IS_ERR(psrc)) return PTR_ERR(psrc); pdst = f2fs_get_new_data_page(dst_inode, NULL,dst + i,
Quoted 54 lines
Quoted 54 lines
true); if (IS_ERR(pdst)) { f2fs_put_page(psrc, 1); return PTR_ERR(pdst); } memcpy_page(pdst, 0, psrc, 0, PAGE_SIZE); set_page_dirty(pdst); f2fs_put_page(pdst, 1); f2fs_put_page(psrc, 1); ret = f2fs_truncate_hole(src_inode, src + i, src + i + 1); if (ret) return ret; i++; }...
}Thanks,
Quoted 33 lines
In addition, this patch could be applied to mainline if possible?
Thanks
Quoted 28 lines
Thanks,
Quoted 24 lines
We will read old data at the second time. The root cause is that user still can see the previous source data after being moved. We fix it by adding truncating after
__exchange_data_block.Fixes 4dd6f977fc77 ("f2fs: support an ioctl to move a range ofdata
blocks")Signed-off-by Zhang Qilong <[email protected]>---
v2:
- moving truncating to the range off2fs_lock_op()v3:
- modify the title and commit message--- fs/f2fs/file.c | 3 +++ 1 file changed, 3 insertions(+)fs/f2fs/file.c index renamed from fs/f2fs/file.c +0
-0
82cda1258227..e9dfa41baf9e100644fs/f2fs/file.c static int f2fs_move_file_range(struct · line 2824
Quoted 1 line
fs/f2fs/file.c +0
-0@@ -2824,6 +2824,7 @@ static int f2fs_move_file_range(struct file *file_in,
loff_tpos_in,Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
fs/f2fs/file.c static int f2fs_move_file_range(struct · line 2830
Quoted 6 lines
fs/f2fs/file.c +1
-0goto out_src; } +filemap_invalidate_lock (src->i_mapping);f2fs_lock_op (sbi); ret = __exchange_data_block(src, dst, pos_in >>
F2FS_BLKSIZE_BITS,Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
pos_out >> F2FS_BLKSIZE_BITS, @@-2835,7
Quoted 17 lines
Quoted 17 lines
+2836,9 @@ static
Quoted 16 lines
Quoted 11 lines
Quoted 1 line
int f2fs_move_file_range(struct file
*file_in,
loff_tpos_in,fs/f2fs/file.c
Quoted 9 lines
else if (dst_osize != dst->i_size) f2fs_i_size_write(dst, dst_osize); }fs/f2fs/file.c +2
-0+truncate_pagecache_range (src, pos_in, pos_in + len -1 );f2fs_unlock_op (sbi); +filemap_invalidate_unlock (src->i_mapping);if (src != dst)f2fs_up_write (&F2FS_I (dst)->i_gc_rwsem[WRITE ]);_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
Chao Yu
maintainerQuoted 60 lines · zhangqilong
Quoted 50 lines · zhangqilong
Quoted 23 lines
Quoted 23 lines · zhangqilong
Quoted 22 lines
Quoted 22 lines · On 2022/10/20 15:27, zhangqilong via Linux-f2fs-devel wrote:
Quoted 10 lines
Quoted 10 lines · Zhang Qilong
Quoted 8 lines
In the following case:
process 1 process 2->open A ->mmap ->read # the first time ->ioctl w/h F2FS_IOC_MOVE_RANGE # (range A->B) ->read # the second timeQuoted 8 lines
Quoted 3 lines
How about checking B as well? Previous mapped data can still be accessed after
F2FS_IOC_MOVE_RANGE?Hi
I have checked B as well. Previous mapped data can't be accessed after
F2FS_IOC_MOVE_RANGE.I doubt that we didn't call
flush_dcache_page()in below branch, so user may see stall data afterF2FS_IOC_MOVE_RANGE? Am I missingQuoted 7 lines
Quoted 7 lines
something?
Quoted 6 lines
Quoted 1 line
Hi,
You are right, it needs
flush_dcache_page, but it is unnecessary here, the__clone_blkaddrs()is called byFALLOC_FL_COLLAPSE_RANGE/
Quoted 4 lines
Quoted 4 lines
FALLOC_FL_INSERT_RANGE/F2FS_IOC_MOVE_RANGE.Quoted 3 lines
->__exchange_data_block()
->__clone_blkaddrs()Quoted 8 lines
Quoted 6 lines
Quoted 2 lines
f2fs_do_collapse()andf2fs_insert_range()havetruncate_pagecacheafter__exchange_data_block()It seem we have analyzed before. So weonly need to add a truncate operation for
F2FS_IOC_MOVE_RANGE.I mean it needs to call
truncate_pagecache_range(dst, ...)inf2fs_move_file_range()as well, right?Yes, I think it should call
truncate_pagecache_range(dst, ...)or
flush_dcache_page()here.Quoted 5 lines
I submitted a patch before, it seems to be forgetten.
https://lore.kernel.org/linux-f2fs-devel/20220825024102.120651-1-zhang
[email protected]/Quoted 9 lines
Quoted 2 lines
But, I test it w/o
truncate_pagecache_range(dst, ...)orflush_dcache_page(), user can not see stall dst data, maybe It is a bitdifficult to construct the scene for me.
Please check the condition how can we run into below else branch. I guess you need to persist data blocks of src into a checkpoint w/ SYNC(2), then
__clone_blkaddrs()will copy data from page cache directly instead of exchanging metadatas.
Quoted 5 lines
Thanks for your suggestion, I try it later for this point. If I have any progress, I will notify you immediately.
Do you have any suggestion for this patch? :)
f2fs: Fix data consistency inf2fs_move_file_range()
No objection from my side... :)
I think it needs to test/verify the case I mentioned before merging this patch.
Thanks,
Quoted 104 lines
Thanks,
Quoted 101 lines
Thanks,
Quoted 98 lines
Thanks,
Quoted 96 lines
Thanks,
Quoted 7 lines
Quoted 7 lines
__clone_blkaddrs()
{
...} else { struct page *psrc, *pdst;Quoted 5 lines
Quoted 5 lines
psrc = f2fs_get_lock_data_page(src_inode, src + i, true); if (IS_ERR(psrc)) return PTR_ERR(psrc); pdst = f2fs_get_new_data_page(dst_inode, NULL,dst + i,
Quoted 54 lines
Quoted 54 lines
true); if (IS_ERR(pdst)) { f2fs_put_page(psrc, 1); return PTR_ERR(pdst); } memcpy_page(pdst, 0, psrc, 0, PAGE_SIZE); set_page_dirty(pdst); f2fs_put_page(pdst, 1); f2fs_put_page(psrc, 1); ret = f2fs_truncate_hole(src_inode, src + i, src + i + 1); if (ret) return ret; i++; }...
}Thanks,
Quoted 33 lines
In addition, this patch could be applied to mainline if possible?
Thanks
Quoted 28 lines
Thanks,
Quoted 24 lines
We will read old data at the second time. The root cause is that user still can see the previous source data after being moved. We fix it by adding truncating after
__exchange_data_block.Fixes 4dd6f977fc77 ("f2fs: support an ioctl to move a range ofdata
blocks")Signed-off-by Zhang Qilong <[email protected]>---
v2:
- moving truncating to the range off2fs_lock_op()v3:
- modify the title and commit message--- fs/f2fs/file.c | 3 +++ 1 file changed, 3 insertions(+)fs/f2fs/file.c index renamed from fs/f2fs/file.c +0
-0
82cda1258227..e9dfa41baf9e100644fs/f2fs/file.c static int f2fs_move_file_range(struct · line 2824
Quoted 1 line
fs/f2fs/file.c +0
-0@@ -2824,6 +2824,7 @@ static int f2fs_move_file_range(struct file *file_in,
loff_tpos_in,Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
fs/f2fs/file.c static int f2fs_move_file_range(struct · line 2830
Quoted 6 lines
fs/f2fs/file.c +1
-0goto out_src; } +filemap_invalidate_lock (src->i_mapping);f2fs_lock_op (sbi); ret = __exchange_data_block(src, dst, pos_in >>
F2FS_BLKSIZE_BITS,Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
pos_out >> F2FS_BLKSIZE_BITS, @@-2835,7
Quoted 17 lines
Quoted 17 lines
+2836,9 @@ static
Quoted 16 lines
Quoted 11 lines
Quoted 1 line
int f2fs_move_file_range(struct file
*file_in,
loff_tpos_in,fs/f2fs/file.c
Quoted 9 lines
else if (dst_osize != dst->i_size) f2fs_i_size_write(dst, dst_osize); }fs/f2fs/file.c +2
-0+truncate_pagecache_range (src, pos_in, pos_in + len -1 );f2fs_unlock_op (sbi); +filemap_invalidate_unlock (src->i_mapping);if (src != dst)f2fs_up_write (&F2FS_I (dst)->i_gc_rwsem[WRITE ]);_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel