2020-02-27 00:28:08

by Stefan Berger

[permalink] [raw]
Subject: [PATCH v3 0/4] Enable vTPM 2.0 for the IBM vTPM driver

From: Stefan Berger <[email protected]>

QEMU 5.0 will support the PAPR vTPM device model for TPM 1.2 and TPM 2.0.
This series of patches enables vTPM 2.0 support for the IBM vTPM driver.

Regards,
Stefan

- v2->v3:
- Added fixes tag to patch 2/4; the race seems to have existed
since the driver was first added
- Renamed tpm2_init to tpm2_init_commands in 3/4

- v1->v2:
- Addressed comments to v1; added patch 3 to handle case when
TPM_OPS_AUTO_STARTUP is not set


Stefan Berger (4):
tpm: of: Handle IBM,vtpm20 case when getting log parameters
tpm: ibmvtpm: Wait for buffer to be set before proceeding
tpm: Implement tpm2_init_commands to use in non-auto startup case
tpm: ibmvtpm: Add support for TPM 2

drivers/char/tpm/eventlog/of.c | 8 +++++++-
drivers/char/tpm/tpm-interface.c | 5 ++++-
drivers/char/tpm/tpm.h | 1 +
drivers/char/tpm/tpm2-cmd.c | 14 ++++++++++++++
drivers/char/tpm/tpm_ibmvtpm.c | 13 +++++++++++++
drivers/char/tpm/tpm_ibmvtpm.h | 1 +
6 files changed, 40 insertions(+), 2 deletions(-)

--
2.23.0


2020-02-27 00:28:29

by Stefan Berger

[permalink] [raw]
Subject: [PATCH v3 4/4] tpm: ibmvtpm: Add support for TPM 2

From: Stefan Berger <[email protected]>

Support TPM 2 in the IBM vTPM driver. The hypervisor tells us what
version of TPM is connected through the vio_device_id.

In case a TPM 2 is found, we set the TPM_CHIP_FLAG_TPM2 flag.

Signed-off-by: Stefan Berger <[email protected]>
---
drivers/char/tpm/tpm_ibmvtpm.c | 4 ++++
1 file changed, 4 insertions(+)

diff --git a/drivers/char/tpm/tpm_ibmvtpm.c b/drivers/char/tpm/tpm_ibmvtpm.c
index eee566eddb35..0df815f9a6c5 100644
--- a/drivers/char/tpm/tpm_ibmvtpm.c
+++ b/drivers/char/tpm/tpm_ibmvtpm.c
@@ -29,6 +29,7 @@ static const char tpm_ibmvtpm_driver_name[] = "tpm_ibmvtpm";

static const struct vio_device_id tpm_ibmvtpm_device_table[] = {
{ "IBM,vtpm", "IBM,vtpm"},
+ { "IBM,vtpm", "IBM,vtpm20"},
{ "", "" }
};
MODULE_DEVICE_TABLE(vio, tpm_ibmvtpm_device_table);
@@ -672,6 +673,9 @@ static int tpm_ibmvtpm_probe(struct vio_dev *vio_dev,
if (rc)
goto init_irq_cleanup;

+ if (!strcmp(id->compat, "IBM,vtpm20"))
+ chip->flags |= TPM_CHIP_FLAG_TPM2;
+
if (!wait_event_timeout(ibmvtpm->crq_queue.wq,
ibmvtpm->rtce_buf != NULL,
HZ)) {
--
2.23.0

2020-02-27 00:28:56

by Stefan Berger

[permalink] [raw]
Subject: [PATCH v3 3/4] tpm: Implement tpm2_init_commands to use in non-auto startup case

From: Stefan Berger <[email protected]>

The IBM vTPM device driver will not use TPM_OPS_AUTO_STARTUP since we
assume the firmware has initialized the TPM 2 and TPM2_Startup() need
not be sent. Therefore, tpm2_auto_startup() will not be called. To cover
the tpm_chip's initialization of timeouts, command durations, and
command attributes we implement tpm2_init_commands() function that will
be called instead of tpm2_auto_startup().

Signed-off-by: Stefan Berger <[email protected]>
---
drivers/char/tpm/tpm-interface.c | 5 ++++-
drivers/char/tpm/tpm.h | 1 +
drivers/char/tpm/tpm2-cmd.c | 14 ++++++++++++++
3 files changed, 19 insertions(+), 1 deletion(-)

diff --git a/drivers/char/tpm/tpm-interface.c b/drivers/char/tpm/tpm-interface.c
index a438b1206fcb..30d80b94db33 100644
--- a/drivers/char/tpm/tpm-interface.c
+++ b/drivers/char/tpm/tpm-interface.c
@@ -371,8 +371,11 @@ int tpm_auto_startup(struct tpm_chip *chip)
{
int rc;

- if (!(chip->ops->flags & TPM_OPS_AUTO_STARTUP))
+ if (!(chip->ops->flags & TPM_OPS_AUTO_STARTUP)) {
+ if (chip->flags & TPM_CHIP_FLAG_TPM2)
+ return tpm2_init_commands(chip);
return 0;
+ }

if (chip->flags & TPM_CHIP_FLAG_TPM2)
rc = tpm2_auto_startup(chip);
diff --git a/drivers/char/tpm/tpm.h b/drivers/char/tpm/tpm.h
index 5620747da0cf..30da942d714a 100644
--- a/drivers/char/tpm/tpm.h
+++ b/drivers/char/tpm/tpm.h
@@ -222,6 +222,7 @@ ssize_t tpm2_get_tpm_pt(struct tpm_chip *chip, u32 property_id,
u32 *value, const char *desc);

ssize_t tpm2_get_pcr_allocation(struct tpm_chip *chip);
+int tpm2_init_commands(struct tpm_chip *chip);
int tpm2_auto_startup(struct tpm_chip *chip);
void tpm2_shutdown(struct tpm_chip *chip, u16 shutdown_type);
unsigned long tpm2_calc_ordinal_duration(struct tpm_chip *chip, u32 ordinal);
diff --git a/drivers/char/tpm/tpm2-cmd.c b/drivers/char/tpm/tpm2-cmd.c
index 13696deceae8..2d0c5a3b65c0 100644
--- a/drivers/char/tpm/tpm2-cmd.c
+++ b/drivers/char/tpm/tpm2-cmd.c
@@ -709,6 +709,20 @@ static int tpm2_startup(struct tpm_chip *chip)
return rc;
}

+/**
+ * tpm2_init_commands - Get timeouts, durations and command code attributes
+ * in case tpm2_auto_startup is not used.
+ * @chip: TPM chip to use
+ *
+ * Return 0 on success, < 0 in case of fatal error.
+ */
+int tpm2_init_commands(struct tpm_chip *chip)
+{
+ tpm2_get_timeouts(chip);
+
+ return tpm2_get_cc_attrs_tbl(chip);
+}
+
/**
* tpm2_auto_startup - Perform the standard automatic TPM initialization
* sequence
--
2.23.0

2020-02-27 00:29:12

by Stefan Berger

[permalink] [raw]
Subject: [PATCH v3 1/4] tpm: of: Handle IBM,vtpm20 case when getting log parameters

From: Stefan Berger <[email protected]>

A vTPM 2.0 is identified by 'IBM,vtpm20' in the 'compatible' node in
the device tree. Handle it in the same way as 'IBM,vtpm'.

The vTPM 2.0's log is written in little endian format so that for this
aspect we can rely on existing code.

Signed-off-by: Stefan Berger <[email protected]>
Acked-by: Jarkko Sakkinen <[email protected]>
---
drivers/char/tpm/eventlog/of.c | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/drivers/char/tpm/eventlog/of.c b/drivers/char/tpm/eventlog/of.c
index af347c190819..a31a625ad44e 100644
--- a/drivers/char/tpm/eventlog/of.c
+++ b/drivers/char/tpm/eventlog/of.c
@@ -17,6 +17,12 @@
#include "../tpm.h"
#include "common.h"

+static const char * const compatibles[] = {
+ "IBM,vtpm",
+ "IBM,vtpm20",
+ NULL
+};
+
int tpm_read_log_of(struct tpm_chip *chip)
{
struct device_node *np;
@@ -51,7 +57,7 @@ int tpm_read_log_of(struct tpm_chip *chip)
* endian format. For this reason, vtpm doesn't need conversion
* but physical tpm needs the conversion.
*/
- if (of_property_match_string(np, "compatible", "IBM,vtpm") < 0) {
+ if (!of_device_compatible_match(np, compatibles)) {
size = be32_to_cpup((__force __be32 *)sizep);
base = be64_to_cpup((__force __be64 *)basep);
} else {
--
2.23.0

2020-02-27 16:04:35

by Jarkko Sakkinen

[permalink] [raw]
Subject: Re: [PATCH v3 4/4] tpm: ibmvtpm: Add support for TPM 2

On Wed, Feb 26, 2020 at 07:26:54PM -0500, Stefan Berger wrote:
> From: Stefan Berger <[email protected]>
>
> Support TPM 2 in the IBM vTPM driver. The hypervisor tells us what
> version of TPM is connected through the vio_device_id.
>
> In case a TPM 2 is found, we set the TPM_CHIP_FLAG_TPM2 flag.
>
> Signed-off-by: Stefan Berger <[email protected]>

The commit message does not have anything on "vtpm20".

/Jarkko

2020-02-27 16:05:28

by Jarkko Sakkinen

[permalink] [raw]
Subject: Re: [PATCH v3 3/4] tpm: Implement tpm2_init_commands to use in non-auto startup case

On Wed, Feb 26, 2020 at 07:26:53PM -0500, Stefan Berger wrote:
> From: Stefan Berger <[email protected]>
>
> The IBM vTPM device driver will not use TPM_OPS_AUTO_STARTUP since we
> assume the firmware has initialized the TPM 2 and TPM2_Startup() need
> not be sent. Therefore, tpm2_auto_startup() will not be called. To cover
> the tpm_chip's initialization of timeouts, command durations, and
> command attributes we implement tpm2_init_commands() function that will
> be called instead of tpm2_auto_startup().
>
> Signed-off-by: Stefan Berger <[email protected]>
> ---
> drivers/char/tpm/tpm-interface.c | 5 ++++-
> drivers/char/tpm/tpm.h | 1 +
> drivers/char/tpm/tpm2-cmd.c | 14 ++++++++++++++
> 3 files changed, 19 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/char/tpm/tpm-interface.c b/drivers/char/tpm/tpm-interface.c
> index a438b1206fcb..30d80b94db33 100644
> --- a/drivers/char/tpm/tpm-interface.c
> +++ b/drivers/char/tpm/tpm-interface.c
> @@ -371,8 +371,11 @@ int tpm_auto_startup(struct tpm_chip *chip)
> {
> int rc;
>
> - if (!(chip->ops->flags & TPM_OPS_AUTO_STARTUP))
> + if (!(chip->ops->flags & TPM_OPS_AUTO_STARTUP)) {
> + if (chip->flags & TPM_CHIP_FLAG_TPM2)
> + return tpm2_init_commands(chip);
> return 0;
> + }
>
> if (chip->flags & TPM_CHIP_FLAG_TPM2)
> rc = tpm2_auto_startup(chip);
> diff --git a/drivers/char/tpm/tpm.h b/drivers/char/tpm/tpm.h
> index 5620747da0cf..30da942d714a 100644
> --- a/drivers/char/tpm/tpm.h
> +++ b/drivers/char/tpm/tpm.h
> @@ -222,6 +222,7 @@ ssize_t tpm2_get_tpm_pt(struct tpm_chip *chip, u32 property_id,
> u32 *value, const char *desc);
>
> ssize_t tpm2_get_pcr_allocation(struct tpm_chip *chip);
> +int tpm2_init_commands(struct tpm_chip *chip);
> int tpm2_auto_startup(struct tpm_chip *chip);
> void tpm2_shutdown(struct tpm_chip *chip, u16 shutdown_type);
> unsigned long tpm2_calc_ordinal_duration(struct tpm_chip *chip, u32 ordinal);
> diff --git a/drivers/char/tpm/tpm2-cmd.c b/drivers/char/tpm/tpm2-cmd.c
> index 13696deceae8..2d0c5a3b65c0 100644
> --- a/drivers/char/tpm/tpm2-cmd.c
> +++ b/drivers/char/tpm/tpm2-cmd.c
> @@ -709,6 +709,20 @@ static int tpm2_startup(struct tpm_chip *chip)
> return rc;
> }
>
> +/**
> + * tpm2_init_commands - Get timeouts, durations and command code attributes
> + * in case tpm2_auto_startup is not used.
> + * @chip: TPM chip to use
> + *
> + * Return 0 on success, < 0 in case of fatal error.
> + */
> +int tpm2_init_commands(struct tpm_chip *chip)
> +{
> + tpm2_get_timeouts(chip);
> +
> + return tpm2_get_cc_attrs_tbl(chip);

Call * locally in vtpm instead of adding quirks to the TPM driver.

/Jarkko