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=1796222419; b=TltiQ2qd7XNWBKkGictfxU79sFrLUieXiRiaiYM8ULdwF2UVcMYaPQM1RJ3DlnR+A/1C yMFq+lTyab1xB0m2WkLqFg677e1Aof1kppWMTmJBQgiEeW+3TTRPYolZYmkrhYK1Wero6 Mk6UqzzQcmifTR5Cqf1KfBhNrV/LXYCWD2C0kBOwGAhQVzBboQN+bhzwDYzYFjOzbhutL 39R4FXt8v19hVYNk5hmJ33bmoiq67lJb3BddzzDZO7W1cR2dGpS94x3jopsu3+PWltrbq zmzQZORz4S/cA6wsb5A6D4qMhKnZfUXQx1UurrckkfRmw/S15ZGq4GTDc3FHtcjdlWw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796222419; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=WAFSDyKCKEk4vG+My2h+x5/+gI1tNdKv6rbPiEnqY8w=; b=SCbnmnqKi3s+OtGRtZ+VUB+GEwGh2ruyF+ZtyeHEvptcA1llWOVPrUQBWGB0RLLA7fQz eFAI8T8BGKGxT1oBJfD3emrYdT45y39am6XYYHCo/v6FLkyX4s/y3iueRF8tGahpWVnXA XWZ6HTezCpxYPI9qcCbGiLRowuATrOt7BnNPotIMS2ObZT5aykheSSykGP7RTswkWilJw BUxBq2nwu2DWiRqXV4HxHsQBtpKq7A+SlfSL/Sm8aZGkygDJGVY3GOu440GvQybEfW1Mk iGNCdBt4NC/PbpZ40hvqSfITMVpFQMB4J2tbCp1VOqClowm7cANrBtDSMVejy73Ldtw== 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=KMgVdWCL; 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 DEA1A606A31A for ; Wed, 2 Dec 2026 14:40:19 +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=KMgVdWCL Received: by smtp.kernel.org (Postfix) with ESMTPSA id 55AE91F000C1; Wed, 2 Dec 2026 14:40:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796222419; bh=WAFSDyKCKEk4vG+My2h+x5/+gI1tNdKv6rbPiEnqY8w=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=KMgVdWCLIv4OCB/TIZnhMITlMTWzjwN+G1jK5C9mlXBw9+iMs6OljmyrfWLDk9hzD A1pUeWXMBNs9cweY/79VBo99Rl5zx8sPKZoqe3XLdXdFiJCsQeIghwleT69oLUUKHc bqFREiq0OcEF54DYI1F8mftdRrUKBfPv9O/tYBXG4v03fuWcjOnTBfeX/vITVtt0jf ynpuge7UFKdF9sQcIiL67A2v+Bgk31Vf2PdgMZyDN5T8Vul3GbuAW0oWpetsx7FALN niX+Br5JurHVDrzgtwAEkDImRPt9VFcdDLuybCBSMcruccOuaWrabNdDSPwo2ELXE3 wW6zV7hok3QCg== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH] 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 In-Reply-To: <20261202141814.668810-1-mark.syms@citrix.com> References: <20261202141814.668810-1-mark.syms@citrix.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Wed, 02 Dec 2026 14:40:18 +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 2 potential issues to consider: - [Critical] gfs2: stale cached IOMAP_HOLE reused in gfs2_writeback_range() - [Low] gfs2: missing Fixes trailer for writeback iomap caching bug -- commit febe07e5d07d46ee6a99440c51133ed31590c10c Author: Mark Syms > gfs2: Revalidate the cached writeback mapping after a punch > > gfs2_writeback_range() keeps using the mapping cached in wpc->iomap > for every folio it covers, but punch_hole() can free blocks inside > that mapping while writeback is still walking the file. > > This happens on an ordinary buffered write. gfs2_file_buffered_write() > runs with page faults disabled, so a source page that is not resident > makes the write come up short, and gfs2_iomap_end() punches the > unwritten blocks it had just allocated. The retry allocates new > blocks, but writeback writes the retried folios to the freed ones > through the stale mapping. The new blocks are never written and keep > whatever they held before, exposing another file's data. On a > cluster the freed blocks may already belong to another node. > > Found in XenServer, where suspend images on GFS2 picked up other > guests' memory. A reproducer that writes 512 KiB extents from a buffer > whose tail is repeatedly dropped with MADV_DONTNEED, with > sync_file_range() running alongside, corrupted 11 blocks in 20 rounds > before this change and none after. > > Count deallocations per inode and reuse the cached mapping only while > the count is unchanged. > > Signed-off-by: Mark Syms [Severity: Low] This fixes the cached writeback mapping introduced in commit 2164f9b91869. Should this include: Fixes: 2164f9b91869 ("gfs2: use iomap for buffered I/O in ordered and wri= teback mode") > diff --git a/fs/gfs2/bmap.c b/fs/gfs2/bmap.c > index 35b0d8d41b98f..9be06b8be98ef 100644 > --- a/fs/gfs2/bmap.c > +++ b/fs/gfs2/bmap.c [ ... ] > @@ -2515,17 +2518,23 @@ int __gfs2_punch_hole(struct file *file, loff_t o= ffset, loff_t length) > static ssize_t gfs2_writeback_range(struct iomap_writepage_ctx *wpc, > struct folio *folio, u64 offset, unsigned int len, u64 end_pos) > { > - if (WARN_ON_ONCE(gfs2_is_stuffed(GFS2_I(wpc->inode)))) > + struct gfs2_inode *ip =3D GFS2_I(wpc->inode); > + u32 seq; > + > + if (WARN_ON_ONCE(gfs2_is_stuffed(ip))) > return -EIO; > =20 > + seq =3D atomic_read_acquire(&ip->i_dealloc_seq); > if (offset < wpc->iomap.offset || > - offset >=3D wpc->iomap.offset + wpc->iomap.length) { > + offset >=3D wpc->iomap.offset + wpc->iomap.length || > + wpc->iomap.validity_cookie !=3D seq) { > int ret; > =20 > memset(&wpc->iomap, 0, sizeof(wpc->iomap)); > ret =3D gfs2_iomap_get(wpc->inode, offset, INT_MAX, &wpc->iomap); > if (ret) > return ret; > + wpc->iomap.validity_cookie =3D seq; > } > =20 > return iomap_add_to_ioend(wpc, folio, offset, end_pos, len); [Severity: Critical] Can gfs2_writeback_range() still reuse a stale cached IOMAP_HOLE mapping after new blocks are allocated inside that hole? When blocksize < PAGE_SIZE, a dirty folio can have an allocated block followed by hole blocks that are marked dirty (for example, when a short buffered write on an uptodate folio with folio->private =3D=3D NULL faults after the first block and gfs2_iomap_end() punches the rest of the folio). When writeback reaches the unallocated block in that folio, gfs2_iomap_get() returns an IOMAP_HOLE mapping spanning up to INT_MAX bytes and caches it with validity_cookie =3D seq. When the retry allocates blocks in that hole via __gfs2_iomap_alloc() and dirties the following folios, ip->i_dealloc_seq is not incremented. As writeback advances to those folios, wpc->iomap.validity_cookie still matches seq, so iomap_add_to_ioend() sees IOMAP_HOLE and skips submitting I/O while iomap_writeback_folio() clears the dirty state, leaving the newly allocated blocks unwritten on disk. Checking wpc->iomap.type !=3D IOMAP_MAPPED (or bumping the sequence counter on allocation as well) would avoid reusing cached hole mappings. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261202141814.6688= 10-1-mark.syms@citrix.com?part=3D1