From: Bert Karwatzki <spasswolf@web.de>
To: "Liam R . Howlett" <Liam.Howlett@oracle.com>
Cc: Bert Karwatzki <spasswolf@web.de>,
Suren Baghdasaryan <surenb@google.com>,
Vlastimil Babka <vbabka@suse.cz>,
Lorenzo Stoakes <lstoakes@gmail.com>,
Matthew Wilcox <willy@infradead.org>,
sidhartha.kumar@oracle.com,
"Paul E . McKenney" <paulmck@kernel.org>,
Jiri Olsa <olsajiri@gmail.com>,
linux-kernel@vger.kernel.org, linux-mm@kvack.org,
Andrew Morton <akpm@linux-foundation.org>,
Kees Cook <kees@kernel.org>, Jeff Xu <jeffxu@chromium.org>,
"Liam R . Howlett" <Liam.Howlett@Oracle.com>
Subject: [PATCH v5.1 10/19] mm/mmap: Support vma == NULL in init_vma_munmap()
Date: Fri, 16 Aug 2024 13:13:51 +0200 [thread overview]
Message-ID: <20240816111405.11793-11-spasswolf@web.de> (raw)
In-Reply-To: <20240816111405.11793-1-spasswolf@web.de>
Adding support for a NULL vma means the init_vma_munmap() can be
initialized for a less error-prone process when calling
vms_complete_munmap_vmas() later on.
Signed-off-by: Liam R. Howlett <Liam.Howlett@Oracle.com>
---
mm/mmap.c | 5 +----
mm/vma.c | 26 ++++++++++++++++----------
mm/vma.h | 14 ++++++++++++++
3 files changed, 31 insertions(+), 14 deletions(-)
diff --git a/mm/mmap.c b/mm/mmap.c
index 56d0aaff8478..16fd14b243f9 100644
--- a/mm/mmap.c
+++ b/mm/mmap.c
@@ -1395,16 +1395,13 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
if (unlikely(!can_modify_mm(mm, addr, end)))
return -EPERM;
- /* arch_unmap() might do unmaps itself. */
- arch_unmap(mm, addr, end);
-
/* Find the first overlapping VMA */
vma = vma_find(&vmi, end);
+ init_vma_munmap(&vms, &vmi, vma, addr, end, uf, /* unlock = */ false);
if (vma) {
mt_init_flags(&mt_detach, vmi.mas.tree->ma_flags & MT_FLAGS_LOCK_MASK);
mt_on_stack(mt_detach);
mas_init(&mas_detach, &mt_detach, /* addr = */ 0);
- init_vma_munmap(&vms, &vmi, vma, addr, end, uf, /* unlock = */ false);
/* Prepare to unmap any existing mapping in the area */
if (vms_gather_munmap_vmas(&vms, &mas_detach))
return -ENOMEM;
diff --git a/mm/vma.c b/mm/vma.c
index e4677364082b..a5ca42b7161b 100644
--- a/mm/vma.c
+++ b/mm/vma.c
@@ -352,16 +352,22 @@ static void __vma_link_file(struct vm_area_struct *vma,
* @uf: The userfaultfd list_head
* @unlock: Unlock after the operation. Only unlocked on success
*/
-static inline void init_vma_munmap(struct vma_munmap_struct *vms,
+void
+init_vma_munmap(struct vma_munmap_struct *vms,
struct vma_iterator *vmi, struct vm_area_struct *vma,
- unsigned long start, unsigned long end, struct list_head *uf,
- bool unlock)
+ unsigned long start, unsigned long end,
+ struct list_head *uf, bool unlock)
{
vms->vmi = vmi;
vms->vma = vma;
- vms->mm = vma->vm_mm;
- vms->start = start;
- vms->end = end;
+ if (vma) {
+ vms->mm = vma->vm_mm;
+ vms->start = start;
+ vms->end = end;
+ } else {
+ vms->mm = NULL;
+ vms->start = vms->end = 0;
+ }
vms->unlock = unlock;
vms->uf = uf;
vms->vma_count = 0;
@@ -699,8 +705,8 @@ static inline void abort_munmap_vmas(struct ma_state *mas_detach)
* needed to be done once the vma maple tree is updated.
*/
-static void vms_complete_munmap_vmas(struct vma_munmap_struct *vms,
- struct ma_state *mas_detach)
+void vms_complete_munmap_vmas(struct vma_munmap_struct *vms,
+ struct ma_state *mas_detach)
{
struct vm_area_struct *vma;
struct mm_struct *mm;
@@ -748,8 +754,8 @@ static void vms_complete_munmap_vmas(struct vma_munmap_struct *vms,
*
* Return: 0 on success
*/
-static int vms_gather_munmap_vmas(struct vma_munmap_struct *vms,
- struct ma_state *mas_detach)
+int vms_gather_munmap_vmas(struct vma_munmap_struct *vms,
+ struct ma_state *mas_detach)
{
struct vm_area_struct *next = NULL;
int error = -ENOMEM;
diff --git a/mm/vma.h b/mm/vma.h
index 7ba0d71b50ca..8b2401f93c74 100644
--- a/mm/vma.h
+++ b/mm/vma.h
@@ -63,6 +63,12 @@ void anon_vma_interval_tree_post_update_vma(struct vm_area_struct *vma);
/* Required for do_brk_flags(). */
void vma_prepare(struct vma_prepare *vp);
+/* Required for mmap_region() */
+void init_vma_munmap(struct vma_munmap_struct *vms,
+ struct vma_iterator *vmi, struct vm_area_struct *vma,
+ unsigned long start, unsigned long end,
+ struct list_head *uf, bool unlock);
+
/* Required for do_brk_flags(). */
void init_vma_prep(struct vma_prepare *vp,
struct vm_area_struct *vma);
@@ -78,6 +84,14 @@ int vma_expand(struct vma_iterator *vmi, struct vm_area_struct *vma,
int vma_shrink(struct vma_iterator *vmi, struct vm_area_struct *vma,
unsigned long start, unsigned long end, pgoff_t pgoff);
+/* Required for mmap_region() */
+void vms_complete_munmap_vmas(struct vma_munmap_struct *vms,
+ struct ma_state *mas_detach);
+
+/* Required for mmap_region() */
+int vms_gather_munmap_vmas(struct vma_munmap_struct *vms,
+ struct ma_state *mas_detach);
+
int
do_vmi_align_munmap(struct vma_iterator *vmi, struct vm_area_struct *vma,
struct mm_struct *mm, unsigned long start,
--
2.45.2
next prev parent reply other threads:[~2024-08-16 11:14 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-08-16 11:13 [PATCH v5.1 00/19] Rebase v5 patchset to next-20240816 Bert Karwatzki
2024-08-16 11:13 ` [PATCH v5.1 01/19] mm/mmap: Correctly position vma_iterator in __split_vma() Bert Karwatzki
2024-08-16 11:13 ` [PATCH v5.1 02/19] mm/mmap: Introduce abort_munmap_vmas() Bert Karwatzki
2024-08-16 11:13 ` [PATCH v5.1 03/19] mm/mmap: Introduce vmi_complete_munmap_vmas() Bert Karwatzki
2024-08-16 11:13 ` [PATCH v5.1 04/19] mm/mmap: Extract the gathering of vmas from do_vmi_align_munmap() Bert Karwatzki
2024-08-16 11:13 ` [PATCH v5.1 05/19] mm/mmap: Introduce vma_munmap_struct for use in munmap operations Bert Karwatzki
2024-08-16 11:13 ` [PATCH v5.1 06/19] mm/mmap: Change munmap to use vma_munmap_struct() for accounting and surrounding vmas Bert Karwatzki
2024-08-16 11:13 ` [PATCH v5.1 07/19] mm/mmap: Extract validate_mm() from vma_complete() Bert Karwatzki
2024-08-16 11:13 ` [PATCH v5.1 08/19] mm/mmap: Inline munmap operation in mmap_region() Bert Karwatzki
2024-08-16 11:13 ` [PATCH v5.1 09/19] mm/mmap: Expand mmap_region() munmap call Bert Karwatzki
2024-08-16 11:13 ` Bert Karwatzki [this message]
2024-08-16 11:13 ` [PATCH v5.1 11/19] mm/mmap: Reposition vma iterator in mmap_region() Bert Karwatzki
2024-08-16 11:13 ` [PATCH v5.1 12/19] mm/mmap: Track start and end of munmap in vma_munmap_struct Bert Karwatzki
2024-08-16 11:13 ` [PATCH v5.1 13/19] mm/mmap: Clean up unmap_region() argument list Bert Karwatzki
2024-08-16 11:13 ` [PATCH v5.1 14/19] mm/mmap: Avoid zeroing vma tree in mmap_region() Bert Karwatzki
2024-08-16 11:13 ` [PATCH v5.1 15/19] mm/mmap: Use PHYS_PFN " Bert Karwatzki
2024-08-16 11:33 ` [PATCH v5.1 00/19] Rebase v5 patchset to next-20240816 Lorenzo Stoakes
2024-08-16 11:55 ` Bert Karwatzki
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=20240816111405.11793-11-spasswolf@web.de \
--to=spasswolf@web.de \
--cc=Liam.Howlett@oracle.com \
--cc=akpm@linux-foundation.org \
--cc=jeffxu@chromium.org \
--cc=kees@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=lstoakes@gmail.com \
--cc=olsajiri@gmail.com \
--cc=paulmck@kernel.org \
--cc=sidhartha.kumar@oracle.com \
--cc=surenb@google.com \
--cc=vbabka@suse.cz \
--cc=willy@infradead.org \
/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