From patchwork Mon Feb 27 17:36:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suren Baghdasaryan X-Patchwork-Id: 13153979 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 B1146C64ED6 for ; Mon, 27 Feb 2023 17:37:18 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4DDF96B0095; Mon, 27 Feb 2023 12:37:18 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 48D3C6B0096; Mon, 27 Feb 2023 12:37:18 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 37D336B0098; Mon, 27 Feb 2023 12:37:18 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 275DD6B0095 for ; Mon, 27 Feb 2023 12:37:18 -0500 (EST) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 024D6140B0C for ; Mon, 27 Feb 2023 17:37:17 +0000 (UTC) X-FDA: 80513778156.28.17CBDD0 Received: from mail-yw1-f201.google.com (mail-yw1-f201.google.com [209.85.128.201]) by imf01.hostedemail.com (Postfix) with ESMTP id DECA040024 for ; Mon, 27 Feb 2023 17:37:15 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=MCQ0c4ia; spf=pass (imf01.hostedemail.com: domain of 3Sur8YwYKCDknpmZiWbjjbgZ.Xjhgdips-hhfqVXf.jmb@flex--surenb.bounces.google.com designates 209.85.128.201 as permitted sender) smtp.mailfrom=3Sur8YwYKCDknpmZiWbjjbgZ.Xjhgdips-hhfqVXf.jmb@flex--surenb.bounces.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=1677519435; 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=h8ePWaoI68GEISPuC9Ge+4qXkO8FW2G00MOJpn9vfbw=; b=MLq3IRd8hQndVs68d4E+ElzHQcfNtrB5gEPCodP8rKogZfmxyPBzjzja4FgZLzjo8HTB7s wjrgk/7aIY4w0gVJnifmC+Nz3TSAAuv7zK1L7MxUE5tV+W6Q7iiLaRUqdC77Bu+YSVKK5o DrmVHuUPaubcuN+cftP/IEJ1EYo3j2k= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=MCQ0c4ia; spf=pass (imf01.hostedemail.com: domain of 3Sur8YwYKCDknpmZiWbjjbgZ.Xjhgdips-hhfqVXf.jmb@flex--surenb.bounces.google.com designates 209.85.128.201 as permitted sender) smtp.mailfrom=3Sur8YwYKCDknpmZiWbjjbgZ.Xjhgdips-hhfqVXf.jmb@flex--surenb.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1677519435; a=rsa-sha256; cv=none; b=mdol6TwMm2memvJ/02m4wTgCgRGA0VNCRvCHoossGg3v61BCxizGh9oRG0PCb5V37IDAnm XQyQRVzgzuv2ErVz8bTvzdu0/ul/71I5MTo5z7kCFVrMql6sVuvaZYxpPkdDrdFoRVWmTQ m8+gquoM4yw9YgCCSpKUkMOhYfgXLBo= Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-536c8bcae3bso154382897b3.2 for ; Mon, 27 Feb 2023 09:37:15 -0800 (PST) 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:message-id:reply-to; bh=h8ePWaoI68GEISPuC9Ge+4qXkO8FW2G00MOJpn9vfbw=; b=MCQ0c4ia6IOTYMEFJR7GcbSkx2aCS+J3n3kLqdT/eCneA5RnZIfOSsLVqqbhg8oV3C z6a/cjMHL2s70DKPWTui5sWqdtSoRO2Sa3X/ZDXnFAdUlSIwaWZO5o28PzA9YRicQEsL lrmb7xLSeO5Upy8PojNo03zIknEUlOaIGEk3GY2vDeeMswBskS1b7cfH1kyMJjq2FiTa EPOOWdtU+2jcY+efHi/NzqtHu6KIrndJCcMf9jiuRTBG5FPDsaXOxEi35OK/QcXUq7OH bWHqrLVOAQNuSwHdqjlfEqvb31BygBYoGvuY/kisE56Bi1ONNPXA+NnMTkKqBCgcNMjA jbEw== 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:message-id:reply-to; bh=h8ePWaoI68GEISPuC9Ge+4qXkO8FW2G00MOJpn9vfbw=; b=AxaLS60Kd+LSMuPO07pQTIZqVOvcsziTo4rq9DbR/Z4VyeBnDrUNIVEHPuq5EavCVc O5HJYK1eLsAm8YGa0FYKC8/Pu4L48oYRLgziIjAhzBrQi5jqlGfZuvHc4CEO7PIW49mP jpYcqMIIzgzIl4y/IA2HHo68nfau3ymnL7gg5dLWLbbR81E/wJDT7j7BVffArPhc/F3j BNPMRh45YM2dnmdQKkJO1Y9ydBlMYlFQFM6qDsyHDofAQqgDIF0iJqJpzWbTxUnD84vV JUUmwgskjtqKOAVvZL/T3x1Tq/aPH6kMR5soFTJjBrMKRIbGLINfJGJGEfHV7w0A3i9G 5yKA== X-Gm-Message-State: AO0yUKU672NWN83XcmV4zyP7ee7sa8LYBBZjXVjDexhgG6YqdnCCX2v0 HFO1tWgla6LKAJndDZBuYsh0+XVCqFs= X-Google-Smtp-Source: AK7set9am1xybr1j78qWLG/uhzYsiBlXA8SkEZQ4RtcwObl9A6wj5gHEFg0gqcEhjrM4bOMvHErmcMX4UGI= X-Received: from surenb-desktop.mtv.corp.google.com ([2620:15c:211:200:e1f6:21d1:eead:3897]) (user=surenb job=sendgmr) by 2002:a5b:84b:0:b0:a09:32fb:be73 with SMTP id v11-20020a5b084b000000b00a0932fbbe73mr9490924ybq.0.1677519434899; Mon, 27 Feb 2023 09:37:14 -0800 (PST) Date: Mon, 27 Feb 2023 09:36:15 -0800 In-Reply-To: <20230227173632.3292573-1-surenb@google.com> Mime-Version: 1.0 References: <20230227173632.3292573-1-surenb@google.com> X-Mailer: git-send-email 2.39.2.722.g9855ee24e9-goog Message-ID: <20230227173632.3292573-17-surenb@google.com> Subject: [PATCH v4 16/33] mm/mmap: write-lock VMAs in vma_prepare before modifying them 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, paulmck@kernel.org, mingo@redhat.com, will@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, punit.agrawal@bytedance.com, lstoakes@gmail.com, peterjung1337@gmail.com, rientjes@google.com, chriscli@google.com, axelrasmussen@google.com, joelaf@google.com, minchan@google.com, rppt@kernel.org, jannh@google.com, shakeelb@google.com, tatashin@google.com, edumazet@google.com, gthelen@google.com, gurua@google.com, arjunroy@google.com, soheil@google.com, leewalsh@google.com, posk@google.com, michalechner92@googlemail.com, linux-mm@kvack.org, linux-arm-kernel@lists.infradead.org, linuxppc-dev@lists.ozlabs.org, x86@kernel.org, linux-kernel@vger.kernel.org, kernel-team@android.com, Suren Baghdasaryan X-Rspam-User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m ME06o+JM llshxKYJKLnjllbBVUSJoedTUxOVPChKifC0v20b6KKAV26yCWmtzD2eB4wb17qCyLlZTSwm5+LHFq/2NyED+zuRGz0JiJw5aYS1zZy/RNstAzjeXyKEr3v2eAygDDCN3yTLrICIprrBzhA0gXzR8R/HG4MBB5VW+n0L6igkM32qirN3fnfmX4oRyx6TYHs0nfit0tcd8WeiFIBp6ze7NU+23Hh1XVrgbPMyDySNTgxJPTJhT0esmW7Qw8MVVyHvWAsPY6HS4HVwjZDNIcSvNURHxUuRN1YvUbRQBU0HbZtq6ZHfKvjI355gVXnOPaS2Yg7aU6gTiapCyg7jWEZce2/ePBjZOYhznW74hCk6laZcQC6qgRWILI42IVQTlSJtlZCk6K2/bwT40nySKLttX/PQGlfDstvOwG6SLcMZvr5OlAqMzg4s2fw4TkozKREtHUdAzmrssgkRoAJbu5ex7MG4wk/2d8k2pNcU03Bwr3aEYbbuyh5Wz48WGwtd0YzqBorgMoV3bn8nIB6I5+/jcA2i7jLBpX/zA2dYQxpZQWRpQRBowPTa51vTw5t2V8ZNDLUIA8xNCBjiu1RtJZ4KCLrkCFiIrf+zmiY+G1ViCLIBWpu/qivOHs8Bfk/bT3GagUIelsoj2r0nQ8hXdk1KKnKNKbkUdEffma9Th+oSDwx2E61o= 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: Write-lock all VMAs which might be affected by a merge, split, expand or shrink operations. All these operations use vma_prepare() before making the modifications, therefore it provides a centralized place to perform VMA locking. Signed-off-by: Suren Baghdasaryan --- mm/mmap.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/mm/mmap.c b/mm/mmap.c index 92893d86c0af..e73fbb84ce12 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -502,6 +502,16 @@ static inline void init_vma_prep(struct vma_prepare *vp, */ static inline void vma_prepare(struct vma_prepare *vp) { + if (vp->vma) + vma_start_write(vp->vma); + if (vp->adj_next) + vma_start_write(vp->adj_next); + /* vp->insert is always a newly created VMA, no need for locking */ + if (vp->remove) + vma_start_write(vp->remove); + if (vp->remove2) + vma_start_write(vp->remove2); + if (vp->file) { uprobe_munmap(vp->vma, vp->vma->vm_start, vp->vma->vm_end);