Skip to contentSkip to conversation

ext4: use rcu API in debug_print_tree

PATCH Superseded Phong Tran 4 participants 7 messages Dec 1, 2019 – Dec 16, 2019

Subsystems (3)
lore
Share & tools
lore

Phong Tran

author
#0 lore raw

PATCH 1/1 ext4: use rcu API in debug_print_tree

struct ext4_sb_info.system_blks was marked __rcu. But access the pointer without using RCU lock and dereference. Sparse warning with __rcu notation:

block_validity.c:139:29: warning: incorrect type in argument 1 (different address spaces)
block_validity.c:139:29: expected struct rb_root const *
block_validity.c:139:29: got struct rb_root [noderef] <asn:4> *

---
 fs/ext4/block_validity.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
fs/ext4/block_validity.c +5 -1
index d4d4fdfac1a6..1ee04e76bbe0 100644
@@ -133,10 +133,13 @@ static void debug_print_tree(struct ext4_sb_info *sbi)
 {
 	struct rb_node *node;
 	struct ext4_system_zone *entry;
+	struct ext4_system_blocks *system_blks;
 	int first = 1;
 
 	printk(KERN_INFO "System zones: ");
-	node = rb_first(&sbi->system_blks->root);
+	rcu_read_lock();
+	system_blks = rcu_dereference(sbi->system_blks);
+	node = rb_first(&system_blks->root);
 	while (node) {
 		entry = rb_entry(node, struct ext4_system_zone, node);
 		printk(KERN_CONT "%s%llu-%llu", first ? "" : ", ",
@@ -144,6 +147,7 @@ static void debug_print_tree(struct ext4_sb_info *sbi)
 		first = 0;
 		node = rb_next(node);
 	}
+	rcu_read_unlock();
 	printk(KERN_CONT "\n");
 }
 
Signature · 1 line
2.20.1
reviewer Reviewed-by on v1 1/1
#1 lore raw
Quoted 9 lines · Phong Tran

struct ext4_sb_info.system_blks was marked __rcu. But access the pointer without using RCU lock and dereference. Sparse warning with __rcu notation:

block_validity.c:139:29: warning: incorrect type in argument 1 (different address spaces)
block_validity.c:139:29: expected struct rb_root const *
block_validity.c:139:29: got struct rb_root [noderef] <asn:4> *

Thanks for the patch. It looks good to me. You can add:

Honza

Quoted 34 lines
---
 fs/ext4/block_validity.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
fs/ext4/block_validity.c +5 -1
index d4d4fdfac1a6..1ee04e76bbe0 100644
@@ -133,10 +133,13 @@ static void debug_print_tree(struct ext4_sb_info *sbi)
 {
 	struct rb_node *node;
 	struct ext4_system_zone *entry;
+	struct ext4_system_blocks *system_blks;
 	int first = 1;
 
 	printk(KERN_INFO "System zones: ");
-	node = rb_first(&sbi->system_blks->root);
+	rcu_read_lock();
+	system_blks = rcu_dereference(sbi->system_blks);
+	node = rb_first(&system_blks->root);
 	while (node) {
 		entry = rb_entry(node, struct ext4_system_zone, node);
 		printk(KERN_CONT "%s%llu-%llu", first ? "" : ", ",
@@ -144,6 +147,7 @@ static void debug_print_tree(struct ext4_sb_info *sbi)
 		first = 0;
 		node = rb_next(node);
 	}
+	rcu_read_unlock();
 	printk(KERN_CONT "\n");
 }
 
Signature · 1 line
2.20.1
Signature · 2 lines
Jan Kara <[email protected]>
SUSE Labs, CR
author
#2 lore raw

PATCH v2 1/1 ext4: use rcu API in debug_print_tree

struct ext4_sb_info.system_blks was marked __rcu. But access the pointer without using RCU lock and dereference. Sparse warning with __rcu notation:

block_validity.c:139:29: warning: incorrect type in argument 1 (different address spaces)
block_validity.c:139:29: expected struct rb_root const *
block_validity.c:139:29: got struct rb_root [noderef] <asn:4> *

---
 fs/ext4/block_validity.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

---
change log:
V2: Add Reviewed-by: Jan Kara <[email protected]>

fs/ext4/block_validity.c +5 -1
index d4d4fdfac1a6..1ee04e76bbe0 100644
@@ -133,10 +133,13 @@ static void debug_print_tree(struct ext4_sb_info *sbi)
 {
 	struct rb_node *node;
 	struct ext4_system_zone *entry;
+	struct ext4_system_blocks *system_blks;
 	int first = 1;
 
 	printk(KERN_INFO "System zones: ");
-	node = rb_first(&sbi->system_blks->root);
+	rcu_read_lock();
+	system_blks = rcu_dereference(sbi->system_blks);
+	node = rb_first(&system_blks->root);
 	while (node) {
 		entry = rb_entry(node, struct ext4_system_zone, node);
 		printk(KERN_CONT "%s%llu-%llu", first ? "" : ", ",
@@ -144,6 +147,7 @@ static void debug_print_tree(struct ext4_sb_info *sbi)
 		first = 0;
 		node = rb_next(node);
 	}
+	rcu_read_unlock();
 	printk(KERN_CONT "\n");
 }
 
Signature · 1 line
2.20.1
#3 lore raw
Quoted 11 lines · Phong Tran

struct ext4_sb_info.system_blks was marked __rcu. But access the pointer without using RCU lock and dereference. Sparse warning with __rcu notation:

block_validity.c:139:29: warning: incorrect type in argument 1 (different address spaces)
block_validity.c:139:29: expected struct rb_root const *
block_validity.c:139:29: got struct rb_root [noderef] <asn:4> *

Thanks Phong! Looks like a real bug fix caught thanks to Sparse. So let us mark for stable as well?

- Joel

Quoted 38 lines
---
 fs/ext4/block_validity.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

---
change log:
V2: Add Reviewed-by: Jan Kara <[email protected]>

fs/ext4/block_validity.c +5 -2
index d4d4fdfac1a6..1ee04e76bbe0 100644
@@ -133,10 +133,13 @@ static void debug_print_tree(struct ext4_sb_info *sbi)
 {
        struct rb_node *node;
        struct ext4_system_zone *entry;
+       struct ext4_system_blocks *system_blks;
        int first = 1;
 
        printk(KERN_INFO "System zones: ");
-       node = rb_first(&sbi->system_blks->root);
+       rcu_read_lock();
+       system_blks = rcu_dereference(sbi->system_blks);
+       node = rb_first(&system_blks->root);
        while (node) {
                entry = rb_entry(node, struct ext4_system_zone, node);
                printk(KERN_CONT "%s%llu-%llu", first ? "" : ", ",
@@ -144,6 +147,7 @@ static void debug_print_tree(struct ext4_sb_info *sbi)
                first = 0;
                node = rb_next(node);
        }
+       rcu_read_unlock();
        printk(KERN_CONT "\n");
 }
 
--

2.20.1

reviewer
#4 lore raw
Quoted 10 lines · Joel Fernandes
Quoted 9 lines · Phong Tran

struct ext4_sb_info.system_blks was marked __rcu. But access the pointer without using RCU lock and dereference. Sparse warning with __rcu notation:

block_validity.c:139:29: warning: incorrect type in argument 1 (different address spaces)
block_validity.c:139:29: expected struct rb_root const *
block_validity.c:139:29: got struct rb_root [noderef] <asn:4> *

Quoted 5 lines
Quoted 2 lines

Thanks Phong! Looks like a real bug fix caught thanks to Sparse. So let us mark for stable as well?

Well, not really. The code is active only with CONFIG_EXT4_DEBUG enabled and in this case there's no race with remount (and thus sbi->system_blks changing) possible. So the change is really only to silence the sparse warning.

Honza

Quoted 41 lines

- Joel

Quoted 38 lines
---
 fs/ext4/block_validity.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

---
change log:
V2: Add Reviewed-by: Jan Kara <[email protected]>

fs/ext4/block_validity.c +5 -2
index d4d4fdfac1a6..1ee04e76bbe0 100644
@@ -133,10 +133,13 @@ static void debug_print_tree(struct ext4_sb_info *sbi)
 {
        struct rb_node *node;
        struct ext4_system_zone *entry;
+       struct ext4_system_blocks *system_blks;
        int first = 1;
 
        printk(KERN_INFO "System zones: ");
-       node = rb_first(&sbi->system_blks->root);
+       rcu_read_lock();
+       system_blks = rcu_dereference(sbi->system_blks);
+       node = rb_first(&system_blks->root);
        while (node) {
                entry = rb_entry(node, struct ext4_system_zone, node);
                printk(KERN_CONT "%s%llu-%llu", first ? "" : ", ",
@@ -144,6 +147,7 @@ static void debug_print_tree(struct ext4_sb_info *sbi)
                first = 0;
                node = rb_next(node);
        }
+       rcu_read_unlock();
        printk(KERN_CONT "\n");
 }
 
--

2.20.1

Signature · 2 lines
Jan Kara <[email protected]>
SUSE Labs, CR
#5 lore raw
Quoted 14 lines · Jan Kara
Quoted 13 lines · Joel Fernandes
Quoted 11 lines · Phong Tran

struct ext4_sb_info.system_blks was marked __rcu. But access the pointer without using RCU lock and dereference. Sparse warning with __rcu notation:

block_validity.c:139:29: warning: incorrect type in argument 1 (different address spaces)
block_validity.c:139:29: expected struct rb_root const *
block_validity.c:139:29: got struct rb_root [noderef] <asn:4> *

Quoted 7 lines
Quoted 2 lines

Thanks Phong! Looks like a real bug fix caught thanks to Sparse. So let us mark for stable as well?

Well, not really. The code is active only with CONFIG_EXT4_DEBUG enabled and in this case there's no race with remount (and thus sbi->system_blks changing) possible. So the change is really only to silence the sparse warning.

Ok, thanks for clarifying.

-Joel

Quoted 47 lines

Honza

Quoted 41 lines

- Joel

Quoted 38 lines
---
 fs/ext4/block_validity.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

---
change log:
V2: Add Reviewed-by: Jan Kara <[email protected]>

fs/ext4/block_validity.c +5 -2
index d4d4fdfac1a6..1ee04e76bbe0 100644
@@ -133,10 +133,13 @@ static void debug_print_tree(struct ext4_sb_info *sbi)
 {
        struct rb_node *node;
        struct ext4_system_zone *entry;
+       struct ext4_system_blocks *system_blks;
        int first = 1;
 
        printk(KERN_INFO "System zones: ");
-       node = rb_first(&sbi->system_blks->root);
+       rcu_read_lock();
+       system_blks = rcu_dereference(sbi->system_blks);
+       node = rb_first(&system_blks->root);
        while (node) {
                entry = rb_entry(node, struct ext4_system_zone, node);
                printk(KERN_CONT "%s%llu-%llu", first ? "" : ", ",
@@ -144,6 +147,7 @@ static void debug_print_tree(struct ext4_sb_info *sbi)
                first = 0;
                node = rb_next(node);
        }
+       rcu_read_unlock();
        printk(KERN_CONT "\n");
 }
 
--

2.20.1

Signature · 2 lines
Jan Kara <[email protected]>
SUSE Labs, CR
maintainer Applied
#6 lore raw
In reply to Phong Tran
Quoted 10 lines · Phong Tran

struct ext4_sb_info.system_blks was marked __rcu. But access the pointer without using RCU lock and dereference. Sparse warning with __rcu notation:

block_validity.c:139:29: warning: incorrect type in argument 1 (different address spaces)
block_validity.c:139:29: expected struct rb_root const *
block_validity.c:139:29: got struct rb_root [noderef] <asn:4> *

Applied, thanks.

- Ted
_______________________________________________
Linux-kernel-mentees mailing list [email protected]
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees