* [PATCH] f2fs: avoid GC causing encrypted file corrupted
@ 2018-09-18 12:39 Yunlong Song
2018-09-18 13:21 ` Chao Yu
` (2 more replies)
0 siblings, 3 replies; 8+ messages in thread
From: Yunlong Song @ 2018-09-18 12:39 UTC (permalink / raw)
To: jaegeuk, chao, yuchao0, yunlong.song, yunlong.song
Cc: miaoxie, bintian.wang, shengyong1, heyunlei, linux-f2fs-devel,
linux-kernel
The encrypted file may be corrupted by GC in following case:
Time 1: | segment 1 blkaddr = A | GC -> | segment 2 blkaddr = B |
Encrypted block 1 is moved from blkaddr A of segment 1 to blkaddr B of
segment 2,
Time 2: | segment 1 blkaddr = B | GC -> | segment 3 blkaddr = C |
Before page 1 is written back and if segment 2 become a victim, then
page 1 is moved from blkaddr B of segment 2 to blkaddr Cof segment 3,
during the GC process of Time 2, f2fs should wait for page 1 written back
before reading it, or move_data_block will read a garbage block from
blkaddr B since page is not written back to blkaddr B yet.
Commit 6aa58d8a ("f2fs: readahead encrypted block during GC") introduce
ra_data_block to read encrypted block, but it forgets to add
f2fs_wait_on_page_writeback to avoid racing between GC and flush.
Signed-off-by: Yunlong Song <yunlong.song@huawei.com>
---
fs/f2fs/gc.c | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git a/fs/f2fs/gc.c b/fs/f2fs/gc.c
index a4c1a41..c55fb62 100644
--- a/fs/f2fs/gc.c
+++ b/fs/f2fs/gc.c
@@ -641,6 +641,14 @@ static int ra_data_block(struct inode *inode, pgoff_t index)
fio.page = page;
fio.new_blkaddr = fio.old_blkaddr = dn.data_blkaddr;
+ /*
+ * don't cache encrypted data into meta inode until previous dirty
+ * data were writebacked to avoid racing between GC and flush.
+ */
+ f2fs_wait_on_page_writeback(page, DATA, true);
+
+ f2fs_wait_on_block_writeback(inode, dn.data_blkaddr);
+
fio.encrypted_page = f2fs_pagecache_get_page(META_MAPPING(sbi),
dn.data_blkaddr,
FGP_LOCK | FGP_CREAT, GFP_NOFS);
@@ -723,6 +731,8 @@ static void move_data_block(struct inode *inode, block_t bidx,
*/
f2fs_wait_on_page_writeback(page, DATA, true);
+ f2fs_wait_on_block_writeback(inode, dn.data_blkaddr);
+
err = f2fs_get_node_info(fio.sbi, dn.nid, &ni);
if (err)
goto put_out;
--
1.8.5.2
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH] f2fs: avoid GC causing encrypted file corrupted
2018-09-18 12:39 [PATCH] f2fs: avoid GC causing encrypted file corrupted Yunlong Song
@ 2018-09-18 13:21 ` Chao Yu
2018-11-13 3:16 ` Chao Yu
2018-09-18 18:17 ` Jaegeuk Kim
2018-10-24 8:07 ` Yunlong Song
2 siblings, 1 reply; 8+ messages in thread
From: Chao Yu @ 2018-09-18 13:21 UTC (permalink / raw)
To: Yunlong Song, jaegeuk, yuchao0, yunlong.song
Cc: miaoxie, bintian.wang, shengyong1, heyunlei, linux-f2fs-devel,
linux-kernel
On 2018/9/18 20:39, Yunlong Song wrote:
> The encrypted file may be corrupted by GC in following case:
>
> Time 1: | segment 1 blkaddr = A | GC -> | segment 2 blkaddr = B |
> Encrypted block 1 is moved from blkaddr A of segment 1 to blkaddr B of
> segment 2,
>
> Time 2: | segment 1 blkaddr = B | GC -> | segment 3 blkaddr = C |
>
> Before page 1 is written back and if segment 2 become a victim, then
> page 1 is moved from blkaddr B of segment 2 to blkaddr Cof segment 3,
> during the GC process of Time 2, f2fs should wait for page 1 written back
> before reading it, or move_data_block will read a garbage block from
> blkaddr B since page is not written back to blkaddr B yet.
>
> Commit 6aa58d8a ("f2fs: readahead encrypted block during GC") introduce
> ra_data_block to read encrypted block, but it forgets to add
> f2fs_wait_on_page_writeback to avoid racing between GC and flush.
>
> Signed-off-by: Yunlong Song <yunlong.song@huawei.com>
Reviewed-by: Chao Yu <yuchao0@huawei.com>
Thanks,
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] f2fs: avoid GC causing encrypted file corrupted
2018-09-18 12:39 [PATCH] f2fs: avoid GC causing encrypted file corrupted Yunlong Song
2018-09-18 13:21 ` Chao Yu
@ 2018-09-18 18:17 ` Jaegeuk Kim
2018-09-19 2:37 ` Yunlong Song
2018-09-21 14:20 ` Chao Yu
2018-10-24 8:07 ` Yunlong Song
2 siblings, 2 replies; 8+ messages in thread
From: Jaegeuk Kim @ 2018-09-18 18:17 UTC (permalink / raw)
To: Yunlong Song
Cc: chao, yuchao0, yunlong.song, miaoxie, bintian.wang, shengyong1,
heyunlei, linux-f2fs-devel, linux-kernel
On 09/18, Yunlong Song wrote:
> The encrypted file may be corrupted by GC in following case:
>
> Time 1: | segment 1 blkaddr = A | GC -> | segment 2 blkaddr = B |
> Encrypted block 1 is moved from blkaddr A of segment 1 to blkaddr B of
> segment 2,
>
> Time 2: | segment 1 blkaddr = B | GC -> | segment 3 blkaddr = C |
segment 2 blkaddr = B?
>
> Before page 1 is written back and if segment 2 become a victim, then
> page 1 is moved from blkaddr B of segment 2 to blkaddr Cof segment 3,
C of ?
> during the GC process of Time 2, f2fs should wait for page 1 written back
> before reading it, or move_data_block will read a garbage block from
> blkaddr B since page is not written back to blkaddr B yet.
move_data_block() checks PageUptodate() so it won't get garbage, yes?
So, does ra_data_block need to check PageUptodate?
>
> Commit 6aa58d8a ("f2fs: readahead encrypted block during GC") introduce
> ra_data_block to read encrypted block, but it forgets to add
> f2fs_wait_on_page_writeback to avoid racing between GC and flush.
>
> Signed-off-by: Yunlong Song <yunlong.song@huawei.com>
> ---
> fs/f2fs/gc.c | 10 ++++++++++
> 1 file changed, 10 insertions(+)
>
> diff --git a/fs/f2fs/gc.c b/fs/f2fs/gc.c
> index a4c1a41..c55fb62 100644
> --- a/fs/f2fs/gc.c
> +++ b/fs/f2fs/gc.c
> @@ -641,6 +641,14 @@ static int ra_data_block(struct inode *inode, pgoff_t index)
> fio.page = page;
> fio.new_blkaddr = fio.old_blkaddr = dn.data_blkaddr;
>
> + /*
> + * don't cache encrypted data into meta inode until previous dirty
> + * data were writebacked to avoid racing between GC and flush.
> + */
> + f2fs_wait_on_page_writeback(page, DATA, true);
> +
> + f2fs_wait_on_block_writeback(inode, dn.data_blkaddr);
> +
> fio.encrypted_page = f2fs_pagecache_get_page(META_MAPPING(sbi),
> dn.data_blkaddr,
> FGP_LOCK | FGP_CREAT, GFP_NOFS);
> @@ -723,6 +731,8 @@ static void move_data_block(struct inode *inode, block_t bidx,
> */
> f2fs_wait_on_page_writeback(page, DATA, true);
>
> + f2fs_wait_on_block_writeback(inode, dn.data_blkaddr);
> +
> err = f2fs_get_node_info(fio.sbi, dn.nid, &ni);
> if (err)
> goto put_out;
> --
> 1.8.5.2
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] f2fs: avoid GC causing encrypted file corrupted
2018-09-18 18:17 ` Jaegeuk Kim
@ 2018-09-19 2:37 ` Yunlong Song
2018-09-21 14:20 ` Chao Yu
1 sibling, 0 replies; 8+ messages in thread
From: Yunlong Song @ 2018-09-19 2:37 UTC (permalink / raw)
To: Jaegeuk Kim
Cc: chao, yuchao0, yunlong.song, miaoxie, bintian.wang, shengyong1,
heyunlei, linux-f2fs-devel, linux-kernel
On 2018/9/19 2:17, Jaegeuk Kim wrote:
> On 09/18, Yunlong Song wrote:
>> The encrypted file may be corrupted by GC in following case:
>>
>> Time 1: | segment 1 blkaddr = A | GC -> | segment 2 blkaddr = B |
>> Encrypted block 1 is moved from blkaddr A of segment 1 to blkaddr B of
>> segment 2,
>>
>> Time 2: | segment 1 blkaddr = B | GC -> | segment 3 blkaddr = C |
> segment 2 blkaddr = B?
Sorry for typing error.
Yes.
>
>> Before page 1 is written back and if segment 2 become a victim, then
>> page 1 is moved from blkaddr B of segment 2 to blkaddr Cof segment 3,
> C of ?
Yes.
>
>> during the GC process of Time 2, f2fs should wait for page 1 written back
>> before reading it, or move_data_block will read a garbage block from
>> blkaddr B since page is not written back to blkaddr B yet.
> move_data_block() checks PageUptodate() so it won't get garbage, yes?
> So, does ra_data_block need to check PageUptodate?
You mean if page 1 is read from blkaddr B before it is written back to
blkaddr B, then
the page will become non-uptodate status, why? Is it because
__read_end_io checks
"(bio->bi_status || PageError(page))" and ClearPageUptodate(page)?
>
>> Commit 6aa58d8a ("f2fs: readahead encrypted block during GC") introduce
>> ra_data_block to read encrypted block, but it forgets to add
>> f2fs_wait_on_page_writeback to avoid racing between GC and flush.
>>
>> Signed-off-by: Yunlong Song <yunlong.song@huawei.com>
>> ---
>> fs/f2fs/gc.c | 10 ++++++++++
>> 1 file changed, 10 insertions(+)
>>
>> diff --git a/fs/f2fs/gc.c b/fs/f2fs/gc.c
>> index a4c1a41..c55fb62 100644
>> --- a/fs/f2fs/gc.c
>> +++ b/fs/f2fs/gc.c
>> @@ -641,6 +641,14 @@ static int ra_data_block(struct inode *inode, pgoff_t index)
>> fio.page = page;
>> fio.new_blkaddr = fio.old_blkaddr = dn.data_blkaddr;
>>
>> + /*
>> + * don't cache encrypted data into meta inode until previous dirty
>> + * data were writebacked to avoid racing between GC and flush.
>> + */
>> + f2fs_wait_on_page_writeback(page, DATA, true);
>> +
>> + f2fs_wait_on_block_writeback(inode, dn.data_blkaddr);
>> +
>> fio.encrypted_page = f2fs_pagecache_get_page(META_MAPPING(sbi),
>> dn.data_blkaddr,
>> FGP_LOCK | FGP_CREAT, GFP_NOFS);
>> @@ -723,6 +731,8 @@ static void move_data_block(struct inode *inode, block_t bidx,
>> */
>> f2fs_wait_on_page_writeback(page, DATA, true);
>>
>> + f2fs_wait_on_block_writeback(inode, dn.data_blkaddr);
>> +
>> err = f2fs_get_node_info(fio.sbi, dn.nid, &ni);
>> if (err)
>> goto put_out;
>> --
>> 1.8.5.2
> .
>
--
Thanks,
Yunlong Song
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] f2fs: avoid GC causing encrypted file corrupted
2018-09-18 18:17 ` Jaegeuk Kim
2018-09-19 2:37 ` Yunlong Song
@ 2018-09-21 14:20 ` Chao Yu
1 sibling, 0 replies; 8+ messages in thread
From: Chao Yu @ 2018-09-21 14:20 UTC (permalink / raw)
To: Jaegeuk Kim, Yunlong Song
Cc: yuchao0, yunlong.song, miaoxie, bintian.wang, shengyong1,
heyunlei, linux-f2fs-devel, linux-kernel
On 2018/9/19 2:17, Jaegeuk Kim wrote:
> On 09/18, Yunlong Song wrote:
>> The encrypted file may be corrupted by GC in following case:
>>
>> Time 1: | segment 1 blkaddr = A | GC -> | segment 2 blkaddr = B |
>> Encrypted block 1 is moved from blkaddr A of segment 1 to blkaddr B of
>> segment 2,
>>
>> Time 2: | segment 1 blkaddr = B | GC -> | segment 3 blkaddr = C |
>
> segment 2 blkaddr = B?
>
>>
>> Before page 1 is written back and if segment 2 become a victim, then
>> page 1 is moved from blkaddr B of segment 2 to blkaddr Cof segment 3,
>
> C of ?
>
>> during the GC process of Time 2, f2fs should wait for page 1 written back
>> before reading it, or move_data_block will read a garbage block from
>> blkaddr B since page is not written back to blkaddr B yet.
>
> move_data_block() checks PageUptodate() so it won't get garbage, yes?
I think the problem here is:
Thread A Background GC Thread
- writepage
- f2fs_outplace_write_data
fio->encrypted_page is in-flight
- gc_data_segment
- ra_data_block
- f2fs_pagecache_get_page
- f2fs_submit_page_bio
cache garbage data in meta page
Device
Receive encrypted data
- f2fs_write_end_io
- move_data_block
- f2fs_pagecache_get_page
- if (PageUptodate(mpage)) memcpy()
So here we copy garbage data into meta page
- f2fs_submit_page_write
Here we migrate incorrect data to new address
> So, does ra_data_block need to check PageUptodate?
Yes, I think so, could improve this in another patch.
Thanks,
>
>>
>> Commit 6aa58d8a ("f2fs: readahead encrypted block during GC") introduce
>> ra_data_block to read encrypted block, but it forgets to add
>> f2fs_wait_on_page_writeback to avoid racing between GC and flush.
>>
>> Signed-off-by: Yunlong Song <yunlong.song@huawei.com>
>> ---
>> fs/f2fs/gc.c | 10 ++++++++++
>> 1 file changed, 10 insertions(+)
>>
>> diff --git a/fs/f2fs/gc.c b/fs/f2fs/gc.c
>> index a4c1a41..c55fb62 100644
>> --- a/fs/f2fs/gc.c
>> +++ b/fs/f2fs/gc.c
>> @@ -641,6 +641,14 @@ static int ra_data_block(struct inode *inode, pgoff_t index)
>> fio.page = page;
>> fio.new_blkaddr = fio.old_blkaddr = dn.data_blkaddr;
>>
>> + /*
>> + * don't cache encrypted data into meta inode until previous dirty
>> + * data were writebacked to avoid racing between GC and flush.
>> + */
>> + f2fs_wait_on_page_writeback(page, DATA, true);
>> +
>> + f2fs_wait_on_block_writeback(inode, dn.data_blkaddr);
>> +
>> fio.encrypted_page = f2fs_pagecache_get_page(META_MAPPING(sbi),
>> dn.data_blkaddr,
>> FGP_LOCK | FGP_CREAT, GFP_NOFS);
>> @@ -723,6 +731,8 @@ static void move_data_block(struct inode *inode, block_t bidx,
>> */
>> f2fs_wait_on_page_writeback(page, DATA, true);
>>
>> + f2fs_wait_on_block_writeback(inode, dn.data_blkaddr);
>> +
>> err = f2fs_get_node_info(fio.sbi, dn.nid, &ni);
>> if (err)
>> goto put_out;
>> --
>> 1.8.5.2
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] f2fs: avoid GC causing encrypted file corrupted
2018-09-18 12:39 [PATCH] f2fs: avoid GC causing encrypted file corrupted Yunlong Song
2018-09-18 13:21 ` Chao Yu
2018-09-18 18:17 ` Jaegeuk Kim
@ 2018-10-24 8:07 ` Yunlong Song
2 siblings, 0 replies; 8+ messages in thread
From: Yunlong Song @ 2018-10-24 8:07 UTC (permalink / raw)
To: jaegeuk, chao, yuchao0, yunlong.song
Cc: miaoxie, bintian.wang, shengyong1, heyunlei, linux-f2fs-devel,
linux-kernel
ping...
On 2018/9/18 20:39, Yunlong Song wrote:
> The encrypted file may be corrupted by GC in following case:
>
> Time 1: | segment 1 blkaddr = A | GC -> | segment 2 blkaddr = B |
> Encrypted block 1 is moved from blkaddr A of segment 1 to blkaddr B of
> segment 2,
>
> Time 2: | segment 1 blkaddr = B | GC -> | segment 3 blkaddr = C |
>
> Before page 1 is written back and if segment 2 become a victim, then
> page 1 is moved from blkaddr B of segment 2 to blkaddr Cof segment 3,
> during the GC process of Time 2, f2fs should wait for page 1 written back
> before reading it, or move_data_block will read a garbage block from
> blkaddr B since page is not written back to blkaddr B yet.
>
> Commit 6aa58d8a ("f2fs: readahead encrypted block during GC") introduce
> ra_data_block to read encrypted block, but it forgets to add
> f2fs_wait_on_page_writeback to avoid racing between GC and flush.
>
> Signed-off-by: Yunlong Song <yunlong.song@huawei.com>
> ---
> fs/f2fs/gc.c | 10 ++++++++++
> 1 file changed, 10 insertions(+)
>
> diff --git a/fs/f2fs/gc.c b/fs/f2fs/gc.c
> index a4c1a41..c55fb62 100644
> --- a/fs/f2fs/gc.c
> +++ b/fs/f2fs/gc.c
> @@ -641,6 +641,14 @@ static int ra_data_block(struct inode *inode, pgoff_t index)
> fio.page = page;
> fio.new_blkaddr = fio.old_blkaddr = dn.data_blkaddr;
>
> + /*
> + * don't cache encrypted data into meta inode until previous dirty
> + * data were writebacked to avoid racing between GC and flush.
> + */
> + f2fs_wait_on_page_writeback(page, DATA, true);
> +
> + f2fs_wait_on_block_writeback(inode, dn.data_blkaddr);
> +
> fio.encrypted_page = f2fs_pagecache_get_page(META_MAPPING(sbi),
> dn.data_blkaddr,
> FGP_LOCK | FGP_CREAT, GFP_NOFS);
> @@ -723,6 +731,8 @@ static void move_data_block(struct inode *inode, block_t bidx,
> */
> f2fs_wait_on_page_writeback(page, DATA, true);
>
> + f2fs_wait_on_block_writeback(inode, dn.data_blkaddr);
> +
> err = f2fs_get_node_info(fio.sbi, dn.nid, &ni);
> if (err)
> goto put_out;
--
Thanks,
Yunlong Song
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH] f2fs: avoid GC causing encrypted file corrupted
2018-09-18 13:21 ` Chao Yu
@ 2018-11-13 3:16 ` Chao Yu
2018-11-14 21:54 ` Jaegeuk Kim
0 siblings, 1 reply; 8+ messages in thread
From: Chao Yu @ 2018-11-13 3:16 UTC (permalink / raw)
To: Chao Yu, Yunlong Song, jaegeuk, yunlong.song
Cc: miaoxie, bintian.wang, shengyong1, heyunlei, linux-f2fs-devel,
linux-kernel
Jaegeuk,
On 2018/9/18 21:21, Chao Yu wrote:
> On 2018/9/18 20:39, Yunlong Song wrote:
>> The encrypted file may be corrupted by GC in following case:
>>
>> Time 1: | segment 1 blkaddr = A | GC -> | segment 2 blkaddr = B |
>> Encrypted block 1 is moved from blkaddr A of segment 1 to blkaddr B of
>> segment 2,
>>
>> Time 2: | segment 1 blkaddr = B | GC -> | segment 3 blkaddr = C |
>>
>> Before page 1 is written back and if segment 2 become a victim, then
>> page 1 is moved from blkaddr B of segment 2 to blkaddr Cof segment 3,
>> during the GC process of Time 2, f2fs should wait for page 1 written back
>> before reading it, or move_data_block will read a garbage block from
>> blkaddr B since page is not written back to blkaddr B yet.
>>
>> Commit 6aa58d8a ("f2fs: readahead encrypted block during GC") introduce
>> ra_data_block to read encrypted block, but it forgets to add
>> f2fs_wait_on_page_writeback to avoid racing between GC and flush.
>>
>> Signed-off-by: Yunlong Song <yunlong.song@huawei.com>
>
> Reviewed-by: Chao Yu <yuchao0@huawei.com>
I've reviewed this patch, could you add missing tag in the patch located in
dev-test branch?
Thanks,
>
> Thanks,
>
> .
>
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] f2fs: avoid GC causing encrypted file corrupted
2018-11-13 3:16 ` Chao Yu
@ 2018-11-14 21:54 ` Jaegeuk Kim
0 siblings, 0 replies; 8+ messages in thread
From: Jaegeuk Kim @ 2018-11-14 21:54 UTC (permalink / raw)
To: Chao Yu
Cc: Chao Yu, Yunlong Song, yunlong.song, miaoxie, bintian.wang,
shengyong1, heyunlei, linux-f2fs-devel, linux-kernel
On 11/13, Chao Yu wrote:
> Jaegeuk,
>
> On 2018/9/18 21:21, Chao Yu wrote:
> > On 2018/9/18 20:39, Yunlong Song wrote:
> >> The encrypted file may be corrupted by GC in following case:
> >>
> >> Time 1: | segment 1 blkaddr = A | GC -> | segment 2 blkaddr = B |
> >> Encrypted block 1 is moved from blkaddr A of segment 1 to blkaddr B of
> >> segment 2,
> >>
> >> Time 2: | segment 1 blkaddr = B | GC -> | segment 3 blkaddr = C |
> >>
> >> Before page 1 is written back and if segment 2 become a victim, then
> >> page 1 is moved from blkaddr B of segment 2 to blkaddr Cof segment 3,
> >> during the GC process of Time 2, f2fs should wait for page 1 written back
> >> before reading it, or move_data_block will read a garbage block from
> >> blkaddr B since page is not written back to blkaddr B yet.
> >>
> >> Commit 6aa58d8a ("f2fs: readahead encrypted block during GC") introduce
> >> ra_data_block to read encrypted block, but it forgets to add
> >> f2fs_wait_on_page_writeback to avoid racing between GC and flush.
> >>
> >> Signed-off-by: Yunlong Song <yunlong.song@huawei.com>
> >
> > Reviewed-by: Chao Yu <yuchao0@huawei.com>
>
> I've reviewed this patch, could you add missing tag in the patch located in
> dev-test branch?
Sorry, done.
>
> Thanks,
>
> >
> > Thanks,
> >
> > .
> >
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2018-11-14 22:28 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-09-18 12:39 [PATCH] f2fs: avoid GC causing encrypted file corrupted Yunlong Song
2018-09-18 13:21 ` Chao Yu
2018-11-13 3:16 ` Chao Yu
2018-11-14 21:54 ` Jaegeuk Kim
2018-09-18 18:17 ` Jaegeuk Kim
2018-09-19 2:37 ` Yunlong Song
2018-09-21 14:20 ` Chao Yu
2018-10-24 8:07 ` Yunlong Song
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).