Re: [PATCH v6 0/5] Fix easy bits of the negative dentry problem

From: Amir Goldstein

Date: Tue Nov 24 2026 - 08:08:43 EST


On Tue, Nov 24, 2026 at 7:42 AM NeilBrown <neilb@xxxxxxxxxxx> wrote:
>
> On Tue, 24 Nov 2026, NeilBrown wrote:
> > This v6:
> > - fixes the autofs changes in 1/5
>
> Sashiko says this is racy. I think it is but the original code was just
> as racy. Maybe the race isn't relevant. I haven't properly understood
> it yet.
>
> > - updates d_duplicate() in 1/5
>
> The fix was seriously broken. Sorry.
>
> > - uses a new version of 2/5 from Amir
>
> Sashiko has something to say about this
>
> Can clearing FSNOTIFY_CONN_FLAG_UPDATE_CHILDREN and dropping conn->lock
> before fsnotify_set_children_dentry_flags() finishes allow a concurrent
> watch-adding syscall to return to userspace before the children's
> DCACHE_FSNOTIFY_PARENT_WATCHED flags have been set?
>
> Thoughts?

Sashiko is right, but this race is not new.
The same window exists upstream: if another thread's recalc observes
the 0->watching transition and does the walk, fanotify_mark() can return
to userspace before all children have DCACHE_FSNOTIFY_PARENT_WATCHED set.

What changes with this series is that the walk is sleepable, so the
window is longer, and in some workloads it could go from rare to
plausible. OTOH, skipping negative dentries may shorten the walk.

The more important question is whether a child can be left without
PARENT_WATCHED permanently. Upstream it can: the transition can be
observed by a recalc from the mark destroy path, which never walks.
With FSNOTIFY_CONN_FLAG_UPDATE_CHILDREN that cannot happen.
Every transition sets the flag, and every caller that can add a watch
consumes it,
so a walk that started after the transition always runs and fixes the flags.
What remains is the transient window above.

I think a proper fix for the transient window needs a sequence counter
of scans in the connector. Each caller would wait until a scan that
started after its transition has completed, no matter which thread ran it.

I think we can live with this v6 patch for your series and deal with
the remaining race later if we want to, but I am not sure and would
like to hear what Jan thinks.

If you want, I can implement the sequence counter for v7.

Thanks,
Amir.