From patchwork Mon Aug 29 21:25:18 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suren Baghdasaryan X-Patchwork-Id: 12958439 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 48213ECAAD4 for ; Mon, 29 Aug 2022 21:26:06 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C5BFC940013; Mon, 29 Aug 2022 17:26:04 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id BE296940008; Mon, 29 Aug 2022 17:26:04 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A833D940013; Mon, 29 Aug 2022 17:26:04 -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 83655940008 for ; Mon, 29 Aug 2022 17:26:04 -0400 (EDT) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 60D0E1A0A64 for ; Mon, 29 Aug 2022 21:26:04 +0000 (UTC) X-FDA: 79853913048.02.9AC6227 Received: from mail-pl1-f201.google.com (mail-pl1-f201.google.com [209.85.214.201]) by imf28.hostedemail.com (Postfix) with ESMTP id 27707C005C for ; Mon, 29 Aug 2022 21:26:03 +0000 (UTC) Received: by mail-pl1-f201.google.com with SMTP id y9-20020a17090322c900b00174c881abaeso2531392plg.6 for ; Mon, 29 Aug 2022 14:26:03 -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; bh=KQbM9RENeAKpMamE0B+V4MUsqhzbhGXDlXXjmQQUA6A=; b=B9JYMkX5xydBJOgcGzuYw+brQarCWmRWS+0/Aqinb/OY26MbR1xT5axtOfpYrKlmA6 qGVi7LP6LaJMDcQJmEECw3J6IqaSMiez5M7VUbq2lZEZKkVSQHjZtuqy9g7s10YpHljB L9LJY/vXV43u8aIw7/j+LcG51+Bdx5jgIt7f2hLczg1JgYzlwTyYBe/lmm+nmwMuVZWc thodE+2BI084oTXFC0MD73T0ggmHuAL+ik6FuitgxrIkPY+yM+/axTrbJYGoWGabXb1/ atpqGKZe5bOiVGcNY/fR8gQx2/9qiwRjzQjgpRwLojxFdTcGDVT+d94c/I/T/XPhcGEF rEbQ== 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; bh=KQbM9RENeAKpMamE0B+V4MUsqhzbhGXDlXXjmQQUA6A=; b=kh8LfgVptghICoWYvyxVLAfGY8m//9z82hy8ItZolDOjq7gj9IIpXbIniBidpbUIW9 gYG2Iw48T1dqZV04HD8rpMa3s2K8b3MnSO5qXmXcOMGqkSTcAgg0bOD7B4Z0Qd7Z2AmS Uc/zwQkktPK9wNhPuukU8RHAB0bmNUIDT+ZalNcADD95xLYunoDP9mOszmGoUQzcjK7U /r+14Ucl2lVn7/hhboNBIT5ZCJmhuJg0nlw6x40SZ8mPvbPhxbcQodWzE0/q9/9VXWkm PV/6hIDC8IEBik4F/Kew6RLYvx8EgQsawrE4ad0WcqbjH22XVkNoJYuNIcHWJNJqZ5gf VQ4A== X-Gm-Message-State: ACgBeo36ioFK/YUn4hFGYMLIQB0gFKh8f+QhjmB/el4BxE0dI8L0MJzI rldExyb0WbtzfKM/qG5zoUG0j6NM42U= X-Google-Smtp-Source: AA6agR7f4s+E2TUUdzlInwBIWNCTTjaS2dHpmImL6O3kfzXJ6rCAm5H+xn8nFf0AEemGeSJLYPdhv1d/+n8= X-Received: from surenb-spec.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:3e30]) (user=surenb job=sendgmr) by 2002:a05:6a00:b8a:b0:537:f81:203a with SMTP id g10-20020a056a000b8a00b005370f81203amr18341111pfj.80.1661808363176; Mon, 29 Aug 2022 14:26:03 -0700 (PDT) Date: Mon, 29 Aug 2022 21:25:18 +0000 In-Reply-To: <20220829212531.3184856-1-surenb@google.com> Mime-Version: 1.0 References: <20220829212531.3184856-1-surenb@google.com> X-Mailer: git-send-email 2.37.2.672.g94769d06f0-goog Message-ID: <20220829212531.3184856-16-surenb@google.com> Subject: [RFC PATCH 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@techsingularity.net, 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, riel@surriel.com, 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-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1661808364; a=rsa-sha256; cv=none; b=En34NEhR0K12vfiiILmQaAlYl/oXu6PI7Z5iPud8+hBlUXEJWX7BCMP7Gd1qaNgemQkHR8 5MSOsfkU5j6oRus6Inf+7fw1cH8N3tsr4DW6Nr8YPZx3fBfkf0sxieCMxOdVXdJ4MHPWpW 0Hb6Tf7uuWLT87sKi6uYufiIzcAkgbU= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=B9JYMkX5; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf28.hostedemail.com: domain of 36y4NYwYKCJwOQNAJ7CKKCHA.8KIHEJQT-IIGR68G.KNC@flex--surenb.bounces.google.com designates 209.85.214.201 as permitted sender) smtp.mailfrom=36y4NYwYKCJwOQNAJ7CKKCHA.8KIHEJQT-IIGR68G.KNC@flex--surenb.bounces.google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1661808364; 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=KQbM9RENeAKpMamE0B+V4MUsqhzbhGXDlXXjmQQUA6A=; b=gQ6EGj7Qn6Hoeu+1fYAvRIkbJzZV5VAu8GIvBCoe8dZiqPnzG5UkjQjndMOQliCA72CXOO XcKq18Dd4PmUkKznTO3HHkjg9d4L/jGZ7LvHCeWZ7b8Z/m2ySbgyC5oylZWU6gRpDgre7m 77F5gTKKdUYT272EV+eUVWwVVStwRtI= Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=B9JYMkX5; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf28.hostedemail.com: domain of 36y4NYwYKCJwOQNAJ7CKKCHA.8KIHEJQT-IIGR68G.KNC@flex--surenb.bounces.google.com designates 209.85.214.201 as permitted sender) smtp.mailfrom=36y4NYwYKCJwOQNAJ7CKKCHA.8KIHEJQT-IIGR68G.KNC@flex--surenb.bounces.google.com X-Rspam-User: X-Rspamd-Server: rspam10 X-Stat-Signature: 9m8xqzpqj8c87w815oo46yqw3n74u8dm X-Rspamd-Queue-Id: 27707C005C X-HE-Tag: 1661808363-765975 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000275, 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; }