From patchwork Fri Jan 27 19:40:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suren Baghdasaryan X-Patchwork-Id: 13119258 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 948E0C38142 for ; Fri, 27 Jan 2023 19:42:03 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2D9806B0096; Fri, 27 Jan 2023 14:42:03 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 289446B0098; Fri, 27 Jan 2023 14:42:03 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 12A4E6B0099; Fri, 27 Jan 2023 14:42:03 -0500 (EST) 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 0297B6B0096 for ; Fri, 27 Jan 2023 14:42:03 -0500 (EST) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id C83A18089E for ; Fri, 27 Jan 2023 19:42:02 +0000 (UTC) X-FDA: 80401599684.29.7E44228 Received: from mail-yb1-f202.google.com (mail-yb1-f202.google.com [209.85.219.202]) by imf14.hostedemail.com (Postfix) with ESMTP id 1E8EB100014 for ; Fri, 27 Jan 2023 19:41:57 +0000 (UTC) Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=iI2a7Mep; spf=pass (imf14.hostedemail.com: domain of 3BSnUYwYKCMwAC9w5ty66y3w.u64305CF-442Dsu2.69y@flex--surenb.bounces.google.com designates 209.85.219.202 as permitted sender) smtp.mailfrom=3BSnUYwYKCMwAC9w5ty66y3w.u64305CF-442Dsu2.69y@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=vIuOo+WD7hhMM8dbfJD4mGHBD08/Cqf6l0kIi97gWpI=; b=3l8T5PZ5qz+2jTwY7g06rAUZYykZRsJis5iufKWEskQdufK3uw2MPszQ+gG5GSfLayRfEo nx9oCd4IuSxlBlcFRScF+RnlaicchmEmKOo4ChsvpRevio1dRbagdDeBeqbE1tET5YEFCT cbpig9SiaJmdD1pnUubqYb3YEw68nUM= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=iI2a7Mep; spf=pass (imf14.hostedemail.com: domain of 3BSnUYwYKCMwAC9w5ty66y3w.u64305CF-442Dsu2.69y@flex--surenb.bounces.google.com designates 209.85.219.202 as permitted sender) smtp.mailfrom=3BSnUYwYKCMwAC9w5ty66y3w.u64305CF-442Dsu2.69y@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=tDQe8nGWSDZ5yZ+h43ixMNDBlfVjs1UUtHsUiEPlNuyYEt/u/hPcDqJbHlHAkRinZs/5RI dUyk+EdkYfyk0z/m+c1tjFw0AWfD2YSf2gWlD348TkOk+RFjwINP23DYYLGENx8f+MGz88 8DYzkuPtrPg9JsFXCGgC6qhYa+EPDNo= Received: by mail-yb1-f202.google.com with SMTP id p19-20020a25d813000000b0080b78270db5so6348716ybg.15 for ; Fri, 27 Jan 2023 11:41:57 -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=vIuOo+WD7hhMM8dbfJD4mGHBD08/Cqf6l0kIi97gWpI=; b=iI2a7MepfOBNDqB7wu+/83gKbYOOOUW8grtwa3CiYxFM9JfwE6yM70Ne3Bb3nWcBVw Yu75uY4jTmGekedOn8ngeIwpB83dCuwgdGAmo3PP8/5H9WQZ6zUPSiR4iOLBbFN7215j t5fY8PD6baQLdLtkjh6u6ca2lGsT7fHu5oxzuRWhyEjLoCc6wJIYtxHPj4OPz1R/r154 +v9JTIHiwr1S1nQG1EzjVKOQzPqMVCb1Q8Qi6vYQuYU/8I9rd1kQnHGC5kdzCbnlOWk7 FPBIbkrQ5+p0qEBCYmhl8CWtOia+KC/VA/z2TgOLyA8KXzLYreAkUsa906GcFZG1qYyr SCmA== 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=vIuOo+WD7hhMM8dbfJD4mGHBD08/Cqf6l0kIi97gWpI=; b=3EJ5InoaDMAIZKEkAusn0xzS5hvx4XLsRlAgSHGuplw1xFlcn1karfQFL/HDnsqHNe 46C2/Lbc6XQC4HooH/P2rEjmqoKItiAHJ1n0e2wMmnRaZPMqO+JIJZF7LrjZYXzjFxWp jFz3/PFkJ89wnvryy7f9AfCU60INe4PcfVUrjtrvJlKdjOgt8X7HR3s03MCSNIB/mPKj AXI2vmJNJOh+GoUeh2XGra/rgBC2+JUZCKvbSj/SOv9bCkoxyaO2nmAdeYIE5CR+7OTI pJ8jhD5BXksu0btBKA1kpiNfBWO0NUXxhTkSJA52tvbQKVJhvSPtzzqA6LXh4FZRPgMf lipw== X-Gm-Message-State: AO0yUKUitaIxCu1EZuUI55L2QLbOd4+67c5ikBgbpShRUNdMCFlJE/ji SoDNlY1SGkWa+1gZQTyrN6oEkcavuBs= X-Google-Smtp-Source: AK7set91XCOXqw0Dg5UJpzZX/mqq3ueYFNiPcfvNNp2V4Tl7t8riuyYgZdoB/8yFEdiYxfiOzkRBBcWpyqU= X-Received: from surenb-desktop.mtv.corp.google.com ([2620:15c:211:200:4e19:be9:c5d0:8483]) (user=surenb job=sendgmr) by 2002:a81:3e15:0:b0:506:653c:db97 with SMTP id l21-20020a813e15000000b00506653cdb97mr1675918ywa.201.1674848517274; Fri, 27 Jan 2023 11:41:57 -0800 (PST) Date: Fri, 27 Jan 2023 11:40:55 -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-19-surenb@google.com> Subject: [PATCH v2 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, 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 X-Rspamd-Queue-Id: 1E8EB100014 X-Stat-Signature: 98sstob16rsbig5ehsthukukz5uuoy1x X-R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nFEIWH2Xasn59pS6WNeuALxYXPRSSeRFpNJuRnZxZOSm8KP5KdBQYgPsJmHAG7n17Saf+9ibxhuXn8arpQnbpynXZjb2YBMZa5fG9bcTcYwSsZm8iPH+VSrz45tCBm1XL4KWCu50cB3ZWt8PPQqVM0509juTwpIXsWTxDFa1cEgLgGKFWp7uvakKV35jdzlGC3wvk/YHhy1jZxR3WsGsWb8Qa8EBo3a66a04+79IpvgZQpn0oIE21EX9uo+GG+ggKFkGUtYP21tcuyXJO98Y1bdCi3Q2Ill/A56Fe9oYR6PckIMa4JeMY/3BCQ4ValSWnJ5KBPI8V+P2vQbgHFG+Fdm3cdIgHHf+1oVtujTpgpZ0GLGxX2Tb/jXRrPggDZAwoxfyXLIutpAr95PzNmjNN62y3eku8m8gXW4CO9d/XjQczPgm78cVMn0nk9UZiGVDNnB7b8NEJXospJzKxALwzMTnI6AgVxxyJiO5jYLH+PQJVJvcD+s2hB0uDKdm52NUc9fumD+ZlE6UMpXp8TWTphu+S3+SGAoVCBjYVzPYe7++IdEqF0IbZ/HLhQjIOMyHzv35Ck2v2r8GA== 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 b3c247073aa0..5bdfd087b632 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -2261,6 +2261,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();