Page MenuHomeFreeBSD

getblk: Avoid sleeping on wrong buf in lockless path
ClosedPublic

Authored by cem on Thu, Jul 30, 9:57 PM.

Details

Summary

If the buffer identity changed during lookup, sleeping could introduce a
lock order reversal. Since we do not know if the identity changed until we
get the lock, we must try-lock (LK_NOWAIT) only. EINTR and ERESTART error
handling becomes irrelevant, as we no longer sleep.

Reported by: kib
X-MFC-With: r363482

Diff Detail

Repository
rS FreeBSD src repository
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.

Event Timeline

cem requested review of this revision.Thu, Jul 30, 9:57 PM
cem created this revision.
kib added inline comments.Thu, Jul 30, 10:31 PM
sys/kern/vfs_bio.c
3868 ↗(On Diff #75188)

SLEEPFAIL does not make sense together with NOWAIT.

cem added inline comments.Thu, Jul 30, 11:23 PM
sys/kern/vfs_bio.c
3888–3891 ↗(On Diff #75188)

Should this logic be changed to avoid LK_SLEEPFAIL | LK_NOWAIT?

lockflags = LK_EXCLUSIVE | LK_INTERLOCK;

if ((flags & GB_LOCK_NOWAIT) != 0)
    lockflags |= LK_NOWAIT;
else
    lockflags |= LK_SLEEPFAIL;
cem updated this revision to Diff 75189.Thu, Jul 30, 11:27 PM

Drop LK_SLEEPFAIL for LK_NOWAIT lockless lookup path. No functional change.

kib accepted this revision.Thu, Jul 30, 11:46 PM
kib added inline comments.
sys/kern/vfs_bio.c
3868 ↗(On Diff #75188)

Drop lockflags use there, pass LK_EXCLUSIVE | LK_NOWAIT directly to BUF_TIMELOCK().

3888–3891 ↗(On Diff #75188)

I think it would clarify the code.

This revision is now accepted and ready to land.Thu, Jul 30, 11:46 PM
cem marked an inline comment as done.Fri, Jul 31, 12:03 AM
cem added inline comments.
sys/kern/vfs_bio.c
3868 ↗(On Diff #75188)

will do.

3888–3891 ↗(On Diff #75188)

will do as a follow-up

This revision was automatically updated to reflect the committed changes.