Linux Kernel Mentees Archive on lore.kernel.org
 help / color / Atom feed
* [Linux-kernel-mentees] [PATCH] ext4: use rcu API in debug_print_tree
@ 2019-12-01  3:51 Phong Tran
  2019-12-13 11:35 ` Jan Kara
  0 siblings, 1 reply; 7+ messages in thread
From: Phong Tran @ 2019-12-01  3:51 UTC (permalink / raw)
  To: tytso, adilger.kernel, paulmck, joel
  Cc: rcu, linux-ext4, linux-kernel-mentees, linux-kernel

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> *

Signed-off-by: Phong Tran <tranmanphong@gmail.com>
---
 fs/ext4/block_validity.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/fs/ext4/block_validity.c b/fs/ext4/block_validity.c
index d4d4fdfac1a6..1ee04e76bbe0 100644
--- a/fs/ext4/block_validity.c
+++ b/fs/ext4/block_validity.c
@@ -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

_______________________________________________
Linux-kernel-mentees mailing list
Linux-kernel-mentees@lists.linuxfoundation.org
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [Linux-kernel-mentees] [PATCH] ext4: use rcu API in debug_print_tree
  2019-12-01  3:51 [Linux-kernel-mentees] [PATCH] ext4: use rcu API in debug_print_tree Phong Tran
@ 2019-12-13 11:35 ` Jan Kara
  2019-12-13 15:33   ` [Linux-kernel-mentees] [PATCH V2] " Phong Tran
  0 siblings, 1 reply; 7+ messages in thread
From: Jan Kara @ 2019-12-13 11:35 UTC (permalink / raw)
  To: Phong Tran
  Cc: tytso, paulmck, linux-kernel, rcu, adilger.kernel, joel,
	linux-ext4, linux-kernel-mentees

On Sun 01-12-19 10:51:07, Phong Tran wrote:
> 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> *
> 
> Signed-off-by: Phong Tran <tranmanphong@gmail.com>

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

Reviewed-by: Jan Kara <jack@suse.cz>

								Honza

> ---
>  fs/ext4/block_validity.c | 6 +++++-
>  1 file changed, 5 insertions(+), 1 deletion(-)
> 
> diff --git a/fs/ext4/block_validity.c b/fs/ext4/block_validity.c
> index d4d4fdfac1a6..1ee04e76bbe0 100644
> --- a/fs/ext4/block_validity.c
> +++ b/fs/ext4/block_validity.c
> @@ -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
> 
-- 
Jan Kara <jack@suse.com>
SUSE Labs, CR
_______________________________________________
Linux-kernel-mentees mailing list
Linux-kernel-mentees@lists.linuxfoundation.org
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Linux-kernel-mentees] [PATCH V2] ext4: use rcu API in debug_print_tree
  2019-12-13 11:35 ` Jan Kara
@ 2019-12-13 15:33   ` " Phong Tran
  2019-12-13 18:11     ` Joel Fernandes
  2019-12-16  2:41     ` Theodore Y. Ts'o
  0 siblings, 2 replies; 7+ messages in thread
From: Phong Tran @ 2019-12-13 15:33 UTC (permalink / raw)
  To: jack, tytso, adilger.kernel
  Cc: paulmck, linux-kernel, rcu, joel, linux-ext4, linux-kernel-mentees

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> *

Reviewed-by: Jan Kara <jack@suse.cz>
Signed-off-by: Phong Tran <tranmanphong@gmail.com>
---
 fs/ext4/block_validity.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

---
change log:
V2: Add Reviewed-by: Jan Kara <jack@suse.cz>

diff --git a/fs/ext4/block_validity.c b/fs/ext4/block_validity.c
index d4d4fdfac1a6..1ee04e76bbe0 100644
--- a/fs/ext4/block_validity.c
+++ b/fs/ext4/block_validity.c
@@ -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

_______________________________________________
Linux-kernel-mentees mailing list
Linux-kernel-mentees@lists.linuxfoundation.org
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [Linux-kernel-mentees] [PATCH V2] ext4: use rcu API in debug_print_tree
  2019-12-13 15:33   ` [Linux-kernel-mentees] [PATCH V2] " Phong Tran
@ 2019-12-13 18:11     ` Joel Fernandes
  2019-12-13 19:49       ` Jan Kara
  2019-12-16  2:41     ` Theodore Y. Ts'o
  1 sibling, 1 reply; 7+ messages in thread
From: Joel Fernandes @ 2019-12-13 18:11 UTC (permalink / raw)
  To: Phong Tran
  Cc: Theodore Y. Ts'o, Paul E. McKenney, LKML, stable, rcu,
	adilger.kernel, Jan Kara, linux-ext4, linux-kernel-mentees

On Fri, Dec 13, 2019 at 7:39 AM Phong Tran <tranmanphong@gmail.com> wrote:
>
> 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> *
>
> Reviewed-by: Jan Kara <jack@suse.cz>
> Signed-off-by: Phong Tran <tranmanphong@gmail.com>

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

- Joel

> ---
>  fs/ext4/block_validity.c | 6 +++++-
>  1 file changed, 5 insertions(+), 1 deletion(-)
>
> ---
> change log:
> V2: Add Reviewed-by: Jan Kara <jack@suse.cz>
>
> diff --git a/fs/ext4/block_validity.c b/fs/ext4/block_validity.c
> index d4d4fdfac1a6..1ee04e76bbe0 100644
> --- a/fs/ext4/block_validity.c
> +++ b/fs/ext4/block_validity.c
> @@ -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
>
_______________________________________________
Linux-kernel-mentees mailing list
Linux-kernel-mentees@lists.linuxfoundation.org
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [Linux-kernel-mentees] [PATCH V2] ext4: use rcu API in debug_print_tree
  2019-12-13 18:11     ` Joel Fernandes
@ 2019-12-13 19:49       ` Jan Kara
  2019-12-13 23:19         ` Joel Fernandes
  0 siblings, 1 reply; 7+ messages in thread
From: Jan Kara @ 2019-12-13 19:49 UTC (permalink / raw)
  To: Joel Fernandes
  Cc: Theodore Y. Ts'o, Paul E. McKenney, LKML, stable, rcu,
	adilger.kernel, Jan Kara, linux-ext4, linux-kernel-mentees

On Fri 13-12-19 10:11:50, Joel Fernandes wrote:
> On Fri, Dec 13, 2019 at 7:39 AM Phong Tran <tranmanphong@gmail.com> wrote:
> >
> > 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> *
> >
> > Reviewed-by: Jan Kara <jack@suse.cz>
> > Signed-off-by: Phong Tran <tranmanphong@gmail.com>
> 
> 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

> 
> - Joel
> 
> > ---
> >  fs/ext4/block_validity.c | 6 +++++-
> >  1 file changed, 5 insertions(+), 1 deletion(-)
> >
> > ---
> > change log:
> > V2: Add Reviewed-by: Jan Kara <jack@suse.cz>
> >
> > diff --git a/fs/ext4/block_validity.c b/fs/ext4/block_validity.c
> > index d4d4fdfac1a6..1ee04e76bbe0 100644
> > --- a/fs/ext4/block_validity.c
> > +++ b/fs/ext4/block_validity.c
> > @@ -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
> >
-- 
Jan Kara <jack@suse.com>
SUSE Labs, CR
_______________________________________________
Linux-kernel-mentees mailing list
Linux-kernel-mentees@lists.linuxfoundation.org
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [Linux-kernel-mentees] [PATCH V2] ext4: use rcu API in debug_print_tree
  2019-12-13 19:49       ` Jan Kara
@ 2019-12-13 23:19         ` Joel Fernandes
  0 siblings, 0 replies; 7+ messages in thread
From: Joel Fernandes @ 2019-12-13 23:19 UTC (permalink / raw)
  To: Jan Kara
  Cc: Theodore Y. Ts'o, Paul E. McKenney, LKML, stable, rcu,
	adilger.kernel, linux-ext4, linux-kernel-mentees

On Fri, Dec 13, 2019 at 08:49:43PM +0100, Jan Kara wrote:
> On Fri 13-12-19 10:11:50, Joel Fernandes wrote:
> > On Fri, Dec 13, 2019 at 7:39 AM Phong Tran <tranmanphong@gmail.com> wrote:
> > >
> > > 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> *
> > >
> > > Reviewed-by: Jan Kara <jack@suse.cz>
> > > Signed-off-by: Phong Tran <tranmanphong@gmail.com>
> > 
> > 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

> 
> 								Honza
> 
> > 
> > - Joel
> > 
> > > ---
> > >  fs/ext4/block_validity.c | 6 +++++-
> > >  1 file changed, 5 insertions(+), 1 deletion(-)
> > >
> > > ---
> > > change log:
> > > V2: Add Reviewed-by: Jan Kara <jack@suse.cz>
> > >
> > > diff --git a/fs/ext4/block_validity.c b/fs/ext4/block_validity.c
> > > index d4d4fdfac1a6..1ee04e76bbe0 100644
> > > --- a/fs/ext4/block_validity.c
> > > +++ b/fs/ext4/block_validity.c
> > > @@ -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
> > >
> -- 
> Jan Kara <jack@suse.com>
> SUSE Labs, CR
_______________________________________________
Linux-kernel-mentees mailing list
Linux-kernel-mentees@lists.linuxfoundation.org
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [Linux-kernel-mentees] [PATCH V2] ext4: use rcu API in debug_print_tree
  2019-12-13 15:33   ` [Linux-kernel-mentees] [PATCH V2] " Phong Tran
  2019-12-13 18:11     ` Joel Fernandes
@ 2019-12-16  2:41     ` Theodore Y. Ts'o
  1 sibling, 0 replies; 7+ messages in thread
From: Theodore Y. Ts'o @ 2019-12-16  2:41 UTC (permalink / raw)
  To: Phong Tran
  Cc: jack, paulmck, linux-kernel, rcu, adilger.kernel, joel,
	linux-ext4, linux-kernel-mentees

On Fri, Dec 13, 2019 at 10:33:07PM +0700, Phong Tran wrote:
> 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> *
> 
> Reviewed-by: Jan Kara <jack@suse.cz>
> Signed-off-by: Phong Tran <tranmanphong@gmail.com>

Applied, thanks.

						- Ted
_______________________________________________
Linux-kernel-mentees mailing list
Linux-kernel-mentees@lists.linuxfoundation.org
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, back to index

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-12-01  3:51 [Linux-kernel-mentees] [PATCH] ext4: use rcu API in debug_print_tree Phong Tran
2019-12-13 11:35 ` Jan Kara
2019-12-13 15:33   ` [Linux-kernel-mentees] [PATCH V2] " Phong Tran
2019-12-13 18:11     ` Joel Fernandes
2019-12-13 19:49       ` Jan Kara
2019-12-13 23:19         ` Joel Fernandes
2019-12-16  2:41     ` Theodore Y. Ts'o

Linux Kernel Mentees Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-kernel-mentees/0 linux-kernel-mentees/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-kernel-mentees linux-kernel-mentees/ https://lore.kernel.org/linux-kernel-mentees \
		linux-kernel-mentees@lists.linuxfoundation.org
	public-inbox-index linux-kernel-mentees

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.linuxfoundation.lists.linux-kernel-mentees


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git