From patchwork Fri Aug 16 11:13:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bert Karwatzki X-Patchwork-Id: 13766006 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 830EDC531DC for ; Fri, 16 Aug 2024 11:14:54 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id EB2BF6B016B; Fri, 16 Aug 2024 07:14:40 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E3B7F6B016D; Fri, 16 Aug 2024 07:14:40 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C3DB26B016E; Fri, 16 Aug 2024 07:14:40 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 9E8D56B016B for ; Fri, 16 Aug 2024 07:14:40 -0400 (EDT) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 0F912161AD3 for ; Fri, 16 Aug 2024 11:14:40 +0000 (UTC) X-FDA: 82457850720.15.AB9B981 Received: from mout.web.de (mout.web.de [212.227.17.12]) by imf06.hostedemail.com (Postfix) with ESMTP id 16165180025 for ; Fri, 16 Aug 2024 11:14:37 +0000 (UTC) Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=web.de header.s=s29768273 header.b=KTIUKbqw; spf=pass (imf06.hostedemail.com: domain of spasswolf@web.de designates 212.227.17.12 as permitted sender) smtp.mailfrom=spasswolf@web.de; dmarc=pass (policy=quarantine) header.from=web.de ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1723806841; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=HVP/JBjkTr9Kn9Gb734inJ0oeOamhPQyJTNaGFebizI=; b=4EvCGwcwqf+Cok8L/TkiE9oXEtYEyfFoxpgEJ3nr7vPxafSiiY137dmoXpmoVUthjlUV8Y LdHqmR7rAySHciDgRJk6MPjhOGie8SxC1q8UX/WUJm43lL0QdaOAra2sHiXWrSzv9iGfRP ImTNVs5EyVK1YPpWI5m9zueBmiNrfzs= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=pass header.d=web.de header.s=s29768273 header.b=KTIUKbqw; spf=pass (imf06.hostedemail.com: domain of spasswolf@web.de designates 212.227.17.12 as permitted sender) smtp.mailfrom=spasswolf@web.de; dmarc=pass (policy=quarantine) header.from=web.de ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1723806841; a=rsa-sha256; cv=none; b=CDmyp2B5UiiEcAjjcwaMzOrVGtBby14l1RtSP2UHxpsywcyswSoqcKnPkUjQ0/G6D6XTcB WnTXiYJ8xJhmGYE0xFKqneL4aoAevLbM93Ipv7WRWD2VpuQ1nGALoi5WPJoEBEnjquweVe mihiQO/03wc0jGQJjfjK+kGOhbgEPos= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=web.de; s=s29768273; t=1723806871; x=1724411671; i=spasswolf@web.de; bh=HVP/JBjkTr9Kn9Gb734inJ0oeOamhPQyJTNaGFebizI=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:Message-ID:In-Reply-To: References:MIME-Version:Content-Transfer-Encoding:cc: content-transfer-encoding:content-type:date:from:message-id: mime-version:reply-to:subject:to; b=KTIUKbqwITLr7s3ozUruWYzgNjxVdUriID/MyHfuFupfMx1YVebgTrsoY6dLeq4k OCX4U0zKfvsNLGQ2rJP6QltSstQ4NWtGZDfAKWXLD2ijVPhz8Yp2tra+fh/bcmR2n SjaW5PxmbincXKXI0CjAIu5AtU5OnD8AguuHy1Z5su4mPKm1xJhkTti85JcoImI8P OtsenG7/TEDcbiT1qZ1S3Mfnk4V5i71ho+DHjWSuihffRlXUHtAG+hb4PoXSQvw9v aCGctUAkjVwayc8ySZmsLWTfdMtNFdNrGCWX9u4BPOncDeXhRn5a8gE6lkUBdVKBE WH61SGftsH7BwAzUCQ== X-UI-Sender-Class: 814a7b36-bfc1-4dae-8640-3722d8ec6cd6 Received: from localhost.localdomain ([84.119.92.193]) by smtp.web.de (mrweb106 [213.165.67.124]) with ESMTPSA (Nemesis) id 1MYcll-1siVpl3UGp-00KwGf; Fri, 16 Aug 2024 13:14:30 +0200 From: Bert Karwatzki To: "Liam R . Howlett" Cc: Bert Karwatzki , Suren Baghdasaryan , Vlastimil Babka , Lorenzo Stoakes , Matthew Wilcox , sidhartha.kumar@oracle.com, "Paul E . McKenney" , Jiri Olsa , linux-kernel@vger.kernel.org, linux-mm@kvack.org, Andrew Morton , Kees Cook , Jeff Xu , "Liam R . Howlett" Subject: [PATCH v5.1 10/19] mm/mmap: Support vma == NULL in init_vma_munmap() Date: Fri, 16 Aug 2024 13:13:51 +0200 Message-ID: <20240816111405.11793-11-spasswolf@web.de> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240816111405.11793-1-spasswolf@web.de> References: <20240816111405.11793-1-spasswolf@web.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:q6+PZLLMAQhWGIUUnFe+NK15H6pxq8ferPSFmbhVruB+Iqj34vi Vvig817bDMFiALU3jtN/o0wRK0UO1X5QqtBSqp+Iqio8LXi6y3r/oDwXXq3gx2BsHCnuh14 AH3rPst1zjnX+pOpVIkFQyAJwYAevi5S5yMmDiVojj2gHzh4HsT4BPDOqoGBXjYpzvjLcfN uEY1Eo3o4fHIWymmZivMQ== UI-OutboundReport: notjunk:1;M01:P0:tkq2ZyJLUUs=;NDKjhBHZLAb57n0MPvbpI3x+bmC GlJwSGtGlSmhH+wk8dboCb737ZESaJU11qZazsPwQL02aDo2gj6uoNqASE2fd5Q7qYBx/3fBX YYVZVL5dxrBbOTJ/4XNwWisEA7uQWpRyealJgCEabYWKQzQurC7FbEnZbebt0Kdms+zkl6Iq6 tIMVtVbvp2jweIlYej6fNdhJSRvYO4lWDsrsd11PzyqmnDj8gfG+48zGHIyf5GrI0SuCjp/Qa F4aVFJ6YderwAViV6tmOe4QyK2oNj8VD0sUZqG/d3cghCfHpWd9WZVpy2g+XiEVnyLG6AkMG/ tUGtex19WbBY4HH3Pjw3sJ3g18amYEJq3pa8X9L0z9FzIfGC6WK1WaYGSzKzcBM67lWcFcDNI UszMkBaaoIMk3gF/UEzGCa/5MTER4p6Q5O5EKovTzO2yWUz/jk4YizFGWVWmCL6elTISGSitw kijhC8P8STWE/Rq4s1ppo25ongtBW0trP+X/7fjfyhMORookvTg2j75x6F0U5ZNmxVgzctu/j YF/cmkuWSFIlxrGcmocR+F6cEDhKAdBtXJ2uY1sFCULoIxCWYHw4lrYS4vEa6hfXzBfp6AvnP lgLu4Bfzv00BwoOzmSFrotPuAvD0R2wSDBkmiN+hhdOmGdhXJU4jV+Tn0Ixw2nl4ujSDEbWxu 6TYA/k45Yzzhm/ZlTAV9D3iTZQ7UPO5NU8gplaNOMwxi049jiXn8hdgPdBU+2pjmw64od2Hb1 kOwOh1+f5JSo2mjBbkG7y5C07ptNIhZZphDvohTC3/fqdGt6GThMcac4JY/5eUyzwufcaDATp AF5Uqn0euHQj/wPWzjny+q/Q== X-Rspamd-Server: rspam03 X-Rspam-User: X-Rspamd-Queue-Id: 16165180025 X-Stat-Signature: 34gbw5j9eyt9r94tbrhpgb1n1dukmg71 X-HE-Tag: 1723806877-379285 X-HE-Meta: U2FsdGVkX1/Ygq9aiGF6c1A0JbwwZlqqiXIQjiExf4KIyhdtSbA5SrNNvx28MLeYrXs/0Oigfv+3Byq2lV2NF44UB2ExhGzwktqNJbaU3ddzMC4yyusTgW9ypBH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NW+ix5cdmmLEm8bshYfSl7dBbI3bcQGLK4UiB1qCkr8y6wLdbyTtuJdp44PGs6udvx4AuufzzSjbFEuyRtk/srumDAiO6rFJ6qbEe0 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: 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 --- mm/mmap.c | 5 +---- mm/vma.c | 26 ++++++++++++++++---------- mm/vma.h | 14 ++++++++++++++ 3 files changed, 31 insertions(+), 14 deletions(-) -- 2.45.2 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,