From mboxrd@z Thu Jan 1 00:00:00 1970 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 8B318C3DA41 for ; Wed, 10 Jul 2024 16:07:16 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1839E6B008C; Wed, 10 Jul 2024 12:07:16 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 13CC56B0092; Wed, 10 Jul 2024 12:07:16 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id F3ED96B0093; Wed, 10 Jul 2024 12:07:15 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id CA6316B008C for ; Wed, 10 Jul 2024 12:07:15 -0400 (EDT) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 4738EA015B for ; Wed, 10 Jul 2024 16:07:15 +0000 (UTC) X-FDA: 82324322430.29.90FBA31 Received: from mail-ot1-f51.google.com (mail-ot1-f51.google.com [209.85.210.51]) by imf23.hostedemail.com (Postfix) with ESMTP id 4A450140015 for ; Wed, 10 Jul 2024 16:07:13 +0000 (UTC) Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=SroTghdR; spf=pass (imf23.hostedemail.com: domain of surenb@google.com designates 209.85.210.51 as permitted sender) smtp.mailfrom=surenb@google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1720627601; 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-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=TjVbji5CrCqJ7kcfK3q/blM1DKJ1iwhRu2WNPrIdCio=; b=Vfm7BUzoSzq8r2spumCQN7cHi6IkOayHx12u6r3HYDgBKrefQAzodXGAEwWc/5/xyCI3oZ XHRQkTrcZH0JQyfEpCM1j25o0ITpUFhEFSsiQCfTYMCawPcOySh0CRHPDBspDXuJuSiaco Ed0GyoHDV26Ubekb+iaTThzOaR/oAj4= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1720627601; a=rsa-sha256; cv=none; b=exFp6BZ7FzfjWsWk01JIVufVBqrCfPg+VSw0FYqoQlr8695Ep7bSUTfs2I+IOT3KjVWwCp P7C2xmvUEGAEhWBQtLxFHdHd9OsNA19Gp1bOEBxqWhBLkT5/e3sgqx2LQYqshpyZza++bz TGzE0MEvrOQZuo2WerRtWoFs43W9BPg= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=SroTghdR; spf=pass (imf23.hostedemail.com: domain of surenb@google.com designates 209.85.210.51 as permitted sender) smtp.mailfrom=surenb@google.com; dmarc=pass (policy=reject) header.from=google.com Received: by mail-ot1-f51.google.com with SMTP id 46e09a7af769-7036f1f3434so1715562a34.1 for ; Wed, 10 Jul 2024 09:07:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1720627632; x=1721232432; darn=kvack.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=TjVbji5CrCqJ7kcfK3q/blM1DKJ1iwhRu2WNPrIdCio=; b=SroTghdRcp80Aa33RczsJ8WG3xS1LFb85WOEycXG1Am1Bt9yE3Gl/7TdDhvYBKLi/u 3W3B56CQZFXp3mTBBBfqabvGc08itOqbzoQJ69jmlPTkEdlNXgbjtLjEVjCr5R4wPZmp EW4uZ38+pxG5BuJtcXs+YCov2NEFAdJYBlSQgHiELmFzrTZaCTUmAAA+wPYbVusAJF2O AK5X1J4VbnZx59EiwCiIo7OMD6FxJ6VlHqKyR5n3hmmYDink5UDy9GINfVIY+wAUKLWQ WijHj4uon+Oh4IBCmKhHV43Jy498g4Oaom6LbKfX/B1YUxZrpTumPNq6zDmde1UpAaL1 DlmQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720627632; x=1721232432; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=TjVbji5CrCqJ7kcfK3q/blM1DKJ1iwhRu2WNPrIdCio=; b=Xof+TXwbMBztUBDHimSfaQ8WNuN0U8vdtgvl5MVgEeoPC5uPyHFBaM5+58yXohJr9E 3IN0RlYiDidS8damfYVCEiTpdJwK/YzNgNWZeckSZ3ICBLbb7LIPE2IkfVYST3rx4m+4 olysGh5xT3q1ZJy7BhW9mLOiumE4+PKP7GZuZki0cfNfx4HBWBHV5GUIFe+UVnrPXHfQ sYp1VlRw1O1siOIArany2dNSEobnHq5dIW60XMqpx3omobRwz2xn2D6tpaumhRyoml3F 6iR54fE3X6vXoNi4pwAsummuEc8cJXBgqe1HVwhdGiCA9eNog0JYvFubYF/aMpNffKQC csdw== X-Gm-Message-State: AOJu0YxG8rI2Cb9lFs7/6zHQqthSs9A3dGEGBKIjW0KogCmgRnhwCBaR pmQY5cOXlg0lQXNWk/xvOOlMbG7L/OhjNpvN6P/HPc5XBWK+yt+7W27Gk6MQrcBcgz64cSIRNyO Csjv0a2oRim+RWNboW1Nj9tm8F2LvDmELOzgw X-Google-Smtp-Source: AGHT+IEGuarjvl5P4EGO1WQRi2n+KDiCzE7RxqIQt9FVliErglbbA/aZXJxMQ5n6Ec63O5U9XcMPQHJgipWfsXpCYtQ= X-Received: by 2002:a9d:5912:0:b0:703:5f9f:82f2 with SMTP id 46e09a7af769-70375a0baccmr6882491a34.18.1720627632042; Wed, 10 Jul 2024 09:07:12 -0700 (PDT) MIME-Version: 1.0 References: <20240704182718.2653918-1-Liam.Howlett@oracle.com> <20240704182718.2653918-4-Liam.Howlett@oracle.com> In-Reply-To: <20240704182718.2653918-4-Liam.Howlett@oracle.com> From: Suren Baghdasaryan Date: Wed, 10 Jul 2024 09:07:01 -0700 Message-ID: Subject: Re: [PATCH v3 03/16] mm/mmap: Introduce vmi_complete_munmap_vmas() To: "Liam R. Howlett" Cc: linux-mm@kvack.org, Andrew Morton , Vlastimil Babka , Lorenzo Stoakes , Matthew Wilcox , sidhartha.kumar@oracle.com, "Paul E . McKenney" , Bert Karwatzki , Jiri Olsa , linux-kernel@vger.kernel.org, Kees Cook Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Stat-Signature: zyonoqdsmfzzztbgosnu4towzaz8jwr4 X-Rspamd-Queue-Id: 4A450140015 X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1720627633-907309 X-HE-Meta: U2FsdGVkX18jGa6Jft0radQ6zmSMOhpJU0p78OntE4hTl7StxZAM0QY2jmKHQninTRXPC9z8hGeoriQuyubwdz2A+DnPdpucVPvIfh8WoL6OrfMkSycRKXuSUeoc4HiCv6AWm3IOGwGYzjWOzq9kLlzidSF6jk6KZ9hRuenwpkpQFYnkp2NDT2CitemNJoCXpDZXPTBBPe8+6BR+XfSWgDJj8VYZifBvehKxmxPTsTIAPsjDylFnKANDgDuDJzED2xhel3p44m2OhEQTwk0Kximgjzx9DnyskdgiAfF6oUogkgyKhGumvhGcYXHXqQmr4Y5kARepXIMvuvo1lj99TU9e3qZ4KXNBWBFXU455VREb2OeZOm86X7ZeTtRt/mYbmaZMKWyj2UhHMv7Qwh0z2Atfw/8jMxh+j/c14JEF3bNxs6zJS66n7WdH2dJF9M5IFKf2p9Oir7V/aLrKdzPEX8WkoZ/T28ZAIbDytxAvEcWiF4s/iFfNT0omj07iLiHLh8FghqAEj0CG9ZsVOvN6Lqxc1X285eJr28xSgccSn/lka2/VjirDzhhPH3n+VH445Reb0Pz1/KfhkNfvDR/OWXqDDdSX055vTzXYkeTm6vLCqMo6QVCslxNic7kBrskFaJSUYc6NUc2vc/JYhwn6rsn5I53C/V+H8CEakcp1dXhogYCrpymDymy/gAol6RNPyog7ANA4/iEdVjsM4Xmdp/ZTegW67MU7erBQGVED9agCzVkB8bBYHLoYuhvg8Ovpl/iMIUvPOzeJ6lRlU1BW/0N6cTL/KpqDRQ4qKNw2xZgTVYHp4P7ltXXfCGBOp9pM8c5a7Sr3pd80piszgDis85vXuDjJEBAK3D9X+lwY3S1wRchBYB0FD6pMG5fUrWsBo0sCP7UX2xv8mvONwlg4fNdOX47CD9OkVV/BIElnLR1kj2LCMMlY/T2kk5+VJcDoSN7NhsUTvnmo+OxXk2/ TqLpRpzO 5aA+Dxotfzq81UTEzseJzsjpQwRselwNL/pAM6TCDn8/+Hso0aXhFefF7CnL4awpqhmjmUK+7BgENJ+5VhS3b6jZova3imGFAGSs1kXB0bvVFiIact3fDDFNDV/z5Qt8KbBmxic2o+scqQzHjQnmw4V2KDcJYwvj+CnhSx6KXh2j+e+/bSyLOttyZ6n8DK3h3TpAy3GjJuAPw8DGIq3IPhonL6HMKqzsMf8P25s+rFLc/Oo1gHYutSymccROwrPIl+vHmkCIXzVGro/A= 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: On Thu, Jul 4, 2024 at 11:27=E2=80=AFAM Liam R. Howlett wrote: > > Extract all necessary operations that need to be completed after the vma > maple tree is updated from a munmap() operation. Extracting this makes > the later patch in the series easier to understand. > > Signed-off-by: Liam R. Howlett > --- > mm/mmap.c | 79 +++++++++++++++++++++++++++++++++++++------------------ > 1 file changed, 53 insertions(+), 26 deletions(-) > > diff --git a/mm/mmap.c b/mm/mmap.c > index d572e1ff8255..411798f46932 100644 > --- a/mm/mmap.c > +++ b/mm/mmap.c > @@ -2605,6 +2605,56 @@ static inline void abort_munmap_vmas(struct ma_sta= te *mas_detach) > __mt_destroy(mas_detach->tree); > } > > +/* > + * vmi_complete_munmap_vmas() - Finish the munmap() operation > + * @vmi: The vma iterator You are missing vma and mm documentation. With that fixed Reviewed-by: Suren Baghdasaryan > + * @start: The start address > + * @end: The end address > + * @unlock: Unlock the mm or not > + * @mas_detach: them maple state of the detached vma maple tree > + * @locked_vm: The locked_vm count in the detached vmas > + * > + * This function updates the mm_struct, unmaps the region, frees the res= ources > + * used for the munmap() and may downgrade the lock - if requested. Eve= rything > + * needed to be done once the vma maple tree is updated. > + */ > +static void > +vmi_complete_munmap_vmas(struct vma_iterator *vmi, struct vm_area_struct= *vma, > + struct mm_struct *mm, unsigned long start, > + unsigned long end, bool unlock, struct ma_state *mas_deta= ch, > + unsigned long locked_vm) > +{ > + struct vm_area_struct *prev, *next; > + int count; > + > + count =3D mas_detach->index + 1; > + mm->map_count -=3D count; > + mm->locked_vm -=3D locked_vm; > + if (unlock) > + mmap_write_downgrade(mm); > + > + prev =3D vma_iter_prev_range(vmi); > + next =3D vma_next(vmi); > + if (next) > + vma_iter_prev_range(vmi); > + > + /* > + * We can free page tables without write-locking mmap_lock becaus= e VMAs > + * were isolated before we downgraded mmap_lock. > + */ > + mas_set(mas_detach, 1); > + unmap_region(mm, mas_detach, vma, prev, next, start, end, count, > + !unlock); > + /* Statistics and freeing VMAs */ > + mas_set(mas_detach, 0); > + remove_mt(mm, mas_detach); > + validate_mm(mm); > + if (unlock) > + mmap_read_unlock(mm); > + > + __mt_destroy(mas_detach->tree); > +} > + > /* > * do_vmi_align_munmap() - munmap the aligned region from @start to @end= . > * @vmi: The vma iterator > @@ -2624,7 +2674,7 @@ do_vmi_align_munmap(struct vma_iterator *vmi, struc= t vm_area_struct *vma, > struct mm_struct *mm, unsigned long start, > unsigned long end, struct list_head *uf, bool unlock) > { > - struct vm_area_struct *prev, *next =3D NULL; > + struct vm_area_struct *next =3D NULL; > struct maple_tree mt_detach; > int count =3D 0; > int error =3D -ENOMEM; > @@ -2728,31 +2778,8 @@ do_vmi_align_munmap(struct vma_iterator *vmi, stru= ct vm_area_struct *vma, > goto clear_tree_failed; > > /* Point of no return */ > - mm->locked_vm -=3D locked_vm; > - mm->map_count -=3D count; > - if (unlock) > - mmap_write_downgrade(mm); > - > - prev =3D vma_iter_prev_range(vmi); > - next =3D vma_next(vmi); > - if (next) > - vma_iter_prev_range(vmi); > - > - /* > - * We can free page tables without write-locking mmap_lock becaus= e VMAs > - * were isolated before we downgraded mmap_lock. > - */ > - mas_set(&mas_detach, 1); > - unmap_region(mm, &mas_detach, vma, prev, next, start, end, count, > - !unlock); > - /* Statistics and freeing VMAs */ > - mas_set(&mas_detach, 0); > - remove_mt(mm, &mas_detach); > - validate_mm(mm); > - if (unlock) > - mmap_read_unlock(mm); > - > - __mt_destroy(&mt_detach); > + vmi_complete_munmap_vmas(vmi, vma, mm, start, end, unlock, &mas_d= etach, > + locked_vm); > return 0; > > clear_tree_failed: > -- > 2.43.0 >