From patchwork Fri Aug 23 20:08:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13775931 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 C2D9FC5321E for ; Fri, 23 Aug 2024 20:08:46 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 42CEA6B0249; Fri, 23 Aug 2024 16:08:46 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 3DCF26B024B; Fri, 23 Aug 2024 16:08:46 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2A42B800C8; Fri, 23 Aug 2024 16:08:46 -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 0AC626B0249 for ; Fri, 23 Aug 2024 16:08:46 -0400 (EDT) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id C6824A148F for ; Fri, 23 Aug 2024 20:08:45 +0000 (UTC) X-FDA: 82484598210.23.F88C125 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf11.hostedemail.com (Postfix) with ESMTP id 1187C4000C for ; Fri, 23 Aug 2024 20:08:43 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="HxUThJl/"; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf11.hostedemail.com: domain of dhowells@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1724443657; a=rsa-sha256; cv=none; b=zjPkPv5py3YLLsJxYbrtVegmfnyMCieWhuJ5Knl/WNt/BAEjcu3SW5y/tlNoqomelutQ4A XpaAVbYPksbwz1UMPjzANWLbRQ8u6hQ0u7XkPTKZZYyWAkjAMzfmg5mAEPcWwhwT5Elepv R6VdNsf/ILikhxGIus86srg9hsowJ8I= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="HxUThJl/"; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf11.hostedemail.com: domain of dhowells@redhat.com designates 170.10.129.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=1724443657; 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=RGA+JSA2V14ATaPgBBckAPvuIzNuSHMAH2nz3txsJbBSeAkCNcwH5GgjaX1FRHPQhm5z5s iJWqSCDCAMVI+RJKCViTSAkuBpgpnbQnaI8TRBZwp74i2SEe64YjQuFp1n20FXuLmkUN+Z aApJb3ApLTy+Q20MwrB+HRFx6jTa4Xk= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1724443723; 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=HxUThJl/Fc/eYIKa+/Q9mjLsAcsWxBP/O0vNZwY3Kllu6/BWQsbPx94sf6x04CMsYCLav2 f19w17YLyTdgsMtVB9jwSi8D+HRkQrh0Wbg5oaAfYh/vZLe0tdD77P3K7qJ/J+bI2iexzU 3i8F4umS5Xf3uQstWegsIzrAm1Z4Ymc= 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-459-Djwg1nHIPVOepKsh7DLV1g-1; Fri, 23 Aug 2024 16:08:37 -0400 X-MC-Unique: Djwg1nHIPVOepKsh7DLV1g-1 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (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 A790219560A2; Fri, 23 Aug 2024 20:08:34 +0000 (UTC) Received: from warthog.procyon.org.uk.com (unknown [10.42.28.30]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 7292D3001FE5; Fri, 23 Aug 2024 20:08:29 +0000 (UTC) From: David Howells To: Christian Brauner , Steve French Cc: David Howells , Pankaj Raghav , Paulo Alcantara , 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/9] mm: Fix missing folio invalidation calls during truncation Date: Fri, 23 Aug 2024 21:08:09 +0100 Message-ID: <20240823200819.532106-2-dhowells@redhat.com> In-Reply-To: <20240823200819.532106-1-dhowells@redhat.com> References: <20240823200819.532106-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 1187C4000C X-Stat-Signature: m6p56kpp3rsddtyxhbucoay1pxqkwmkb X-Rspam-User: X-HE-Tag: 1724443723-160753 X-HE-Meta: U2FsdGVkX19SeX8jH9rLppjS4WFJUQYluot8Ww+Ee5uAA+E+VTbZaNpIyr4qFKZFifcefoFK+hbbe/zXgZWhMi9dxd50RNPYM3KWv612xLqSxq3cUPCvHk7HszhNeFw25vV8405h2FawwoiZJxdgtt7C6ksUt3kH7aqm5wO4ynh5JFx0QHi3c42ktzSSu/OChQsEj7f/l01MS9CTHkIInV5yiNC/5e14EVUoG5ymLDPx9yed08jGb55hguaP63vQfv/FX7aBi31McuTTwsf5zzZ5lr+xVO/XfXpSp5cL2QFXf1/CCFJxtp2WJuSaGyVF3OQmntY2fvW3EXgIKYWk1Ssow5E5iIu0gaD9VemOP/fW+81CDd3Zq4gxl1wgH5iZCCIIBsx9Kk1SmIDFfmk0Mi1IfEJ1M1PbRimb6v+MB0++6KQGw/I/2Lqzg+41tQPQe2LMIPaJUv9LesVfsRXv+vNKjOdvZvGGdHcw5/u5TUcqVakUE3FS4ZeHYK0b9I5TYsxGpNtxe77oHWkL7clQWS6ZizaIiB2duZLRZ7SJObY03J0Z0NcIUMwTe9pqm5phyBXvaANECY5H+g/884QXHNksCBiXkliiQng30ZSHtk2K9WizOUN7oCBqnc6yNop+S4JfOznHSWWoCBeE2AyxaGcaOF8/0nOES8KYNp5n6EOc61ACSTRJZUAxw0/1ELB4J1H895A0m40wBMhkUibsC+Tuxx56NyfkVE5Ncfm8FNKaXMybgZvcKPowAHk/7EQnfZOmmkdCPo4cN4dOKTT7KxW0Nw1sitdT1SEyA6DiHKqBQW2Mip8i3VRhWPojk5wq/6r/1An9giDXjN7IOYtoP5ui7UMfkKWCAIMfDQf3NKbweaUedeo5QfQIvlBWsMu4jhNy+ueCqwBZGjeeApvpMCFNZ/LkHE174tagMV6r+fgiB6FoByzmfGVKHf9mDaa0ZNgBFw8KtPBx8lJ0QxX x1Qm2VJn j03oaNWL2vb7DvJccTTUZo90Wv6n+MHN0fswHUouPkYdVjBljF8XIJ+2PSR3YT5qZxZdnjAY9TGEGvqBWjt2LhshUI7wyZQMpbQLim7o9Kub5aRjng2NB5Njn1kid4qh3+7MpFib4koL/i5n9T0ZbCqLYWoDLMtcjcUnmAQB34wAM8vOXcPx0rO5z/aPwnJuO1j1QSvbWBKglU0PgaTEolC+0AnYM2Ph9AnjiRZcWa3reN3xVSLwF/s/kX4FE1Fywupi2B3O5LOPk/b0rnNHlIfPX2C+2NAAdF5N7V5X8tiS5cqvQOR+qNf3XBOLtzH1rlBur2uDn56l1xnK3DND/0yrWmgB3fJ1Wu7kHbPL6ugw4iF3uN2MISK2j0Q9JUhOegGnKw3b6FZdN6ut8jrn7AZ1oPr7fTApGxI5cFmCdwHoYII/mT2w+3vW3ewwPQYvntSuyEhdk26tiVLSW0mMrneQ7p5/6VhX7j8p5xiIGMbbooUxCAiJfzBezcQw10zjshThMNyfn3meV80D+hssPw4xtPd3u7sRz9AcTP0Ga+zRZ6jvb4+TrwlUJjX8+dBb1hpTAsRJIKLbHQWTHic9PvyCWTlzphiom6k052B86P6+j5d0C2epzGtVVMg== 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] Reviewed-by: Matthew Wilcox (Oracle) --- 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 Fri Aug 23 20:08:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13775932 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 D88F1C531DC for ; Fri, 23 Aug 2024 20:08:52 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6C5F16B0275; Fri, 23 Aug 2024 16:08:52 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 674CF6B0276; Fri, 23 Aug 2024 16:08:52 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 53C646B0277; Fri, 23 Aug 2024 16:08:52 -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 338416B0275 for ; Fri, 23 Aug 2024 16:08:52 -0400 (EDT) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id ED5D6C0D5E for ; Fri, 23 Aug 2024 20:08:51 +0000 (UTC) X-FDA: 82484598462.01.758C907 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf29.hostedemail.com (Postfix) with ESMTP id 32F0212000A for ; Fri, 23 Aug 2024 20:08:50 +0000 (UTC) Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=N440LJsG; spf=pass (imf29.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=1724443665; 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=2k2S7hY8Ais5IOOFuTd2zvOueGvrX7F4ttO81UBUiH24Ubccvtu18VOg9Lb1nOB0rFmXB+ eeW9aABtcl4o/dGWx2xdDrASA0qCXbTLGRtDRCNkTGJ8ocCf5OmPL2mIm7SwvcgRDJ+Vus 1u+Z7EnGPoy8KjaUWEMUD/yGR1wHiKw= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=N440LJsG; spf=pass (imf29.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=1724443665; a=rsa-sha256; cv=none; b=vO9Og51SlSaIuW01u0H2bNkG9UJomociZrEK9VBbUCOyUm+pzVwbNrygVVxbJ+c9pyWwum cwcGCdhHkSstJw0HVRygnNiii9SqWN69IYDTO8+rywV95GruURYvL2QD0BduJ+AQ6iajJz umKoYNIk6h+gIVa+xxdGFamp+YQyZic= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1724443729; 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=N440LJsGGOY/B2U51BAAmYfpFknVsyB5eK+wBVN0rwORqx3SLRefS4Cpvl173FcwPTElHG nZdW5Chy5M74mxR9XOVQXOYYFPxwGC4w2ucpgg8b98wCJl6n87dFPUou9Rk6c6+oU1nZuI xTtfVSTK7vTmk1IOAhbNldZy49KwHp8= 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-122-xMba_EeYPL-FTD2gDob40w-1; Fri, 23 Aug 2024 16:08:44 -0400 X-MC-Unique: xMba_EeYPL-FTD2gDob40w-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-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 96CB019560AD; Fri, 23 Aug 2024 20:08:40 +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 DE7901955E8C; Fri, 23 Aug 2024 20:08:35 +0000 (UTC) From: David Howells To: Christian Brauner , Steve French Cc: David Howells , Pankaj Raghav , Paulo Alcantara , 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/9] afs: Fix post-setattr file edit to do truncation correctly Date: Fri, 23 Aug 2024 21:08:10 +0100 Message-ID: <20240823200819.532106-3-dhowells@redhat.com> In-Reply-To: <20240823200819.532106-1-dhowells@redhat.com> References: <20240823200819.532106-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.15 X-Stat-Signature: 8kdoc9wzp9j5o4wczyg6goone3un9fot X-Rspam-User: X-Rspamd-Queue-Id: 32F0212000A X-Rspamd-Server: rspam02 X-HE-Tag: 1724443730-17683 X-HE-Meta: U2FsdGVkX18jpEsUFGw4TgtCgd6l4CNQC3NREFmNKb+DqbCI4AEypOpFyJ4ZQclyzR/8bMY6ihZOBlI88KIIsZGsHcY/0x1tIPqSxDi/TOv/gwa6OLKEtNHxbi6g4vNGo4mRWoEryq/mgxlp8a9L6rrCTuP7rwnjirZeKVI6c5h1xwOYghJJBBjwjHoqnKcMw8bSOqvvJRc4MS51P65ITjEkAFGneofIos2dMretVH1zY2qKgsefvVO+ADUdG+/fU83CROVwjo3jV6QzVFieSj4nUTE4mYbEBaD/50hnAhWUHj8/KovBYo221TDYn+Evkj72ciJnGrMkpizeA7tRWEhUHuc/dj1p9AQbjsfJieRNSTnWJV0XC/PTqpcQ2cWWi83o89Zx6CFr5nEX30utvKYeYbaTMyiExAwpznqn02xgVW2yyeSDQnmFuzmd9czGKpyA8+CMV3ldcFA+r/6w9SZ71GO3fIRQziYkn8YC6c/Z73oS5fUhQI8hanMqCcEIPOJRFLBFRZxeZleTW13ULR/BeteBNelH9vKtu3X2nHndEwM+bD47COOVJCQiFKcthTo8pJqtUeexqVa4H04XLDHGSmXfLvx7PtvFSiuytGhX1prcLVPfhuqhoIru3058/315YXiqm+KmAbTxYMIPYWxQOzAURuCiek8WMnT6IDWOLK5raQlqx10wc8Q0q1JvQYlTpqlJO4AFl2VvkSd4YgEXf3VX1NLwR+M1m6H3c+IbfOhQfMae0vutinFHvTEkwCzSGJuci8b/83Fuo1MPS4q6KQsfHGpFzqgTJdxn+lEPc8f9Wl8lR6GvjwvfAV8aXKtqt3rRxEuzASc5rwhhdJVFI+3W/Uu9rdrFfX+Qp7TpapZwsN5nBmizbsnBR3T1v/YE+2gooImlWYPIHUM3AhUPtCqM0z9V4JNWx/fSHR9Qou01TyFgJzHkxrdkDtLzwcXqA/Ob7cd0iv17Wbi INPBUSou o6NUivW+2CvAVHxlDf1diyzRPGOaSUfRHNmmSHytNolrN1kyW2vQls9grDnv14shwvu85DAVyqN9nyKVnntz8hpVBd2OsqOKDE2QjagJMp1UNpIYuXpRzll+ApdE4gq3/FfQKDMD1oSRqpnocd4ggb6JRD4S3ZUTbCaoGl1/eoMiMiip3hcrPxf3wH8+CDOMY4MAaAaTP3niGLQQxBdsq9SZ2nykRIeGymaLCFQNYm32RcTBil8gqGZcOCGVEE98Wf07JMuaMgJd60P8wUtsMyoa6PR/aHD2HcsgAOntHLgVFnun87VPyeR/ejrBZe3V1jzqsqu0YROayQp0bZ+Ae8TbNLZMJK+n4E1t1IdEO10hkHedd7reqrVkCYePHJcqxZ5VEZYue5MHFUS/KNfluNwGU3mzCwZ1KxQ+CZmt/euXjLyVf19V4QRAAOJkRF5+nsbUSy1GJYSdRQOJv2ULcYQqS/7X8kOCDOWbVcYDe4dNY+rXFPDo570nA/wViUGxoa+YSdJUoo7SIE9eJNCVYKgGky5sTI1mnRV/H+TPj3g0jATedgjgPUUClHA== 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 Fri Aug 23 20:08:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13775933 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 5B534C5321D for ; Fri, 23 Aug 2024 20:08:56 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DA4106B0279; Fri, 23 Aug 2024 16:08:55 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D539C6B0278; Fri, 23 Aug 2024 16:08:55 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BCC9C6B0279; Fri, 23 Aug 2024 16:08:55 -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 93D916B0276 for ; Fri, 23 Aug 2024 16:08:55 -0400 (EDT) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 1E6241A00E0 for ; Fri, 23 Aug 2024 20:08:55 +0000 (UTC) X-FDA: 82484598630.05.44FCEDE Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf28.hostedemail.com (Postfix) with ESMTP id 6B562C000D for ; Fri, 23 Aug 2024 20:08:53 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=ekz4yxq1; spf=pass (imf28.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=1724443623; 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=rMRkcKek9lVISY3DopYxhGhNsAhcFddf3ky4pWgjlz0j1lBPyDJwLsbE/6Eac0VZxxf2fW 60jfAHfRFNN4UZiI+5bCpLtO1YQeNSeQHmljCusOWWZnjLZ8KmpahGPogSvgHLUh7D4Tmf qW6t9hCphN6LIWZl61OkYld6g46O8AA= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=ekz4yxq1; spf=pass (imf28.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=1724443623; a=rsa-sha256; cv=none; b=CrTEOuH/74ztu1f4T+ABMUwmh0p+sCKHddPfojgsJaYng7T/zzY0D8xdpF1kk7bPRa4bkH JR/uGDQ+1hyjn6HNPmp0EIOKyNmQ6ur1HEize+MY5lgLHmpLFscuxA7K2U3QI2CP3ba7q8 Eu4L6JMXv3kOMwX8Hi5X1oW0+yzehzs= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1724443732; 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=ekz4yxq1RLQzM5Xgnwd9faEVqSNzz4WywcsTRXv/TnieTnLRJ+uIN5CFnBzRVyCUoMVF2H GgYOMpc8dEXHQyKjeJfLjZglTPo8F+sWPJwlzewJjyF8tRCEkr79AteZfSBsIf1g88R2HH JBb1GPKUGDcELj0snBvEPdnRvQUamp8= 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-439-JPiGnaA-NR6p3XE_f4cFaQ-1; Fri, 23 Aug 2024 16:08:49 -0400 X-MC-Unique: JPiGnaA-NR6p3XE_f4cFaQ-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 385D61955D50; Fri, 23 Aug 2024 20:08:47 +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 D8E451955DD8; Fri, 23 Aug 2024 20:08:41 +0000 (UTC) From: David Howells To: Christian Brauner , Steve French Cc: David Howells , Pankaj Raghav , Paulo Alcantara , 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/9] netfs: Fix netfs_release_folio() to say no if folio dirty Date: Fri, 23 Aug 2024 21:08:11 +0100 Message-ID: <20240823200819.532106-4-dhowells@redhat.com> In-Reply-To: <20240823200819.532106-1-dhowells@redhat.com> References: <20240823200819.532106-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.15 X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 6B562C000D X-Stat-Signature: owzfsdkywcutxnzdjzpp1xhk15koy3mf X-Rspam-User: X-HE-Tag: 1724443733-264326 X-HE-Meta: U2FsdGVkX18Kra0EKL8QUCnlIG0m1EPOZaWmEFRiz8/0U2Oenv4j/lPwQ9z9lRL5q7YvYCE6kzjfCXMVJGS7/T+g8XRb4qWhlAmgL7EURVONEItSKOErBCyMyuaAyzKC8vrd1xO389eg4r85F+j6c8dX7J0XP/BMj0RxOFvZYa/MXxIpeMiSObzwUQ+rh0gqUnmCDIhxAmffM44qsf22gkiL7WlvHmVKKjExQCFXl+eqxfwkodGDuinFKZ8vEHYiUUI1JCliUPgSCROB3QiNauOmKS4OsUa3cwUAZrKcqfXGPmkRFBB8ZzcetHtEFKp9x/VrER5Mmm5LB53jNAUbLkJG1xwR5wSNZ6S2YnmjRQVtJZTO47cUxlNu9G2pNyQYGhunanJVe6YHMQkVcx/bGdN1yC11OBrq0BMnuqQ5wRofpJ5bZFexPyZOVoi+Zql7Yt8dHC+2QA1WEyBC3pjihIgmWYE+fo71/xMq4Xlexpi+w4U4OHdhCCZZukZHgnFj+DL0EhSvioIQ9Vzh9Ym7/MhBOZfeq+kka2pdd+5g3Ig8ch+SGJrP50Z2TcCIRkMTv5OuB5CFLIPNOHDKqaPRQnWBaLOtZ0pLXmlRGhdJ9ubxNauXsMse0xsXWcH7Xv1saVx3pgcWwPMJHu6E576fCSrAmBjCfTWqlcYq+pWD/Bc6DyPhsevbcPodkmGPOQ2glZZ5uwwu9AY5/tfufs9RzUgGtmOfvs8FX/DTpnBIqZ/W2AIXCP2uwCbEXfC4Q/1+rLdmWIcXH3Id1yGCR8smZ7yqmO4TV4vLJeqjZlvOx6WC8CSlALG9lkHDQeJpWHNdY+Hyf41Ndc0gZVmhfZlWkX8YkDbsaNPxhOFp0F2ODPEeGjhivpWnXc9cI3XbE8aFpEgIQE3RnUgHqq+f2ZY/iYFofiHuvZOJ3T4HPVN+8+bd2zDUYLZMF/6ttoyys3u8hovmVRFkxpirAL1ZSe3 KaAoAGfF N8bPjjUscY/V79lng/pDIFZ0/4Ul2t8n5bxYfppBzvIvmPjB1+t/TXVQf5l3jeioeTdnDXOf4r3RZ9wlNSTnApHMVg4iA6O16901uGcJBMbDbLwJCU4ZHh0pRXwO/W5v29fsZpp9+sA3M5CTpHoeGeOsXChTLJ+quhOJ7CWrWLfO3EdRWcRNl03ePANs6EdzWdK/wi7gr6NoDTkRstU8hTRNzT/TkWd/L7k7t9iLvDFRPemcrl8GC9BmURROPUrB7l1fucYnCdef58omIl5mSlxxNPoh21Yq+1Nc3zBmx4/0hAkv7stv31n8YUthqnbG2sjR5mKir5+PxvW+1tin4KnJLTY8/6AznqVjfPce0rmt/AQRx5JLwDjgMxdCxvgPn43ZhnDcHrnFVdMwdKtpafPsa/3061vOKDsd6XBxYLMBIhm2cUwm57z8o9CfXKSauQaENVZPEboOcIaoQyfiUzkukUWHAcRDIyqPi4rX7ffhrQYxThCr2Dtpk0dvlLY/n4vxgg5TwlFA+DYDeC/sshEHht8nZCb/JNSRq2QOaZtMoEsTUGZ8HYNJnUQY1zsP4bknuFwoH0LqxrcUB5ezA/8tYZxaXjOrGQFIfmU1dm1zx7EYERXgCmbkSw5SZ3DBH6OXodinJeR/COlLW9tdsxNN5qcput3Amo3Ka 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 Fri Aug 23 20:08:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13775934 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 189DFC5472C for ; Fri, 23 Aug 2024 20:09:05 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A20C46B02CE; Fri, 23 Aug 2024 16:09:04 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 9D0346B02D0; Fri, 23 Aug 2024 16:09:04 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8713B6B02D1; Fri, 23 Aug 2024 16:09:04 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 69A176B02CE for ; Fri, 23 Aug 2024 16:09:04 -0400 (EDT) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 1C2E681E54 for ; Fri, 23 Aug 2024 20:09:04 +0000 (UTC) X-FDA: 82484599008.03.D57C373 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf19.hostedemail.com (Postfix) with ESMTP id 60B9C1A000E for ; Fri, 23 Aug 2024 20:09:02 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=KDyqb4ii; spf=pass (imf19.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=1724443677; 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=oIG6tx6XYNU7ALVI340GW0VFFIUXzPUblKoQcY1ifM2B1ObjVUUPr6DCwpF7gA2fInh9us c6nrEeXMB212dHAQwzoAXEZyM84R3y9n2+QvDEqyBU8kZQvgBiVek260mBAB8Dyakj1H3p Fv8EAkbPiAaqFifWTPdI4oQvvmVmXFo= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=KDyqb4ii; spf=pass (imf19.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=1724443677; a=rsa-sha256; cv=none; b=1s+XiIUpnT8OkDG4qlIzBU+MF82EcU/M71wfDgCdumQY73intHo7WMrqcYmUccjdl4J1n0 KCruHmNJcvwvu7JxqSaBJDaV9631UHmGB6qQBQcQB0lISuDIoU/iDtPHbJKTwM+RLIprZG wHSo7kz3bB4uRdx44E9vPFC0oOqVNw8= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1724443741; 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=KDyqb4iiIX4v+uz9pi9cOp44FdJGHKfGzzB+E1sOSPutNRSrU0ysVN27EBCZpEVo8dfGMl 7luCFWL/8vlwM5cPGzKYjM91Ymm2HMktxz8Z8YioC++2kw01CYsagxlDvwg58riZJRttVn kHvGnzqQ5AxNnulPygPGCMi4jFWLuBs= Received: from mx-prod-mc-01.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-461-Sz3wsQBWNzSGl0B-Sn23dQ-1; Fri, 23 Aug 2024 16:08:56 -0400 X-MC-Unique: Sz3wsQBWNzSGl0B-Sn23dQ-1 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (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-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 4EEA41955BED; Fri, 23 Aug 2024 20:08:53 +0000 (UTC) Received: from warthog.procyon.org.uk.com (unknown [10.42.28.30]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 5B0903001FE5; Fri, 23 Aug 2024 20:08:48 +0000 (UTC) From: David Howells To: Christian Brauner , Steve French Cc: David Howells , Pankaj Raghav , Paulo Alcantara , 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/9] netfs: Fix trimming of streaming-write folios in netfs_inval_folio() Date: Fri, 23 Aug 2024 21:08:12 +0100 Message-ID: <20240823200819.532106-5-dhowells@redhat.com> In-Reply-To: <20240823200819.532106-1-dhowells@redhat.com> References: <20240823200819.532106-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 X-Stat-Signature: 63as3qygiqettmgdw5wqpzu6sedu6j9u X-Rspam-User: X-Rspamd-Queue-Id: 60B9C1A000E X-Rspamd-Server: rspam02 X-HE-Tag: 1724443742-878444 X-HE-Meta: U2FsdGVkX1/djGp+z/hsU7+6iagJCuKGlbjdHIai/3ii1FNL+XaUqFCkWcIe78sKVA//ErEXD6fg2cGqFosXzZUNQvOlEaNcGCTG0VbCa+i2AFJSYWfoNFU8wllWxAkjsS2K1oeCngjVuUexkgS5FFSzcPw9qX9AAIQj0RlgWpbcgu2Y+DBDrG4XFsi173PBzlwsZpr1H29EinL+WJDUFtMPssla7q8KUuDjfbVT3Of3wbctIjSHpuHB9xjLW5BBHU8+ulr9QOAJP0DRnUnAdJq8BPSi2FJhMZ5kp6lqyc4cAJjiYnC2FU/aRjMDwf9IIFU1AQviw6Ba18fVAlfidThcJAuJlqGSUS+urHYYDwm6xMY8bFpeoc6X5togZuixqDCXyFVcEtDi5LH8OoQaneYsqiFCY7mJ/Ti23Cmokix3y6m1LxQCI9U91gPzgHe6ea4cJ//N3dq4MAtwNJRsSNMhMrfDrKcftpluyBtukTCGJx10vo63wAsb/nc5IUBR5UAVEFs5tGqhyT3zYlFD/VBH5BxAxGWKkGRmQ71PbaSenv6h1nEfi4LXkZYJIyNZL+uDhUbv7Fsy27tc9cDQxTGsS3GNCkD7xLrUWBsru4VKPzNERfBJZir2rl4osv6qtPTgmW20AWWUjfqQv0F4VTZG6kqbZAZ0XmhQ9YrsNT0u0pnDhCqniqRxThBIjqvubajIEyLPLgbJcTc39KESnCzhycQnpcyaqHrxkEPClPMPhj9BjrhwZe1xZZ9IJ1LZIvHIL8HPb7YAPsrhpxX9/vVU3CthfJ5eNM6hJb8om5LvwF0cJzzX29v43gP8CXdKa7e7h8vjlF5uenrmwt1hIXhqPiw8esCbc4J/9NYC/iy3YURmA3d9wZnPKRoFk7nzOZ4nN4gad70YiiRUNSfCnaym08OFaJB3IfhZ91LI7aSx+K+fKou7xyD/HkqmmUmacdos6VM4/XGZpvoCSqy JtXyYCjy H12h50NuWohidfZJQsxuYe7FOll+BAML4Ne8PVC2IMijC7ZeKcouZdf8msL3NXCya5BWZbQS9iRANAq9gZWdU09azsIDfQpemYPA5qW6fitSb8hOwMFewI8KKtDZMV2+TLxlLuQFyOsiEq0oAnky7H99anbokWFnAmHVEYttmCaLv1yZSyCF7VDRM7BpCT2ynnc4RZyHeykY9nyt9mVWj3V6VvEoHgiIZ4hRarMtpFTypBYvb6bw0QX1c4S4l4TVDvioRbdRkMF1gaUMHKMSDfdvQwnq+oj/jVUDL9Bm1RwwclhEfqyuYeHUpmxwOhnXWy0AbD33s6jugkzTh21qpDquyhG2n372ne7uh6JdBJcvK+D0SXjaILpVNU5FXnh1e4Qo0ASvcSj+pf0843p4iVWM6Aim0BFFW6Hm0vXyboAZNiX1Zd2LdKRvRKAYXKLJpjCTVt3iTMuPfdgz2XKuh4bvc66xo25UXX76CN3bwhsDAxXqV054KvYpzXSWWf8QmFNvkvsrEQvEFNXFjYLRY99orzOLGWs1gwaebSZH/P9ifnshxfpwfMxjOKaTeN9DS63Kz4WYOGqb14KFrnVpQXmO3Amg/9KTNRDmKRQkpAgJx5ND6BBwpLzpWrcKmj68gBJmo 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; From patchwork Fri Aug 23 20:08:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13775935 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 C2F86C5321D for ; Fri, 23 Aug 2024 20:09:10 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 53E5B6B0308; Fri, 23 Aug 2024 16:09:10 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 4EDCA6B030A; Fri, 23 Aug 2024 16:09:10 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3DE7A6B030B; Fri, 23 Aug 2024 16:09:10 -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 1D6EC6B0308 for ; Fri, 23 Aug 2024 16:09:10 -0400 (EDT) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id BC61481E85 for ; Fri, 23 Aug 2024 20:09:09 +0000 (UTC) X-FDA: 82484599218.03.33BCD51 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf09.hostedemail.com (Postfix) with ESMTP id E68E614002B for ; Fri, 23 Aug 2024 20:09:07 +0000 (UTC) Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="PbPaHx/f"; spf=pass (imf09.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=1724443682; 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=J+Q2VjHdhruKVNJRsL+DNuwA1V8DkjXpTij4fAf/kXM=; b=K2n44lv7Nd0IaCNRddX147RcSsYBQNyWBJhI8pdwn2Tg/pyS25g8LPIj8t3D1k58lcEfj4 avz2vs+y4BV8jbOVPJLfrtVNImI8OZ0sCP3VpRD81/0QKc7FpCfdhLFPGIzbkuaheNgF0z jR6DmWPrhtDBqTYub56jltQEnq6FmZ4= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="PbPaHx/f"; spf=pass (imf09.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=1724443682; a=rsa-sha256; cv=none; b=q/MljYJQtLX5kqfLf24R7AOco7CJNaL+ByTMwlexYhGBrL/hxV0IP0RWziTYpSuHj2qTJi s7DWF/csYqygAuxePRcIby2u1VIjzyP9hwsjgAbbdP7tT9iecF/Rwo/rMsnbcHF4sd5QrC OVUyeFgU/aWWVEivw8K7NHokP44wZB8= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1724443747; 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=J+Q2VjHdhruKVNJRsL+DNuwA1V8DkjXpTij4fAf/kXM=; b=PbPaHx/fPP54Bw874NsvZmT1iFpCzay78CIXmDjOJP7pgRWGviPQ6je4hFdxYHUMMcVx+T oSib5xd14O6aFOc6+EhJIGaQ390tT6moGeygSt9rMsFyk/1poFg4Dn9cRxcJDaGkHHPWrw YIShIkXCXG5SpWxlrBT3yzGEcty/6Pw= Received: from mx-prod-mc-01.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-562-iX0mBMvkOMy-sMazWAhTNw-1; Fri, 23 Aug 2024 16:09:01 -0400 X-MC-Unique: iX0mBMvkOMy-sMazWAhTNw-1 Received: from mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.40]) (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-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 6A0991955D48; Fri, 23 Aug 2024 20:08:59 +0000 (UTC) Received: from warthog.procyon.org.uk.com (unknown [10.42.28.30]) by mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 90C0319560AE; Fri, 23 Aug 2024 20:08:54 +0000 (UTC) From: David Howells To: Christian Brauner , Steve French Cc: David Howells , Pankaj Raghav , Paulo Alcantara , 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 Subject: [PATCH 5/9] netfs: Fix missing iterator reset on retry of short read Date: Fri, 23 Aug 2024 21:08:13 +0100 Message-ID: <20240823200819.532106-6-dhowells@redhat.com> In-Reply-To: <20240823200819.532106-1-dhowells@redhat.com> References: <20240823200819.532106-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.40 X-Stat-Signature: zzpzqsdbtekf6us5xru4ii1pna311opi X-Rspam-User: X-Rspamd-Queue-Id: E68E614002B X-Rspamd-Server: rspam02 X-HE-Tag: 1724443747-526713 X-HE-Meta: U2FsdGVkX196w0Q8TW7hqP7/qzztRRWnYi3/vcwohyc+zBIO4L7AxOWTAeGvXNgbKn2g1+3rAQ03yiSwCAytHxEgjHcgnYY0WB58bUQ56dccHrGOi574odQhOc1P1HhXH5TnG4/pq6E8iGGcwzjfDilcF+WCtgsuqs6zdEN46yYf0j1/ElV8fW7n6t2HwQcgox+ZQd1AqOq+fcPKJGKkRhOA8+wle7UAeC62s1MCn9O9mNM+wLNuXsgPmArW5cTxUXvtUFl2sVSLWcy/CCAudmgGA55C+MyCv9k/UcJWhe9fkYVeAto1pAj3zmVtdFdzGB2q6YNqOxeb+NJeHBI51S1XhJGXEk7s0KUWUygUjlvbzq1w9gC64p9Vzyati2zo/f7h77zzmsL7K6XM4P8lztahHFrsdTL71cwxHxRHOFpfniuDF1j8byNv4hNg7KXi6y7UDXeDKtbVePkBcEHdZhLFMeQ01jizT25MN0GzxaAaSj8BtLPni0zfjgOR25PVNThlYQrxJ0EgpQBLOVU9keJjAgA8JyNvSkBK38P5NXBEpn6bb4NakY2XpTFn00BeNYgNCzCmqKVj8VL056vic64wCKAqtx8GK0BLsUPBag6K3ISRePKStuoV1Z47JpXmmr94ldLLmKeKMoQu4yey/bTsMhP9OhE07ARmkk51muHm7TvdGo8K8+GCK81IJYvCsnDpfGdDvm3Ehf842Kfgz0WyXy9Dc2SU+1hxPa8RSDXrXGd5uBmOvSWy4xcQzV8VpV+1YcxBH9rmQWLcUoelgQjNrTFLdT8b2siUunv2qIBWvl0n5h4+phiY6u9L5Th1AY/JP7BrP1WS9ZVUztY7BIqvJfMnzDiCT8TyXLh5fdwEHYRB6stMJjp8xsE7OMtPzQ14ykneP9JsX4rb3RN09b4Pvr8vyNBzoL2y4wC+s65ZBOQexWSkZR6fOupu4jkedZEZJQcOKS3WfTUYQ2l MnxhXN62 cKlE6kyvR0/6uh7KW/Kzp5vWJUPdFHGWdW8QvHR9xmnBHiQJvEtPFWcGp1bkrkDiuWe2+DRMwR6KucY+NJgEPAz5hy9v3iF8lTUqLst9eZQWV3kR+Rfs+9JeQYxw4MLwao2YXzqGGIfYCd8cs1gAQ8Ynz2mk3F0Ducu4J8Z/hAedGbWZXVvvFYTP4Xa9v4xVE/xkm4jILvKAUfIYdDnB00/75QZO+QGjOq1n5f5AoOdLor6SKoZCoewTjBAJIRFqryNlyrwrRPfkpqADr3yoOXcakf4uWiDZpfQY/7p7MiD3cI90QsInblGrIU1jhpo40t3nvPUaVypF0tUlNel2VxR392c9+ayNRiVuoTK00lnrfYiSBV4u5d74JSte/2Po7LOPMW6FgqRzdQduLmqLTAwbOQC/E2WDc+aSZPvDMsGEuUGy3U0rpMZjXe97Y5g8/nGkmqsPJAsKVfEOAzZjWKI/ShHLxHBVRamt7 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_rreq_perform_resubmissions() to reset before retrying a short read, otherwise the wrong part of the output buffer will be used. Fixes: 92b6cc5d1e7c ("netfs: Add iov_iters to (sub)requests to describe various buffers") Signed-off-by: David Howells cc: Steve French cc: Paulo Alcantara cc: Jeff Layton cc: linux-cifs@vger.kernel.org cc: netfs@lists.linux.dev cc: linux-fsdevel@vger.kernel.org --- fs/netfs/io.c | 1 + 1 file changed, 1 insertion(+) diff --git a/fs/netfs/io.c b/fs/netfs/io.c index 5367caf3fa28..4da0a494e860 100644 --- a/fs/netfs/io.c +++ b/fs/netfs/io.c @@ -313,6 +313,7 @@ static bool netfs_rreq_perform_resubmissions(struct netfs_io_request *rreq) netfs_reset_subreq_iter(rreq, subreq); netfs_read_from_server(rreq, subreq); } else if (test_bit(NETFS_SREQ_SHORT_IO, &subreq->flags)) { + netfs_reset_subreq_iter(rreq, subreq); netfs_rreq_short_read(rreq, subreq); } } From patchwork Fri Aug 23 20:08:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13775936 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 3F2CEC5321E for ; Fri, 23 Aug 2024 20:09:16 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id CDEE06B034E; Fri, 23 Aug 2024 16:09:15 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C8F656B0350; Fri, 23 Aug 2024 16:09:15 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B30766B0351; Fri, 23 Aug 2024 16:09:15 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 948F16B034E for ; Fri, 23 Aug 2024 16:09:15 -0400 (EDT) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 5A1C5C1E17 for ; Fri, 23 Aug 2024 20:09:15 +0000 (UTC) X-FDA: 82484599470.09.35B9BE3 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 A5B8014000B for ; Fri, 23 Aug 2024 20:09:13 +0000 (UTC) Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=WFSxc58Y; 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=1724443712; a=rsa-sha256; cv=none; b=KkRHAgC6jJVuCwP2zheLMMnbMNmbzs6XCh+Z1KmTyKH3+8rZtcceLn3lTpWEoBHIayO5ZJ 2QEe3b1MpFTHxWWjTDCuMdYwRcyVx0s4nQz3B1E6Xo2nJSOMH7HIIQukxh9onQJbPXZ/X3 +p7CLaOD9VQ3vJ3cZI3xEdl/DuulEPA= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=WFSxc58Y; 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=1724443712; 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=jhhLpebTwUeEsqiiCXCW6FgURg7tDrbiy/xAxbLEp7c=; b=y6jxVM+H8r5HHLDcdprpwTXkDWqoTx3DQF8AEzvTKrc5AIUgWu+RPM+o4cvkG6b7iGYWev KuBy3JsCP1NlpbTQbJZ2GqigWPqa5rzVisvo79GrnGEuEwiDgG/KLQIyJSkMAUIe3P1Egw LbI6EWcSdcGe/uQ6SKNDRaeiv+xtmQ0= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1724443753; 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=jhhLpebTwUeEsqiiCXCW6FgURg7tDrbiy/xAxbLEp7c=; b=WFSxc58Y17tin6af0kj3KhlumbItLwzXaJRwa3Ht+C1XUl6Z125tAyG9opZd0EoQGuCEEe erCgbQUoq3J7C8obFOwP0DAJUd/lDWKoN98O5su5giEzx/DP2PXCxDHaqwPPSojSnEcbNP afe91gnU0v1U9hY/0IuzWdwNjqdiKtg= 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-621-X6x6BoSbM_mD1yPRqXW4Vg-1; Fri, 23 Aug 2024 16:09:07 -0400 X-MC-Unique: X6x6BoSbM_mD1yPRqXW4Vg-1 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (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 1E4251955D4B; Fri, 23 Aug 2024 20:09:05 +0000 (UTC) Received: from warthog.procyon.org.uk.com (unknown [10.42.28.30]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id AC9E03001FE5; Fri, 23 Aug 2024 20:09:00 +0000 (UTC) From: David Howells To: Christian Brauner , Steve French Cc: David Howells , Pankaj Raghav , Paulo Alcantara , 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, Christian Brauner Subject: [PATCH 6/9] cifs: Fix lack of credit renegotiation on read retry Date: Fri, 23 Aug 2024 21:08:14 +0100 Message-ID: <20240823200819.532106-7-dhowells@redhat.com> In-Reply-To: <20240823200819.532106-1-dhowells@redhat.com> References: <20240823200819.532106-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 X-Stat-Signature: hdesjyh15mxaij8tq81swfk3fgusady3 X-Rspamd-Queue-Id: A5B8014000B X-Rspam-User: X-Rspamd-Server: rspam10 X-HE-Tag: 1724443753-122306 X-HE-Meta: U2FsdGVkX1+uxZZma4mzXJ+uRq5EPKzE639of3NCtzpo9YLCVNVTlO5WbBCnzJNpuoIFxb4v//Xmk8grBMn1UjawzXXOTnMG8TxaAt4BACSkpEZQ2P6X6E3WyRN2JTaBKcFnelrobNddEd94eUsB8y+KbLcuBUynsxQiRnst1+0VdluCxy0lRPVgo6nY78uMHwtm5Ik88G1fbLcGG2bh3kjXla4W6z0kcpx+lPNCaJFY3tDsxSJDAFy+2Hrh7f98aCNDhzhLYmNwlZ+g9COz/5iod4VVU4GqhaguMP4UNPbuC25D0AOmkvXVk1vxP3uY93UWT+zZKgs5N/xVKXboMJvh39VFSXPt6tZFJJHBqneareTuhxz7dQP8qWKWOmOZW0ifE6OjAiuom7O6rJvOB0ZpRAUwYD3flzXZu0K2VZCx8nsSRo40jjay9Wa3CIiFDKnJrxeGq6smcsJ3MuquZKFBsxXthgodDAGotclc5x+KWwL1Mlyn8AkaOyvg3xdF+l7yqI2HRQEIxedjqXQKUUYloCbgkTioyVHaSWh/Eun5sXdqxUAjxgHZg23W87A9T4AzgpxI8uM8IKeCo9Cy5/qOz5DsEtzwYVZrdMB0FdFz+Wvozs4PN3Sdm/J81pwP6WBYgs2pilZLbT0VaEv80vpB0zugLUfwhF/Wn8haJQFpqlioj2MZUAG3bvotRSv1aHoTeyLV8S+P5d+jg3/4ijoEq68Izvkm2Occ0ubWqi4wqyQ76Ee1Vh8IY+9fFNkp/DTQUxcsXLd2lV2i+U1jg8hwfNld1rfLCZLpmYgVWO4qA4uhJJ+xyWd+6JaU0k+2xn9wgZN2UcXhovOiZBATZ44UDMHsf5++KN0fa/XhO4Q+LbCYND2MV0N6/0g0MQEaw17LUacfkBp/9Iqu9x8pou+nxbW4QHV7oSWPVUDuChK+V19gBQzl005EOozN92ZSH/tqIiX6rI73N+pAV0X rExIVpR5 O4Y0XsgSSHKvgToYU+afbQrI4P4qf8NiCwW0ZGqIwaz1hpFBAM1hLKBo6hBqqcrTLZuJDKtMY6Wq5eKvcokHxwQNuwc2J00TA9Sl9Bh8vOltll0jF7AZP4qO2q5DfVWH5/s0SWTPDPEUXY0MrCwgWjrhB9V3ZUWTihK3/Smg0M8k7q7LTLInOzBW8hZ5Fnj0Zqvn1Vo9R4GipiK/ahdsGQv0JPgqRIBuMjONO+PzW205d7P8i9b1zOgNQjbpbDsH9OGl71TN4oRMi7heYjzdJtQ50L5gUiRkSYNKyxk5VEKlL7ahQJa3czHxHfb/S9d8wkoKLehvkq/k6OMq66CCMTC9LMtf99i/q9GU1oylmWOOb5Vi37FZWh96RpSW1dGq8O5j9sKhlUKbA/YFf46x7tKgF9dQEf23GocaW0obbFswJUGsDtCri+Qbkpk99JaelYfoFfIK0X0aVsOqVVRCnn09lqhOL34enBGSk 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 asks cifs to issue a read operation, it prefaces this with a call to ->clamp_length() which cifs uses to negotiate credits, providing receive capacity on the server; however, in the event that a read op needs reissuing, netfslib doesn't call ->clamp_length() again as that could shorten the subrequest, leaving a gap. This causes the retried read to be done with zero credits which causes the server to reject it with STATUS_INVALID_PARAMETER. This is a problem for a DIO read that is requested that would go over the EOF. The short read will be retried, causing EINVAL to be returned to the user when it fails. Fix this by making cifs_req_issue_read() negotiate new credits if retrying (NETFS_SREQ_RETRYING now gets set in the read side as well as the write side in this instance). This isn't sufficient, however: the new credits might not be sufficient to complete the remainder of the read, so also add an additional field, rreq->actual_len, that holds the actual size of the op we want to perform without having to alter subreq->len. We then rely on repeated short reads being retried until we finish the read or reach the end of file and make a zero-length read. Also fix a couple of places where the subrequest start and length need to be altered by the amount so far transferred when being used. Fixes: 69c3c023af25 ("cifs: Implement netfslib hooks") Signed-off-by: David Howells Link: https://lore.kernel.org/r/20240822220650.318774-2-dhowells@redhat.com cc: Steve French cc: Paulo Alcantara cc: Jeff Layton cc: linux-cifs@vger.kernel.org cc: netfs@lists.linux.dev cc: linux-fsdevel@vger.kernel.org Signed-off-by: Christian Brauner --- fs/netfs/io.c | 2 ++ fs/smb/client/cifsglob.h | 1 + fs/smb/client/file.c | 37 +++++++++++++++++++++++++++++++++---- fs/smb/client/smb2ops.c | 2 +- fs/smb/client/smb2pdu.c | 28 +++++++++++++++++----------- fs/smb/client/trace.h | 1 + 6 files changed, 55 insertions(+), 16 deletions(-) diff --git a/fs/netfs/io.c b/fs/netfs/io.c index 4da0a494e860..3303b515b536 100644 --- a/fs/netfs/io.c +++ b/fs/netfs/io.c @@ -306,6 +306,7 @@ static bool netfs_rreq_perform_resubmissions(struct netfs_io_request *rreq) break; subreq->source = NETFS_DOWNLOAD_FROM_SERVER; subreq->error = 0; + __set_bit(NETFS_SREQ_RETRYING, &subreq->flags); netfs_stat(&netfs_n_rh_download_instead); trace_netfs_sreq(subreq, netfs_sreq_trace_download_instead); netfs_get_subrequest(subreq, netfs_sreq_trace_get_resubmit); @@ -313,6 +314,7 @@ static bool netfs_rreq_perform_resubmissions(struct netfs_io_request *rreq) netfs_reset_subreq_iter(rreq, subreq); netfs_read_from_server(rreq, subreq); } else if (test_bit(NETFS_SREQ_SHORT_IO, &subreq->flags)) { + __set_bit(NETFS_SREQ_RETRYING, &subreq->flags); netfs_reset_subreq_iter(rreq, subreq); netfs_rreq_short_read(rreq, subreq); } diff --git a/fs/smb/client/cifsglob.h b/fs/smb/client/cifsglob.h index 5c9b3e6cd95f..ffd8373bb4b1 100644 --- a/fs/smb/client/cifsglob.h +++ b/fs/smb/client/cifsglob.h @@ -1486,6 +1486,7 @@ struct cifs_io_subrequest { struct cifs_io_request *req; }; ssize_t got_bytes; + size_t actual_len; unsigned int xid; int result; bool have_xid; diff --git a/fs/smb/client/file.c b/fs/smb/client/file.c index 1fc66bcf49eb..b94802438c62 100644 --- a/fs/smb/client/file.c +++ b/fs/smb/client/file.c @@ -111,6 +111,7 @@ static void cifs_issue_write(struct netfs_io_subrequest *subreq) goto fail; } + wdata->actual_len = wdata->subreq.len; rc = adjust_credits(wdata->server, wdata, cifs_trace_rw_credits_issue_write_adjust); if (rc) goto fail; @@ -153,7 +154,7 @@ static bool cifs_clamp_length(struct netfs_io_subrequest *subreq) struct cifs_io_request *req = container_of(subreq->rreq, struct cifs_io_request, rreq); struct TCP_Server_Info *server = req->server; struct cifs_sb_info *cifs_sb = CIFS_SB(rreq->inode->i_sb); - size_t rsize = 0; + size_t rsize; int rc; rdata->xid = get_xid(); @@ -166,8 +167,8 @@ static bool cifs_clamp_length(struct netfs_io_subrequest *subreq) cifs_sb->ctx); - rc = server->ops->wait_mtu_credits(server, cifs_sb->ctx->rsize, &rsize, - &rdata->credits); + rc = server->ops->wait_mtu_credits(server, cifs_sb->ctx->rsize, + &rsize, &rdata->credits); if (rc) { subreq->error = rc; return false; @@ -183,7 +184,8 @@ static bool cifs_clamp_length(struct netfs_io_subrequest *subreq) server->credits, server->in_flight, 0, cifs_trace_rw_credits_read_submit); - subreq->len = min_t(size_t, subreq->len, rsize); + subreq->len = umin(subreq->len, rsize); + rdata->actual_len = subreq->len; #ifdef CONFIG_CIFS_SMB_DIRECT if (server->smbd_conn) @@ -203,12 +205,39 @@ static void cifs_req_issue_read(struct netfs_io_subrequest *subreq) struct netfs_io_request *rreq = subreq->rreq; struct cifs_io_subrequest *rdata = container_of(subreq, struct cifs_io_subrequest, subreq); struct cifs_io_request *req = container_of(subreq->rreq, struct cifs_io_request, rreq); + struct TCP_Server_Info *server = req->server; + struct cifs_sb_info *cifs_sb = CIFS_SB(rreq->inode->i_sb); int rc = 0; cifs_dbg(FYI, "%s: op=%08x[%x] mapping=%p len=%zu/%zu\n", __func__, rreq->debug_id, subreq->debug_index, rreq->mapping, subreq->transferred, subreq->len); + if (test_bit(NETFS_SREQ_RETRYING, &subreq->flags)) { + /* + * As we're issuing a retry, we need to negotiate some new + * credits otherwise the server may reject the op with + * INVALID_PARAMETER. Note, however, we may get back less + * credit than we need to complete the op, in which case, we + * shorten the op and rely on additional rounds of retry. + */ + size_t rsize = umin(subreq->len - subreq->transferred, + cifs_sb->ctx->rsize); + + rc = server->ops->wait_mtu_credits(server, rsize, &rdata->actual_len, + &rdata->credits); + if (rc) + goto out; + + rdata->credits.in_flight_check = 1; + + trace_smb3_rw_credits(rdata->rreq->debug_id, + rdata->subreq.debug_index, + rdata->credits.value, + server->credits, server->in_flight, 0, + cifs_trace_rw_credits_read_resubmit); + } + if (req->cfile->invalidHandle) { do { rc = cifs_reopen_file(req->cfile, true); diff --git a/fs/smb/client/smb2ops.c b/fs/smb/client/smb2ops.c index 322cabc69c6f..14c3d11869ba 100644 --- a/fs/smb/client/smb2ops.c +++ b/fs/smb/client/smb2ops.c @@ -301,7 +301,7 @@ smb2_adjust_credits(struct TCP_Server_Info *server, unsigned int /*enum smb3_rw_credits_trace*/ trace) { struct cifs_credits *credits = &subreq->credits; - int new_val = DIV_ROUND_UP(subreq->subreq.len, SMB2_MAX_BUFFER_SIZE); + int new_val = DIV_ROUND_UP(subreq->actual_len, SMB2_MAX_BUFFER_SIZE); int scredits, in_flight; if (!credits->value || credits->value == new_val) diff --git a/fs/smb/client/smb2pdu.c b/fs/smb/client/smb2pdu.c index 83facb54276a..d80107d1ba9e 100644 --- a/fs/smb/client/smb2pdu.c +++ b/fs/smb/client/smb2pdu.c @@ -4530,9 +4530,9 @@ smb2_readv_callback(struct mid_q_entry *mid) "rdata server %p != mid server %p", rdata->server, mid->server); - cifs_dbg(FYI, "%s: mid=%llu state=%d result=%d bytes=%zu\n", + cifs_dbg(FYI, "%s: mid=%llu state=%d result=%d bytes=%zu/%zu\n", __func__, mid->mid, mid->mid_state, rdata->result, - rdata->subreq.len); + rdata->actual_len, rdata->subreq.len - rdata->subreq.transferred); switch (mid->mid_state) { case MID_RESPONSE_RECEIVED: @@ -4586,15 +4586,18 @@ smb2_readv_callback(struct mid_q_entry *mid) rdata->subreq.debug_index, rdata->xid, rdata->req->cfile->fid.persistent_fid, - tcon->tid, tcon->ses->Suid, rdata->subreq.start, - rdata->subreq.len, rdata->result); + tcon->tid, tcon->ses->Suid, + rdata->subreq.start + rdata->subreq.transferred, + rdata->actual_len, + rdata->result); } else trace_smb3_read_done(rdata->rreq->debug_id, rdata->subreq.debug_index, rdata->xid, rdata->req->cfile->fid.persistent_fid, tcon->tid, tcon->ses->Suid, - rdata->subreq.start, rdata->got_bytes); + rdata->subreq.start + rdata->subreq.transferred, + rdata->got_bytes); if (rdata->result == -ENODATA) { /* We may have got an EOF error because fallocate @@ -4622,6 +4625,7 @@ smb2_async_readv(struct cifs_io_subrequest *rdata) { int rc, flags = 0; char *buf; + struct netfs_io_subrequest *subreq = &rdata->subreq; struct smb2_hdr *shdr; struct cifs_io_parms io_parms; struct smb_rqst rqst = { .rq_iov = rdata->iov, @@ -4632,15 +4636,15 @@ smb2_async_readv(struct cifs_io_subrequest *rdata) int credit_request; cifs_dbg(FYI, "%s: offset=%llu bytes=%zu\n", - __func__, rdata->subreq.start, rdata->subreq.len); + __func__, subreq->start, subreq->len); if (!rdata->server) rdata->server = cifs_pick_channel(tcon->ses); io_parms.tcon = tlink_tcon(rdata->req->cfile->tlink); io_parms.server = server = rdata->server; - io_parms.offset = rdata->subreq.start; - io_parms.length = rdata->subreq.len; + io_parms.offset = subreq->start + subreq->transferred; + io_parms.length = rdata->actual_len; io_parms.persistent_fid = rdata->req->cfile->fid.persistent_fid; io_parms.volatile_fid = rdata->req->cfile->fid.volatile_fid; io_parms.pid = rdata->req->pid; @@ -4655,11 +4659,13 @@ smb2_async_readv(struct cifs_io_subrequest *rdata) rdata->iov[0].iov_base = buf; rdata->iov[0].iov_len = total_len; + rdata->got_bytes = 0; + rdata->result = 0; shdr = (struct smb2_hdr *)buf; if (rdata->credits.value > 0) { - shdr->CreditCharge = cpu_to_le16(DIV_ROUND_UP(rdata->subreq.len, + shdr->CreditCharge = cpu_to_le16(DIV_ROUND_UP(rdata->actual_len, SMB2_MAX_BUFFER_SIZE)); credit_request = le16_to_cpu(shdr->CreditCharge) + 8; if (server->credits >= server->max_credits) @@ -4683,11 +4689,11 @@ smb2_async_readv(struct cifs_io_subrequest *rdata) if (rc) { cifs_stats_fail_inc(io_parms.tcon, SMB2_READ_HE); trace_smb3_read_err(rdata->rreq->debug_id, - rdata->subreq.debug_index, + subreq->debug_index, rdata->xid, io_parms.persistent_fid, io_parms.tcon->tid, io_parms.tcon->ses->Suid, - io_parms.offset, io_parms.length, rc); + io_parms.offset, rdata->actual_len, rc); } async_readv_out: diff --git a/fs/smb/client/trace.h b/fs/smb/client/trace.h index 0f0c10c7ada7..8e9964001e2a 100644 --- a/fs/smb/client/trace.h +++ b/fs/smb/client/trace.h @@ -30,6 +30,7 @@ EM(cifs_trace_rw_credits_old_session, "old-session") \ EM(cifs_trace_rw_credits_read_response_add, "rd-resp-add") \ EM(cifs_trace_rw_credits_read_response_clear, "rd-resp-clr") \ + EM(cifs_trace_rw_credits_read_resubmit, "rd-resubmit") \ EM(cifs_trace_rw_credits_read_submit, "rd-submit ") \ EM(cifs_trace_rw_credits_write_prepare, "wr-prepare ") \ EM(cifs_trace_rw_credits_write_response_add, "wr-resp-add") \ From patchwork Fri Aug 23 20:08:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13775937 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 AB94FC531DC for ; Fri, 23 Aug 2024 20:09:18 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 430176B0369; Fri, 23 Aug 2024 16:09:18 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 3B6406B036A; Fri, 23 Aug 2024 16:09:18 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 208B16B0367; Fri, 23 Aug 2024 16:09:18 -0400 (EDT) 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 0102B6B0364 for ; Fri, 23 Aug 2024 16:09:17 -0400 (EDT) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id B2F031C022B for ; Fri, 23 Aug 2024 20:09:17 +0000 (UTC) X-FDA: 82484599554.17.6EDC6E8 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf28.hostedemail.com (Postfix) with ESMTP id 15320C0018 for ; Fri, 23 Aug 2024 20:09:15 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=WTP+BMBu; spf=pass (imf28.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=1724443691; 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=QRzYATgp/3eeTZkiFzTxq5j7styCnaCIZoOTDKL0BZk=; b=dUeoWlA62XcERNZcHJMxtcaYiLLi69Rnd9bYW3iz2dp5Lxt0Pu1cOS3aG7GZuu0wPwuN0m t2h3WDo3iLvfI1y8XMWFcM2b/LGQsfRh5SrgicYoC/5BQtVl2+6uABLGvkEHBTeKK9yZ5J aUC2KpCjdKqe9lZHbr0FQRFvfsp4ouI= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=WTP+BMBu; spf=pass (imf28.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=1724443691; a=rsa-sha256; cv=none; b=E/yeLbZkKxCYPNOxGfINNCYHsHfJIXyB4zMfo0Ws9lD3UGqFX0RQKtZuIlac0kLgH761xg Kth7ClO+xugA0RPpqh3LHmkAG6VugG4/6HkuL88oGNjU6wdEC6ty/YW6d+LSbqIockD5HJ bDWD7HXHCsALJFtI5CNd15hHi4P51gY= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1724443755; 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=QRzYATgp/3eeTZkiFzTxq5j7styCnaCIZoOTDKL0BZk=; b=WTP+BMBub34R9eWqfAwTSs+LGYdzIyABbxeRcnF4SYsox3QsVL/omeWVHgNenE0gGpPd74 8skG6UrfIHOu8Dv92g8KBimmz1cnUHOXkC4W63ahbw3vgzKWjSmlVI0YdpzU9bTgEYELln 9Fn8Oajp+NL7wepVfUtRZobYALHk/4U= Received: from mx-prod-mc-01.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-146--Hm1Ra-bNfy8Awu75_bZog-1; Fri, 23 Aug 2024 16:09:13 -0400 X-MC-Unique: -Hm1Ra-bNfy8Awu75_bZog-1 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (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-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id CE8F51955BF7; Fri, 23 Aug 2024 20:09:10 +0000 (UTC) Received: from warthog.procyon.org.uk.com (unknown [10.42.28.30]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 76A741954B3E; Fri, 23 Aug 2024 20:09:06 +0000 (UTC) From: David Howells To: Christian Brauner , Steve French Cc: David Howells , Pankaj Raghav , Paulo Alcantara , 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, Christian Brauner Subject: [PATCH 7/9] netfs, cifs: Fix handling of short DIO read Date: Fri, 23 Aug 2024 21:08:15 +0100 Message-ID: <20240823200819.532106-8-dhowells@redhat.com> In-Reply-To: <20240823200819.532106-1-dhowells@redhat.com> References: <20240823200819.532106-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 X-Stat-Signature: 9cu7x7x9faua5pd7zp3yxm7xg3yn7fnp X-Rspam-User: X-Rspamd-Queue-Id: 15320C0018 X-Rspamd-Server: rspam02 X-HE-Tag: 1724443755-156506 X-HE-Meta: U2FsdGVkX19bTmEcQ9smsDsbhZ/z/xGKFdvF/7gCR9z+1rs+oZUt3G1ouXhDVIfvUqXhqH0RZNCG3J6Z8Pb75M6LbLeH5XaRNIceaH/8CHRxtPgPb8D7j1MS0lzpqYKllWSsCenrK18cL+P4zhwTmPhU8oPW8Dwt8KIdycdyUhVGvqa8YZZi0ikecK+Rg9YnrWgQvmLMBvcRSpaqKQqnZoi435NmLG7T1FysJjVH4xrRy/Cz/MMQCXR7eIplyZRvdhucPPsTt2EVJcBDT3Eg7wQ+gEIqw6PX0wFtS4VATLZTicpxMrRdZAN/x+xACwhtfpblOFzpYXiF3wZdT1w2px/m0/1Tq+i5m78pI231U0GK3XwmPUaxriQfrtzQ4bJIr6atP3d33dlARV7l+HOU4Yl21Bv3pKiZFM1D+kEjr4iMa4SvCIc0saITRFF3QgNOb2AtY+bhwpCDh9jsbxSZ3o39U0fmullk+UidwFjthkPcwIc0gsPm0QHDjCMbctYmc6TSezCawKVZnOYh0hTVTtvrhteRSJeVugkIVspBJI/u3rfHUzYLs6H3w0Vh2V6ZhndUK4p1fCN5RKvZx9gqlFl77AqqMqvdvjob1wMRvxHnUb1BRGBy8nRNUgRwlQ5ddZgdHUF1CCjQaaXs1ccYG7V1x1CJIW8LxuWMILiK23V8Qe/9mJ87noKmt4er10Ef+GF9nOUed0rqSknb6etyEfDGFmx7icR+/CkHSCVPq5LoxtSJXkDJTo8nRdFGOP+Cr1FB3KUqkn/3T/KZeSJTmsR/7sH1yLFyjCklrM8U/L31COWTv8/z7HnfS/vf7rF9Tt/Xi3l1QEco7fMhzoiBZvmXeWksGdnGKaJPP7pmUAUfBn/n1dp4dkoJhVGDsI/4FHPmmP0JdHTgUVrtArr6b/d5M1IpH1EYos/Dt3q0XDp8FgVQHI4Vv3DigZNWyE4sM+iLfiLPa99NNGJIzur wlORInw+ 7Y0QqlqohNA8RddB6bti0SGhNCoHj3mNQQVRH9/3nhU6YTav/0Ik5k9b4bAbAaBXZbh/Wm8MjBot5f2JaRmC0E5t1sfRykXJtrmQF2Se7OZAOdMI485g5ZbqC9pSS7UHcLtWCSjpSTOJIgRWslSSLGimIzV89yaC+7/DAZD7te4OYoUIVpyV2PHi1yV1PhrBwxvsdC46JkX41N0CnIj06BHcPU2NY84uvr9E+YjhKjTGJx4onBgT1pd8faHWhs7c52a+7wZP0Xzt7z+URfcImF1HkDmK053NhgFwtxDZuSuwdDV9fQvCYpmZKi4QgObcQAol6pzA5GYvXEDDgKVYGz6wTSb/rpXfYktSotpnf5Bdpse2QWPRPctn2srMGoaNTKsaRs2m/vNog+MHaBVRdBKGZvmIQIOJVPPk1QOjVX2rEWgcuyRl3b3koE70kUpniBRms/vW7v3xBS1H06wJPUMXOv/nwq3lIZP5g 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: Short DIO reads, particularly in relation to cifs, are not being handled correctly by cifs and netfslib. This can be tested by doing a DIO read of a file where the size of read is larger than the size of the file. When it crosses the EOF, it gets a short read and this gets retried, and in the case of cifs, the retry read fails, with the failure being translated to ENODATA. Fix this by the following means: (1) Add a flag, NETFS_SREQ_HIT_EOF, for the filesystem to set when it detects that the read did hit the EOF. (2) Make the netfslib read assessment stop processing subrequests when it encounters one with that flag set. (3) Return rreq->transferred, the accumulated contiguous amount read to that point, to userspace for a DIO read. (4) Make cifs set the flag and clear the error if the read RPC returned ENODATA. (5) Make cifs set the flag and clear the error if a short read occurred without error and the read-to file position is now at the remote inode size. Fixes: 69c3c023af25 ("cifs: Implement netfslib hooks") Signed-off-by: David Howells Link: https://lore.kernel.org/r/20240822220650.318774-3-dhowells@redhat.com cc: Steve French cc: Paulo Alcantara cc: Jeff Layton cc: linux-cifs@vger.kernel.org cc: netfs@lists.linux.dev cc: linux-fsdevel@vger.kernel.org Signed-off-by: Christian Brauner --- fs/netfs/io.c | 17 +++++++++++------ fs/smb/client/smb2pdu.c | 13 +++++++++---- include/linux/netfs.h | 1 + 3 files changed, 21 insertions(+), 10 deletions(-) diff --git a/fs/netfs/io.c b/fs/netfs/io.c index 3303b515b536..943128507af5 100644 --- a/fs/netfs/io.c +++ b/fs/netfs/io.c @@ -368,7 +368,8 @@ static void netfs_rreq_assess_dio(struct netfs_io_request *rreq) if (subreq->error || subreq->transferred == 0) break; transferred += subreq->transferred; - if (subreq->transferred < subreq->len) + if (subreq->transferred < subreq->len || + test_bit(NETFS_SREQ_HIT_EOF, &subreq->flags)) break; } @@ -503,7 +504,8 @@ void netfs_subreq_terminated(struct netfs_io_subrequest *subreq, subreq->error = 0; subreq->transferred += transferred_or_error; - if (subreq->transferred < subreq->len) + if (subreq->transferred < subreq->len && + !test_bit(NETFS_SREQ_HIT_EOF, &subreq->flags)) goto incomplete; complete: @@ -782,10 +784,13 @@ int netfs_begin_read(struct netfs_io_request *rreq, bool sync) TASK_UNINTERRUPTIBLE); ret = rreq->error; - if (ret == 0 && rreq->submitted < rreq->len && - rreq->origin != NETFS_DIO_READ) { - trace_netfs_failure(rreq, NULL, ret, netfs_fail_short_read); - ret = -EIO; + if (ret == 0) { + if (rreq->origin == NETFS_DIO_READ) { + ret = rreq->transferred; + } else if (rreq->submitted < rreq->len) { + trace_netfs_failure(rreq, NULL, ret, netfs_fail_short_read); + ret = -EIO; + } } } else { /* If we decrement nr_outstanding to 0, the ref belongs to us. */ diff --git a/fs/smb/client/smb2pdu.c b/fs/smb/client/smb2pdu.c index d80107d1ba9e..9829784e8ec5 100644 --- a/fs/smb/client/smb2pdu.c +++ b/fs/smb/client/smb2pdu.c @@ -4507,6 +4507,7 @@ static void smb2_readv_callback(struct mid_q_entry *mid) { struct cifs_io_subrequest *rdata = mid->callback_data; + struct netfs_inode *ictx = netfs_inode(rdata->rreq->inode); struct cifs_tcon *tcon = tlink_tcon(rdata->req->cfile->tlink); struct TCP_Server_Info *server = rdata->server; struct smb2_hdr *shdr = @@ -4600,11 +4601,15 @@ smb2_readv_callback(struct mid_q_entry *mid) rdata->got_bytes); if (rdata->result == -ENODATA) { - /* We may have got an EOF error because fallocate - * failed to enlarge the file. - */ - if (rdata->subreq.start < rdata->subreq.rreq->i_size) + __set_bit(NETFS_SREQ_HIT_EOF, &rdata->subreq.flags); + rdata->result = 0; + } else { + if (rdata->got_bytes < rdata->actual_len && + rdata->subreq.start + rdata->subreq.transferred + rdata->got_bytes == + ictx->remote_i_size) { + __set_bit(NETFS_SREQ_HIT_EOF, &rdata->subreq.flags); rdata->result = 0; + } } trace_smb3_rw_credits(rreq_debug_id, subreq_debug_index, rdata->credits.value, server->credits, server->in_flight, diff --git a/include/linux/netfs.h b/include/linux/netfs.h index 983816608f15..c47443e7a97e 100644 --- a/include/linux/netfs.h +++ b/include/linux/netfs.h @@ -198,6 +198,7 @@ struct netfs_io_subrequest { #define NETFS_SREQ_NEED_RETRY 9 /* Set if the filesystem requests a retry */ #define NETFS_SREQ_RETRYING 10 /* Set if we're retrying */ #define NETFS_SREQ_FAILED 11 /* Set if the subreq failed unretryably */ +#define NETFS_SREQ_HIT_EOF 12 /* Set if we hit the EOF */ }; enum netfs_io_origin { From patchwork Fri Aug 23 20:08:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13775938 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 9A52AC531DC for ; Fri, 23 Aug 2024 20:09:27 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2F5826B03A1; Fri, 23 Aug 2024 16:09:27 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 2A543800C8; Fri, 23 Aug 2024 16:09:27 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 146B16B03A3; Fri, 23 Aug 2024 16:09:27 -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 E8A026B03A1 for ; Fri, 23 Aug 2024 16:09:26 -0400 (EDT) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 8E22A140122 for ; Fri, 23 Aug 2024 20:09:26 +0000 (UTC) X-FDA: 82484599932.29.DA72173 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf24.hostedemail.com (Postfix) with ESMTP id C38EF18001B for ; Fri, 23 Aug 2024 20:09:24 +0000 (UTC) Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=UFp1Bgtx; spf=pass (imf24.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=1724443682; 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=JCLN+DgZIMYjLim8F8YFGy04wez+ty5Hq7K/oJiQsg4=; b=ou9700jGU4lkjWjCk7eHgC5wE8+mQxCtZeVU1/3ZrPkhGT6kmXOjTseQwbAvpG9wS+u6du zGPJ1mXGHRy6hF0Ynt+W9tXZtI2zLcEKijj0oR3i0qlPkGu15HwHP8YFypujYVUhkGkWAQ rHDDhMdhPwQ4dgrQEf8jgyT3GVobpF8= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1724443682; a=rsa-sha256; cv=none; b=8QsmVzY7NSQPAYPtUL2hBrrxIune77idfmQvnwdgeBxvq2mHjIeg4pllMLl1Jny68WE0AK mMkUVnG7Vqd6Tyk6b45nwb02iHPumi0yGSA72rB3YQi6UGO5AzxbUG9ZngGLuRKClYZ4mM T1oLKBo/ebKillNehiJ8BkLH6DwhddQ= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=UFp1Bgtx; spf=pass (imf24.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 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1724443764; 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=JCLN+DgZIMYjLim8F8YFGy04wez+ty5Hq7K/oJiQsg4=; b=UFp1BgtxFrBGOcjc3/d1vwNsCgge2oVdt5+ZcbBvCJZcWX2rV0daqRKTdgohUjBLzmv0tk F53sBhsozuEOi+BEpetsAI22MNpyOcjaCgiOlNhK4jby0+clIOCKigtdwS09mYgo+CrYF4 X62FinngfZ0WzBOyC+RzlcjSMvAO9XY= 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-634-N2VgEkt9MmW_PQ0CeQQcEw-1; Fri, 23 Aug 2024 16:09:18 -0400 X-MC-Unique: N2VgEkt9MmW_PQ0CeQQcEw-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 740711955D4D; Fri, 23 Aug 2024 20:09:16 +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 42F201956053; Fri, 23 Aug 2024 20:09:12 +0000 (UTC) From: David Howells To: Christian Brauner , Steve French Cc: David Howells , Pankaj Raghav , Paulo Alcantara , 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, Shyam Prasad N Subject: [PATCH 8/9] cifs: Fix FALLOC_FL_PUNCH_HOLE support Date: Fri, 23 Aug 2024 21:08:16 +0100 Message-ID: <20240823200819.532106-9-dhowells@redhat.com> In-Reply-To: <20240823200819.532106-1-dhowells@redhat.com> References: <20240823200819.532106-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 X-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: C38EF18001B X-Stat-Signature: 81rwnqhfxu3t3ejd1idqe9o5ko36rpz9 X-HE-Tag: 1724443764-415899 X-HE-Meta: U2FsdGVkX1/qGjRzXM/rCTeA/j+Lgecd4lPIgPEjlmuHmSeHiYydelU2Tj9+Y+RK+ce9mnyQymRjDxG2pQJwP+8rPIv2ZbbKh5NdN0Bfmec+9tvyA+eSODDWyqOd1cNNzI4GYBYxz4ZajVAJYS2eA2WYUAsSWGDVPR+55v5b4pdcAeslrxgzVDK6KdPJrjkenGgczubMbA9qDSxAt85Z2rDfutChKRh8RmcFuDrRYxIywWet5nYqFZt7StUqDUuBtBZAKYUhoTVw5IDqdFa3jI9gdmWNp3U/ToUmDX5gL1QE+RR+6ilLnKt6cT2fym3l7cOybTaMcdGOZDFFRLZRcTOhsI2R21GCc2gt5Pb6WRNIAlbhc7+yhhsJgnGgI3IObGbfhKb59EG/GypO/scVLPAFG92dlg2Gp358hJ8EUK29hlGMOvrKrrDRWxBRA7mpqMR6cCvxT8UtTazQqLY+6uUXl6vyiRwcK7ObOAMKBl+p0lOX5xyATXqPwENRgkd5jsCxgupIdHOu1YY5irlQKZNdiWvkRbIFOCqqT7LG3mqyIBipeGH4MpuFdQGQNnP3+BvTdzTU8IiRbSz10Xsd2bh8V7APQt1ISruAnTHTSqL8U7QQRqVmoG6AhjQmEg22gOgJW+MyvV5035EFoZ3sWR87CtBbxvSsGdhvV345kg2ad5+P0EUZBKgu0zs/wmAgwYQafaUo5N+Rj+sEUuhxPnTlWKgYLPMYR/QVCqV2gvpvPZo7ESWsLwaZIjZALz/vrCJZRkoUr+W3PErbrhsvG67VNZEUbKIF/mTAXM/ZoFIdWbjIZ8yNf8yM94o9NNHyvUErvS4ND4aP907pReBUUPWvWOq18hLSBIvltaghfP1I9ut4s9pXnAnqvfGw1IGL8wCwoeLA7LNJ+KUO1CqDUcEhRoD4dJ9EXT5jukm80+cUyeU3WhuuJlh3GvFxTLO3vd0H4XG3D6isLNR6Yo+ gMwIOuSS Dt5f2RHdwshMYw0BQxSOxTfy/+xk1X8dYoyowDuNqGJT7pfOQtlaFyfYmLpoZ5ma9Gwax0bMM/THzjZ507xLM9xsY5gjelw8ZDkSOJzsnX4D1XGRwg29WMWCTHvQBQnMbbJ0RfqjvW1OEsekSl6h3yG5SbvZGvM6bJZNzld3c+nM+ele+N3jZV9FwHkQW3Ti1MyBnjVNEbKNY0+bJ2zIK7q62bLsjvaqMHJpdsMfrl8I6Qywsvve4Xp0Hd9lx+aFXaNGnYZMQJMoM9lmKBAY3TfGQdEyksyDHjFEvwmQaGJ1YZn74jpJvts9uio3jgwfPJrQHw45dw871EjAYmmnG55L2X2/lqNhevJPOHR8VeXAUsVyT40OV33kbi4+MLUp1jLCubaUS+80/Ec8N0f35P5k6nyEPqpUcs3SYMFH228YaOY86v27p/ybA2xSECL1SkelEROd0B7nJcxKaj+OC1oFrOFPy5oE7AJNtNlBAGtZGUsmkZrwYwWdcRC2zs1afVQGGYThHHijrqQtUXVgj4IxY6GjhIR8GhUmlYk7smzBp6mg= 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: The cifs filesystem doesn't quite emulate FALLOC_FL_PUNCH_HOLE correctly (note that due to lack of protocol support, it can't actually implement it directly). Whilst it will (partially) invalidate dirty folios in the pagecache, it doesn't write them back first, and so the EOF marker on the server may be lower than inode->i_size. This presents a problem, however, as if the punched hole invalidates the tail of the locally cached dirty data, writeback won't know it needs to move the EOF over to account for the hole punch (which isn't supposed to move the EOF). We could just write zeroes over the punched out region of the pagecache and write that back - but this is supposed to be a deallocatory operation. Fix this by manually moving the EOF over on the server after the operation if the hole punched would corrupt it. Note that the FSCTL_SET_ZERO_DATA RPC and the setting of the EOF should probably be compounded to stop a third party interfering (or, at least, massively reduce the chance). This was reproducible occasionally by using fsx with the following script: truncate 0x0 0x375e2 0x0 punch_hole 0x2f6d3 0x6ab5 0x375e2 truncate 0x0 0x3a71f 0x375e2 mapread 0xee05 0xcf12 0x3a71f write 0x2078e 0x5604 0x3a71f write 0x3ebdf 0x1421 0x3a71f * punch_hole 0x379d0 0x8630 0x40000 * mapread 0x2aaa2 0x85b 0x40000 fallocate 0x1b401 0x9ada 0x40000 read 0x15f2 0x7d32 0x40000 read 0x32f37 0x7a3b 0x40000 * The second "write" should extend the EOF to 0x40000, and the "punch_hole" should operate inside of that - but that depends on whether the VM gets in and writes back the data first. If it doesn't, the file ends up 0x3a71f in size, not 0x40000. Fixes: 31742c5a3317 ("enable fallocate punch hole ("fallocate -p") for SMB3") Signed-off-by: David Howells cc: Steve French cc: Paulo Alcantara cc: Shyam Prasad N cc: Jeff Layton cc: linux-cifs@vger.kernel.org cc: netfs@lists.linux.dev --- fs/smb/client/smb2ops.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/fs/smb/client/smb2ops.c b/fs/smb/client/smb2ops.c index 14c3d11869ba..8fb68c47c218 100644 --- a/fs/smb/client/smb2ops.c +++ b/fs/smb/client/smb2ops.c @@ -3305,6 +3305,7 @@ static long smb3_punch_hole(struct file *file, struct cifs_tcon *tcon, struct inode *inode = file_inode(file); struct cifsFileInfo *cfile = file->private_data; struct file_zero_data_information fsctl_buf; + unsigned long long end = offset + len, i_size, remote_i_size; long rc; unsigned int xid; __u8 set_sparse = 1; @@ -3336,6 +3337,27 @@ static long smb3_punch_hole(struct file *file, struct cifs_tcon *tcon, (char *)&fsctl_buf, sizeof(struct file_zero_data_information), CIFSMaxBufSize, NULL, NULL); + + if (rc) + goto unlock; + + /* If there's dirty data in the buffer that would extend the EOF if it + * were written, then we need to move the EOF marker over to the lower + * of the high end of the hole and the proposed EOF. The problem is + * that we locally hole-punch the tail of the dirty data, the proposed + * EOF update will end up in the wrong place. + */ + i_size = i_size_read(inode); + remote_i_size = netfs_inode(inode)->remote_i_size; + if (end > remote_i_size && i_size > remote_i_size) { + unsigned long long extend_to = umin(end, i_size); + rc = SMB2_set_eof(xid, tcon, cfile->fid.persistent_fid, + cfile->fid.volatile_fid, cfile->pid, extend_to); + if (rc >= 0) + netfs_inode(inode)->remote_i_size = extend_to; + } + +unlock: filemap_invalidate_unlock(inode->i_mapping); out: inode_unlock(inode); From patchwork Fri Aug 23 20:08:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13775939 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 195B7C531DC for ; Fri, 23 Aug 2024 20:09:36 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A6E9C6B03A6; Fri, 23 Aug 2024 16:09:35 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A1E546B03A7; Fri, 23 Aug 2024 16:09:35 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8E6F56B03A8; Fri, 23 Aug 2024 16:09:35 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 6F09A6B03A6 for ; Fri, 23 Aug 2024 16:09:35 -0400 (EDT) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 20323400FF for ; Fri, 23 Aug 2024 20:09:35 +0000 (UTC) X-FDA: 82484600310.16.DB8E9B3 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf02.hostedemail.com (Postfix) with ESMTP id 72F628001F for ; Fri, 23 Aug 2024 20:09:33 +0000 (UTC) Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=e6AEJq46; spf=pass (imf02.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=1724443690; 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=FAmCIU0bJDpl8o1iuVK4ffMXJRGL1l5OGSxq2KqoTWQ=; b=S0rQhIAlH166d0dZuGqySL032VkjERl5Zm0LRQCgRYwA/yMea7m1r8Ur34f+VBVy6N2vGd 2o0RK++RBReLmfOo51OMDANPRlaXeNk3lIpoQIQvOpH1h/PgUjyEgb3TY0FxS9OcosXsFd aMIVBDB7UXuLubxPXD5HJqCKpx3DRjY= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1724443690; a=rsa-sha256; cv=none; b=jWxXd1KrDHoST95ewhlrMblvVh9rPqB48HfvXzEGS9at6pny49nVQuou7Y3CqiQrHaHWJG dmRmXNaBnlOm8G49BlI4WcWkUIewRMH4FkBXq+qpjTvbieEByubW1RdTmOIl1N78e5VyVR 365Ro0iWOSXNx9gysBK2XIUsJgHt6LY= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=e6AEJq46; spf=pass (imf02.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 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1724443772; 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=FAmCIU0bJDpl8o1iuVK4ffMXJRGL1l5OGSxq2KqoTWQ=; b=e6AEJq46BsP4iTfwepakJaujeLZPPi1MbEtv+VxXkZ1JMoy2hnpCje6jZjasvnYyw0LI1K hLEsYj3Cw9TRmWSHp82/8bNk5NpApQ1CfbnDdZeCFKEk39nB3Pe6czriEo0E8FEAOzWo4m FITHfTaQiGSyT72yNPQW8FMcSEJ0Flc= 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-154-Dvwmp2x-PPyrCItiYsUPfQ-1; Fri, 23 Aug 2024 16:09:29 -0400 X-MC-Unique: Dvwmp2x-PPyrCItiYsUPfQ-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 5AD3B19560B7; Fri, 23 Aug 2024 20:09:27 +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 EDBE11956053; Fri, 23 Aug 2024 20:09:17 +0000 (UTC) From: David Howells To: Christian Brauner , Steve French Cc: David Howells , Pankaj Raghav , Paulo Alcantara , 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 Subject: [PATCH 9/9] netfs, cifs: Improve some debugging bits Date: Fri, 23 Aug 2024 21:08:17 +0100 Message-ID: <20240823200819.532106-10-dhowells@redhat.com> In-Reply-To: <20240823200819.532106-1-dhowells@redhat.com> References: <20240823200819.532106-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 X-Stat-Signature: gbp85ph9nak1jbk3dw1kqydq9rqcf4qs X-Rspamd-Queue-Id: 72F628001F X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1724443773-397595 X-HE-Meta: U2FsdGVkX18NEn8CB0e3jBl0HLKr655U2l8eGT/+NMYwjrZBoReII65fa8Q6FwMaNytxoCxt8joaTekKaV9PjA0J+bHcBte3WPfUrZqyg6ntwHAp6azrjHFQXNjV9fW13gcekENxMjz9NG/OyfdL3NGxfWb2nqx7NNF3njfFT3Xd9HHeJX/jyfOv5nMSJ5TIHTARl+dTaxDsyPg55K4aOvrE+Iqu6v6kOyvZC6hMMQkuSQVtkB5r/zlZY828cPYUJxikskAMY05pgmAIfVzE+/CNuRE7uG1CDVUnUB2fIGkmy68i8ILklK9/+sPdLWJad0qIMoZ0TGo5m6OcHCYkhhIQXuWfcjKFzHANO2fURvL6lkBCUcasv30WbxikcISs+YMsTQDl2LFNP2Dw6UMEpZi0l3+kWMaNi1eKsGpT8l42V9tETPINvEcTlMoSOLL6VpAJyGmZkrP1etpcMicZ56tl9YM/jOX1WqdLl9YI9zsEd0ozxi3OlExgoXRafV5mLyoBrZaRc2NdEiipE8mkrN5NEnfJbdqC30TSfhzNc8jnOcfJD9D0FjUwncFZIoetvJ20Sxe0a5a15k6u/JmLOhR0J8NHbqbnJsykQsb5mmbCl2UnCxtJ3uFzGwdnV4vngcauiTKgJBZhxSHpbxlUZSXoG4J1Upv02RXzDQGHEhh9CdRoeqVTFLGH6IGsvS9TOCbYtRB/E5UcfXqlPj3t/B1Brp2zsz/5lp85evVOL/WIRg+UbF9PjG4ygvk7+kqt4nKzJ6/ZuZq0TUN7QhWaMRp5I13SF0pp/S8r38sLd7oA6KIamMPD+xs2Iv8fKtqzx52npGioyrC+UGUpyNRD6sHOUHqvysBnXzo+2e4LB7kl2X6PuW9FqCrY27JeQAY9gxU4XEPcfRlRPydK1KebovzrmxXCRPdU+tdrxtNC1IV+2OCt/q0MkzUgIVeNTm3wP5kowwB3cjlc2nXzcnB fCUdbroP 125yz1x8+LDK9lDHiSYmx0tBuxpPpo7pkpPd3quHWzQsN+I7CQatWfcjXDiZ7waMz/l1NQ0W5+y/99rOpFyw6H4UCE2BRspPrl5b/rsYMVqmVQxHv1+G0q+HCe5XpocFl9X52Ge7FPe7V37osaQtJZLgbK6ylSLIgp42uNcAhJtt2d2Mz7kmd/Z0CEK547C1MGpBWS2CfmT0ERVu+ckYL+NTT0VtxdrdRRhfzXLabWTsvD53h7CLM63Rx6xKJZDagJ8adlaqs8d35pVaqprisgraTc0+zMt5I1z0/RTl7t+5ycD5yUKWnlE3gem759epzkXpwrqvl4h6YZ1Dk9c04LE3NKeKMy6Ormkr1ExpFCK3qSrc1Dop8pox8j3iS97B7KKUIUcwThxC5sxyj+GU4vSSBU9/cZJtBKdHfDv83DXPVy26fXLyQ9RPlbKPUlqF9+io4PuywGz6R6Fa2gcUbl4bj+tqOdQ0M4Sn1 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: Improve some debugging bits: (1) The netfslib _debug() macro doesn't need a newline in its format string. (2) Display the request debug ID and subrequest index in messages emitted in smb2_adjust_credits() to make it easier to reference in traces. Signed-off-by: David Howells cc: Steve French cc: Paulo Alcantara cc: Jeff Layton cc: linux-cifs@vger.kernel.org cc: netfs@lists.linux.dev cc: linux-fsdevel@vger.kernel.org --- fs/netfs/io.c | 2 +- fs/smb/client/smb2ops.c | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/fs/netfs/io.c b/fs/netfs/io.c index 943128507af5..d6ada4eba744 100644 --- a/fs/netfs/io.c +++ b/fs/netfs/io.c @@ -270,7 +270,7 @@ static void netfs_reset_subreq_iter(struct netfs_io_request *rreq, if (count == remaining) return; - _debug("R=%08x[%u] ITER RESUB-MISMATCH %zx != %zx-%zx-%llx %x\n", + _debug("R=%08x[%u] ITER RESUB-MISMATCH %zx != %zx-%zx-%llx %x", rreq->debug_id, subreq->debug_index, iov_iter_count(&subreq->io_iter), subreq->transferred, subreq->len, rreq->i_size, diff --git a/fs/smb/client/smb2ops.c b/fs/smb/client/smb2ops.c index 8fb68c47c218..2741f7d63fe7 100644 --- a/fs/smb/client/smb2ops.c +++ b/fs/smb/client/smb2ops.c @@ -316,7 +316,8 @@ smb2_adjust_credits(struct TCP_Server_Info *server, cifs_trace_rw_credits_no_adjust_up); trace_smb3_too_many_credits(server->CurrentMid, server->conn_id, server->hostname, 0, credits->value - new_val, 0); - cifs_server_dbg(VFS, "request has less credits (%d) than required (%d)", + cifs_server_dbg(VFS, "R=%x[%x] request has less credits (%d) than required (%d)", + subreq->rreq->debug_id, subreq->subreq.debug_index, credits->value, new_val); return -EOPNOTSUPP; @@ -338,8 +339,9 @@ smb2_adjust_credits(struct TCP_Server_Info *server, trace_smb3_reconnect_detected(server->CurrentMid, server->conn_id, server->hostname, scredits, credits->value - new_val, in_flight); - cifs_server_dbg(VFS, "trying to return %d credits to old session\n", - credits->value - new_val); + cifs_server_dbg(VFS, "R=%x[%x] trying to return %d credits to old session\n", + subreq->rreq->debug_id, subreq->subreq.debug_index, + credits->value - new_val); return -EAGAIN; } From patchwork Sat Aug 24 11:56:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13776409 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 D59CFC52D6F for ; Sat, 24 Aug 2024 11:57:13 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B2881800E4; Sat, 24 Aug 2024 07:57:12 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id AB160800D4; Sat, 24 Aug 2024 07:57:12 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9523D800E4; Sat, 24 Aug 2024 07:57:12 -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 6D5B3800D4 for ; Sat, 24 Aug 2024 07:57:12 -0400 (EDT) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id C21A8A7756 for ; Sat, 24 Aug 2024 11:57:11 +0000 (UTC) X-FDA: 82486988262.15.B15D06A Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf27.hostedemail.com (Postfix) with ESMTP id F270D40008 for ; Sat, 24 Aug 2024 11:57:08 +0000 (UTC) Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=ik6E3l3i; spf=pass (imf27.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=1724500611; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=7MlSZRgX4NtPTJfbL1OG/C/fCyXDm1yZsFhC7WYkkOo=; b=ZBNTVDPLOXsOc5eMGoXklG36T/HsBOGcrHUUhCpib1EL/+6i/TnuktcDJ2qwoQ+zYd/vvQ whhA1rklWvr68puRfbu84vha+Q9f3n8/MHO4It+Rwny0cGHBMXgw71JJHOnrr/jjtTzC9o +e25ji/qkAr3TkIOIL198j3sDLOT+0Y= ARC-Authentication-Results: i=1; imf27.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=ik6E3l3i; spf=pass (imf27.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=1724500611; a=rsa-sha256; cv=none; b=xdgAFGVOBzAS3d1C2jHCYBeXTYmvKxlmiDGHLajPZgoCg8S//haBoUdePLgH2z1ACym0C2 YKxXqO3BejctnNLrEMVCUaWG2qG5gob9UaxJ6yisCOQThKBCkYKOKkDgjDKruzd0dYRO3o S8FDxGKq/lc9loI6vHmQrfWX19wpNzc= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1724500628; h=from:from:reply-to:subject:subject:date:date:message-id:message-id:to: cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=7MlSZRgX4NtPTJfbL1OG/C/fCyXDm1yZsFhC7WYkkOo=; b=ik6E3l3ihYfC39vb/oZ1HuAsevce3MQPmPa++1Es3+3CQi9VCPvJDOv6Gg3eBLjD/Hax8P Zpt/SpUnIOWnHqnPNGaXI7jziEY50WiRs8cUpHjFrfnZA2mF8jXoW1sqf+CvbhEZNaSSOU ebhcDsjom0RQFb/n/H+xukjm/ryC5D0= 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-554-dsco4DIKOqS_7UEUarFQjQ-1; Sat, 24 Aug 2024 07:57:03 -0400 X-MC-Unique: dsco4DIKOqS_7UEUarFQjQ-1 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (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 A55D61955F43; Sat, 24 Aug 2024 11:56:59 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.42.28.30]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 4C96919560AA; Sat, 24 Aug 2024 11:56:54 +0000 (UTC) Organization: Red Hat UK Ltd. Registered Address: Red Hat UK Ltd, Amberley Place, 107-111 Peascod Street, Windsor, Berkshire, SI4 1TE, United Kingdom. Registered in England and Wales under Company Registration No. 3798903 From: David Howells In-Reply-To: <20240823200819.532106-1-dhowells@redhat.com> References: <20240823200819.532106-1-dhowells@redhat.com> Cc: dhowells@redhat.com, Christian Brauner , Steve French , Pankaj Raghav , Paulo Alcantara , 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 Subject: [PATCH 10/9] netfs: Fix interaction of streaming writes with zero-point tracker MIME-Version: 1.0 Content-ID: <563285.1724500613.1@warthog.procyon.org.uk> Date: Sat, 24 Aug 2024 12:56:53 +0100 Message-ID: <563286.1724500613@warthog.procyon.org.uk> X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 X-Rspam-User: X-Stat-Signature: qh73ggdrwt75e6pni9ewsbsahyh1z3cn X-Rspamd-Queue-Id: F270D40008 X-Rspamd-Server: rspam11 X-HE-Tag: 1724500628-440727 X-HE-Meta: U2FsdGVkX1/ezsy1SemHDvpH/MQIK7FjvfQ2fZtkCUW9OgLm79pTdKEd6jPs3BbsLehRCSHNG/UhIUjiBZuaQvm+WhqV3AljaMqV5uQAqT+mgENdYjXoVRDYSH4Bf1itKblYH0tQ2Qj8kGvQEFQDb3VYOU5V4iSwgdoGm6mEYLvtrBx0pq1dcfqZowF/w4cE2mADS/NNLg5Ze2wckQEj71rcdNArGgNocT8SJTFfq2gE8cY0Wu4ofPnvc72H6o3akidP+xHbcN0ml4dMQmjXV6TBA3uos8QE87K90XxYyUdHI1ZeEkHhDp+m00Guojow2eOZz3Re+c76tQCr0DY3gYHNVdVCVFyVLuCd81Foy5ucyXRf+5l6eZSgoQAdaqGuauNZpFTksg76DM9bu+8Mr/V6glR0Wxtp0SMvVGS9TKX4RzLo9+3sQVokFUjKfgcxfEbIo6oP4NaQgfOoKIilUC9TfymYktEkIocNTwqAK2sHv94Nzwzwuvl2iQnblCxPfXPtTfiZP+JKKBr6pWV5f/F7fE+IM1hLQoTEL/QibVIGUkUItin1w3lZ0k3xaM+zKdqBqIMHTr9w41hNqQ7L0IZRg8YEdAMqGmWgpYGfzy2MFvZbE4iw+nr/1G5deyX9os1hFmjADnKjIOyMBgcpt6L0DjwxDwOb+VkAtY/x9wBl1CBgOIWc3wprcxH5+r0WTOyz0f3vKcRR8CtGlecjRctQmXjxw2au/wuysr8oWJzBSohW/mnfbBhn/ZgO0H5B9HsVVjgY8pBtmroPCQifu2A8oz4ULV4zt6ahcaxPJlEDU8Kj0CEQaJUXLF0LZiUBMO33VJWpeXPF37TrLbURMEqdLrUhcaYa7y0LFIFAZ6mnf4T41pXa8RvWdrGU9KkaITiCYWV4SSR4kN+/pS5oI6g9TyoajSRqRsYb5kTHBdbDOpPmSS3cV8WxWt+wGxFs1Q9qHzFp//kZn/zQtTH Vcv2rACK wF4ygM1SB/HkVb6UgzgoUglrf96DQHsJONZn9QhZW3ckV6tkBaea0Lv73Q0rGPmZADjzi10qRSmOQM/fmQ2JqpfLwu2w+9x8HH/zSoKah5isXNlw5AnYg7vm5mN9jSsZtBCiUC4M2pUCpreKpmkpovWYPW+nZBzq81ckIUa2/En5WBQQerZJEOSGyMmRBjVqISpsnLn3njYT2lUMw0C8YbMXdsk5NOYzGXTEEzSXyTfNFYDfxmuP4aHJGGkqert/Z/nkiwmgjCLCgg5IovGwhYF0U+4EqS0n71DgP72X75IVpxhmIJQRzAjW/D+Rej9FDBjlZCmrekJtNamwTLe5AjWrZOQyqeEz2NnPR6GB4nevlJUqc+No3/gADrRuo+k9B9VEoOQEo7nbedyU5lI9tCLRGrJNbCvUSK7rIrtZh4IHjCpcLTPoHTD4pchFdRqz8rl8Ngik9XExzFtVZPVBFmCH66zNJI3LI77j+cjXFAQZByWesCM9DhKiGBH4wZGOiUPAkDZN4nx6079UEtwPhTz4oNF2yNO7PEm5R X-Bogosity: Ham, tests=bogofilter, spamicity=0.000001, 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 a folio that is marked for streaming write (dirty, but not uptodate, with partial content specified in the private data) is written back, the folio is effectively switched to the blank state upon completion of the write. This means that if we want to read it in future, we need to reread the whole folio. However, if the folio is above the zero_point position, when it is read back, it will just be cleared and the read skipped, leading to apparent local corruption. Fix this by increasing the zero_point to the end of the dirty data in the folio when clearing the folio state after writeback. This is analogous to the folio having ->release_folio() called upon it. This was causing the config.log generated by configuring a cpython tree on a cifs share to get corrupted because the scripts involved were appending text to the file in small pieces. Fixes: 288ace2f57c9 ("netfs: New writeback implementation") Signed-off-by: David Howells cc: Steve French cc: Paulo Alcantara cc: Jeff Layton cc: linux-cifs@vger.kernel.org cc: netfs@lists.linux.dev cc: linux-fsdevel@vger.kernel.org --- fs/netfs/write_collect.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/fs/netfs/write_collect.c b/fs/netfs/write_collect.c index 426cf87aaf2e..ae7a2043f670 100644 --- a/fs/netfs/write_collect.c +++ b/fs/netfs/write_collect.c @@ -33,6 +33,7 @@ int netfs_folio_written_back(struct folio *folio) { enum netfs_folio_trace why = netfs_folio_trace_clear; + struct netfs_inode *ictx = netfs_inode(folio->mapping->host); struct netfs_folio *finfo; struct netfs_group *group = NULL; int gcount = 0; @@ -41,6 +42,12 @@ int netfs_folio_written_back(struct folio *folio) /* Streaming writes cannot be redirtied whilst under writeback, * so discard the streaming record. */ + unsigned long long fend; + + fend = folio_pos(folio) + finfo->dirty_offset + finfo->dirty_len; + if (fend > ictx->zero_point) + ictx->zero_point = fend; + folio_detach_private(folio); group = finfo->netfs_group; gcount++;