From: Jarkko Sakkinen <jarkko.sakkinen-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>
To: Peter Huewe <peterhuewe-Mmb7MZpHnFY@public.gmane.org>
Cc: "moderated list:TPM DEVICE DRIVER"
<tpmdd-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org>,
open list <linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org>
Subject: Re: [PATCH] tpm: remove redundant code from self-test functions
Date: Wed, 30 Mar 2016 09:37:03 +0300 [thread overview]
Message-ID: <20160330063234.GA24436@intel.com> (raw)
In-Reply-To: <1459316279-32532-1-git-send-email-jarkko.sakkinen-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>
On Wed, Mar 30, 2016 at 08:37:59AM +0300, Jarkko Sakkinen wrote:
> Self-test functions construct PCR read calls by ad hoc, which is only a
> waste space. Use instead tpm_pcr_read_dev (renamed as tpm1_pcr_read() by
> this commit) in tpm_do_selftest and tpm2_pcr_read() in
> tpm2_do_selftest() functions in order to remove the duplicate code.
>
> Patch can be tested easily tested by running the a kernel with this
> patch compiled in since self-test is done when the a device driver
> initializes.
Oops, I had a fixup for tpm-sysfs.c that I forgot to squash to the final
patch. Sorry about the compilation error. It can be fixed by changing
the call to tpm1_pcr_read() (parameters are same).
/Jarkko
> Signed-off-by: Jarkko Sakkinen <jarkko.sakkinen-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>
> ---
> drivers/char/tpm/tpm-interface.c | 14 +++++---------
> drivers/char/tpm/tpm2-cmd.c | 14 ++------------
> 2 files changed, 7 insertions(+), 21 deletions(-)
>
> diff --git a/drivers/char/tpm/tpm-interface.c b/drivers/char/tpm/tpm-interface.c
> index 5397b64..0c8140f 100644
> --- a/drivers/char/tpm/tpm-interface.c
> +++ b/drivers/char/tpm/tpm-interface.c
> @@ -1,6 +1,6 @@
> /*
> * Copyright (C) 2004 IBM Corporation
> - * Copyright (C) 2014 Intel Corporation
> + * Copyright (C) 2014, 2016 Intel Corporation
> *
> * Authors:
> * Leendert van Doorn <leendert-aZOuKsOsJu3MbYB6QlFGEg@public.gmane.org>
> @@ -666,7 +666,7 @@ static struct tpm_input_header pcrread_header = {
> .ordinal = TPM_ORDINAL_PCRREAD
> };
>
> -int tpm_pcr_read_dev(struct tpm_chip *chip, int pcr_idx, u8 *res_buf)
> +int tpm1_pcr_read(struct tpm_chip *chip, int pcr_idx, u8 *res_buf)
> {
> int rc;
> struct tpm_cmd_t cmd;
> @@ -676,7 +676,7 @@ int tpm_pcr_read_dev(struct tpm_chip *chip, int pcr_idx, u8 *res_buf)
> rc = tpm_transmit_cmd(chip, &cmd, READ_PCR_RESULT_SIZE,
> "attempting to read a pcr value");
>
> - if (rc == 0)
> + if (rc == 0 && res_buf)
> memcpy(res_buf, cmd.params.pcrread_out.pcr_result,
> TPM_DIGEST_SIZE);
> return rc;
> @@ -728,7 +728,7 @@ int tpm_pcr_read(u32 chip_num, int pcr_idx, u8 *res_buf)
> if (chip->flags & TPM_CHIP_FLAG_TPM2)
> rc = tpm2_pcr_read(chip, pcr_idx, res_buf);
> else
> - rc = tpm_pcr_read_dev(chip, pcr_idx, res_buf);
> + rc = tpm1_pcr_read(chip, pcr_idx, res_buf);
> tpm_put_ops(chip);
> return rc;
> }
> @@ -793,7 +793,6 @@ int tpm_do_selftest(struct tpm_chip *chip)
> unsigned int loops;
> unsigned int delay_msec = 100;
> unsigned long duration;
> - struct tpm_cmd_t cmd;
>
> duration = tpm_calc_ordinal_duration(chip, TPM_ORD_CONTINUE_SELFTEST);
>
> @@ -808,9 +807,7 @@ int tpm_do_selftest(struct tpm_chip *chip)
>
> do {
> /* Attempt to read a PCR value */
> - cmd.header.in = pcrread_header;
> - cmd.params.pcrread_in.pcr_idx = cpu_to_be32(0);
> - rc = tpm_transmit(chip, (u8 *) &cmd, READ_PCR_RESULT_SIZE);
> + rc = tpm1_pcr_read(chip, 0, NULL);
> /* Some buggy TPMs will not respond to tpm_tis_ready() for
> * around 300ms while the self test is ongoing, keep trying
> * until the self test duration expires. */
> @@ -825,7 +822,6 @@ int tpm_do_selftest(struct tpm_chip *chip)
> if (rc < TPM_HEADER_SIZE)
> return -EFAULT;
>
> - rc = be32_to_cpu(cmd.header.out.return_code);
> if (rc == TPM_ERR_DISABLED || rc == TPM_ERR_DEACTIVATED) {
> dev_info(&chip->dev,
> "TPM is disabled/deactivated (0x%X)\n", rc);
> diff --git a/drivers/char/tpm/tpm2-cmd.c b/drivers/char/tpm/tpm2-cmd.c
> index 5fc0e7c..afe8d47 100644
> --- a/drivers/char/tpm/tpm2-cmd.c
> +++ b/drivers/char/tpm/tpm2-cmd.c
> @@ -284,7 +284,7 @@ int tpm2_pcr_read(struct tpm_chip *chip, int pcr_idx, u8 *res_buf)
>
> rc = tpm_transmit_cmd(chip, &cmd, sizeof(cmd),
> "attempting to read a pcr value");
> - if (rc == 0) {
> + if (rc == 0 && res_buf) {
> buf = cmd.params.pcrread_out.digest;
> memcpy(res_buf, buf, TPM_DIGEST_SIZE);
> }
> @@ -861,7 +861,6 @@ int tpm2_do_selftest(struct tpm_chip *chip)
> unsigned int loops;
> unsigned int delay_msec = 100;
> unsigned long duration;
> - struct tpm2_cmd cmd;
> int i;
>
> duration = tpm2_calc_ordinal_duration(chip, TPM2_CC_SELF_TEST);
> @@ -874,19 +873,10 @@ int tpm2_do_selftest(struct tpm_chip *chip)
>
> for (i = 0; i < loops; i++) {
> /* Attempt to read a PCR value */
> - cmd.header.in = tpm2_pcrread_header;
> - cmd.params.pcrread_in.pcr_selects_cnt = cpu_to_be32(1);
> - cmd.params.pcrread_in.hash_alg = cpu_to_be16(TPM2_ALG_SHA1);
> - cmd.params.pcrread_in.pcr_select_size = TPM2_PCR_SELECT_MIN;
> - cmd.params.pcrread_in.pcr_select[0] = 0x01;
> - cmd.params.pcrread_in.pcr_select[1] = 0x00;
> - cmd.params.pcrread_in.pcr_select[2] = 0x00;
> -
> - rc = tpm_transmit_cmd(chip, (u8 *) &cmd, sizeof(cmd), NULL);
> + rc = tpm2_pcr_read(chip, 0, NULL);
> if (rc < 0)
> break;
>
> - rc = be32_to_cpu(cmd.header.out.return_code);
> if (rc != TPM2_RC_TESTING)
> break;
>
> --
> 2.7.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=278785471&iu=/4140
WARNING: multiple messages have this Message-ID (diff)
From: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
To: Peter Huewe <peterhuewe@gmx.de>
Cc: Marcel Selhorst <tpmdd@selhorst.net>,
Jason Gunthorpe <jgunthorpe@obsidianresearch.com>,
"moderated list:TPM DEVICE DRIVER"
<tpmdd-devel@lists.sourceforge.net>,
open list <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] tpm: remove redundant code from self-test functions
Date: Wed, 30 Mar 2016 09:37:03 +0300 [thread overview]
Message-ID: <20160330063234.GA24436@intel.com> (raw)
In-Reply-To: <1459316279-32532-1-git-send-email-jarkko.sakkinen@linux.intel.com>
On Wed, Mar 30, 2016 at 08:37:59AM +0300, Jarkko Sakkinen wrote:
> Self-test functions construct PCR read calls by ad hoc, which is only a
> waste space. Use instead tpm_pcr_read_dev (renamed as tpm1_pcr_read() by
> this commit) in tpm_do_selftest and tpm2_pcr_read() in
> tpm2_do_selftest() functions in order to remove the duplicate code.
>
> Patch can be tested easily tested by running the a kernel with this
> patch compiled in since self-test is done when the a device driver
> initializes.
Oops, I had a fixup for tpm-sysfs.c that I forgot to squash to the final
patch. Sorry about the compilation error. It can be fixed by changing
the call to tpm1_pcr_read() (parameters are same).
/Jarkko
> Signed-off-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
> ---
> drivers/char/tpm/tpm-interface.c | 14 +++++---------
> drivers/char/tpm/tpm2-cmd.c | 14 ++------------
> 2 files changed, 7 insertions(+), 21 deletions(-)
>
> diff --git a/drivers/char/tpm/tpm-interface.c b/drivers/char/tpm/tpm-interface.c
> index 5397b64..0c8140f 100644
> --- a/drivers/char/tpm/tpm-interface.c
> +++ b/drivers/char/tpm/tpm-interface.c
> @@ -1,6 +1,6 @@
> /*
> * Copyright (C) 2004 IBM Corporation
> - * Copyright (C) 2014 Intel Corporation
> + * Copyright (C) 2014, 2016 Intel Corporation
> *
> * Authors:
> * Leendert van Doorn <leendert@watson.ibm.com>
> @@ -666,7 +666,7 @@ static struct tpm_input_header pcrread_header = {
> .ordinal = TPM_ORDINAL_PCRREAD
> };
>
> -int tpm_pcr_read_dev(struct tpm_chip *chip, int pcr_idx, u8 *res_buf)
> +int tpm1_pcr_read(struct tpm_chip *chip, int pcr_idx, u8 *res_buf)
> {
> int rc;
> struct tpm_cmd_t cmd;
> @@ -676,7 +676,7 @@ int tpm_pcr_read_dev(struct tpm_chip *chip, int pcr_idx, u8 *res_buf)
> rc = tpm_transmit_cmd(chip, &cmd, READ_PCR_RESULT_SIZE,
> "attempting to read a pcr value");
>
> - if (rc == 0)
> + if (rc == 0 && res_buf)
> memcpy(res_buf, cmd.params.pcrread_out.pcr_result,
> TPM_DIGEST_SIZE);
> return rc;
> @@ -728,7 +728,7 @@ int tpm_pcr_read(u32 chip_num, int pcr_idx, u8 *res_buf)
> if (chip->flags & TPM_CHIP_FLAG_TPM2)
> rc = tpm2_pcr_read(chip, pcr_idx, res_buf);
> else
> - rc = tpm_pcr_read_dev(chip, pcr_idx, res_buf);
> + rc = tpm1_pcr_read(chip, pcr_idx, res_buf);
> tpm_put_ops(chip);
> return rc;
> }
> @@ -793,7 +793,6 @@ int tpm_do_selftest(struct tpm_chip *chip)
> unsigned int loops;
> unsigned int delay_msec = 100;
> unsigned long duration;
> - struct tpm_cmd_t cmd;
>
> duration = tpm_calc_ordinal_duration(chip, TPM_ORD_CONTINUE_SELFTEST);
>
> @@ -808,9 +807,7 @@ int tpm_do_selftest(struct tpm_chip *chip)
>
> do {
> /* Attempt to read a PCR value */
> - cmd.header.in = pcrread_header;
> - cmd.params.pcrread_in.pcr_idx = cpu_to_be32(0);
> - rc = tpm_transmit(chip, (u8 *) &cmd, READ_PCR_RESULT_SIZE);
> + rc = tpm1_pcr_read(chip, 0, NULL);
> /* Some buggy TPMs will not respond to tpm_tis_ready() for
> * around 300ms while the self test is ongoing, keep trying
> * until the self test duration expires. */
> @@ -825,7 +822,6 @@ int tpm_do_selftest(struct tpm_chip *chip)
> if (rc < TPM_HEADER_SIZE)
> return -EFAULT;
>
> - rc = be32_to_cpu(cmd.header.out.return_code);
> if (rc == TPM_ERR_DISABLED || rc == TPM_ERR_DEACTIVATED) {
> dev_info(&chip->dev,
> "TPM is disabled/deactivated (0x%X)\n", rc);
> diff --git a/drivers/char/tpm/tpm2-cmd.c b/drivers/char/tpm/tpm2-cmd.c
> index 5fc0e7c..afe8d47 100644
> --- a/drivers/char/tpm/tpm2-cmd.c
> +++ b/drivers/char/tpm/tpm2-cmd.c
> @@ -284,7 +284,7 @@ int tpm2_pcr_read(struct tpm_chip *chip, int pcr_idx, u8 *res_buf)
>
> rc = tpm_transmit_cmd(chip, &cmd, sizeof(cmd),
> "attempting to read a pcr value");
> - if (rc == 0) {
> + if (rc == 0 && res_buf) {
> buf = cmd.params.pcrread_out.digest;
> memcpy(res_buf, buf, TPM_DIGEST_SIZE);
> }
> @@ -861,7 +861,6 @@ int tpm2_do_selftest(struct tpm_chip *chip)
> unsigned int loops;
> unsigned int delay_msec = 100;
> unsigned long duration;
> - struct tpm2_cmd cmd;
> int i;
>
> duration = tpm2_calc_ordinal_duration(chip, TPM2_CC_SELF_TEST);
> @@ -874,19 +873,10 @@ int tpm2_do_selftest(struct tpm_chip *chip)
>
> for (i = 0; i < loops; i++) {
> /* Attempt to read a PCR value */
> - cmd.header.in = tpm2_pcrread_header;
> - cmd.params.pcrread_in.pcr_selects_cnt = cpu_to_be32(1);
> - cmd.params.pcrread_in.hash_alg = cpu_to_be16(TPM2_ALG_SHA1);
> - cmd.params.pcrread_in.pcr_select_size = TPM2_PCR_SELECT_MIN;
> - cmd.params.pcrread_in.pcr_select[0] = 0x01;
> - cmd.params.pcrread_in.pcr_select[1] = 0x00;
> - cmd.params.pcrread_in.pcr_select[2] = 0x00;
> -
> - rc = tpm_transmit_cmd(chip, (u8 *) &cmd, sizeof(cmd), NULL);
> + rc = tpm2_pcr_read(chip, 0, NULL);
> if (rc < 0)
> break;
>
> - rc = be32_to_cpu(cmd.header.out.return_code);
> if (rc != TPM2_RC_TESTING)
> break;
>
> --
> 2.7.3
>
next prev parent reply other threads:[~2016-03-30 6:37 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-03-30 5:37 [PATCH] tpm: remove redundant code from self-test functions Jarkko Sakkinen
2016-03-30 5:37 ` Jarkko Sakkinen
[not found] ` <1459316279-32532-1-git-send-email-jarkko.sakkinen-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>
2016-03-30 6:22 ` kbuild test robot
2016-03-30 6:22 ` kbuild test robot
2016-03-30 6:37 ` Jarkko Sakkinen [this message]
2016-03-30 6:37 ` Jarkko Sakkinen
2016-03-30 6:50 ` kbuild test robot
2016-03-30 6:50 ` kbuild test robot
2016-03-30 12:59 ` kbuild test robot
2016-03-30 12:59 ` kbuild test robot
-- strict thread matches above, loose matches on Subject: below --
2016-03-30 13:20 Jarkko Sakkinen
2016-03-30 13:20 ` Jarkko Sakkinen
2016-03-30 13:25 ` Jarkko Sakkinen
[not found] ` <1459344045-21602-1-git-send-email-jarkko.sakkinen-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>
2016-03-31 5:46 ` Jason Gunthorpe
2016-03-31 5:46 ` Jason Gunthorpe
[not found] ` <20160331054623.GB20504-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
2016-03-31 6:37 ` Jarkko Sakkinen
2016-03-31 6:37 ` Jarkko Sakkinen
[not found] ` <20160331063756.GA6393-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
2016-04-02 3:16 ` Jason Gunthorpe
2016-04-02 3:16 ` Jason Gunthorpe
2016-04-05 9:42 ` Jarkko Sakkinen
[not found] ` <20160405094221.GA12672-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
2016-04-06 14:03 ` Christophe Ricard
[not found] ` <CALD+uuwQnvKL7TsiBXme=P8NKEX2gD1mOx-AxV7OHiBgmi4ykw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2016-04-07 11:30 ` Jarkko Sakkinen
2016-04-07 11:30 ` 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=20160330063234.GA24436@intel.com \
--to=jarkko.sakkinen-vuqaysv1563yd54fqh9/ca@public.gmane.org \
--cc=linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=peterhuewe-Mmb7MZpHnFY@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 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.