On Sat, Oct 05, 2024 at 03:01:45PM GMT, Linus Torvalds wrote: > On Sat, 5 Oct 2024 at 14:42, Linus Torvalds > <torvalds@xxxxxxxxxxxxxxxxxxxx> wrote: > > > > and I think that might work, although the zero count case worries me > > (ie 'fput twice'). > > > > Currently we avoid the fput twice because we use that > > "inc_not_zero()". So that needs some thinking about. > > Actually, it's worse. Even the > > if (ret > 1) > > case is dangerous, because we could have two or more threads doing > that atomic_inc_return() on a dead file descriptor at the same time. > > So that approach is just broken. Iiuc, then we should retain the deadzone handling but should replace atomic_long_add_negative() with atomic_long_add_negative_relaxed(). So I would add: static inline __must_check bool rcuref_long_inc(rcuref_long_t *ref) { /* * Unconditionally increase the reference count with full * ordering. The saturation and dead zones provide enough * tolerance for this. */ if (likely(!atomic_long_add_negative(1, &ref->refcnt))) return true; /* Handle the cases inside the saturation and dead zones */ return rcuref_long_get_slowpath(ref); } Or did I miss something else?