Received: by 2002:ab2:60d1:0:b0:1f7:5705:b850 with SMTP id i17csp605600lqm; Wed, 1 May 2024 10:01:20 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCX0Zu94dzTkZ9s1+BcqamI4P6txYDTYLmIsl0zVgDtO2TLwtBDzvbDQ/fDi7yj9Do8X48U1NOTJKYSNdGb1Qt0XsvvSDNmahB8acqP6Cg== X-Google-Smtp-Source: AGHT+IHSTgtZ1QwysHKUd6X7xOCq9ErNbrrN8Ig0H0Xf69zCXLMLXY16szdVOyMJal3cMz4BuqCB X-Received: by 2002:a17:90a:7143:b0:2b1:dd0e:e20 with SMTP id g3-20020a17090a714300b002b1dd0e0e20mr3235930pjs.38.1714582879902; Wed, 01 May 2024 10:01:19 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1714582879; cv=pass; d=google.com; s=arc-20160816; b=t+a/rfGuqWAeP80E35+uzWJnOedN+Ci6Rycnh/dBWt1ncBAOs1eeyhd4J0jwn9bRUK kxcmienFcSQbcKNuKZ3TfaCf5Vf4oyBXsa9jkro3EUKzMngFn5u4HDRC5MHfZo5XUPLq RYUyf8M1/YP8YWYwC8k8FuRkCCeCazzwPeT0FSwNZuKxt2jB/I8oLqOIA/4VIB0gVjNY 46Wo8lO4FKuVYvrltf3sMCAsxtQsUz25qOI28K4AadqeZjv+CdUK4rhzDTtS3sE1Kfy8 l7m/s/EfJuR1Q5DY7Gl1nRTRcuzyJbIg56z1Q3i5qL7do2PaDoe8i/BWZzdiD4kZrLjy IpKQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=message-id:date:content-transfer-encoding:content-id:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:subject:cc:to :references:in-reply-to:from:organization:dkim-signature; bh=pbBAwD6JC5VL1ukHU3KFqlt1QekHLcO5vtkGzyQGBMM=; fh=0CIerLb/cM50vy7gQm3XRz1x4J6a65cahl3DlMj5j9E=; b=w64hcZJqQ/srMNIvfQ2r1vxB3bkMjBHBIwKZZ0Cb+9Ws9czR0OcZvrAZO5rEr+kdCQ snYAd+LuOdwKo5yZ59jLfzPcV1tSuLTej9GoN+0AsGgc7WvwoG5ihx5yxp5cuL2CRMFT 8C1fxxf4L+KjR6hb6MH0NVVlMk4RNu/D8RBeXy2FyuYNrflZr0LPc0Ugzr6Y5zJ1TVyO 8wvvHMiX++phT1K1ky50Tly69k5dCpstEmbarK7Q9+CkL2wgl3kH7HdiG5G51KwPfYhM 5l6ARqJb30rKfQqBuGutDJlbBB3lDzfFQatwwUe2At5NtZssa7vj7a1fpjSz1yygtzk0 A/yA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=MSRxgjH8; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-nfs+bounces-3121-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-nfs+bounces-3121-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id sy16-20020a17090b2d1000b002b079e5cee3si1840486pjb.133.2024.05.01.10.01.19 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 May 2024 10:01:19 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-nfs+bounces-3121-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=MSRxgjH8; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-nfs+bounces-3121-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-nfs+bounces-3121-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 81AF7282748 for ; Wed, 1 May 2024 17:01:19 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3A8FF17591; Wed, 1 May 2024 17:01:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="MSRxgjH8" X-Original-To: linux-nfs@vger.kernel.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.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 A0D9AC125 for ; Wed, 1 May 2024 17:01:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714582873; cv=none; b=f5sdZMtKeHgbOeVH5+kVuTrHSIzTlqA53x4vWs5sbvLs9z0N+TP33Lo0iHGfii+m9fQTvQ8EvkdBV6oi7abNmbvA8QzaLwfSyOmAKv7qo8ph7ZumRmOijT1OLfXQ4hBhJbT8MRMMMjWj46NOhZBARORI/XJEuaugeh/RHBnsYNo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714582873; c=relaxed/simple; bh=5x+R/tulRuIaS8VcnMqYfEwZKfLlmJE83wErUp3TIJI=; h=From:In-Reply-To:References:To:Cc:Subject:MIME-Version: Content-Type:Date:Message-ID; b=RS4GVgKT+nPg4p8D4Valiw2t4ABPtVDdiA95g3gsP8jdJRWTyWWESXP6w2vRb6y+MF2MPUNjo7qb/ttyYjxaCIjErO1GesmxaB5IJqz4Ab06lGKiLyv8OwkJpj6novam7NG6QZwGbEseDQjma6OT466LdFIb0aHiIjJ2VzgAK/g= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=MSRxgjH8; arc=none smtp.client-ip=170.10.129.124 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=1714582869; 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: in-reply-to:in-reply-to:references:references; bh=pbBAwD6JC5VL1ukHU3KFqlt1QekHLcO5vtkGzyQGBMM=; b=MSRxgjH8KQNJt6sQg2HXSn/6qaVMrp4UTkCQsEZ66b7kd1lmeiKL+uH0Z71Q6hDiBaJzCH aGt7t68XSylcdsr8TvCfIBT9szDAZ4msy4RGS22FOvpRPSI4AcKJwBeUc+is388te6XMdC wP2aCuyyF7RuGXkFFggKymffsIGqceI= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-209-jValeIcOO1Sva0kNIIWiZg-1; Wed, 01 May 2024 13:01:07 -0400 X-MC-Unique: jValeIcOO1Sva0kNIIWiZg-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 014948948A6; Wed, 1 May 2024 17:01:04 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.42.28.22]) by smtp.corp.redhat.com (Postfix) with ESMTP id 512842166B31; Wed, 1 May 2024 17:01:00 +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: <20240430140056.261997-15-dhowells@redhat.com> References: <20240430140056.261997-15-dhowells@redhat.com> <20240430140056.261997-1-dhowells@redhat.com> To: Christian Brauner Cc: dhowells@redhat.com, Jeff Layton , Gao Xiang , Dominique Martinet , Matthew Wilcox , Steve French , Marc Dionne , Paulo Alcantara , Shyam Prasad N , Tom Talpey , Eric Van Hensbergen , Ilya Dryomov , netfs@lists.linux.dev, 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, Latchesar Ionkov , Christian Schoenebeck Subject: Re: [PATCH v2 14/22] netfs: New writeback implementation Precedence: bulk X-Mailing-List: linux-nfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <458059.1714582859.1@warthog.procyon.org.uk> Content-Transfer-Encoding: quoted-printable Date: Wed, 01 May 2024 18:00:59 +0100 Message-ID: <458060.1714582859@warthog.procyon.org.uk> X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.6 This needs the attached change. It needs to allow for netfs_perform_write= () changing i_size whilst we're doing writeback. The issue is that i_size is cached in the netfs_io_request struct (as that's what we're going to tell = the server the new i_size should be), but we're not updating this properly if i_size moves between us creating the request and us deciding to write out = the folio in which i_size was when we created the request. This can lead to the folio_zero_segment() that can be seen in the patch be= low clearing the wrong amount of the final page - assuming it's still the fina= l page. David --- diff --git a/fs/netfs/write_issue.c b/fs/netfs/write_issue.c index 69c50f4cbf41..e190043bc0da 100644 --- a/fs/netfs/write_issue.c +++ b/fs/netfs/write_issue.c @@ -315,13 +315,19 @@ static int netfs_write_folio(struct netfs_io_request= *wreq, struct netfs_group *fgroup; /* TODO: Use this with ceph */ struct netfs_folio *finfo; size_t fsize =3D folio_size(folio), flen =3D fsize, foff =3D 0; - loff_t fpos =3D folio_pos(folio); + loff_t fpos =3D folio_pos(folio), i_size; bool to_eof =3D false, streamw =3D false; bool debug =3D false; = _enter(""); = - if (fpos >=3D wreq->i_size) { + /* netfs_perform_write() may shift i_size around the page or from out + * of the page to beyond it, but cannot move i_size into or through the + * page since we have it locked. + */ + i_size =3D i_size_read(wreq->inode); + + if (fpos >=3D i_size) { /* mmap beyond eof. */ _debug("beyond eof"); folio_start_writeback(folio); @@ -332,6 +338,9 @@ static int netfs_write_folio(struct netfs_io_request *= wreq, return 0; } = + if (fpos + fsize > wreq->i_size) + wreq->i_size =3D i_size; + fgroup =3D netfs_folio_group(folio); finfo =3D netfs_folio_info(folio); if (finfo) { @@ -342,14 +351,14 @@ static int netfs_write_folio(struct netfs_io_request= *wreq, = if (wreq->origin =3D=3D NETFS_WRITETHROUGH) { to_eof =3D false; - if (flen > wreq->i_size - fpos) - flen =3D wreq->i_size - fpos; - } else if (flen > wreq->i_size - fpos) { - flen =3D wreq->i_size - fpos; + if (flen > i_size - fpos) + flen =3D i_size - fpos; + } else if (flen > i_size - fpos) { + flen =3D i_size - fpos; if (!streamw) folio_zero_segment(folio, flen, fsize); to_eof =3D true; - } else if (flen =3D=3D wreq->i_size - fpos) { + } else if (flen =3D=3D i_size - fpos) { to_eof =3D true; } flen -=3D foff;