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

Brian Foster
2025-10-14T17:52:54Z

On Tue, Oct 14, 2025 at 10:01:53AM -0700, Joanne Koong wrote:
> On Tue, Oct 14, 2025 at 5:43 AM Miklos Szeredi <miklos@szeredi.hu> wrote:
> >
> > On Tue, 14 Oct 2025 at 09:48, Miklos Szeredi <miklos@szeredi.hu> wrote:
> >
> > > Maybe the solution is to change the write-through to regular cached
> > > write + fsync range? That could even be a complexity reduction.
> >
> > While this would be nice, it's impossible to guarantee requests being
> > initiated in the context of the original write(2), which means that
> > the information about which open file it originated from might be
> > lost. This could result in regressions, so I don't think we should
> > risk it.
> >
> > Will try the idea of marking folios writeback for the duration of the write.
> >
>
> Is it safe to mark a folio as being under writeback if it doesn't
> actually go through mm writeback? for example, my understanding is
> that the inode wb mechanisms get initiated when an inode is marked
> dirty (__mark_inode_dirty()) but writethrough skips any dirtying.
> Afaict, folio_start_writeback()/folio_end_write() needs i_wb.
> Additionally, if the server page faults on the folio that is now
> marked as under writeback, does that lead to a deadlock since
> page_mkwrite() waits on folio writeback?
>

WRT dirtying I think Miklos was primarily concerned with some other
thread being able to pick up the folio for writeback. I'm not certain if
writeback is dependent on being dirty, but if it is, ISTM you could
technically still mark the folio dirty and transition it to writeback
before it's unlocked in the write path. To Miklos earlier point that
would put the folio through the same sequence as proper writeback,
except I think would claim the writeback work for the current task.

That might start to look wonky I suppose, but maybe that can be
addressed after if it can at least be shown to fix the problem. For
example, if it's really just the wb that is an issue, perhaps an
inode_attach_wb() is all that's needed?

I'm not sure about the fault case. I'm assuming fuse still supports
traditional writeback and that this would all work similarly to that
case.

Brian

>
> Thanks,
> Joanne
>
> > Thanks,
> > Miklos
>