Received: by 2002:a05:7412:37c9:b0:e2:908c:2ebd with SMTP id jz9csp66917rdb; Mon, 18 Sep 2023 08:24:45 -0700 (PDT) X-Google-Smtp-Source: AGHT+IG6Q9kr/PKADq1rByLKtVXFYb1ZwVM+7EfUxP5t9n3oQVGt3Nhym/igIvFaPuMF2ScMLFxu X-Received: by 2002:a05:6a00:1409:b0:68e:380c:6b15 with SMTP id l9-20020a056a00140900b0068e380c6b15mr8810976pfu.26.1695050685462; Mon, 18 Sep 2023 08:24:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695050685; cv=none; d=google.com; s=arc-20160816; b=ip8kAfJrzh8QT5KBGWBrVpAotWTznnMUeAY5MJXxzskAoc9rjGXs+vkO5pmTUF/nYb BbBKn1vfoVE/cCnHQVI6IToGXI+XPnacwXyEnrD3UTSVD5yKT2YGCthG3oMKsAAeOL6U FsaBHFgNWmZ2SnfG4Xy0RtNLQFVx4xkBYPs9dwxIJJOVvieWE7MRZGrYgPWSFQUEfC4j jT2vrCgga3tnKXZJdp/DYDhnX2SOl4MUMT4+sfB9yFxUiFDREDUybnJ6nxHlPxNOGtkD eUr3MlbiP49tY2/4kT5OAQPmx/uwncGhKZMlk645jzBNJdD1dtpEAshXsLKOnRx48tKK mojw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:message-id:date:content-transfer-encoding :content-id:mime-version:subject:cc:to:from:organization :dkim-signature; bh=6KA4lTlnVdzbmyx5pVQ5ofjoQSRiAU3XEpYXJ1nkwrA=; fh=2m6QJAfb4yK6LI9SWbVCR3n5DunHggiBgheifRrxN6k=; b=nEEj14f0UJpMwGa971/2TCIsdNxTC5pf0QocWyAC96hZiUkOeHZ920FyyO7XjUepO0 QYdXCHPUvwE8WvcixB4CwTk0N+tvMjWWYL7DE+666bl8m6TjaQKVWOqCR+cy45GqJ8n5 PKpmmoBHAeCmjLgny28E688NOnYeeG9AUGSx9h3yjy/FFu3N/JWQxH0cszeok7C8d9NF 2MbRMkGX/lAZF9mE03Iid+ina2w0S0MrS/jz9zJb3N6nJ2AYYy0SAgdscpVLMKKUaRhO lB0qe74Xz2Gor+WkTRNejFYkpXY1N0OP4Fy6Z5hP+dklkMrHg0Zg6y0XtM9dk29x0f9a 3CJA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=ULhI9Mca; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id z11-20020a6553cb000000b0055c77028579si8117635pgr.747.2023.09.18.08.24.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Sep 2023 08:24:45 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=ULhI9Mca; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id B28A28028871; Mon, 18 Sep 2023 08:24:42 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240307AbjIRPYh (ORCPT + 99 others); Mon, 18 Sep 2023 11:24:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58922 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238243AbjIRPYf (ORCPT ); Mon, 18 Sep 2023 11:24:35 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9C8C026B6 for ; Mon, 18 Sep 2023 08:20:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1695050402; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=6KA4lTlnVdzbmyx5pVQ5ofjoQSRiAU3XEpYXJ1nkwrA=; b=ULhI9McajzvQI47X/5D2isYzY1ugCMRMWS6VDUaI6Z9+WJbswoGe0ZTIj0o/qlSEY4QPrv iQcjDUQjdObwjcLmtbP7/0g4ioOcSfbCg+np2EnQ2hh9Q3PBPF/Qi5REn5cwKQ1ncyaTHh dkn/UxAbOusShomum6jdRtWKay4qgOQ= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-227-PKA3tFlTMryOWIa3kWRgkg-1; Mon, 18 Sep 2023 09:17:13 -0400 X-MC-Unique: PKA3tFlTMryOWIa3kWRgkg-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 8FEE929AA386; Mon, 18 Sep 2023 13:17:12 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.42.28.216]) by smtp.corp.redhat.com (Postfix) with ESMTP id 96ADAC158BA; Mon, 18 Sep 2023 13:17:11 +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 To: torvalds@linux-foundation.org cc: dhowells@redhat.com, Dave Wysochanski , Jeff Layton , linux-cachefs@redhat.com, linux-nfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2] netfs: Only call folio_start_fscache() one time for each folio MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <3993456.1695043031.1@warthog.procyon.org.uk> Content-Transfer-Encoding: quoted-printable Date: Mon, 18 Sep 2023 14:17:11 +0100 Message-ID: <3993457.1695043031@warthog.procyon.org.uk> X-Scanned-By: MIMEDefang 3.1 on 10.11.54.8 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL, SPF_HELO_NONE,SPF_NONE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Mon, 18 Sep 2023 08:24:42 -0700 (PDT) Hi Linus, Could you apply this please? Thanks, David --- From: Dave Wysochanski If a network filesystem using netfs implements a clamp_length() function, it can set subrequest lengths smaller than a page size. When we loop through the folios in netfs_rreq_unlock_folios() to set any folios to be written back, we need to make sure we only call folio_start_fscache() once for each folio. Otherwise, this simple testcase: mount -o fsc,rsize=3D1024,wsize=3D1024 127.0.0.1:/export /mnt/nfs dd if=3D/dev/zero of=3D/mnt/nfs/file.bin bs=3D4096 count=3D1 1+0 records in 1+0 records out 4096 bytes (4.1 kB, 4.0 KiB) copied, 0.0126359 s, 324 kB/s echo 3 > /proc/sys/vm/drop_caches cat /mnt/nfs/file.bin > /dev/null will trigger an oops similar to the following: ... page dumped because: VM_BUG_ON_FOLIO(folio_test_private_2(folio)) ------------[ cut here ]------------ kernel BUG at include/linux/netfs.h:44! ... CPU: 5 PID: 134 Comm: kworker/u16:5 Kdump: loaded Not tainted 6.4.0-rc5 ... RIP: 0010:netfs_rreq_unlock_folios+0x68e/0x730 [netfs] ... Call Trace: netfs_rreq_assess+0x497/0x660 [netfs] netfs_subreq_terminated+0x32b/0x610 [netfs] nfs_netfs_read_completion+0x14e/0x1a0 [nfs] nfs_read_completion+0x2f9/0x330 [nfs] rpc_free_task+0x72/0xa0 [sunrpc] rpc_async_release+0x46/0x70 [sunrpc] process_one_work+0x3bd/0x710 worker_thread+0x89/0x610 kthread+0x181/0x1c0 ret_from_fork+0x29/0x50 Fixes: 3d3c95046742 ("netfs: Provide readahead and readpage netfs helpers" Link: https://bugzilla.redhat.com/show_bug.cgi?id=3D2210612 Signed-off-by: Dave Wysochanski Reviewed-by: Jeff Layton Signed-off-by: David Howells Link: https://lore.kernel.org/r/20230608214137.856006-1-dwysocha@redhat.co= m/ # v1 Link: https://lore.kernel.org/r/20230915185704.1082982-1-dwysocha@redhat.c= om/ # v2 --- fs/netfs/buffered_read.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/fs/netfs/buffered_read.c b/fs/netfs/buffered_read.c index 3404707ddbe7..2cd3ccf4c439 100644 --- a/fs/netfs/buffered_read.c +++ b/fs/netfs/buffered_read.c @@ -47,12 +47,14 @@ void netfs_rreq_unlock_folios(struct netfs_io_request = *rreq) xas_for_each(&xas, folio, last_page) { loff_t pg_end; bool pg_failed =3D false; + bool folio_started; = if (xas_retry(&xas, folio)) continue; = pg_end =3D folio_pos(folio) + folio_size(folio) - 1; = + folio_started =3D false; for (;;) { loff_t sreq_end; = @@ -60,8 +62,10 @@ void netfs_rreq_unlock_folios(struct netfs_io_request *= rreq) pg_failed =3D true; break; } - if (test_bit(NETFS_SREQ_COPY_TO_CACHE, &subreq->flags)) + if (!folio_started && test_bit(NETFS_SREQ_COPY_TO_CACHE, &subreq->flag= s)) { folio_start_fscache(folio); + folio_started =3D true; + } pg_failed |=3D subreq_failed; sreq_end =3D subreq->start + subreq->len - 1; if (pg_end < sreq_end)