Page MenuHomeFreeBSD

devfs: Fix FLASTCLOSE handling
DraftPublic

Authored by markj on Wed, Sep 16, 12:05 PM.
Tags
None
Referenced Files
F172220362: D59724.id186842.diff
Wed, Sep 16, 11:30 PM
F172219472: D59724.diff
Wed, Sep 16, 11:17 PM
F172218773: D59724.diff
Wed, Sep 16, 11:04 PM
Subscribers
None
This is a draft revision that has not yet been submitted for review.

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

Event Timeline