From: Stefan Berger <stefanb@linux.vnet.ibm.com>
To: "Michael S. Tsirkin" <mst@redhat.com>
Cc: qemu-devel@nongnu.org, andreas.niederl@iaik.tugraz.at
Subject: Re: [Qemu-devel] [PATCH V14 5/7] Add a TPM Passthrough backend driver implementation
Date: Mon, 20 Feb 2012 16:12:56 -0500 [thread overview]
Message-ID: <4F42B758.7010001@linux.vnet.ibm.com> (raw)
In-Reply-To: <20120220200113.GB18751@redhat.com>
On 02/20/2012 03:01 PM, Michael S. Tsirkin wrote:
> On Wed, Dec 14, 2011 at 08:43:20AM -0500, Stefan Berger wrote:
>> +struct TPMPassthruState {
>> + QemuThread thread;
>> + bool thread_terminate;
>> + bool thread_running;
>> +
>> + TPMPassthruThreadParams tpm_thread_params;
>> +
>> + char tpm_dev[64];
> why not strdup and avoid length limits?
>
>
Fixed.
>> +
>> + /* in case we were to slow and missed the signal, the
>
>
> too slow
Fixed.
> +
>> + qemu_mutex_lock(&tpm_pt->tpm_thread_params.tpm_state->state_lock);
>> + qemu_cond_signal(&tpm_pt->tpm_thread_params.tpm_state->to_tpm_cond);
>> + qemu_mutex_unlock(&tpm_pt->tpm_thread_params.tpm_state->state_lock);
> why lock?
>
Before the other thread calls the function to wait for the condition it
has to grab the lock. Since the signal is not sticky, it could happen
that it had grabbed the lock but wasn't waiting for the condition, yet,
thus missing the signal yet still waiting for it soon after and then it
may end up waiting forever. The lock prevents this. Check example here:
https://computing.llnl.gov/tutorials/pthreads/#ConVarSignal
>> +static size_t tpm_passthrough_realloc_buffer(TPMSizedBuffer *sb)
>> +{
>> + size_t wanted_size = 4096; /* Linux tpm.c buffer size */
> what does the comment mean?
>
It basically means that it allocates the same size of buffer as the
Linux driver does. If the TPM was to send a response (there are no
requests of even close that size) then the Linux driver can accommodate
the size of the response, we can also accomodate it.
>> + * (error response is fine) within one second.
>> + */
>> +static int tpm_passthrough_test_tpmdev(int fd)
>> +{
>> + struct tpm_req_hdr req = {
>> + .tag = cpu_to_be16(TPM_TAG_RQU_COMMAND),
>> + .len = cpu_to_be32(sizeof(req)),
>> + .ordinal = cpu_to_be32(TPM_ORD_GetTicks),
>> + };
>> + struct tpm_resp_hdr *resp;
>> + fd_set readfds;
>> + int n;
>> + struct timeval tv = {
>> + .tv_sec = 1,
>> + .tv_usec = 0,
>> + };
>> + unsigned char buf[1024];
>> +
>> + n = write(fd,&req, sizeof(req));
>> + if (n< 0) {
>> + return errno;
>> + }
>> + if (n != sizeof(req)) {
>> + return EFAULT;
>> + }
>> +
>> + FD_ZERO(&readfds);
>> + FD_SET(fd,&readfds);
>> +
>> + /* wait for a second */
>> + n = select(fd + 1,&readfds, NULL, NULL,&tv);
>> + if (n != 1) {
>> + return errno;
>> + }
>> +
>> + n = read(fd,&buf, sizeof(buf));
> so why read the whole buf? hoiw do we know 1024 is enough?
The size of the response for this particular command can easily be read
into 1024 bytes, even less than 50 would be enough. I could try to come
up with the exact number, but that then probably causes more
questions... 1024 bytes is ample space.
> read the heade then discard the rest
> until empty.
>
I don't follow... ?
FYI: The TPM only lets you read the buffer in one go. If you don't bring
a buffer with enough size when doing the read from /dev/tpm0, the rest
of the result is gone. No 2nd read on the same response buffer.
Even though /dev/tpm0 blocks in the write(), the above select() is there
to prepare for usage with sockets. It doesn't hurt at the moment, but it
also doesn't do the expected wait for 1 second...
Stefan
next prev parent reply other threads:[~2012-02-20 21:13 UTC|newest]
Thread overview: 41+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-12-14 13:43 [Qemu-devel] [PATCH V14 0/7] Qemu Trusted Platform Module (TPM) integration Stefan Berger
2011-12-14 13:43 ` [Qemu-devel] [PATCH V14 1/7] Support for TPM command line options Stefan Berger
2011-12-14 13:43 ` [Qemu-devel] [PATCH V14 2/7] Add TPM (frontend) hardware interface (TPM TIS) to Qemu Stefan Berger
2012-02-20 8:51 ` Michael S. Tsirkin
2012-02-20 15:48 ` Stefan Berger
2012-02-20 19:37 ` Michael S. Tsirkin
2012-02-20 19:58 ` Stefan Berger
2012-02-23 20:47 ` Stefan Berger
2012-02-20 22:02 ` Michael S. Tsirkin
2012-02-21 0:43 ` Stefan Berger
2012-02-21 3:18 ` Michael S. Tsirkin
2012-02-21 11:19 ` Stefan Berger
2012-02-21 12:18 ` Michael S. Tsirkin
2012-02-21 15:05 ` Stefan Berger
2012-02-21 19:58 ` Michael S. Tsirkin
2012-02-21 22:30 ` Stefan Berger
2012-02-21 23:08 ` Michael S. Tsirkin
2012-02-22 0:21 ` Stefan Berger
2012-02-22 4:34 ` Michael S. Tsirkin
2012-02-22 15:03 ` Stefan Berger
2012-02-22 17:55 ` Stefan Berger
2012-03-02 12:02 ` Stefan Berger
2012-03-04 22:59 ` Michael S. Tsirkin
2012-03-05 15:44 ` Stefan Berger
2012-03-05 15:46 ` Stefan Berger
2011-12-14 13:43 ` [Qemu-devel] [PATCH V14 3/7] Add a debug register Stefan Berger
2011-12-14 13:43 ` [Qemu-devel] [PATCH V14 4/7] Build the TPM frontend code Stefan Berger
2011-12-14 13:43 ` [Qemu-devel] [PATCH V14 5/7] Add a TPM Passthrough backend driver implementation Stefan Berger
2012-02-20 19:51 ` Michael S. Tsirkin
2012-02-20 20:25 ` Stefan Berger
2012-02-20 21:15 ` Michael S. Tsirkin
2012-02-21 1:03 ` Stefan Berger
2012-03-21 23:27 ` Anthony Liguori
2012-02-20 20:01 ` Michael S. Tsirkin
2012-02-20 21:12 ` Stefan Berger [this message]
2012-02-20 21:30 ` Michael S. Tsirkin
2012-02-21 0:30 ` Stefan Berger
2011-12-14 13:43 ` [Qemu-devel] [PATCH V14 6/7] Introduce --enable-tpm-passthrough configure option Stefan Berger
2011-12-14 13:43 ` [Qemu-devel] [PATCH V14 7/7] Add fd parameter for TPM passthrough driver Stefan Berger
2012-01-12 16:59 ` [Qemu-devel] [PATCH V14 0/7] Qemu Trusted Platform Module (TPM) integration Paul Moore
2012-01-16 19:21 ` Paul Moore
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4F42B758.7010001@linux.vnet.ibm.com \
--to=stefanb@linux.vnet.ibm.com \
--cc=andreas.niederl@iaik.tugraz.at \
--cc=mst@redhat.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).