From patchwork Fri Aug 16 16:10:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bert Karwatzki X-Patchwork-Id: 13766577 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 64826C531DC for ; Fri, 16 Aug 2024 16:10:35 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E5E7F6B034A; Fri, 16 Aug 2024 12:10:34 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E0D906B0365; Fri, 16 Aug 2024 12:10:34 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C883E6B0367; Fri, 16 Aug 2024 12:10:34 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id A6A776B034A for ; Fri, 16 Aug 2024 12:10:34 -0400 (EDT) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 224B1140130 for ; Fri, 16 Aug 2024 16:10:34 +0000 (UTC) X-FDA: 82458596388.16.C589601 Received: from mout.web.de (mout.web.de [212.227.15.4]) by imf06.hostedemail.com (Postfix) with ESMTP id 3761C180017 for ; Fri, 16 Aug 2024 16:10:31 +0000 (UTC) Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=web.de header.s=s29768273 header.b=qZjuni5L; dmarc=pass (policy=quarantine) header.from=web.de; spf=pass (imf06.hostedemail.com: domain of spasswolf@web.de designates 212.227.15.4 as permitted sender) smtp.mailfrom=spasswolf@web.de ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1723824572; a=rsa-sha256; cv=none; b=swKL0hWeGiZYkhD0npXlQ+9RF/81G1qu+G84dY6QccaqVBG6qq3fz4ozzw43dyKrzcODnK reuY40Yn2sUGY7WwxudmhD4HsrD+LNtOzDpO2xqjV50YN4lvXFn308Okyrh2s8G/BID2La lL8TjNP7pXx41FCsrB1TV7nlx+Od3zo= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=pass header.d=web.de header.s=s29768273 header.b=qZjuni5L; dmarc=pass (policy=quarantine) header.from=web.de; spf=pass (imf06.hostedemail.com: domain of spasswolf@web.de designates 212.227.15.4 as permitted sender) smtp.mailfrom=spasswolf@web.de ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1723824572; 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:references:dkim-signature; bh=AqH8ZahU0Ew/z25cFE4au3x3zvZRx/o0pPBf330Utj0=; b=Hw7Ua3YwKsNCVgP7wGQMgdNnebCRdGTuRHyjpON36g7nc9ZYF+NCJ6SLM9FustmfpxC/ax zjODkgS47IzAp7Vxw6QeDzUx9fvCJmHN+K+/KRmRnxlsJdE1ZolyGbqGwsbwwwRSFH+jxs /XZCFFkfy4F5pkKvtfYwLhAHOprPitw= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=web.de; s=s29768273; t=1723824624; x=1724429424; i=spasswolf@web.de; bh=AqH8ZahU0Ew/z25cFE4au3x3zvZRx/o0pPBf330Utj0=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:Message-ID: MIME-Version:Content-Transfer-Encoding:cc: content-transfer-encoding:content-type:date:from:message-id: mime-version:reply-to:subject:to; b=qZjuni5LCs4oYuVCZusa6gqTmhASB26+km+807lc16rRQCXxjNmVnGenGI353vWZ YUaFhqmZxlGsp9npjX3QqYw/U1u8tPFj33qXVOaffgyanCdqmipDqeRa7x6iGXHKV O9IwLuk8F6hnFzqM4rwY2T8yoLwZsZpJJv3U3zRNf7Ly2l7R27497HXNRSy8vDu2s DjUrlK0mHhGSggk2WKCVba7PUKnW7JlFVqfQrEH66pZDzriYX95lJF4+w5mlSDEA7 g2jywPtKZRB24Jkap7rpYFsXZmbEvy1ifI8I4UYV7Kyt7i7lwxvM6sIfp4ORqH577 qKHlkvP2kbmKJRzddA== X-UI-Sender-Class: 814a7b36-bfc1-4dae-8640-3722d8ec6cd6 Received: from localhost.localdomain ([84.119.92.193]) by smtp.web.de (mrweb006 [213.165.67.108]) with ESMTPSA (Nemesis) id 1MKuKH-1sswPS2QWr-00Lcmp; Fri, 16 Aug 2024 18:10:23 +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 18/19] ipc/shm, mm: Drop do_vma_munmap() Date: Fri, 16 Aug 2024 18:10:19 +0200 Message-ID: <20240816161020.2845-1-spasswolf@web.de> X-Mailer: git-send-email 2.45.2 MIME-Version: 1.0 X-Provags-ID: V03:K1:pG5/9OccDc0jmknnLiMC90N3TcGHFcL+ezavX79zPFVjOUla0KP 8ZdVhdU/iTbUmFt/RfpHAzG2yCA9a4ZiOpoksJz7cBSVm85f3uHKhKAIaRorQspNBFnzeGm bDzqstp3/21sQy5rU4iBk8fZQbv3hyPxbSvdW25SfKghV/VOT4cFF9eUMZPkEeieMrujo6j v/eoITaqZ+PtCqam4e0Rw== UI-OutboundReport: notjunk:1;M01:P0:eYlzR9waZA8=;X2ciPsgPNvjP5nI2TnpdJPGQpTl ZGbpSOwDaVm5k/sSYOr2VTEIHeTvCjtWQ2bvND3mBcq4ssJ4Be+fMKt1Z4bB4RiT2RM4RfsZV BuyBUSKFYD47YkkHMm6TqgHiwrQZAEVb8QQXnYl534UVjW4WC09jHMSJVKt6cgaCu6n/jJf9/ FWa0xEThkn8DjzmmMKgqR8yXouWYgP7O6YToci1pn/Zyimqf6JcN8vzVs8jOKPDFJdw0bUJjX 63JiWjWs778Ybdm5x1QJupMw0hYyxAzNbctfeH3rDNuuk/0qTAuF2NMBNnPfl21lF/0UUvUd6 xewZ8FhVtfAr/A6lUPAS4FAepYzao8RKRaNoYwjQ4eUx+sPj/DQRLr0Q0ZPVNPPKlvSkLWyGa o5gtJLqgMr4sSc3SArDITKaGf2N3fbEom82k4iK8q9ILREJVeijK3Mwgmsj8KOh/u2NXOTnWh 1G6gJg2RZJZhaINrW5tAn2dLjepplmhCGNdDeSI2XIaZCZZ1lO4JAydRwJ39x9GTME6mpPQtj TyFnRYi2Kwf52MKLCLpOWm9eJQ326jKjXQfCUZknw1+IP7meLbuTWxKzdZRd5p7kzfIhTDpkB /ZrViptLTW5MuilUD4Z1nNGGeVckAvz7nUiKAMN3WZmIrj3cQ7GeKz9uAzIPltCyTK0hBaTPW oIusx3li8L3Dl2ReYZdSAzjDx1t37H2jET/faXZ3xrH7gRe3DbcrC8xMAlQskJseQD6D4JoZI DlftLjMzMoH43BGtPbki3ST2Ip5yC281Uy16uPt2qM2kp6eYq7/dBTidKNMBsUxbJvRejE+5+ nGPF7cZj2glANQ3dcMJAzDHg== X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 3761C180017 X-Stat-Signature: t9g4d3pmxfdic5ehatbiwnai988ctc9k X-Rspam-User: X-HE-Tag: 1723824631-751125 X-HE-Meta: U2FsdGVkX18AYCXDH/q2nsUJFooFDioFbsR1kozi+feDtxV6ODhSHUUgYKi2DOP5opJgFIJkeUWAE+/U99CWFXmZUmuEzdDNY79vVD3prbaKXubAiKgROBZ8KqtvLw5SEmxJ1P6WeZ3I9eubJiWjvexu2SjphgTM3KVecZWP3LPmpD6LTvksY4TN2ZxW/1T5IuUXki/f5n8eJIKItgHcOkH39zxJB3t7E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4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: The do_vma_munmap() wrapper existed for callers that didn't have a vma iterator and needed to check the vma mseal status prior to calling the underlying munmap(). All callers now use a vma iterator and since the mseal check of can_modify_mm() has been moved to do_vmi_align_munmap() and the vmas are aligned, this function can just be called instead. do_vmi_align_munmap() can no longer be static as ipc/shm is using it and it is exported via the mm.h header. Signed-off-by: Liam R. Howlett --- include/linux/mm.h | 6 +++--- ipc/shm.c | 8 ++++---- mm/mmap.c | 31 ++++--------------------------- 3 files changed, 11 insertions(+), 34 deletions(-) -- 2.45.2 diff --git a/include/linux/mm.h b/include/linux/mm.h index 653287396808..2dccdc7ba09a 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -3292,14 +3292,14 @@ extern unsigned long do_mmap(struct file *file, unsigned long addr, extern int do_vmi_munmap(struct vma_iterator *vmi, struct mm_struct *mm, unsigned long start, size_t len, struct list_head *uf, bool unlock); +extern int do_vmi_align_munmap(struct vma_iterator *vmi, struct vm_area_struct *vma, + struct mm_struct *mm, unsigned long start, + unsigned long end, struct list_head *uf, bool unlock); extern int do_munmap(struct mm_struct *, unsigned long, size_t, struct list_head *uf); extern int do_madvise(struct mm_struct *mm, unsigned long start, size_t len_in, int behavior); #ifdef CONFIG_MMU -extern int do_vma_munmap(struct vma_iterator *vmi, struct vm_area_struct *vma, - unsigned long start, unsigned long end, - struct list_head *uf, bool unlock); extern int __mm_populate(unsigned long addr, unsigned long len, int ignore_errors); static inline void mm_populate(unsigned long addr, unsigned long len) diff --git a/ipc/shm.c b/ipc/shm.c index 3e3071252dac..99564c870084 100644 --- a/ipc/shm.c +++ b/ipc/shm.c @@ -1778,8 +1778,8 @@ long ksys_shmdt(char __user *shmaddr) */ file = vma->vm_file; size = i_size_read(file_inode(vma->vm_file)); - do_vma_munmap(&vmi, vma, vma->vm_start, vma->vm_end, - NULL, false); + do_vmi_align_munmap(&vmi, vma, mm, vma->vm_start, + vma->vm_end, NULL, false); /* * We discovered the size of the shm segment, so * break out of here and fall through to the next @@ -1803,8 +1803,8 @@ long ksys_shmdt(char __user *shmaddr) if ((vma->vm_ops == &shm_vm_ops) && ((vma->vm_start - addr)/PAGE_SIZE == vma->vm_pgoff) && (vma->vm_file == file)) { - do_vma_munmap(&vmi, vma, vma->vm_start, vma->vm_end, - NULL, false); + do_vmi_align_munmap(&vmi, vma, mm, vma->vm_start, + vma->vm_end, NULL, false); } vma = vma_next(&vmi); diff --git a/mm/mmap.c b/mm/mmap.c index ae74d0674b6d..d2f47cd66650 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -169,11 +169,12 @@ SYSCALL_DEFINE1(brk, unsigned long, brk) goto out; /* mapping intersects with an existing non-brk vma. */ /* * mm->brk must be protected by write mmap_lock. - * do_vma_munmap() will drop the lock on success, so update it - * before calling do_vma_munmap(). + * do_vmi_align_munmap() will drop the lock on success, so + * update it before calling do_vma_munmap(). */ mm->brk = brk; - if (do_vma_munmap(&vmi, brkvma, newbrk, oldbrk, &uf, true)) + if (do_vmi_align_munmap(&vmi, brkvma, mm, newbrk, oldbrk, &uf, + /* unlock = */ true)) goto out; goto success_unlocked; @@ -1747,30 +1748,6 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size, return ret; } -/* - * do_vma_munmap() - Unmap a full or partial vma. - * @vmi: The vma iterator pointing at the vma - * @vma: The first vma to be munmapped - * @start: the start of the address to unmap - * @end: The end of the address to unmap - * @uf: The userfaultfd list_head - * @unlock: Drop the lock on success - * - * unmaps a VMA mapping when the vma iterator is already in position. - * Does not handle alignment. - * - * Return: 0 on success drops the lock of so directed, error on failure and will - * still hold the lock. - */ -int do_vma_munmap(struct vma_iterator *vmi, struct vm_area_struct *vma, - unsigned long start, unsigned long end, struct list_head *uf, - bool unlock) -{ - struct mm_struct *mm = vma->vm_mm; - - return do_vmi_align_munmap(vmi, vma, mm, start, end, uf, unlock); -} - /* * do_brk_flags() - Increase the brk vma if the flags match. * @vmi: The vma iterator