Skip to contentSkip to conversation

f2fs: fix a mount fail for wrong next_scan_nid

PATCH In review Yunlei He 3 participants 6 messages Apr 26, 2017 – May 4, 2017 F2FS file system

lore
Share & tools
lore

Yunlei He

author
#0 lore raw

PATCH 1/1 f2fs: fix a mount fail for wrong next_scan_nid

-write_checkpoint
-do_checkpoint
-next_free_nid <--- something wrong with next free nid

-f2fs_fill_super
-build_node_manager
-build_free_nids
-get_current_nat_page
-__get_meta_page <--- attempt to access beyond end of device

---
 fs/f2fs/node.c | 3 +++
 1 file changed, 3 insertions(+)
fs/f2fs/node.c +3 -0
index b99e318..98351a4 100644
@@ -1955,6 +1955,9 @@ static void __build_free_nids(struct f2fs_sb_info *sbi, bool sync, bool mount)
 	int i = 0;
 	nid_t nid = nm_i->next_scan_nid;
 
+	if (unlikely(nid >= nm_i->max_nid))
+		nid = 0;
+
 	/* Enough entries */
 	if (nm_i->nid_cnt[FREE_NID_LIST] >= NAT_ENTRY_PER_BLOCK)
 		return;
Signature · 6 lines
2.10.1


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
#1 lore raw

Hi all,

Quoted 3 lines · Yunlei He

-write_checkpoint
-do_checkpoint
-next_free_nid <--- something wrong with next free nid

Since we have figured out how next_scan_nid can be changed to a wrong value, so how about add a bug_on here to detect potential issue for further fixing?

Thanks,

Quoted 18 lines

-f2fs_fill_super
-build_node_manager
-build_free_nids
-get_current_nat_page
-__get_meta_page <--- attempt to access beyond end of device

---
 fs/f2fs/node.c | 3 +++
 1 file changed, 3 insertions(+)
fs/f2fs/node.c +0 -0
index b99e318..98351a4 100644

fs/f2fs/node.c static void __build_free_nids(struct f2fs_sb_info *sbi, bool sync, bool mount) · line 1963

Quoted 9 lines
fs/f2fs/node.c +3 -0
@@ -1955,6 +1955,9 @@ static void __build_free_nids(struct f2fs_sb_info *sbi, bool sync, bool mount)
 	int i = 0;
 	nid_t nid = nm_i->next_scan_nid;
 
+	if (unlikely(nid >= nm_i->max_nid))
+		nid = 0;
+
 	/* Enough entries */
 	if (nm_i->nid_cnt[FREE_NID_LIST] >= NAT_ENTRY_PER_BLOCK)
 		return;

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot

maintainer
#2 lore raw
Quoted 9 lines · Chao Yu

Hi all,

Quoted 3 lines · Yunlei He

-write_checkpoint
-do_checkpoint
-next_free_nid <--- something wrong with next free nid

Since we have figured out how next_scan_nid can be changed to a wrong value, so how about add a bug_on here to detect potential issue for further fixing?

I'll drop this patch for next merge window.
So, what was the root cause of this?

Thanks,

Quoted 23 lines

Thanks,

Quoted 20 lines

-f2fs_fill_super
-build_node_manager
-build_free_nids
-get_current_nat_page
-__get_meta_page <--- attempt to access beyond end of device

---
 fs/f2fs/node.c | 3 +++
 1 file changed, 3 insertions(+)
fs/f2fs/node.c +0 -0
index b99e318..98351a4 100644
@@ -1955,6 +1955,9 @@ static void __build_free_nids(struct f2fs_sb_info *sbi, bool sync, bool mount)
 	int i = 0;
 	nid_t nid = nm_i->next_scan_nid;
 
Quoted 7 lines

fs/f2fs/node.c static void __build_free_nids(struct f2fs_sb_info *sbi, bool sync, bool mount) · line 1963

Quoted 7 lines
fs/f2fs/node.c +3 -0
+	if (unlikely(nid >= nm_i->max_nid))
+		nid = 0;
+
 	/* Enough entries */
 	if (nm_i->nid_cnt[FREE_NID_LIST] >= NAT_ENTRY_PER_BLOCK)
 		return;

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot

#3 lore raw
Quoted 8 lines · Jaegeuk Kim
Quoted 7 lines · Chao Yu

Hi all,

Quoted 3 lines · Yunlei He

-write_checkpoint
-do_checkpoint
-next_free_nid <--- something wrong with next free nid

Quoted 5 lines
Quoted 2 lines

Since we have figured out how next_scan_nid can be changed to a wrong value, so how about add a bug_on here to detect potential issue for further fixing?

I'll drop this patch for next merge window.
So, what was the root cause of this?

I don't know yet, :( maybe it was caused by bit-transition of cpu or memory.

Thanks,

Quoted 26 lines

Thanks,

Quoted 23 lines

Thanks,

Quoted 20 lines

-f2fs_fill_super
-build_node_manager
-build_free_nids
-get_current_nat_page
-__get_meta_page <--- attempt to access beyond end of device

---
 fs/f2fs/node.c | 3 +++
 1 file changed, 3 insertions(+)
fs/f2fs/node.c +0 -0
index b99e318..98351a4 100644
@@ -1955,6 +1955,9 @@ static void __build_free_nids(struct f2fs_sb_info *sbi, bool sync, bool mount)
 	int i = 0;
 	nid_t nid = nm_i->next_scan_nid;
 
Quoted 10 lines
Quoted 7 lines

fs/f2fs/node.c static void __build_free_nids(struct f2fs_sb_info *sbi, bool sync, bool mount) · line 1963

Quoted 7 lines
fs/f2fs/node.c +3 -0
+	if (unlikely(nid >= nm_i->max_nid))
+		nid = 0;
+
 	/* Enough entries */
 	if (nm_i->nid_cnt[FREE_NID_LIST] >= NAT_ENTRY_PER_BLOCK)
 		return;

.

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot

maintainer
#4 lore raw
Quoted 9 lines · Chao Yu
Quoted 8 lines · Jaegeuk Kim
Quoted 7 lines · Chao Yu

Hi all,

Quoted 3 lines · Yunlei He

-write_checkpoint
-do_checkpoint
-next_free_nid <--- something wrong with next free nid

Quoted 7 lines
Quoted 5 lines
Quoted 2 lines

Since we have figured out how next_scan_nid can be changed to a wrong value, so how about add a bug_on here to detect potential issue for further fixing?

I'll drop this patch for next merge window.
So, what was the root cause of this?

I don't know yet, :( maybe it was caused by bit-transition of cpu or memory.

Hmm, then this patch would be just fine, as I think. Even if nm_i->next_scan_nid was corrupted, we can set it back as normal.

Thanks,

Quoted 39 lines

Thanks,

Quoted 36 lines

Thanks,

Quoted 23 lines

Thanks,

Quoted 20 lines

-f2fs_fill_super
-build_node_manager
-build_free_nids
-get_current_nat_page
-__get_meta_page <--- attempt to access beyond end of device

---
 fs/f2fs/node.c | 3 +++
 1 file changed, 3 insertions(+)
fs/f2fs/node.c +0 -0
index b99e318..98351a4 100644
@@ -1955,6 +1955,9 @@ static void __build_free_nids(struct f2fs_sb_info *sbi, bool sync, bool mount)
 	int i = 0;
 	nid_t nid = nm_i->next_scan_nid;
 
Quoted 7 lines

fs/f2fs/node.c static void __build_free_nids(struct f2fs_sb_info *sbi, bool sync, bool mount) · line 1963

Quoted 7 lines
fs/f2fs/node.c +3 -0
+	if (unlikely(nid >= nm_i->max_nid))
+		nid = 0;
+
 	/* Enough entries */
 	if (nm_i->nid_cnt[FREE_NID_LIST] >= NAT_ENTRY_PER_BLOCK)
 		return;

.

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot

#5 lore raw
Quoted 13 lines · Jaegeuk Kim
Quoted 12 lines · Chao Yu
Quoted 11 lines · Jaegeuk Kim
Quoted 9 lines · Chao Yu

Hi all,

Quoted 3 lines · Yunlei He

-write_checkpoint
-do_checkpoint
-next_free_nid <--- something wrong with next free nid

Since we have figured out how next_scan_nid can be changed to a wrong value, so how about add a bug_on here to detect potential issue for further fixing?

Quoted 7 lines
Quoted 4 lines
Quoted 2 lines

I'll drop this patch for next merge window.
So, what was the root cause of this?

I don't know yet, :( maybe it was caused by bit-transition of cpu or memory.

Hmm, then this patch would be just fine, as I think. Even if nm_i->next_scan_nid was corrupted, we can set it back as normal.

IMO, for product, it's better to set it back, as we expect filesystem module has fault tolerance itself, for upstream, it would be good to keep bug_on to detect further bug. Anyway, not a big deal. ;)

Thanks,

Quoted 43 lines

Thanks,

Quoted 39 lines

Thanks,

Quoted 36 lines

Thanks,

Quoted 23 lines

Thanks,

Quoted 20 lines

-f2fs_fill_super
-build_node_manager
-build_free_nids
-get_current_nat_page
-__get_meta_page <--- attempt to access beyond end of device

---
 fs/f2fs/node.c | 3 +++
 1 file changed, 3 insertions(+)
fs/f2fs/node.c +0 -0
index b99e318..98351a4 100644
@@ -1955,6 +1955,9 @@ static void __build_free_nids(struct f2fs_sb_info *sbi, bool sync, bool mount)
 	int i = 0;
 	nid_t nid = nm_i->next_scan_nid;
 
Quoted 7 lines

fs/f2fs/node.c static void __build_free_nids(struct f2fs_sb_info *sbi, bool sync, bool mount) · line 1963

Quoted 7 lines
fs/f2fs/node.c +3 -0
+	if (unlikely(nid >= nm_i->max_nid))
+		nid = 0;
+
 	/* Enough entries */
 	if (nm_i->nid_cnt[FREE_NID_LIST] >= NAT_ENTRY_PER_BLOCK)
 		return;

.

Quoted 2 lines

.

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot