linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH RFC 0/2] Generalize tpm2_get_tpm_pt to tpm2_get_cap
@ 2016-10-09 10:14 Jarkko Sakkinen
  2016-10-09 10:14 ` [PATCH RFC 1/2] tpm: move TPM 2.0 command and response constants to tpm2-cmd.c Jarkko Sakkinen
                   ` (2 more replies)
  0 siblings, 3 replies; 16+ messages in thread
From: Jarkko Sakkinen @ 2016-10-09 10:14 UTC (permalink / raw)
  To: Peter Huewe
  Cc: Jarkko Sakkinen, Jason Gunthorpe, open list,
	moderated list:TPM DEVICE DRIVER

We need to generalize tpm2_get_tpm_pt to tpm2_get_cap in order to it be
suitable for grabbing handles, PCR banks and so forth.

Jarkko Sakkinen (2):
  tpm: move TPM 2.0 command and response constants to tpm2-cmd.c
  tpm: refactor tpm2_get_tpm_pt to tpm2_getcap_cmd

 drivers/char/tpm/tpm.h          |  48 ++----------------
 drivers/char/tpm/tpm2-cmd.c     | 106 +++++++++++++++++++++++++++-------------
 drivers/char/tpm/tpm_tis_core.c |   3 +-
 3 files changed, 80 insertions(+), 77 deletions(-)

-- 
2.7.4

^ permalink raw reply	[flat|nested] 16+ messages in thread

* [PATCH RFC 1/2] tpm: move TPM 2.0 command and response constants to tpm2-cmd.c
  2016-10-09 10:14 [PATCH RFC 0/2] Generalize tpm2_get_tpm_pt to tpm2_get_cap Jarkko Sakkinen
@ 2016-10-09 10:14 ` Jarkko Sakkinen
  2016-10-09 10:14 ` [PATCH RFC 2/2] tpm: refactor tpm2_get_tpm_pt to tpm2_getcap_cmd Jarkko Sakkinen
  2016-11-04  7:28 ` [PATCH RFC 0/2] Generalize tpm2_get_tpm_pt to tpm2_get_cap Jarkko Sakkinen
  2 siblings, 0 replies; 16+ messages in thread
From: Jarkko Sakkinen @ 2016-10-09 10:14 UTC (permalink / raw)
  To: Peter Huewe
  Cc: Jarkko Sakkinen, Marcel Selhorst, Jason Gunthorpe,
	moderated list:TPM DEVICE DRIVER, open list

The constans used to construct TPM 2.0 messages are only needed inside
tpm2-cmd.c so it is better to move them there.

Signed-off-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
---
 drivers/char/tpm/tpm.h      | 42 ------------------------------------------
 drivers/char/tpm/tpm2-cmd.c | 42 ++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 42 insertions(+), 42 deletions(-)

diff --git a/drivers/char/tpm/tpm.h b/drivers/char/tpm/tpm.h
index 4d183c9..0fab6d5 100644
--- a/drivers/char/tpm/tpm.h
+++ b/drivers/char/tpm/tpm.h
@@ -81,48 +81,6 @@ enum tpm2_const {
 	TPM2_DURATION_LONG	= 2000,
 };
 
-enum tpm2_structures {
-	TPM2_ST_NO_SESSIONS	= 0x8001,
-	TPM2_ST_SESSIONS	= 0x8002,
-};
-
-enum tpm2_return_codes {
-	TPM2_RC_HASH		= 0x0083, /* RC_FMT1 */
-	TPM2_RC_INITIALIZE	= 0x0100, /* RC_VER1 */
-	TPM2_RC_DISABLED	= 0x0120,
-	TPM2_RC_TESTING		= 0x090A, /* RC_WARN */
-};
-
-enum tpm2_algorithms {
-	TPM2_ALG_SHA1		= 0x0004,
-	TPM2_ALG_KEYEDHASH	= 0x0008,
-	TPM2_ALG_SHA256		= 0x000B,
-	TPM2_ALG_SHA384		= 0x000C,
-	TPM2_ALG_SHA512		= 0x000D,
-	TPM2_ALG_NULL		= 0x0010,
-	TPM2_ALG_SM3_256	= 0x0012,
-};
-
-enum tpm2_command_codes {
-	TPM2_CC_FIRST		= 0x011F,
-	TPM2_CC_SELF_TEST	= 0x0143,
-	TPM2_CC_STARTUP		= 0x0144,
-	TPM2_CC_SHUTDOWN	= 0x0145,
-	TPM2_CC_CREATE		= 0x0153,
-	TPM2_CC_LOAD		= 0x0157,
-	TPM2_CC_UNSEAL		= 0x015E,
-	TPM2_CC_FLUSH_CONTEXT	= 0x0165,
-	TPM2_CC_GET_CAPABILITY	= 0x017A,
-	TPM2_CC_GET_RANDOM	= 0x017B,
-	TPM2_CC_PCR_READ	= 0x017E,
-	TPM2_CC_PCR_EXTEND	= 0x0182,
-	TPM2_CC_LAST		= 0x018F,
-};
-
-enum tpm2_permanent_handles {
-	TPM2_RS_PW		= 0x40000009,
-};
-
 enum tpm2_capabilities {
 	TPM2_CAP_TPM_PROPERTIES = 6,
 };
diff --git a/drivers/char/tpm/tpm2-cmd.c b/drivers/char/tpm/tpm2-cmd.c
index 7df55d5..2900e18 100644
--- a/drivers/char/tpm/tpm2-cmd.c
+++ b/drivers/char/tpm/tpm2-cmd.c
@@ -19,6 +19,48 @@
 #include <crypto/hash_info.h>
 #include <keys/trusted-type.h>
 
+enum tpm2_structures {
+	TPM2_ST_NO_SESSIONS	= 0x8001,
+	TPM2_ST_SESSIONS	= 0x8002,
+};
+
+enum tpm2_return_codes {
+	TPM2_RC_HASH		= 0x0083, /* RC_FMT1 */
+	TPM2_RC_INITIALIZE	= 0x0100, /* RC_VER1 */
+	TPM2_RC_DISABLED	= 0x0120,
+	TPM2_RC_TESTING		= 0x090A, /* RC_WARN */
+};
+
+enum tpm2_algorithms {
+	TPM2_ALG_SHA1		= 0x0004,
+	TPM2_ALG_KEYEDHASH	= 0x0008,
+	TPM2_ALG_SHA256		= 0x000B,
+	TPM2_ALG_SHA384		= 0x000C,
+	TPM2_ALG_SHA512		= 0x000D,
+	TPM2_ALG_NULL		= 0x0010,
+	TPM2_ALG_SM3_256	= 0x0012,
+};
+
+enum tpm2_command_codes {
+	TPM2_CC_FIRST		= 0x011F,
+	TPM2_CC_SELF_TEST	= 0x0143,
+	TPM2_CC_STARTUP		= 0x0144,
+	TPM2_CC_SHUTDOWN	= 0x0145,
+	TPM2_CC_CREATE		= 0x0153,
+	TPM2_CC_LOAD		= 0x0157,
+	TPM2_CC_UNSEAL		= 0x015E,
+	TPM2_CC_FLUSH_CONTEXT	= 0x0165,
+	TPM2_CC_GET_CAPABILITY	= 0x017A,
+	TPM2_CC_GET_RANDOM	= 0x017B,
+	TPM2_CC_PCR_READ	= 0x017E,
+	TPM2_CC_PCR_EXTEND	= 0x0182,
+	TPM2_CC_LAST		= 0x018F,
+};
+
+enum tpm2_permanent_handles {
+	TPM2_RS_PW		= 0x40000009,
+};
+
 enum tpm2_object_attributes {
 	TPM2_OA_USER_WITH_AUTH		= BIT(6),
 };
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH RFC 2/2] tpm: refactor tpm2_get_tpm_pt to tpm2_getcap_cmd
  2016-10-09 10:14 [PATCH RFC 0/2] Generalize tpm2_get_tpm_pt to tpm2_get_cap Jarkko Sakkinen
  2016-10-09 10:14 ` [PATCH RFC 1/2] tpm: move TPM 2.0 command and response constants to tpm2-cmd.c Jarkko Sakkinen
@ 2016-10-09 10:14 ` Jarkko Sakkinen
  2016-11-11  4:21   ` [tpmdd-devel] " Nayna
  2016-11-04  7:28 ` [PATCH RFC 0/2] Generalize tpm2_get_tpm_pt to tpm2_get_cap Jarkko Sakkinen
  2 siblings, 1 reply; 16+ messages in thread
From: Jarkko Sakkinen @ 2016-10-09 10:14 UTC (permalink / raw)
  To: Peter Huewe
  Cc: Jarkko Sakkinen, Marcel Selhorst, Jason Gunthorpe,
	moderated list:TPM DEVICE DRIVER, open list

Refactored tpm2_get_tpm_pt to tpm2_getcap_cmd, which means that it also
takes capability ID as input. This is required to access
TPM_CAP_HANDLES, which contains metadata needed for swapping transient
data.

Signed-off-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
---
 drivers/char/tpm/tpm.h          |  6 +++-
 drivers/char/tpm/tpm2-cmd.c     | 64 ++++++++++++++++++++---------------------
 drivers/char/tpm/tpm_tis_core.c |  3 +-
 3 files changed, 38 insertions(+), 35 deletions(-)

diff --git a/drivers/char/tpm/tpm.h b/drivers/char/tpm/tpm.h
index 0fab6d5..8176f42 100644
--- a/drivers/char/tpm/tpm.h
+++ b/drivers/char/tpm/tpm.h
@@ -85,6 +85,10 @@ enum tpm2_capabilities {
 	TPM2_CAP_TPM_PROPERTIES = 6,
 };
 
+enum tpm2_properties {
+	TPM2_PT_FAMILY_INDICATOR	= 0x100,
+};
+
 enum tpm2_startup_types {
 	TPM2_SU_CLEAR	= 0x0000,
 	TPM2_SU_STATE	= 0x0001,
@@ -485,7 +489,7 @@ int tpm2_seal_trusted(struct tpm_chip *chip,
 int tpm2_unseal_trusted(struct tpm_chip *chip,
 			struct trusted_key_payload *payload,
 			struct trusted_key_options *options);
-ssize_t tpm2_get_tpm_pt(struct tpm_chip *chip, u32 property_id,
+ssize_t tpm2_getcap_cmd(struct tpm_chip *chip, u32 cap_id, u32 property_id,
 			u32 *value, const char *desc);
 
 int tpm2_auto_startup(struct tpm_chip *chip);
diff --git a/drivers/char/tpm/tpm2-cmd.c b/drivers/char/tpm/tpm2-cmd.c
index 2900e18..fcf3d86 100644
--- a/drivers/char/tpm/tpm2-cmd.c
+++ b/drivers/char/tpm/tpm2-cmd.c
@@ -111,13 +111,13 @@ struct tpm2_pcr_extend_in {
 	u8				digest[TPM_DIGEST_SIZE];
 } __packed;
 
-struct tpm2_get_tpm_pt_in {
+struct tpm2_getcap_in {
 	__be32	cap_id;
 	__be32	property_id;
 	__be32	property_cnt;
 } __packed;
 
-struct tpm2_get_tpm_pt_out {
+struct tpm2_getcap_out {
 	u8	more_data;
 	__be32	subcap_id;
 	__be32	property_cnt;
@@ -140,8 +140,8 @@ union tpm2_cmd_params {
 	struct	tpm2_pcr_read_in	pcrread_in;
 	struct	tpm2_pcr_read_out	pcrread_out;
 	struct	tpm2_pcr_extend_in	pcrextend_in;
-	struct	tpm2_get_tpm_pt_in	get_tpm_pt_in;
-	struct	tpm2_get_tpm_pt_out	get_tpm_pt_out;
+	struct	tpm2_getcap_in		getcap_in;
+	struct	tpm2_getcap_out		getcap_out;
 	struct	tpm2_get_random_in	getrandom_in;
 	struct	tpm2_get_random_out	getrandom_out;
 };
@@ -435,16 +435,6 @@ int tpm2_get_random(struct tpm_chip *chip, u8 *out, size_t max)
 	return total ? total : -EIO;
 }
 
-#define TPM2_GET_TPM_PT_IN_SIZE \
-	(sizeof(struct tpm_input_header) + \
-	 sizeof(struct tpm2_get_tpm_pt_in))
-
-static const struct tpm_input_header tpm2_get_tpm_pt_header = {
-	.tag = cpu_to_be16(TPM2_ST_NO_SESSIONS),
-	.length = cpu_to_be32(TPM2_GET_TPM_PT_IN_SIZE),
-	.ordinal = cpu_to_be32(TPM2_CC_GET_CAPABILITY)
-};
-
 /**
  * Append TPMS_AUTH_COMMAND to the buffer. The buffer must be allocated with
  * tpm_buf_alloc().
@@ -750,35 +740,43 @@ out:
 	return rc;
 }
 
+#define TPM2_GETCAP_IN_SIZE \
+	(sizeof(struct tpm_input_header) + sizeof(struct tpm2_getcap_in))
+
+static const struct tpm_input_header tpm2_getcap_header = {
+	.tag = cpu_to_be16(TPM2_ST_NO_SESSIONS),
+	.length = cpu_to_be32(TPM2_GETCAP_IN_SIZE),
+	.ordinal = cpu_to_be32(TPM2_CC_GET_CAPABILITY)
+};
+
 /**
- * tpm2_get_tpm_pt() - get value of a TPM_CAP_TPM_PROPERTIES type property
- * @chip:		TPM chip to use.
- * @property_id:	property ID.
- * @value:		output variable.
+ * tpm2_getcap_cmd() - execute a TPM2_GetCapability command
+ * @chip:		TPM chip to use
+ * @cap_id:		capability ID
+ * @property_id:	property ID
+ * @value:		value of the property
  * @desc:		passed to tpm_transmit_cmd()
  *
- * 0 is returned when the operation is successful. If a negative number is
- * returned it remarks a POSIX error code. If a positive number is returned
- * it remarks a TPM error.
+ * Return: same as with tpm_transmit_cmd
  */
-ssize_t tpm2_get_tpm_pt(struct tpm_chip *chip, u32 property_id,  u32 *value,
-			const char *desc)
+ssize_t tpm2_getcap_cmd(struct tpm_chip *chip, u32 cap_id, u32 property_id,
+			u32 *value, const char *desc)
 {
 	struct tpm2_cmd cmd;
 	int rc;
 
-	cmd.header.in = tpm2_get_tpm_pt_header;
-	cmd.params.get_tpm_pt_in.cap_id = cpu_to_be32(TPM2_CAP_TPM_PROPERTIES);
-	cmd.params.get_tpm_pt_in.property_id = cpu_to_be32(property_id);
-	cmd.params.get_tpm_pt_in.property_cnt = cpu_to_be32(1);
+	cmd.header.in = tpm2_getcap_header;
+	cmd.params.getcap_in.cap_id = cpu_to_be32(cap_id);
+	cmd.params.getcap_in.property_id = cpu_to_be32(property_id);
+	cmd.params.getcap_in.property_cnt = cpu_to_be32(1);
 
 	rc = tpm_transmit_cmd(chip, &cmd, sizeof(cmd), 0, desc);
 	if (!rc)
-		*value = be32_to_cpu(cmd.params.get_tpm_pt_out.value);
+		*value = be32_to_cpu(cmd.params.getcap_out.value);
 
 	return rc;
 }
-EXPORT_SYMBOL_GPL(tpm2_get_tpm_pt);
+EXPORT_SYMBOL_GPL(tpm2_getcap_cmd);
 
 #define TPM2_STARTUP_IN_SIZE \
 	(sizeof(struct tpm_input_header) + \
@@ -978,10 +976,10 @@ int tpm2_probe(struct tpm_chip *chip)
 	struct tpm2_cmd cmd;
 	int rc;
 
-	cmd.header.in = tpm2_get_tpm_pt_header;
-	cmd.params.get_tpm_pt_in.cap_id = cpu_to_be32(TPM2_CAP_TPM_PROPERTIES);
-	cmd.params.get_tpm_pt_in.property_id = cpu_to_be32(0x100);
-	cmd.params.get_tpm_pt_in.property_cnt = cpu_to_be32(1);
+	cmd.header.in = tpm2_getcap_header;
+	cmd.params.getcap_in.cap_id = cpu_to_be32(TPM2_CAP_TPM_PROPERTIES);
+	cmd.params.getcap_in.property_id = cpu_to_be32(TPM2_PT_FAMILY_INDICATOR);
+	cmd.params.getcap_in.property_cnt = cpu_to_be32(1);
 
 	rc = tpm_transmit_cmd(chip, &cmd, sizeof(cmd),  0, NULL);
 	if (rc <  0)
diff --git a/drivers/char/tpm/tpm_tis_core.c b/drivers/char/tpm/tpm_tis_core.c
index e3bf31b..792ccd1 100644
--- a/drivers/char/tpm/tpm_tis_core.c
+++ b/drivers/char/tpm/tpm_tis_core.c
@@ -528,7 +528,8 @@ static int tpm_tis_gen_interrupt(struct tpm_chip *chip)
 	cap_t cap;
 
 	if (chip->flags & TPM_CHIP_FLAG_TPM2)
-		return tpm2_get_tpm_pt(chip, 0x100, &cap2, desc);
+		return tpm2_getcap_cmd(chip, TPM2_CAP_TPM_PROPERTIES,
+				       TPM2_PT_FAMILY_INDICATOR, &cap2, desc);
 	else
 		return tpm_getcap(chip, TPM_CAP_PROP_TIS_TIMEOUT, &cap, desc);
 }
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 16+ messages in thread

* Re: [PATCH RFC 0/2] Generalize tpm2_get_tpm_pt to tpm2_get_cap
  2016-10-09 10:14 [PATCH RFC 0/2] Generalize tpm2_get_tpm_pt to tpm2_get_cap Jarkko Sakkinen
  2016-10-09 10:14 ` [PATCH RFC 1/2] tpm: move TPM 2.0 command and response constants to tpm2-cmd.c Jarkko Sakkinen
  2016-10-09 10:14 ` [PATCH RFC 2/2] tpm: refactor tpm2_get_tpm_pt to tpm2_getcap_cmd Jarkko Sakkinen
@ 2016-11-04  7:28 ` Jarkko Sakkinen
  2016-11-11  4:42   ` Nayna
  2 siblings, 1 reply; 16+ messages in thread
From: Jarkko Sakkinen @ 2016-11-04  7:28 UTC (permalink / raw)
  To: Nayna Jain; +Cc: Jason Gunthorpe, open list, moderated list:TPM DEVICE DRIVER

Nayna,

I've already sent these earlier this month as we had this discussion. 
Please look up your emails. I can apply these if they look good for
you. Please review them.

/Jarkko

On Sun, Oct 09, 2016 at 01:14:14PM +0300, Jarkko Sakkinen wrote:
> We need to generalize tpm2_get_tpm_pt to tpm2_get_cap in order to it be
> suitable for grabbing handles, PCR banks and so forth.
> 
> Jarkko Sakkinen (2):
>   tpm: move TPM 2.0 command and response constants to tpm2-cmd.c
>   tpm: refactor tpm2_get_tpm_pt to tpm2_getcap_cmd
> 
>  drivers/char/tpm/tpm.h          |  48 ++----------------
>  drivers/char/tpm/tpm2-cmd.c     | 106 +++++++++++++++++++++++++++-------------
>  drivers/char/tpm/tpm_tis_core.c |   3 +-
>  3 files changed, 80 insertions(+), 77 deletions(-)
> 
> -- 
> 2.7.4
> 

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [tpmdd-devel] [PATCH RFC 2/2] tpm: refactor tpm2_get_tpm_pt to tpm2_getcap_cmd
  2016-10-09 10:14 ` [PATCH RFC 2/2] tpm: refactor tpm2_get_tpm_pt to tpm2_getcap_cmd Jarkko Sakkinen
@ 2016-11-11  4:21   ` Nayna
  2016-11-12  0:02     ` Jarkko Sakkinen
  0 siblings, 1 reply; 16+ messages in thread
From: Nayna @ 2016-11-11  4:21 UTC (permalink / raw)
  To: Jarkko Sakkinen, Peter Huewe; +Cc: moderated list:TPM DEVICE DRIVER, open list



On 10/09/2016 03:44 PM, Jarkko Sakkinen wrote:
> Refactored tpm2_get_tpm_pt to tpm2_getcap_cmd, which means that it also
> takes capability ID as input. This is required to access
> TPM_CAP_HANDLES, which contains metadata needed for swapping transient
> data.
>
> Signed-off-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
> ---
>   drivers/char/tpm/tpm.h          |  6 +++-
>   drivers/char/tpm/tpm2-cmd.c     | 64 ++++++++++++++++++++---------------------
>   drivers/char/tpm/tpm_tis_core.c |  3 +-
>   3 files changed, 38 insertions(+), 35 deletions(-)
>
> diff --git a/drivers/char/tpm/tpm.h b/drivers/char/tpm/tpm.h
> index 0fab6d5..8176f42 100644
> --- a/drivers/char/tpm/tpm.h
> +++ b/drivers/char/tpm/tpm.h
> @@ -85,6 +85,10 @@ enum tpm2_capabilities {
>   	TPM2_CAP_TPM_PROPERTIES = 6,
>   };
>
> +enum tpm2_properties {
> +	TPM2_PT_FAMILY_INDICATOR	= 0x100,
> +};
> +
>   enum tpm2_startup_types {
>   	TPM2_SU_CLEAR	= 0x0000,
>   	TPM2_SU_STATE	= 0x0001,
> @@ -485,7 +489,7 @@ int tpm2_seal_trusted(struct tpm_chip *chip,
>   int tpm2_unseal_trusted(struct tpm_chip *chip,
>   			struct trusted_key_payload *payload,
>   			struct trusted_key_options *options);
> -ssize_t tpm2_get_tpm_pt(struct tpm_chip *chip, u32 property_id,
> +ssize_t tpm2_getcap_cmd(struct tpm_chip *chip, u32 cap_id, u32 property_id,
>   			u32 *value, const char *desc);
>
>   int tpm2_auto_startup(struct tpm_chip *chip);
> diff --git a/drivers/char/tpm/tpm2-cmd.c b/drivers/char/tpm/tpm2-cmd.c
> index 2900e18..fcf3d86 100644
> --- a/drivers/char/tpm/tpm2-cmd.c
> +++ b/drivers/char/tpm/tpm2-cmd.c
> @@ -111,13 +111,13 @@ struct tpm2_pcr_extend_in {
>   	u8				digest[TPM_DIGEST_SIZE];
>   } __packed;
>
> -struct tpm2_get_tpm_pt_in {
> +struct tpm2_getcap_in {
>   	__be32	cap_id;
>   	__be32	property_id;
>   	__be32	property_cnt;
>   } __packed;
>
> -struct tpm2_get_tpm_pt_out {
> +struct tpm2_getcap_out {
>   	u8	more_data;
>   	__be32	subcap_id;
>   	__be32	property_cnt;
> @@ -140,8 +140,8 @@ union tpm2_cmd_params {
>   	struct	tpm2_pcr_read_in	pcrread_in;
>   	struct	tpm2_pcr_read_out	pcrread_out;
>   	struct	tpm2_pcr_extend_in	pcrextend_in;
> -	struct	tpm2_get_tpm_pt_in	get_tpm_pt_in;
> -	struct	tpm2_get_tpm_pt_out	get_tpm_pt_out;
> +	struct	tpm2_getcap_in		getcap_in;
> +	struct	tpm2_getcap_out		getcap_out;
>   	struct	tpm2_get_random_in	getrandom_in;
>   	struct	tpm2_get_random_out	getrandom_out;
>   };
> @@ -435,16 +435,6 @@ int tpm2_get_random(struct tpm_chip *chip, u8 *out, size_t max)
>   	return total ? total : -EIO;
>   }
>
> -#define TPM2_GET_TPM_PT_IN_SIZE \
> -	(sizeof(struct tpm_input_header) + \
> -	 sizeof(struct tpm2_get_tpm_pt_in))
> -
> -static const struct tpm_input_header tpm2_get_tpm_pt_header = {
> -	.tag = cpu_to_be16(TPM2_ST_NO_SESSIONS),
> -	.length = cpu_to_be32(TPM2_GET_TPM_PT_IN_SIZE),
> -	.ordinal = cpu_to_be32(TPM2_CC_GET_CAPABILITY)
> -};
> -
>   /**
>    * Append TPMS_AUTH_COMMAND to the buffer. The buffer must be allocated with
>    * tpm_buf_alloc().
> @@ -750,35 +740,43 @@ out:
>   	return rc;
>   }
>
> +#define TPM2_GETCAP_IN_SIZE \
> +	(sizeof(struct tpm_input_header) + sizeof(struct tpm2_getcap_in))
> +
> +static const struct tpm_input_header tpm2_getcap_header = {
> +	.tag = cpu_to_be16(TPM2_ST_NO_SESSIONS),
> +	.length = cpu_to_be32(TPM2_GETCAP_IN_SIZE),
> +	.ordinal = cpu_to_be32(TPM2_CC_GET_CAPABILITY)
> +};
> +
>   /**
> - * tpm2_get_tpm_pt() - get value of a TPM_CAP_TPM_PROPERTIES type property
> - * @chip:		TPM chip to use.
> - * @property_id:	property ID.
> - * @value:		output variable.
> + * tpm2_getcap_cmd() - execute a TPM2_GetCapability command
> + * @chip:		TPM chip to use
> + * @cap_id:		capability ID
> + * @property_id:	property ID
> + * @value:		value of the property
>    * @desc:		passed to tpm_transmit_cmd()
>    *
> - * 0 is returned when the operation is successful. If a negative number is
> - * returned it remarks a POSIX error code. If a positive number is returned
> - * it remarks a TPM error.
> + * Return: same as with tpm_transmit_cmd
>    */
> -ssize_t tpm2_get_tpm_pt(struct tpm_chip *chip, u32 property_id,  u32 *value,
> -			const char *desc)
> +ssize_t tpm2_getcap_cmd(struct tpm_chip *chip, u32 cap_id, u32 property_id,
> +			u32 *value, const char *desc)

This function currently returns single value "u32 *value" as output data.

Some calling function expect list of values from capabilities output.
For eg., get_active_banks() use TPM_CAP_PCRS capability to retrieve list 
of active banks. And this capability returns array of pcr 
selections(which is a struct representing each active PCR bank)

I was thinking, can we define output parameter as struct of cap_id and 
union of expected cap_data ?

struct cap_out {
   u32 cap_id;
   union cap_data {
      struct tpml_pcr_selection assignedPCR;
      struct tpml_tagged_tpm_property tpmProperties;
      struct tpml_handle handles;
   }
}

And then the calling function, map union to the cap_data expected as per 
id, and parse it.

Thanks & Regards,
   - Nayna


>   {
>   	struct tpm2_cmd cmd;
>   	int rc;
>
> -	cmd.header.in = tpm2_get_tpm_pt_header;
> -	cmd.params.get_tpm_pt_in.cap_id = cpu_to_be32(TPM2_CAP_TPM_PROPERTIES);
> -	cmd.params.get_tpm_pt_in.property_id = cpu_to_be32(property_id);
> -	cmd.params.get_tpm_pt_in.property_cnt = cpu_to_be32(1);
> +	cmd.header.in = tpm2_getcap_header;
> +	cmd.params.getcap_in.cap_id = cpu_to_be32(cap_id);
> +	cmd.params.getcap_in.property_id = cpu_to_be32(property_id);
> +	cmd.params.getcap_in.property_cnt = cpu_to_be32(1);
>
>   	rc = tpm_transmit_cmd(chip, &cmd, sizeof(cmd), 0, desc);
>   	if (!rc)
> -		*value = be32_to_cpu(cmd.params.get_tpm_pt_out.value);
> +		*value = be32_to_cpu(cmd.params.getcap_out.value);
>
>   	return rc;
>   }
> -EXPORT_SYMBOL_GPL(tpm2_get_tpm_pt);
> +EXPORT_SYMBOL_GPL(tpm2_getcap_cmd);
>
>   #define TPM2_STARTUP_IN_SIZE \
>   	(sizeof(struct tpm_input_header) + \
> @@ -978,10 +976,10 @@ int tpm2_probe(struct tpm_chip *chip)
>   	struct tpm2_cmd cmd;
>   	int rc;
>
> -	cmd.header.in = tpm2_get_tpm_pt_header;
> -	cmd.params.get_tpm_pt_in.cap_id = cpu_to_be32(TPM2_CAP_TPM_PROPERTIES);
> -	cmd.params.get_tpm_pt_in.property_id = cpu_to_be32(0x100);
> -	cmd.params.get_tpm_pt_in.property_cnt = cpu_to_be32(1);
> +	cmd.header.in = tpm2_getcap_header;
> +	cmd.params.getcap_in.cap_id = cpu_to_be32(TPM2_CAP_TPM_PROPERTIES);
> +	cmd.params.getcap_in.property_id = cpu_to_be32(TPM2_PT_FAMILY_INDICATOR);
> +	cmd.params.getcap_in.property_cnt = cpu_to_be32(1);
>
>   	rc = tpm_transmit_cmd(chip, &cmd, sizeof(cmd),  0, NULL);
>   	if (rc <  0)
> diff --git a/drivers/char/tpm/tpm_tis_core.c b/drivers/char/tpm/tpm_tis_core.c
> index e3bf31b..792ccd1 100644
> --- a/drivers/char/tpm/tpm_tis_core.c
> +++ b/drivers/char/tpm/tpm_tis_core.c
> @@ -528,7 +528,8 @@ static int tpm_tis_gen_interrupt(struct tpm_chip *chip)
>   	cap_t cap;
>
>   	if (chip->flags & TPM_CHIP_FLAG_TPM2)
> -		return tpm2_get_tpm_pt(chip, 0x100, &cap2, desc);
> +		return tpm2_getcap_cmd(chip, TPM2_CAP_TPM_PROPERTIES,
> +				       TPM2_PT_FAMILY_INDICATOR, &cap2, desc);
>   	else
>   		return tpm_getcap(chip, TPM_CAP_PROP_TIS_TIMEOUT, &cap, desc);
>   }
>

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH RFC 0/2] Generalize tpm2_get_tpm_pt to tpm2_get_cap
  2016-11-04  7:28 ` [PATCH RFC 0/2] Generalize tpm2_get_tpm_pt to tpm2_get_cap Jarkko Sakkinen
@ 2016-11-11  4:42   ` Nayna
  0 siblings, 0 replies; 16+ messages in thread
From: Nayna @ 2016-11-11  4:42 UTC (permalink / raw)
  To: Jarkko Sakkinen
  Cc: Jason Gunthorpe, open list, moderated list:TPM DEVICE DRIVER



On 11/04/2016 12:58 PM, Jarkko Sakkinen wrote:
> Nayna,
>
> I've already sent these earlier this month as we had this discussion.
> Please look up your emails. I can apply these if they look good for
> you. Please review them.

Sure, I replied just now. I am sorry if delay in response. I was off 
early this week and still going through all mails.

Thanks & Regards,
   - Nayna

>
> /Jarkko
>
> On Sun, Oct 09, 2016 at 01:14:14PM +0300, Jarkko Sakkinen wrote:
>> We need to generalize tpm2_get_tpm_pt to tpm2_get_cap in order to it be
>> suitable for grabbing handles, PCR banks and so forth.
>>
>> Jarkko Sakkinen (2):
>>    tpm: move TPM 2.0 command and response constants to tpm2-cmd.c
>>    tpm: refactor tpm2_get_tpm_pt to tpm2_getcap_cmd
>>
>>   drivers/char/tpm/tpm.h          |  48 ++----------------
>>   drivers/char/tpm/tpm2-cmd.c     | 106 +++++++++++++++++++++++++++-------------
>>   drivers/char/tpm/tpm_tis_core.c |   3 +-
>>   3 files changed, 80 insertions(+), 77 deletions(-)
>>
>> --
>> 2.7.4
>>
>

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [tpmdd-devel] [PATCH RFC 2/2] tpm: refactor tpm2_get_tpm_pt to tpm2_getcap_cmd
  2016-11-11  4:21   ` [tpmdd-devel] " Nayna
@ 2016-11-12  0:02     ` Jarkko Sakkinen
  2016-11-14 23:48       ` Jarkko Sakkinen
  2016-11-17 11:50       ` Nayna
  0 siblings, 2 replies; 16+ messages in thread
From: Jarkko Sakkinen @ 2016-11-12  0:02 UTC (permalink / raw)
  To: Nayna; +Cc: Peter Huewe, moderated list:TPM DEVICE DRIVER, open list

On Fri, Nov 11, 2016 at 09:51:45AM +0530, Nayna wrote:
> 
> 
> On 10/09/2016 03:44 PM, Jarkko Sakkinen wrote:
> > Refactored tpm2_get_tpm_pt to tpm2_getcap_cmd, which means that it also
> > takes capability ID as input. This is required to access
> > TPM_CAP_HANDLES, which contains metadata needed for swapping transient
> > data.
> > 
> > Signed-off-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
> > ---
> >   drivers/char/tpm/tpm.h          |  6 +++-
> >   drivers/char/tpm/tpm2-cmd.c     | 64 ++++++++++++++++++++---------------------
> >   drivers/char/tpm/tpm_tis_core.c |  3 +-
> >   3 files changed, 38 insertions(+), 35 deletions(-)
> > 
> > diff --git a/drivers/char/tpm/tpm.h b/drivers/char/tpm/tpm.h
> > index 0fab6d5..8176f42 100644
> > --- a/drivers/char/tpm/tpm.h
> > +++ b/drivers/char/tpm/tpm.h
> > @@ -85,6 +85,10 @@ enum tpm2_capabilities {
> >   	TPM2_CAP_TPM_PROPERTIES = 6,
> >   };
> > 
> > +enum tpm2_properties {
> > +	TPM2_PT_FAMILY_INDICATOR	= 0x100,
> > +};
> > +
> >   enum tpm2_startup_types {
> >   	TPM2_SU_CLEAR	= 0x0000,
> >   	TPM2_SU_STATE	= 0x0001,
> > @@ -485,7 +489,7 @@ int tpm2_seal_trusted(struct tpm_chip *chip,
> >   int tpm2_unseal_trusted(struct tpm_chip *chip,
> >   			struct trusted_key_payload *payload,
> >   			struct trusted_key_options *options);
> > -ssize_t tpm2_get_tpm_pt(struct tpm_chip *chip, u32 property_id,
> > +ssize_t tpm2_getcap_cmd(struct tpm_chip *chip, u32 cap_id, u32 property_id,
> >   			u32 *value, const char *desc);
> > 
> >   int tpm2_auto_startup(struct tpm_chip *chip);
> > diff --git a/drivers/char/tpm/tpm2-cmd.c b/drivers/char/tpm/tpm2-cmd.c
> > index 2900e18..fcf3d86 100644
> > --- a/drivers/char/tpm/tpm2-cmd.c
> > +++ b/drivers/char/tpm/tpm2-cmd.c
> > @@ -111,13 +111,13 @@ struct tpm2_pcr_extend_in {
> >   	u8				digest[TPM_DIGEST_SIZE];
> >   } __packed;
> > 
> > -struct tpm2_get_tpm_pt_in {
> > +struct tpm2_getcap_in {
> >   	__be32	cap_id;
> >   	__be32	property_id;
> >   	__be32	property_cnt;
> >   } __packed;
> > 
> > -struct tpm2_get_tpm_pt_out {
> > +struct tpm2_getcap_out {
> >   	u8	more_data;
> >   	__be32	subcap_id;
> >   	__be32	property_cnt;
> > @@ -140,8 +140,8 @@ union tpm2_cmd_params {
> >   	struct	tpm2_pcr_read_in	pcrread_in;
> >   	struct	tpm2_pcr_read_out	pcrread_out;
> >   	struct	tpm2_pcr_extend_in	pcrextend_in;
> > -	struct	tpm2_get_tpm_pt_in	get_tpm_pt_in;
> > -	struct	tpm2_get_tpm_pt_out	get_tpm_pt_out;
> > +	struct	tpm2_getcap_in		getcap_in;
> > +	struct	tpm2_getcap_out		getcap_out;
> >   	struct	tpm2_get_random_in	getrandom_in;
> >   	struct	tpm2_get_random_out	getrandom_out;
> >   };
> > @@ -435,16 +435,6 @@ int tpm2_get_random(struct tpm_chip *chip, u8 *out, size_t max)
> >   	return total ? total : -EIO;
> >   }
> > 
> > -#define TPM2_GET_TPM_PT_IN_SIZE \
> > -	(sizeof(struct tpm_input_header) + \
> > -	 sizeof(struct tpm2_get_tpm_pt_in))
> > -
> > -static const struct tpm_input_header tpm2_get_tpm_pt_header = {
> > -	.tag = cpu_to_be16(TPM2_ST_NO_SESSIONS),
> > -	.length = cpu_to_be32(TPM2_GET_TPM_PT_IN_SIZE),
> > -	.ordinal = cpu_to_be32(TPM2_CC_GET_CAPABILITY)
> > -};
> > -
> >   /**
> >    * Append TPMS_AUTH_COMMAND to the buffer. The buffer must be allocated with
> >    * tpm_buf_alloc().
> > @@ -750,35 +740,43 @@ out:
> >   	return rc;
> >   }
> > 
> > +#define TPM2_GETCAP_IN_SIZE \
> > +	(sizeof(struct tpm_input_header) + sizeof(struct tpm2_getcap_in))
> > +
> > +static const struct tpm_input_header tpm2_getcap_header = {
> > +	.tag = cpu_to_be16(TPM2_ST_NO_SESSIONS),
> > +	.length = cpu_to_be32(TPM2_GETCAP_IN_SIZE),
> > +	.ordinal = cpu_to_be32(TPM2_CC_GET_CAPABILITY)
> > +};
> > +
> >   /**
> > - * tpm2_get_tpm_pt() - get value of a TPM_CAP_TPM_PROPERTIES type property
> > - * @chip:		TPM chip to use.
> > - * @property_id:	property ID.
> > - * @value:		output variable.
> > + * tpm2_getcap_cmd() - execute a TPM2_GetCapability command
> > + * @chip:		TPM chip to use
> > + * @cap_id:		capability ID
> > + * @property_id:	property ID
> > + * @value:		value of the property
> >    * @desc:		passed to tpm_transmit_cmd()
> >    *
> > - * 0 is returned when the operation is successful. If a negative number is
> > - * returned it remarks a POSIX error code. If a positive number is returned
> > - * it remarks a TPM error.
> > + * Return: same as with tpm_transmit_cmd
> >    */
> > -ssize_t tpm2_get_tpm_pt(struct tpm_chip *chip, u32 property_id,  u32 *value,
> > -			const char *desc)
> > +ssize_t tpm2_getcap_cmd(struct tpm_chip *chip, u32 cap_id, u32 property_id,
> > +			u32 *value, const char *desc)
> 
> This function currently returns single value "u32 *value" as output data.
> 
> Some calling function expect list of values from capabilities output.
> For eg., get_active_banks() use TPM_CAP_PCRS capability to retrieve list of
> active banks. And this capability returns array of pcr selections(which is a
> struct representing each active PCR bank)
> 
> I was thinking, can we define output parameter as struct of cap_id and union
> of expected cap_data ?

Unless you have major concerns about performance, which I think are not
relevant here, calling this in a loop is perfectly adequate and a lot of
simpler than having a generic version (with moreData handling and
everything).

I would rather see uses of struct cap_t to shrink than to expand. The
same goes for other horrific unions that exist today in the driver.

/Jarkko

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [tpmdd-devel] [PATCH RFC 2/2] tpm: refactor tpm2_get_tpm_pt to tpm2_getcap_cmd
  2016-11-12  0:02     ` Jarkko Sakkinen
@ 2016-11-14 23:48       ` Jarkko Sakkinen
  2016-11-24 13:42         ` Nayna
  2016-11-17 11:50       ` Nayna
  1 sibling, 1 reply; 16+ messages in thread
From: Jarkko Sakkinen @ 2016-11-14 23:48 UTC (permalink / raw)
  To: Nayna; +Cc: moderated list:TPM DEVICE DRIVER, open list, linux-security-module

On Fri, Nov 11, 2016 at 04:02:43PM -0800, Jarkko Sakkinen wrote:
> On Fri, Nov 11, 2016 at 09:51:45AM +0530, Nayna wrote:
> > 
> > 
> > On 10/09/2016 03:44 PM, Jarkko Sakkinen wrote:
> > > Refactored tpm2_get_tpm_pt to tpm2_getcap_cmd, which means that it also
> > > takes capability ID as input. This is required to access
> > > TPM_CAP_HANDLES, which contains metadata needed for swapping transient
> > > data.
> > > 
> > > Signed-off-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
> > > ---
> > >   drivers/char/tpm/tpm.h          |  6 +++-
> > >   drivers/char/tpm/tpm2-cmd.c     | 64 ++++++++++++++++++++---------------------
> > >   drivers/char/tpm/tpm_tis_core.c |  3 +-
> > >   3 files changed, 38 insertions(+), 35 deletions(-)
> > > 
> > > diff --git a/drivers/char/tpm/tpm.h b/drivers/char/tpm/tpm.h
> > > index 0fab6d5..8176f42 100644
> > > --- a/drivers/char/tpm/tpm.h
> > > +++ b/drivers/char/tpm/tpm.h
> > > @@ -85,6 +85,10 @@ enum tpm2_capabilities {
> > >   	TPM2_CAP_TPM_PROPERTIES = 6,
> > >   };
> > > 
> > > +enum tpm2_properties {
> > > +	TPM2_PT_FAMILY_INDICATOR	= 0x100,
> > > +};
> > > +
> > >   enum tpm2_startup_types {
> > >   	TPM2_SU_CLEAR	= 0x0000,
> > >   	TPM2_SU_STATE	= 0x0001,
> > > @@ -485,7 +489,7 @@ int tpm2_seal_trusted(struct tpm_chip *chip,
> > >   int tpm2_unseal_trusted(struct tpm_chip *chip,
> > >   			struct trusted_key_payload *payload,
> > >   			struct trusted_key_options *options);
> > > -ssize_t tpm2_get_tpm_pt(struct tpm_chip *chip, u32 property_id,
> > > +ssize_t tpm2_getcap_cmd(struct tpm_chip *chip, u32 cap_id, u32 property_id,
> > >   			u32 *value, const char *desc);
> > > 
> > >   int tpm2_auto_startup(struct tpm_chip *chip);
> > > diff --git a/drivers/char/tpm/tpm2-cmd.c b/drivers/char/tpm/tpm2-cmd.c
> > > index 2900e18..fcf3d86 100644
> > > --- a/drivers/char/tpm/tpm2-cmd.c
> > > +++ b/drivers/char/tpm/tpm2-cmd.c
> > > @@ -111,13 +111,13 @@ struct tpm2_pcr_extend_in {
> > >   	u8				digest[TPM_DIGEST_SIZE];
> > >   } __packed;
> > > 
> > > -struct tpm2_get_tpm_pt_in {
> > > +struct tpm2_getcap_in {
> > >   	__be32	cap_id;
> > >   	__be32	property_id;
> > >   	__be32	property_cnt;
> > >   } __packed;
> > > 
> > > -struct tpm2_get_tpm_pt_out {
> > > +struct tpm2_getcap_out {
> > >   	u8	more_data;
> > >   	__be32	subcap_id;
> > >   	__be32	property_cnt;
> > > @@ -140,8 +140,8 @@ union tpm2_cmd_params {
> > >   	struct	tpm2_pcr_read_in	pcrread_in;
> > >   	struct	tpm2_pcr_read_out	pcrread_out;
> > >   	struct	tpm2_pcr_extend_in	pcrextend_in;
> > > -	struct	tpm2_get_tpm_pt_in	get_tpm_pt_in;
> > > -	struct	tpm2_get_tpm_pt_out	get_tpm_pt_out;
> > > +	struct	tpm2_getcap_in		getcap_in;
> > > +	struct	tpm2_getcap_out		getcap_out;
> > >   	struct	tpm2_get_random_in	getrandom_in;
> > >   	struct	tpm2_get_random_out	getrandom_out;
> > >   };
> > > @@ -435,16 +435,6 @@ int tpm2_get_random(struct tpm_chip *chip, u8 *out, size_t max)
> > >   	return total ? total : -EIO;
> > >   }
> > > 
> > > -#define TPM2_GET_TPM_PT_IN_SIZE \
> > > -	(sizeof(struct tpm_input_header) + \
> > > -	 sizeof(struct tpm2_get_tpm_pt_in))
> > > -
> > > -static const struct tpm_input_header tpm2_get_tpm_pt_header = {
> > > -	.tag = cpu_to_be16(TPM2_ST_NO_SESSIONS),
> > > -	.length = cpu_to_be32(TPM2_GET_TPM_PT_IN_SIZE),
> > > -	.ordinal = cpu_to_be32(TPM2_CC_GET_CAPABILITY)
> > > -};
> > > -
> > >   /**
> > >    * Append TPMS_AUTH_COMMAND to the buffer. The buffer must be allocated with
> > >    * tpm_buf_alloc().
> > > @@ -750,35 +740,43 @@ out:
> > >   	return rc;
> > >   }
> > > 
> > > +#define TPM2_GETCAP_IN_SIZE \
> > > +	(sizeof(struct tpm_input_header) + sizeof(struct tpm2_getcap_in))
> > > +
> > > +static const struct tpm_input_header tpm2_getcap_header = {
> > > +	.tag = cpu_to_be16(TPM2_ST_NO_SESSIONS),
> > > +	.length = cpu_to_be32(TPM2_GETCAP_IN_SIZE),
> > > +	.ordinal = cpu_to_be32(TPM2_CC_GET_CAPABILITY)
> > > +};
> > > +
> > >   /**
> > > - * tpm2_get_tpm_pt() - get value of a TPM_CAP_TPM_PROPERTIES type property
> > > - * @chip:		TPM chip to use.
> > > - * @property_id:	property ID.
> > > - * @value:		output variable.
> > > + * tpm2_getcap_cmd() - execute a TPM2_GetCapability command
> > > + * @chip:		TPM chip to use
> > > + * @cap_id:		capability ID
> > > + * @property_id:	property ID
> > > + * @value:		value of the property
> > >    * @desc:		passed to tpm_transmit_cmd()
> > >    *
> > > - * 0 is returned when the operation is successful. If a negative number is
> > > - * returned it remarks a POSIX error code. If a positive number is returned
> > > - * it remarks a TPM error.
> > > + * Return: same as with tpm_transmit_cmd
> > >    */
> > > -ssize_t tpm2_get_tpm_pt(struct tpm_chip *chip, u32 property_id,  u32 *value,
> > > -			const char *desc)
> > > +ssize_t tpm2_getcap_cmd(struct tpm_chip *chip, u32 cap_id, u32 property_id,
> > > +			u32 *value, const char *desc)
> > 
> > This function currently returns single value "u32 *value" as output data.
> > 
> > Some calling function expect list of values from capabilities output.
> > For eg., get_active_banks() use TPM_CAP_PCRS capability to retrieve list of
> > active banks. And this capability returns array of pcr selections(which is a
> > struct representing each active PCR bank)
> > 
> > I was thinking, can we define output parameter as struct of cap_id and union
> > of expected cap_data ?
> 
> Unless you have major concerns about performance, which I think are not
> relevant here, calling this in a loop is perfectly adequate and a lot of
> simpler than having a generic version (with moreData handling and
> everything).
> 
> I would rather see uses of struct cap_t to shrink than to expand. The
> same goes for other horrific unions that exist today in the driver.

If you are fine with this patch (give Reviewed-by) I can apply this
and add to my 4.10 pull request so that we have common baseline to
develop both event log and the resource manager.

This is a very low risk commit to take to 4.10 because it is only used
for interrupt generation in the TIS driver at the moment.

/Jarkko

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [tpmdd-devel] [PATCH RFC 2/2] tpm: refactor tpm2_get_tpm_pt to tpm2_getcap_cmd
  2016-11-12  0:02     ` Jarkko Sakkinen
  2016-11-14 23:48       ` Jarkko Sakkinen
@ 2016-11-17 11:50       ` Nayna
  2016-11-17 17:42         ` Jarkko Sakkinen
  1 sibling, 1 reply; 16+ messages in thread
From: Nayna @ 2016-11-17 11:50 UTC (permalink / raw)
  To: Jarkko Sakkinen; +Cc: Peter Huewe, moderated list:TPM DEVICE DRIVER, open list



On 11/12/2016 05:32 AM, Jarkko Sakkinen wrote:
> On Fri, Nov 11, 2016 at 09:51:45AM +0530, Nayna wrote:
>>
>>
>> On 10/09/2016 03:44 PM, Jarkko Sakkinen wrote:
>>> Refactored tpm2_get_tpm_pt to tpm2_getcap_cmd, which means that it also
>>> takes capability ID as input. This is required to access
>>> TPM_CAP_HANDLES, which contains metadata needed for swapping transient
>>> data.
>>>
>>> Signed-off-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
>>> ---
>>>    drivers/char/tpm/tpm.h          |  6 +++-
>>>    drivers/char/tpm/tpm2-cmd.c     | 64 ++++++++++++++++++++---------------------
>>>    drivers/char/tpm/tpm_tis_core.c |  3 +-
>>>    3 files changed, 38 insertions(+), 35 deletions(-)
>>>
>>> diff --git a/drivers/char/tpm/tpm.h b/drivers/char/tpm/tpm.h
>>> index 0fab6d5..8176f42 100644
>>> --- a/drivers/char/tpm/tpm.h
>>> +++ b/drivers/char/tpm/tpm.h
>>> @@ -85,6 +85,10 @@ enum tpm2_capabilities {
>>>    	TPM2_CAP_TPM_PROPERTIES = 6,
>>>    };
>>>
>>> +enum tpm2_properties {
>>> +	TPM2_PT_FAMILY_INDICATOR	= 0x100,
>>> +};
>>> +
>>>    enum tpm2_startup_types {
>>>    	TPM2_SU_CLEAR	= 0x0000,
>>>    	TPM2_SU_STATE	= 0x0001,
>>> @@ -485,7 +489,7 @@ int tpm2_seal_trusted(struct tpm_chip *chip,
>>>    int tpm2_unseal_trusted(struct tpm_chip *chip,
>>>    			struct trusted_key_payload *payload,
>>>    			struct trusted_key_options *options);
>>> -ssize_t tpm2_get_tpm_pt(struct tpm_chip *chip, u32 property_id,
>>> +ssize_t tpm2_getcap_cmd(struct tpm_chip *chip, u32 cap_id, u32 property_id,
>>>    			u32 *value, const char *desc);
>>>
>>>    int tpm2_auto_startup(struct tpm_chip *chip);
>>> diff --git a/drivers/char/tpm/tpm2-cmd.c b/drivers/char/tpm/tpm2-cmd.c
>>> index 2900e18..fcf3d86 100644
>>> --- a/drivers/char/tpm/tpm2-cmd.c
>>> +++ b/drivers/char/tpm/tpm2-cmd.c
>>> @@ -111,13 +111,13 @@ struct tpm2_pcr_extend_in {
>>>    	u8				digest[TPM_DIGEST_SIZE];
>>>    } __packed;
>>>
>>> -struct tpm2_get_tpm_pt_in {
>>> +struct tpm2_getcap_in {
>>>    	__be32	cap_id;
>>>    	__be32	property_id;
>>>    	__be32	property_cnt;
>>>    } __packed;
>>>
>>> -struct tpm2_get_tpm_pt_out {
>>> +struct tpm2_getcap_out {
>>>    	u8	more_data;
>>>    	__be32	subcap_id;
>>>    	__be32	property_cnt;
>>> @@ -140,8 +140,8 @@ union tpm2_cmd_params {
>>>    	struct	tpm2_pcr_read_in	pcrread_in;
>>>    	struct	tpm2_pcr_read_out	pcrread_out;
>>>    	struct	tpm2_pcr_extend_in	pcrextend_in;
>>> -	struct	tpm2_get_tpm_pt_in	get_tpm_pt_in;
>>> -	struct	tpm2_get_tpm_pt_out	get_tpm_pt_out;
>>> +	struct	tpm2_getcap_in		getcap_in;
>>> +	struct	tpm2_getcap_out		getcap_out;
>>>    	struct	tpm2_get_random_in	getrandom_in;
>>>    	struct	tpm2_get_random_out	getrandom_out;
>>>    };
>>> @@ -435,16 +435,6 @@ int tpm2_get_random(struct tpm_chip *chip, u8 *out, size_t max)
>>>    	return total ? total : -EIO;
>>>    }
>>>
>>> -#define TPM2_GET_TPM_PT_IN_SIZE \
>>> -	(sizeof(struct tpm_input_header) + \
>>> -	 sizeof(struct tpm2_get_tpm_pt_in))
>>> -
>>> -static const struct tpm_input_header tpm2_get_tpm_pt_header = {
>>> -	.tag = cpu_to_be16(TPM2_ST_NO_SESSIONS),
>>> -	.length = cpu_to_be32(TPM2_GET_TPM_PT_IN_SIZE),
>>> -	.ordinal = cpu_to_be32(TPM2_CC_GET_CAPABILITY)
>>> -};
>>> -
>>>    /**
>>>     * Append TPMS_AUTH_COMMAND to the buffer. The buffer must be allocated with
>>>     * tpm_buf_alloc().
>>> @@ -750,35 +740,43 @@ out:
>>>    	return rc;
>>>    }
>>>
>>> +#define TPM2_GETCAP_IN_SIZE \
>>> +	(sizeof(struct tpm_input_header) + sizeof(struct tpm2_getcap_in))
>>> +
>>> +static const struct tpm_input_header tpm2_getcap_header = {
>>> +	.tag = cpu_to_be16(TPM2_ST_NO_SESSIONS),
>>> +	.length = cpu_to_be32(TPM2_GETCAP_IN_SIZE),
>>> +	.ordinal = cpu_to_be32(TPM2_CC_GET_CAPABILITY)
>>> +};
>>> +
>>>    /**
>>> - * tpm2_get_tpm_pt() - get value of a TPM_CAP_TPM_PROPERTIES type property
>>> - * @chip:		TPM chip to use.
>>> - * @property_id:	property ID.
>>> - * @value:		output variable.
>>> + * tpm2_getcap_cmd() - execute a TPM2_GetCapability command
>>> + * @chip:		TPM chip to use
>>> + * @cap_id:		capability ID
>>> + * @property_id:	property ID
>>> + * @value:		value of the property
>>>     * @desc:		passed to tpm_transmit_cmd()
>>>     *
>>> - * 0 is returned when the operation is successful. If a negative number is
>>> - * returned it remarks a POSIX error code. If a positive number is returned
>>> - * it remarks a TPM error.
>>> + * Return: same as with tpm_transmit_cmd
>>>     */
>>> -ssize_t tpm2_get_tpm_pt(struct tpm_chip *chip, u32 property_id,  u32 *value,
>>> -			const char *desc)
>>> +ssize_t tpm2_getcap_cmd(struct tpm_chip *chip, u32 cap_id, u32 property_id,
>>> +			u32 *value, const char *desc)
>>
>> This function currently returns single value "u32 *value" as output data.
>>
>> Some calling function expect list of values from capabilities output.
>> For eg., get_active_banks() use TPM_CAP_PCRS capability to retrieve list of
>> active banks. And this capability returns array of pcr selections(which is a
>> struct representing each active PCR bank)
>>
>> I was thinking, can we define output parameter as struct of cap_id and union
>> of expected cap_data ?
>
> Unless you have major concerns about performance, which I think are not
> relevant here, calling this in a loop is perfectly adequate and a lot of
> simpler than having a generic version (with moreData handling and
> everything).
>
> I would rather see uses of struct cap_t to shrink than to expand. The
> same goes for other horrific unions that exist today in the driver.

I agree with the idea of not using union.

I tested this for capability TPM2_CAP_PCRS. It seems TPM2_CAP_PCRS 
capability always returns full PCR allocation, and more_data as 0, So, I 
think the idea of looping over based on more_data may not work for this 
capability.

I was thinking in place of having u32 *value returning actual value, can 
we have it as void *value, where getcap_cmd will memcpy its out 
parameter content after subcap_id to value, and then calling function 
typecast to expected type and use it.

Please let me know if I am missing something in using this function.

Thanks & Regards,
    - Nayna


>
> /Jarkko
>

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [tpmdd-devel] [PATCH RFC 2/2] tpm: refactor tpm2_get_tpm_pt to tpm2_getcap_cmd
  2016-11-17 11:50       ` Nayna
@ 2016-11-17 17:42         ` Jarkko Sakkinen
  2016-11-18 12:12           ` Nayna
  0 siblings, 1 reply; 16+ messages in thread
From: Jarkko Sakkinen @ 2016-11-17 17:42 UTC (permalink / raw)
  To: Nayna; +Cc: Peter Huewe, moderated list:TPM DEVICE DRIVER, open list

On Thu, Nov 17, 2016 at 05:20:36PM +0530, Nayna wrote:
 
> I tested this for capability TPM2_CAP_PCRS. It seems TPM2_CAP_PCRS
> capability always returns full PCR allocation, and more_data as 0, So, I
> think the idea of looping over based on more_data may not work for this
> capability.

You can always request one value at a time until there's no more.

If you request N values, depending on the hardware, the hardware returns
to you anything from 1 to N values. If you implement a function that
requests N values in the command, you *must* handle the case where
moreData is 1 even if the hardware you are testing that never happens.

That's the reason why I would start with a function that you request one
property of one capability and optimize it in future if it doesn't scale
for some workload.

Do you have a workload where it doesn't scale?

/Jarkko

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [tpmdd-devel] [PATCH RFC 2/2] tpm: refactor tpm2_get_tpm_pt to tpm2_getcap_cmd
  2016-11-17 17:42         ` Jarkko Sakkinen
@ 2016-11-18 12:12           ` Nayna
  2016-11-18 16:13             ` Jarkko Sakkinen
  0 siblings, 1 reply; 16+ messages in thread
From: Nayna @ 2016-11-18 12:12 UTC (permalink / raw)
  To: Jarkko Sakkinen; +Cc: Peter Huewe, moderated list:TPM DEVICE DRIVER, open list



On 11/17/2016 11:12 PM, Jarkko Sakkinen wrote:
> On Thu, Nov 17, 2016 at 05:20:36PM +0530, Nayna wrote:
>
>> I tested this for capability TPM2_CAP_PCRS. It seems TPM2_CAP_PCRS
>> capability always returns full PCR allocation, and more_data as 0, So, I
>> think the idea of looping over based on more_data may not work for this
>> capability.
>
> You can always request one value at a time until there's no more.
>
> If you request N values, depending on the hardware, the hardware returns
> to you anything from 1 to N values. If you implement a function that
> requests N values in the command, you *must* handle the case where
> moreData is 1 even if the hardware you are testing that never happens.
>
> That's the reason why I would start with a function that you request one
> property of one capability and optimize it in future if it doesn't scale
> for some workload.
>
> Do you have a workload where it doesn't scale?

Thanks Jarkko for explaining in detail.

If I understood correctly, the idea is to request for one property at a 
time, and if we need multiple properties, then to request for each of 
them in a loop. In case of TPM2_CAP_PCRS, property is always zero. This 
is how I am calling getcap_cmd for TPM2_CAP_PCRS.

tpm2_getcap_cmd(chip, TPM2_CAP_PCRS, 0, &cap_data, "get active pcr 
banks");

Output :

[   17.081665] tpm: cap id to receive value is 2
[   17.081666] tpm: TPM2_CAP_COMMANDS: more data 1
[   17.081667] tpm: 2
[   17.081668] tpm: tpm2_get_active_banks  -------> cap is TPM2_CAP_PCRS
[   17.171665] tpm: cap id to receive value is 5
[   17.171666] tpm: TPM2_CAP_PCRS: more data 0 ---> more data is zero.
[   17.171666] tpm: TPM2_CAP_PCRS: more data 0
[   17.171667] tpm: count pcr banks is 2 ------> count of active pcr 
banks information returned

more_data is always zero here, so am not sure how to handle more_data in 
this case ?
Since property_id is always zero, I am not able to request for one 
property at a time.
and response_buffer returns the details for both active banks.

This is the expected behavior defined in TCG 2.0 Part 3 Commands 
Specification (Section 30.2.1):

"TPM_CAP_PCRS – Returns the current allocation of PCR in a 
TPML_PCR_SELECTION. The property parameter shall be zero. The TPM will 
always respond to this command with the full PCR allocation and moreData 
will be NO."

Please let me know, if I am missing something.

Thanks & Regards,
    - Nayna


>
> /Jarkko
>

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [tpmdd-devel] [PATCH RFC 2/2] tpm: refactor tpm2_get_tpm_pt to tpm2_getcap_cmd
  2016-11-18 12:12           ` Nayna
@ 2016-11-18 16:13             ` Jarkko Sakkinen
  2016-11-22  9:08               ` Nayna
  0 siblings, 1 reply; 16+ messages in thread
From: Jarkko Sakkinen @ 2016-11-18 16:13 UTC (permalink / raw)
  To: Nayna; +Cc: Peter Huewe, moderated list:TPM DEVICE DRIVER, open list

On Fri, Nov 18, 2016 at 05:42:01PM +0530, Nayna wrote:
> 
> 
> On 11/17/2016 11:12 PM, Jarkko Sakkinen wrote:
> > On Thu, Nov 17, 2016 at 05:20:36PM +0530, Nayna wrote:
> > 
> > > I tested this for capability TPM2_CAP_PCRS. It seems TPM2_CAP_PCRS
> > > capability always returns full PCR allocation, and more_data as 0, So, I
> > > think the idea of looping over based on more_data may not work for this
> > > capability.
> > 
> > You can always request one value at a time until there's no more.
> > 
> > If you request N values, depending on the hardware, the hardware returns
> > to you anything from 1 to N values. If you implement a function that
> > requests N values in the command, you *must* handle the case where
> > moreData is 1 even if the hardware you are testing that never happens.
> > 
> > That's the reason why I would start with a function that you request one
> > property of one capability and optimize it in future if it doesn't scale
> > for some workload.
> > 
> > Do you have a workload where it doesn't scale?
> 
> Thanks Jarkko for explaining in detail.
> 
> If I understood correctly, the idea is to request for one property at a
> time, and if we need multiple properties, then to request for each of them
> in a loop. In case of TPM2_CAP_PCRS, property is always zero. This is how I
> am calling getcap_cmd for TPM2_CAP_PCRS.
> 
> tpm2_getcap_cmd(chip, TPM2_CAP_PCRS, 0, &cap_data, "get active pcr banks");
> 
> Output :
> 
> [   17.081665] tpm: cap id to receive value is 2
> [   17.081666] tpm: TPM2_CAP_COMMANDS: more data 1
> [   17.081667] tpm: 2
> [   17.081668] tpm: tpm2_get_active_banks  -------> cap is TPM2_CAP_PCRS
> [   17.171665] tpm: cap id to receive value is 5
> [   17.171666] tpm: TPM2_CAP_PCRS: more data 0 ---> more data is zero.
> [   17.171666] tpm: TPM2_CAP_PCRS: more data 0
> [   17.171667] tpm: count pcr banks is 2 ------> count of active pcr banks
> information returned
> 
> more_data is always zero here, so am not sure how to handle more_data in
> this case ?
> Since property_id is always zero, I am not able to request for one property
> at a time.
> and response_buffer returns the details for both active banks.
> 
> This is the expected behavior defined in TCG 2.0 Part 3 Commands
> Specification (Section 30.2.1):
> 
> "TPM_CAP_PCRS – Returns the current allocation of PCR in a
> TPML_PCR_SELECTION. The property parameter shall be zero. The TPM will
> always respond to this command with the full PCR allocation and moreData
> will be NO."
> 
> Please let me know, if I am missing something.

Thanks for pointing that. I think you got it right and I had some wrong
assumptions about 'moreData'.

Here's what I propose. Do a non-generic function just for getting CAP_PCRS.
You could call it tpm2_get_pcr_allocation() as you don't want or rather
need to handle all the bells and whistles in that TPM command.

It makes a lot more sense now than having one-size-for-all function.

/Jarkko

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [tpmdd-devel] [PATCH RFC 2/2] tpm: refactor tpm2_get_tpm_pt to tpm2_getcap_cmd
  2016-11-18 16:13             ` Jarkko Sakkinen
@ 2016-11-22  9:08               ` Nayna
  2016-11-22 11:03                 ` Jarkko Sakkinen
  0 siblings, 1 reply; 16+ messages in thread
From: Nayna @ 2016-11-22  9:08 UTC (permalink / raw)
  To: Jarkko Sakkinen; +Cc: Peter Huewe, moderated list:TPM DEVICE DRIVER, open list



On 11/18/2016 09:43 PM, Jarkko Sakkinen wrote:
> On Fri, Nov 18, 2016 at 05:42:01PM +0530, Nayna wrote:
>>
>>
>> On 11/17/2016 11:12 PM, Jarkko Sakkinen wrote:
>>> On Thu, Nov 17, 2016 at 05:20:36PM +0530, Nayna wrote:
>>>
>>>> I tested this for capability TPM2_CAP_PCRS. It seems TPM2_CAP_PCRS
>>>> capability always returns full PCR allocation, and more_data as 0, So, I
>>>> think the idea of looping over based on more_data may not work for this
>>>> capability.
>>>
>>> You can always request one value at a time until there's no more.
>>>
>>> If you request N values, depending on the hardware, the hardware returns
>>> to you anything from 1 to N values. If you implement a function that
>>> requests N values in the command, you *must* handle the case where
>>> moreData is 1 even if the hardware you are testing that never happens.
>>>
>>> That's the reason why I would start with a function that you request one
>>> property of one capability and optimize it in future if it doesn't scale
>>> for some workload.
>>>
>>> Do you have a workload where it doesn't scale?
>>
>> Thanks Jarkko for explaining in detail.
>>
>> If I understood correctly, the idea is to request for one property at a
>> time, and if we need multiple properties, then to request for each of them
>> in a loop. In case of TPM2_CAP_PCRS, property is always zero. This is how I
>> am calling getcap_cmd for TPM2_CAP_PCRS.
>>
>> tpm2_getcap_cmd(chip, TPM2_CAP_PCRS, 0, &cap_data, "get active pcr banks");
>>
>> Output :
>>
>> [   17.081665] tpm: cap id to receive value is 2
>> [   17.081666] tpm: TPM2_CAP_COMMANDS: more data 1
>> [   17.081667] tpm: 2
>> [   17.081668] tpm: tpm2_get_active_banks  -------> cap is TPM2_CAP_PCRS
>> [   17.171665] tpm: cap id to receive value is 5
>> [   17.171666] tpm: TPM2_CAP_PCRS: more data 0 ---> more data is zero.
>> [   17.171666] tpm: TPM2_CAP_PCRS: more data 0
>> [   17.171667] tpm: count pcr banks is 2 ------> count of active pcr banks
>> information returned
>>
>> more_data is always zero here, so am not sure how to handle more_data in
>> this case ?
>> Since property_id is always zero, I am not able to request for one property
>> at a time.
>> and response_buffer returns the details for both active banks.
>>
>> This is the expected behavior defined in TCG 2.0 Part 3 Commands
>> Specification (Section 30.2.1):
>>
>> "TPM_CAP_PCRS – Returns the current allocation of PCR in a
>> TPML_PCR_SELECTION. The property parameter shall be zero. The TPM will
>> always respond to this command with the full PCR allocation and moreData
>> will be NO."
>>
>> Please let me know, if I am missing something.
>
> Thanks for pointing that. I think you got it right and I had some wrong
> assumptions about 'moreData'.
>
> Here's what I propose. Do a non-generic function just for getting CAP_PCRS.
> You could call it tpm2_get_pcr_allocation() as you don't want or rather
> need to handle all the bells and whistles in that TPM command.
>
> It makes a lot more sense now than having one-size-for-all function.

Thanks Jarkko, Yeah, Sure, I will write it as different non-generic call.
Otherwise, the function works good.
Also, I am thinking now I can write "multi-bank support for extend" on 
top of master branch itself.  Any issues with that ?

Thanks & Regards,
    - Nayna

>
> /Jarkko
>

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [tpmdd-devel] [PATCH RFC 2/2] tpm: refactor tpm2_get_tpm_pt to tpm2_getcap_cmd
  2016-11-22  9:08               ` Nayna
@ 2016-11-22 11:03                 ` Jarkko Sakkinen
  0 siblings, 0 replies; 16+ messages in thread
From: Jarkko Sakkinen @ 2016-11-22 11:03 UTC (permalink / raw)
  To: Nayna; +Cc: Peter Huewe, moderated list:TPM DEVICE DRIVER, open list

On Tue, Nov 22, 2016 at 02:38:21PM +0530, Nayna wrote:
> 
> 
> On 11/18/2016 09:43 PM, Jarkko Sakkinen wrote:
> > On Fri, Nov 18, 2016 at 05:42:01PM +0530, Nayna wrote:
> > > 
> > > 
> > > On 11/17/2016 11:12 PM, Jarkko Sakkinen wrote:
> > > > On Thu, Nov 17, 2016 at 05:20:36PM +0530, Nayna wrote:
> > > > 
> > > > > I tested this for capability TPM2_CAP_PCRS. It seems TPM2_CAP_PCRS
> > > > > capability always returns full PCR allocation, and more_data as 0, So, I
> > > > > think the idea of looping over based on more_data may not work for this
> > > > > capability.
> > > > 
> > > > You can always request one value at a time until there's no more.
> > > > 
> > > > If you request N values, depending on the hardware, the hardware returns
> > > > to you anything from 1 to N values. If you implement a function that
> > > > requests N values in the command, you *must* handle the case where
> > > > moreData is 1 even if the hardware you are testing that never happens.
> > > > 
> > > > That's the reason why I would start with a function that you request one
> > > > property of one capability and optimize it in future if it doesn't scale
> > > > for some workload.
> > > > 
> > > > Do you have a workload where it doesn't scale?
> > > 
> > > Thanks Jarkko for explaining in detail.
> > > 
> > > If I understood correctly, the idea is to request for one property at a
> > > time, and if we need multiple properties, then to request for each of them
> > > in a loop. In case of TPM2_CAP_PCRS, property is always zero. This is how I
> > > am calling getcap_cmd for TPM2_CAP_PCRS.
> > > 
> > > tpm2_getcap_cmd(chip, TPM2_CAP_PCRS, 0, &cap_data, "get active pcr banks");
> > > 
> > > Output :
> > > 
> > > [   17.081665] tpm: cap id to receive value is 2
> > > [   17.081666] tpm: TPM2_CAP_COMMANDS: more data 1
> > > [   17.081667] tpm: 2
> > > [   17.081668] tpm: tpm2_get_active_banks  -------> cap is TPM2_CAP_PCRS
> > > [   17.171665] tpm: cap id to receive value is 5
> > > [   17.171666] tpm: TPM2_CAP_PCRS: more data 0 ---> more data is zero.
> > > [   17.171666] tpm: TPM2_CAP_PCRS: more data 0
> > > [   17.171667] tpm: count pcr banks is 2 ------> count of active pcr banks
> > > information returned
> > > 
> > > more_data is always zero here, so am not sure how to handle more_data in
> > > this case ?
> > > Since property_id is always zero, I am not able to request for one property
> > > at a time.
> > > and response_buffer returns the details for both active banks.
> > > 
> > > This is the expected behavior defined in TCG 2.0 Part 3 Commands
> > > Specification (Section 30.2.1):
> > > 
> > > "TPM_CAP_PCRS – Returns the current allocation of PCR in a
> > > TPML_PCR_SELECTION. The property parameter shall be zero. The TPM will
> > > always respond to this command with the full PCR allocation and moreData
> > > will be NO."
> > > 
> > > Please let me know, if I am missing something.
> > 
> > Thanks for pointing that. I think you got it right and I had some wrong
> > assumptions about 'moreData'.
> > 
> > Here's what I propose. Do a non-generic function just for getting CAP_PCRS.
> > You could call it tpm2_get_pcr_allocation() as you don't want or rather
> > need to handle all the bells and whistles in that TPM command.
> > 
> > It makes a lot more sense now than having one-size-for-all function.
> 
> Thanks Jarkko, Yeah, Sure, I will write it as different non-generic call.
> Otherwise, the function works good.
> Also, I am thinking now I can write "multi-bank support for extend" on top
> of master branch itself.  Any issues with that ?

I'm not sure what exactly I should or should not have an issue with.

I can check the patch but won't apply or test it before it is used for
something if that is what you are asking.

/Jarkko

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [tpmdd-devel] [PATCH RFC 2/2] tpm: refactor tpm2_get_tpm_pt to tpm2_getcap_cmd
  2016-11-14 23:48       ` Jarkko Sakkinen
@ 2016-11-24 13:42         ` Nayna
  2016-11-25  8:09           ` Jarkko Sakkinen
  0 siblings, 1 reply; 16+ messages in thread
From: Nayna @ 2016-11-24 13:42 UTC (permalink / raw)
  To: Jarkko Sakkinen
  Cc: moderated list:TPM DEVICE DRIVER, open list, linux-security-module



On 11/15/2016 05:18 AM, Jarkko Sakkinen wrote:
> On Fri, Nov 11, 2016 at 04:02:43PM -0800, Jarkko Sakkinen wrote:
>> On Fri, Nov 11, 2016 at 09:51:45AM +0530, Nayna wrote:
>>>
>>>
>>> On 10/09/2016 03:44 PM, Jarkko Sakkinen wrote:
>>>> Refactored tpm2_get_tpm_pt to tpm2_getcap_cmd, which means that it also
>>>> takes capability ID as input. This is required to access
>>>> TPM_CAP_HANDLES, which contains metadata needed for swapping transient
>>>> data.
>>>>
>>>> Signed-off-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
>>>> ---
>>>>    drivers/char/tpm/tpm.h          |  6 +++-
>>>>    drivers/char/tpm/tpm2-cmd.c     | 64 ++++++++++++++++++++---------------------
>>>>    drivers/char/tpm/tpm_tis_core.c |  3 +-
>>>>    3 files changed, 38 insertions(+), 35 deletions(-)
>>>>
>>>> diff --git a/drivers/char/tpm/tpm.h b/drivers/char/tpm/tpm.h
>>>> index 0fab6d5..8176f42 100644
>>>> --- a/drivers/char/tpm/tpm.h
>>>> +++ b/drivers/char/tpm/tpm.h
>>>> @@ -85,6 +85,10 @@ enum tpm2_capabilities {
>>>>    	TPM2_CAP_TPM_PROPERTIES = 6,
>>>>    };
>>>>
>>>> +enum tpm2_properties {
>>>> +	TPM2_PT_FAMILY_INDICATOR	= 0x100,
>>>> +};
>>>> +
>>>>    enum tpm2_startup_types {
>>>>    	TPM2_SU_CLEAR	= 0x0000,
>>>>    	TPM2_SU_STATE	= 0x0001,
>>>> @@ -485,7 +489,7 @@ int tpm2_seal_trusted(struct tpm_chip *chip,
>>>>    int tpm2_unseal_trusted(struct tpm_chip *chip,
>>>>    			struct trusted_key_payload *payload,
>>>>    			struct trusted_key_options *options);
>>>> -ssize_t tpm2_get_tpm_pt(struct tpm_chip *chip, u32 property_id,
>>>> +ssize_t tpm2_getcap_cmd(struct tpm_chip *chip, u32 cap_id, u32 property_id,
>>>>    			u32 *value, const char *desc);
>>>>
>>>>    int tpm2_auto_startup(struct tpm_chip *chip);
>>>> diff --git a/drivers/char/tpm/tpm2-cmd.c b/drivers/char/tpm/tpm2-cmd.c
>>>> index 2900e18..fcf3d86 100644
>>>> --- a/drivers/char/tpm/tpm2-cmd.c
>>>> +++ b/drivers/char/tpm/tpm2-cmd.c
>>>> @@ -111,13 +111,13 @@ struct tpm2_pcr_extend_in {
>>>>    	u8				digest[TPM_DIGEST_SIZE];
>>>>    } __packed;
>>>>
>>>> -struct tpm2_get_tpm_pt_in {
>>>> +struct tpm2_getcap_in {
>>>>    	__be32	cap_id;
>>>>    	__be32	property_id;
>>>>    	__be32	property_cnt;
>>>>    } __packed;
>>>>
>>>> -struct tpm2_get_tpm_pt_out {
>>>> +struct tpm2_getcap_out {
>>>>    	u8	more_data;
>>>>    	__be32	subcap_id;
>>>>    	__be32	property_cnt;
>>>> @@ -140,8 +140,8 @@ union tpm2_cmd_params {
>>>>    	struct	tpm2_pcr_read_in	pcrread_in;
>>>>    	struct	tpm2_pcr_read_out	pcrread_out;
>>>>    	struct	tpm2_pcr_extend_in	pcrextend_in;
>>>> -	struct	tpm2_get_tpm_pt_in	get_tpm_pt_in;
>>>> -	struct	tpm2_get_tpm_pt_out	get_tpm_pt_out;
>>>> +	struct	tpm2_getcap_in		getcap_in;
>>>> +	struct	tpm2_getcap_out		getcap_out;
>>>>    	struct	tpm2_get_random_in	getrandom_in;
>>>>    	struct	tpm2_get_random_out	getrandom_out;
>>>>    };
>>>> @@ -435,16 +435,6 @@ int tpm2_get_random(struct tpm_chip *chip, u8 *out, size_t max)
>>>>    	return total ? total : -EIO;
>>>>    }
>>>>
>>>> -#define TPM2_GET_TPM_PT_IN_SIZE \
>>>> -	(sizeof(struct tpm_input_header) + \
>>>> -	 sizeof(struct tpm2_get_tpm_pt_in))
>>>> -
>>>> -static const struct tpm_input_header tpm2_get_tpm_pt_header = {
>>>> -	.tag = cpu_to_be16(TPM2_ST_NO_SESSIONS),
>>>> -	.length = cpu_to_be32(TPM2_GET_TPM_PT_IN_SIZE),
>>>> -	.ordinal = cpu_to_be32(TPM2_CC_GET_CAPABILITY)
>>>> -};
>>>> -
>>>>    /**
>>>>     * Append TPMS_AUTH_COMMAND to the buffer. The buffer must be allocated with
>>>>     * tpm_buf_alloc().
>>>> @@ -750,35 +740,43 @@ out:
>>>>    	return rc;
>>>>    }
>>>>
>>>> +#define TPM2_GETCAP_IN_SIZE \
>>>> +	(sizeof(struct tpm_input_header) + sizeof(struct tpm2_getcap_in))
>>>> +
>>>> +static const struct tpm_input_header tpm2_getcap_header = {
>>>> +	.tag = cpu_to_be16(TPM2_ST_NO_SESSIONS),
>>>> +	.length = cpu_to_be32(TPM2_GETCAP_IN_SIZE),
>>>> +	.ordinal = cpu_to_be32(TPM2_CC_GET_CAPABILITY)
>>>> +};
>>>> +
>>>>    /**
>>>> - * tpm2_get_tpm_pt() - get value of a TPM_CAP_TPM_PROPERTIES type property
>>>> - * @chip:		TPM chip to use.
>>>> - * @property_id:	property ID.
>>>> - * @value:		output variable.
>>>> + * tpm2_getcap_cmd() - execute a TPM2_GetCapability command
>>>> + * @chip:		TPM chip to use
>>>> + * @cap_id:		capability ID
>>>> + * @property_id:	property ID
>>>> + * @value:		value of the property
>>>>     * @desc:		passed to tpm_transmit_cmd()
>>>>     *
>>>> - * 0 is returned when the operation is successful. If a negative number is
>>>> - * returned it remarks a POSIX error code. If a positive number is returned
>>>> - * it remarks a TPM error.
>>>> + * Return: same as with tpm_transmit_cmd
>>>>     */
>>>> -ssize_t tpm2_get_tpm_pt(struct tpm_chip *chip, u32 property_id,  u32 *value,
>>>> -			const char *desc)
>>>> +ssize_t tpm2_getcap_cmd(struct tpm_chip *chip, u32 cap_id, u32 property_id,
>>>> +			u32 *value, const char *desc)
>>>
>>> This function currently returns single value "u32 *value" as output data.
>>>
>>> Some calling function expect list of values from capabilities output.
>>> For eg., get_active_banks() use TPM_CAP_PCRS capability to retrieve list of
>>> active banks. And this capability returns array of pcr selections(which is a
>>> struct representing each active PCR bank)
>>>
>>> I was thinking, can we define output parameter as struct of cap_id and union
>>> of expected cap_data ?
>>
>> Unless you have major concerns about performance, which I think are not
>> relevant here, calling this in a loop is perfectly adequate and a lot of
>> simpler than having a generic version (with moreData handling and
>> everything).
>>
>> I would rather see uses of struct cap_t to shrink than to expand. The
>> same goes for other horrific unions that exist today in the driver.
>
> If you are fine with this patch (give Reviewed-by) I can apply this
> and add to my 4.10 pull request so that we have common baseline to
> develop both event log and the resource manager.
>
> This is a very low risk commit to take to 4.10 because it is only used
> for interrupt generation in the TIS driver at the moment.

Works for capabilities with more_data(yes) and single value properties.

Reviewed-by: Nayna Jain <nayna@linux.vnet.ibm.com>

Thanks & Regards,
   - Nayna

>
> /Jarkko
>

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [tpmdd-devel] [PATCH RFC 2/2] tpm: refactor tpm2_get_tpm_pt to tpm2_getcap_cmd
  2016-11-24 13:42         ` Nayna
@ 2016-11-25  8:09           ` Jarkko Sakkinen
  0 siblings, 0 replies; 16+ messages in thread
From: Jarkko Sakkinen @ 2016-11-25  8:09 UTC (permalink / raw)
  To: Nayna; +Cc: moderated list:TPM DEVICE DRIVER, open list, linux-security-module

On Thu, Nov 24, 2016 at 07:12:57PM +0530, Nayna wrote:
> 
> 
> On 11/15/2016 05:18 AM, Jarkko Sakkinen wrote:
> > On Fri, Nov 11, 2016 at 04:02:43PM -0800, Jarkko Sakkinen wrote:
> > > On Fri, Nov 11, 2016 at 09:51:45AM +0530, Nayna wrote:
> > > > 
> > > > 
> > > > On 10/09/2016 03:44 PM, Jarkko Sakkinen wrote:
> > > > > Refactored tpm2_get_tpm_pt to tpm2_getcap_cmd, which means that it also
> > > > > takes capability ID as input. This is required to access
> > > > > TPM_CAP_HANDLES, which contains metadata needed for swapping transient
> > > > > data.
> > > > > 
> > > > > Signed-off-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
> > > > > ---
> > > > >    drivers/char/tpm/tpm.h          |  6 +++-
> > > > >    drivers/char/tpm/tpm2-cmd.c     | 64 ++++++++++++++++++++---------------------
> > > > >    drivers/char/tpm/tpm_tis_core.c |  3 +-
> > > > >    3 files changed, 38 insertions(+), 35 deletions(-)
> > > > > 
> > > > > diff --git a/drivers/char/tpm/tpm.h b/drivers/char/tpm/tpm.h
> > > > > index 0fab6d5..8176f42 100644
> > > > > --- a/drivers/char/tpm/tpm.h
> > > > > +++ b/drivers/char/tpm/tpm.h
> > > > > @@ -85,6 +85,10 @@ enum tpm2_capabilities {
> > > > >    	TPM2_CAP_TPM_PROPERTIES = 6,
> > > > >    };
> > > > > 
> > > > > +enum tpm2_properties {
> > > > > +	TPM2_PT_FAMILY_INDICATOR	= 0x100,
> > > > > +};
> > > > > +
> > > > >    enum tpm2_startup_types {
> > > > >    	TPM2_SU_CLEAR	= 0x0000,
> > > > >    	TPM2_SU_STATE	= 0x0001,
> > > > > @@ -485,7 +489,7 @@ int tpm2_seal_trusted(struct tpm_chip *chip,
> > > > >    int tpm2_unseal_trusted(struct tpm_chip *chip,
> > > > >    			struct trusted_key_payload *payload,
> > > > >    			struct trusted_key_options *options);
> > > > > -ssize_t tpm2_get_tpm_pt(struct tpm_chip *chip, u32 property_id,
> > > > > +ssize_t tpm2_getcap_cmd(struct tpm_chip *chip, u32 cap_id, u32 property_id,
> > > > >    			u32 *value, const char *desc);
> > > > > 
> > > > >    int tpm2_auto_startup(struct tpm_chip *chip);
> > > > > diff --git a/drivers/char/tpm/tpm2-cmd.c b/drivers/char/tpm/tpm2-cmd.c
> > > > > index 2900e18..fcf3d86 100644
> > > > > --- a/drivers/char/tpm/tpm2-cmd.c
> > > > > +++ b/drivers/char/tpm/tpm2-cmd.c
> > > > > @@ -111,13 +111,13 @@ struct tpm2_pcr_extend_in {
> > > > >    	u8				digest[TPM_DIGEST_SIZE];
> > > > >    } __packed;
> > > > > 
> > > > > -struct tpm2_get_tpm_pt_in {
> > > > > +struct tpm2_getcap_in {
> > > > >    	__be32	cap_id;
> > > > >    	__be32	property_id;
> > > > >    	__be32	property_cnt;
> > > > >    } __packed;
> > > > > 
> > > > > -struct tpm2_get_tpm_pt_out {
> > > > > +struct tpm2_getcap_out {
> > > > >    	u8	more_data;
> > > > >    	__be32	subcap_id;
> > > > >    	__be32	property_cnt;
> > > > > @@ -140,8 +140,8 @@ union tpm2_cmd_params {
> > > > >    	struct	tpm2_pcr_read_in	pcrread_in;
> > > > >    	struct	tpm2_pcr_read_out	pcrread_out;
> > > > >    	struct	tpm2_pcr_extend_in	pcrextend_in;
> > > > > -	struct	tpm2_get_tpm_pt_in	get_tpm_pt_in;
> > > > > -	struct	tpm2_get_tpm_pt_out	get_tpm_pt_out;
> > > > > +	struct	tpm2_getcap_in		getcap_in;
> > > > > +	struct	tpm2_getcap_out		getcap_out;
> > > > >    	struct	tpm2_get_random_in	getrandom_in;
> > > > >    	struct	tpm2_get_random_out	getrandom_out;
> > > > >    };
> > > > > @@ -435,16 +435,6 @@ int tpm2_get_random(struct tpm_chip *chip, u8 *out, size_t max)
> > > > >    	return total ? total : -EIO;
> > > > >    }
> > > > > 
> > > > > -#define TPM2_GET_TPM_PT_IN_SIZE \
> > > > > -	(sizeof(struct tpm_input_header) + \
> > > > > -	 sizeof(struct tpm2_get_tpm_pt_in))
> > > > > -
> > > > > -static const struct tpm_input_header tpm2_get_tpm_pt_header = {
> > > > > -	.tag = cpu_to_be16(TPM2_ST_NO_SESSIONS),
> > > > > -	.length = cpu_to_be32(TPM2_GET_TPM_PT_IN_SIZE),
> > > > > -	.ordinal = cpu_to_be32(TPM2_CC_GET_CAPABILITY)
> > > > > -};
> > > > > -
> > > > >    /**
> > > > >     * Append TPMS_AUTH_COMMAND to the buffer. The buffer must be allocated with
> > > > >     * tpm_buf_alloc().
> > > > > @@ -750,35 +740,43 @@ out:
> > > > >    	return rc;
> > > > >    }
> > > > > 
> > > > > +#define TPM2_GETCAP_IN_SIZE \
> > > > > +	(sizeof(struct tpm_input_header) + sizeof(struct tpm2_getcap_in))
> > > > > +
> > > > > +static const struct tpm_input_header tpm2_getcap_header = {
> > > > > +	.tag = cpu_to_be16(TPM2_ST_NO_SESSIONS),
> > > > > +	.length = cpu_to_be32(TPM2_GETCAP_IN_SIZE),
> > > > > +	.ordinal = cpu_to_be32(TPM2_CC_GET_CAPABILITY)
> > > > > +};
> > > > > +
> > > > >    /**
> > > > > - * tpm2_get_tpm_pt() - get value of a TPM_CAP_TPM_PROPERTIES type property
> > > > > - * @chip:		TPM chip to use.
> > > > > - * @property_id:	property ID.
> > > > > - * @value:		output variable.
> > > > > + * tpm2_getcap_cmd() - execute a TPM2_GetCapability command
> > > > > + * @chip:		TPM chip to use
> > > > > + * @cap_id:		capability ID
> > > > > + * @property_id:	property ID
> > > > > + * @value:		value of the property
> > > > >     * @desc:		passed to tpm_transmit_cmd()
> > > > >     *
> > > > > - * 0 is returned when the operation is successful. If a negative number is
> > > > > - * returned it remarks a POSIX error code. If a positive number is returned
> > > > > - * it remarks a TPM error.
> > > > > + * Return: same as with tpm_transmit_cmd
> > > > >     */
> > > > > -ssize_t tpm2_get_tpm_pt(struct tpm_chip *chip, u32 property_id,  u32 *value,
> > > > > -			const char *desc)
> > > > > +ssize_t tpm2_getcap_cmd(struct tpm_chip *chip, u32 cap_id, u32 property_id,
> > > > > +			u32 *value, const char *desc)
> > > > 
> > > > This function currently returns single value "u32 *value" as output data.
> > > > 
> > > > Some calling function expect list of values from capabilities output.
> > > > For eg., get_active_banks() use TPM_CAP_PCRS capability to retrieve list of
> > > > active banks. And this capability returns array of pcr selections(which is a
> > > > struct representing each active PCR bank)
> > > > 
> > > > I was thinking, can we define output parameter as struct of cap_id and union
> > > > of expected cap_data ?
> > > 
> > > Unless you have major concerns about performance, which I think are not
> > > relevant here, calling this in a loop is perfectly adequate and a lot of
> > > simpler than having a generic version (with moreData handling and
> > > everything).
> > > 
> > > I would rather see uses of struct cap_t to shrink than to expand. The
> > > same goes for other horrific unions that exist today in the driver.
> > 
> > If you are fine with this patch (give Reviewed-by) I can apply this
> > and add to my 4.10 pull request so that we have common baseline to
> > develop both event log and the resource manager.
> > 
> > This is a very low risk commit to take to 4.10 because it is only used
> > for interrupt generation in the TIS driver at the moment.
> 
> Works for capabilities with more_data(yes) and single value properties.
> 
> Reviewed-by: Nayna Jain <nayna@linux.vnet.ibm.com>
> 
> Thanks & Regards,
>   - Nayna

Thanks. Not taking this into release though because you don't need it
as was the result of earlier discussion.

/Jarkko

^ permalink raw reply	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2016-11-25  8:10 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-10-09 10:14 [PATCH RFC 0/2] Generalize tpm2_get_tpm_pt to tpm2_get_cap Jarkko Sakkinen
2016-10-09 10:14 ` [PATCH RFC 1/2] tpm: move TPM 2.0 command and response constants to tpm2-cmd.c Jarkko Sakkinen
2016-10-09 10:14 ` [PATCH RFC 2/2] tpm: refactor tpm2_get_tpm_pt to tpm2_getcap_cmd Jarkko Sakkinen
2016-11-11  4:21   ` [tpmdd-devel] " Nayna
2016-11-12  0:02     ` Jarkko Sakkinen
2016-11-14 23:48       ` Jarkko Sakkinen
2016-11-24 13:42         ` Nayna
2016-11-25  8:09           ` Jarkko Sakkinen
2016-11-17 11:50       ` Nayna
2016-11-17 17:42         ` Jarkko Sakkinen
2016-11-18 12:12           ` Nayna
2016-11-18 16:13             ` Jarkko Sakkinen
2016-11-22  9:08               ` Nayna
2016-11-22 11:03                 ` Jarkko Sakkinen
2016-11-04  7:28 ` [PATCH RFC 0/2] Generalize tpm2_get_tpm_pt to tpm2_get_cap Jarkko Sakkinen
2016-11-11  4:42   ` Nayna

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).