* Avoiding EBUSY on TPM writes
@ 2023-06-15 21:09 Matthew Garrett
2023-06-15 23:38 ` James Bottomley
0 siblings, 1 reply; 3+ messages in thread
From: Matthew Garrett @ 2023-06-15 21:09 UTC (permalink / raw)
To: linux-integrity; +Cc: peterhuewe, jarkko, jgg
We're running into a situation where concurrent TPM accesses can trigger
EBUSY on write due to there either being a queued command or a response
not yet having been read. Obviously one approach would be to retry, but
that involves us either spinning or waiting for an arbitrary amount of
time between attempts, which doesn't seem ideal. There's a poll
interface that tells us whether there's a response to read but (a) that
doesn't help in the enqueued command situation and (b) this would still
be racy - we could be notified that the response has been read, be
preempted, and have another process perform a write before we get the
opportunity to.
What's the right way to fix this? One approach would simply be to
replace the EBUSY with an interruptible sleep and wake the process when
the TPM is available, but that feels like it's technically an ABI break.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Avoiding EBUSY on TPM writes
2023-06-15 21:09 Avoiding EBUSY on TPM writes Matthew Garrett
@ 2023-06-15 23:38 ` James Bottomley
2023-06-15 23:54 ` Matthew Garrett
0 siblings, 1 reply; 3+ messages in thread
From: James Bottomley @ 2023-06-15 23:38 UTC (permalink / raw)
To: Matthew Garrett, linux-integrity; +Cc: peterhuewe, jarkko, jgg
On Thu, 2023-06-15 at 22:09 +0100, Matthew Garrett wrote:
> We're running into a situation where concurrent TPM accesses can
> trigger EBUSY on write due to there either being a queued command or
> a response not yet having been read. Obviously one approach would be
> to retry, but that involves us either spinning or waiting for an
> arbitrary amount of time between attempts, which doesn't seem ideal.
> There's a poll interface that tells us whether there's a response to
> read but (a) that doesn't help in the enqueued command situation and
> (b) this would still be racy - we could be notified that the
> response has been read, be preempted, and have another process
> perform a write before we get the opportunity to.
That's by design: the fd interface is command/response per open fd, so
if you try to send another command before you get a response you'll get
an EBUSY by design. If you didn't, how would you know which response
belonged to which command (there's no counter or other identifier)?
However, this behaviour is per-fd, why can't you just open multiple
fd's for your multiple accesses? /dev/tpmrm0 will assure that they
don't see each other and that the commands are properly sequenced
without giving you an EBUSY. And bonus you don't have to keep global
track of how many transient resources you've used.
James
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Avoiding EBUSY on TPM writes
2023-06-15 23:38 ` James Bottomley
@ 2023-06-15 23:54 ` Matthew Garrett
0 siblings, 0 replies; 3+ messages in thread
From: Matthew Garrett @ 2023-06-15 23:54 UTC (permalink / raw)
To: James Bottomley; +Cc: linux-integrity, peterhuewe, jarkko, jgg
On Thu, Jun 15, 2023 at 07:38:57PM -0400, James Bottomley wrote:
> However, this behaviour is per-fd, why can't you just open multiple
> fd's for your multiple accesses? /dev/tpmrm0 will assure that they
> don't see each other and that the commands are properly sequenced
> without giving you an EBUSY. And bonus you don't have to keep global
> track of how many transient resources you've used.
Argh! Sorry, I'd missed that this was per-fd - that makes complete
sense. Let me figure out why we're re-using the same fd for multiple
requests.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2023-06-15 23:54 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-06-15 21:09 Avoiding EBUSY on TPM writes Matthew Garrett
2023-06-15 23:38 ` James Bottomley
2023-06-15 23:54 ` Matthew Garrett
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).