Page MenuHomeFreeBSD

devfs: Fix FLASTCLOSE handling
Needs ReviewPublic

Authored by markj on Wed, Sep 16, 12:06 PM.
Tags
None
Referenced Files
F172323438: D59725.id186846.diff
Thu, Sep 17, 5:50 PM
F172322930: D59725.id186846.diff
Thu, Sep 17, 5:45 PM
F172235363: D59725.id186846.diff
Thu, Sep 17, 3:00 AM
F172219531: D59725.diff
Wed, Sep 16, 11:17 PM
Unknown Object (File)
Wed, Sep 16, 8:53 PM
Unknown Object (File)
Wed, Sep 16, 1:33 PM
Unknown Object (File)
Wed, Sep 16, 1:31 PM
Subscribers
This revision needs review, but there are no reviewers specified.

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
Build Status
Buildable 76971
Build 73854: arc lint + arc unit