* Re: [PATCH v2] vma: Detect infinite loop in vma tree
2024-10-31 19:36 [PATCH v2] vma: Detect infinite loop in vma tree Liam R. Howlett
@ 2024-10-31 20:48 ` Andrew Morton
2024-10-31 21:21 ` Liam R. Howlett
2024-10-31 21:42 ` David Hildenbrand
` (2 subsequent siblings)
3 siblings, 1 reply; 6+ messages in thread
From: Andrew Morton @ 2024-10-31 20:48 UTC (permalink / raw)
To: Liam R. Howlett
Cc: linux-mm, linux-kernel, Liam R. Howlett, Lorenzo Stoakes,
Vlastimil Babka, Jann Horn
On Thu, 31 Oct 2024 15:36:08 -0400 "Liam R. Howlett" <Liam.Howlett@oracle.com> wrote:
> From: "Liam R. Howlett" <Liam.Howlett@Oracle.com>
>
> There have been no reported infinite loops in the tree, but checking the
> detection of an infinite loop during validation is simple enough. Add
> the detection to the validate_mm() function so that error reports are
> clear and don't just report stalls.
>
> This does not protect against internal maple tree issues, but it does
> detect too many vmas being returned from the tree.
>
> The variance of +10 is to allow for the debugging output to be more useful for
> nearly correct counts. In the event of more than 10 over the map_count, the
> count will be set to -1 for easier identification of a potential infinite loop.
>
> Note that the mmap lock is held to ensure a consistent tree state during the
> validation process.
>
> ...
>
> +++ b/mm/vma.c
> @@ -615,7 +615,10 @@ void validate_mm(struct mm_struct *mm)
> anon_vma_unlock_read(anon_vma);
> }
> #endif
> - i++;
> + if (++i > mm->map_count + 10) {
> + i = -1;
> + break;
> + }
> }
> if (i != mm->map_count) {
> pr_emerg("map_count %d vma iterator %d\n", mm->map_count, i);
It might be helpful to tell readers what's going on here?
--- a/mm/vma.c~vma-detect-infinite-loop-in-vma-tree-fix
+++ a/mm/vma.c
@@ -615,6 +615,7 @@ void validate_mm(struct mm_struct *mm)
anon_vma_unlock_read(anon_vma);
}
#endif
+ /* Check for a infinite loop */
if (++i > mm->map_count + 10) {
i = -1;
break;
_
^ permalink raw reply [flat|nested] 6+ messages in thread* Re: [PATCH v2] vma: Detect infinite loop in vma tree
2024-10-31 20:48 ` Andrew Morton
@ 2024-10-31 21:21 ` Liam R. Howlett
0 siblings, 0 replies; 6+ messages in thread
From: Liam R. Howlett @ 2024-10-31 21:21 UTC (permalink / raw)
To: Andrew Morton
Cc: linux-mm, linux-kernel, Lorenzo Stoakes, Vlastimil Babka, Jann Horn
* Andrew Morton <akpm@linux-foundation.org> [241031 16:48]:
> On Thu, 31 Oct 2024 15:36:08 -0400 "Liam R. Howlett" <Liam.Howlett@oracle.com> wrote:
>
> > From: "Liam R. Howlett" <Liam.Howlett@Oracle.com>
> >
> > There have been no reported infinite loops in the tree, but checking the
> > detection of an infinite loop during validation is simple enough. Add
> > the detection to the validate_mm() function so that error reports are
> > clear and don't just report stalls.
> >
> > This does not protect against internal maple tree issues, but it does
> > detect too many vmas being returned from the tree.
> >
> > The variance of +10 is to allow for the debugging output to be more useful for
> > nearly correct counts. In the event of more than 10 over the map_count, the
> > count will be set to -1 for easier identification of a potential infinite loop.
> >
> > Note that the mmap lock is held to ensure a consistent tree state during the
> > validation process.
> >
> > ...
> >
> > +++ b/mm/vma.c
> > @@ -615,7 +615,10 @@ void validate_mm(struct mm_struct *mm)
> > anon_vma_unlock_read(anon_vma);
> > }
> > #endif
> > - i++;
> > + if (++i > mm->map_count + 10) {
> > + i = -1;
> > + break;
> > + }
> > }
> > if (i != mm->map_count) {
> > pr_emerg("map_count %d vma iterator %d\n", mm->map_count, i);
>
> It might be helpful to tell readers what's going on here?
Sounds good. I guess I should have waited longer for a v2.
>
> --- a/mm/vma.c~vma-detect-infinite-loop-in-vma-tree-fix
> +++ a/mm/vma.c
> @@ -615,6 +615,7 @@ void validate_mm(struct mm_struct *mm)
> anon_vma_unlock_read(anon_vma);
> }
> #endif
> + /* Check for a infinite loop */
> if (++i > mm->map_count + 10) {
> i = -1;
> break;
> _
>
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v2] vma: Detect infinite loop in vma tree
2024-10-31 19:36 [PATCH v2] vma: Detect infinite loop in vma tree Liam R. Howlett
2024-10-31 20:48 ` Andrew Morton
@ 2024-10-31 21:42 ` David Hildenbrand
2024-10-31 21:44 ` Vlastimil Babka
2024-11-01 10:54 ` Lorenzo Stoakes
3 siblings, 0 replies; 6+ messages in thread
From: David Hildenbrand @ 2024-10-31 21:42 UTC (permalink / raw)
To: Liam R. Howlett, Andrew Morton
Cc: linux-mm, linux-kernel, Lorenzo Stoakes, Vlastimil Babka, Jann Horn
On 31.10.24 20:36, Liam R. Howlett wrote:
> From: "Liam R. Howlett" <Liam.Howlett@Oracle.com>
>
> There have been no reported infinite loops in the tree, but checking the
> detection of an infinite loop during validation is simple enough. Add
> the detection to the validate_mm() function so that error reports are
> clear and don't just report stalls.
>
> This does not protect against internal maple tree issues, but it does
> detect too many vmas being returned from the tree.
>
> The variance of +10 is to allow for the debugging output to be more useful for
> nearly correct counts. In the event of more than 10 over the map_count, the
> count will be set to -1 for easier identification of a potential infinite loop.
>
> Note that the mmap lock is held to ensure a consistent tree state during the
> validation process.
>
> Signed-off-by: Liam R. Howlett <Liam.Howlett@Oracle.com>
> Cc: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
> Cc: Vlastimil Babka <vbabka@suse.cz>
> Cc: Jann Horn <jannh@google.com>
> ---
> mm/vma.c | 5 ++++-
> 1 file changed, 4 insertions(+), 1 deletion(-)
>
> diff --git a/mm/vma.c b/mm/vma.c
> index 68138e8c153e..283e6bc4884f 100644
> --- a/mm/vma.c
> +++ b/mm/vma.c
> @@ -615,7 +615,10 @@ void validate_mm(struct mm_struct *mm)
> anon_vma_unlock_read(anon_vma);
> }
> #endif
> - i++;
> + if (++i > mm->map_count + 10) {
> + i = -1;
> + break;
> + }
> }
> if (i != mm->map_count) {
> pr_emerg("map_count %d vma iterator %d\n", mm->map_count, i);
Reviewed-by: David Hildenbrand <david@redhat.com>
--
Cheers,
David / dhildenb
^ permalink raw reply [flat|nested] 6+ messages in thread* Re: [PATCH v2] vma: Detect infinite loop in vma tree
2024-10-31 19:36 [PATCH v2] vma: Detect infinite loop in vma tree Liam R. Howlett
2024-10-31 20:48 ` Andrew Morton
2024-10-31 21:42 ` David Hildenbrand
@ 2024-10-31 21:44 ` Vlastimil Babka
2024-11-01 10:54 ` Lorenzo Stoakes
3 siblings, 0 replies; 6+ messages in thread
From: Vlastimil Babka @ 2024-10-31 21:44 UTC (permalink / raw)
To: Liam R. Howlett, Andrew Morton
Cc: linux-mm, linux-kernel, Lorenzo Stoakes, Jann Horn
On 10/31/24 20:36, Liam R. Howlett wrote:
> From: "Liam R. Howlett" <Liam.Howlett@Oracle.com>
>
> There have been no reported infinite loops in the tree, but checking the
> detection of an infinite loop during validation is simple enough. Add
> the detection to the validate_mm() function so that error reports are
> clear and don't just report stalls.
>
> This does not protect against internal maple tree issues, but it does
> detect too many vmas being returned from the tree.
>
> The variance of +10 is to allow for the debugging output to be more useful for
> nearly correct counts. In the event of more than 10 over the map_count, the
> count will be set to -1 for easier identification of a potential infinite loop.
>
> Note that the mmap lock is held to ensure a consistent tree state during the
> validation process.
>
> Signed-off-by: Liam R. Howlett <Liam.Howlett@Oracle.com>
> Cc: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
> Cc: Vlastimil Babka <vbabka@suse.cz>
> Cc: Jann Horn <jannh@google.com>
Reviewed-by: Vlastimil Babka <vbabka@suse.cz>
> ---
> mm/vma.c | 5 ++++-
> 1 file changed, 4 insertions(+), 1 deletion(-)
>
> diff --git a/mm/vma.c b/mm/vma.c
> index 68138e8c153e..283e6bc4884f 100644
> --- a/mm/vma.c
> +++ b/mm/vma.c
> @@ -615,7 +615,10 @@ void validate_mm(struct mm_struct *mm)
> anon_vma_unlock_read(anon_vma);
> }
> #endif
> - i++;
> + if (++i > mm->map_count + 10) {
> + i = -1;
> + break;
> + }
> }
> if (i != mm->map_count) {
> pr_emerg("map_count %d vma iterator %d\n", mm->map_count, i);
^ permalink raw reply [flat|nested] 6+ messages in thread* Re: [PATCH v2] vma: Detect infinite loop in vma tree
2024-10-31 19:36 [PATCH v2] vma: Detect infinite loop in vma tree Liam R. Howlett
` (2 preceding siblings ...)
2024-10-31 21:44 ` Vlastimil Babka
@ 2024-11-01 10:54 ` Lorenzo Stoakes
3 siblings, 0 replies; 6+ messages in thread
From: Lorenzo Stoakes @ 2024-11-01 10:54 UTC (permalink / raw)
To: Liam R. Howlett
Cc: Andrew Morton, linux-mm, linux-kernel, Vlastimil Babka, Jann Horn
On Thu, Oct 31, 2024 at 03:36:08PM -0400, Liam R. Howlett wrote:
> From: "Liam R. Howlett" <Liam.Howlett@Oracle.com>
>
> There have been no reported infinite loops in the tree, but checking the
> detection of an infinite loop during validation is simple enough. Add
> the detection to the validate_mm() function so that error reports are
> clear and don't just report stalls.
>
> This does not protect against internal maple tree issues, but it does
> detect too many vmas being returned from the tree.
>
> The variance of +10 is to allow for the debugging output to be more useful for
> nearly correct counts. In the event of more than 10 over the map_count, the
> count will be set to -1 for easier identification of a potential infinite loop.
>
> Note that the mmap lock is held to ensure a consistent tree state during the
> validation process.
>
> Signed-off-by: Liam R. Howlett <Liam.Howlett@Oracle.com>
Reviewed-by: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
> Cc: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
> Cc: Vlastimil Babka <vbabka@suse.cz>
> Cc: Jann Horn <jannh@google.com>
> ---
> mm/vma.c | 5 ++++-
> 1 file changed, 4 insertions(+), 1 deletion(-)
>
> diff --git a/mm/vma.c b/mm/vma.c
> index 68138e8c153e..283e6bc4884f 100644
> --- a/mm/vma.c
> +++ b/mm/vma.c
> @@ -615,7 +615,10 @@ void validate_mm(struct mm_struct *mm)
> anon_vma_unlock_read(anon_vma);
> }
> #endif
> - i++;
> + if (++i > mm->map_count + 10) {
> + i = -1;
> + break;
> + }
> }
> if (i != mm->map_count) {
> pr_emerg("map_count %d vma iterator %d\n", mm->map_count, i);
> --
> 2.43.0
>
^ permalink raw reply [flat|nested] 6+ messages in thread