Received: by 2002:a05:7412:e794:b0:fa:551:50a7 with SMTP id o20csp259512rdd; Tue, 9 Jan 2024 03:24:11 -0800 (PST) X-Google-Smtp-Source: AGHT+IGBV+r9uRBcz6VP03D1Vgb0LYt0DWeBeAVIedLuTDPjvFIO3qVe0dpCEbvU2CnMerwigAoc X-Received: by 2002:a17:90a:fd11:b0:28c:1eff:ac4a with SMTP id cv17-20020a17090afd1100b0028c1effac4amr2852172pjb.90.1704799451172; Tue, 09 Jan 2024 03:24:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704799451; cv=none; d=google.com; s=arc-20160816; b=hwH1037S/tM1RNvsT/jDi9FLRv4ZHMimyedr/NCbuWDjDhHi1gsFvrCO46k37CfLdZ 1CXQL5dPxDBRve0mF8LVuY4M6MVHRUqfeXiyKNxLoUV3wxa0/vtujXTU5u62o4v8v/v1 932mq+r4P3XP7Mg+B/nM4z/+NC4r9JGA2KgMa6fvpQfgkpVdqHRtZ4gNEiO3DP/F5OYD hcWLFdt0jF+V0Ch25x86egtC6wzicP4D1giwspQWN2zSb7b0qaEet1WkHiYDs68CaI/a dENvr9L0d3xX1kkjgaLI0o/fjypGU+iquPelKFUVLhadoZ6GkHj0zISPd0JyZkb+i6Rh 8G/w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=v9Zmt8qPNtA4BbCqgJuw0LKGT28DtGNcpxFrcZYWG/0=; fh=wHeWnRAPvg2xJ56RgmOMhm93PiD0Bj1H5ZiEjecP7fw=; b=QMmpEhZJo7eZt4Z1XEkJeZd3zIXNjV2gNkghndViitxzdUIgSSnfqGmwbiSQVv+JgH ll50s8Qi9bQPuX32ranrsRdT/bQ0v/NvcyHUoIAIVRLGI0DeleAsPO1rBNojZ2Z9VbSs 8GiZlOA5DbDkTlmE/PZOAW62g2Q6u4Rslx+loYgukjXrKTXfZ0tLlxsiZDPWHZGcIeqX F4J+RImgZWy+BLMhvL5bX6gPMbyiZuaaCujNwc3NGu68UrGqExLhE8KOpuRYxbpxNSW5 jpJXgoY08OMOYZdUVl9eqJquNxV7n+v0XQUYx0Wa7UDWiBs3Gz+otkhr8Ak/oM0gvQb/ p7uQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=elitUFS1; spf=pass (google.com: domain of linux-kernel+bounces-20760-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-20760-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id u5-20020a17090a450500b0028bd6fd8b2dsi7149926pjg.83.2024.01.09.03.24.10 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Jan 2024 03:24:11 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-20760-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=elitUFS1; spf=pass (google.com: domain of linux-kernel+bounces-20760-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-20760-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 685D8B23ADF for ; Tue, 9 Jan 2024 11:23:17 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1883639ADE; Tue, 9 Jan 2024 11:21:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="elitUFS1" Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E8D2039870 for ; Tue, 9 Jan 2024 11:20:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1704799258; 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=elitUFS17RNYLyh4NrsXXo12fnyDkbYf77V6a9cH4wTJCJzRHAK9Y8m9R4LZtLzv1llWY9 YMpeKjKk+8DLsHvjL2/XuICFUmubB4ut/GZpbO8G1MvRAhNW9ZB6x76u9R8prQ9Zz/gsqH 8bnSAqyDbAjfykeaZNjShBmm6dr+0AM= 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> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.6 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;