From patchwork Thu Sep 1 17:35:03 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suren Baghdasaryan X-Patchwork-Id: 12962981 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 1DABFECAAD3 for ; Thu, 1 Sep 2022 17:36:03 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B04BD80025; Thu, 1 Sep 2022 13:36:02 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A8D168000D; Thu, 1 Sep 2022 13:36:02 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9070380025; Thu, 1 Sep 2022 13:36:02 -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 7B5C98000D for ; Thu, 1 Sep 2022 13:36:02 -0400 (EDT) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 5A3E6C105F for ; Thu, 1 Sep 2022 17:36:02 +0000 (UTC) X-FDA: 79864219764.27.53E24B4 Received: from mail-pl1-f202.google.com (mail-pl1-f202.google.com [209.85.214.202]) by imf04.hostedemail.com (Postfix) with ESMTP id 17A9140051 for ; Thu, 1 Sep 2022 17:36:01 +0000 (UTC) Received: by mail-pl1-f202.google.com with SMTP id b9-20020a170903228900b001730a0e11e5so12193459plh.19 for ; Thu, 01 Sep 2022 10:36:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date; bh=jyHdLFPHMbjXGLnwUzIxKnvlA/GbLLDhxKEqR7mLfqg=; b=TCOmQuZ0ealmr2rj6cwh5S5dr2tHdE6kJbl5yIAByz1pqanqNTRiefLGtYBY7Bfwis HCiC64ttZOFWEgwG30yQXn+Yd1NgQ1aDGCJSNFZhazZq9lt7mplm3W+aibX2RLK/lLN0 uAX/ZCVxAoOvxpbxeS81kOPFHzixGFCJRTo1WJXrfNWNtHfKZEdnfDSt0EcuBcHbmrUl KJFv/JkMarGz2fGZyZ6GmZqZcaDNiv8ls/HHTwoDoMD28NmijZHaa+6d5o2vJqrlXSFO lKUsBOqEBkv1O0j454aqLOLj6gi+Hg3Qlj1nIC3dhAGDngGkgQrOdGW8W2dVGnwocfag do3w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date; bh=jyHdLFPHMbjXGLnwUzIxKnvlA/GbLLDhxKEqR7mLfqg=; b=ndHy1pOVaWAg9Zud8KZ/eQoriM3XQynyS8uUnXkmMycoG0kYVaUfnDh9am45jC68yX 2DHzkMXHEYcfwmhfl60acAehXFDXz8dSCzSH2vxdQH8QLsXLyeUxwpyL4JINbApS9Arp RT17LiazkKz1hGRmxkgLjXfmWHsB0wvQiwQzAyP2b6ivQ1UiCjJX0nOdIiyfTGlUk3o+ SpOdD/oP7aNKjPXwje4JvS7y5OFxNDF1uyeM+mmK47QQqfJh4+wATiB5MHbkpPI6hSnx nbqoLYRENEo1DL0V2elp9j5sA67ph+RN4A0OHN0IbKRAWOq2JQHOvwRHoFG3Ua4VKlhb 0cGA== X-Gm-Message-State: ACgBeo2PFy2Efi4Dc9bctyzqFtPmSU7u0WEc5hmV364q+Hnuf6syyIT7 u7TybM1NUH7EO9dW1QD4/QLUapMlckM= X-Google-Smtp-Source: AA6agR4mIrBI+VqdmK9XxquJrzUivZu8ctMQy2Mh5DPiMdzbr+5VMUvdiKSOqW1XRdAe5w+IQuXOVrbXRFY= X-Received: from surenb-desktop.mtv.corp.google.com ([2620:15c:211:200:1bfc:e7ee:6530:4449]) (user=surenb job=sendgmr) by 2002:a63:2cc2:0:b0:41c:681d:60d2 with SMTP id s185-20020a632cc2000000b0041c681d60d2mr26204273pgs.502.1662053761168; Thu, 01 Sep 2022 10:36:01 -0700 (PDT) Date: Thu, 1 Sep 2022 10:35:03 -0700 In-Reply-To: <20220901173516.702122-1-surenb@google.com> Mime-Version: 1.0 References: <20220901173516.702122-1-surenb@google.com> X-Mailer: git-send-email 2.37.2.789.g6183377224-goog Message-ID: <20220901173516.702122-16-surenb@google.com> Subject: [RFC PATCH RESEND 15/28] mm/mmap: mark adjacent VMAs as locked if they can grow into unmapped area From: Suren Baghdasaryan To: akpm@linux-foundation.org Cc: 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, ldufour@linux.ibm.com, 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, surenb@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 ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1662053762; 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: in-reply-to:in-reply-to:references:references:dkim-signature; bh=jyHdLFPHMbjXGLnwUzIxKnvlA/GbLLDhxKEqR7mLfqg=; b=X1TRKADt4gPkm6VjTXUvllXntrjNY6no7Xm5WM6sToWLy1NMBTnUUM4bm7OnA1mLHYQB+B CE3lNfcpSa9J+av3JBJeq9gcXzGS6pqUxFkefXOqXAgVH8QQvKgyTvI1XIc+WF5iCJtUF2 q781v2G43fcG794utA13cSmW7oKFprY= ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=TCOmQuZ0; spf=pass (imf04.hostedemail.com: domain of 3ge0QYwYKCL4wyvirfksskpi.gsqpmry1-qqozego.svk@flex--surenb.bounces.google.com designates 209.85.214.202 as permitted sender) smtp.mailfrom=3ge0QYwYKCL4wyvirfksskpi.gsqpmry1-qqozego.svk@flex--surenb.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1662053762; a=rsa-sha256; cv=none; b=k50UVkIWIhEUARMjkwil773pFQlIii/hFk9UHDKBcB3MxpahWE9COai7EghdONznEeIQGN OOF3nBJef4W+rBvNHC5MnqIYZS4eHimJJq3pYyVNxBgrXp+Mi2+la226BLi4YzZ8q6okKM fFKS1GovPO61GI/ohr7EbkOW+1YEfBs= Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=TCOmQuZ0; spf=pass (imf04.hostedemail.com: domain of 3ge0QYwYKCL4wyvirfksskpi.gsqpmry1-qqozego.svk@flex--surenb.bounces.google.com designates 209.85.214.202 as permitted sender) smtp.mailfrom=3ge0QYwYKCL4wyvirfksskpi.gsqpmry1-qqozego.svk@flex--surenb.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com X-Rspam-User: X-Stat-Signature: ggkepajni9ef9rs6jm6uxmswz93s9uh3 X-Rspamd-Queue-Id: 17A9140051 X-Rspamd-Server: rspam05 X-HE-Tag: 1662053761-113732 X-Bogosity: Ham, tests=bogofilter, spamicity=0.013779, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: While unmapping VMAs, adjacent VMAs might be able to grow into the area being unmapped. In such cases mark adjacent VMAs as locked to prevent this growth. Signed-off-by: Suren Baghdasaryan --- mm/mmap.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/mm/mmap.c b/mm/mmap.c index b0d78bdc0de0..b31cc97c2803 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -2680,10 +2680,14 @@ detach_vmas_to_be_unmapped(struct mm_struct *mm, struct vm_area_struct *vma, * VM_GROWSUP VMA. Such VMAs can change their size under * down_read(mmap_lock) and collide with the VMA we are about to unmap. */ - if (vma && (vma->vm_flags & VM_GROWSDOWN)) + if (vma && (vma->vm_flags & VM_GROWSDOWN)) { + vma_mark_locked(vma); return false; - if (prev && (prev->vm_flags & VM_GROWSUP)) + } + if (prev && (prev->vm_flags & VM_GROWSUP)) { + vma_mark_locked(prev); return false; + } return true; }