From patchwork Fri Aug 16 11:13:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bert Karwatzki X-Patchwork-Id: 13766005 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 7D2BAC531DE for ; Fri, 16 Aug 2024 11:14:51 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C8D926B0167; Fri, 16 Aug 2024 07:14:39 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id BEEF06B0169; Fri, 16 Aug 2024 07:14:39 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A42AD6B016B; Fri, 16 Aug 2024 07:14:39 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 77FD86B0167 for ; Fri, 16 Aug 2024 07:14:39 -0400 (EDT) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 3275EA9440 for ; Fri, 16 Aug 2024 11:14:39 +0000 (UTC) X-FDA: 82457850678.16.F2F9471 Received: from mout.web.de (mout.web.de [212.227.17.11]) by imf07.hostedemail.com (Postfix) with ESMTP id 426654001B for ; Fri, 16 Aug 2024 11:14:37 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=web.de header.s=s29768273 header.b=BNZQMBdl; spf=pass (imf07.hostedemail.com: domain of spasswolf@web.de designates 212.227.17.11 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=1723806840; 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=q0h6rMe/QGaT++JPp5Z3rkGRpCNRbqXYhv4xZ4c2KKA=; b=4WzoNQpI07tFYWhy6J79PJJ8PEekAS5GF5uIQi6DJMOiHPiN9NsqsaH1Q3JEVEVweGZIIV MLodzWXTAU5+oOIXLQAaEAk5NYy+AmJQaNIz/gAQI3bQn+M9fj8/k1uKfSHnmxoHNnEu1T BHLBITVZzE1s4IZYhssNohWHX3fgVYM= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=pass header.d=web.de header.s=s29768273 header.b=BNZQMBdl; spf=pass (imf07.hostedemail.com: domain of spasswolf@web.de designates 212.227.17.11 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=1723806840; a=rsa-sha256; cv=none; b=nqJo2ow3PzE7m3aTZNMGl3dPG1eBh8SrfVDl3TOqb5yf74oadymG0Oe6Mdg1yLGXrVYjnR ivGqM7KlUNzHQYLVNC2qm9eEmUpxB5H1Beu6CJ2G5AvcTnSks0DtLU5J+j1mHwWDp0DeNw Ztxx5hZIUgr58wM8MTi6b61JjyrdMk0= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=web.de; s=s29768273; t=1723806870; x=1724411670; i=spasswolf@web.de; bh=q0h6rMe/QGaT++JPp5Z3rkGRpCNRbqXYhv4xZ4c2KKA=; 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=BNZQMBdltYarlRDfr9l+xhmEOPgu9dPnz1Vy9AwBEuxr8kVyy5YMCQ/XXZ/sjkBp PL25ghqtjvKhQqHM80zU1tHv8j1h5eFoeEAByPSoy+pFfzXDQQnpVjIv7yk3d178B tnzjVme3+aY4X6TXNq6XFO4IKvTxM17KYhJnEdJU/6rJ1W8DtqVq9CErAIZUWrkY6 4qqHSmHCSds6Dv0YzEn5qN1LXOUVEA3dtdyZ8hB9A48pTtAhzvy59rB0R1K0iwpS1 KihTCbL98EqYRU3IkBUkB302Ng7HaTn378t240WUYkw2KXLII7EAI+dmiWtBr+0rA v9QJU+x3DP7ceUSeDA== 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 1N62yY-1s859h3aUy-00suJG; Fri, 16 Aug 2024 13:14:29 +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" , Lorenzo Stoakes Subject: [PATCH v5.1 09/19] mm/mmap: Expand mmap_region() munmap call Date: Fri, 16 Aug 2024 13:13:50 +0200 Message-ID: <20240816111405.11793-10-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:3fFxHOvIpxuFtPf29BwBcYr+yqtYehqzJgvJRmGLNR5rOdc3yPh GnhJ5knCS7QqrGbxM4+N3sB1dK0m3tOiqQNX/oZaSkeGkyW2goQaQFwguClg7nXkljAuNrv VLOtsAsKtAbCw7uxsSOSChzIRpt92HTrS9e5onFPgvYbwKfjn19554eeeuPzWfd88tq5kSm 9afxwJHMcns5e3+Mm28rg== UI-OutboundReport: notjunk:1;M01:P0:tp495Uzsi2o=;GLD5Dcf/qUytGv/C6v/BITps8Us +roeUFaZ/z5RrHebMmZgfH+F8xHoZymY5ZqBlzcK1zjLUAuSZKY9+YVXq6QZsZpL7YisgJsEQ T5uRQaXAu3JnIdsvEx/up1cmL2khi0SOKpd+BBnXH16QOviyk91OZRIDm83WyP8kHPMZFqmmn rACVD0h7cWN4wy7NabEwIzIUI2D5J6K6ClK0ezWIlAz5UJFKDiWeYt0+YPP5ENQ8fsac9qOhj eEDiM+rmzmq24stZhvKp5hNB/iDLB/MLiYyjJRt4kcFi8FMW5eJL2nYvjs/WcyltmTIEnCKdV 1NrcqJyMkNUv1j3nXE15+6ZhrpbXpPPWRCrHxgS2l44r9EuYNCLYGj+rpOlnSBXqA1wgn63mm VIybrgzIGm1aMSgWFZ2yWTMeOznnGw2CtJC5VpJEFzX5EjEv+S1uiPlFHV+t9qURZsbtNn/kP OU+8G8zCPSNtaWzKhupwevc9+ljHktVJQG+4959tVHWgBJ6s+H3R8bDnL02KLvFTwrWQyGzAS fu5blI2j0srPMH5Hsep15VQNDxr7aCXHNOSwImB6aVusBvQRTEdsqRaAjPgONh+lshC8EmoeE Asgvcc3fn2NaLcfRr5Yzm8f4Fnha7+mUCvvqgbbCstRSCIdYSC/hEoqiCTW6uFjWgCcwirBVV nrq+BKyLIcuSiD7HLz8mZUAhJ97o2PNUJZF25BCTLdlYVN/sFWp3VGJktPvYlt/qRmoVmJo5V M7zNdEK7sBfw22z6iWfW/Ij6AwKssGFzwa3GGXM+8VA9SSGGpWk5nRl9FBVlj8YXBamJQVP5C PxfzF1Llmai/300S+RI/2QNA== X-Rspamd-Server: rspam03 X-Rspam-User: X-Rspamd-Queue-Id: 426654001B X-Stat-Signature: hfazscw13aow77k9a9gzaxcg4yy5swn3 X-HE-Tag: 1723806877-491331 X-HE-Meta: U2FsdGVkX1+JHruSn9tpg9ERseZxib07P4OgLUkj+vNpY6ligQouAaMJANcffNo/SgcxWBrDOzG7gmd5F9FfhVz74AY+GFjYWlkooxXKq9osN9m9uPM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kwI+v3VbGRt/aDQ39c5PLa0r1e4HKNs62aETymGl7qEUe7ZZagPdGE= 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: Open code the do_vmi_align_munmap() call so that it can be broken up later in the series. Signed-off-by: Liam R. Howlett Reviewed-by: Lorenzo Stoakes --- mm/mmap.c | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) -- 2.45.2 diff --git a/mm/mmap.c b/mm/mmap.c index 6ed27cf12217..56d0aaff8478 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -1366,6 +1366,9 @@ unsigned long mmap_region(struct file *file, unsigned long addr, struct vm_area_struct *next, *prev, *merge; pgoff_t pglen = len >> PAGE_SHIFT; unsigned long charged = 0; + struct vma_munmap_struct vms; + struct ma_state mas_detach; + struct maple_tree mt_detach; unsigned long end = addr + len; unsigned long merge_start = addr, merge_end = end; bool writable_file_mapping = false; @@ -1398,10 +1401,27 @@ unsigned long mmap_region(struct file *file, unsigned long addr, /* Find the first overlapping VMA */ vma = vma_find(&vmi, end); if (vma) { - /* Unmap any existing mapping in the area */ - if (do_vmi_align_munmap(&vmi, vma, mm, addr, end, uf, false)) + 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; + + /* Remove any existing mappings from the vma tree */ + if (vma_iter_clear_gfp(&vmi, addr, end, GFP_KERNEL)) return -ENOMEM; + + /* Unmap any existing mapping in the area */ + vms_complete_munmap_vmas(&vms, &mas_detach); + next = vms.next; + prev = vms.prev; + vma_prev(&vmi); vma = NULL; + } else { + next = vma_next(&vmi); + prev = vma_prev(&vmi); } /* @@ -1414,8 +1434,6 @@ unsigned long mmap_region(struct file *file, unsigned long addr, vm_flags |= VM_ACCOUNT; } - next = vma_next(&vmi); - prev = vma_prev(&vmi); if (vm_flags & VM_SPECIAL) { if (prev) vma_iter_next_range(&vmi);