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 7875EECAAD5 for ; Fri, 9 Sep 2022 00:51:36 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id AB55A8D0003; Thu, 8 Sep 2022 20:51:35 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A3D548D0001; Thu, 8 Sep 2022 20:51:35 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8B6878D0003; Thu, 8 Sep 2022 20:51:35 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 79E558D0001 for ; Thu, 8 Sep 2022 20:51:35 -0400 (EDT) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 4AFD6160424 for ; Fri, 9 Sep 2022 00:51:35 +0000 (UTC) X-FDA: 79890718950.12.397D3D0 Received: from mail-yb1-f178.google.com (mail-yb1-f178.google.com [209.85.219.178]) by imf07.hostedemail.com (Postfix) with ESMTP id F12B840072 for ; Fri, 9 Sep 2022 00:51:34 +0000 (UTC) Received: by mail-yb1-f178.google.com with SMTP id 11so540667ybu.0 for ; Thu, 08 Sep 2022 17:51:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date; bh=LBNHsgANfOuYwqoZHaxODMzZ7UA+U8+5hufwxCbYv44=; b=L4r1/zM0OJVEeznCxkFeDmzDJp0IcMmbKN2OvdW9zrSpQ1s5Kdty/1rkvqWo33TMhT xWV4jNGh+PbGvXm0RJQ/3GpSL8k3kkDWsQF1guPOx0QIt2B1p6UW/G2dGSAhnz6g0J3G aCbemhwYTPosRuwZH2Cn9ZVgTqZfSGP+OkF8xPq4LUSXcNwj3wBeXn3dSPUF2TrfIRpN JQVL/x1hFZ6eG+8WyfHTfUzx9yazN5pP/4MU/Ug9tlPrBw51u68/InTGeJUXAmTQ46F7 6ZwC93ANh6AAupdl3kfj2t2GfNBg9A4jCF4ximO4iROdJ/9dV1Q4vF+NqMLn6BAhU5rt CPow== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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; bh=LBNHsgANfOuYwqoZHaxODMzZ7UA+U8+5hufwxCbYv44=; b=OOHh2hhK4R6QwJWz4+zj1XsIVO6b0rhPVSLVEQCi7ef3xk/Qqoat4j0Ke7I5EHbEuu IbGtK3t0IwKu9UquKPvg7IYxcdcTU+egnjZRuXrLl7ipYwOTltZu9pvORVmBI1UBPkFU FPrDHip92zinIeJkiIC55gavy26hWYc9zlLEujlXruwXCsRmZQDsWqFugktYeLUBJp9S vfDImO5INjS7MP7zYjgnqg5OJHALn2+DQ/AoDzmAeS4+pU3bhqWJVhZ79WrkaiSEOJVd 3hQityd9fySji8D0PID2wRf46L/apavR37GndgQEJnuEij/6pf8rhCZ3uxefvUx6TtWO n2CQ== X-Gm-Message-State: ACgBeo3WJkOm1poXLFPNlKleIktNPGY5ygiyoTl3uZB+IGey+tquanW1 Eq7i+pNvcQ8Z5WDEl/7JJsv3C213eYFTd1HMR+5CFQ== X-Google-Smtp-Source: AA6agR5aiD/mHNLJf/uZTrUlH+sUk3m6QYGueoAr4dyZUEHwTfC+FSD4X8APTDBjLx4o2R6CQUyPXRoAsWEaWYZ1kA0= X-Received: by 2002:a25:d209:0:b0:6a8:e5f1:f179 with SMTP id j9-20020a25d209000000b006a8e5f1f179mr9413490ybg.380.1662684694045; Thu, 08 Sep 2022 17:51:34 -0700 (PDT) MIME-Version: 1.0 References: <20220901173516.702122-1-surenb@google.com> <20220901173516.702122-11-surenb@google.com> In-Reply-To: From: Suren Baghdasaryan Date: Thu, 8 Sep 2022 17:51:23 -0700 Message-ID: Subject: Re: [RFC PATCH RESEND 10/28] mm/mmap: mark VMAs as locked in vma_adjust To: Laurent Dufour Cc: akpm@linux-foundation.org, michel@lespinasse.org, jglisse@google.com, mhocko@suse.com, vbabka@suse.cz, hannes@cmpxchg.org, mgorman@suse.de, dave@stgolabs.net, willy@infradead.org, liam.howlett@oracle.com, peterz@infradead.org, laurent.dufour@fr.ibm.com, paulmck@kernel.org, luto@kernel.org, songliubraving@fb.com, peterx@redhat.com, david@redhat.com, dhowells@redhat.com, hughd@google.com, bigeasy@linutronix.de, kent.overstreet@linux.dev, rientjes@google.com, axelrasmussen@google.com, joelaf@google.com, minchan@google.com, kernel-team@android.com, linux-mm@kvack.org, linux-arm-kernel@lists.infradead.org, linuxppc-dev@lists.ozlabs.org, x86@kernel.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1662684694; a=rsa-sha256; cv=none; b=8TKUPZf518WoVt+2fDIErLUCFWEVV6Wbh2uWFFm33FJvTjoVCKSGwEepvDlKcV9PXr2eT+ R115urWEWxKp7LRoglEHCDiOhM2b8VyLThpn7itGw6P03SsDTA6GBKQCsq2MUoXHqhaPAB 9LzaoVguBTKwdGkL8iwP05HxBdmPzR0= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b="L4r1/zM0"; spf=pass (imf07.hostedemail.com: domain of surenb@google.com designates 209.85.219.178 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=1662684694; 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=LBNHsgANfOuYwqoZHaxODMzZ7UA+U8+5hufwxCbYv44=; b=x5HpYWyp0atbXU1va0fIjCHS2Vi/q+nQT3fjn/sWue9+1yRMlCd1H9JsFyIhPWKyo/FPD/ BYqroGREqFhJFE+idtto9/IoI4rD536/TJovI4B0yElEY+6p/gpMhjLLHWfumlGbgc8UNp eJh2n2XHpXGl7jhpi5Q5wPn8oIH9dYs= Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b="L4r1/zM0"; spf=pass (imf07.hostedemail.com: domain of surenb@google.com designates 209.85.219.178 as permitted sender) smtp.mailfrom=surenb@google.com; dmarc=pass (policy=reject) header.from=google.com X-Stat-Signature: j4m9d9kw6n8tnnw6ou59qfnnpdfcemmo X-Rspam-User: X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: F12B840072 X-HE-Tag: 1662684694-878053 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000020, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Tue, Sep 6, 2022 at 8:35 AM Laurent Dufour wrote= : > > Le 01/09/2022 =C3=A0 19:34, Suren Baghdasaryan a =C3=A9crit : > > vma_adjust modifies a VMA and possibly its neighbors. Mark them as lock= ed > > before making the modifications. > > > > Signed-off-by: Suren Baghdasaryan > > --- > > mm/mmap.c | 11 ++++++++++- > > 1 file changed, 10 insertions(+), 1 deletion(-) > > > > diff --git a/mm/mmap.c b/mm/mmap.c > > index f89c9b058105..ed58cf0689b2 100644 > > --- a/mm/mmap.c > > +++ b/mm/mmap.c > > @@ -710,6 +710,10 @@ int __vma_adjust(struct vm_area_struct *vma, unsig= ned long start, > > long adjust_next =3D 0; > > int remove_next =3D 0; > > > > + vma_mark_locked(vma); > > + if (next) > > + vma_mark_locked(next); > > + > > I was wondering if the VMAs insert and expand should be locked too. > > For expand, I can't see any valid reason, but for insert, I'm puzzled. > I would think that it is better to lock the VMA to be inserted but I can'= t > really justify that. > > It may be nice to detail why this is not need to lock insert and expand h= ere. 'expand' is always locked before it's passed to __vma_adjust() by vma_merge(). It has to be locked before we decide "Can it merge with the predecessor?" here https://elixir.bootlin.com/linux/latest/source/mm/mmap.c#L1201 because a change in VMA can affect that decision. I spent many hours tracking the issue caused by not locking the VMA before making this decision. It might be good to add a comment about this... AFAIKT 'insert' is only used by __split_vma() and it's always a brand new VMA which is not yet linked into mm->mmap. Any reason __vma_adjust() should lock it? > > > if (next && !insert) { > > struct vm_area_struct *exporter =3D NULL, *importer =3D N= ULL; > > > > @@ -754,8 +758,11 @@ int __vma_adjust(struct vm_area_struct *vma, unsig= ned long start, > > * If next doesn't have anon_vma, import from vma= after > > * next, if the vma overlaps with it. > > */ > > - if (remove_next =3D=3D 2 && !next->anon_vma) > > + if (remove_next =3D=3D 2 && !next->anon_vma) { > > exporter =3D next->vm_next; > > + if (exporter) > > + vma_mark_locked(exporter); > > + } > > > > } else if (end > next->vm_start) { > > /* > > @@ -931,6 +938,8 @@ int __vma_adjust(struct vm_area_struct *vma, unsign= ed long start, > > * "vma->vm_next" gap must be updated. > > */ > > next =3D vma->vm_next; > > + if (next) > > + vma_mark_locked(next); > > } else { > > /* > > * For the scope of the comment "next" and > > -- > To unsubscribe from this group and stop receiving emails from it, send an= email to kernel-team+unsubscribe@android.com. >