From patchwork Mon Mar 27 17:45:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 13189758 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 2E5D1C76195 for ; Mon, 27 Mar 2023 17:45:32 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5DD26900003; Mon, 27 Mar 2023 13:45:31 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 5C2B7900004; Mon, 27 Mar 2023 13:45:31 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 48A6E900003; Mon, 27 Mar 2023 13:45:31 -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 38DC3900002 for ; Mon, 27 Mar 2023 13:45:31 -0400 (EDT) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 102971C619B for ; Mon, 27 Mar 2023 17:45:31 +0000 (UTC) X-FDA: 80615405262.18.12BA2B7 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf03.hostedemail.com (Postfix) with ESMTP id D4DA52000F for ; Mon, 27 Mar 2023 17:45:27 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=CKZEq1db; spf=none (imf03.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=1679939128; 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=fIu8B1m7y8UbXtnikmeJqrXTu7pczz9sY+BTw0TDSzU=; b=kI65/MhytCIBNRdJpUPlAf1bO0qlglRfummp3ol91arJKuuRSpmMdfXQw7LycvCZNrH01c Krn+MlEUxeNAVA6dFMxOyn+s+GJSWlpfcf1/+w6tk2sat1AKy7QYnPi79PHOoKQ72Oh4Bs mZTWyKBR820WaAj4cbbi1X1O7A/rfsM= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=CKZEq1db; spf=none (imf03.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=1679939128; a=rsa-sha256; cv=none; b=4Ovlo48bzi7O1taVFGE8MKmAVFeDFHgYP1AZajlx6w5pR04uFD8AXcnwG7k9uHjW+HqNLe xGb9ZIByf3jvJCOxzWFRqSfGAy/a7RS0MLadP4fcVVjSly85wvTa5FBfYs0vuJ70QalZpL Ca7vQ1Cq0cb0Jo+D925X7X9aig1fb5w= 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=fIu8B1m7y8UbXtnikmeJqrXTu7pczz9sY+BTw0TDSzU=; b=CKZEq1dbnw8YiG6UxQX5giGqXs b9qOE9hP4Zc+UTvy3UaWf9zFtTwqx+oPjlM6oYJZ+pjwcvBhQVO9urgYaxU378GSBu8PsOwkXiF2A P4w04/3X/Fk1dY8qO8rC5ABsCZ7tFnh7uVzkv62LsGUGSEU/ICt9/0nUVB4km/SkSgNgS4BL+TAzC I4/GoC4sgAfZcX7tK4aIIKfdPPPTJFpJSW94ooUXmGFjYrE5T3cpYJG7HES7h2QaDy3NFlDwcgp3O TsA8xaG1nVozZmC/WGOlhUKJiumhksvu+7CChPzNidOSqJ41toO1BytsA5c0/aUS1F1bhyv5WDQRu uZdUAbvA==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1pgquI-007bGU-9o; 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 1/3] xfs: Remove xfs_filemap_map_pages() wrapper Date: Mon, 27 Mar 2023 18:45:13 +0100 Message-Id: <20230327174515.1811532-2-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-Stat-Signature: 457xd77ghjsd64ca4wpkz89buhgjqan4 X-Rspam-User: X-Rspamd-Queue-Id: D4DA52000F X-Rspamd-Server: rspam06 X-HE-Tag: 1679939127-836864 X-HE-Meta: U2FsdGVkX1+Yi0MqtgbL8cdkF1RLKgTQpJK6N9t+CdRY12HoVMO+p91Cc5Z0r89BNLnBdB6O4dogUPb2eJrVakcrJNhuefliOODbfoYX+QaD5GXV9IThwZiTMMfXEGpmAKrrvc+LB8r3v2Q/Fvj3Da5ALRnE3RWRA9vNNvRPxPw/Giub9MEwrMXypVNCI/VHg7SpsnNzieM86BfUbRB1u5OCUj0BLe6pBuSl07wMyAYznoNHI6fW0Zy5+prUn1CxYw2sXsDzUe35JSv0pBOltG/UHqVnLb0LJeLuWAdrAWt4rD7ttiBRylNEUJPZPsaamqAwN7dYd45xy0MduaboW1cJCEqgZ0iS6NYlQECVzLB1EK7ZFqbt0bcdu4rCSew61Yq9Mu/7GnAh5m39Q/J8VDwx5OaRYyPgvf0EEboA0+WxX5fEdKvMCVgzuOmqx7GNUwKWr28cFeilOZQVcuKsb0/NB1xbJrGqKRaSwyFZ3sjN9sNhZSbhMQZREirZREvQkHtbkbGVbruD+yVrfsGG8KIOBpHtaUlwRimchHCzegR0cO+bAn8+UGAkXS383TCMaxKa8CMp2OR9xagFJgqIL/ghMUATTgzR5x5SXp3szlxk01eKkElgkIagCuehd20ftfs0utyP1YudzUdI0D0LAZ5bR0lLy1SLYldbvq6HaHW3XZmTF/qv50jWHiop+5cS5lMORYTUT3pKrSyfsEAndwWNvNS4EMJI/Gyn+/RwrUX1CkPl41NjBBwXgNCS8mt2HadDVAJs2AuP+lDvMGsjKGtUN9VaxGpsbSAmum45slFpvZDvOzg1OPfppFXThLbpZlV/oucuBjrvHpw1xaZH7OfXz5tCZ1LdCypTFVULVQDd04B0gh3UxYqwxQBBIn683beUy3GHYadJwO4f5V6QK57VrGxgTLdWeI/uPmCkNzY1CQefuPh3nAMJaZfudPEO/eYWLJ/vteyvI/+MBCw KTQ3zxWB pl2da1W+brdeGL/jPmyWwC79ARF7Qg64MvoChPHthVxvJ73Bu+VdfSB+JK2wP1tUmAxuxURJ1U+8lz8nbaHzqycprvBqI38f654iaK4D9or4rZXi4n+AMadPdSvECgjIk+D74D+7GEy9pDpBGPfCsKoV3JA66E7zKTh5+TGJK5JaejmsO5Fi0tKKarp0zqTlFbYDX+2Mu7a0qiu8is18pEWZpxS5VqesVwWNK+P8BnfUKjfkHeoEd09gzwg== 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: XFS doesn't actually need to be holding the XFS_MMAPLOCK_SHARED to do this. filemap_map_pages() cannot bring new folios into the page cache and the folio lock is taken during filemap_map_pages() which provides sufficient protection against a truncation or hole punch. Signed-off-by: Matthew Wilcox (Oracle) Reviewed-by: Dave Chinner --- fs/xfs/xfs_file.c | 17 +---------------- 1 file changed, 1 insertion(+), 16 deletions(-) diff --git a/fs/xfs/xfs_file.c b/fs/xfs/xfs_file.c index 863289aaa441..aede746541f8 100644 --- a/fs/xfs/xfs_file.c +++ b/fs/xfs/xfs_file.c @@ -1389,25 +1389,10 @@ xfs_filemap_pfn_mkwrite( return __xfs_filemap_fault(vmf, PE_SIZE_PTE, true); } -static vm_fault_t -xfs_filemap_map_pages( - struct vm_fault *vmf, - pgoff_t start_pgoff, - pgoff_t end_pgoff) -{ - struct inode *inode = file_inode(vmf->vma->vm_file); - vm_fault_t ret; - - xfs_ilock(XFS_I(inode), XFS_MMAPLOCK_SHARED); - ret = filemap_map_pages(vmf, start_pgoff, end_pgoff); - xfs_iunlock(XFS_I(inode), XFS_MMAPLOCK_SHARED); - return ret; -} - static const struct vm_operations_struct xfs_file_vm_ops = { .fault = xfs_filemap_fault, .huge_fault = xfs_filemap_huge_fault, - .map_pages = xfs_filemap_map_pages, + .map_pages = filemap_map_pages, .page_mkwrite = xfs_filemap_page_mkwrite, .pfn_mkwrite = xfs_filemap_pfn_mkwrite, }; From patchwork Mon Mar 27 17:45:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 13189759 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 DA559C6FD1D for ; Mon, 27 Mar 2023 17:45:32 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8F78B900004; Mon, 27 Mar 2023 13:45:31 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8CED6900002; Mon, 27 Mar 2023 13:45:31 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 74D58900005; Mon, 27 Mar 2023 13:45:31 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 53100900002 for ; Mon, 27 Mar 2023 13:45:31 -0400 (EDT) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 2A274160591 for ; Mon, 27 Mar 2023 17:45:31 +0000 (UTC) X-FDA: 80615405262.13.845AB33 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf25.hostedemail.com (Postfix) with ESMTP id 744B1A000E for ; Mon, 27 Mar 2023 17:45:29 +0000 (UTC) Authentication-Results: imf25.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=lf+sGi73; spf=none (imf25.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=1679939129; a=rsa-sha256; cv=none; b=yzyrJZg3KO1athzzA0zHsH4tGFOgLo2ukTK4JIB9NpatLqvkmXIzxsuNtzIeNBIlPBhDcT 1u3jgngGxGlAbcmMMigG8oW4lZmTuklZHDGYv27lEDjyYEJWHks1yw/ag2U7lVel1gKlIV PaU+N1FnxE7WFUzp4HDI11SLklvh81E= ARC-Authentication-Results: i=1; imf25.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=lf+sGi73; spf=none (imf25.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=1679939129; 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=GAyshjmKzZkCN3bMmDoTxHf/sR0cear/9s9hk1TbP0k=; b=1uGD9tPvaFVoF9Y71pwFOdCWtYTjqdUVCehTS8mKnk4fs7dqswwBG9SRWw8sOmjUacDtFL OlsrWKhu+Cx7neCdhcjHW4mCC/ZMieMoVLL7wdgrCdnw9nrDVcv9UDYmPKzjzMALY+vPQV xC3zHyWe6GvVOBZ6jWc0jwrA3ynxaEs= 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=GAyshjmKzZkCN3bMmDoTxHf/sR0cear/9s9hk1TbP0k=; b=lf+sGi73/ao9HbjaotBl2pVUzS pHH+wy60rrUFTqs+ErZYZmfjokJg2KXASQ+LmXKQy0XUSYzLIxvDDEwx6xSN7FNyAH+SsfFei0bID 3S6nHNMDJuUoZblr82s8LNGOzLzyA0XAt5qx092xMNkJQ2gKXS5prSE0iQ+2BOztSnlhDFZi+Lm+7 ONzWtkKoNSC9uFiMfvXkS/DOEgqJw3Kb4NovLp+d3T9dvyrz1fVXw0tVDxktZuOCskGIG4Ftv90UH a306skCf2SweTCGwfoQxnWcS0xKPlj/el+ecfNH3Xj8ZXE2+n+06FaOrPA7n1DHTk1OQ/va8IiawA asZPxL9g==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1pgquI-007bGW-CW; 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, David Howells Subject: [PATCH v2 2/3] afs: Split afs_pagecache_valid() out of afs_validate() Date: Mon, 27 Mar 2023 18:45:14 +0100 Message-Id: <20230327174515.1811532-3-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-Queue-Id: 744B1A000E X-Rspamd-Server: rspam01 X-Stat-Signature: mgr4nkij1zc6xx7hqdcq17wguc9ktsed X-HE-Tag: 1679939129-536527 X-HE-Meta: U2FsdGVkX1/G0J2TRnrRQv203eWyME6dJsKJvIBIdhS0zhHQXmKt3ghbHvcm5idZoR3vJ3jGCT8KudCEw89C3N7Gx7sWa6q/ZJvu8ympIDGueT/3NtAy29qhj+08+ggsN2xFTAtWHZOMDHOTNdDeW3nZJCA7aDppkt0nankhFxyLHTtVdEg4TpHOYT/XbLnwVYd4089Pfib1MpEUZ5es17lFbLppYiC+9HnbsbAOgEc1MT9DDj3PVckHUHVHCYZlSU0bvrNFahjfV+iEakSSm+btEepzLRqUlNar2YKx0VysKSKYIRTBY43tcwXpbKW3YLxL/uQQ1G6V3Fhyeqot1etmFCkRQ943ZK6QWFTlq8Z+a6fQ/3Cc3qCMuqvETB2iIbop/ZayAHnmyxjw/sSy+qb2JQVvSl9LiAofxMMXJLEjORXEMAOJPtFQ5soUgK8z3Ov4n1wxyWv3fPPeSitXYDPPR+hACmxZF8hm2nDSHVH+0iOwTEgMINfse1HoTcsr5bVjdjC/shgaS80PO8wT75dG5OeBe+Ps3vYcQ+CKux6htItRTpvh0vMAhUa5XfgE1/wrhyMTK8ED/xvM9aXiepxAjDm72a65S9QxKp84D00H+fJFFzTAuHzEldQXZzH6zkAo1Nq1LsNg5uyJk3PjPON+UAIvxlEm9iMbnzHH/6fI2KCG7G3g3RTjVedmMXAQG/SvXuqfdytZLBKceTlS0bq/PPxMQRNIzpnTGhJz2iADzuC3TzrdMAc8Ub+6r8ozsXYdgo3GNhhEnO1KAAE+4g4TFs2Ia7o9YzAq5UIyysUlAiHcpG9N8p06WywBK2EXLBPw+Ay/GxDKC8HWV+KYOwW1/chRk/dWFkexZHD3S2YrbhHvLRahDfVh/sNC0tn3suTdl0l+MU3YomEDh5Fy0NL/yWpxxtomppXcmNDpbqy8LdDlUkrj4mryrzPrZIlHDybN2S+UwkCl51FsSML KeLcL0SV RcL2rlfDWLekK6GHd58SaWr5JR6s5L1E3oCJbIx4cRzTHW+xFREzo0VDGn7mH9aNhpVU4T+9Hobe4WRA37TvLZgEkyImMq3jbgcS8AbPPQsDmMx4F2EvAqnEVtfcasG5kXGWqJMkQVUs73fWQmdc/e8cCXR/g00zQA2O4fO/Aq4n/QXKJsA9Igumxk8/BYxndpFcKYQwPFij4148/EJYpkBUgcbbtrTmradhLFdJjTKPInc6oR/GMzjNYVpeaSN5T66/KolkBr6Z1AFE= 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: For the map_pages() method, we need a test that does not sleep. The page fault handler will continue to call the fault() method where we can sleep and do the full revalidation there. Signed-off-by: Matthew Wilcox (Oracle) Acked-by: David Howells Tested-by: David Howells --- fs/afs/file.c | 14 ++------------ fs/afs/inode.c | 27 +++++++++++++++++++-------- fs/afs/internal.h | 1 + 3 files changed, 22 insertions(+), 20 deletions(-) diff --git a/fs/afs/file.c b/fs/afs/file.c index 68d6d5dc608d..719b31374879 100644 --- a/fs/afs/file.c +++ b/fs/afs/file.c @@ -569,20 +569,10 @@ static void afs_vm_close(struct vm_area_struct *vma) static vm_fault_t afs_vm_map_pages(struct vm_fault *vmf, pgoff_t start_pgoff, pgoff_t end_pgoff) { struct afs_vnode *vnode = AFS_FS_I(file_inode(vmf->vma->vm_file)); - struct afs_file *af = vmf->vma->vm_file->private_data; - switch (afs_validate(vnode, af->key)) { - case 0: + if (afs_pagecache_valid(vnode)) return filemap_map_pages(vmf, start_pgoff, end_pgoff); - case -ENOMEM: - return VM_FAULT_OOM; - case -EINTR: - case -ERESTARTSYS: - return VM_FAULT_RETRY; - case -ESTALE: - default: - return VM_FAULT_SIGBUS; - } + return 0; } static ssize_t afs_file_read_iter(struct kiocb *iocb, struct iov_iter *iter) diff --git a/fs/afs/inode.c b/fs/afs/inode.c index 0167e96e5198..b1bdffd5e888 100644 --- a/fs/afs/inode.c +++ b/fs/afs/inode.c @@ -667,6 +667,24 @@ bool afs_check_validity(struct afs_vnode *vnode) return false; } +/* + * Returns true if the pagecache is still valid. Does not sleep. + */ +bool afs_pagecache_valid(struct afs_vnode *vnode) +{ + if (unlikely(test_bit(AFS_VNODE_DELETED, &vnode->flags))) { + if (vnode->netfs.inode.i_nlink) + clear_nlink(&vnode->netfs.inode); + return true; + } + + if (test_bit(AFS_VNODE_CB_PROMISED, &vnode->flags) && + afs_check_validity(vnode)) + return true; + + return false; +} + /* * validate a vnode/inode * - there are several things we need to check @@ -684,14 +702,7 @@ int afs_validate(struct afs_vnode *vnode, struct key *key) vnode->fid.vid, vnode->fid.vnode, vnode->flags, key_serial(key)); - if (unlikely(test_bit(AFS_VNODE_DELETED, &vnode->flags))) { - if (vnode->netfs.inode.i_nlink) - clear_nlink(&vnode->netfs.inode); - goto valid; - } - - if (test_bit(AFS_VNODE_CB_PROMISED, &vnode->flags) && - afs_check_validity(vnode)) + if (afs_pagecache_valid(vnode)) goto valid; down_write(&vnode->validate_lock); diff --git a/fs/afs/internal.h b/fs/afs/internal.h index ad8523d0d038..5c95df6621f9 100644 --- a/fs/afs/internal.h +++ b/fs/afs/internal.h @@ -1171,6 +1171,7 @@ extern struct inode *afs_iget(struct afs_operation *, struct afs_vnode_param *); extern struct inode *afs_root_iget(struct super_block *, struct key *); extern bool afs_check_validity(struct afs_vnode *); extern int afs_validate(struct afs_vnode *, struct key *); +bool afs_pagecache_valid(struct afs_vnode *); extern int afs_getattr(struct mnt_idmap *idmap, const struct path *, struct kstat *, u32, unsigned int); extern int afs_setattr(struct mnt_idmap *idmap, struct dentry *, struct iattr *); 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 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 */