From: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
To: linux-mm@kvack.org, linux-kernel@vger.kernel.org,
Andrew Morton <akpm@linux-foundation.org>
Cc: "Liam R . Howlett" <Liam.Howlett@oracle.com>,
Vlastimil Babka <vbabka@suse.cz>
Subject: Re: [PATCH v2 06/10] mm: avoid using vma_merge() for new VMAs
Date: Tue, 27 Aug 2024 12:41:00 +0100 [thread overview]
Message-ID: <c0ef6b6a-1c9b-4da2-a180-c8e1c73b1c28@lucifer.local> (raw)
In-Reply-To: <57f55a1473586a88211e04b44c6b128332d4272c.1724441678.git.lorenzo.stoakes@oracle.com>
On Fri, Aug 23, 2024 at 09:07:01PM GMT, Lorenzo Stoakes wrote:
[snip]
> void unlink_file_vma_batch_init(struct unlink_vma_file_batch *vb)
> @@ -1426,9 +1536,10 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
> struct vm_area_struct *vma = *vmap;
> unsigned long vma_start = vma->vm_start;
> struct mm_struct *mm = vma->vm_mm;
> - struct vm_area_struct *new_vma, *prev;
> + struct vm_area_struct *new_vma;
> bool faulted_in_anon_vma = true;
> VMA_ITERATOR(vmi, mm, addr);
> + VMG_VMA_STATE(vmg, &vmi, NULL, vma, addr, addr + len);
>
> /*
> * If anonymous vma has not yet been faulted, update new pgoff
> @@ -1439,11 +1550,18 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
> faulted_in_anon_vma = false;
> }
>
> - new_vma = find_vma_prev(mm, addr, &prev);
> + new_vma = find_vma_prev(mm, addr, &vmg.prev);
> if (new_vma && new_vma->vm_start < addr + len)
> return NULL; /* should never get here */
>
> - new_vma = vma_merge_new_vma(&vmi, prev, vma, addr, addr + len, pgoff);
> + vmg.vma = NULL; /* New VMA range. */
> + vmg.pgoff = pgoff;
> + vmg.next = vma_next(&vmi);
> + vma_prev(&vmi);
> + vma_iter_next_range(&vmi);
> +
> + new_vma = vma_merge_new_range(&vmg);
> +
> if (new_vma) {
> /*
> * Source vma may have been merged into new_vma
[snip]
Hi Andrew - could you squash the attached fix-patch into this please? As
there is an issue with a CONFIG_DEBUG_VM check firing when copy_vma()
unnecessarily moves the VMA iterator as reported at [0].
Thanks!
[0]: https://lore.kernel.org/linux-mm/202408271452.c842a71d-lkp@intel.com/
----8<----
From 53b41cc9ddfaf30f8a037f466686d942e0e64943 Mon Sep 17 00:00:00 2001
From: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
Date: Tue, 27 Aug 2024 11:59:27 +0100
Subject: [PATCH] mm: only advance iterator if prev exists
If we have no VMAs prior to us, such as in a case where we are mremap()'ing
a VMA backwards, then we will advance the iterator backwards to 0, before
moving to the original range again.
The intent is to position the iterator at or before the gap, therefore we
must avoid this - this is simply addressed by only advancing the iterator
should vma_prev() yield a result.
Reported-by: kernel test robot <oliver.sang@intel.com>
Closes: https://lore.kernel.org/oe-lkp/202408271452.c842a71d-lkp@intel.com
Signed-off-by: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
---
mm/vma.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/mm/vma.c b/mm/vma.c
index 8a5fa15f46a2..7d948edbbb9e 100644
--- a/mm/vma.c
+++ b/mm/vma.c
@@ -1557,8 +1557,8 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
vmg.vma = NULL; /* New VMA range. */
vmg.pgoff = pgoff;
vmg.next = vma_next(&vmi);
- vma_prev(&vmi);
- vma_iter_next_range(&vmi);
+ if (vma_prev(&vmi))
+ vma_iter_next_range(&vmi);
new_vma = vma_merge_new_range(&vmg);
--
2.46.0
next prev parent reply other threads:[~2024-08-27 11:41 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-08-23 20:06 [PATCH v2 00/10] mm: remove vma_merge() Lorenzo Stoakes
2024-08-23 20:06 ` [PATCH v2 01/10] tools: improve vma test Makefile Lorenzo Stoakes
2024-08-28 19:16 ` Liam R. Howlett
2024-08-23 20:06 ` [PATCH v2 02/10] tools: add VMA merge tests Lorenzo Stoakes
2024-08-28 19:16 ` Liam R. Howlett
2024-08-23 20:06 ` [PATCH v2 03/10] mm: introduce vma_merge_struct and abstract vma_merge(),vma_modify() Lorenzo Stoakes
2024-08-28 19:35 ` Liam R. Howlett
2024-08-30 13:28 ` Lorenzo Stoakes
2024-08-23 20:06 ` [PATCH v2 04/10] mm: remove duplicated open-coded VMA policy check Lorenzo Stoakes
2024-08-28 19:42 ` Liam R. Howlett
2024-08-23 20:07 ` [PATCH v2 05/10] mm: abstract vma_expand() to use vma_merge_struct Lorenzo Stoakes
2024-08-28 20:03 ` Liam R. Howlett
2024-08-23 20:07 ` [PATCH v2 06/10] mm: avoid using vma_merge() for new VMAs Lorenzo Stoakes
2024-08-27 11:41 ` Lorenzo Stoakes [this message]
2024-08-28 20:52 ` Liam R. Howlett
2024-08-30 15:19 ` Lorenzo Stoakes
2024-08-29 19:46 ` Mark Brown
2024-08-29 21:22 ` Lorenzo Stoakes
2024-08-30 12:59 ` Mark Brown
2024-08-30 13:02 ` Lorenzo Stoakes
2024-08-30 13:05 ` Mark Brown
2024-08-30 13:10 ` Lorenzo Stoakes
2024-08-23 20:07 ` [PATCH v2 07/10] mm: make vma_prepare() and friends static and internal to vma.c Lorenzo Stoakes
2024-08-23 20:07 ` [PATCH v2 08/10] mm: introduce commit_merge(), abstracting final commit of merge Lorenzo Stoakes
2024-08-23 20:07 ` [PATCH v2 09/10] mm: refactor vma_merge() into modify-only vma_merge_existing_range() Lorenzo Stoakes
2024-08-23 20:07 ` [PATCH v2 10/10] mm: rework vm_ops->close() handling on VMA merge Lorenzo Stoakes
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=c0ef6b6a-1c9b-4da2-a180-c8e1c73b1c28@lucifer.local \
--to=lorenzo.stoakes@oracle.com \
--cc=Liam.Howlett@oracle.com \
--cc=akpm@linux-foundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=vbabka@suse.cz \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox