public inbox for v9fs@lists.linux.dev
 help / color / mirror / Atom feed
* [BUG] 9p: data corruption with cache=mmap under concurrent stat/write
@ 2025-12-24 14:29 Pierre Barre
  2025-12-24 22:33 ` Dominique Martinet
  0 siblings, 1 reply; 6+ messages in thread
From: Pierre Barre @ 2025-12-24 14:29 UTC (permalink / raw)
  To: ericvh, lucho, asmadeus; +Cc: linux_oss, v9fs, linux-kernel

Hi,

I'm hitting data corruption using 9p with cache=mmap when stat() is called concurrently with writes.

Environment:
- Kernel: v6.18.1-061801
- Mount options: cache=mmap
- Transport: unix

Reproducer:
1. Mount 9p filesystem with cache=mmap
2. Run PostgreSQL with data directory on 9p mount
3. Run pgbench workload
4. Simultaneously run `watch -n 0.1 tree -ah` on the data directory

PostgreSQL reports:
  ERROR: unexpected data beyond EOF in block N of relation "..."
  HINT: This has been seen to occur with buggy kernels

Analysis:

The issue appears to be race conditions in getattr/setattr when using
writeback caching:

1. v9fs_vfs_getattr_dotl() condition checks `v9ses->cache` instead of
   `v9ses->cache & CACHE_WRITEBACK`, triggering writeback flush for
   any cache mode
2. Both getattr and setattr call filemap_fdatawrite() which initiates
   writeback but doesn't wait for completion. The subsequent server
   stat/wstat sees stale file size.

Would using filemap_write_and_wait() instead be the correct fix?

Thanks,
Pierre Barre

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2026-01-05  7:54 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-12-24 14:29 [BUG] 9p: data corruption with cache=mmap under concurrent stat/write Pierre Barre
2025-12-24 22:33 ` Dominique Martinet
2025-12-25 10:23   ` Christian Schoenebeck
2025-12-25 14:52     ` Pierre Barre
2025-12-26 13:13       ` Pierre Barre
2026-01-05  7:54     ` David Howells

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox