From patchwork Fri Jan 27 19:40:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suren Baghdasaryan X-Patchwork-Id: 13119261 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 40757C61DA4 for ; Fri, 27 Jan 2023 19:42:08 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 105996B0099; Fri, 27 Jan 2023 14:42:07 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 066486B009C; Fri, 27 Jan 2023 14:42:06 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C575E6B0099; Fri, 27 Jan 2023 14:42:06 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id B0F436B0099 for ; Fri, 27 Jan 2023 14:42:06 -0500 (EST) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 8D82D80619 for ; Fri, 27 Jan 2023 19:42:06 +0000 (UTC) X-FDA: 80401599852.02.7F30E73 Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.201]) by imf22.hostedemail.com (Postfix) with ESMTP id CF430C002C for ; Fri, 27 Jan 2023 19:41:58 +0000 (UTC) Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=GKKENfMf; spf=pass (imf22.hostedemail.com: domain of 3AinUYwYKCMk796t2qv33v0t.r310x29C-11zAprz.36v@flex--surenb.bounces.google.com designates 209.85.219.201 as permitted sender) smtp.mailfrom=3AinUYwYKCMk796t2qv33v0t.r310x29C-11zAprz.36v@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=1674848518; 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=L4ezA/DdKPqYrQ5cS+Ke2gtcDFDEWQ5+mTqJ9joAzRk=; b=CRigBxutiXKuxVvJElPEqYtvjVwfafGEWL9heiPsEZhJXuite898AJG4XGTPk+rCo8cMYQ kfkK0Di9B01UWLu/++eyCI6nFdFbsjGsawaW8Mu0e+a9ES/54wrKzuA2qBPb6AShK3Smld nUOHxHQkpFdDDFhOdd2UWVP9O9iivWM= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=GKKENfMf; spf=pass (imf22.hostedemail.com: domain of 3AinUYwYKCMk796t2qv33v0t.r310x29C-11zAprz.36v@flex--surenb.bounces.google.com designates 209.85.219.201 as permitted sender) smtp.mailfrom=3AinUYwYKCMk796t2qv33v0t.r310x29C-11zAprz.36v@flex--surenb.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1674848518; a=rsa-sha256; cv=none; b=YYli7h631IsAcJP3Jqly2a/PqtqAYeAflu3sSWlb6ytnNDXUOjR+UN1z4FPxQfqhpYdskD F6YQYw1Z+7geYROvtRsSy4BViUKRDPN4WSji5Hk+6caM6Qh5Dh84Zk3otR21ZjFihv0vxO t6iXRi84au2lVq28EHH38t9W/PcfXDs= Received: by mail-yb1-f201.google.com with SMTP id d21-20020a25add5000000b007ff8112e8b8so6429496ybe.17 for ; Fri, 27 Jan 2023 11:41:58 -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=L4ezA/DdKPqYrQ5cS+Ke2gtcDFDEWQ5+mTqJ9joAzRk=; b=GKKENfMfMG4N0pZCcl9OmPXOIcATJjfZsJmDxgzcwEK7KGqwCsad+AWtcOXvaoC0br qvO01w86MwzjSygGqi8PA6cojX9dXaSV7GQ7IPy4D+7hoAEyyoJoE4vESGbmz//KocjS XInPKVcNcxUU/7v9tYz8Eq3N+worhIjUrPeLT3iGbzfEm71MChhnFLrlat60IF4TyfFg cT/sx9cN16Dq7Csnqgd8AQwbf9+2MwGgrR42iD3xwMMpBpotxh+QKt5ySOsx98KoL0iq FNYiUMi+Hv+PIq3dZA5NAAwxArkgkUL/euE7T+pJZglO6ldDOiv8hb2KxyDrVWXCBL/Q MOaA== 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=L4ezA/DdKPqYrQ5cS+Ke2gtcDFDEWQ5+mTqJ9joAzRk=; b=GhX3GmRJJTPWoCEHkbkPmRSQnIjHRG3/SFX3hIJmAhgdKTgTEfrnq3smIolBe4ZyoL y1Jt/fsbgWdDS7be/ODkSBiVnC/NYu25cTLuRqiG7JJxG5GmnwZxVhGl31ZoeHLbNbVv 8JZNFVMjoM7sQ3HJye/tlQujEd5YbBKM1Eq8pdCjNOrPmEzBuMl7ulJoF7+MAS8wjziq 6EXaX+qCa4xrMiHWScXYjGGGX6g7pULhCmCLXwaBw3ZLxMYgIiHAR3KfijzXR7oHQPCz K8fUkAzSzxxKILN6Anufc+q5tS/knVd6n/k1nIWS8std3al9vEDA/EoQZy0KY8XThXDz W3Rw== X-Gm-Message-State: AFqh2kooOkVM4+974u883mBD9RBnCrQXTeeID52kKtkhNztDZ8uMffDF k7MDFKUDhKRRCgMDK2M09ESrDYTyIFI= X-Google-Smtp-Source: AMrXdXtaMEzriXRGDDaPyWp6cI2qFr9C55J9V7x8prQAmgawr911NF2wOHqTeINFz8M7FkUN1SViGFe49Jc= X-Received: from surenb-desktop.mtv.corp.google.com ([2620:15c:211:200:4e19:be9:c5d0:8483]) (user=surenb job=sendgmr) by 2002:a25:3c9:0:b0:803:3696:c473 with SMTP id 192-20020a2503c9000000b008033696c473mr2168756ybd.224.1674848514947; Fri, 27 Jan 2023 11:41:54 -0800 (PST) Date: Fri, 27 Jan 2023 11:40:54 -0800 In-Reply-To: <20230127194110.533103-1-surenb@google.com> Mime-Version: 1.0 References: <20230127194110.533103-1-surenb@google.com> X-Mailer: git-send-email 2.39.1.456.gfc5497dd1b-goog Message-ID: <20230127194110.533103-18-surenb@google.com> Subject: [PATCH v2 17/33] mm/mremap: write-lock VMA while remapping it to a new address range 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, 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, 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, surenb@google.com, Laurent Dufour X-Rspam-User: X-Rspamd-Server: rspam03 X-Stat-Signature: tx18ru4zozsz18t9ad66ry9oy9gtpup9 X-Rspamd-Queue-Id: CF430C002C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hZ2aTNVTd2jnMmnHSTvjH2BELyD1fV3TEr3eH5ObQ8okMqcqkkaSet37FF6sjvidg6RmbAxhf5XS181PbDR6skXZubf3D1sXmuCmuz52uiq033f2hRpA9NKOKsXjMAecbshXqfyLWTu+YcFKvxyY3FqYb8/WIlsTK0ZHqxkdbJjUjSlqYj+0QAEYp4VpdPqEQTOCHTgDIPqncR4wmrosBsYvmEI105k6ZQozN5Ewqi/Ykp7LsKrb4MWsIQ4+OXIiAIvOSYfEq+DyppOJVn1Jdk1cY9sjwY1HPGMGbwDSQtO7Oj0TqkYd4mJej2Pv/VCDO6mr8zMUau7OYtSzB4Rq53kI2d9MxCihksCMBdta2Y1J4ml1mYe42N76l5sLpRVfDdXi8bEzfkjp2WuU7m6sO7athvwaDxS/5YFOUHnkTGuLkXSLBHph8CAw1Pzw1sE/HtOADFsEr1SHDkANqPcQaqBHiv5UmgrLa7lnoASPLW98NOtjHIZAzXNKKuLIxqKQAa7qbjpLpsZr9uM9JlxCq2BBZwZylrE7KYait+lZOtD+X8AlB0NvUqRoDBseNNvJiXtJKaudvTaITWpNITBSxVMzO0g== 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 VMA as locked before copying it and when copy_vma produces a new VMA. Signed-off-by: Suren Baghdasaryan Reviewed-by: Laurent Dufour --- mm/mmap.c | 1 + mm/mremap.c | 1 + 2 files changed, 2 insertions(+) diff --git a/mm/mmap.c b/mm/mmap.c index 60038c24d836..b3c247073aa0 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -3202,6 +3202,7 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap, get_file(new_vma->vm_file); if (new_vma->vm_ops && new_vma->vm_ops->open) new_vma->vm_ops->open(new_vma); + vma_start_write(new_vma); if (vma_link(mm, new_vma)) goto out_vma_link; *need_rmap_locks = false; diff --git a/mm/mremap.c b/mm/mremap.c index 411a85682b58..dd541e59edda 100644 --- a/mm/mremap.c +++ b/mm/mremap.c @@ -623,6 +623,7 @@ static unsigned long move_vma(struct vm_area_struct *vma, return -ENOMEM; } + vma_start_write(vma); new_pgoff = vma->vm_pgoff + ((old_addr - vma->vm_start) >> PAGE_SHIFT); new_vma = copy_vma(&vma, new_addr, new_len, new_pgoff, &need_rmap_locks);