From: sashiko-bot@kernel.org
To: "Mark Syms" <mark.syms@citrix.com>,
"Andreas Gruenbacher" <agruenba@redhat.com>
Cc: gfs2@lists.linux.dev, "Christoph Hellwig" <hch@lst.de>
Subject: Re: [PATCH v3 2/2] gfs2: Revalidate the cached writeback mapping after a punch
Date: Fri, 04 Dec 2026 17:11:14 +0000 [thread overview]
Message-ID: <sashiko-outbox-250272@kernel.org> (raw)
In-Reply-To: <b343c8ea19e798312edda5237e673ae0a6b7d1fa.1796393524.git.mark.syms@citrix.com>
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 <mark.syms@citrix.com>
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, struct iomap *iomap,
> ip->i_height = mp->mp_fheight;
> gfs2_add_inode_blocks(&ip->i_inode, alloced);
> gfs2_dinode_out(ip, dibh->b_data);
> + iomap->validity_cookie = 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 != 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 = false;
[ ... ]
> @@ -1983,7 +2011,9 @@ static int punch_hole(struct gfs2_inode *ip, u64 offset, u64 length)
>
> out:
> if (btotal) {
> - if (current->journal_info == NULL) {
> + if (current->journal_info) {
> + gfs2_update_mapping_seq(ip);
> + } else {
> int ret2;
>
> ret2 = 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 across
further metadata levels (including blocking reads in fillup_metapath()) before
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 punch
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 == S)
sweep_bh_for_rgrps()
down_write(&ip->i_rw_mutex)
*p = 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 == 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_writepage_ctx *wpc,
> return -EIO;
>
> if (offset < wpc->iomap.offset ||
> - offset >= wpc->iomap.offset + wpc->iomap.length) {
> + offset >= wpc->iomap.offset + wpc->iomap.length ||
> + !gfs2_iomap_valid(wpc->inode, &wpc->iomap)) {
> int ret;
>
> 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 == 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.
--
Sashiko AI review · https://sashiko.dev/#/patchset/cover.1796393524.git.mark.syms@citrix.com?part=2
next prev parent reply other threads:[~2026-12-04 17:11 UTC|newest]
Thread overview: 10+ 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
2026-12-02 15:57 ` [PATCH v2] " Mark Syms
2026-12-02 20:54 ` Andreas Gruenbacher
2026-12-04 16:08 ` [PATCH v3 0/2] " Mark Syms
2026-12-04 16:08 ` [PATCH v3 1/2] gfs2: minor punch_hole error path cleanup Mark Syms
2026-12-04 16:37 ` sashiko-bot
2026-12-04 16:08 ` [PATCH v3 2/2] gfs2: Revalidate the cached writeback mapping after a punch Mark Syms
2026-12-04 17:11 ` sashiko-bot [this message]
2026-12-04 16:26 ` [PATCH v3 0/2] " Andreas Gruenbacher
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-250272@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=agruenba@redhat.com \
--cc=gfs2@lists.linux.dev \
--cc=hch@lst.de \
--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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.