From patchwork Fri Nov 17 21:15:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13459585 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 721ECC54FB9 for ; Fri, 17 Nov 2023 21:17:51 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A17FA8D0053; Fri, 17 Nov 2023 16:17:50 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 9C71F8D001C; Fri, 17 Nov 2023 16:17:50 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7F2F08D0053; Fri, 17 Nov 2023 16:17:50 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 69AE28D001C for ; Fri, 17 Nov 2023 16:17:50 -0500 (EST) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 426A31CB1AB for ; Fri, 17 Nov 2023 21:17:50 +0000 (UTC) X-FDA: 81468708300.17.0BC9BF6 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf11.hostedemail.com (Postfix) with ESMTP id 847654000C for ; Fri, 17 Nov 2023 21:17:48 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=ORo8jBwa; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf11.hostedemail.com: domain of dhowells@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1700255868; 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=njtooIaoqHtxOz+7Ms2cQooTNH6njUKNcTP7iunfXh8=; b=T8CcQvcTpdDVzv5dpW7iIx6QdbXQ3JrVIS8+HgTDU8zWfCdQiaaiwC6CbW9npmS3OpAAPo 5lB1GuV+mj/OtcSR75byWIPUru+mZ+ag/GQW1mbLWO8Tgu+28RAilgPeb7t9sBLv7u0aeS Mrqg2wV1KKSmRjmIMv6eGZHA1n2XLO0= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=ORo8jBwa; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf11.hostedemail.com: domain of dhowells@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1700255868; a=rsa-sha256; cv=none; b=P7h5+JhJnhOCp83CtwKZLBxAoXwlF+mbUM9OcZ6Y6+qKiYeQqmuGsaY6DPaiJAVKPi4g2p rQLJtEealyEIYZ6GV0YRxjPgZ43wedNPiTcytaf7nD8l8jzyKRwUFENjXJM8eKDN7fed8c Ov2WhhD6FfzjH7RpTDOL9T/anHh7AWs= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1700255867; 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=njtooIaoqHtxOz+7Ms2cQooTNH6njUKNcTP7iunfXh8=; b=ORo8jBwa04P35iQW8AV/qqfRBTEjk26nbYl8eA3LDZ8Fa6uh7rLYcs3aXp6efDzO2AZoDo lOmuS76OmgQVJ2hQPc7W/f2KJJa+lRPt8VtqoQBKeZuZgQAEt5XzS/p+ylA76OvEgZ6r83 rJi+tAyUsQSCWbq+gC6NRDkCaps2D94= 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-472-1TtKUSzjOcS24bYRIYVe3A-1; Fri, 17 Nov 2023 16:17:44 -0500 X-MC-Unique: 1TtKUSzjOcS24bYRIYVe3A-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (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 457B328040BB; Fri, 17 Nov 2023 21:17:43 +0000 (UTC) Received: from warthog.procyon.org.com (unknown [10.42.28.16]) by smtp.corp.redhat.com (Postfix) with ESMTP id A789DC15881; Fri, 17 Nov 2023 21:17:40 +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-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 v2 28/51] netfs: Allow buffered shared-writeable mmap through netfs_page_mkwrite() Date: Fri, 17 Nov 2023 21:15:20 +0000 Message-ID: <20231117211544.1740466-29-dhowells@redhat.com> In-Reply-To: <20231117211544.1740466-1-dhowells@redhat.com> References: <20231117211544.1740466-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.8 X-Rspamd-Queue-Id: 847654000C X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: j6q8xzyqxieaf3gxaooiurc1k73cefsq X-HE-Tag: 1700255868-746442 X-HE-Meta: U2FsdGVkX19yVKQMvCp33YaBndrbWpSBLs8xF9JGuodvlcLnWpzUTrgyaSaoN/1po4YpO7cfF6DV7cILsQsckIuZ+bWmy0QnHz60U7uY1oY1WlXUWeQZJIxkWaIAPQlLAkOz0KkALu6NK8LtoOHrFw6uNmrv8yGvXnWh97zrOD5QRPlsVMjKATTKSCTjDHfe1ujKnPvd1eJ8Y+I4yC/1kqxwWHsxVkqPqwp53RZYsWPaEAZ9/M6se0UyV38mEJgqY24EAfTADJz2wWQaiRTqoCRx6K+yj31ySM59QsVIDonnLqoYL8mweNDXBJM6X97UXPry2yy9+aHDJQIuFPrg4Scz5HH+NHPZeQKXUWha4F/76Z0StCCEPh9ECIn5Ita8LvnrIffXsg6gztifxXLPa8og/Q/eJua+QnT25aPfA/26EHl6Sf+OSZKhpqY4HzLSTKCRZdY5RL0LDgqbXgzIs2MB3Utlgw2x0izNMnUBMoYzhePz5b6FDtzGK9KAd7BYrPNaiGiRzdMesskCVg0+im5LN3v6fjTCnvjwLPe3OFqepjgyowQxyvnNIu5qheYoMwDRsizYQ3RUrDGNuJJyvavQsXvqxTcGZ+ba/foEmv2s1pF047Y6dFdFIRNYfQ+ZmCqZWmd23XugqfBjNaVnNMFnnC0wzEfxN/v4lGQqIpS+MOR8gCDHJ5QWnmebENbigK23VUhORJUNTVxzIEMnaCxA9EPkJBeJODNLzB5jxuQhG0Kmx8AJJi7W5fv4dUjNJnX8PN8Gt0RKWSek0qU1RFZs38c2kKJ5Q2p291++/z7FgIibvJeUd08iNLH5p1KvWBOgj8SVMoMcvJDqWhQZac5gBk1z67VdSocraW+/a53IlV8n/GYr/SXVnD42qB7NDlAAFys+OCTomBH3D48NMJJN9KzA/r0iBKu+aRYrSX20/B9INmDrFgC+BI8xim5qMPwxicMmam+Knx3/buS 1Xbu+eos EAUhK/OCT+oAa0kGk4nFYhXy4U3QgWUBRxtmvmQDDCTIc6V2luFlW3dpEx4EH85o1IEQBP5cbZ6j+t2x7KoiMN3tX0tByaZwvIKFHgI8bIDrb9DxdmH7mQuZDa7IQBd+RVq9bFFbo8kuJXD7u8kCuDcrjLUJwnyVGpn1Jza3wSHfEW9kkr6PXB3InAmPthmZ7sbxOHpJvYmc3aWwgovmyxTjCmag+2cWar5I5e5RoodUR3nmfOGrZh2fe5U7BOn3y8S7I+TCYNB51zqUFgJOt5MW/aZXBM0g03ZIsBaQUQEF/RCOVgUaejWpMagsYzHsjOaanuclOlzcs0XZooannkW03Bw== 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 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 4cdadd1ce328..80e48af8b72f 100644 --- a/include/linux/netfs.h +++ b/include/linux/netfs.h @@ -404,6 +404,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);