diff mbox series

[3/5] mm/vmalloc: Initialize VA's list node after unlink

Message ID 20220607093449.3100-4-urezki@gmail.com (mailing list archive)
State New
Headers show
Series Reduce a vmalloc internal lock contention preparation work | expand

Commit Message

Uladzislau Rezki June 7, 2022, 9:34 a.m. UTC
A vmap_area can travel between different places. For example
attached/detached to/from different rb-trees. In order to
prevent fancy bugs, initialize a VA's list node after it is
removed from the list, so it pairs with VA's rb_node which
is also initialized.

There is no functional change as a result of this patch.

Signed-off-by: Uladzislau Rezki (Sony) <urezki@gmail.com>
---
 mm/vmalloc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Baoquan He June 8, 2022, 3:19 a.m. UTC | #1
On 06/07/22 at 11:34am, Uladzislau Rezki (Sony) wrote:
> A vmap_area can travel between different places. For example
> attached/detached to/from different rb-trees. In order to
> prevent fancy bugs, initialize a VA's list node after it is
> removed from the list, so it pairs with VA's rb_node which
> is also initialized.
> 
> There is no functional change as a result of this patch.
> 
> Signed-off-by: Uladzislau Rezki (Sony) <urezki@gmail.com>
> ---
>  mm/vmalloc.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/mm/vmalloc.c b/mm/vmalloc.c
> index 745e89eb6ca1..82771e555273 100644
> --- a/mm/vmalloc.c
> +++ b/mm/vmalloc.c
> @@ -978,7 +978,7 @@ __unlink_va(struct vmap_area *va, struct rb_root *root, bool augment)
>  	else
>  		rb_erase(&va->rb_node, root);
>  
> -	list_del(&va->list);
> +	list_del_init(&va->list);

Don't object this change, while list_del poison members, which is also
not bad?

static inline void list_del(struct list_head *entry)                                     
{                                                                                        
        __list_del_entry(entry);                                                         
        entry->next = LIST_POISON1;                                                      
        entry->prev = LIST_POISON2;                                                      
}   


>  	RB_CLEAR_NODE(&va->rb_node);
>  }
>  
> -- 
> 2.30.2
> 
>
Uladzislau Rezki June 9, 2022, 12:36 p.m. UTC | #2
>
> On 06/07/22 at 11:34am, Uladzislau Rezki (Sony) wrote:
> > A vmap_area can travel between different places. For example
> > attached/detached to/from different rb-trees. In order to
> > prevent fancy bugs, initialize a VA's list node after it is
> > removed from the list, so it pairs with VA's rb_node which
> > is also initialized.
> >
> > There is no functional change as a result of this patch.
> >
> > Signed-off-by: Uladzislau Rezki (Sony) <urezki@gmail.com>
> > ---
> >  mm/vmalloc.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/mm/vmalloc.c b/mm/vmalloc.c
> > index 745e89eb6ca1..82771e555273 100644
> > --- a/mm/vmalloc.c
> > +++ b/mm/vmalloc.c
> > @@ -978,7 +978,7 @@ __unlink_va(struct vmap_area *va, struct rb_root *root, bool augment)
> >       else
> >               rb_erase(&va->rb_node, root);
> >
> > -     list_del(&va->list);
> > +     list_del_init(&va->list);
>
> Don't object this change, while list_del poison members, which is also
> not bad?
>
It is not bad for sure. The main aim was to be align with what the
RB_CLEAR_NODE() does, i.e. initialize VA when it is detached
and be safe with list manipulation when it is detached. For example
whether it is empty or not: list_empty(), etc.
Baoquan He June 9, 2022, 1:30 p.m. UTC | #3
On 06/09/22 at 02:36pm, Uladzislau Rezki wrote:
> >
> > On 06/07/22 at 11:34am, Uladzislau Rezki (Sony) wrote:
> > > A vmap_area can travel between different places. For example
> > > attached/detached to/from different rb-trees. In order to
> > > prevent fancy bugs, initialize a VA's list node after it is
> > > removed from the list, so it pairs with VA's rb_node which
> > > is also initialized.
> > >
> > > There is no functional change as a result of this patch.
> > >
> > > Signed-off-by: Uladzislau Rezki (Sony) <urezki@gmail.com>
> > > ---
> > >  mm/vmalloc.c | 2 +-
> > >  1 file changed, 1 insertion(+), 1 deletion(-)
> > >
> > > diff --git a/mm/vmalloc.c b/mm/vmalloc.c
> > > index 745e89eb6ca1..82771e555273 100644
> > > --- a/mm/vmalloc.c
> > > +++ b/mm/vmalloc.c
> > > @@ -978,7 +978,7 @@ __unlink_va(struct vmap_area *va, struct rb_root *root, bool augment)
> > >       else
> > >               rb_erase(&va->rb_node, root);
> > >
> > > -     list_del(&va->list);
> > > +     list_del_init(&va->list);
> >
> > Don't object this change, while list_del poison members, which is also
> > not bad?
> >
> It is not bad for sure. The main aim was to be align with what the
> RB_CLEAR_NODE() does, i.e. initialize VA when it is detached
> and be safe with list manipulation when it is detached. For example
> whether it is empty or not: list_empty(), etc.

Agree. list_del() can't make list_empty() work, and RB_CLEAR_NODE() has
done the clearing already.

Then this change looks reasonable to me, thanks.

Reviewed-by: Baoquan He <bhe@redhat.com>
Uladzislau Rezki June 9, 2022, 1:53 p.m. UTC | #4
On Thu, Jun 9, 2022 at 3:30 PM Baoquan He <bhe@redhat.com> wrote:
>
> On 06/09/22 at 02:36pm, Uladzislau Rezki wrote:
> > >
> > > On 06/07/22 at 11:34am, Uladzislau Rezki (Sony) wrote:
> > > > A vmap_area can travel between different places. For example
> > > > attached/detached to/from different rb-trees. In order to
> > > > prevent fancy bugs, initialize a VA's list node after it is
> > > > removed from the list, so it pairs with VA's rb_node which
> > > > is also initialized.
> > > >
> > > > There is no functional change as a result of this patch.
> > > >
> > > > Signed-off-by: Uladzislau Rezki (Sony) <urezki@gmail.com>
> > > > ---
> > > >  mm/vmalloc.c | 2 +-
> > > >  1 file changed, 1 insertion(+), 1 deletion(-)
> > > >
> > > > diff --git a/mm/vmalloc.c b/mm/vmalloc.c
> > > > index 745e89eb6ca1..82771e555273 100644
> > > > --- a/mm/vmalloc.c
> > > > +++ b/mm/vmalloc.c
> > > > @@ -978,7 +978,7 @@ __unlink_va(struct vmap_area *va, struct rb_root *root, bool augment)
> > > >       else
> > > >               rb_erase(&va->rb_node, root);
> > > >
> > > > -     list_del(&va->list);
> > > > +     list_del_init(&va->list);
> > >
> > > Don't object this change, while list_del poison members, which is also
> > > not bad?
> > >
> > It is not bad for sure. The main aim was to be align with what the
> > RB_CLEAR_NODE() does, i.e. initialize VA when it is detached
> > and be safe with list manipulation when it is detached. For example
> > whether it is empty or not: list_empty(), etc.
>
> Agree. list_del() can't make list_empty() work, and RB_CLEAR_NODE() has
> done the clearing already.
>
> Then this change looks reasonable to me, thanks.
>
> Reviewed-by: Baoquan He <bhe@redhat.com>
>
Thanks!
diff mbox series

Patch

diff --git a/mm/vmalloc.c b/mm/vmalloc.c
index 745e89eb6ca1..82771e555273 100644
--- a/mm/vmalloc.c
+++ b/mm/vmalloc.c
@@ -978,7 +978,7 @@  __unlink_va(struct vmap_area *va, struct rb_root *root, bool augment)
 	else
 		rb_erase(&va->rb_node, root);
 
-	list_del(&va->list);
+	list_del_init(&va->list);
 	RB_CLEAR_NODE(&va->rb_node);
 }