From patchwork Mon Feb 27 17:36:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suren Baghdasaryan X-Patchwork-Id: 13153981 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 C88F9C7EE23 for ; Mon, 27 Feb 2023 17:37:23 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4DDF0280002; Mon, 27 Feb 2023 12:37:23 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 48DD5280001; Mon, 27 Feb 2023 12:37:23 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3091A280002; Mon, 27 Feb 2023 12:37:23 -0500 (EST) 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 1E647280001 for ; Mon, 27 Feb 2023 12:37:23 -0500 (EST) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id E0182140B09 for ; Mon, 27 Feb 2023 17:37:22 +0000 (UTC) X-FDA: 80513778324.03.0E3E2C3 Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.202]) by imf01.hostedemail.com (Postfix) with ESMTP id 0FDFA40016 for ; Mon, 27 Feb 2023 17:37:20 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=J6HTSW3i; spf=pass (imf01.hostedemail.com: domain of 3UOr8YwYKCD8tvsfochpphmf.dpnmjovy-nnlwbdl.psh@flex--surenb.bounces.google.com designates 209.85.128.202 as permitted sender) smtp.mailfrom=3UOr8YwYKCD8tvsfochpphmf.dpnmjovy-nnlwbdl.psh@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=1677519441; 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=r0m7Mx7yExEfpE40BLjkT9H7Bv79s8byLhYJ0wRxTC4=; b=CDAvUI09PT66jQoAqU8SAlG21YoWsJIa8V6+nCgJrU9tzNIKCDPWqBvArF8OCuFeN6jfv5 W0ZZ7ZYaitl4RxPuu2w+sknvX2GOPbAnCpIhxzsS8Z1d6YA5O99RiVwN4NNy2ifSQ/Zosd vJSz69515L2tHs+p/+ySNcMzL3FVLso= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=J6HTSW3i; spf=pass (imf01.hostedemail.com: domain of 3UOr8YwYKCD8tvsfochpphmf.dpnmjovy-nnlwbdl.psh@flex--surenb.bounces.google.com designates 209.85.128.202 as permitted sender) smtp.mailfrom=3UOr8YwYKCD8tvsfochpphmf.dpnmjovy-nnlwbdl.psh@flex--surenb.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1677519441; a=rsa-sha256; cv=none; b=4+uR3PC3MVxqxdG5RUTUOmR1muxc1mJXEVscOqsrKaMtw+m+GBUTo1FauLRLfSwVhfxAZH moQ87FuWNGg/gi7ABJal0Faa7+w61uGHoHh6g27rhLMnDZB5nfTs32zasAD1UaRRuUGaMC hB1MAmhB/SKXWbUkF/BeGxts0BCwXfo= Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-536af109f9aso154254607b3.13 for ; Mon, 27 Feb 2023 09:37:20 -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=r0m7Mx7yExEfpE40BLjkT9H7Bv79s8byLhYJ0wRxTC4=; b=J6HTSW3ije3IDV45f4imLJua2F9c9fG/LezyaDIF0k2VV4fuwgH+fku2QXSjWP2auL d+6+O+xNSm6Xj7FlWbcn2IucG0PD3/gJW2mH/MURmde3Q+9WMeczT04Csr++aQNQAB4v uOclz5rts/w0oMZxgj6JdiddKEJJwswsgJAAZvi48OAzGBi1BuSBhTNF8+d2d3+YbCDm fwaoPEsSaG9C8KiMPsrgpeVhqU2cm1pHUxTYDzrWvN6667+vmOEZ293x3rsB2i9qTzir LhGya0SRahx81MeDy4vFauftQ8Z+i+VjBO+uhvPnINIKKKPeRWHZkWIWZS9shPaay/sM /HGA== 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=r0m7Mx7yExEfpE40BLjkT9H7Bv79s8byLhYJ0wRxTC4=; b=nQ9xuy58ezQWkkagrKakuhZbe9ywdDdfaXIbmFP9hNOuwMWNwFAlfHNuPf6GpKXB49 r+oBkte482wvxrzQlk/KUbhfAoVs62117sSZA1NJD7AJFa8BRrmMH0NIyO7Oa3yiOCyq Dh4vHDU9wX8RC2GOlvfTG1yN7/IVBmdXPvfEsOtJTWmTScE9ucd7qx+4jje8UZuXnG6D dAnnUhuYEXFWVZbB3aNxphBt38IMsTB9xStY/Mmf88eT95a5Yt58zdiPhXSQYMrS+yKp 2ZzB08N7tKuCHfZW7Y5Y0t2w73hKY6+3c2k/e1PrG+NNIVxATITTqmZ2O5obwwmyBMGx nJzQ== X-Gm-Message-State: AO0yUKWP/7Oy0OJWwPDYqV07DJeynWd+Z/ThhmWe4yaaQnxHYGczzI6k DpHD9fm9nNusgWiOipOy5qZNxt6Q4IU= X-Google-Smtp-Source: AK7set8EV36Dr/ESiL80fu1d1SaW9bmdiDECZfWEbGGMOjKuqTD7GEuVWa5jynsNqQ2pFS6J79ENwuY0pY0= X-Received: from surenb-desktop.mtv.corp.google.com ([2620:15c:211:200:e1f6:21d1:eead:3897]) (user=surenb job=sendgmr) by 2002:a25:938e:0:b0:a60:c167:c056 with SMTP id a14-20020a25938e000000b00a60c167c056mr4911453ybm.9.1677519440118; Mon, 27 Feb 2023 09:37:20 -0800 (PST) Date: Mon, 27 Feb 2023 09:36:17 -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-19-surenb@google.com> Subject: [PATCH v4 18/33] mm: write-lock VMAs before removing them from VMA tree 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: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 0FDFA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mwLE+hGLzWEL3H41IhjlMGgbMiGX0rFqkJVkP0fkleQS2QW952mvYRV09nuISu7YW7W5sdJ1Jei35UkjAIwhvl2vX3WLi3jQgyNpFe5yl/4cpeQceclzVZ37/5LGOxAn1XGYVXZ2YX4obDBjzjC1/kvxUF8blk/btxXQxnT9Rlis+QEgZArBm8csulqV1lLzavHFzf7hcTAoRIDTKQuPJI8LdDDYGHgLAjmNLXG5WTnW2KO1NBgcaZ6utXddFEarmzOROK6Owaqm50IvjeIfd+QSjOotZluLagao0yFZlQH8O0ype7/EHXCw5Ji9pJggrTJeGEDfNGIUJI12uJYEhHnBo76PB3U55t+2t8pU5nBx0nr67dlqIO7mrCGBF4pgDoGZZ/1PKUSlUwz1n2hfGLS3TNtEgKjjlJfIPYlX7t18LE1G+c7G0LU+4WWJXRWMZbcawcVkTBNM0EtnKQMQCoW3moa9bfuPEnhnyuGDvV+RDPYpyk3woDxjiBrV541I3fh9OwIb377ub8R85D8fW0XpI+qFILuBpFxGnSR17etN6rpfszJB36h8nJLVLCW8qXna4N2xYafVHnVBXbGQg3Q95ULwMDk1OzEGmNF8R01rlAA== 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-locking VMAs before isolating them ensures that page fault handlers don't operate on isolated VMAs. Signed-off-by: Suren Baghdasaryan --- mm/mmap.c | 1 + mm/nommu.c | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/mm/mmap.c b/mm/mmap.c index 1f42b9a52b9b..f7ed357056c4 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -2255,6 +2255,7 @@ int split_vma(struct vma_iterator *vmi, struct vm_area_struct *vma, static inline int munmap_sidetree(struct vm_area_struct *vma, struct ma_state *mas_detach) { + vma_start_write(vma); mas_set_range(mas_detach, vma->vm_start, vma->vm_end - 1); if (mas_store_gfp(mas_detach, vma, GFP_KERNEL)) return -ENOMEM; diff --git a/mm/nommu.c b/mm/nommu.c index 57ba243c6a37..2ab162d773e2 100644 --- a/mm/nommu.c +++ b/mm/nommu.c @@ -588,6 +588,7 @@ static int delete_vma_from_mm(struct vm_area_struct *vma) current->pid); return -ENOMEM; } + vma_start_write(vma); cleanup_vma_from_mm(vma); /* remove from the MM's tree and list */ @@ -1519,6 +1520,10 @@ void exit_mmap(struct mm_struct *mm) */ mmap_write_lock(mm); for_each_vma(vmi, vma) { + /* + * No need to lock VMA because this is the only mm user and no + * page fault handled can race with it. + */ cleanup_vma_from_mm(vma); delete_vma(mm, vma); cond_resched();