From patchwork Mon Mar 27 17:45:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Matthew Wilcox (Oracle)" X-Patchwork-Id: 13189760 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 540A5C76195 for ; Mon, 27 Mar 2023 17:45:35 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id CEF43900005; Mon, 27 Mar 2023 13:45:34 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C9F60900002; Mon, 27 Mar 2023 13:45:34 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B405C900005; Mon, 27 Mar 2023 13:45:34 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id A4BD1900002 for ; Mon, 27 Mar 2023 13:45:34 -0400 (EDT) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 48505AB993 for ; Mon, 27 Mar 2023 17:45:34 +0000 (UTC) X-FDA: 80615405388.08.D23E92C Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf24.hostedemail.com (Postfix) with ESMTP id 93072180021 for ; Mon, 27 Mar 2023 17:45:32 +0000 (UTC) Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=qZecYoGc; spf=none (imf24.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1679939132; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=sN2jldM9CY7aIkWwKeR1CK1+RammERB2ANKihvDELc4=; b=EoYPgYwYwqgHO1wrK+vxmZp/Pp5hNMe1sXF8YyC9QdqbQO2HznHTTJ8i3FI72vh2rtqqtt ALab6tnayBKvw5TJeNV3XEJpBR1c8SNPXbq9jUAswU17qili+2n+y/geHSd9LFPKwGWliT fqZQYfFm9+z1hSeFbXteWt/lBVD5ywI= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=qZecYoGc; spf=none (imf24.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1679939132; a=rsa-sha256; cv=none; b=xFjhSqdwGuhVgd6iNNYCXviGxomChxlHcJdqZq8pUyF3jNKFGntOt3AOMKwkj3Lc0mtWHo rMnRXi1jcCHw6XsoSB1X+AQPrb19gfuYScTCbHMCKm++YhAmOYfvUkFWjfvous+N8INyT7 249rhfa6+m+P4MFTDWBau+3FosAjjbM= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=sN2jldM9CY7aIkWwKeR1CK1+RammERB2ANKihvDELc4=; b=qZecYoGcykBbwmr7BQ73lsvQRL 7gZkBAEKJXtSnbFL1+kjXtQ9/BHx6ug9L2v458DCOq4fkXkxqUuFJ4CZ5M7L/GVgnHcLBQYhRBFC6 QWrfg+YCRq5wnEsDCbLZUN4kZSYirKyVwj0+KdtHTIXuD0om2HYLsfQhgcHrgVOgs5juAvishtQp0 VhctSXw8l3NyR8zrorbrBrgVMmqTFpSm2Bpvfy4H2Z4hLc7Jx5L4AmO8o6wcHhHgc8w7HvEUhJ24D 3Z9ZT4zFFIjhtTwiayCAFm1+6tWK5MycDRBzmsaxNAciKbdsiMxohtdQWGGc15DRYTUAP47SaXfGj Dspc/OhA==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1pgquI-007bGY-FT; Mon, 27 Mar 2023 17:45:22 +0000 From: "Matthew Wilcox (Oracle)" To: Andrew Morton Cc: "Matthew Wilcox (Oracle)" , linux-xfs@vger.kernel.org, linux-afs@lists.infradead.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH v2 3/3] mm: Hold the RCU read lock over calls to ->map_pages Date: Mon, 27 Mar 2023 18:45:15 +0100 Message-Id: <20230327174515.1811532-4-willy@infradead.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20230327174515.1811532-1-willy@infradead.org> References: <20230327174515.1811532-1-willy@infradead.org> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam03 X-Stat-Signature: wkqr9rfzx9fgqjmyx15myfbskssaebsj X-Rspamd-Queue-Id: 93072180021 X-HE-Tag: 1679939132-10782 X-HE-Meta: U2FsdGVkX1+sX53Ha0Abd90LcHfRAD+TO+LL/X1gvNcPkbwsauq5Z2UyqrBXXD3IBj66yYNyaShEYtsHHPhkuIQ2WuFz6Vj2UlHxYLYAJL19WJD1JRtql9pWBdwYabNHeeRG7YQq2ZQb6iwSX6mCzwt4VPYg2RxlcmIwtwPSGtCQqdLy8EimgSidXUF8BCCtavjB/p3MsE78miTW3kC89RqQC0u/XREqdcrjYsuN1PVf2p0KiPKHoJMqFelsnjzRDHQpg4kk0THJxXDjAD0qDzYLtmllkIP57Zm5f1Gxis6foMKDno7WVGWESJB0VNHfxmSRxN+2xZVcYCxiP3Yh0N6L8ruCYWzDw0VDMJwT5YvqrcjIB6EE3JUbSvU4gIjpmZkt/3adf+0/p4mXCdpGvUyeolD22Ewk0xAFm0/S8Vx4pbtZispdRh7taw7pRvOw9KLz93y6z4zbULebTp+uegBSaCuM1Y9cvwSOZkxITihSYVk6JaOfRM9FooktQgysuJ+IdnZCKgoqd98dYWRcuMkW5Uk5lKUdPjKq5QbyMY/o0axIqHDl/FtWLZ8Uo6wo3t0ZTBA3mO6jJbgmnA2XV03TbI3VYHxLOUEDVqAitDISUFKkSX/9GQxaPdEOEy+yNTfY17up9gzjJ+6BnSqQmS2JD6DRJz0bYaHa3k09OX3DVPOndv2Je2cKb7uQras9UVUo35HXFey1+bS8jPWJUrhn+THtgyj8vCiGZHwM54junTWagCHpDLyl7WJbjHQcO/46M3vhesamVcbxdmHctvBO3p25kmhMx4lO0WnuFMOKdcG+PyPhzyqqZBaRtYbt32aJVLhUYXjUCkn5GQMbDaTfd/2zi+CymfyFW6VKXcAJjnvde7q7vtMgmkyHI6i0M/P1tSvDgu1muSKQnDuQg4cGAyZin2WqbCTp4/SmLBIcw5tB/jsKksJIbSmqcTP5d/GTdLG9qHlbVZSz25S GMQRTU6S quPRsFLmitSZcJMw1zBIPhV1F5Fdnj6Cj6NgJzPxouqt+4USCpK/SHhguEY8tPE+elwyWk0NJ/zjaIrdsFnsQvVrcPjUCzXxCwJy25FGAujJqXaJYey15eCe0c9MV6Hb0pgwruWxfH6It6kRNTkCAIo/0jr54mVxIjBNgKLTtSuPKE3r7mWOiGVmjkw79matR7M/uauZ08p1vmEBTVNCSYJdryQ5bsEc5YDmTDB/h2YNnGhZbPe5GulrhmA== 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: Prevent filesystems from doing things which sleep in their map_pages method. This is in preparation for a pagefault path protected only by RCU. Signed-off-by: Matthew Wilcox (Oracle) --- Documentation/filesystems/locking.rst | 4 ++-- mm/memory.c | 11 ++++++++--- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/Documentation/filesystems/locking.rst b/Documentation/filesystems/locking.rst index 922886fefb7f..8a80390446ba 100644 --- a/Documentation/filesystems/locking.rst +++ b/Documentation/filesystems/locking.rst @@ -645,7 +645,7 @@ ops mmap_lock PageLocked(page) open: yes close: yes fault: yes can return with page locked -map_pages: yes +map_pages: read page_mkwrite: yes can return with page locked pfn_mkwrite: yes access: yes @@ -661,7 +661,7 @@ locked. The VM will unlock the page. ->map_pages() is called when VM asks to map easy accessible pages. Filesystem should find and map pages associated with offsets from "start_pgoff" -till "end_pgoff". ->map_pages() is called with page table locked and must +till "end_pgoff". ->map_pages() is called with the RCU lock held and must not block. If it's not possible to reach a page without blocking, filesystem should skip it. Filesystem should use set_pte_range() to setup page table entry. Pointer to entry associated with the page is passed in diff --git a/mm/memory.c b/mm/memory.c index 8071bb17abf2..a7edf6d714db 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -4461,6 +4461,7 @@ static vm_fault_t do_fault_around(struct vm_fault *vmf) /* The page offset of vmf->address within the VMA. */ pgoff_t vma_off = vmf->pgoff - vmf->vma->vm_pgoff; pgoff_t from_pte, to_pte; + vm_fault_t ret; /* The PTE offset of the start address, clamped to the VMA. */ from_pte = max(ALIGN_DOWN(pte_off, nr_pages), @@ -4476,9 +4477,13 @@ static vm_fault_t do_fault_around(struct vm_fault *vmf) return VM_FAULT_OOM; } - return vmf->vma->vm_ops->map_pages(vmf, - vmf->pgoff + from_pte - pte_off, - vmf->pgoff + to_pte - pte_off); + rcu_read_lock(); + ret = vmf->vma->vm_ops->map_pages(vmf, + vmf->pgoff + from_pte - pte_off, + vmf->pgoff + to_pte - pte_off); + rcu_read_unlock(); + + return ret; } /* Return true if we should do read fault-around, false otherwise */