Page MenuHomeFreeBSD

getblk: Avoid sleeping on wrong buf in lockless path
ClosedPublic

Authored by cem on Jul 30 2020, 9:57 PM.
Tags
None
Referenced Files
Unknown Object (File)
Oct 5 2023, 8:50 AM
Unknown Object (File)
Sep 19 2023, 11:55 AM
Unknown Object (File)
Sep 7 2023, 2:14 AM
Unknown Object (File)
Sep 7 2023, 2:13 AM
Unknown Object (File)
Sep 7 2023, 2:13 AM
Unknown Object (File)
Sep 7 2023, 2:12 AM
Unknown Object (File)
Sep 1 2023, 6:13 PM
Unknown Object (File)
Aug 14 2023, 5:58 AM
Subscribers

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

Lint
Lint Passed
Unit
No Test Coverage
Build Status
Buildable 32667
Build 30119: arc lint + arc unit

Event Timeline

cem requested review of this revision.Jul 30 2020, 9:57 PM
cem created this revision.
sys/kern/vfs_bio.c
3868–3870

SLEEPFAIL does not make sense together with NOWAIT.

sys/kern/vfs_bio.c
3888–3891

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;

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

kib added inline comments.
sys/kern/vfs_bio.c
3868–3870

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

3888–3891

I think it would clarify the code.

This revision is now accepted and ready to land.Jul 30 2020, 11:46 PM
cem marked an inline comment as done.Jul 31 2020, 12:03 AM
cem added inline comments.
sys/kern/vfs_bio.c
3868–3870

will do.

3888–3891

will do as a follow-up

This revision was automatically updated to reflect the committed changes.