From patchwork Mon Feb 8 19:27:07 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Berger X-Patchwork-Id: 8254311 Return-Path: X-Original-To: patchwork-tpmdd-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id EDBB99F1C0 for ; Mon, 8 Feb 2016 19:27:30 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id AD785203DA for ; Mon, 8 Feb 2016 19:27:29 +0000 (UTC) Received: from lists.sourceforge.net (lists.sourceforge.net [216.34.181.88]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 74375203B4 for ; Mon, 8 Feb 2016 19:27:28 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=sfs-ml-2.v29.ch3.sourceforge.com) by sfs-ml-2.v29.ch3.sourceforge.com with esmtp (Exim 4.76) (envelope-from ) id 1aSrT5-0001qF-4r; Mon, 08 Feb 2016 19:27:27 +0000 Received: from sog-mx-2.v43.ch3.sourceforge.com ([172.29.43.192] helo=mx.sourceforge.net) by sfs-ml-2.v29.ch3.sourceforge.com with esmtp (Exim 4.76) (envelope-from ) id 1aSrT4-0001q1-3U for tpmdd-devel@lists.sourceforge.net; Mon, 08 Feb 2016 19:27:26 +0000 X-ACL-Warn: Received: from e35.co.us.ibm.com ([32.97.110.153]) by sog-mx-2.v43.ch3.sourceforge.com with esmtps (TLSv1:AES256-SHA:256) (Exim 4.76) id 1aSrT3-0005AK-2z for tpmdd-devel@lists.sourceforge.net; Mon, 08 Feb 2016 19:27:26 +0000 Received: from localhost by e35.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Mon, 8 Feb 2016 12:27:19 -0700 Received: from d03dlp01.boulder.ibm.com (9.17.202.177) by e35.co.us.ibm.com (192.168.1.135) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Mon, 8 Feb 2016 12:27:16 -0700 X-IBM-Helo: d03dlp01.boulder.ibm.com X-IBM-MailFrom: stefanb@linux.vnet.ibm.com X-IBM-RcptTo: tpmdd-devel@lists.sourceforge.net Received: from b03cxnp08027.gho.boulder.ibm.com (b03cxnp08027.gho.boulder.ibm.com [9.17.130.19]) by d03dlp01.boulder.ibm.com (Postfix) with ESMTP id 24B931FF0041 for ; Mon, 8 Feb 2016 12:15:26 -0700 (MST) Received: from d03av04.boulder.ibm.com (d03av04.boulder.ibm.com [9.17.195.170]) by b03cxnp08027.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id u18JRG2t26214492 for ; Mon, 8 Feb 2016 12:27:16 -0700 Received: from d03av04.boulder.ibm.com (loopback [127.0.0.1]) by d03av04.boulder.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id u18JRFbR016200 for ; Mon, 8 Feb 2016 12:27:16 -0700 Received: from dhcp-9-2-140-43.watson.ibm.com (dhcp-9-2-140-28.watson.ibm.com [9.2.140.28]) by d03av04.boulder.ibm.com (8.14.4/8.14.4/NCO v10.0 AVin) with ESMTP id u18JRBMB015717; Mon, 8 Feb 2016 12:27:14 -0700 From: Stefan Berger To: tpmdd-devel@lists.sourceforge.net Date: Mon, 8 Feb 2016 14:27:07 -0500 Message-Id: <1454959628-30582-5-git-send-email-stefanb@linux.vnet.ibm.com> X-Mailer: git-send-email 2.4.3 In-Reply-To: <1454959628-30582-1-git-send-email-stefanb@linux.vnet.ibm.com> References: <1454959628-30582-1-git-send-email-stefanb@linux.vnet.ibm.com> X-TM-AS-MML: disable X-Content-Scanned: Fidelis XPS MAILER x-cbid: 16020819-0013-0000-0000-00001CA643FA X-Spam-Score: -0.2 (/) X-Headers-End: 1aSrT3-0005AK-2z Cc: dhowells@redhat.com, dwmw2@infradead.org Subject: [tpmdd-devel] [PATCH v5 4/5] Initialize TPM and get durations and timeouts X-BeenThere: tpmdd-devel@lists.sourceforge.net X-Mailman-Version: 2.1.9 Precedence: list List-Id: Tpm Device Driver maintainance List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: tpmdd-devel-bounces@lists.sourceforge.net X-Spam-Status: No, score=-7.2 required=5.0 tests=BAYES_00, HK_RANDOM_ENVFROM, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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. To not allow to interleave with commands from user space, so send the TPM_Startup as the first command. The timeouts can then be gotten at any later time, even interleaved with commands from user space. Signed-off-by: Stefan Berger --- drivers/char/tpm/tpm-vtpm.c | 58 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/drivers/char/tpm/tpm-vtpm.c b/drivers/char/tpm/tpm-vtpm.c index 6ee1e44..d9fd797 100644 --- a/drivers/char/tpm/tpm-vtpm.c +++ b/drivers/char/tpm/tpm-vtpm.c @@ -41,6 +41,7 @@ struct vtpm_dev { long state; #define STATE_OPENED_BIT 0 +#define STATE_INIT_VTPM 1 spinlock_t buf_lock; /* lock for buffers */ @@ -52,6 +53,8 @@ struct vtpm_dev { size_t resp_len; /* length of queued TPM response */ u8 resp_buf[TPM_BUFSIZE]; /* response buffer */ + struct work_struct work; /* task that retrieves TPM timeouts */ + struct list_head list; }; @@ -292,6 +295,9 @@ static int vtpm_tpm_op_send(struct tpm_chip *chip, u8 *buf, size_t count) spin_unlock(&vtpm_dev->buf_lock); + /* sync for first startup command */ + set_bit(STATE_INIT_VTPM, &vtpm_dev->state); + wake_up_interruptible(&vtpm_dev->wq); return rc; @@ -323,6 +329,52 @@ 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); + + if (vtpm_dev->flags & VTPM_FLAG_TPM2) + tpm2_startup(vtpm_dev->chip, TPM2_SU_CLEAR); + else { + /* we must send TPM_Startup() first */ + tpm_startup(vtpm_dev->chip, TPM_ST_CLEAR); + tpm_get_timeouts(vtpm_dev->chip); + } +} + +/* + * vtpm_dev_start_work: Schedule the work for TPM 1.2 & 2 initialization + */ +static int vtpm_dev_start_work(struct vtpm_dev *vtpm_dev) +{ + int sig; + + INIT_WORK(&vtpm_dev->work, vtpm_dev_work); + schedule_work(&vtpm_dev->work); + + /* make sure we send the 1st command before user space can */ + sig = wait_event_interruptible(vtpm_dev->wq, + test_bit(STATE_INIT_VTPM, &vtpm_dev->state)); + if (sig) { + cancel_work_sync(&vtpm_dev->work); + return -EINTR; + } + return 0; +} + +/* + * vtpm_dev_stop_work: prevent the scheduled work from running + */ +static void vtpm_dev_stop_work(struct vtpm_dev *vtpm_dev) +{ + cancel_work_sync(&vtpm_dev->work); +} + +/* * Code related to creation and deletion of device pairs */ static void vtpm_dev_release(struct device *dev) @@ -449,6 +501,10 @@ static struct file *vtpm_create_device_pair( } vtpm_dev->chip = chip; + rc = vtpm_dev_start_work(vtpm_dev); + if (rc) + goto err_vtpm_fput; + vtpm_new_pair->fd = fd; vtpm_new_pair->major = MAJOR(vtpm_dev->chip->dev.devt); vtpm_new_pair->minor = MINOR(vtpm_dev->chip->dev.devt); @@ -476,6 +532,8 @@ err_delete_vtpm_dev: */ static void vtpm_delete_device_pair(struct vtpm_dev *vtpm_dev) { + vtpm_dev_stop_work(vtpm_dev); + spin_lock(&driver_lock); list_del_rcu(&vtpm_dev->list); spin_unlock(&driver_lock);