Mark the device as dying before teardown and destroy the character device before freeing its private state or lock. This prevents cdev methods from entering with a freed internal buffer or a destroyed sx. Check the teardown state in command paths, honor failures from the cdev private data interface, and keep the lifecycle lock across TPM retry delays so detach cannot interpose between retries. Block new cdev operations after a successful Shutdown(STATE). Keep the suspend gate and the TPM command under the same lock so a userspace command cannot invalidate the saved state before S3 entry. Clear the gate only after Startup(STATE) succeeds. Keep entropy harvesting scheduled after a transient command or suspend failure, but stop it while suspended or once teardown begins. Queue the next timeout while holding the lifecycle lock so release cannot miss a concurrent requeue. Validated on two TPM 2.0 FIFO systems. Each completed five device suspend/resume cycles, rejected both new and already-open cdev operations with EBUSY while suspended, completed 200 concurrent PCR reads, and detached cleanly while four PCR readers were active. A ThinkPad P50 also completed a full S3 cycle with PCR 0 unchanged and 50 successful reads after resume. MFC after: 2 weeks
Details
Details
- Reviewers
markj kevans seuros - Commits
- rGa3daa1e8f598: tpm20: Harden the common device lifecycle
Diff Detail
Diff Detail
- Repository
- rG FreeBSD src repository
- Lint
Lint Not Applicable - Unit
Tests Not Applicable
Event Timeline
| sys/dev/tpm/tpm20.c | ||
|---|---|---|
| 393 | I think I agree with holding the lock prior to calling tpm20_command, but I kind of suspect we actually do want to drop it between retry attempts and recheck for sc->dying between them. We may need something to block concurrent entrance to tpm20_command, but depending on why the detach was initiated trying to talk to the hardware seems like it could be fraught with peril and it's maybe better to catch that sooner. | |
| 446–447 | I'd maybe move this up above the cmd construction just to get error cases out of the way earlier, but I don't insist | |