Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp5392570rdb; Wed, 13 Dec 2023 07:28:57 -0800 (PST) X-Google-Smtp-Source: AGHT+IGJG2lsJ4+7dd2x/WRR0Y8rl8DRofYHfLYbMsNeNdKzZrprmlhSojYpyw0rXCuPjlCKSTJd X-Received: by 2002:a05:6a00:9388:b0:6ce:2732:278 with SMTP id ka8-20020a056a00938800b006ce27320278mr4574917pfb.39.1702481337379; Wed, 13 Dec 2023 07:28:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702481337; cv=none; d=google.com; s=arc-20160816; b=VSPCPEhpNYFycei5bAArkbsldJBmG2bb24guYsYL8CaH3usd3JKumCm/YaWDj/c5rP Vub5oiRucnWLOB8hTcivMaT4TLKcNnDX5RsLdidYdxv13OOPPVZBS5t0HnZZ7wNU7JNr wjOpMrUu0tq53/Z86YiFy5KI7BtDRcRu+e8t649vSzn7uNh48w6a3kv8eTkiNRT0AOS9 /PCw1UL/mgIMODtDNrTPgGobgXrWJFQcTAdvS9v+VYcME0AijXZpLzqYVBUfE5byQK8S N502KjgSHYvuLzc1JYEFBtjWI56j3nKP8vlSaLwGI2/7uOETZEBH8trkry7eMa10ZzIv S5Cg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=YcUt6Wlq9qFzNGrM+VViKKkJSoOctikTKew3FuWO+5w=; fh=ib4gl95HfLmZdfX9QIMf3rTepWCH9JlNymcDKJTPhJg=; b=uUHwXghZaYxvcdtvKb5LJboSjY/rjxqIB8qoT+/mS6SBQVzYmtKxvnP2KBnkEruWRw mSTgPHDEsDx3SXmn6IhXUjPguCJrYKtVDxx8URLsy1XzRcSLPL+2iHtxtSF6tY3ey6ms mU5j/LTaBePTMsdavUDCDsTNaIVhFxF+Fj+ycOvePLIEU5Kgu4wFrTS0i7VLdVn2ZKMl iPA2ydPRDKxk9cgvF9UwJA9f3fwht8Vh9tF2YEo+2+nM50pZbwBpv38whihLNGo0WU94 C2ytfE6gkAb5oqo2Cpvacf3xAK5UyAeUAsLNj4vSegIw0URnpFkppm0ynx65pKIoHFYO h11A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=gLv5GG6k; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from lipwig.vger.email (lipwig.vger.email. [23.128.96.33]) by mx.google.com with ESMTPS id fh13-20020a056a00390d00b006cefb653cecsi7039581pfb.146.2023.12.13.07.28.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Dec 2023 07:28:57 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) client-ip=23.128.96.33; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=gLv5GG6k; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id 15AF2803513F; Wed, 13 Dec 2023 07:28:54 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1442289AbjLMP2e (ORCPT + 99 others); Wed, 13 Dec 2023 10:28:34 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51642 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1442268AbjLMP14 (ORCPT ); Wed, 13 Dec 2023 10:27:56 -0500 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 94D671A1 for ; Wed, 13 Dec 2023 07:26:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1702481176; 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=YcUt6Wlq9qFzNGrM+VViKKkJSoOctikTKew3FuWO+5w=; b=gLv5GG6kvlq+zf19omWGETI6yJLtk5mjzf9gy+7kHtHee+E8niftBpaYddaTUv3DEvf1Yn RaS4AXv+U7RzoGBsBDJWpNauJgGDSFiBhLnARww7SuCxpdiAGXR2CixBxyISUCuRXjaoFx dXypIvynKt5BX3JjZ+GJRzE4cqypPDY= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-477-izgs5zPOPzO_FpSrM-V7uQ-1; Wed, 13 Dec 2023 10:26:13 -0500 X-MC-Unique: izgs5zPOPzO_FpSrM-V7uQ-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (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 CD5CC890FCD; Wed, 13 Dec 2023 15:26:11 +0000 (UTC) Received: from warthog.procyon.org.com (unknown [10.42.28.2]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2EE7F40C6EB9; Wed, 13 Dec 2023 15:26:08 +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 v4 31/39] netfs: Allow buffered shared-writeable mmap through netfs_page_mkwrite() Date: Wed, 13 Dec 2023 15:23:41 +0000 Message-ID: <20231213152350.431591-32-dhowells@redhat.com> In-Reply-To: <20231213152350.431591-1-dhowells@redhat.com> References: <20231213152350.431591-1-dhowells@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.2 X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Wed, 13 Dec 2023 07:28:54 -0800 (PST) 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 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 702b864a4993..46c0a6b45bb8 100644 --- a/include/linux/netfs.h +++ b/include/linux/netfs.h @@ -403,6 +403,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);