From patchwork Tue Aug 20 23:20:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13770635 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 90887C5320E for ; Tue, 20 Aug 2024 23:21:29 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1AC766B0089; Tue, 20 Aug 2024 19:21:29 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 10C4D6B008A; Tue, 20 Aug 2024 19:21:29 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id EEFA06B008C; Tue, 20 Aug 2024 19:21:28 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id CCA6E6B0089 for ; Tue, 20 Aug 2024 19:21:28 -0400 (EDT) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 8BB90C063D for ; Tue, 20 Aug 2024 23:21:28 +0000 (UTC) X-FDA: 82474197456.21.E6F236A Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf20.hostedemail.com (Postfix) with ESMTP id D75891C0019 for ; Tue, 20 Aug 2024 23:21:26 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="RfIOKBY/"; spf=pass (imf20.hostedemail.com: domain of dhowells@redhat.com designates 170.10.129.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=1724196024; 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=i1WfTcBSz40dFfs4YPek5T5SHQcjJbpn4yprFOLb05E=; b=fFDOizg5M2d/iyx6+nWghrbmICncRkpgNYnxMbxL/t4r5Ca0X9bcR1MnEmIjJC/LbUeJc8 laQxYckc3m3j2kSl063te6SNujWJ92kSuti7uk/k8Zek07XsegcI9tzlRmhWlavq6TxkQT ZcX9ECRsvGccd6zF7aexG6QP7OqlTSo= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="RfIOKBY/"; spf=pass (imf20.hostedemail.com: domain of dhowells@redhat.com designates 170.10.129.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=1724196024; a=rsa-sha256; cv=none; b=XU6x5r0/2HGF5DusK4usL55CU/qIrElzBN27Cpkg46G+G6VLLFwezlaTvpy1wb/wEdbmxM IzXXh+s7s5lQ9o2kWI5XS8AQBTHlzrWczAsXyVx7beiafvd7s4I0qqD/sS9wjiJKVlhqse i5Vs1hxF0L9YvK3snuyEX4czrHVslaM= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1724196086; 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=i1WfTcBSz40dFfs4YPek5T5SHQcjJbpn4yprFOLb05E=; b=RfIOKBY/8ZzBMJnIXQ3D8Y5GdiHSvmGOv7+clK9buSUMyufLHdNkGVc/bx3UijrYweIoIp c393GPuztF6AW3TU3L2NKwFeZyTLQBQlpp3scaHCEbvvoovHJLUK1yv2l2YiOKKriEVUYs /CBzFyZhPgumYXbQEf6ybxRXFCQb2MM= Received: from mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-515-qlsSCgy2P9econK9DfSahQ-1; Tue, 20 Aug 2024 19:21:23 -0400 X-MC-Unique: qlsSCgy2P9econK9DfSahQ-1 Received: from mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.15]) (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 mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id EBEED1955D48; Tue, 20 Aug 2024 23:21:19 +0000 (UTC) Received: from warthog.procyon.org.uk.com (unknown [10.42.28.30]) by mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 8A1AE1955E8C; Tue, 20 Aug 2024 23:21:14 +0000 (UTC) From: David Howells To: Christian Brauner Cc: David Howells , Pankaj Raghav , Jeff Layton , Matthew Wilcox , netfs@lists.linux.dev, 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-erofs@lists.ozlabs.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Marc Dionne Subject: [PATCH 1/4] mm: Fix missing folio invalidation calls during truncation Date: Wed, 21 Aug 2024 00:20:55 +0100 Message-ID: <20240820232105.3792638-2-dhowells@redhat.com> In-Reply-To: <20240820232105.3792638-1-dhowells@redhat.com> References: <20240820232105.3792638-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MI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gNu2b2K6JQgGyaLmuosTWxxIwKDewt0GaNwCr9Bg2 o/v+2efJ S/VNlTzAvSrHzy368HWfsjlsFFO4+J0BhaPVojiGYZoRxXrkGFzYqZIGWlSTBLlTIiAR3Qse1geAdfzXbtW27tIjbVNQyCSrO9rMATHzdTFnXemG1Teb7EAXgLyLT39YX+IKMSRaXxMqZ4Ui3Mt5ocPhISPjMK49tNyjjEiuQjJE11qG5a0baSI4Xy/fOZwWsC9sn2PTFyMFdopstb+MhBUebYG7VqdD98i/rLfm83NM8hMCNuOWR+ahee5PbPPtbkKegfwLLE7FTdZUkWtDtx0dKrBfvRvH72nYhiQxXn6LQ89Co2fVnBBcAvmVYO+lpnyElxYvvoUpXl2AismPJJKPKtn5saYAOr9WGeKhN/x7KbpwXt0NErg+qSw4Z5D7h+TI/+LQi8tX6puNXL8DTuIco3Tp6CARm1/4s7qyDIZThLYZU7wqtaJC4YzykCmlAuz2e5+7NE/KdOOxBmCgyRuJZvmbstTqlQCEbMqcXWuBp91V/1bWhjJb8WerEU+u9/YhVYFxBDdzKvnIQnyq2J3IRXTiKlCwhQu6J7izDFpIWN3JlVFS+1NkWwzDK0Czq6Hl+L52f5xfg1agibva+eMbRJosUVZSP8PkBOxr1pTti3vg2T8Ci4jX9fg== 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: When AS_RELEASE_ALWAYS is set on a mapping, the ->release_folio() and ->invalidate_folio() calls should be invoked even if PG_private and PG_private_2 aren't set. This is used by netfslib to keep track of the point above which reads can be skipped in favour of just zeroing pagecache locally. There are a couple of places in truncation in which invalidation is only called when folio_has_private() is true. Fix these to check folio_needs_release() instead. Without this, the generic/075 and generic/112 xfstests (both fsx-based tests) fail with minimum folio size patches applied[1]. Fixes: b4fa966f03b7 ("mm, netfs, fscache: stop read optimisation when folio removed from pagecache") Signed-off-by: David Howells cc: Matthew Wilcox (Oracle) cc: Pankaj Raghav cc: Jeff Layton cc: Marc Dionne cc: linux-afs@lists.infradead.org cc: netfs@lists.linux.dev cc: linux-mm@kvack.org cc: linux-fsdevel@vger.kernel.org Link: https://lore.kernel.org/r/20240815090849.972355-1-kernel@pankajraghav.com/ [1] --- mm/truncate.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mm/truncate.c b/mm/truncate.c index 4d61fbdd4b2f..0668cd340a46 100644 --- a/mm/truncate.c +++ b/mm/truncate.c @@ -157,7 +157,7 @@ static void truncate_cleanup_folio(struct folio *folio) if (folio_mapped(folio)) unmap_mapping_folio(folio); - if (folio_has_private(folio)) + if (folio_needs_release(folio)) folio_invalidate(folio, 0, folio_size(folio)); /* @@ -219,7 +219,7 @@ bool truncate_inode_partial_folio(struct folio *folio, loff_t start, loff_t end) if (!mapping_inaccessible(folio->mapping)) folio_zero_range(folio, offset, length); - if (folio_has_private(folio)) + if (folio_needs_release(folio)) folio_invalidate(folio, offset, length); if (!folio_test_large(folio)) return true; From patchwork Tue Aug 20 23:20:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13770636 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 61B10C5321D for ; Tue, 20 Aug 2024 23:21:40 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E54496B008C; Tue, 20 Aug 2024 19:21:39 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E04E56B0092; Tue, 20 Aug 2024 19:21:39 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CCC046B0093; Tue, 20 Aug 2024 19:21:39 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id ACDCF6B008C for ; Tue, 20 Aug 2024 19:21:39 -0400 (EDT) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 5DC3CC063D for ; Tue, 20 Aug 2024 23:21:39 +0000 (UTC) X-FDA: 82474197918.12.6C4D64B Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf25.hostedemail.com (Postfix) with ESMTP id 9E87BA0004 for ; Tue, 20 Aug 2024 23:21:37 +0000 (UTC) Authentication-Results: imf25.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=C8FHukd7; spf=pass (imf25.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=1724196057; a=rsa-sha256; cv=none; b=AKchdeTrRr9YbO/t24Ju/0+JL8hOeihOsX47/Gofx3PhJdStLCrZUhz6+dpji3my6uIILn 1yR2vi3GLX5dvLaoJtHLlXt6gCh18iEByc2PNSZBuU7Wrio4yk8NdzefWUXE5bZwUB5xjV WHRYahYM4kbskzEp9SsKzZqsaIZIShQ= ARC-Authentication-Results: i=1; imf25.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=C8FHukd7; spf=pass (imf25.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=1724196057; 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=LLNXobqu9Lr51n4CzgcItZvbbRppxWdYVF89daxGYJk=; b=F2wrLzd9KgOjOwPGRgSwbONhFYClj3RPJglX5xnGeTRYEjbLXp4iqkBD5/bsKrO4/1GQDP e7C0qGjtosk3gPQzx2nmcPdIQutsNF8zQnmVpQ+vxKjroi2Q/emt3Fuzuj7t9t69TtLZN2 KxkjUi8C1wuoquVxof7S3elE60owWtM= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1724196096; 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=LLNXobqu9Lr51n4CzgcItZvbbRppxWdYVF89daxGYJk=; b=C8FHukd7rmJ6on+u0PHuCKBwcfCn4I3ndGc3+HIn7MJagFXu41+7/MYNBdk9X0N98c8b27 UrVOaOnmHP7KurEw5mX6bbF2XPXmLGoug9uAz47i/qSAN1ihjaWheyWg3N0rBHhGB22s3r a8wwC9dVhlxCpxTOG3+4ge7ZFi76uqw= Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-34-12CfHN9WNkObG7tnXd9WhA-1; Tue, 20 Aug 2024 19:21:29 -0400 X-MC-Unique: 12CfHN9WNkObG7tnXd9WhA-1 Received: from mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.15]) (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 mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 3436B195608A; Tue, 20 Aug 2024 23:21:25 +0000 (UTC) Received: from warthog.procyon.org.uk.com (unknown [10.42.28.30]) by mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 09A0F1955E8C; Tue, 20 Aug 2024 23:21:20 +0000 (UTC) From: David Howells To: Christian Brauner Cc: David Howells , Pankaj Raghav , Jeff Layton , Matthew Wilcox , netfs@lists.linux.dev, 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-erofs@lists.ozlabs.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Marc Dionne Subject: [PATCH 2/4] afs: Fix post-setattr file edit to do truncation correctly Date: Wed, 21 Aug 2024 00:20:56 +0100 Message-ID: <20240820232105.3792638-3-dhowells@redhat.com> In-Reply-To: <20240820232105.3792638-1-dhowells@redhat.com> References: <20240820232105.3792638-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.15 X-Stat-Signature: mgpkyyeqee1sf7dr38qq7uncfn7oq1n8 X-Rspamd-Queue-Id: 9E87BA0004 X-Rspam-User: X-Rspamd-Server: rspam10 X-HE-Tag: 1724196097-13594 X-HE-Meta: U2FsdGVkX19awzC28NHh9j8cxzCU23aWvzlj5zLtUMJo8354DmBsW/NQwRLFRosuEytPvGaqCv/Csax3hQ3WF1w/WvrD/CzEljPPke926v3hT/cE5ELCiOGKa/moVslsfj7UUXKLpfHw4qSuJgiFiyWp7JCQoWdYgxJO3hG9dbvbHpjqqLkBG0RbrcMO5u9hbYqNbiwcbDwAop1gGW5on/fuxRntJrdm6cNeZvM6MPfBbKSebpfZX79bDYHK/IXKI0qFtM56ptylG6ZXDmsvRKNCjOrMhQCtAeZu8jJudxwx0nQDO4hJaoteHQOBQ7By/h7E00rr6EsZ01ZPno5Xpka3Uq95b/NumcQkyJ86nprcRQmDD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16YO6e/4AsgMJM4zwkVDwuyk2ZkIvAv0bqwFuxq8e1pDeX/fsWGSLDcbXgT9g1RnWSoBZvMVoHMI2wAxnDhyOKhYGJDCE7gcYqNnwJA== 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: At the end of an kAFS RPC operation, there is an "edit" phase (originally intended for post-directory modification ops to edit the local image) that the setattr VFS op uses to fix up the pagecache if the RPC that requested truncation of a file was successful. afs_setattr_edit_file() calls truncate_setsize() which sets i_size, expands the pagecache if needed and truncates the pagecache. The first two of those, however, are redundant as they've already been done by afs_setattr_success() under the io_lock and the first is also done under the callback lock (cb_lock). Fix afs_setattr_edit_file() to call truncate_pagecache() instead (which is called by truncate_setsize(), thereby skipping the redundant parts. Fixes: 100ccd18bb41 ("netfs: Optimise away reads above the point at which there can be no data") Signed-off-by: David Howells cc: Matthew Wilcox (Oracle) cc: Pankaj Raghav cc: Jeff Layton cc: Marc Dionne cc: linux-afs@lists.infradead.org cc: netfs@lists.linux.dev cc: linux-mm@kvack.org cc: linux-fsdevel@vger.kernel.org --- fs/afs/inode.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/fs/afs/inode.c b/fs/afs/inode.c index 3acf5e050072..a95e77670b49 100644 --- a/fs/afs/inode.c +++ b/fs/afs/inode.c @@ -695,13 +695,18 @@ static void afs_setattr_edit_file(struct afs_operation *op) { struct afs_vnode_param *vp = &op->file[0]; struct afs_vnode *vnode = vp->vnode; + struct inode *inode = &vnode->netfs.inode; if (op->setattr.attr->ia_valid & ATTR_SIZE) { loff_t size = op->setattr.attr->ia_size; - loff_t i_size = op->setattr.old_i_size; + loff_t old = op->setattr.old_i_size; + + /* Note: inode->i_size was updated by afs_apply_status() inside + * the I/O and callback locks. + */ - if (size != i_size) { - truncate_setsize(&vnode->netfs.inode, size); + if (size != old) { + truncate_pagecache(inode, size); netfs_resize_file(&vnode->netfs, size, true); fscache_resize_cookie(afs_vnode_cache(vnode), size); } From patchwork Tue Aug 20 23:20:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13770638 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 3DEB7C5320E for ; Tue, 20 Aug 2024 23:21:47 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C0C5A6B0095; Tue, 20 Aug 2024 19:21:46 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B6D5F6B0096; Tue, 20 Aug 2024 19:21:46 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A0CF86B0098; Tue, 20 Aug 2024 19:21:46 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 78C3F6B0095 for ; Tue, 20 Aug 2024 19:21:46 -0400 (EDT) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id F0CB9805EE for ; Tue, 20 Aug 2024 23:21:45 +0000 (UTC) X-FDA: 82474198170.07.050EB4C Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf23.hostedemail.com (Postfix) with ESMTP id 46848140008 for ; Tue, 20 Aug 2024 23:21:44 +0000 (UTC) Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=DWV0lOPf; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf23.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=1724196045; a=rsa-sha256; cv=none; b=01MQmeN/0DMPLY4m6vXRR/SlT3r1JREsijYZd1irSjZ6HUZkVBMrQOQGyJFkuJTwJSFOpr PW3nlk8Y2vjvNFMiCfjhzas1fzpaBg2GhSgv0o4xqrlWWMCjgC3Vm26v+FpSgUCsgcpvmP NMccJZ6BJABlpsv5tuM+KYSlEeIpdKs= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=DWV0lOPf; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf23.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=1724196045; 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=B4tfOtZ3an7b1aGGuqLauY14dten5jR69+zwwl0cSBE=; b=dbiksVAa1SwlvgrEfa1zpiXDRsVLOtqjMxt8POe4wHl/ychn93/psd2oXlh0euR24+RmT1 JQXhVTCg5oaq+OgBuPvMr4H1Z8SaSk16uJxzChHVHSyO9FSZ85KtsRp7r/FtMPlvvQtRKu lrEQOSMN9fiJKfZ9OLX6ePTL+Kxmy1I= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1724196103; 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=B4tfOtZ3an7b1aGGuqLauY14dten5jR69+zwwl0cSBE=; b=DWV0lOPfZ1bjgSMaLnr7dTDop0ZBRLJ0vTZ2rzhKAvX08mJfPXrSb4+C1hXDnwR+t+fNgs dNnPEMPHtmH4EVVA9DOJEyAc36zQk+tuQxIA2WN7JAsTa83u58SfkqQ988SRJGbMAjFEk6 qfhN7+/qwdSQQlu5QwOdvjMqA5EXnHU= Received: from mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-354-Mj8yoYdJNz-fatkw3PTnGQ-1; Tue, 20 Aug 2024 19:21:36 -0400 X-MC-Unique: Mj8yoYdJNz-fatkw3PTnGQ-1 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (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 mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 29EA31955D52; Tue, 20 Aug 2024 23:21:31 +0000 (UTC) Received: from warthog.procyon.org.uk.com (unknown [10.42.28.30]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id B0C261955F54; Tue, 20 Aug 2024 23:21:26 +0000 (UTC) From: David Howells To: Christian Brauner Cc: David Howells , Pankaj Raghav , Jeff Layton , Matthew Wilcox , netfs@lists.linux.dev, 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-erofs@lists.ozlabs.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Marc Dionne Subject: [PATCH 3/4] netfs: Fix netfs_release_folio() to say no if folio dirty Date: Wed, 21 Aug 2024 00:20:57 +0100 Message-ID: <20240820232105.3792638-4-dhowells@redhat.com> In-Reply-To: <20240820232105.3792638-1-dhowells@redhat.com> References: <20240820232105.3792638-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 X-Rspamd-Queue-Id: 46848140008 X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: zqk8nkfso6g1xexgimi53wgujcpr9s7b X-HE-Tag: 1724196104-629308 X-HE-Meta: U2FsdGVkX1+s0cjAHPUs1JmSu1MSSDHOLP/y3eV6ANPv8C+C47urAnKcU+jzqYnMwVrk5QAmCdoZ5Guyn2BJDk0GR4D9Z2ePb+vrO4Sd2jv91+Stza4PT8IZRAkCl7+e+sRN4yyRVBvywbnettO2zqS/GYU8AzvjeR2DeQUidrt6FYi2fjmFDTJb4n+QPj8r2UrqywVQIQLKX+9QDZAbE7kob7I650NJJFBh881E47CYyNZupa9f0+gag2AbO+/fY3Sroib5pNdFINslE8zQfqndUfm/DzWK+AOup6F9NwLEi8UtK4QhrKnhCHJstRa2aQXLze0DL2Rv/2hY64sVGA9PL7mBGGfT/RNAWvcfECh/i8OGKKcJ6X/sYCbaSQLiKhad/bHG6QrHWLOWZdvv6KSBK4bori0TaBEdBgVoWdtgpzOVaXmlESf2MWDhROlkeLNGXlKOZFs/k8D23PUg4rXrDxCuNQlFbP6gcAZlVtxZUxe8oi92bC3rA7L2QY56MnhOqjw81q8RiGHZb+CSIWCp637Ql2WdxdndwRb1zHaMmtm89bNPcnHCOPysHd6BkOTg/3a9swZT1+0Hq8yrvdx9bdcr7BfCvCMQQuvIxjrzf+jbCNUPSXSQKdmnzW9zJH3wSufgAx1Q3EeG1GhRFkTr3Ei62ESjUMZNLS87bPtOsCR0+JtGsQOW/RNhVkwC6Rix3Q1EZoS7c56s4cF2Hv9kwK+ahHL+vN7inhpW+hBF4SFo+tnW7n+HhK+AJpa+Eu7GamDUKBk5hisX3/wtqX6FwjZU7G0xbGZXnIo9+db6ALbbVTy395h9n05lRodKC8J4UgGulJhP/JVLRKUba6j87yeykWQrcrrKYlTrYUFzuGEhiM2ajAewrs90YIlz6cNa4ZUFADC1UlWUJQohayAnJHY+i2rObRwoPZVuw2trcIvh7I4dMtA4m9bZXrob5r314ajzXXtb/GdEjZ2 s9YQKOYo 6edEChyqmyO8SEQhTQxFWdttzGvHtwbFDnZhhNcVQ8LjzyCuetR9rb2lG7xcvy7hVZWHhV/X8zFrDzeG6ynvGcDd4lcH8+6IO/qdlda6GvXhwH0LtOdLZlkso2Sascyqo1FPiV8PcH9uPcef97MW7J34X3gspixeZ+HjChjXw7QL4MovhwDumyto+jTlCfn2Zn/YfNm88QIL+h49jsbIzCaf7N6fOp/kqi/7OPfbTYYZRnQ43NI5Pt+nOEHhpunIMO/gXWGcFw25/ZfsVF/W9iGU5PjzJUzz73zVuDfn68q3bkUbjvE+nHJr+t6hs/vE/Uy7V2eXNn17McQ2aBv/5bXmufQlpq3+w31wcUOPIC0HFcvDRVUFEm5env2YL8TjrPyLzVxXxcz2MBAnUdD1Z0v5v5+piBQUHSogEWpqeuK3P8kKTrP3uYni75s+ziGu1/4bIpT+NGJQG3kDejgjS+dsHj+nQSSu88oGS5YdewXuR+tF0hM0NsPf+UbPTHvvMldbjGeUVRJ3aRw//MGkYaJOOGF7lrGZ2erRHC5tC3ismivpiTu9hQByyo3Q8yDDZSNJls2hngkSnzZGlikDMd7D9vcFqpXDTR4KmbUAmN5jEBwe3kYPKGmvDGxu9HcQR8hka3RCxQRG/zugKOb92e3Z/MkrRuxeOxuBO 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: Fix netfs_release_folio() to say no (ie. return false) if the folio is dirty (analogous with iomap's behaviour). Without this, it will say yes to the release of a dirty page by split_huge_page_to_list_to_order(), which will result in the loss of untruncated data in the folio. Without this, the generic/075 and generic/112 xfstests (both fsx-based tests) fail with minimum folio size patches applied[1]. Fixes: c1ec4d7c2e13 ("netfs: Provide invalidate_folio and release_folio calls") Signed-off-by: David Howells cc: Matthew Wilcox (Oracle) cc: Pankaj Raghav cc: Jeff Layton cc: Marc Dionne cc: linux-afs@lists.infradead.org cc: netfs@lists.linux.dev cc: linux-mm@kvack.org cc: linux-fsdevel@vger.kernel.org Link: https://lore.kernel.org/r/20240815090849.972355-1-kernel@pankajraghav.com/ [1] --- fs/netfs/misc.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/fs/netfs/misc.c b/fs/netfs/misc.c index 554a1a4615ad..69324761fcf7 100644 --- a/fs/netfs/misc.c +++ b/fs/netfs/misc.c @@ -161,6 +161,9 @@ bool netfs_release_folio(struct folio *folio, gfp_t gfp) struct netfs_inode *ctx = netfs_inode(folio_inode(folio)); unsigned long long end; + if (folio_test_dirty(folio)) + return false; + end = folio_pos(folio) + folio_size(folio); if (end > ctx->zero_point) ctx->zero_point = end; From patchwork Tue Aug 20 23:20:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13770637 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 7D26BC3DA4A for ; Tue, 20 Aug 2024 23:21:44 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0C13B6B0093; Tue, 20 Aug 2024 19:21:44 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 070F46B0095; Tue, 20 Aug 2024 19:21:43 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E07566B0096; Tue, 20 Aug 2024 19:21:43 -0400 (EDT) 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 BC5C76B0093 for ; Tue, 20 Aug 2024 19:21:43 -0400 (EDT) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 76F391A0561 for ; Tue, 20 Aug 2024 23:21:43 +0000 (UTC) X-FDA: 82474198086.21.D77F156 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf26.hostedemail.com (Postfix) with ESMTP id C855E140014 for ; Tue, 20 Aug 2024 23:21:41 +0000 (UTC) Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=bL5YwMs7; spf=pass (imf26.hostedemail.com: domain of dhowells@redhat.com designates 170.10.129.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=1724196039; 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=9pcRiiH/lYTDVoni9WSyylXIzj+0iyqYBGBDYoCG5zI=; b=H9yos/6ts2LsEIyCMwqyzMh6/t88LJL1gObWxIncgNbZ2L/6YqzxTGP3yCemz4BScEX5t9 WUy5RH0yg8vZ6crLb4/1+D9D1tqL0W8lBtwpqVYlWZM9ufWdrE4DHsKCQb+vRrQJKR7UTS tFoZiyGd4dpxVE5MzClrIexSx7D9bw4= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=bL5YwMs7; spf=pass (imf26.hostedemail.com: domain of dhowells@redhat.com designates 170.10.129.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=1724196039; a=rsa-sha256; cv=none; b=MWYwE4jwWWuKv6A6zALleknvtWQABAxmShI1b5r5GvSLBjuBroZIEA0Ynwgg4/EDIFOYHh +rZyx/bFMbZvc+9Y+fTXZpzhXgBR44rXi6cF2iHN7gEDwtAgKsIal3W4ZudGREpC0gMFj1 4uJvEMXWSUbIisYf9xtDilaGyHui7hw= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1724196101; 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=9pcRiiH/lYTDVoni9WSyylXIzj+0iyqYBGBDYoCG5zI=; b=bL5YwMs7SvgXFDIvahEHcYDnzj21cS7pigOHa0kpfCXFP95pm7NVWFzc3U8WEhkRVqVxed VvhHazVjG6h8medU/VUoPleNV5kLzyDQibsA7HTT/dkOlK/FWIRQ1ujU9xeIukcQ+FQ6D/ dfpWey0SapXPLFXt/Nj0NRS3Bxqw1oA= Received: from mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-329-JolRJguvP_SguD5LijFaFg-1; Tue, 20 Aug 2024 19:21:39 -0400 X-MC-Unique: JolRJguvP_SguD5LijFaFg-1 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (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 mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id BA9DE19560AD; Tue, 20 Aug 2024 23:21:36 +0000 (UTC) Received: from warthog.procyon.org.uk.com (unknown [10.42.28.30]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id A9E6F1955F54; Tue, 20 Aug 2024 23:21:32 +0000 (UTC) From: David Howells To: Christian Brauner Cc: David Howells , Pankaj Raghav , Jeff Layton , Matthew Wilcox , netfs@lists.linux.dev, 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-erofs@lists.ozlabs.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Marc Dionne Subject: [PATCH 4/4] netfs: Fix trimming of streaming-write folios in netfs_inval_folio() Date: Wed, 21 Aug 2024 00:20:58 +0100 Message-ID: <20240820232105.3792638-5-dhowells@redhat.com> In-Reply-To: <20240820232105.3792638-1-dhowells@redhat.com> References: <20240820232105.3792638-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 X-Stat-Signature: dm9e167g4icga3tc19a8q7szenjfm84j X-Rspam-User: X-Rspamd-Queue-Id: C855E140014 X-Rspamd-Server: rspam02 X-HE-Tag: 1724196101-127598 X-HE-Meta: U2FsdGVkX180ImLGacD5QmAz/czfrAhOEAKkZbHoxoGzLcewKRn1HggkQwCH67y0X1vVSRxbLtfS+G8Nw4UC7/s5lweeoaDBuJbYTmaCQgzg9iTbzPzBzTEpsfpK1jlYVvsl+RYm+MnwLFD0FTVOFs7uWAy4FL6YwhPxqGDYZQBcsIY4aweM/Ahy0hin+5XsjYxvy7523SwlVOxpR1Fc4z4gppabHcAi1XmFNPHREL1jo3HsGVF5WPxB8IUmtVnGsyWBkJ31vmUNCzR9S1/LyRq2wRQBgz83G37gp9/A32nHDYy7eSkcG08ztE8KhVTbY8bOgq5+IKPvwU8prmz7ljHsYumgZhXQuwOCZw6bmPQbrvtrulhx4StNuYqWZCo9OTtA8PC5hd9nHmloQGFMowyJKncpFVn2AY3Xul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yAqLCU8CQkfmE15aJ2MnuFk21yjqzlgXtNO6aiNLHM1Eu/wJRShJuCqZ3fmJp7YhZXfJJYd1Q3MN1mMb6dQAHXslXxcaX+pkIi9 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: When netfslib writes to a folio that it doesn't have data for, but that data exists on the server, it will make a 'streaming write' whereby it stores data in a folio that is marked dirty, but not uptodate. When it does this, it attaches a record to folio->private to track the dirty region. When truncate() or fallocate() wants to invalidate part of such a folio, it will call into ->invalidate_folio(), specifying the part of the folio that is to be invalidated. netfs_invalidate_folio(), on behalf of the filesystem, must then determine how to trim the streaming write record. In a couple of cases, however, it does this incorrectly (the reduce-length and move-start cases are switched over and don't, in any case, calculate the value correctly). Fix this by making the logic tree more obvious and fixing the cases. Fixes: 9ebff83e6481 ("netfs: Prep to use folio->private for write grouping and streaming write") Signed-off-by: David Howells cc: Matthew Wilcox (Oracle) cc: Pankaj Raghav cc: Jeff Layton cc: Marc Dionne cc: linux-afs@lists.infradead.org cc: netfs@lists.linux.dev cc: linux-mm@kvack.org cc: linux-fsdevel@vger.kernel.org --- fs/netfs/misc.c | 50 ++++++++++++++++++++++++++++++++++--------------- 1 file changed, 35 insertions(+), 15 deletions(-) diff --git a/fs/netfs/misc.c b/fs/netfs/misc.c index 69324761fcf7..c1f321cf5999 100644 --- a/fs/netfs/misc.c +++ b/fs/netfs/misc.c @@ -97,10 +97,20 @@ EXPORT_SYMBOL(netfs_clear_inode_writeback); void netfs_invalidate_folio(struct folio *folio, size_t offset, size_t length) { struct netfs_folio *finfo; + struct netfs_inode *ctx = netfs_inode(folio_inode(folio)); size_t flen = folio_size(folio); _enter("{%lx},%zx,%zx", folio->index, offset, length); + if (offset == 0 && length == flen) { + unsigned long long i_size = i_size_read(&ctx->inode); + unsigned long long fpos = folio_pos(folio), end; + + end = umin(fpos + flen, i_size); + if (fpos < i_size && end > ctx->zero_point) + ctx->zero_point = end; + } + folio_wait_private_2(folio); /* [DEPRECATED] */ if (!folio_test_private(folio)) @@ -115,18 +125,34 @@ void netfs_invalidate_folio(struct folio *folio, size_t offset, size_t length) /* We have a partially uptodate page from a streaming write. */ unsigned int fstart = finfo->dirty_offset; unsigned int fend = fstart + finfo->dirty_len; - unsigned int end = offset + length; + unsigned int iend = offset + length; if (offset >= fend) return; - if (end <= fstart) + if (iend <= fstart) + return; + + /* The invalidation region overlaps the data. If the region + * covers the start of the data, we either move along the start + * or just erase the data entirely. + */ + if (offset <= fstart) { + if (iend >= fend) + goto erase_completely; + /* Move the start of the data. */ + finfo->dirty_len = fend - iend; + finfo->dirty_offset = offset; + return; + } + + /* Reduce the length of the data if the invalidation region + * covers the tail part. + */ + if (iend >= fend) { + finfo->dirty_len = offset - fstart; return; - if (offset <= fstart && end >= fend) - goto erase_completely; - if (offset <= fstart && end > fstart) - goto reduce_len; - if (offset > fstart && end >= fend) - goto move_start; + } + /* A partial write was split. The caller has already zeroed * it, so just absorb the hole. */ @@ -139,12 +165,6 @@ void netfs_invalidate_folio(struct folio *folio, size_t offset, size_t length) folio_clear_uptodate(folio); kfree(finfo); return; -reduce_len: - finfo->dirty_len = offset + length - finfo->dirty_offset; - return; -move_start: - finfo->dirty_len -= offset - finfo->dirty_offset; - finfo->dirty_offset = offset; } EXPORT_SYMBOL(netfs_invalidate_folio); @@ -164,7 +184,7 @@ bool netfs_release_folio(struct folio *folio, gfp_t gfp) if (folio_test_dirty(folio)) return false; - end = folio_pos(folio) + folio_size(folio); + end = umin(folio_pos(folio) + folio_size(folio), i_size_read(&ctx->inode)); if (end > ctx->zero_point) ctx->zero_point = end;