From: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
To: Stefan Berger <stefanb@linux.vnet.ibm.com>
Cc: tpmdd-devel@lists.sourceforge.net, linux-doc@vger.kernel.org,
linux-api@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-security-module@vger.kernel.org
Subject: Re: [v8,09/10] tpm: Initialize TPM and get durations and timeouts
Date: Tue, 22 Mar 2016 08:34:59 +0200 [thread overview]
Message-ID: <20160322063459.GA9420@intel.com> (raw)
In-Reply-To: <1457909680-14085-10-git-send-email-stefanb@linux.vnet.ibm.com>
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@linux.vnet.ibm.com>
> CC: linux-kernel@vger.kernel.org
> CC: linux-doc@vger.kernel.org
> CC: linux-api@vger.kernel.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()?
Is there some scenario where STATE_OPENED_FLAG would evaluate false
at this point?
Actually I couldn't find a scenario where this check would be needed
because:
* In vtpm_proxy_work() vtpm_proxy_fops_undo_open() is called after
sending TPM commands.
* vtpm_proxy_delete_device() calls vtpm_proxy_work_stop() as its
first statement.
Am I ignoring something?
/Jarkko
> @@ -110,6 +122,11 @@ static ssize_t vtpm_proxy_fops_write(struct file *filp, const char __user *buf,
>
> mutex_lock(&proxy_dev->buf_lock);
>
> + if (!(proxy_dev->state & STATE_OPENED_FLAG)) {
> + mutex_unlock(&proxy_dev->buf_lock);
> + return -EPIPE;
> + }
> +
> if (count > sizeof(proxy_dev->buffer) ||
> !(proxy_dev->state & STATE_WAIT_RESPONSE_FLAG)) {
> mutex_unlock(&proxy_dev->buf_lock);
> @@ -154,6 +171,9 @@ static unsigned int vtpm_proxy_fops_poll(struct file *filp, poll_table *wait)
> if (proxy_dev->req_len)
> ret |= POLLIN | POLLRDNORM;
>
> + if (!(proxy_dev->state & STATE_OPENED_FLAG))
> + ret |= POLLHUP;
> +
> mutex_unlock(&proxy_dev->buf_lock);
>
> return ret;
> @@ -341,6 +361,55 @@ static const struct tpm_class_ops vtpm_proxy_tpm_ops = {
> };
>
> /*
> + * Code related to the startup of the TPM 2 and startup of TPM 1.2 +
> + * retrieval of timeouts and durations.
> + */
> +
> +static void vtpm_proxy_work(struct work_struct *work)
> +{
> + struct proxy_dev *proxy_dev = container_of(work, struct proxy_dev,
> + work);
> + int rc;
> +
> + if (proxy_dev->flags & VTPM_PROXY_FLAG_TPM2)
> + rc = tpm2_startup(proxy_dev->chip, TPM2_SU_CLEAR);
> + else
> + rc = tpm_get_timeouts(proxy_dev->chip);
> +
> + if (rc)
> + goto err;
> +
> + rc = tpm_chip_register(proxy_dev->chip);
> + if (rc)
> + goto err;
> +
> + return;
> +
> +err:
> + vtpm_proxy_fops_undo_open(proxy_dev);
> +}
> +
> +/*
> + * vtpm_proxy_work_stop: make sure the work has finished
> + *
> + * This function is useful when user space closed the fd
> + * while the driver still determines timeouts.
> + */
> +static void vtpm_proxy_work_stop(struct proxy_dev *proxy_dev)
> +{
> + vtpm_proxy_fops_undo_open(proxy_dev);
> + flush_work(&proxy_dev->work);
> +}
> +
> +/*
> + * vtpm_proxy_work_start: Schedule the work for TPM 1.2 & 2 initialization
> + */
> +static inline void vtpm_proxy_work_start(struct proxy_dev *proxy_dev)
> +{
> + queue_work(workqueue, &proxy_dev->work);
> +}
> +
> +/*
> * Code related to creation and deletion of device pairs
> */
> static struct proxy_dev *vtpm_proxy_create_proxy_dev(void)
> @@ -355,6 +424,7 @@ static struct proxy_dev *vtpm_proxy_create_proxy_dev(void)
>
> init_waitqueue_head(&proxy_dev->wq);
> mutex_init(&proxy_dev->buf_lock);
> + INIT_WORK(&proxy_dev->work, vtpm_proxy_work);
>
> chip = tpm_chip_alloc(NULL, &vtpm_proxy_tpm_ops);
> if (IS_ERR(chip)) {
> @@ -425,9 +495,7 @@ static struct file *vtpm_proxy_create_device(
> if (proxy_dev->flags & VTPM_PROXY_FLAG_TPM2)
> proxy_dev->chip->flags |= TPM_CHIP_FLAG_TPM2;
>
> - rc = tpm_chip_register(proxy_dev->chip);
> - if (rc)
> - goto err_vtpm_fput;
> + vtpm_proxy_work_start(proxy_dev);
>
> vtpm_new_dev->fd = fd;
> vtpm_new_dev->major = MAJOR(proxy_dev->chip->dev.devt);
> @@ -436,12 +504,6 @@ static struct file *vtpm_proxy_create_device(
>
> return file;
>
> -err_vtpm_fput:
> - put_unused_fd(fd);
> - fput(file);
> -
> - return ERR_PTR(rc);
> -
> err_put_unused_fd:
> put_unused_fd(fd);
>
> @@ -456,6 +518,8 @@ err_delete_proxy_dev:
> */
> static void vtpm_proxy_delete_device(struct proxy_dev *proxy_dev)
> {
> + vtpm_proxy_work_stop(proxy_dev);
> +
> /*
> * A client may hold the 'ops' lock, so let it know that the server
> * side shuts down before we try to grab the 'ops' lock when
> @@ -555,11 +619,24 @@ static int __init vtpm_module_init(void)
> return rc;
> }
>
> + workqueue = create_workqueue("tpm-vtpm");
> + if (!workqueue) {
> + pr_err("couldn't create workqueue\n");
> + rc = -ENOMEM;
> + goto err_vtpmx_cleanup;
> + }
> +
> return 0;
> +
> +err_vtpmx_cleanup:
> + vtpmx_cleanup();
> +
> + return rc;
> }
>
> static void __exit vtpm_module_exit(void)
> {
> + destroy_workqueue(workqueue);
> vtpmx_cleanup();
> }
>
next prev parent reply other threads:[~2016-03-22 6:34 UTC|newest]
Thread overview: 44+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-03-13 22:54 [PATCH v8 00/10] Multi-instance vTPM proxy driver Stefan Berger
2016-03-13 22:54 ` Stefan Berger
[not found] ` <1457909680-14085-1-git-send-email-stefanb-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org>
2016-03-13 22:54 ` [PATCH v8 01/10] tpm: Get rid of chip->pdev Stefan Berger
2016-03-13 22:54 ` Stefan Berger
2016-03-13 22:54 ` [PATCH v8 02/10] tpm: Get rid of devname Stefan Berger
2016-03-13 22:54 ` Stefan Berger
2016-03-13 22:54 ` [PATCH v8 03/10] tpm: Provide strong locking for device removal Stefan Berger
2016-03-13 22:54 ` Stefan Berger
2016-03-13 22:54 ` [PATCH v8 04/10] tpm: Get rid of module locking Stefan Berger
2016-03-13 22:54 ` Stefan Berger
2016-03-13 22:54 ` [PATCH v8 05/10] tpm: Split out the devm stuff from tpmm_chip_alloc Stefan Berger
2016-03-13 22:54 ` Stefan Berger
2016-03-13 22:54 ` [PATCH v8 06/10] tpm: Replace device number bitmap with IDR Stefan Berger
2016-03-13 22:54 ` Stefan Berger
2016-03-15 5:58 ` Jarkko Sakkinen
2016-03-13 22:54 ` [PATCH v8 07/10] tpm: Introduce TPM_CHIP_FLAG_VIRTUAL Stefan Berger
2016-03-13 22:54 ` Stefan Berger
2016-03-13 22:54 ` [PATCH v8 08/10] tpm: Proxy driver for supporting multiple emulated TPMs Stefan Berger
2016-03-13 22:54 ` 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
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 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: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-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-13 22:54 ` Stefan Berger
2016-03-22 6:34 ` Jarkko Sakkinen [this message]
2016-03-22 10:54 ` [v8,09/10] " 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
2016-03-29 15:53 ` Stefan Berger
2016-03-13 22:54 ` [PATCH v8 10/10] tpm: Add documentation for the tpm_vtpm device driver Stefan Berger
2016-03-13 22:54 ` Stefan Berger
2016-03-29 16:24 ` [PATCH v8 00/10] Multi-instance vTPM proxy driver Jarkko Sakkinen
[not found] ` <20160329162433.GB24833-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
2016-03-29 16:31 ` 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=20160322063459.GA9420@intel.com \
--to=jarkko.sakkinen@linux.intel.com \
--cc=linux-api@vger.kernel.org \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-security-module@vger.kernel.org \
--cc=stefanb@linux.vnet.ibm.com \
--cc=tpmdd-devel@lists.sourceforge.net \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.