From patchwork Thu Sep 1 17:34:57 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suren Baghdasaryan X-Patchwork-Id: 12962975 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 BBF6BECAAD5 for ; Thu, 1 Sep 2022 17:35:47 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 586BC8001F; Thu, 1 Sep 2022 13:35:47 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 535A88000D; Thu, 1 Sep 2022 13:35:47 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3D6FF8001F; Thu, 1 Sep 2022 13:35:47 -0400 (EDT) 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 2FEF68000D for ; Thu, 1 Sep 2022 13:35:47 -0400 (EDT) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 08D06140FBC for ; Thu, 1 Sep 2022 17:35:47 +0000 (UTC) X-FDA: 79864219134.16.C508695 Received: from mail-pl1-f201.google.com (mail-pl1-f201.google.com [209.85.214.201]) by imf02.hostedemail.com (Postfix) with ESMTP id 9E9908005F for ; Thu, 1 Sep 2022 17:35:46 +0000 (UTC) Received: by mail-pl1-f201.google.com with SMTP id i1-20020a170902cf0100b001730caeec78so12089805plg.7 for ; Thu, 01 Sep 2022 10:35:46 -0700 (PDT) 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; bh=f3HBd//8MTEjGtUKjIJ6VlUao66B8ATA87dRitXKN6o=; b=osN5P5u2gNPNqCUBvTG+Zi66behXZjVMeiTYran173d3bK7x/C4pNezlQHCFvkYQk7 qOQqzQeCFbXQDX9e+QRzeVBdZKr22OFya12CKF/BNucIJ15gJeM6CJ6xJtVhkJ86JMIW z0BrEcSFGRuuGzZ7AIa/XsKdDh+JkQT9DWUmeCCWJ5VsR1VGSIBZmgZx0ZCJYBHl+XPj GoCI/RFibFsonWSqgiZwplWva8pXUgT5urz+18AucAe/seeiQYlfr5LWvUC2qg96tyno slrVqaBJlR1Fm38ZmASWvylf1J3rbhYM8n7OsiK4uazMHDS7+qFeKWZULOPVqfmGOKH5 n3ag== 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; bh=f3HBd//8MTEjGtUKjIJ6VlUao66B8ATA87dRitXKN6o=; b=s0aTz9jpN6x0BIXX30bj91iVGXEgpjf2MbtsI/oHGAPtMiheXGtuqYjHkGp1HjnT98 6tlgxny3xa9KuSXnL41mBuhDA+cDoV+EwjWCGOpAyprGeCauZI6+qCmaoXKclIZdphlS mkM4rsBDhMBhunTQpA8JssYcTDMJrQIq+IE6qImSJc7ksTztM/uVfp+n0rwZjMvYkR3i k/hlMZzYp8C73YaJnqI5s5Klrk5fL10VUDdUmHayyX9hdv/gcaqOVa1f0jIRhaOIcj9c yuuqUTGa4pKORNSZYACe7Pny/40/WCmLVkdfi7O63qBtvu+iDSq+bDCBFIQV5l8LXbwI ZflA== X-Gm-Message-State: ACgBeo0NQhDxbHq/UYTDtOddOJcrM+JIy8WzXuiV2jSaCrsqo29zIwYU AL1e83hGbXumLWJ+9YiPZwLlp0ZuNkA= X-Google-Smtp-Source: AA6agR6Q3wPydZYjoco/mRjMkhmNWxJo3Xdi/ebZ3ovzfa+ebF5iWZWFhqHdfMvubIqW+qGVzpwNqTYAd9U= X-Received: from surenb-desktop.mtv.corp.google.com ([2620:15c:211:200:1bfc:e7ee:6530:4449]) (user=surenb job=sendgmr) by 2002:a17:903:2351:b0:175:58b8:cdef with SMTP id c17-20020a170903235100b0017558b8cdefmr4890777plh.30.1662053745409; Thu, 01 Sep 2022 10:35:45 -0700 (PDT) Date: Thu, 1 Sep 2022 10:34:57 -0700 In-Reply-To: <20220901173516.702122-1-surenb@google.com> Mime-Version: 1.0 References: <20220901173516.702122-1-surenb@google.com> X-Mailer: git-send-email 2.37.2.789.g6183377224-goog Message-ID: <20220901173516.702122-10-surenb@google.com> Subject: [RFC PATCH RESEND 09/28] mm/mempolicy: mark VMA as locked when changing protection policy 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@suse.de, 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, rientjes@google.com, axelrasmussen@google.com, joelaf@google.com, minchan@google.com, surenb@google.com, kernel-team@android.com, linux-mm@kvack.org, linux-arm-kernel@lists.infradead.org, linuxppc-dev@lists.ozlabs.org, x86@kernel.org, linux-kernel@vger.kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1662053746; 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=f3HBd//8MTEjGtUKjIJ6VlUao66B8ATA87dRitXKN6o=; b=BK47kD+N1z8eR4bz60BztQJVnHBJ6lkY0trcCt/XaqFahQ+2vSVZo9W0Irfm72wmvNEQGP CbhojOtXhgzmFqK6z7Otzoj+6tbU5BsTXjpiQp7Z9+9/yZFj3d+dcV0gdBTiuuUe0dlaPX oOc04I0haujpWSaYI9YPdPQDK0hK/jk= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=osN5P5u2; spf=pass (imf02.hostedemail.com: domain of 3ce0QYwYKCK4gifSbPUccUZS.QcaZWbil-aaYjOQY.cfU@flex--surenb.bounces.google.com designates 209.85.214.201 as permitted sender) smtp.mailfrom=3ce0QYwYKCK4gifSbPUccUZS.QcaZWbil-aaYjOQY.cfU@flex--surenb.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1662053746; a=rsa-sha256; cv=none; b=20hePyLWll4U0G8b/zrL4rOCYyW7ZE0whFw9vFR/GVSDWc9udson1kIyxRxPbiR6fbmFiR ba3zRnljZ6UgVFP2kgXRw5JnHH0Y0lyrXnd8twnP4OqUVcwjl91rDqzsyGPRTY4idYsmv2 jNspC+fwX6HPM/CiPp4tX/hJA8aZfcU= X-Stat-Signature: y5acm9xxtqsx4i9iec4cn7emh6fm1que X-Rspamd-Queue-Id: 9E9908005F Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=osN5P5u2; spf=pass (imf02.hostedemail.com: domain of 3ce0QYwYKCK4gifSbPUccUZS.QcaZWbil-aaYjOQY.cfU@flex--surenb.bounces.google.com designates 209.85.214.201 as permitted sender) smtp.mailfrom=3ce0QYwYKCK4gifSbPUccUZS.QcaZWbil-aaYjOQY.cfU@flex--surenb.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com X-Rspam-User: X-Rspamd-Server: rspam04 X-HE-Tag: 1662053746-387590 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: Protect VMA from concurrent page fault handler while performing VMA protection policy changes. Signed-off-by: Suren Baghdasaryan --- mm/mempolicy.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/mm/mempolicy.c b/mm/mempolicy.c index b73d3248d976..6be1e5c75556 100644 --- a/mm/mempolicy.c +++ b/mm/mempolicy.c @@ -383,8 +383,10 @@ void mpol_rebind_mm(struct mm_struct *mm, nodemask_t *new) struct vm_area_struct *vma; mmap_write_lock(mm); - for (vma = mm->mmap; vma; vma = vma->vm_next) + for (vma = mm->mmap; vma; vma = vma->vm_next) { + vma_mark_locked(vma); mpol_rebind_policy(vma->vm_policy, new); + } mmap_write_unlock(mm); } @@ -632,6 +634,7 @@ unsigned long change_prot_numa(struct vm_area_struct *vma, struct mmu_gather tlb; int nr_updated; + vma_mark_locked(vma); tlb_gather_mmu(&tlb, vma->vm_mm); nr_updated = change_protection(&tlb, vma, addr, end, PAGE_NONE, @@ -765,6 +768,7 @@ static int vma_replace_policy(struct vm_area_struct *vma, if (IS_ERR(new)) return PTR_ERR(new); + vma_mark_locked(vma); if (vma->vm_ops && vma->vm_ops->set_policy) { err = vma->vm_ops->set_policy(vma, new); if (err)