linux-api.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Stefan Berger <stefanb-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org>
To: Jarkko Sakkinen
	<jarkko.sakkinen-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>
Cc: tpmdd-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org,
	linux-doc-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	linux-api-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	linux-security-module-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Subject: Re: [v8,09/10] tpm: Initialize TPM and get durations and timeoutsg
Date: Tue, 29 Mar 2016 11:53:14 -0400	[thread overview]
Message-ID: <56FAA4EA.1040309@linux.vnet.ibm.com> (raw)
In-Reply-To: <20160329153143.GA15083-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>

On 03/29/2016 11:31 AM, Jarkko Sakkinen wrote:
> On Tue, Mar 22, 2016 at 06:54:30AM -0400, Stefan Berger wrote:
>> On 03/22/2016 02:34 AM, Jarkko Sakkinen wrote:
>>> On Sun, Mar 13, 2016 at 06:54:39PM -0400, Stefan Berger wrote:
>>>> Add the retrieval of TPM 1.2 durations and timeouts. Since this requires
>>>> the startup of the TPM, do this for TPM 1.2 and TPM 2.
>>>>
>>>> Signed-off-by: Stefan Berger <stefanb-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org>
>>>> CC: linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
>>>> CC: linux-doc-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
>>>> CC: linux-api-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
>>>>
>>>> ---
>>>> drivers/char/tpm/tpm_vtpm_proxy.c | 95 +++++++++++++++++++++++++++++++++++----
>>>>   1 file changed, 86 insertions(+), 9 deletions(-)
>>>>
>>>> diff --git a/drivers/char/tpm/tpm_vtpm_proxy.c b/drivers/char/tpm/tpm_vtpm_proxy.c
>>>> index 2bb2c8c..7fd686b 100644
>>>> --- a/drivers/char/tpm/tpm_vtpm_proxy.c
>>>> +++ b/drivers/char/tpm/tpm_vtpm_proxy.c
>>>> @@ -45,8 +45,11 @@ struct proxy_dev {
>>>>   	size_t req_len;              /* length of queued TPM request */
>>>>   	size_t resp_len;             /* length of queued TPM response */
>>>>   	u8 buffer[TPM_BUFSIZE];      /* request/response buffer */
>>>> +
>>>> +	struct work_struct work;     /* task that retrieves TPM timeouts */
>>>>   };
>>>> +static struct workqueue_struct *workqueue;
>>>>   static void vtpm_proxy_delete_device(struct proxy_dev *proxy_dev);
>>>> @@ -67,6 +70,15 @@ static ssize_t vtpm_proxy_fops_read(struct file *filp, char __user *buf,
>>>>   	size_t len;
>>>>   	int sig, rc;
>>>> +	mutex_lock(&proxy_dev->buf_lock);
>>>> +
>>>> +	if (!(proxy_dev->state & STATE_OPENED_FLAG)) {
>>>> +		mutex_unlock(&proxy_dev->buf_lock);
>>>> +		return -EPIPE;
>>>> +	}
>>>> +
>>>> +	mutex_unlock(&proxy_dev->buf_lock);
>>>> +
>>>>   	sig = wait_event_interruptible(proxy_dev->wq, proxy_dev->req_len != 0);
>>>>   	if (sig)
>>>>   		return -EINTR;
>>> What if STATE_OPENED_FLAG is set after mutex_unlock()?
>> This flag is only set when the file descriptor for the server side is
>> created (vtpm_proxy_fops_open()). After that it can only be cleared
>> (vtpm_fops_undo_open()) due to an error condition, which then indicates to
>> the server side that the file descriptor is now unusable. One error
>> condition can for example be the failure by the TPM emulator to respond to
>> the TPM_Startup with a success in the response.
> You take the lock two times and OPENED flag could change in-between.
>
> Why couldn't you put the call after wait_event_* after taking the lock?

Good point. Actually the test for the flag has to go into the 
wait_event_interruptible test (without mutex?!) and we have to look at 
that flag after the wait_event_interruptible again to check whether no 
more requests are coming due to the OPEN flag not being set anymore as 
result of an error condition.

I can post a v9 with that change. However, the dropping of the priv 
field from the vendor struct  in the other patch series, will again 
require changes either here or in that other series.

     Stefan

  parent reply	other threads:[~2016-03-29 15:53 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <1457909680-14085-1-git-send-email-stefanb@linux.vnet.ibm.com>
     [not found] ` <1457909680-14085-1-git-send-email-stefanb-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org>
2016-03-13 22:54   ` [PATCH v8 08/10] tpm: Proxy driver for supporting multiple emulated TPMs Stefan Berger
2016-03-14 16:26     ` Jarkko Sakkinen
     [not found]     ` <1457909680-14085-9-git-send-email-stefanb-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org>
2016-03-16 12:09       ` Jarkko Sakkinen
     [not found]         ` <20160316120916.GA14820-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
2016-03-16 13:49           ` Stefan Berger
2016-03-16 17:49         ` Jason Gunthorpe
     [not found]           ` <20160316174904.GA6127-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
2016-03-16 20:37             ` Jarkko Sakkinen
2016-03-16 20:42     ` Jarkko Sakkinen
     [not found]       ` <20160316204244.GB23966-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
2016-03-17 17:45         ` Stefan Berger
2016-03-18  8:52           ` Jarkko Sakkinen
     [not found]             ` <20160318085200.GA5604-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
2016-03-18 11:58               ` Stefan Berger
2016-03-18 13:06             ` Jarkko Sakkinen
2016-03-13 22:54   ` [PATCH v8 09/10] tpm: Initialize TPM and get durations and timeouts Stefan Berger
2016-03-22  6:34     ` [v8,09/10] " Jarkko Sakkinen
2016-03-22 10:54       ` Stefan Berger
2016-03-29 15:31         ` [v8,09/10] tpm: Initialize TPM and get durations and timeoutsg Jarkko Sakkinen
     [not found]           ` <20160329153143.GA15083-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
2016-03-29 15:53             ` Stefan Berger [this message]
2016-03-13 22:54   ` [PATCH v8 10/10] tpm: Add documentation for the tpm_vtpm device driver Stefan Berger

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=56FAA4EA.1040309@linux.vnet.ibm.com \
    --to=stefanb-23vcf4htsmix0ybbhkvfkdbpr1lh4cv8@public.gmane.org \
    --cc=jarkko.sakkinen-VuQAYsv1563Yd54FQh9/CA@public.gmane.org \
    --cc=linux-api-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=linux-doc-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=linux-security-module-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=tpmdd-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.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).