From: Nayna Jain <nayna@linux.vnet.ibm.com> To: linux-integrity@vger.kernel.org Cc: zohar@linux.vnet.ibm.com, linux-security-module@vger.kernel.org, linux-kernel@vger.kernel.org, peterhuewe@gmx.de, jarkko.sakkinen@linux.intel.com, tpmdd@selhorst.net, jgunthorpe@obsidianresearch.com, patrickc@us.ibm.com, Nayna Jain <nayna@linux.vnet.ibm.com> Subject: [PATCH v3 2/5] tpm: ignore burstcount to improve tpm_tis send() performance Date: Wed, 4 Oct 2017 06:29:21 -0400 [thread overview] Message-ID: <20171004102924.12355-3-nayna@linux.vnet.ibm.com> (raw) In-Reply-To: <20171004102924.12355-1-nayna@linux.vnet.ibm.com> The TPM burstcount status indicates the number of bytes that can be sent to the TPM without causing bus wait states. Effectively, it is the number of empty bytes in the command FIFO. Further, some TPMs have a static burstcount, when the value remains zero until the entire FIFO is empty. This patch optimizes the tpm_tis_send_data() function by checking the burstcount only once. And if the burstcount is valid, it writes all the bytes at once, permitting wait states. The performance of a 34 byte extend on a TPM 1.2 with an 8 byte burstcount improved from 41msec to 14msec. After this change, performance on a TPM 1.2 with an 8 byte burstcount for 1000 extends improved from ~41sec to ~14sec. Suggested-by: Ken Goldman <kgold@linux.vnet.ibm.com> in conjunction with the TPM Device Driver work group. Signed-off-by: Nayna Jain <nayna@linux.vnet.ibm.com> Acked-by: Mimi Zohar <zohar@linux.vnet.ibm.com> --- drivers/char/tpm/tpm_tis_core.c | 42 ++++++++++++++++------------------------- 1 file changed, 16 insertions(+), 26 deletions(-) diff --git a/drivers/char/tpm/tpm_tis_core.c b/drivers/char/tpm/tpm_tis_core.c index b33126a35694..8da425e1783f 100644 --- a/drivers/char/tpm/tpm_tis_core.c +++ b/drivers/char/tpm/tpm_tis_core.c @@ -316,7 +316,6 @@ static int tpm_tis_send_data(struct tpm_chip *chip, u8 *buf, size_t len) { struct tpm_tis_data *priv = dev_get_drvdata(&chip->dev); int rc, status, burstcnt; - size_t count = 0; bool itpm = priv->flags & TPM_TIS_ITPM_WORKAROUND; status = tpm_tis_status(chip); @@ -330,35 +329,26 @@ static int tpm_tis_send_data(struct tpm_chip *chip, u8 *buf, size_t len) } } - while (count < len - 1) { - burstcnt = get_burstcount(chip); - if (burstcnt < 0) { - dev_err(&chip->dev, "Unable to read burstcount\n"); - rc = burstcnt; - goto out_err; - } - burstcnt = min_t(int, burstcnt, len - count - 1); - rc = tpm_tis_write_bytes(priv, TPM_DATA_FIFO(priv->locality), - burstcnt, buf + count); - if (rc < 0) - goto out_err; + /* + * Get the initial burstcount to ensure TPM is ready to + * accept data. + */ + burstcnt = get_burstcount(chip); + if (burstcnt < 0) { + dev_err(&chip->dev, "Unable to read burstcount\n"); + rc = burstcnt; + goto out_err; + } - count += burstcnt; + burstcnt = len - 1; - if (wait_for_tpm_stat(chip, TPM_STS_VALID, chip->timeout_c, - &priv->int_queue, false) < 0) { - rc = -ETIME; - goto out_err; - } - status = tpm_tis_status(chip); - if (!itpm && (status & TPM_STS_DATA_EXPECT) == 0) { - rc = -EIO; - goto out_err; - } - } + rc = tpm_tis_write_bytes(priv, TPM_DATA_FIFO(priv->locality), + burstcnt, buf); + if (rc < 0) + goto out_err; /* write last byte */ - rc = tpm_tis_write8(priv, TPM_DATA_FIFO(priv->locality), buf[count]); + rc = tpm_tis_write8(priv, TPM_DATA_FIFO(priv->locality), buf[len-1]); if (rc < 0) goto out_err; -- 2.13.3
WARNING: multiple messages have this Message-ID (diff)
From: nayna@linux.vnet.ibm.com (Nayna Jain) To: linux-security-module@vger.kernel.org Subject: [PATCH v3 2/5] tpm: ignore burstcount to improve tpm_tis send() performance Date: Wed, 4 Oct 2017 06:29:21 -0400 [thread overview] Message-ID: <20171004102924.12355-3-nayna@linux.vnet.ibm.com> (raw) In-Reply-To: <20171004102924.12355-1-nayna@linux.vnet.ibm.com> The TPM burstcount status indicates the number of bytes that can be sent to the TPM without causing bus wait states. Effectively, it is the number of empty bytes in the command FIFO. Further, some TPMs have a static burstcount, when the value remains zero until the entire FIFO is empty. This patch optimizes the tpm_tis_send_data() function by checking the burstcount only once. And if the burstcount is valid, it writes all the bytes at once, permitting wait states. The performance of a 34 byte extend on a TPM 1.2 with an 8 byte burstcount improved from 41msec to 14msec. After this change, performance on a TPM 1.2 with an 8 byte burstcount for 1000 extends improved from ~41sec to ~14sec. Suggested-by: Ken Goldman <kgold@linux.vnet.ibm.com> in conjunction with the TPM Device Driver work group. Signed-off-by: Nayna Jain <nayna@linux.vnet.ibm.com> Acked-by: Mimi Zohar <zohar@linux.vnet.ibm.com> --- drivers/char/tpm/tpm_tis_core.c | 42 ++++++++++++++++------------------------- 1 file changed, 16 insertions(+), 26 deletions(-) diff --git a/drivers/char/tpm/tpm_tis_core.c b/drivers/char/tpm/tpm_tis_core.c index b33126a35694..8da425e1783f 100644 --- a/drivers/char/tpm/tpm_tis_core.c +++ b/drivers/char/tpm/tpm_tis_core.c @@ -316,7 +316,6 @@ static int tpm_tis_send_data(struct tpm_chip *chip, u8 *buf, size_t len) { struct tpm_tis_data *priv = dev_get_drvdata(&chip->dev); int rc, status, burstcnt; - size_t count = 0; bool itpm = priv->flags & TPM_TIS_ITPM_WORKAROUND; status = tpm_tis_status(chip); @@ -330,35 +329,26 @@ static int tpm_tis_send_data(struct tpm_chip *chip, u8 *buf, size_t len) } } - while (count < len - 1) { - burstcnt = get_burstcount(chip); - if (burstcnt < 0) { - dev_err(&chip->dev, "Unable to read burstcount\n"); - rc = burstcnt; - goto out_err; - } - burstcnt = min_t(int, burstcnt, len - count - 1); - rc = tpm_tis_write_bytes(priv, TPM_DATA_FIFO(priv->locality), - burstcnt, buf + count); - if (rc < 0) - goto out_err; + /* + * Get the initial burstcount to ensure TPM is ready to + * accept data. + */ + burstcnt = get_burstcount(chip); + if (burstcnt < 0) { + dev_err(&chip->dev, "Unable to read burstcount\n"); + rc = burstcnt; + goto out_err; + } - count += burstcnt; + burstcnt = len - 1; - if (wait_for_tpm_stat(chip, TPM_STS_VALID, chip->timeout_c, - &priv->int_queue, false) < 0) { - rc = -ETIME; - goto out_err; - } - status = tpm_tis_status(chip); - if (!itpm && (status & TPM_STS_DATA_EXPECT) == 0) { - rc = -EIO; - goto out_err; - } - } + rc = tpm_tis_write_bytes(priv, TPM_DATA_FIFO(priv->locality), + burstcnt, buf); + if (rc < 0) + goto out_err; /* write last byte */ - rc = tpm_tis_write8(priv, TPM_DATA_FIFO(priv->locality), buf[count]); + rc = tpm_tis_write8(priv, TPM_DATA_FIFO(priv->locality), buf[len-1]); if (rc < 0) goto out_err; -- 2.13.3 -- To unsubscribe from this list: send the line "unsubscribe linux-security-module" in the body of a message to majordomo at vger.kernel.org More majordomo info@ http://vger.kernel.org/majordomo-info.html
next prev parent reply other threads:[~2017-10-04 10:29 UTC|newest] Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top 2017-10-04 10:29 [PATCH v3 0/4] additional TPM performance improvements Nayna Jain 2017-10-04 10:29 ` Nayna Jain 2017-10-04 10:29 ` [PATCH v3 1/5] tpm: move wait_for_tpm_stat() to respective driver files Nayna Jain 2017-10-04 10:29 ` Nayna Jain 2017-10-10 14:57 ` Jarkko Sakkinen 2017-10-10 14:57 ` Jarkko Sakkinen 2017-10-04 10:29 ` Nayna Jain [this message] 2017-10-04 10:29 ` [PATCH v3 2/5] tpm: ignore burstcount to improve tpm_tis send() performance Nayna Jain 2017-10-10 15:04 ` Jarkko Sakkinen 2017-10-10 15:04 ` Jarkko Sakkinen 2017-10-11 11:29 ` Nayna Jain 2017-10-11 11:29 ` Nayna Jain 2017-10-11 11:29 ` Nayna Jain 2017-10-04 10:29 ` [PATCH v3 3/5] tpm: reduce polling delay in tpm_tis wait_for_tpm_stat() Nayna Jain 2017-10-04 10:29 ` Nayna Jain 2017-10-12 11:17 ` Jarkko Sakkinen 2017-10-12 11:17 ` Jarkko Sakkinen 2017-10-04 10:29 ` [PATCH v3 4/5] tpm: reduce tpm_msleep() time in get_burstcount() Nayna Jain 2017-10-04 10:29 ` Nayna Jain 2017-10-12 11:18 ` Jarkko Sakkinen 2017-10-12 11:18 ` Jarkko Sakkinen 2017-10-12 13:14 ` Nayna Jain 2017-10-12 13:14 ` Nayna Jain 2017-10-12 13:14 ` Nayna Jain 2017-10-04 10:29 ` [PATCH v3 5/5] tpm: use tpm_msleep() value as max delay Nayna Jain 2017-10-04 10:29 ` Nayna Jain 2017-10-12 11:19 ` Jarkko Sakkinen 2017-10-12 11:19 ` 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=20171004102924.12355-3-nayna@linux.vnet.ibm.com \ --to=nayna@linux.vnet.ibm.com \ --cc=jarkko.sakkinen@linux.intel.com \ --cc=jgunthorpe@obsidianresearch.com \ --cc=linux-integrity@vger.kernel.org \ --cc=linux-kernel@vger.kernel.org \ --cc=linux-security-module@vger.kernel.org \ --cc=patrickc@us.ibm.com \ --cc=peterhuewe@gmx.de \ --cc=tpmdd@selhorst.net \ --cc=zohar@linux.vnet.ibm.com \ /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: linkBe 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.