From patchwork Mon Jan 9 20:53:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suren Baghdasaryan X-Patchwork-Id: 13094289 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 0BE23C61DB3 for ; Mon, 9 Jan 2023 20:54:43 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9BF118E0003; Mon, 9 Jan 2023 15:54:42 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 96EFF8E0001; Mon, 9 Jan 2023 15:54:42 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 80FED8E0003; Mon, 9 Jan 2023 15:54:42 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 70F708E0001 for ; Mon, 9 Jan 2023 15:54:42 -0500 (EST) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 466701C65D7 for ; Mon, 9 Jan 2023 20:54:42 +0000 (UTC) X-FDA: 80336464404.05.B147BC0 Received: from mail-pl1-f202.google.com (mail-pl1-f202.google.com [209.85.214.202]) by imf24.hostedemail.com (Postfix) with ESMTP id ADC89180011 for ; Mon, 9 Jan 2023 20:54:40 +0000 (UTC) Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=pKSCW4f0; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf24.hostedemail.com: domain of 3D3-8YwYKCCQSURENBGOOGLE.COMLINUX-MMKVACK.ORG@flex--surenb.bounces.google.com designates 209.85.214.202 as permitted sender) smtp.mailfrom=3D3-8YwYKCCQSURENBGOOGLE.COMLINUX-MMKVACK.ORG@flex--surenb.bounces.google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1673297680; 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=olOpibg5eXy7KG3cFGJtGZQRi2wnSYuvllMlsZALFjE=; b=w89lltjnCijcX0rvuy/3bD3OEC648VaWO/js8hFlIkEI4HFqgDdfX5ny/tdi0dT72O7DFd anZ7GdddJ9IVr9cNZ7g5qyH1f+azeZTGeoyJQKnOSA/kjSBq7xpSaBIJJEsxiS2ZQ5DUHw sbcUIJxnb0FN7QdzyCTDHem+spETaMs= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=pKSCW4f0; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf24.hostedemail.com: domain of 3D3-8YwYKCCQSURENBGOOGLE.COMLINUX-MMKVACK.ORG@flex--surenb.bounces.google.com designates 209.85.214.202 as permitted sender) smtp.mailfrom=3D3-8YwYKCCQSURENBGOOGLE.COMLINUX-MMKVACK.ORG@flex--surenb.bounces.google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1673297680; a=rsa-sha256; cv=none; b=aU8VeMyqTDzC0aH3btq/eaTNQ6ZaZipjpjYMod7LgG+PzuohGvM3Wht4mh95yK5+1CFxI+ bSX++s8IVW3Dhx5aiOUrhUsg6tKzGQpCuh3zGwez9j6kI5PpySFBLOJ5dBPgow8gyDVZq3 SxfHAWWsEUbsr6kKcONLA+6aE5Ts7yM= Received: by mail-pl1-f202.google.com with SMTP id l17-20020a170902f69100b001928d6b3efcso6963557plg.2 for ; Mon, 09 Jan 2023 12:54:40 -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=olOpibg5eXy7KG3cFGJtGZQRi2wnSYuvllMlsZALFjE=; b=pKSCW4f0d77MorxMhTYeMa3Bkvztzi2l/11p+8AD9JlAcd7O/4nLaK3tMdO/JZYFZO oqL+3k7pxb64mumhhSbnD+8oqAK9T+YZbtnVKYdyWwz1xTl0lxuCTGJlmjyD4W6tkdoJ ScE8xkE+709mZSvnfMafhqWZz0JUfC8PX8Gqgq4hVWAiFqsbly88nJnbf2OtvsEjRJ+V Bh1jSeLHcoArd7dhSosnJ19E8FECzKPk1IhOzNYJUOL7f9tKHCqrIEP0OXg1wGsfV/sX JopWIX7MNjYmVxKWpBhB8gnFt1KMXJN0MSlcK65fQjg6FKg5IorU4J4ePrdeGZ792swl N3JQ== 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=olOpibg5eXy7KG3cFGJtGZQRi2wnSYuvllMlsZALFjE=; b=NjJaYaBOYnW2FcbRzqHdSWU9Yeo9vpnwL5lHZL6awyqabwsHskqo8huDfybmkuwiFY FQHJrTE0aMP0ph8VNbHaWgc8aKcCSZJH8u/c3ZNAFhMNv7/pWOl8bcbyjnXtIx31KEkw G9zfhlgKNEYEsRWDDdTwXmdGZwA1FUpRFKgek8jQmcHsnW2oh7kdtbB+l/9FgMn0fcCm 4r0/NGWF+LxwVFRD+QmaKYZE3YfsdHSh1b2XNFiWaQkbS6/+hEkPa1uXa3BP2NGamIDr sJDAqV2jJG/uvV4o6u6rm/rZAmyrIUhqSVgot48MIwapEMOPkEGP6aJyegR7KboUGXqL zE+w== X-Gm-Message-State: AFqh2korTnx7kF2p5+PnImk1EkwVL6fjWSnPKLzESnK/XJ6M89NIaCGY jpBASjooTHZ2TLYQgjl2c9ngV5LeUjo= X-Google-Smtp-Source: AMrXdXsFsv+WY6uB2QAxQKVey5zkUH2AXIcpYb3YNAv+Gej95uP4vEcIzk/UCgPyK193sduP1xpoK0p/ZF8= X-Received: from surenb-desktop.mtv.corp.google.com ([2620:15c:211:200:9393:6f7a:d410:55ca]) (user=surenb job=sendgmr) by 2002:a62:1501:0:b0:589:8362:c7ce with SMTP id 1-20020a621501000000b005898362c7cemr251559pfv.21.1673297679447; Mon, 09 Jan 2023 12:54:39 -0800 (PST) Date: Mon, 9 Jan 2023 12:53:18 -0800 In-Reply-To: <20230109205336.3665937-1-surenb@google.com> Mime-Version: 1.0 References: <20230109205336.3665937-1-surenb@google.com> X-Mailer: git-send-email 2.39.0.314.g84b9a713c41-goog Message-ID: <20230109205336.3665937-24-surenb@google.com> Subject: [PATCH 23/41] 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, laurent.dufour@fr.ibm.com, paulmck@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, jannh@google.com, shakeelb@google.com, tatashin@google.com, edumazet@google.com, gthelen@google.com, gurua@google.com, arjunroy@google.com, soheil@google.com, hughlynch@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-Rspam-User: X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: ADC89180011 X-Stat-Signature: 7sk5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L0qAfs3S5rDxDWm3JAo8nYRuY2TeNmXGRgEXZJrj9mSnR3jiCz/sBIZp3uPFVWOQVU8FNxPMC6o4ZnqK+Aw4cy6e/otuX7fHWQZYydJO67jJNPrgTPbLvQhPjmBTN/j/50ZYRssM08djT3xbVw9nU5GDw7yDC0GTQf49YcV5enYyXqSSmIY1phcX+qiLCGoPoXcUkzyXOvzcHyjZG5evGeA1+FpGRdORqyWd1HPyWWUskNs/p/W0uAgZPPXbCYv2V2gN3DTujg7Lx5l+XU/SkoNwWgfqxgMwgPdil9ywYzWgGIMJBBi5t064KjkNjjDzsNcSPU= X-Bogosity: Ham, tests=bogofilter, spamicity=0.001920, 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 | 2 ++ mm/nommu.c | 5 +++++ 2 files changed, 7 insertions(+) diff --git a/mm/mmap.c b/mm/mmap.c index da1908730828..be289e0b693b 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -448,6 +448,7 @@ void vma_mas_store(struct vm_area_struct *vma, struct ma_state *mas) */ void vma_mas_remove(struct vm_area_struct *vma, struct ma_state *mas) { + vma_write_lock(vma); trace_vma_mas_szero(mas->tree, vma->vm_start, vma->vm_end - 1); mas->index = vma->vm_start; mas->last = vma->vm_end - 1; @@ -2300,6 +2301,7 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma, static inline int munmap_sidetree(struct vm_area_struct *vma, struct ma_state *mas_detach) { + vma_write_lock(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 b3154357ced5..7ae91337ef14 100644 --- a/mm/nommu.c +++ b/mm/nommu.c @@ -552,6 +552,7 @@ void vma_mas_store(struct vm_area_struct *vma, struct ma_state *mas) void vma_mas_remove(struct vm_area_struct *vma, struct ma_state *mas) { + vma_write_lock(vma); mas->index = vma->vm_start; mas->last = vma->vm_end - 1; mas_store_prealloc(mas, NULL); @@ -1551,6 +1552,10 @@ void exit_mmap(struct mm_struct *mm) mmap_write_lock(mm); for_each_vma(vmi, vma) { cleanup_vma_from_mm(vma); + /* + * No need to lock VMA because this is the only mm user and no + * page fault handled can race with it. + */ delete_vma(mm, vma); cond_resched(); }