From patchwork Thu Dec 21 13:23:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13501944 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 3B9D7C46CD3 for ; Thu, 21 Dec 2023 13:26:16 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2C9496B009C; Thu, 21 Dec 2023 08:26:11 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 278608D0029; Thu, 21 Dec 2023 08:26:11 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0CA0C8D0023; Thu, 21 Dec 2023 08:26:11 -0500 (EST) 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 EC5F06B009C for ; Thu, 21 Dec 2023 08:26:10 -0500 (EST) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id C56211C15DF for ; Thu, 21 Dec 2023 13:26:10 +0000 (UTC) X-FDA: 81590898900.03.DFB4891 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf06.hostedemail.com (Postfix) with ESMTP id 28BA6180017 for ; Thu, 21 Dec 2023 13:26:08 +0000 (UTC) Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=fPCn+GI+; spf=pass (imf06.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=1703165169; 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=Lo7aiJvCCD3HpSl6jVNRfFvoImcPzv/sQTt6KTq//FQ=; b=RFVpQd/yrLsMnI90teZCXw8LuLKiqAKzyO+bSlPW38Uxpxw4wa72IVbpDDBKEWsJst6MqS Tgx6B6AwpmS8+dRhYT51zNBJR7zpSpksU5AmxP2Nrlxzx2XesFYHGEpBbsBe9Rap9JDyea lPJ8gscLEK9gDUeUo7pjP/fLu3FdMtc= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=fPCn+GI+; spf=pass (imf06.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=1703165169; a=rsa-sha256; cv=none; b=kNS7XRNXC1um+G/Luc8YvdCjRHYs/9Fi928Dc6iK8wGGdwjxQ6p24VvuJzn7Kt9x0862Wu R4FQgb26Yquk9eP5eFhqNF1GE9kJlYymrQEC6tXFWJrk6xE1olEOjJGhHdy52TFL9L2q9t AN8wgUdWkGQve602CENwWQQNb1/rnEI= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1703165168; 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=Lo7aiJvCCD3HpSl6jVNRfFvoImcPzv/sQTt6KTq//FQ=; b=fPCn+GI+ZlA3gt5CsTMlxf4AZW06YBe7shhyJ0okOcCdtM7bAUDsRGis3WBKQO9ZBq98kb K27ObfzWTu7fY+MZlLLzhcO6vRYzFQpfx3d0pNfAlxHqk2Oh7H87JPjmlt7Do5gecfkM9M NwpSUHHCp/nSi5ElvPANqGVEjY2Cf5U= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-284-iLvM_qjVNmCc3BKo7CvF9A-1; Thu, 21 Dec 2023 08:26:04 -0500 X-MC-Unique: iLvM_qjVNmCc3BKo7CvF9A-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id C70CE3C000BD; Thu, 21 Dec 2023 13:26:03 +0000 (UTC) Received: from warthog.procyon.org.com (unknown [10.39.195.169]) by smtp.corp.redhat.com (Postfix) with ESMTP id E1C452166B31; Thu, 21 Dec 2023 13:26:00 +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 , Eric Van Hensbergen , Ilya Dryomov , Christian Brauner , linux-cachefs@redhat.com, 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 Subject: [PATCH v5 31/40] netfs: Allow buffered shared-writeable mmap through netfs_page_mkwrite() Date: Thu, 21 Dec 2023 13:23:26 +0000 Message-ID: <20231221132400.1601991-32-dhowells@redhat.com> In-Reply-To: <20231221132400.1601991-1-dhowells@redhat.com> References: <20231221132400.1601991-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54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33/zf2EDKXmFKFUGXTbHWyEscM VOLQVOMY Ycq7vtpXK/qSxkeE97w+UV2xC8sTyphCPAptKa3fGzZwgrWbRp3omidY4rycKy3QIs6pK8CatJls4AksQuSPereMCy3CmA6VsazYiiIeIRIYUYTXpUpwuhFuwskRp/ib/M33TBrLs5aftjLBvGDwWXGPR0Y9njY+E2ZqIfvLd56DycDJAwxHoosr7OkK2NwC+/EkZktMMGBa52yFYqwBHlBp/gyB+wI92hp7WWX4dUz9V4MvIDhyGjGj6Hovq+G8vgNS9X/h4Jrs8cxWOePLnHHmOIWNHWC3uOwK5r1kRGdYH5byBu7wB/JOV/Aih5rHDOUw8LwM3JkK7Tjcmm3ZGLUpVew== 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: List-Subscribe: List-Unsubscribe: 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 Reviewed-by: 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 f244123ab568..70cb8e98d068 100644 --- a/fs/netfs/buffered_write.c +++ b/fs/netfs/buffered_write.c @@ -416,3 +416,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 5c225f308704..e444f814dd56 100644 --- a/include/linux/netfs.h +++ b/include/linux/netfs.h @@ -401,6 +401,10 @@ void netfs_clear_inode_writeback(struct inode *inode, const void *aux); 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);