From: Stefan Berger <stefanb-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org>
To: tpmdd-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org
Cc: linux-doc-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
linux-api-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Subject: [PATCH v6 09/11] tpm: Initialize TPM and get durations and timeouts
Date: Wed, 9 Mar 2016 12:39:28 -0500 [thread overview]
Message-ID: <1457545170-30120-10-git-send-email-stefanb@linux.vnet.ibm.com> (raw)
In-Reply-To: <1457545170-30120-1-git-send-email-stefanb-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org>
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.c | 94 ++++++++++++++++++++++++++++++++++++++++-----
1 file changed, 85 insertions(+), 9 deletions(-)
diff --git a/drivers/char/tpm/tpm_vtpm.c b/drivers/char/tpm/tpm_vtpm.c
index 0da311b..4f75248 100644
--- a/drivers/char/tpm/tpm_vtpm.c
+++ b/drivers/char/tpm/tpm_vtpm.c
@@ -45,8 +45,11 @@ struct vtpm_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_delete_device(struct vtpm_dev *vtpm_dev);
@@ -67,6 +70,15 @@ static ssize_t vtpm_fops_read(struct file *filp, char __user *buf,
size_t len;
int sig, rc;
+ mutex_lock(&vtpm_dev->buf_lock);
+
+ if (!(vtpm_dev->state & STATE_OPENED_FLAG)) {
+ mutex_unlock(&vtpm_dev->buf_lock);
+ return -EPIPE;
+ }
+
+ mutex_unlock(&vtpm_dev->buf_lock);
+
sig = wait_event_interruptible(vtpm_dev->wq, vtpm_dev->req_len != 0);
if (sig)
return -EINTR;
@@ -110,6 +122,11 @@ static ssize_t vtpm_fops_write(struct file *filp, const char __user *buf,
mutex_lock(&vtpm_dev->buf_lock);
+ if (!(vtpm_dev->state & STATE_OPENED_FLAG)) {
+ mutex_unlock(&vtpm_dev->buf_lock);
+ return -EPIPE;
+ }
+
if (count > sizeof(vtpm_dev->buffer) ||
!(vtpm_dev->state & STATE_WAIT_RESPONSE_FLAG)) {
mutex_unlock(&vtpm_dev->buf_lock);
@@ -154,6 +171,9 @@ static unsigned int vtpm_fops_poll(struct file *filp, poll_table *wait)
if (vtpm_dev->req_len)
ret |= POLLIN | POLLRDNORM;
+ if (!(vtpm_dev->state & STATE_OPENED_FLAG))
+ ret |= POLLHUP;
+
mutex_unlock(&vtpm_dev->buf_lock);
return ret;
@@ -341,6 +361,54 @@ static const struct tpm_class_ops vtpm_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_dev_work(struct work_struct *work)
+{
+ struct vtpm_dev *vtpm_dev = container_of(work, struct vtpm_dev, work);
+ int rc;
+
+ if (vtpm_dev->flags & VTPM_FLAG_TPM2)
+ rc = tpm2_startup(vtpm_dev->chip, TPM2_SU_CLEAR);
+ else
+ rc = tpm_get_timeouts(vtpm_dev->chip);
+
+ if (rc)
+ goto err;
+
+ rc = tpm_chip_register(vtpm_dev->chip);
+ if (rc)
+ goto err;
+
+ return;
+
+err:
+ vtpm_fops_undo_open(vtpm_dev);
+}
+
+/*
+ * vtpm_dev_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_dev_work_stop(struct vtpm_dev *vtpm_dev)
+{
+ vtpm_fops_undo_open(vtpm_dev);
+ flush_work(&vtpm_dev->work);
+}
+
+/*
+ * vtpm_dev_work_start: Schedule the work for TPM 1.2 & 2 initialization
+ */
+static inline void vtpm_dev_work_start(struct vtpm_dev *vtpm_dev)
+{
+ queue_work(workqueue, &vtpm_dev->work);
+}
+
+/*
* Code related to creation and deletion of device pairs
*/
static struct vtpm_dev *vtpm_create_vtpm_dev(void)
@@ -355,6 +423,7 @@ static struct vtpm_dev *vtpm_create_vtpm_dev(void)
init_waitqueue_head(&vtpm_dev->wq);
mutex_init(&vtpm_dev->buf_lock);
+ INIT_WORK(&vtpm_dev->work, vtpm_dev_work);
chip = tpm_chip_alloc(NULL, &vtpm_tpm_ops);
if (IS_ERR(chip)) {
@@ -424,9 +493,7 @@ static struct file *vtpm_create_device(
if (vtpm_dev->flags & VTPM_FLAG_TPM2)
vtpm_dev->chip->flags |= TPM_CHIP_FLAG_TPM2;
- rc = tpm_chip_register(vtpm_dev->chip);
- if (rc)
- goto err_vtpm_fput;
+ vtpm_dev_work_start(vtpm_dev);
vtpm_new_dev->fd = fd;
vtpm_new_dev->major = MAJOR(vtpm_dev->chip->dev.devt);
@@ -435,12 +502,6 @@ static struct file *vtpm_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);
@@ -455,6 +516,8 @@ err_delete_vtpm_dev:
*/
static void vtpm_delete_device(struct vtpm_dev *vtpm_dev)
{
+ vtpm_dev_work_stop(vtpm_dev);
+
tpm_chip_unregister(vtpm_dev->chip);
vtpm_fops_undo_open(vtpm_dev);
@@ -549,11 +612,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();
}
--
2.4.3
------------------------------------------------------------------------------
Transform Data into Opportunity.
Accelerate data analysis in your applications with
Intel Data Analytics Acceleration Library.
Click to learn more.
http://pubads.g.doubleclick.net/gampad/clk?id=278785111&iu=/4140
next prev parent reply other threads:[~2016-03-09 17:39 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-03-09 17:39 [PATCH v6 00/11] Multi-instance vTPM driver Stefan Berger
[not found] ` <1457545170-30120-1-git-send-email-stefanb-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org>
2016-03-09 17:39 ` [PATCH v6 01/11] tpm: Get rid of chip->pdev Stefan Berger
2016-03-09 17:39 ` [PATCH v6 02/11] tpm: Get rid of devname Stefan Berger
2016-03-09 17:39 ` [PATCH v6 03/11] tpm: Provide strong locking for device removal Stefan Berger
2016-03-09 17:39 ` [PATCH v6 04/11] tpm: Get rid of module locking Stefan Berger
2016-03-09 17:39 ` [PATCH v6 05/11] tpm: Split out the devm stuff from tpmm_chip_alloc Stefan Berger
2016-03-09 17:39 ` [PATCH v6 06/11] tpm: Replace device number bitmap with IDR Stefan Berger
[not found] ` <1457545170-30120-7-git-send-email-stefanb-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org>
2016-03-10 13:21 ` Jarkko Sakkinen
[not found] ` <20160310132156.GA16320-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
2016-03-10 16:26 ` Stefan Berger
[not found] ` <201603101622.u2AGMCv3031274@d01av05.pok.ibm.com>
[not found] ` <201603101622.u2AGMCv3031274-8DuMPbUlb4HImUpY6SP3GEEOCMrvLtNR@public.gmane.org>
2016-03-10 16:40 ` Jarkko Sakkinen
2016-03-09 17:39 ` [PATCH v6 07/11] tpm: Introduce TPM_CHIP_FLAG_VIRTUAL Stefan Berger
2016-03-09 17:39 ` [PATCH v6 08/11] tpm: Driver for supporting multiple emulated TPMs Stefan Berger
2016-03-10 14:15 ` Jarkko Sakkinen
[not found] ` <1457545170-30120-9-git-send-email-stefanb-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org>
2016-03-09 18:01 ` Andy Lutomirski
[not found] ` <CALCETrXDfHRdFnqK15o1yD8106sn4e6Susr9j7=GGi4sb-p0qQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2016-03-09 18:44 ` Stefan Berger
2016-03-10 16:39 ` Jarkko Sakkinen
[not found] ` <20160310163915.GA4863-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
2016-03-10 17:30 ` Stefan Berger
2016-03-11 9:50 ` Jarkko Sakkinen
2016-03-10 17:32 ` Stefan Berger
[not found] ` <56E1AF9F.3010409-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org>
2016-03-11 10:20 ` Jarkko Sakkinen
2016-03-10 22:12 ` Jason Gunthorpe
2016-03-09 17:39 ` Stefan Berger [this message]
2016-03-09 17:39 ` [PATCH v6 10/11] tpm: Add documentation for the tpm_vtpm device driver Stefan Berger
2016-03-09 17:39 ` [PATCH v6 11/11] A test program for vTPM device creation Stefan Berger
[not found] ` <1457545170-30120-12-git-send-email-stefanb-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org>
2016-03-10 20:57 ` [PATCH v6 11/11] A test program for vTPM devicecreation Stefan Berger
[not found] ` <201603102058.u2AKw7Ie013400@d01av04.pok.ibm.com>
[not found] ` <201603102058.u2AKw7Ie013400-YREtIfBy6dDImUpY6SP3GEEOCMrvLtNR@public.gmane.org>
2016-03-11 10:30 ` Jarkko Sakkinen
[not found] ` <20160311103001.GA13368-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
2016-03-11 13:16 ` 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=1457545170-30120-10-git-send-email-stefanb@linux.vnet.ibm.com \
--to=stefanb-23vcf4htsmix0ybbhkvfkdbpr1lh4cv8@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=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).