All of lore.kernel.org
 help / color / mirror / Atom feed
From: Guilherme Magalhaes <guilherme.magalhaes@hpe.com>
To: linux-integrity@vger.kernel.org
Cc: Guilherme Magalhaes <guilherme.magalhaes@hpe.com>
Subject: [PATCH] tpm: adjust command response sleep time for vTPM
Date: Tue,  3 Oct 2017 17:46:40 -0300	[thread overview]
Message-ID: <20171003204640.62236-1-guilherme.magalhaes@hpe.com> (raw)

Once vTPM is actually a software, it is able to respond the commands much
quicker than physical TPMs. What we propose is to adjust the response
polling time to a usec value when the chip is detected as a vTPM.
With this change, the kernel TPM interface identifies whether the chip is
vTPM and on this case sets the polling sleep time to an optimized value.

The performance result was 12x improvement when comparing PCR extends
using vTPM with the current sleep time and with the adjusted sleep time.
---
 drivers/char/tpm/tpm-interface.c | 6 +++++-
 drivers/char/tpm/tpm.h           | 2 ++
 2 files changed, 7 insertions(+), 1 deletion(-)

diff --git a/drivers/char/tpm/tpm-interface.c b/drivers/char/tpm/tpm-interface.c
index 1d6729be4cd6..d213a3d4b305 100644
--- a/drivers/char/tpm/tpm-interface.c
+++ b/drivers/char/tpm/tpm-interface.c
@@ -455,7 +455,11 @@ ssize_t tpm_transmit(struct tpm_chip *chip, struct tpm_space *space,
 			goto out;
 		}
 
-		tpm_msleep(TPM_TIMEOUT);
+		if (chip->flags & TPM_CHIP_FLAG_VIRTUAL)
+			usleep_range(TPM_TIMEOUT_VTPM_US, TPM_TIMEOUT_VTPM_RANGE_US);
+		else
+			tpm_msleep(TPM_TIMEOUT);
+
 		rmb();
 	} while (time_before(jiffies, stop));
 
diff --git a/drivers/char/tpm/tpm.h b/drivers/char/tpm/tpm.h
index 2d5466a72e40..02d2dd761543 100644
--- a/drivers/char/tpm/tpm.h
+++ b/drivers/char/tpm/tpm.h
@@ -50,6 +50,8 @@ enum tpm_const {
 
 enum tpm_timeout {
 	TPM_TIMEOUT = 5,	/* msecs */
+	TPM_TIMEOUT_VTPM_US = 1,	/* usecs */
+	TPM_TIMEOUT_VTPM_RANGE_US = 5,	/* usecs */
 	TPM_TIMEOUT_RETRY = 100, /* msecs */
 	TPM_TIMEOUT_RANGE_US = 300	/* usecs */
 };
-- 
2.11.0

             reply	other threads:[~2017-10-03 20:48 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-10-03 20:46 Guilherme Magalhaes [this message]
2017-10-03 20:57 ` [PATCH] tpm: adjust command response sleep time for vTPM Magalhaes, Guilherme (Brazil R&D-CL)
2017-10-20  6:56 ` Jarkko Sakkinen

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=20171003204640.62236-1-guilherme.magalhaes@hpe.com \
    --to=guilherme.magalhaes@hpe.com \
    --cc=linux-integrity@vger.kernel.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 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.