tpm: fix multi-threaded access with per-open state
The TPM driver currently has a single buffer per instance to hold the
result of a command, and does not allow subsequent commands to be sent
until the current result is read by the same OS thread that sent the
command, with a timeout to throw away the result after a while if the
result is not read in a timely fashion. This has a couple problems:
- The timeout code has a bug which causes all subsequent commands to hang forever if a different OS thread tries to read the result before the OS thread which sent the command, and the OS thread which sent the command never tries to read the result.
- Even if the first problem is fixed, applications expect to be able to read the result from a different OS thread than the OS thread which sent the command. The particular case that we saw was a go application where the go runtime scheduled the goroutine which read the result to a different OS thread from one where the goroutine that sent the command ran, and there's no way to force these to always run on the same OS thread.
Fix all of this by replacing the global result buffer with a per-open
result buffer via devfs_set_cdevpriv(), so that we no longer need to
block subsequent commands until the results of a previous command are
retrieved or care about which OS thread is reading the result of a
comamnd.
Sponsored by: Netflix