From patchwork Mon Feb 27 17:36:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suren Baghdasaryan X-Patchwork-Id: 13153980 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 EF585C64ED8 for ; Mon, 27 Feb 2023 17:37:20 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8AE8E6B0096; Mon, 27 Feb 2023 12:37:20 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 85D726B0098; Mon, 27 Feb 2023 12:37:20 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6FE976B0099; Mon, 27 Feb 2023 12:37:20 -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 614236B0096 for ; Mon, 27 Feb 2023 12:37:20 -0500 (EST) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 3CFB4809ED for ; Mon, 27 Feb 2023 17:37:20 +0000 (UTC) X-FDA: 80513778240.04.79415C5 Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.202]) by imf16.hostedemail.com (Postfix) with ESMTP id 7461D18001A for ; Mon, 27 Feb 2023 17:37:18 +0000 (UTC) Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=QlvGB3sb; spf=pass (imf16.hostedemail.com: domain of 3Ter8YwYKCDwqspclZemmejc.amkjglsv-kkitYai.mpe@flex--surenb.bounces.google.com designates 209.85.128.202 as permitted sender) smtp.mailfrom=3Ter8YwYKCDwqspclZemmejc.amkjglsv-kkitYai.mpe@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=1677519438; 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=VWwKpXjDg6WAvmp/os9+Adpl/ccsxZtoSX3Q5XOWyQ0=; b=asuCFyvZSgAapwIlVrefX7pYWa4k2ZMV8L+A4vtiZlU5BzUr1MnuOQSzc6KS1dujxytcRs LUdRKoKkWDQ3HOrahxBavut3fIfNcySltijlnIZNr3TdaZKm0/vyYn/ZihfHt52GL3a2sh Fha4nZFLQUiK1+Q5THU8kTixIPzndNY= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=QlvGB3sb; spf=pass (imf16.hostedemail.com: domain of 3Ter8YwYKCDwqspclZemmejc.amkjglsv-kkitYai.mpe@flex--surenb.bounces.google.com designates 209.85.128.202 as permitted sender) smtp.mailfrom=3Ter8YwYKCDwqspclZemmejc.amkjglsv-kkitYai.mpe@flex--surenb.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1677519438; a=rsa-sha256; cv=none; b=xaizBthyXy5PmIGBRm858o5qaaumSlzHQHC7RVXVBYYc5pDQPaVlVdUWJtsQQn7vJ0mogu Mhx/zorSA5/zgCI7QPZVS80R5dhjvVNosN5g2EkokWFMbs5gpIBiVjYeBpgrHLACWHNf8T P22cUikDkeYqPamZFqBqMMEBxdhm7kI= Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-536cad819c7so153268587b3.6 for ; Mon, 27 Feb 2023 09:37:18 -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=VWwKpXjDg6WAvmp/os9+Adpl/ccsxZtoSX3Q5XOWyQ0=; b=QlvGB3sbxoYWlBS31TzcGu38FuNf7Lhjhtq2VlYCxWOSVfHgnAjaRBrb1w97aEacbe K6advecLicCSUfFEo9GDjw6ni0z0vYUO24YPFOrOT6PGrUxiFDeAMZRvmYa7tXn8nDcV jQQpuW50daFJ8WQmqyVE7pXe4jO0h72Ly1mymbXPSaJk3hcoxxEHUhmsYcU7Utdafwgh EoU7EkscyBq5l+R+tPrIdVU+apzyZHKYcAM5J8frjMBd1EpUZg/bzw2FKzGiNCJc/yPF OX60CUqczCC42EwMz0GH4Ohwd96NL51ADp4JavDsEQkoG6zGf4C60SM+ihxfLXuX3u7Q RNJw== 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=VWwKpXjDg6WAvmp/os9+Adpl/ccsxZtoSX3Q5XOWyQ0=; b=c+aFavWTjNbIlwXlW9bm1fqV+V3f1/5Rd579OHmFSyLHz4HbItwoEofp4cNN3WgGwE m81hBOqssJVAtrEhG5YPYrjbXP2DbsfaWEM/kIQ1k3Sg0rrDJdiRWxw6j6RxFkdGeSqF tav9UdTBw/bZQBTiOqAUN2/Xd7PNTEhzD4QyNEo364mWWjK7Zo8Tr8B7oP6IuggkcnCZ JqwgAnrGRj/O6MP+FP9ogMEm2MmRjPefZpwIyloBBJ1UFVLQlGQpXYm5GF4rf9qSOLdj K+XyuCcKdeD4lFcGIc2NDYEESW7qkWEXLu4NYiRgcMq/GfBfe+UxQ3uPOcCMf/eJVxC7 f2fQ== X-Gm-Message-State: AO0yUKX1f67PvFoAtCw8X40i/UIY1K3MBjtqlX/Rq/d82I1lXykk71Cx DyyAV6HUFCzSLuO0h+fn6RNKEa0c48E= X-Google-Smtp-Source: AK7set/Ab7tdetucxhQI7Y0d4CepnVZrRoikg6zNi8DSW4Q8ICogb5HvJ+8Ost/w6wLIBwUIyCkVrkJznGc= X-Received: from surenb-desktop.mtv.corp.google.com ([2620:15c:211:200:e1f6:21d1:eead:3897]) (user=surenb job=sendgmr) by 2002:a05:6902:10c:b0:a9f:3ee4:51a0 with SMTP id o12-20020a056902010c00b00a9f3ee451a0mr10ybh.505.1677519437283; Mon, 27 Feb 2023 09:37:17 -0800 (PST) Date: Mon, 27 Feb 2023 09:36:16 -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-18-surenb@google.com> Subject: [PATCH v4 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, 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 , Laurent Dufour X-Stat-Signature: mq7w9j3mk6ifeiazpjdhy4t89aaqhafd X-Rspam-User: X-Rspamd-Queue-Id: 7461D18001A X-Rspamd-Server: rspam06 X-HE-Tag: 1677519438-710185 X-HE-Meta: U2FsdGVkX1+v2TsrZCZPa4W3wajoQINmE/ghPqVfNEuXafwt9SaKOyyHfxOnPQKC/DyfdVxwowL8wtvgH1z0OgGSi5Ley4S+XJVJpIA+dO7+ZXdqZZBM75qAzVhNSg8M8fn853eHNW65ulWWNs0sQmmE1Gej6ww1hblA04A4tWWViVcbBHxoH8m/gICN2Lk7GY2U9PE1rHhXl0NR3906DynROdJ3oSlegBDocmR2TPY8Ss89GhoU+nW4rm8YS/71iNwWG/GOo+Qp6dswTjCgn58g8g4gh6tt12edszZOtwTpAYA+Q8D7qLz89Ru2rudlMekvg5018vMbMy9MJOQosLjT4Y5watOwqnnlEmbJd16utO357w/1BoASLdu/1pxLHxAbPrdDPBF9wd9yd+N4jlersEIW9qvh0V9HGc/eY0Wq88xBOwE/18mmfNENbYH/94VEBQWWui45Rqa91iA567Pr0jLJzoDRFbKLU76p1LnGZerd1LDu5OT79Qde9EkzzYgMT1CqQmRRZPMQcxwjOhVWQd0lFpTvtVGvPJKi89SKI2PivWj5nvcWPlM0fwV+NNOInrKdYTFs/yXTt0FAEopndayMfJhD4r2+kUmPHwEPMjYZx/mKTf3PqdyrXtXeWks6DdAs/c6uO4CKvEyiQmIv2WQazH/jgJjM+7jn40oc1KEXBcLy5GJ531BRf1C4HdSYS/mYS714ACiE5Q1SVn/5BLlabwPk/MOfJJ9c32NAM2ULLKFyHejLNLYoaUI4XDr0uw+KUGltfRgjVltsCMm17FNp678aTWR4ORokzZbTd44RPW7OY1+XolKE510D3ugA4pw1UDOZBde661HpctZOc93A9wiwlse6oUy31MC8riHX5Sh7qVVRPd132XQoj5UPZyxH+BTI8fF2i9TJLgIgVwtNQM2p1NLWOtcgvEHCQITwi1BfcO5AUdRKs2pnbTG8e/2/zuORhxOmhek wGBhnHzc c9rTdoBP1Ne9N6R4qR2VaCbrXfMKf4Dasy/Mx8M1nk2w/jKjpHmEc37OVth/CVjW8m1lYh5CgePYp2VkilXsgbW3oqgcVbZKwLbV2Oqd7ZN5wmjID5xDKgOtJXMzcrelnhNikLxU/t/xLmLayjjy7OmRG5q0xPcLHHFJsj48XkjEkIngG75YWWesutmHdBnEIYVkX9REAyCQBxYqeB5t6d5MmEtKR8qs4yjXr7BNCULxPh5G0QkZnncxqQ0OcqmcKtkHyxJ4N4VugaReDd/m4AasEyHm3Km0YQw0SYgmgZXshFh/hWIY4JNHdJgtX/CXrku8KQ66kGsPZ/Ozj8S66yQzlYfLnNfTQU3P2wfFn9nc3R6escXnHdAe8rVHYGarRWMH5d6tVqVVCMA/XhVAjxzFWtoqCQ8jgN84JQ9W9aD+RPLPrSXVvs9byf0p5ZGukPfpOrzf8NWZoExBHpdUw/vQ2Fgvo2iqrSm7AsFEDSviTB51biPAkPd9Q8yxDy1wAwAFjN9yXbMe/JZFnTVxj+7j+UzcNGDDHrUy19fihb4vdM+savcyqTPmO+gJKNI1SwG6xkanOD6/hKiQjizRPXrr4ms0oS0KRRPrsVdsuDZ6qwi91h+r9ZwaXurxgFqz4oGz86BjvBa+yc3b4CY+8APDpmA== 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 Reviewed-by: Hyeonggon Yoo <42.hyeyoo@gmail.com> --- mm/mmap.c | 1 + mm/mremap.c | 1 + 2 files changed, 2 insertions(+) diff --git a/mm/mmap.c b/mm/mmap.c index e73fbb84ce12..1f42b9a52b9b 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -3189,6 +3189,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 1ddf7beb62e9..327c38eb132e 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);