From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796404275; b=sziayy1Al5tRgSaMR34fke0biaoBgIJbKpzvuF3u6p50WtEGM9uL8JIKkOE1gOapxYcu tvpDHgtDro7KLRt7pSEu+a41paokhqFNJwfJfloLSPgbKHOKqZtWpV+gsionyu+17Exn1 rAOR1mHkoC2foMLaXVWvMiY5gwDX1xdPZZUwGj9ODc/GbVKu+KnNp3VeP19rWJT/GcjOk U7SNx20kKKbR7sj3IQSP03o8660evTlpjexRe1aU7klOW+EA410HIh/mKPoN1mBa4tiWV XgkXXBMocz+BF+LqGTGpkyIPqPpicYPgEvEV5IGgpT+OsUcw0e2PCO8e1Q4gGtA0EhA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796404275; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=Kq/w7ObEz2WwubhuAqN/U5nWFLqnb+UJWw9fLIQEP8M=; b=DOeX/Q8o/tK9rgFoSgwKbMPRPjCF0mLMhbKzpFwDiw3b2MjidKN+pZ5N9i/9ALKNHBpW lb9r+wkGSJHSgl2zTu7pZfxWwaoDTLYrjDvsozjgoOR0YgdyEqshlXr7uRKD1KpLk/pLK 2ZgRGefUBL9ldlZvUvnjLRB6eQmIC32cXbCkaKwtqW5cGMLqCglqXMc26oujN7mdukcgt I5NPyOaXbo2fTo21vuZx7p+32FUbhUAFzgd0hzPg36qqKxqUJMjgiQe0v4cbT5iQuCxSg xbht0djg/TqcchXuUO6A30jwpSNnECxKk2rqUs3Fkx0MuWX6K9DW+0bd9ThQOMaF+qA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=kM7lti9E; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A3D19606A32C for ; Fri, 4 Dec 2026 17:11:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=kM7lti9E Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5485D1F00A2C; Fri, 4 Dec 2026 17:11:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796404275; bh=Kq/w7ObEz2WwubhuAqN/U5nWFLqnb+UJWw9fLIQEP8M=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=kM7lti9EpDt05Vs7S1j1PZlxXdMiSu1hpfnHNJ0IT7NX5YTT/7HhZ3kw7vBo2z0BW uEw438/oM+BMvwb7WwV8NUqmWul2QSmjpvdjb05N4ir+RMo2i8YTUDUC3Z+6cF1fXO 7Z3aIzAu49115VxZEesuP3lBZGBoxNyAyFjZUt6rC6NIJzMSfNSz/PJ8kQhW/MA3VK 3kadPLbyGGI02Q3JT1Q7EjMnoze8zGDUatzzXsE5qPyXYe49mz1d4iavWK/iavkW5a wJGtJDwGKseS7ZPkQuTMHL6YjpvcUvOc5Y3OsIVpuF0AyIsX1ILv/C84RjgOrroUaZ vfhl/33ixitAg== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH v3 2/2] gfs2: Revalidate the cached writeback mapping after a punch Reply-To: sashiko-reviews@lists.linux.dev To: "Mark Syms" , "Andreas Gruenbacher" Cc: gfs2@lists.linux.dev, "Christoph Hellwig" In-Reply-To: References: <20261202155751.690482-1-mark.syms@citrix.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Fri, 04 Dec 2026 17:11:14 +0000 X-Mailing-List: gfs2@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Thank you for your contribution! Sashiko AI review found 3 potential issues to consider: - [High] gfs2: deferred i_mapping_seq update in punch_hole() races with writeback - [Medium] gfs2: i_mapping_seq bump in __gfs2_iomap_alloc() invalidates writeback cache - [Medium] gfs2: inode_go_inval() misses i_mapping_seq update on cluster invalidation -- commit 576cadb6ded78f5b2a77c217a1a22d5cfb731666 Author: Mark Syms gfs2: Revalidate the cached writeback mapping after a punch This commit adds a per-inode i_mapping_seq counter that is incremented on unstuffing, block allocation, and block deallocation, and checks it via gfs2_iomap_valid() in gfs2_writeback_range() to invalidate cached writeback mappings. > diff --git a/fs/gfs2/bmap.c b/fs/gfs2/bmap.c > index bb9cd9ef8329a..087362bc76c5b 100644 > --- a/fs/gfs2/bmap.c > +++ b/fs/gfs2/bmap.c [ ... ] > @@ -780,6 +796,7 @@ static int __gfs2_iomap_alloc(struct inode *inode, st= ruct iomap *iomap, > ip->i_height =3D mp->mp_fheight; > gfs2_add_inode_blocks(&ip->i_inode, alloced); > gfs2_dinode_out(ip, dibh->b_data); > + iomap->validity_cookie =3D gfs2_update_mapping_seq(ip); > out: > up_write(&ip->i_rw_mutex); > return ret; [Severity: Medium] Does updating i_mapping_seq on every allocation in __gfs2_iomap_alloc() unnecessarily thrash writeback's cached mapping during appending writes? GFS2 allocation only fills zero pointers and never alters existing IOMAP_MAPPED extents. When background writeback or sync_file_range() runs concurrently with appending buffered writes, each allocation invalidates wpc->iomap and forces gfs2_writeback_range() back into gfs2_iomap_get(). That contends directly on ip->i_rw_mutex with __gfs2_iomap_alloc(), re-walks the metadata tree, and repeats gfs2_extent_length() scans instead of reusing the cached extent across folios. Since gfs2_writeback_range() is the only caller of gfs2_iomap_valid(), checking wpc->iomap.type !=3D IOMAP_MAPPED there would avoid caching holes without bumping i_mapping_seq on allocation. [ ... ] > @@ -1627,6 +1654,7 @@ static int sweep_bh_for_rgrps(struct gfs2_inode *ip= , struct gfs2_holder *rd_gh, > gfs2_trans_add_meta(gl, dibh); > gfs2_dinode_out(ip, dibh->b_data); > brelse(dibh); > + gfs2_update_mapping_seq(ip); > up_write(&ip->i_rw_mutex); > gfs2_trans_end(sdp); > buf_in_tr =3D false; [ ... ] > @@ -1983,7 +2011,9 @@ static int punch_hole(struct gfs2_inode *ip, u64 of= fset, u64 length) > =20 > out: > if (btotal) { > - if (current->journal_info =3D=3D NULL) { > + if (current->journal_info) { > + gfs2_update_mapping_seq(ip); > + } else { > int ret2; > =20 > ret2 =3D gfs2_trans_begin(sdp, RES_DINODE + RES_STATFS + [Severity: High] Can deferring gfs2_update_mapping_seq() until transaction end leave a window where concurrent writeback queues I/O to blocks already freed by punch_hole()? In sweep_bh_for_rgrps(), block pointers are zeroed and freed via __gfs2_free_blocks() while i_mapping_seq still holds its pre-punch value. When blks_outside_rgrp is zero, punch_hole() keeps the transaction open acr= oss further metadata levels (including blocking reads in fillup_metapath()) bef= ore updating i_mapping_seq at out:. On filesystems with blocksize < PAGE_SIZE, truncate_pagecache_range() leaves a writable dirty PTE intact on an order-0 boundary folio straddling the pun= ch offset (for example after a short buffered write into gfs2_iomap_end() on a MAP_SHARED file): CPU0 (punch_hole) CPU1 (writeback) gfs2_writeback_range() (folio 0) caches wpc->iomap (seq =3D=3D S) sweep_bh_for_rgrps() down_write(&ip->i_rw_mutex) *p =3D 0; __gfs2_free_blocks() /* i_mapping_seq still S */ fillup_metapath() /* blocks */ folio_clear_dirty_for_io() (folio 1) folio_mkclean() -> iomap_dirty_folio() /* re-dirties punched sub-blocks */ gfs2_writeback_range() gfs2_iomap_valid() -> true (S =3D=3D S) iomap_add_to_ioend() <-- freed blocks gfs2_update_mapping_seq(ip) up_write(&ip->i_rw_mutex) Because gfs2_iomap_valid() reads i_mapping_seq locklessly, writeback skips gfs2_iomap_get() (which would block on i_rw_mutex) and submits I/O to the freed blocks, silently corrupting data once they are reallocated locally or on another cluster node. Updating i_mapping_seq right after taking down_write(&ip->i_rw_mutex) before freeing any blocks, with ordering against lockless readers, would close this window. [ ... ] > @@ -2523,7 +2553,8 @@ static ssize_t gfs2_writeback_range(struct iomap_wr= itepage_ctx *wpc, > return -EIO; > =20 > if (offset < wpc->iomap.offset || > - offset >=3D wpc->iomap.offset + wpc->iomap.length) { > + offset >=3D wpc->iomap.offset + wpc->iomap.length || > + !gfs2_iomap_valid(wpc->inode, &wpc->iomap)) { > int ret; > =20 > memset(&wpc->iomap, 0, sizeof(wpc->iomap)); [Severity: Medium] Can gfs2_writeback_range() reuse a stale cached IOMAP_HOLE mapping after another cluster node allocates blocks, silently dropping dirty writes? Neither inode_go_inval() (under DIO_METADATA) nor gfs2_dinode_in() updates i_mapping_seq. Unlike a mapped ioend, an IOMAP_HOLE mapping clears PG_writeback immediately without holding wpc->wb_ctx, so WB_SYNC_NONE writeback can pause at cond_resched() between folio batches while a glock demotion completes. On a cluster with blocksize < PAGE_SIZE, if a full batch of folios over a punched hole is dirtied (e.g. via GUP write completion): Node A (writeback) Node B / Node A (writer) gfs2_writeback_range() caches IOMAP_HOLE (seq =3D=3D S) writeback_get_folio() folio_batch_release() cond_resched() Node B requests EX glock Node A: inode_go_inval(DIO_METADATA) /* i_mapping_seq still S */ Node B allocates blocks in range Node A: pwrite() -> gfs2_dinode_in() sees IOMAP_MAPPED, dirties folio 31 /* i_mapping_seq still S */ filemap_get_folios_tag() folio_clear_dirty_for_io() gfs2_writeback_range() gfs2_iomap_valid() -> true iomap_add_to_ioend() <-- skips I/O on stale IOMAP_HOLE Because folio_clear_dirty_for_io() has already cleared the dirty state, reusing the stale IOMAP_HOLE drops writeback for folio 31 without submitting I/O, silently losing the write. Updating i_mapping_seq in inode_go_inval() when DIO_METADATA is set (or in gfs2_dinode_in()) would invalidate mappings cached before cluster metadata invalidation. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/cover.1796393524.gi= t.mark.syms@citrix.com?part=3D2