From patchwork Tue Jan 9 11:20:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13514776 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 08A6AC46CD2 for ; Tue, 9 Jan 2024 11:21:03 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9E0FB6B0082; Tue, 9 Jan 2024 06:21:03 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 9698D6B0083; Tue, 9 Jan 2024 06:21:03 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 831046B0085; Tue, 9 Jan 2024 06:21:03 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 6E71B6B0082 for ; Tue, 9 Jan 2024 06:21:03 -0500 (EST) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 47BAD408A1 for ; Tue, 9 Jan 2024 11:21:03 +0000 (UTC) X-FDA: 81659530806.18.368C28D Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf19.hostedemail.com (Postfix) with ESMTP id 90A851A000C for ; Tue, 9 Jan 2024 11:21:00 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=aVUMHiOn; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf19.hostedemail.com: domain of dhowells@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1704799260; 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=v9Zmt8qPNtA4BbCqgJuw0LKGT28DtGNcpxFrcZYWG/0=; b=FIF0nEocgkMmlIAzoBXwbheEhRfj/lqggKVYhFXTxkMq/CXnq2v77fNIUe6wJbYM3sVesg dGXCogFTmoOJ976e26h/wOqWdlLVf3N7zBzkxFKFO9P12xANScICu+53HIxsFRC9bbkdMH /63SjhbkijGINI6Ikj1cjIYlSlPQVak= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=aVUMHiOn; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf19.hostedemail.com: domain of dhowells@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1704799260; a=rsa-sha256; cv=none; b=DdsvT4D2MXT8aQud1GTp/DjrsexwmYplRR/xFyXTjiYVzeoY/LCNc1AGCbwpiXSDdBFOH1 c8NY4l1bvjPTpQASh7oxfmuEkPotICpnOqT6HrKdwN2gDHREjLh6BNNVqDY5v4tovDEzR4 VeMupUy99whDruBkqOF6007Wt3v9DTg= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1704799260; 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=v9Zmt8qPNtA4BbCqgJuw0LKGT28DtGNcpxFrcZYWG/0=; b=aVUMHiOnlSkkNxAoRTJTrLF5vnYjH08buM8p0vjG348ozn+JK8h6ceD3RHiTG7kG3X/w86 V9PMUpqzfL8nRY/ZlbXJ2dw+EsnGEM+j4GZgCRKWdrQlp9upRZSzXehz1q3QUVYxjOJ7bH 6Mc+DGQmv/ZfT9iW8M3ku4pmDUVnM3U= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-452-aZtDJMnWPAi-V2MIXSUMUQ-1; Tue, 09 Jan 2024 06:20:54 -0500 X-MC-Unique: aZtDJMnWPAi-V2MIXSUMUQ-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 28F8329AA3AF; Tue, 9 Jan 2024 11:20:53 +0000 (UTC) Received: from warthog.procyon.org.com (unknown [10.42.28.67]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4CD382166B32; Tue, 9 Jan 2024 11:20:50 +0000 (UTC) From: David Howells To: Christian Brauner , Jeff Layton , Gao Xiang , Dominique Martinet Cc: David Howells , Steve French , Matthew Wilcox , Marc Dionne , Paulo Alcantara , Shyam Prasad N , Tom Talpey , Eric Van Hensbergen , Ilya Dryomov , linux-cachefs@redhat.com, linux-afs@lists.infradead.org, linux-cifs@vger.kernel.org, linux-nfs@vger.kernel.org, ceph-devel@vger.kernel.org, v9fs@lists.linux.dev, linux-erofs@lists.ozlabs.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 4/6] netfs: Fix the loop that unmarks folios after writing to the cache Date: Tue, 9 Jan 2024 11:20:21 +0000 Message-ID: <20240109112029.1572463-5-dhowells@redhat.com> In-Reply-To: <20240109112029.1572463-1-dhowells@redhat.com> References: <20240109112029.1572463-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3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CUVP7JuXzp1J+Pqd0qkU/UTn2AWq4z+jJ p2xKoLpO Mu5q1tqgY6yb4BZZvU2Fa52i2hEMjQvfvMmpnXBVBqFfiOakKdV8XXjx6w/8X8tBev5xGoDDH3XIDe2HhL01rYd++oEVUeCPgi4hCigUWqxzW2zepeEjdlj5CB1csAieoHeG3m7cdlSLXXtksiwj1N3xCB0x7TzX3s1p8yvW7pofqRjyksnKaO/qFZoEF9WLSXAx2yGmq4E16tzXWCA/vNFjflDKfwSzIZU/EpUi2nUV8o15k0RIwyAXSjeKS/XegvWrhKIXIsXa5hhGEJi0cIfUunq6wO9cewsl1Qp5jng7OZeSBbtTyuLgRjr1Mpu6CergAgcVgfWyRTjyLinKYG7GkEfr0AGdUQ5vNS0KqBGrUsSQal7EAvV+yiYQ+A7sM9Ea5j16YLIQ01OU64Lds1inlqArn4LUyAils 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: In the loop in netfs_rreq_unmark_after_write() that removes the PG_fscache from folios after they've been written to the cache, as soon as we remove the mark from a multipage folio, it can get split - and then we might see a fragment of folio again. Guard against this by advancing the 'unlocked' tracker to the index of the last page in the folio to avoid a double removal of the PG_fscache mark. Reported-by: Marc Dionne Signed-off-by: David Howells cc: Matthew Wilcox cc: linux-afs@lists.infradead.org cc: linux-cachefs@redhat.com cc: linux-fsdevel@vger.kernel.org cc: linux-mm@kvack.org --- fs/netfs/buffered_write.c | 1 + fs/netfs/io.c | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/fs/netfs/buffered_write.c b/fs/netfs/buffered_write.c index 6cd8f7422e9a..0b2b7a60dabc 100644 --- a/fs/netfs/buffered_write.c +++ b/fs/netfs/buffered_write.c @@ -698,6 +698,7 @@ static void netfs_pages_written_back(struct netfs_io_request *wreq) end_wb: if (folio_test_fscache(folio)) folio_end_fscache(folio); + xas_advance(&xas, folio_next_index(folio) - 1); folio_end_writeback(folio); } diff --git a/fs/netfs/io.c b/fs/netfs/io.c index 5b5af96cd4b9..4309edf33862 100644 --- a/fs/netfs/io.c +++ b/fs/netfs/io.c @@ -126,7 +126,7 @@ static void netfs_rreq_unmark_after_write(struct netfs_io_request *rreq, */ if (have_unlocked && folio_index(folio) <= unlocked) continue; - unlocked = folio_index(folio); + unlocked = folio_next_index(folio) - 1; trace_netfs_folio(folio, netfs_folio_trace_end_copy); folio_end_fscache(folio); have_unlocked = true;