From: sashiko-bot@kernel.org
To: "Mark Syms" <mark.syms@citrix.com>,
"Andreas Gruenbacher" <agruenba@redhat.com>
Cc: gfs2@lists.linux.dev
Subject: Re: [PATCH] gfs2: Revalidate the cached writeback mapping after a punch
Date: Wed, 02 Dec 2026 14:40:18 +0000 [thread overview]
Message-ID: <sashiko-outbox-245981@kernel.org> (raw)
In-Reply-To: <20261202141814.668810-1-mark.syms@citrix.com>
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 <mark.syms@citrix.com>
> 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 <mark.syms@citrix.com>
[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 writeback 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 offset, 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 = GFS2_I(wpc->inode);
> + u32 seq;
> +
> + if (WARN_ON_ONCE(gfs2_is_stuffed(ip)))
> return -EIO;
>
> + seq = atomic_read_acquire(&ip->i_dealloc_seq);
> if (offset < wpc->iomap.offset ||
> - offset >= wpc->iomap.offset + wpc->iomap.length) {
> + offset >= wpc->iomap.offset + wpc->iomap.length ||
> + wpc->iomap.validity_cookie != seq) {
> int ret;
>
> memset(&wpc->iomap, 0, sizeof(wpc->iomap));
> ret = gfs2_iomap_get(wpc->inode, offset, INT_MAX, &wpc->iomap);
> if (ret)
> return ret;
> + wpc->iomap.validity_cookie = seq;
> }
>
> 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 == 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 = 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 != IOMAP_MAPPED (or bumping the sequence counter
on allocation as well) would avoid reusing cached hole mappings.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261202141814.668810-1-mark.syms@citrix.com?part=1
next prev parent reply other threads:[~2026-12-02 14:40 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-02 14:18 [PATCH] gfs2: Revalidate the cached writeback mapping after a punch Mark Syms
2026-12-02 14:40 ` sashiko-bot [this message]
2026-12-02 15:57 ` [PATCH v2] " Mark Syms
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=sashiko-outbox-245981@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=agruenba@redhat.com \
--cc=gfs2@lists.linux.dev \
--cc=mark.syms@citrix.com \
--cc=sashiko-reviews@lists.linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox