linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] mm/damon/tests/vaddr-kunit: init maple tree without MT_FLAGS_LOCK_EXTERN
@ 2024-09-04 17:29 SeongJae Park
  2024-09-04 18:41 ` Guenter Roeck
  2024-09-04 19:58 ` Guenter Roeck
  0 siblings, 2 replies; 5+ messages in thread
From: SeongJae Park @ 2024-09-04 17:29 UTC (permalink / raw)
  To: Andrew Morton
  Cc: SeongJae Park, Liam R. Howlett, David Hildenbrand,
	Matthew Wilcox (Oracle),
	Brendan Higgins, David Gow, damon, linux-mm, kunit-dev,
	linux-kselftest, linux-kernel, Guenter Roeck, Liam R . Howlett

damon_test_three_regions_in_vmas() initializes a maple tree with
MM_MT_FLAGS.  The flags contains MT_FLAGS_LOCK_EXTERN, which means
mt_lock of the maple tree will not be used.  And therefore the maple
tree initialization code skips initialization of the mt_lock.  However,
__link_vmas(), which adds vmas for test to the maple tree, uses the
mt_lock.  In other words, the uninitialized spinlock is used.  The
problem becomes clear when spinlock debugging is turned on, since it
reports spinlock bad magic bug.

Fix the issue by excluding MT_FLAGS_LOCK_EXTERN from the maple tree
initialization flags.  Note that we don't use empty flags to make it
further similar to the usage of mm maple tree, and to be prepared for
possible future changes, as suggested by Liam.

Reported-by: Guenter Roeck <linux@roeck-us.net>
Closes: https://lore.kernel.org/1453b2b2-6119-4082-ad9e-f3c5239bf87e@roeck-us.net
Fixes: d0cf3dd47f0d ("damon: convert __damon_va_three_regions to use the VMA iterator")
Suggested-by: Liam R. Howlett <Liam.Howlett@oracle.com>
Signed-off-by: SeongJae Park <sj@kernel.org>
---
Changes from v1
(https://lore.kernel.org/20240904004534.1189-1-sj@kernel.org)
- Keep lock usage and update the initialization flags (Liam)
- Fix a typo: s/celar/clear/ (Guenter)

 mm/damon/tests/vaddr-kunit.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/mm/damon/tests/vaddr-kunit.h b/mm/damon/tests/vaddr-kunit.h
index 83626483f82b..a339d117150f 100644
--- a/mm/damon/tests/vaddr-kunit.h
+++ b/mm/damon/tests/vaddr-kunit.h
@@ -77,7 +77,7 @@ static void damon_test_three_regions_in_vmas(struct kunit *test)
 		(struct vm_area_struct) {.vm_start = 307, .vm_end = 330},
 	};
 
-	mt_init_flags(&mm.mm_mt, MM_MT_FLAGS);
+	mt_init_flags(&mm.mm_mt, MT_FLAGS_ALLOC_RANGE | MT_FLAGS_USE_RCU);
 	if (__link_vmas(&mm.mm_mt, vmas, ARRAY_SIZE(vmas)))
 		kunit_skip(test, "Failed to create VMA tree");
 
-- 
2.39.2



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

* Re: [PATCH v2] mm/damon/tests/vaddr-kunit: init maple tree without MT_FLAGS_LOCK_EXTERN
  2024-09-04 17:29 [PATCH v2] mm/damon/tests/vaddr-kunit: init maple tree without MT_FLAGS_LOCK_EXTERN SeongJae Park
@ 2024-09-04 18:41 ` Guenter Roeck
  2024-09-04 18:53   ` SeongJae Park
  2024-09-04 19:58 ` Guenter Roeck
  1 sibling, 1 reply; 5+ messages in thread
From: Guenter Roeck @ 2024-09-04 18:41 UTC (permalink / raw)
  To: SeongJae Park, Andrew Morton
  Cc: Liam R. Howlett, David Hildenbrand, Matthew Wilcox (Oracle),
	Brendan Higgins, David Gow, damon, linux-mm, kunit-dev,
	linux-kselftest, linux-kernel

On 9/4/24 10:29, SeongJae Park wrote:
> damon_test_three_regions_in_vmas() initializes a maple tree with
> MM_MT_FLAGS.  The flags contains MT_FLAGS_LOCK_EXTERN, which means
> mt_lock of the maple tree will not be used.  And therefore the maple
> tree initialization code skips initialization of the mt_lock.  However,
> __link_vmas(), which adds vmas for test to the maple tree, uses the
> mt_lock.  In other words, the uninitialized spinlock is used.  The
> problem becomes clear when spinlock debugging is turned on, since it
> reports spinlock bad magic bug.
> 
> Fix the issue by excluding MT_FLAGS_LOCK_EXTERN from the maple tree
> initialization flags.  Note that we don't use empty flags to make it
> further similar to the usage of mm maple tree, and to be prepared for
> possible future changes, as suggested by Liam.
> 
> Reported-by: Guenter Roeck <linux@roeck-us.net>
> Closes: https://lore.kernel.org/1453b2b2-6119-4082-ad9e-f3c5239bf87e@roeck-us.net
> Fixes: d0cf3dd47f0d ("damon: convert __damon_va_three_regions to use the VMA iterator")
> Suggested-by: Liam R. Howlett <Liam.Howlett@oracle.com>
> Signed-off-by: SeongJae Park <sj@kernel.org>
> ---
> Changes from v1
> (https://lore.kernel.org/20240904004534.1189-1-sj@kernel.org)
> - Keep lock usage and update the initialization flags (Liam)

Not sure I understand how this is better. Is the resulting rcu warning
considered to be irrelevant or a separate problem ?

Thanks,
Guenter

> - Fix a typo: s/celar/clear/ (Guenter)
> 
>   mm/damon/tests/vaddr-kunit.h | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/mm/damon/tests/vaddr-kunit.h b/mm/damon/tests/vaddr-kunit.h
> index 83626483f82b..a339d117150f 100644
> --- a/mm/damon/tests/vaddr-kunit.h
> +++ b/mm/damon/tests/vaddr-kunit.h
> @@ -77,7 +77,7 @@ static void damon_test_three_regions_in_vmas(struct kunit *test)
>   		(struct vm_area_struct) {.vm_start = 307, .vm_end = 330},
>   	};
>   
> -	mt_init_flags(&mm.mm_mt, MM_MT_FLAGS);
> +	mt_init_flags(&mm.mm_mt, MT_FLAGS_ALLOC_RANGE | MT_FLAGS_USE_RCU);
>   	if (__link_vmas(&mm.mm_mt, vmas, ARRAY_SIZE(vmas)))
>   		kunit_skip(test, "Failed to create VMA tree");
>   



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

* Re: [PATCH v2] mm/damon/tests/vaddr-kunit: init maple tree without MT_FLAGS_LOCK_EXTERN
  2024-09-04 18:41 ` Guenter Roeck
@ 2024-09-04 18:53   ` SeongJae Park
  2024-09-04 19:28     ` Liam R. Howlett
  0 siblings, 1 reply; 5+ messages in thread
From: SeongJae Park @ 2024-09-04 18:53 UTC (permalink / raw)
  To: Guenter Roeck
  Cc: SeongJae Park, Andrew Morton, Liam R. Howlett, David Hildenbrand,
	Matthew Wilcox (Oracle),
	Brendan Higgins, David Gow, damon, linux-mm, kunit-dev,
	linux-kselftest, linux-kernel

On Wed, 4 Sep 2024 11:41:28 -0700 Guenter Roeck <linux@roeck-us.net> wrote:

> On 9/4/24 10:29, SeongJae Park wrote:
> > damon_test_three_regions_in_vmas() initializes a maple tree with
> > MM_MT_FLAGS.  The flags contains MT_FLAGS_LOCK_EXTERN, which means
> > mt_lock of the maple tree will not be used.  And therefore the maple
> > tree initialization code skips initialization of the mt_lock.  However,
> > __link_vmas(), which adds vmas for test to the maple tree, uses the
> > mt_lock.  In other words, the uninitialized spinlock is used.  The
> > problem becomes clear when spinlock debugging is turned on, since it
> > reports spinlock bad magic bug.
> > 
> > Fix the issue by excluding MT_FLAGS_LOCK_EXTERN from the maple tree
> > initialization flags.  Note that we don't use empty flags to make it
> > further similar to the usage of mm maple tree, and to be prepared for
> > possible future changes, as suggested by Liam.
> > 
> > Reported-by: Guenter Roeck <linux@roeck-us.net>
> > Closes: https://lore.kernel.org/1453b2b2-6119-4082-ad9e-f3c5239bf87e@roeck-us.net
> > Fixes: d0cf3dd47f0d ("damon: convert __damon_va_three_regions to use the VMA iterator")
> > Suggested-by: Liam R. Howlett <Liam.Howlett@oracle.com>
> > Signed-off-by: SeongJae Park <sj@kernel.org>
> > ---
> > Changes from v1
> > (https://lore.kernel.org/20240904004534.1189-1-sj@kernel.org)
> > - Keep lock usage and update the initialization flags (Liam)
> 
> Not sure I understand how this is better. Is the resulting rcu warning
> considered to be irrelevant or a separate problem ?

I believe it's a separate potential problem (warning) that deserves a look.
Meanwhile, this patch is fixing an issue that is definitely a bug, so better to
fix right now, imho.


Thanks,
SJ

[...]


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

* Re: [PATCH v2] mm/damon/tests/vaddr-kunit: init maple tree without MT_FLAGS_LOCK_EXTERN
  2024-09-04 18:53   ` SeongJae Park
@ 2024-09-04 19:28     ` Liam R. Howlett
  0 siblings, 0 replies; 5+ messages in thread
From: Liam R. Howlett @ 2024-09-04 19:28 UTC (permalink / raw)
  To: SeongJae Park
  Cc: Guenter Roeck, Andrew Morton, David Hildenbrand,
	Matthew Wilcox (Oracle),
	Brendan Higgins, David Gow, damon, linux-mm, kunit-dev,
	linux-kselftest, linux-kernel

* SeongJae Park <sj@kernel.org> [240904 14:53]:
> On Wed, 4 Sep 2024 11:41:28 -0700 Guenter Roeck <linux@roeck-us.net> wrote:
> 
> > On 9/4/24 10:29, SeongJae Park wrote:
> > > damon_test_three_regions_in_vmas() initializes a maple tree with
> > > MM_MT_FLAGS.  The flags contains MT_FLAGS_LOCK_EXTERN, which means
> > > mt_lock of the maple tree will not be used.  And therefore the maple
> > > tree initialization code skips initialization of the mt_lock.  However,
> > > __link_vmas(), which adds vmas for test to the maple tree, uses the
> > > mt_lock.  In other words, the uninitialized spinlock is used.  The
> > > problem becomes clear when spinlock debugging is turned on, since it
> > > reports spinlock bad magic bug.
> > > 
> > > Fix the issue by excluding MT_FLAGS_LOCK_EXTERN from the maple tree
> > > initialization flags.  Note that we don't use empty flags to make it
> > > further similar to the usage of mm maple tree, and to be prepared for
> > > possible future changes, as suggested by Liam.
> > > 
> > > Reported-by: Guenter Roeck <linux@roeck-us.net>
> > > Closes: https://lore.kernel.org/1453b2b2-6119-4082-ad9e-f3c5239bf87e@roeck-us.net
> > > Fixes: d0cf3dd47f0d ("damon: convert __damon_va_three_regions to use the VMA iterator")
> > > Suggested-by: Liam R. Howlett <Liam.Howlett@oracle.com>
> > > Signed-off-by: SeongJae Park <sj@kernel.org>
> > > ---
> > > Changes from v1
> > > (https://lore.kernel.org/20240904004534.1189-1-sj@kernel.org)
> > > - Keep lock usage and update the initialization flags (Liam)
> > 
> > Not sure I understand how this is better. Is the resulting rcu warning
> > considered to be irrelevant or a separate problem ?
> 
> I believe it's a separate potential problem (warning) that deserves a look.
> Meanwhile, this patch is fixing an issue that is definitely a bug, so better to
> fix right now, imho.
> 

Whenever you walk the tree, you need to hold the write lock or the rcu
read lock.  I believe that __damon_va_three_regions() needs to have the
rcu_read_lock()/ruc_read_unlock() around the for_each_vma() loop.

I sent a patch to the old thread that I suspect will fix it - but I
don't see the issue so it is hard to say for sure.

Thanks,
Liam


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

* Re: [PATCH v2] mm/damon/tests/vaddr-kunit: init maple tree without MT_FLAGS_LOCK_EXTERN
  2024-09-04 17:29 [PATCH v2] mm/damon/tests/vaddr-kunit: init maple tree without MT_FLAGS_LOCK_EXTERN SeongJae Park
  2024-09-04 18:41 ` Guenter Roeck
@ 2024-09-04 19:58 ` Guenter Roeck
  1 sibling, 0 replies; 5+ messages in thread
From: Guenter Roeck @ 2024-09-04 19:58 UTC (permalink / raw)
  To: SeongJae Park
  Cc: Andrew Morton, Liam R. Howlett, David Hildenbrand,
	Matthew Wilcox (Oracle),
	Brendan Higgins, David Gow, damon, linux-mm, kunit-dev,
	linux-kselftest, linux-kernel

On Wed, Sep 04, 2024 at 10:29:31AM -0700, SeongJae Park wrote:
> damon_test_three_regions_in_vmas() initializes a maple tree with
> MM_MT_FLAGS.  The flags contains MT_FLAGS_LOCK_EXTERN, which means
> mt_lock of the maple tree will not be used.  And therefore the maple
> tree initialization code skips initialization of the mt_lock.  However,
> __link_vmas(), which adds vmas for test to the maple tree, uses the
> mt_lock.  In other words, the uninitialized spinlock is used.  The
> problem becomes clear when spinlock debugging is turned on, since it
> reports spinlock bad magic bug.
> 
> Fix the issue by excluding MT_FLAGS_LOCK_EXTERN from the maple tree
> initialization flags.  Note that we don't use empty flags to make it
> further similar to the usage of mm maple tree, and to be prepared for
> possible future changes, as suggested by Liam.
> 
> Reported-by: Guenter Roeck <linux@roeck-us.net>
> Closes: https://lore.kernel.org/1453b2b2-6119-4082-ad9e-f3c5239bf87e@roeck-us.net
> Fixes: d0cf3dd47f0d ("damon: convert __damon_va_three_regions to use the VMA iterator")
> Suggested-by: Liam R. Howlett <Liam.Howlett@oracle.com>
> Signed-off-by: SeongJae Park <sj@kernel.org>

Tested-by: Guenter Roeck <linux@roeck-us.net>

> ---
> Changes from v1
> (https://lore.kernel.org/20240904004534.1189-1-sj@kernel.org)
> - Keep lock usage and update the initialization flags (Liam)
> - Fix a typo: s/celar/clear/ (Guenter)
> 
>  mm/damon/tests/vaddr-kunit.h | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/mm/damon/tests/vaddr-kunit.h b/mm/damon/tests/vaddr-kunit.h
> index 83626483f82b..a339d117150f 100644
> --- a/mm/damon/tests/vaddr-kunit.h
> +++ b/mm/damon/tests/vaddr-kunit.h
> @@ -77,7 +77,7 @@ static void damon_test_three_regions_in_vmas(struct kunit *test)
>  		(struct vm_area_struct) {.vm_start = 307, .vm_end = 330},
>  	};
>  
> -	mt_init_flags(&mm.mm_mt, MM_MT_FLAGS);
> +	mt_init_flags(&mm.mm_mt, MT_FLAGS_ALLOC_RANGE | MT_FLAGS_USE_RCU);
>  	if (__link_vmas(&mm.mm_mt, vmas, ARRAY_SIZE(vmas)))
>  		kunit_skip(test, "Failed to create VMA tree");
>  
> -- 
> 2.39.2
> 


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

end of thread, other threads:[~2024-09-04 19:58 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-09-04 17:29 [PATCH v2] mm/damon/tests/vaddr-kunit: init maple tree without MT_FLAGS_LOCK_EXTERN SeongJae Park
2024-09-04 18:41 ` Guenter Roeck
2024-09-04 18:53   ` SeongJae Park
2024-09-04 19:28     ` Liam R. Howlett
2024-09-04 19:58 ` Guenter Roeck

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox