From patchwork Fri Oct 13 16:03:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13421171 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 7EFB8CDB47E for ; Fri, 13 Oct 2023 16:06:41 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6790C80020; Fri, 13 Oct 2023 12:06:18 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 6285580022; Fri, 13 Oct 2023 12:06:18 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4A25180020; Fri, 13 Oct 2023 12:06:18 -0400 (EDT) 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 256D380022 for ; Fri, 13 Oct 2023 12:06:18 -0400 (EDT) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id E4E5E1A0340 for ; Fri, 13 Oct 2023 16:06:17 +0000 (UTC) X-FDA: 81340915194.24.1BC83FC Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf08.hostedemail.com (Postfix) with ESMTP id D431016001A for ; Fri, 13 Oct 2023 16:06:15 +0000 (UTC) Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=YfRr0ZNq; spf=pass (imf08.hostedemail.com: domain of dhowells@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1697213175; 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=e01HNtHrdecUenuf00QKZmcqLnF1Z0lVkw33nPqTUEg=; b=Q0fCkSrtjf4qwjugphKTNTpU8snp80TbaSDHxAKgLX+Vv976WsX6XF6fRW7pYnbtpBFqG7 ys+trgvA0HjlLk4nQw4z9ge+Tq421hr6EhIqTGOoCiNPSI1jnGWjq4wn9ZZ3W6M8PWZ5OV pN1VAASeKmEXfOEGYsFTIcvfgTTmuj8= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=YfRr0ZNq; spf=pass (imf08.hostedemail.com: domain of dhowells@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1697213175; a=rsa-sha256; cv=none; b=mN4XZXI5nXNCluxXtRGFZtbnoxDDfjyNgwlaGc5kMRspEJLvBCN/Jxt8vkIjCUvDgz++M4 vVh7aJanYYHafUaTzF+vahReaOlGMWKi3odv4lKDwF6c5txSSezM7I2kZzTAb7L6HuUa0g YC+8wIk89JSG4VFNWedxuMKy5C9Xrzk= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1697213175; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=e01HNtHrdecUenuf00QKZmcqLnF1Z0lVkw33nPqTUEg=; b=YfRr0ZNqZwAetTLIOpXSfnY7lZeyoGGAID2bxhfL0ogOvpSzBzp6i5Tht09E4PcHp49YIr hMYgsVyEcK1Q2hkQfdX1agWI+4/Oe152ee59qGMEuHZ070ARx9L+o/aTToiwk7l1A3cDo9 8vwD8w03JxzA7Vf0dY8/Mvxd/RqhJcM= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-52--Lg_vaN0O_OFZFocB3Q5SA-1; Fri, 13 Oct 2023 12:06:13 -0400 X-MC-Unique: -Lg_vaN0O_OFZFocB3Q5SA-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id EBC66858280; Fri, 13 Oct 2023 16:06:11 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.42.28.226]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6B2651C060DF; Fri, 13 Oct 2023 16:06:09 +0000 (UTC) From: David Howells To: Jeff Layton , Steve French Cc: David Howells , Matthew Wilcox , Marc Dionne , Paulo Alcantara , Shyam Prasad N , Tom Talpey , Dominique Martinet , Ilya Dryomov , Christian Brauner , linux-afs@lists.infradead.org, linux-cifs@vger.kernel.org, linux-nfs@vger.kernel.org, ceph-devel@vger.kernel.org, v9fs@lists.linux.dev, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-cachefs@redhat.com Subject: [RFC PATCH 30/53] netfs: Allow buffered shared-writeable mmap through netfs_page_mkwrite() Date: Fri, 13 Oct 2023 17:03:59 +0100 Message-ID: <20231013160423.2218093-31-dhowells@redhat.com> In-Reply-To: <20231013160423.2218093-1-dhowells@redhat.com> References: <20231013160423.2218093-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.7 X-Rspamd-Queue-Id: D431016001A X-Rspam-User: X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+7cqlP0KlgaNd2RT3qqp269Wnqnh7XoXWDjjhKwWEz+q2fMYrixxf/aDMBhRnmD/ECSimW7TIOt75jT2MschM7EEIntdxF41tBt2w6O5Amqa18So52GfTSwZz2LeypNFkS/xVUhI75sGHxlCJX3my5BSNg2vCaxRPG4wulD5izryNrPZqmb4+U+JhyxYRynkmtnTx0jcALCRpeKOMjcQIcEl7MIqoIYbvuaFBEp0LE//1mmDb6BogtOfc7DOUnOi0xmfnMQoFAFnfmgnY+k6oIeRaer8ccl7ebaOtVYH005JLRi251yYJQucOitYM3TkE2Rw== 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: Provide an entry point to delegate a filesystem's ->page_mkwrite() to. This checks for conflicting writes, then attached any netfs-specific group marking (e.g. ceph snap) to the page to be considered dirty. Signed-off-by: David Howells cc: Jeff Layton cc: linux-cachefs@redhat.com cc: linux-fsdevel@vger.kernel.org cc: linux-mm@kvack.org --- fs/netfs/buffered_write.c | 59 +++++++++++++++++++++++++++++++++++++++ include/linux/netfs.h | 4 +++ 2 files changed, 63 insertions(+) diff --git a/fs/netfs/buffered_write.c b/fs/netfs/buffered_write.c index 60e7da53cbd2..3c1f26f32351 100644 --- a/fs/netfs/buffered_write.c +++ b/fs/netfs/buffered_write.c @@ -413,3 +413,62 @@ ssize_t netfs_file_write_iter(struct kiocb *iocb, struct iov_iter *from) return ret; } EXPORT_SYMBOL(netfs_file_write_iter); + +/* + * Notification that a previously read-only page is about to become writable. + * Note that the caller indicates a single page of a multipage folio. + */ +vm_fault_t netfs_page_mkwrite(struct vm_fault *vmf, struct netfs_group *netfs_group) +{ + struct folio *folio = page_folio(vmf->page); + struct file *file = vmf->vma->vm_file; + struct inode *inode = file_inode(file); + vm_fault_t ret = VM_FAULT_RETRY; + int err; + + _enter("%lx", folio->index); + + sb_start_pagefault(inode->i_sb); + + if (folio_wait_writeback_killable(folio)) + goto out; + + if (folio_lock_killable(folio) < 0) + goto out; + + /* Can we see a streaming write here? */ + if (WARN_ON(!folio_test_uptodate(folio))) { + ret = VM_FAULT_SIGBUS | VM_FAULT_LOCKED; + goto out; + } + + if (netfs_folio_group(folio) != netfs_group) { + folio_unlock(folio); + err = filemap_fdatawait_range(inode->i_mapping, + folio_pos(folio), + folio_pos(folio) + folio_size(folio)); + switch (err) { + case 0: + ret = VM_FAULT_RETRY; + goto out; + case -ENOMEM: + ret = VM_FAULT_OOM; + goto out; + default: + ret = VM_FAULT_SIGBUS; + goto out; + } + } + + if (folio_test_dirty(folio)) + trace_netfs_folio(folio, netfs_folio_trace_mkwrite_plus); + else + trace_netfs_folio(folio, netfs_folio_trace_mkwrite); + netfs_set_group(folio, netfs_group); + file_update_time(file); + ret = VM_FAULT_LOCKED; +out: + sb_end_pagefault(inode->i_sb); + return ret; +} +EXPORT_SYMBOL(netfs_page_mkwrite); diff --git a/include/linux/netfs.h b/include/linux/netfs.h index d1dc7ba62f17..e2a5a441b7fc 100644 --- a/include/linux/netfs.h +++ b/include/linux/netfs.h @@ -403,6 +403,10 @@ int netfs_write_begin(struct netfs_inode *, struct file *, void netfs_invalidate_folio(struct folio *folio, size_t offset, size_t length); bool netfs_release_folio(struct folio *folio, gfp_t gfp); +/* VMA operations API. */ +vm_fault_t netfs_page_mkwrite(struct vm_fault *vmf, struct netfs_group *netfs_group); + +/* (Sub)request management API. */ void netfs_subreq_terminated(struct netfs_io_subrequest *, ssize_t, bool); void netfs_get_subrequest(struct netfs_io_subrequest *subreq, enum netfs_sreq_ref_trace what);