Re: [PATCH 5.15] fuse: Fix race condition in writethrough path A race

Miklos Szeredi
2025-10-10T08:46:40Z

On Fri, 10 Oct 2025 at 08:25, lu gu <giveme.gulu@gmail.com> wrote:

> This should serialize backend reads and writes for overlapping ranges
> while avoiding the deadlock risk, since the waiting happens at the
> FUSE layer rather than under a page lock.
>
> Does this approach sound reasonable to you? I’d really appreciate your
> feedback on whether this design makes sense, or if you see any
> potential pitfalls I’ve missed.

Thanks for the great report.

The underlying issue here I think is that auto invalidation happens
(based on mtime change) despite the file not having been changed
externally. This can happen because fuse_change_attributes_i() will
look at an old mtime value even if it's known to have been invalidated
by a write for example.

My idea is to introduce FUSE_I_MTIME_UNSTABLE (which would work
similarly to FUSE_I_SIZE_UNSTABLE) and when fetching old_mtime, verify
that it hasn't been invalidated. If old_mtime is invalid or if
FUSE_I_MTIME_UNSTABLE signals that a write is in progress, the page
cache is not invalidated.

Will try this and send a patch.

Thanks,
Miklos