From mboxrd@z Thu Jan 1 00:00:00 1970 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 C5E02C25B75 for ; Thu, 23 May 2024 07:44:30 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 206246B007B; Thu, 23 May 2024 03:44:30 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 1B6846B0082; Thu, 23 May 2024 03:44:30 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 07E816B0083; Thu, 23 May 2024 03:44:30 -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 DA5FA6B007B for ; Thu, 23 May 2024 03:44:29 -0400 (EDT) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 603DE803D8 for ; Thu, 23 May 2024 07:44:29 +0000 (UTC) X-FDA: 82148873058.13.F596C9B Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf12.hostedemail.com (Postfix) with ESMTP id 0B4B54001F for ; Thu, 23 May 2024 07:44:25 +0000 (UTC) Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=NrdBZWP+; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf12.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=1716450266; 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-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=kLhXmfF9Sj87o1Kh7Mk5PB3h8im3PzkGpLpb1UjE6M4=; b=3ZrirpCJgiKdloYoTTKVCmCxyfm5PZrdWF0vC18sv9bk7wgxzohP5/ETkb0hSH6Ce1/ViI +6HRt+eX4CMVM3oSTVLLCP7SC1TNaM4VCou801+cqOiby8Bq3NHltJC0+y53naSWNdQ/EC bubVrtn/2Z8xs2xyhSzp6qaqOV8LyYg= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1716450266; a=rsa-sha256; cv=none; b=QzWpT0j6ux3efn50M21L5oq20hserwTO6ogYzJIA6SbKCSM/A6QzOovkfINvtqekx34R3q zcAgvJWTY0ATnf1Z66orDwlRXaj/8zUyIcTmxULPHVcQrLenEcbZ1G/QQD83Hk8Lysz+jq 2Yl2AK5NCnyG8TIAMJXTqz5q8pQYpKc= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=NrdBZWP+; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf12.hostedemail.com: domain of dhowells@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1716450265; 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=kLhXmfF9Sj87o1Kh7Mk5PB3h8im3PzkGpLpb1UjE6M4=; b=NrdBZWP+kq+YE46/ceGDvc/JrDp9rlwGTAaDuu2SKOR2vG4IXvjSQ3fQNPo+fHwYZimvTu cAlfaEAPlRmDdhqgRnsEqctNuj5Ww5T4CYqUYY3EPvfD+saWLgrJOIwN/iuZFvUe7BNLRw huDMs/W+L42ruY33u2xiDI754muE4E4= 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-211-xEhMxZGhNqmZTQdYoGCbdQ-1; Thu, 23 May 2024 03:44:21 -0400 X-MC-Unique: xEhMxZGhNqmZTQdYoGCbdQ-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (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 E0EA881227E; Thu, 23 May 2024 07:44:20 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.42.28.20]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6EA96C15BED; Thu, 23 May 2024 07:44:18 +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: References: <20231221132400.1601991-1-dhowells@redhat.com> <20231221132400.1601991-41-dhowells@redhat.com> To: Andrea Righi Cc: dhowells@redhat.com, Jeff Layton , Steve French , Matthew Wilcox , Paulo Alcantara , Dominique Martinet , Eric Van Hensbergen , Christian Brauner , linux-afs@lists.infradead.org, linux-cifs@vger.kernel.org, v9fs@lists.linux.dev, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Latchesar Ionkov , Christian Schoenebeck Subject: Re: [PATCH v5 40/40] 9p: Use netfslib read/write_iter MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <531993.1716450257.1@warthog.procyon.org.uk> Content-Transfer-Encoding: quoted-printable Date: Thu, 23 May 2024 08:44:17 +0100 Message-ID: <531994.1716450257@warthog.procyon.org.uk> X-Scanned-By: MIMEDefang 3.4.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MIGgDA88pNck3RIES2/8sjO6dhLOp8TCOktCF jv1Mamuz 13ftQJTreNaIjgB5+NvzAt35SesfR/0JElLk71Z+eXmJIXjx8w6/5xJ1KLypVVM862m8Mtg7X5QyMWE1bu6sNxSakBXIGdOtUXvt+ENRs89iz0mW/eLS86WchqY7Inb21YI+Zm4qGRYzHQwfIRw+lonvokxA3mbR/c2lfXpbW8GcMJrtFBRTvKSsSP5bfy52JN8g2kHMvhYFH3dgqyUXAntsGohcDGNsC0nv/TTsAaG9yZ/vmFuj4Bgufy5pTKga/UXt5JglUicOaRN6RQV6k1kvksHu64MLimidmopu894Jxtai+/ajkC/zgWH0VYqxpHbsbfoaQx4EuHqCWlW9ubFLvKvbYzCVZnL1BboS07FyeIcSbkh7K3MSPrYgrD9tdiOBimBhnB/vdVr54QXC0qFsdGrDUGtvOaZi2YPL7Y29oL/nd1qAlCP5Psk1NworibAG6ENbzCMrvgQZEk1+E0KOiDi0vI1KF8v+AOsFXfil0/+py22OrFF97bwXOTmKuhSACOHIRWGp/oEXth/rViHG30dmlszu+LuNotVeloOWrftK0Tg6q3j+HmMaq+qhnMVmhU4H90o6MmJnSXFsM5l3esrUeaSXoIacZsSc+0eTNZAj3NqTHfDEENIHGrT7yfMrwrThfE2WFf/E= 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: Hi Andrea, Note that there are changes to the netfslib write-side upstream and you mi= ght also want to apply the attached. In https://bugs.launchpad.net/ubuntu/+source/autopkgtest/+bug/2056461 you = say: | It seems that kernel 6.8 introduced a regression in the 9pfs related to | caching and netfslib, that can cause some user-space apps to read conten= t | from files that is not up-to-date (when they are used in a producer/cons= umer | fashion). Can you clarify how these files are being used? David --- commit 39302c160390441ed5b4f4f7ad480c44eddf0962 Author: David Howells Date: Wed May 22 17:30:22 2024 +0100 netfs, 9p: Fix race between umount and async request completion = There's a problem in 9p's interaction with netfslib whereby a crash oc= curs because the 9p_fid structs get forcibly destroyed during client teardo= wn (without paying attention to their refcounts) before netfslib has fini= shed with them. However, it's not a simple case of deferring the clunking = that p9_fid_put() does as that requires the client. = The problem is that netfslib has to unlock pages and clear the IN_PROG= RESS flag before destroying the objects involved - including the pid - and,= in any case, nothing checks to see if writeback completed barring looking= at the page flags. = Fix this by keeping a count of outstanding I/O requests (of any type) = and waiting for it to quiesce during inode eviction. = Signed-off-by: David Howells cc: Eric Van Hensbergen cc: Latchesar Ionkov cc: Dominique Martinet cc: Christian Schoenebeck cc: Jeff Layton cc: Steve French cc: v9fs@lists.linux.dev cc: linux-afs@lists.infradead.org cc: linux-cifs@vger.kernel.org cc: netfs@lists.linux.dev cc: linux-fsdevel@vger.kernel.org diff --git a/fs/9p/vfs_inode.c b/fs/9p/vfs_inode.c index 8c9a896d691e..57cfa9f65046 100644 --- a/fs/9p/vfs_inode.c +++ b/fs/9p/vfs_inode.c @@ -354,6 +354,7 @@ void v9fs_evict_inode(struct inode *inode) version =3D cpu_to_le32(v9inode->qid.version); netfs_clear_inode_writeback(inode, &version); = + netfs_wait_for_outstanding_io(inode); clear_inode(inode); filemap_fdatawrite(&inode->i_data); = @@ -361,8 +362,10 @@ void v9fs_evict_inode(struct inode *inode) if (v9fs_inode_cookie(v9inode)) fscache_relinquish_cookie(v9fs_inode_cookie(v9inode), false); #endif - } else + } else { + netfs_wait_for_outstanding_io(inode); clear_inode(inode); + } } = struct inode * diff --git a/fs/afs/inode.c b/fs/afs/inode.c index 94fc049aff58..c831e711a4ac 100644 --- a/fs/afs/inode.c +++ b/fs/afs/inode.c @@ -652,6 +652,7 @@ void afs_evict_inode(struct inode *inode) = afs_set_cache_aux(vnode, &aux); netfs_clear_inode_writeback(inode, &aux); + netfs_wait_for_outstanding_io(inode); clear_inode(inode); = while (!list_empty(&vnode->wb_keys)) { diff --git a/fs/netfs/objects.c b/fs/netfs/objects.c index c90d482b1650..f4a642727479 100644 --- a/fs/netfs/objects.c +++ b/fs/netfs/objects.c @@ -72,6 +72,7 @@ struct netfs_io_request *netfs_alloc_request(struct addr= ess_space *mapping, } } = + atomic_inc(&ctx->io_count); trace_netfs_rreq_ref(rreq->debug_id, 1, netfs_rreq_trace_new); netfs_proc_add_rreq(rreq); netfs_stat(&netfs_n_rh_rreq); @@ -124,6 +125,7 @@ static void netfs_free_request(struct work_struct *wor= k) { struct netfs_io_request *rreq =3D container_of(work, struct netfs_io_request, work); + struct netfs_inode *ictx =3D netfs_inode(rreq->inode); unsigned int i; = trace_netfs_rreq(rreq, netfs_rreq_trace_free); @@ -142,6 +144,9 @@ static void netfs_free_request(struct work_struct *wor= k) } kvfree(rreq->direct_bv); } + + if (atomic_dec_and_test(&ictx->io_count)) + wake_up_var(&ictx->io_count); call_rcu(&rreq->rcu, netfs_free_request_rcu); } = diff --git a/fs/smb/client/cifsfs.c b/fs/smb/client/cifsfs.c index ec5b639f421a..21c9e173ea9a 100644 --- a/fs/smb/client/cifsfs.c +++ b/fs/smb/client/cifsfs.c @@ -435,6 +435,7 @@ cifs_evict_inode(struct inode *inode) if (inode->i_state & I_PINNING_NETFS_WB) cifs_fscache_unuse_inode_cookie(inode, true); cifs_fscache_release_inode_cookie(inode); + netfs_wait_for_outstanding_io(inode); clear_inode(inode); } = diff --git a/include/linux/netfs.h b/include/linux/netfs.h index d2d291a9cdad..3ca3906bb8da 100644 --- a/include/linux/netfs.h +++ b/include/linux/netfs.h @@ -68,6 +68,7 @@ struct netfs_inode { loff_t remote_i_size; /* Size of the remote file */ loff_t zero_point; /* Size after which we assume there's no data * on the server */ + atomic_t io_count; /* Number of outstanding reqs */ unsigned long flags; #define NETFS_ICTX_ODIRECT 0 /* The file has DIO in progress */ #define NETFS_ICTX_UNBUFFERED 1 /* I/O should not use the pagecache */ @@ -474,6 +475,7 @@ static inline void netfs_inode_init(struct netfs_inode= *ctx, ctx->remote_i_size =3D i_size_read(&ctx->inode); ctx->zero_point =3D LLONG_MAX; ctx->flags =3D 0; + atomic_set(&ctx->io_count, 0); #if IS_ENABLED(CONFIG_FSCACHE) ctx->cache =3D NULL; #endif @@ -517,4 +519,20 @@ static inline struct fscache_cookie *netfs_i_cookie(s= truct netfs_inode *ctx) #endif } = +/** + * netfs_wait_for_outstanding_io - Wait for outstanding I/O to complete + * @ctx: The netfs inode to wait on + * + * Wait for outstanding I/O requests of any type to complete. This is in= tended + * to be called from inode eviction routines. This makes sure that any + * resources held by those requests are cleaned up before we let the inod= e get + * cleaned up. + */ +static inline void netfs_wait_for_outstanding_io(struct inode *inode) +{ + struct netfs_inode *ictx =3D netfs_inode(inode); + + wait_var_event(&ictx->io_count, atomic_read(&ictx->io_count) =3D=3D 0); +} + #endif /* _LINUX_NETFS_H */