Page MenuHomeFreeBSD

devfs: Fix FLASTCLOSE handling
AbandonedPublicDraft

Authored by markj on Wed, Sep 16, 12:05 PM.
Tags
None
Referenced Files
Unknown Object (File)
Fri, Sep 18, 2:31 PM
Unknown Object (File)
Thu, Sep 17, 11:45 PM
Unknown Object (File)
Thu, Sep 17, 9:10 PM
Unknown Object (File)
Thu, Sep 17, 4:32 PM
Unknown Object (File)
Wed, Sep 16, 11:30 PM
Unknown Object (File)
Wed, Sep 16, 11:17 PM
Unknown Object (File)
Wed, Sep 16, 11:04 PM
Subscribers

Details

Reviewers
None
Summary

devfs uses the device's usecount to determine how many times a device
has been opened. If it transitions 1->0, then we should invoke d_close
(assuming D_TRACKCLOSE isn't set).

But, we bump the usecount before calling d_open. Suppose a thread races
to open a device while a different thread is closing it. The first
thread may bump usecount 1->2, and then the closing thread decrements it
2->1. Then, if the open fails, we will decrement again 1->0 but d_close
is not invoked at all.

Fix the problem by incrementing usecount only after a succesful open. I
believe this does not introduce any new races: the usecount is only used
to decide whether to revoke or not, and the session holds an additional
ref via devfs_ctty_ref(). Note however that d_close(FLASTCLOSE) can
now race with d_open().

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Skipped
Unit
Tests Skipped