tpm: TPM2 support
cover tpm: TPM2 support
This patch set enables TPM2 protocol and provides drivers for FIFO and CRB interfaces.
Jarkko Sakkinen (8):
tpm: prepare TPM driver for adding TPM2 support
tpm: TPM2 support for tpm_pcr_read()
tpm: TPM2 support for tpm_do_selftest()
tpm: added tpm2_get_tpm_pt()
tpm: TPM2 support for tpm_pcr_extend()
tpm: TPM2 support for tpm_get_random().
tpm: Driver for TPM 2.0 CRB Interface
tpm: TPM2 sysfs attributes
Will Arthur (4):
tpm: TPM2 support for tpm_calc_ordinal_durations()
tpm: TPM2 support for tpm_startup()
tpm: TPM2 support for tpm_gen_interrupt().
tpm: TPM 2.0 FIFO Interface
drivers/char/tpm/Kconfig | 9 + drivers/char/tpm/Makefile | 3 +- drivers/char/tpm/tpm-chip.c | 175 ++++++++++++++++ drivers/char/tpm/tpm-interface.c | 160 +++++---------- drivers/char/tpm/tpm.h | 84 ++++++++ drivers/char/tpm/tpm2-commands.c | 422 +++++++++++++++++++++++++++++++++++++++ drivers/char/tpm/tpm2-sysfs.c | 242 ++++++++++++++++++++++ drivers/char/tpm/tpm2.h | 108 ++++++++++ drivers/char/tpm/tpm_crb.c | 332 ++++++++++++++++++++++++++++++ drivers/char/tpm/tpm_tis.c | 53 ++++- 10 files changed, 1463 insertions(+), 125 deletions(-) create mode 100644 drivers/char/tpm/tpm-chip.c create mode 100644 drivers/char/tpm/tpm2-commands.c create mode 100644 drivers/char/tpm/tpm2-sysfs.c create mode 100644 drivers/char/tpm/tpm2.h create mode 100644 drivers/char/tpm/tpm_crb.c
Signature · 1 line
2.1.0
PATCH 1/12 tpm: prepare TPM driver for adding TPM2 support
* Separated allocation and registeration into two functions:
* tpm_chip_alloc()
* tpm_chip_register()
* Modified tpm_register_hardware() to call tpm_chip_alloc/register().
* Added tpm2 boolean flag to struct tpm_chip.
* If a chip has tpm2 flag set TCPA log is not initialized in tpm_chip_register().
The rationale is to introduce TPM2 support without existing drivers getting harmed.
--- drivers/char/tpm/Makefile | 2 +- drivers/char/tpm/tpm-chip.c | 169 +++++++++++++++++++++++++++++++++++++++ drivers/char/tpm/tpm-interface.c | 120 ++------------------------- drivers/char/tpm/tpm.h | 9 +++ 4 files changed, 187 insertions(+), 113 deletions(-) create mode 100644 drivers/char/tpm/tpm-chip.c
drivers/char/tpm/Makefile +1 -1
@@ -2,7 +2,7 @@ # Makefile for the kernel tpm device drivers. # obj-$(CONFIG_TCG_TPM) += tpm.o -tpm-y := tpm-interface.o tpm-dev.o tpm-sysfs.o +tpm-y := tpm-interface.o tpm-dev.o tpm-sysfs.o tpm-chip.o tpm-$(CONFIG_ACPI) += tpm_ppi.o ifdef CONFIG_ACPI
drivers/char/tpm/tpm-chip.c new file +169 -0
169 lines not on this page · raw message
drivers/char/tpm/tpm-interface.c +8 -112
156 lines not on this page · raw message
drivers/char/tpm/tpm.h +9 -0
@@ -109,6 +109,8 @@ struct tpm_chip {struct dentry **bios_dir; +bool tpm2;/* is this a TPM2 chip? */ +struct list_head list;void (*release) (struct device *); };
@@ -332,6 +334,13 @@ extern int tpm_pm_resume(struct device *);extern int wait_for_tpm_stat (struct tpm_chip *,u8 ,unsigned long ,wait_queue_head_t *,bool ); +struct tpm_chip *tpm_chip_find_get (int chip_num); +extern void tpm_dev_vendor_release (struct tpm_chip *); +extern struct tpm_chip *tpm_chip_alloc (struct device *dev, +const struct tpm_class_ops *ops); +extern int tpm_chip_register (struct tpm_chip *chip); +extern void tpm_chip_unregister (struct tpm_chip *chip); +int tpm_dev_add_device (struct tpm_chip *chip);void tpm_dev_del_device (struct tpm_chip *chip);int tpm_sysfs_add_device (struct tpm_chip *chip);
Signature · 1 line
2.1.0
Re: [PATCH v1 01/12] tpm: prepare TPM driver for adding TPM2 support
Quoted 3 lines · Jarkko Sakkinen
* Separated allocation and registeration into two functions:
*tpm_chip_alloc()
*tpm_chip_register()
Okay, this is a nice start!
I had intended tpm-interface.c to hold these 'chip' functions and the other cmd related functions to be moved out into tpm-cmds.c (or tpm1-cmds?), which is more symmetrical with what you are doing with tpm2-cmds. Does that seem reasonable?
It doesn't make sense to leave some chip related stuff in tpm-interface mixed with cmd stuff, I'd prefer to see a clean split if you are going to split them.
drivers/char/tpm/tpm-chip.c line 87
Quoted 3 lines
drivers/char/tpm/tpm-chip.c new file +3
-0+struct tpm_chip *tpm_chip_alloc (struct device *dev, +const struct tpm_class_ops *ops) +{
I want to see a clear description of what the unwind procedures are for each step using the new API, and kdoc on all the new API functions drivers are expected to use.
drivers/char/tpm/tpm-chip.c line 124
Quoted 3 lines
drivers/char/tpm/tpm-chip.c new file +3
-0+int tpm_chip_register (struct tpm_chip *chip) +{ +int rc;
All the common startup functions need to be done here too: get timeouts, self test, etc.
Quoted 4 lines
drivers/char/tpm/tpm-chip.c new file +4
-0+ rc =tpm_dev_add_device (chip); +if (rc) +return rc; +
drivers/char/tpm/tpm-chip.c line 139
Quoted 10 lines
drivers/char/tpm/tpm-chip.c new file +10
-0+ rc =tpm_sysfs_add_device (chip); +if (rc) + goto del_misc; + + rc =tpm_add_ppi (&chip->dev->kobj); +if (rc) + goto del_sysfs; + +if (!chip->tpm2) + chip->bios_dir =tpm_bios_log_setup (chip->devname);
What about failure of tpm_bios_log_setup?
Quoted 6 lines
/*
* Called from tpm_<specific>.c probe function only for devices
* the driver has determined it should claim. Prior to callingdrivers/char/tpm/tpm-interface.c +0
-0@@ -1081,61 +1019,19 @@ struct tpm_chip *tpm_register_hardware(struct device *dev, const struct tpm_class_ops *ops) {
drivers/char/tpm/tpm-interface.c struct tpm_chip *tpm_register_hardware(struct device *dev, · line 1026
Quoted 10 lines
drivers/char/tpm/tpm-interface.c +3
-4struct tpm_chip *chip; +int rc; -/* Driver specific per-device data */ - chip =kzalloc (sizeof (*chip),GFP_KERNEL ); - -if (chip ==NULL ) + chip =tpm_chip_alloc (dev, ops); +if (!chip)return NULL ;
I think tpm_chip_alloc should return an ERR_PTR..
drivers/char/tpm/tpm-interface.c struct tpm_chip *tpm_register_hardware(struct device *dev, · line 1031
Quoted 13 lines
drivers/char/tpm/tpm-interface.c +4
-9-mutex_init (&chip->tpm_mutex); -INIT_LIST_HEAD (&chip->list); - - chip->ops = ops; - chip->dev_num =find_first_zero_bit (dev_mask,TPM_NUM_DEVICES ); - -if (chip->dev_num >=TPM_NUM_DEVICES ) { -dev_err (dev,"No available tpm device numbers\n" ); - goto out_free; + rc =tpm_chip_register (chip); +if (rc) { +put_device (chip->dev); +kfree (chip);
No, open coding this is not a good unwind, and this is not correct anyhow, it looks like it will double free chip...
This is where things got stuck for me too, the unwind is where all the problems are and I think the solution is to make the alloc paths completely different between new and old.
We really want tpmm_chip_alloc for the new style path (so drivers have no unwind) and the old style path .. I don't know what is correct there, but the safest thing is to stay exactly the same.
Also, please split this patch into moving stuff into tmp1-cmds.c and then patching to add functionality.
Jason
PATCH 2/12 tpm: TPM2 support for tpm_calc_ordinal_durations()
In reply to Jarkko SakkinenFrom: Will Arthur <[email protected]>
Implemented TPM2 support for tpm_calc_ordinal_duration(). TPM2 version is encapsulated into tpm2_calc_ordinal_duration() that is called by tpm_calc_ordinal_duration() for TPM2 chips.
[jarkko.sakkinen: implemented tpm2_calc_ordinal_duration() based on
the Wills original patch. Updated durations table to use worst case estimates.]
--- drivers/char/tpm/Makefile | 2 +- drivers/char/tpm/tpm-interface.c | 7 +- drivers/char/tpm/tpm.h | 1 + drivers/char/tpm/tpm2-commands.c | 159 +++++++++++++++++++++++++++++++++++++++ drivers/char/tpm/tpm2.h | 26 +++++++ 5 files changed, 193 insertions(+), 2 deletions(-) create mode 100644 drivers/char/tpm/tpm2-commands.c create mode 100644 drivers/char/tpm/tpm2.h
drivers/char/tpm/Makefile +1 -1
@@ -2,7 +2,7 @@ # Makefile for the kernel tpm device drivers. # obj-$(CONFIG_TCG_TPM) += tpm.o -tpm-y := tpm-interface.o tpm-dev.o tpm-sysfs.o tpm-chip.o +tpm-y := tpm-interface.o tpm-dev.o tpm-sysfs.o tpm-chip.o tpm2-commands.o tpm-$(CONFIG_ACPI) += tpm_ppi.o ifdef CONFIG_ACPI
drivers/char/tpm/tpm-interface.c +6 -1
@@ -309,7 +309,12 @@ unsigned long tpm_calc_ordinal_duration(struct tpm_chip *chip, {int duration_idx =TPM_UNDEFINED ;int duration =0 ; -u8 category = (ordinal >>24 ) &0xFF ; +u8 category; + +if (chip->tpm2) +return tpm2_calc_ordinal_duration (chip, ordinal); + + category = (ordinal >>24 ) &0xFF ;if ((category ==TPM_PROTECTED_COMMAND && ordinal <TPM_MAX_ORDINAL ) || (category ==TPM_CONNECTION_COMMAND && ordinal <TSC_MAX_ORDINAL ))
drivers/char/tpm/tpm.h +1 -0
@@ -27,6 +27,7 @@#include <linux/platform_device.h> #include <linux/io.h> #include <linux/tpm.h> +#include "tpm2.h" enum tpm_const {TPM_MINOR =224 ,/* officially assigned */
drivers/char/tpm/tpm2-commands.c new file +159 -0
159 lines not on this page · raw message
drivers/char/tpm/tpm2.h new file +26 -0
@@ -0,0 +1,26 @@ +/* +* Copyright (C) 2014 Intel Corporation +* +* Authors: +* Jarkko Sakkinen <[email protected]> +* +* Maintained by: <[email protected]> +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License as +* published by the Free Software Foundation, version 2 of the +* License. +* +*/ + +#ifndef __DRIVERS_CHAR_TPM2_H__ +#define __DRIVERS_CHAR_TPM2_H__ + +struct tpm_chip ; + +#define TPM2_CC_FIRST 0x11F +#define TPM2_CC_LAST 0x18F + +unsigned long tpm2_calc_ordinal_duration (struct tpm_chip *,u32 ); + +#endif /* __DRIVERS_CHAR_TPM2_H__ */
Signature · 1 line
2.1.0
PATCH 3/12 tpm: TPM2 support for tpm_pcr_read()
In reply to Jarkko SakkinenImplemented TPM2 support for tpm_pcr_read() by adding a new function tpm2_pcr_read_dev() that is called for TPM2 chipsets.
--- drivers/char/tpm/tpm-interface.c | 5 ++++- drivers/char/tpm/tpm.h | 21 ++++++++++++++++++++ drivers/char/tpm/tpm2-commands.c | 43 ++++++++++++++++++++++++++++++++++++++++ drivers/char/tpm/tpm2.h | 18 +++++++++++++++++ 4 files changed, 86 insertions(+), 1 deletion(-)
drivers/char/tpm/tpm-interface.c +4 -1
@@ -680,7 +680,10 @@ int tpm_pcr_read(u32 chip_num, int pcr_idx, u8 *res_buf) chip =tpm_chip_find_get (chip_num);if (chip ==NULL )return -ENODEV ; - rc =tpm_pcr_read_dev (chip, pcr_idx, res_buf); +if (chip->tpm2) + rc =tpm2_pcr_read_dev (chip, pcr_idx, res_buf); +else + rc =tpm_pcr_read_dev (chip, pcr_idx, res_buf);tpm_chip_put (chip);return rc; }
drivers/char/tpm/tpm.h +21 -0
@@ -298,6 +298,25 @@ struct tpm_startup_in {__be16 startup_type; } __packed; +struct tpm2_pcr_read_in { +__be32 pcr_selects_cnt; +__be16 hash_alg; +u8 pcr_select_size; +u8 pcr_select[TPM2_PCR_SELECT_MIN ]; +} __packed; + + +struct tpm2_pcr_read_out { +__be32 update_cnt; +__be32 pcr_selects_cnt; +__be16 hash_alg; +u8 pcr_select_size; +u8 pcr_select[TPM2_PCR_SELECT_MIN ]; +__be32 digests_cnt; +__be16 digest_size; +u8 digest[TPM_DIGEST_SIZE ]; +} __packed; + typedef union { struct tpm_getcap_params_out getcap_out; struct tpm_readpubek_params_out readpubek_out;
@@ -309,6 +328,8 @@ typedef union {struct tpm_getrandom_in getrandom_in;struct tpm_getrandom_out getrandom_out;struct tpm_startup_in startup_in; +struct tpm2_pcr_read_in tpm2_pcrread_in; +struct tpm2_pcr_read_out tpm2_pcrread_out; } tpm_cmd_params;struct tpm_cmd_t {
drivers/char/tpm/tpm2-commands.c +43 -0
46 lines not on this page · raw message
drivers/char/tpm/tpm2.h +18 -0
@@ -16,11 +16,29 @@#ifndef __DRIVERS_CHAR_TPM2_H__#define __DRIVERS_CHAR_TPM2_H__ +enum tpm2_const { +TPM2_PLATFORM_PCR =24 , +TPM2_PCR_SELECT_MIN = ((TPM2_PLATFORM_PCR +7 ) /8 ), +}; + +enum tpm2_structures { +TPM2_ST_NO_SESSIONS =0x8001 , +}; + +enum tpm2_algorithms { +TPM2_ALG_SHA1 =0x0004 , +}; + +enum tpm2_command_codes { +TPM2_CC_PCR_READ =0x017E , +}; +struct tpm_chip ;#define TPM2_CC_FIRST 0x11F#define TPM2_CC_LAST 0x18Funsigned long tpm2_calc_ordinal_duration (struct tpm_chip *,u32 ); +int tpm2_pcr_read_dev (struct tpm_chip *chip,int pcr_idx,u8 *res_buf);#endif /* __DRIVERS_CHAR_TPM2_H__ */
Signature · 1 line
2.1.0
Re: [PATCH v1 03/12] tpm: TPM2 support for tpm_pcr_read()
Quoted 1 line · Jarkko Sakkinen
+static struct
tpm_input_headertpm2_pcrread_header= {
Missing const - all of these static structures in tpm2-cmds.c are missing the const, please fix them all.
drivers/char/tpm/tpm2-commands.c unsigned long tpm2_calc_ordinal_duration(struct tpm_chip *chip, u32 ordinal) · line 169
Quoted 4 lines
drivers/char/tpm/tpm2-commands.c +4
-0+ .tag = cpu_to_be16(TPM2_ST_NO_SESSIONS), + .length = cpu_to_be32(TPM2_PCR_READ_IN_SIZE), + .ordinal = cpu_to_be32(TPM2_CC_PCR_READ) +};
BTW, I always thought this was a goofy and very expensive way to store 3 values and zero initialize. If you want to do something different in the tpm2-cmds.c that would be great too...
Jason
Re: [PATCH v1 03/12] tpm: TPM2 support for tpm_pcr_read()
Quoted 7 lines · Jason Gunthorpe
Quoted 1 line · Jarkko Sakkinen
+static struct
tpm_input_headertpm2_pcrread_header= {Missing const - all of these static structures in
tpm2-cmds.care missing the const, please fix them all.
Quoted 8 lines
drivers/char/tpm/tpm2-commands.c unsigned long tpm2_calc_ordinal_duration(struct tpm_chip *chip, u32 ordinal) · line 169
Quoted 4 lines
drivers/char/tpm/tpm2-commands.c +4
-0+ .tag = cpu_to_be16(TPM2_ST_NO_SESSIONS), + .length = cpu_to_be32(TPM2_PCR_READ_IN_SIZE), + .ordinal = cpu_to_be32(TPM2_CC_PCR_READ) +};BTW, I always thought this was a goofy and very expensive way to store 3 values and zero initialize. If you want to do something different in the
tpm2-cmds.cthat would be great too...
What do you think about the way trusted module builds messages? It's easier to maintain and debug than the approach used in the tpm subsystem.
That's the approach I was thinking to use when I started doing this but didn't want to diverge before I get feedback.
Quoted 1 line
Jason
/Jarkko
Peter Hüwe
maintainerRe: [PATCH v1 03/12] tpm: TPM2 support for tpm_pcr_read()
Am Mittwoch, 24. September 2014, 21:43:23 schrieb Jarkko Sakkinen:
Quoted 16 lines · Jason Gunthorpe
Quoted 6 lines · Jarkko Sakkinen
Quoted 1 line
+static struct
tpm_input_headertpm2_pcrread_header= {Missing const - all of these static structures in
tpm2-cmds.care missing the const, please fix them all.Quoted 8 lines
drivers/char/tpm/tpm2-commands.c unsigned long tpm2_calc_ordinal_duration(struct tpm_chip *chip, u32 ordinal) · line 169
Quoted 4 lines
drivers/char/tpm/tpm2-commands.c +4
-0+ .tag = cpu_to_be16(TPM2_ST_NO_SESSIONS), + .length = cpu_to_be32(TPM2_PCR_READ_IN_SIZE), + .ordinal = cpu_to_be32(TPM2_CC_PCR_READ) +};BTW, I always thought this was a goofy and very expensive way to store 3 values and zero initialize. If you want to do something different in the
tpm2-cmds.cthat would be great too...
Quoted 2 lines
What do you think about the way trusted module builds messages? It's easier to maintain and debug than the approach used in the tpm subsystem.
Can you post an example (e.g. for the command stream above)
Peter
Re: [PATCH v1 03/12] tpm: TPM2 support for tpm_pcr_read()
In reply to Jarkko SakkinenQuoted 3 lines · Jarkko Sakkinen
What do you think about the way trusted module builds messages? It's easier to maintain and debug than the approach used in the tpm subsystem.
Do you have a source reference?
In my userspace TPM work I use a code generator to produce all the marshal/unmarshal/AUTH directly from the TPM specification text. The full generality of TPM RPCs is sufficiently complex that hand coding is too error prone. The handful of ops the kernel does is not so bad though...
Jason
PATCH 4/12 tpm: TPM2 support for tpm_do_selftest()
In reply to Jarkko SakkinenImplemented tpm2_do_selftest() that runs the full (all commands) self-test for the TPM chip. During the self-test TPM2 commands return with the TPM error code RC_TESTING. Waiting is done by issuing PCR read until it executes succesfully or some other error condition than RC_TESTING happens.
--- drivers/char/tpm/tpm-interface.c | 3 ++ drivers/char/tpm/tpm.h | 5 +++ drivers/char/tpm/tpm2-commands.c | 82 ++++++++++++++++++++++++++++++++++++++++ drivers/char/tpm/tpm2.h | 7 ++++ 4 files changed, 97 insertions(+)
drivers/char/tpm/tpm-interface.c +3 -0
@@ -744,6 +744,9 @@ int tpm_do_selftest(struct tpm_chip *chip)unsigned long duration;struct tpm_cmd_t cmd; +if (chip->tpm2) +return tpm2_do_selftest (chip); + duration =tpm_calc_ordinal_duration (chip,TPM_ORD_CONTINUE_SELFTEST ); loops =jiffies_to_msecs (duration) / delay_msec;
drivers/char/tpm/tpm.h +5 -0
@@ -298,6 +298,10 @@ struct tpm_startup_in {__be16 startup_type; } __packed; +struct tpm2_self_test_in { +u8 full_test; +} __packed; +struct tpm2_pcr_read_in {__be32 pcr_selects_cnt;__be16 hash_alg;
@@ -330,6 +334,7 @@ typedef union {struct tpm_startup_in startup_in;struct tpm2_pcr_read_in tpm2_pcrread_in;struct tpm2_pcr_read_out tpm2_pcrread_out; +struct tpm2_self_test_in tpm2_selftest_in; } tpm_cmd_params;struct tpm_cmd_t {
drivers/char/tpm/tpm2-commands.c +82 -0
85 lines not on this page · raw message
drivers/char/tpm/tpm2.h +7 -0
@@ -25,11 +25,17 @@ enum tpm2_structures { TPM2_ST_NO_SESSIONS = 0x8001, }; +enum tpm2_return_codes { +TPM2_RC_TESTING =0x090A , +TPM2_RC_DISABLED =0x0120 , +}; +enum tpm2_algorithms {TPM2_ALG_SHA1 =0x0004 , };enum tpm2_command_codes { +TPM2_CC_SELF_TEST =0x0143 ,TPM2_CC_PCR_READ =0x017E , };
@@ -40,5 +46,6 @@ struct tpm_chip;unsigned long tpm2_calc_ordinal_duration (struct tpm_chip *,u32 );int tpm2_pcr_read_dev (struct tpm_chip *chip,int pcr_idx,u8 *res_buf); +int tpm2_do_selftest (struct tpm_chip *chip);#endif /* __DRIVERS_CHAR_TPM2_H__ */
Signature · 1 line
2.1.0
PATCH 5/12 tpm: added tpm2_get_tpm_pt()
In reply to Jarkko SakkinenAdded the function tpm2_get_tpm_pt() for acquiring TPM properties (properties under under TPM_CAP_TPM_PROPERTIES capability).
--- drivers/char/tpm/tpm.h | 16 ++++++++++++++++ drivers/char/tpm/tpm2-commands.c | 30 ++++++++++++++++++++++++++++++ drivers/char/tpm/tpm2.h | 7 +++++++ 3 files changed, 53 insertions(+)
drivers/char/tpm/tpm.h +16 -0
@@ -321,6 +321,20 @@ struct tpm2_pcr_read_out {u8 digest[TPM_DIGEST_SIZE ]; } __packed; +struct tpm2_get_tpm_pt_in { +__be32 cap_id; +__be32 property_id; +__be32 property_cnt; +} __packed; + +struct tpm2_get_tpm_pt_out { +u8 more_data; +__be32 subcap_id; +__be32 property_cnt; +__be32 property_id; +__be32 value; +} __packed; + typedef union { struct tpm_getcap_params_out getcap_out; struct tpm_readpubek_params_out readpubek_out;
@@ -335,6 +349,8 @@ typedef union {struct tpm2_pcr_read_in tpm2_pcrread_in;struct tpm2_pcr_read_out tpm2_pcrread_out;struct tpm2_self_test_in tpm2_selftest_in; +struct tpm2_get_tpm_pt_in tpm2_get_tpm_pt_in; +struct tpm2_get_tpm_pt_out tpm2_get_tpm_pt_out; } tpm_cmd_params;struct tpm_cmd_t {
drivers/char/tpm/tpm2-commands.c +30 -0
@@ -158,6 +158,36 @@ unsigned long tpm2_calc_ordinal_duration(struct tpm_chip *chip, u32 ordinal)return duration; } +#define TPM2_GET_TPM_PT_IN_SIZE \ + (sizeof(struct tpm_input_header) + \ + sizeof(struct tpm2_get_tpm_pt_in)) + +static 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 ) +}; + +ssize_t tpm2_get_tpm_pt (struct device *dev,u32 property_id,u32 * value, +const char *desc) +{ +struct tpm_cmd_t cmd; +int rc; +struct tpm_chip *chip =dev_get_drvdata (dev); + + cmd.header.in = tpm2_get_tpm_pt_header; + cmd.params.tpm2_get_tpm_pt_in.cap_id = +cpu_to_be32 (TPM2_CAP_TPM_PROPERTIES ); + cmd.params.tpm2_get_tpm_pt_in.property_id = property_id; + cmd.params.tpm2_get_tpm_pt_in.property_cnt =cpu_to_be32 (1 ); + + rc =tpm_transmit_cmd (chip, &cmd,sizeof (cmd), desc); +if (!rc) + *value = cmd.params.tpm2_get_tpm_pt_out.value; + +return rc; +} +#define TPM2_PCR_READ_IN_SIZE \ (sizeof(struct tpm_input_header) + \ sizeof(struct tpm2_pcr_read_in))
drivers/char/tpm/tpm2.h +7 -0
@@ -36,15 +36,22 @@ enum tpm2_algorithms {enum tpm2_command_codes {TPM2_CC_SELF_TEST =0x0143 , +TPM2_CC_GET_CAPABILITY =0x017A ,TPM2_CC_PCR_READ =0x017E , }; +enum tpm2_capabilities { +TPM2_CAP_TPM_PROPERTIES =6 , +}; +struct tpm_chip ;#define TPM2_CC_FIRST 0x11F#define TPM2_CC_LAST 0x18Funsigned long tpm2_calc_ordinal_duration (struct tpm_chip *,u32 ); +ssize_t tpm2_get_tpm_pt (struct device *dev,u32 property_id,u32 * value, +const char *desc);int tpm2_pcr_read_dev (struct tpm_chip *chip,int pcr_idx,u8 *res_buf);int tpm2_do_selftest (struct tpm_chip *chip);
Signature · 1 line
2.1.0
PATCH 6/12 tpm: TPM2 support for tpm_pcr_extend()
In reply to Jarkko SakkinenImplemented TPM2 protocol support for tpm_pcr_extend().
--- drivers/char/tpm/tpm-interface.c | 6 ++++++ drivers/char/tpm/tpm.h | 17 +++++++++++++++++ drivers/char/tpm/tpm2-commands.c | 37 +++++++++++++++++++++++++++++++++++++ drivers/char/tpm/tpm2.h | 7 +++++++ 4 files changed, 67 insertions(+)
drivers/char/tpm/tpm-interface.c +6 -0
@@ -717,6 +717,12 @@ int tpm_pcr_extend(u32 chip_num, int pcr_idx, const u8 *hash)if (chip ==NULL )return -ENODEV ; +if (chip->tpm2) { + rc =tpm2_pcr_extend (chip, pcr_idx, hash); +tpm_chip_put (chip); +return rc; + } + cmd.header.in = pcrextend_header; cmd.params.pcrextend_in.pcr_idx =cpu_to_be32 (pcr_idx);memcpy (cmd.params.pcrextend_in.hash, hash,TPM_DIGEST_SIZE );
drivers/char/tpm/tpm.h +17 -0
@@ -321,6 +321,22 @@ struct tpm2_pcr_read_out {u8 digest[TPM_DIGEST_SIZE ]; } __packed; +struct tpm2_null_auth_area { +__be32 handle; +__be16 nonce_size; +u8 attributes; +__be16 auth_size; +} __packed; + +struct tpm2_pcr_extend_in { +__be32 pcr_idx; +__be32 auth_area_size; +struct tpm2_null_auth_area auth_area; +__be32 digest_cnt; +__be16 hash_alg; +u8 digest[TPM_DIGEST_SIZE ]; +} __packed; +struct tpm2_get_tpm_pt_in {__be32 cap_id;__be32 property_id;
@@ -348,6 +364,7 @@ typedef union {struct tpm_startup_in startup_in;struct tpm2_pcr_read_in tpm2_pcrread_in;struct tpm2_pcr_read_out tpm2_pcrread_out; +struct tpm2_pcr_extend_in tpm2_pcrextend_in;struct tpm2_self_test_in tpm2_selftest_in;struct tpm2_get_tpm_pt_in tpm2_get_tpm_pt_in;struct tpm2_get_tpm_pt_out tpm2_get_tpm_pt_out;
drivers/char/tpm/tpm2-commands.c +37 -0
@@ -231,6 +231,43 @@ int tpm2_pcr_read_dev(struct tpm_chip *chip, int pcr_idx, u8 *res_buf)return rc; } +/** +* tpm_pcr_extend - extend pcr value with hash +* @chip_num: tpm idx # or AN& +* @pcr_idx: pcr idx to extend +* @hash: hash value used to extend pcr value +*/ +static struct tpm_input_header tpm2_pcrextend_header = { + .tag =cpu_to_be16 (TPM2_ST_SESSIONS ), + .length =cpu_to_be32 (sizeof (struct tpm_input_header ) + +sizeof (struct tpm2_pcr_extend_in )), + .ordinal =cpu_to_be32 (TPM2_CC_PCR_EXTEND ) +}; + +int tpm2_pcr_extend (struct tpm_chip *chip,int pcr_idx,const u8 *hash) +{ +struct tpm_cmd_t cmd; +int rc; + + cmd.header.in = tpm2_pcrextend_header; + cmd.params.tpm2_pcrextend_in.pcr_idx =cpu_to_be32 (pcr_idx); + cmd.params.tpm2_pcrextend_in.auth_area_size = +cpu_to_be32 (sizeof (struct tpm2_null_auth_area )); + cmd.params.tpm2_pcrextend_in.auth_area.handle = +cpu_to_be32 (TPM2_RS_PW ); + cmd.params.tpm2_pcrextend_in.auth_area.nonce_size =0 ; + cmd.params.tpm2_pcrextend_in.auth_area.attributes =0 ; + cmd.params.tpm2_pcrextend_in.auth_area.auth_size =0 ; + cmd.params.tpm2_pcrextend_in.digest_cnt =cpu_to_be32 (1 ); + cmd.params.tpm2_pcrextend_in.hash_alg =cpu_to_be16 (TPM2_ALG_SHA1 ); +memcpy (cmd.params.tpm2_pcrextend_in.digest, hash,TPM_DIGEST_SIZE ); + + rc =tpm_transmit_cmd (chip, &cmd,sizeof (cmd), +"attempting extend a PCR value" ); + +return rc; +} +static struct tpm_input_header tpm2_selftest_header = { .tag =cpu_to_be16 (TPM2_ST_NO_SESSIONS ), .length = cpu_to_be32(sizeof(struct tpm_input_header) +
drivers/char/tpm/tpm2.h +7 -0
@@ -23,6 +23,7 @@ enum tpm2_const {enum tpm2_structures {TPM2_ST_NO_SESSIONS =0x8001 , +TPM2_ST_SESSIONS =0x8002 , };enum tpm2_return_codes {
@@ -38,6 +39,11 @@ enum tpm2_command_codes {TPM2_CC_SELF_TEST =0x0143 ,TPM2_CC_GET_CAPABILITY =0x017A ,TPM2_CC_PCR_READ =0x017E , + TPM2_CC_PCR_EXTEND = 0x0182, +}; + +enum tpm2_permanent_handles { +TPM2_RS_PW =0x40000009 , }; enum tpm2_capabilities {
@@ -53,6 +59,7 @@ unsigned long tpm2_calc_ordinal_duration(struct tpm_chip *, u32);ssize_t tpm2_get_tpm_pt (struct device *dev,u32 property_id,u32 * value,const char *desc);int tpm2_pcr_read_dev (struct tpm_chip *chip,int pcr_idx,u8 *res_buf); +int tpm2_pcr_extend (struct tpm_chip *chip,int pcr_idx,const u8 *hash);int tpm2_do_selftest (struct tpm_chip *chip);#endif /* __DRIVERS_CHAR_TPM2_H__ */
Signature · 1 line
2.1.0
PATCH 7/12 tpm: TPM2 support for tpm_get_random().
In reply to Jarkko SakkinenImplemented TPM2 support for tpm_get_random().
--- drivers/char/tpm/tpm-interface.c | 6 ++++++ drivers/char/tpm/tpm.h | 11 ++++++++++ drivers/char/tpm/tpm2-commands.c | 45 ++++++++++++++++++++++++++++++++++++++++ drivers/char/tpm/tpm2.h | 2 ++ 4 files changed, 64 insertions(+)
drivers/char/tpm/tpm-interface.c +6 -0
@@ -1002,6 +1002,12 @@ int tpm_get_random(u32 chip_num, u8 *out, size_t max)if (chip ==NULL )return -ENODEV ; +if (chip->tpm2) { + err =tpm2_get_random (chip, out, max); +tpm_chip_put (chip); +return err; + } + do { tpm_cmd.header.in = tpm_getrandom_header; tpm_cmd.params.getrandom_in.num_bytes = cpu_to_be32(num_bytes);
drivers/char/tpm/tpm.h +11 -0
@@ -351,6 +351,15 @@ struct tpm2_get_tpm_pt_out {__be32 value; } __packed; +struct tpm2_get_random_in { +__be16 size; +} __packed; + +struct tpm2_get_random_out { +__be16 size; +u8 buffer[TPM_MAX_RNG_DATA ]; +} __packed; + typedef union { struct tpm_getcap_params_out getcap_out; struct tpm_readpubek_params_out readpubek_out;
@@ -368,6 +377,8 @@ typedef union {struct tpm2_self_test_in tpm2_selftest_in;struct tpm2_get_tpm_pt_in tpm2_get_tpm_pt_in;struct tpm2_get_tpm_pt_out tpm2_get_tpm_pt_out; +struct tpm2_get_random_in tpm2_getrandom_in; +struct tpm2_get_random_out tpm2_getrandom_out; } tpm_cmd_params;struct tpm_cmd_t {
drivers/char/tpm/tpm2-commands.c +45 -0
48 lines not on this page · raw message
drivers/char/tpm/tpm2.h +2 -0
@@ -38,6 +38,7 @@ enum tpm2_algorithms {enum tpm2_command_codes {TPM2_CC_SELF_TEST =0x0143 ,TPM2_CC_GET_CAPABILITY =0x017A , +TPM2_CC_GET_RANDOM =0x017B ,TPM2_CC_PCR_READ =0x017E ,TPM2_CC_PCR_EXTEND =0x0182 , };
@@ -61,5 +62,6 @@ ssize_t tpm2_get_tpm_pt(struct device *dev, u32 property_id, u32* value,int tpm2_pcr_read_dev (struct tpm_chip *chip,int pcr_idx,u8 *res_buf);int tpm2_pcr_extend (struct tpm_chip *chip,int pcr_idx,const u8 *hash);int tpm2_do_selftest (struct tpm_chip *chip); +int tpm2_get_random (struct tpm_chip *chip,u8 *out,size_t max);#endif /* __DRIVERS_CHAR_TPM2_H__ */
Signature · 1 line
2.1.0
PATCH 8/12 tpm: TPM2 support for tpm_startup()
In reply to Jarkko SakkinenFrom: Will Arthur <[email protected]>
This patch implements TPM2 support for tpm_startup().
[jarkko.sakkinen: implemented tpm2_startup() based on the Wills
original patch.]
--- drivers/char/tpm/tpm-interface.c | 6 +++++- drivers/char/tpm/tpm.h | 4 ++++ drivers/char/tpm/tpm2-commands.c | 17 +++++++++++++++++ drivers/char/tpm/tpm2.h | 2 ++ 4 files changed, 28 insertions(+), 1 deletion(-)
drivers/char/tpm/tpm-interface.c +5 -1
@@ -474,6 +474,7 @@ EXPORT_SYMBOL_GPL(tpm_gen_interrupt);#define TPM_ST_CLEAR cpu_to_be16(1)#define TPM_ST_STATE cpu_to_be16(2)#define TPM_ST_DEACTIVATED cpu_to_be16(3) +static const struct tpm_input_header tpm_startup_header = { .tag =TPM_TAG_RQU_COMMAND , .length =cpu_to_be32 (12 ),
@@ -483,7 +484,10 @@ static const struct tpm_input_header tpm_startup_header = {static int tpm_startup (struct tpm_chip *chip,__be16 startup_type) {struct tpm_cmd_t start_cmd; - start_cmd.header.in = tpm_startup_header; + +if (chip->tpm2) +return tpm2_startup (chip, startup_type); + start_cmd.params.startup_in.startup_type = startup_type;return tpm_transmit_cmd (chip, &start_cmd,TPM_INTERNAL_RESULT_SIZE ,"attempting to start the TPM" );
drivers/char/tpm/tpm.h +4 -0
@@ -298,6 +298,10 @@ struct tpm_startup_in {__be16 startup_type; } __packed; +struct tpm2_startup_in { +__be16 startup_type; +} __packed; +struct tpm2_self_test_in {u8 full_test; } __packed;
drivers/char/tpm/tpm2-commands.c +17 -0
@@ -158,6 +158,23 @@ unsigned long tpm2_calc_ordinal_duration(struct tpm_chip *chip, u32 ordinal)return duration; } +static const struct tpm_input_header tpm2_startup_header = { + .tag =cpu_to_be16 (TPM2_ST_NO_SESSIONS ), + .length =cpu_to_be32 (12 ), + .ordinal =cpu_to_be32 (TPM2_CC_STARTUP ) +}; + +int tpm2_startup (struct tpm_chip *chip,__be16 startup_type) +{ +struct tpm_cmd_t cmd; + + cmd.header.in = tpm2_startup_header; + + cmd.params.startup_in.startup_type = startup_type; +return tpm_transmit_cmd (chip, &cmd,sizeof (cmd), +"attempting to start the TPM" ); +} +#define TPM2_GET_TPM_PT_IN_SIZE \ (sizeof(struct tpm_input_header) + \ sizeof(struct tpm2_get_tpm_pt_in))
drivers/char/tpm/tpm2.h +2 -0
@@ -37,6 +37,7 @@ enum tpm2_algorithms {enum tpm2_command_codes {TPM2_CC_SELF_TEST =0x0143 , +TPM2_CC_STARTUP =0x0144 ,TPM2_CC_GET_CAPABILITY =0x017A ,TPM2_CC_GET_RANDOM =0x017B ,TPM2_CC_PCR_READ =0x017E ,
@@ -57,6 +58,7 @@ struct tpm_chip;#define TPM2_CC_LAST 0x18Funsigned long tpm2_calc_ordinal_duration (struct tpm_chip *,u32 ); +int tpm2_startup (struct tpm_chip *chip,__be16 startup_type);ssize_t tpm2_get_tpm_pt (struct device *dev,u32 property_id,u32 * value,const char *desc);int tpm2_pcr_read_dev (struct tpm_chip *chip,int pcr_idx,u8 *res_buf);
Signature · 1 line
2.1.0
PATCH 9/12 tpm: TPM2 support for tpm_gen_interrupt().
In reply to Jarkko SakkinenFrom: Will Arthur <[email protected]>
This patch adds TPM2 support for tpm_gen_interrupt().
[jarkko.sakkinen: implemented tpm2_gen_interrupt() based on Wills
original patch that is called from tpm_gen_interrupt() for TPM2 chipsets.]
--- drivers/char/tpm/tpm-interface.c | 5 +++++ drivers/char/tpm/tpm2-commands.c | 9 +++++++++ drivers/char/tpm/tpm2.h | 1 + 3 files changed, 15 insertions(+)
drivers/char/tpm/tpm-interface.c +5 -0
@@ -460,6 +460,11 @@ void tpm_gen_interrupt(struct tpm_chip *chip)struct tpm_cmd_t tpm_cmd;ssize_t rc; +if (chip->tpm2) { +tpm2_gen_interrupt (chip); +return ; + } + tpm_cmd.header.in = tpm_getcap_header; tpm_cmd.params.getcap_in.cap =TPM_CAP_PROP ; tpm_cmd.params.getcap_in.subcap_size =cpu_to_be32 (4 );
drivers/char/tpm/tpm2-commands.c +9 -0
@@ -411,3 +411,12 @@ int tpm2_get_random(struct tpm_chip *chip, u8 *out, size_t max)return total ? total : -EIO ; } + +void tpm2_gen_interrupt (struct tpm_chip *chip) +{ +u32 value; +ssize_t rc; + + rc =tpm2_get_tpm_pt (chip->dev,TPM2_CAP_TPM_PROPERTIES , &value, +"attempting to determine the timeouts" ); +}
drivers/char/tpm/tpm2.h +1 -0
@@ -65,5 +65,6 @@ int tpm2_pcr_read_dev(struct tpm_chip *chip, int pcr_idx, u8 *res_buf);int tpm2_pcr_extend (struct tpm_chip *chip,int pcr_idx,const u8 *hash);int tpm2_do_selftest (struct tpm_chip *chip);int tpm2_get_random (struct tpm_chip *chip,u8 *out,size_t max); +void tpm2_gen_interrupt (struct tpm_chip *chip);#endif /* __DRIVERS_CHAR_TPM2_H__ */
Signature · 1 line
2.1.0
PATCH 10/12 tpm: TPM 2.0 FIFO Interface
In reply to Jarkko SakkinenFrom: Will Arthur <[email protected]>
Detect TPM 2.0 by using the extended STS (STS3) register. For TPM 2.0, instead of calling tpm_get_timeouts(), assign duration and timeout values defined in the TPM 2.0 PTP specification.
[jarkko.sakkinen: Added durations and timeouts handling. Rewrote
the commit message.]
--- drivers/char/tpm/tpm-interface.c | 3 +++ drivers/char/tpm/tpm2.h | 7 ++++++ drivers/char/tpm/tpm_tis.c | 53 ++++++++++++++++++++++++++++++++-------- 3 files changed, 53 insertions(+), 10 deletions(-)
drivers/char/tpm/tpm-interface.c +3 -0
@@ -506,6 +506,9 @@ int tpm_get_timeouts(struct tpm_chip *chip)struct duration_t *duration_cap;ssize_t rc; +if (chip->tpm2) +return 0 ; + tpm_cmd.header.in = tpm_getcap_header; tpm_cmd.params.getcap_in.cap =TPM_CAP_PROP ; tpm_cmd.params.getcap_in.subcap_size =cpu_to_be32 (4 );
drivers/char/tpm/tpm2.h +7 -0
@@ -19,6 +19,13 @@enum tpm2_const {TPM2_PLATFORM_PCR =24 ,TPM2_PCR_SELECT_MIN = ((TPM2_PLATFORM_PCR +7 ) /8 ), +TPM2_TIMEOUT_A =750 *1000 , +TPM2_TIMEOUT_B =2000 *1000 , +TPM2_TIMEOUT_C =200 *1000 , +TPM2_TIMEOUT_D =30 *1000 , +TPM2_DURATION_SHORT =20 *1000 , +TPM2_DURATION_MEDIUM =750 *1000 , +TPM2_DURATION_LONG =2000 *1000 , };enum tpm2_structures {
drivers/char/tpm/tpm_tis.c +43 -10
91 lines not on this page · raw message
Signature · 1 line
2.1.0
Re: [PATCH v1 10/12] tpm: TPM 2.0 FIFO Interface
drivers/char/tpm/tpm_tis.c static int tpm_tis_init(struct device *dev, resource_size_t start, · line 548
Quoted 4 lines · Jarkko Sakkinen
drivers/char/tpm/tpm_tis.c +2
-1-if (!(chip =tpm_register_hardware (dev, &tpm_tis))) + chip =tpm_chip_alloc (dev, &tpm_tis); +if (!chip)return -ENODEV ;
Please put this in a separate patch, don't co-mingle it with TPM2 support. If drivers are going to be converted, then I want to see the new API used properly and the driver itself to be a *correct* example of using the new API.
So you have to purge the tis_chips, fix the missing removal functions, call unregister, fix the force probe path, etc.
Quoted 1 line
chip->vendor.iobase=ioremap(start, len);
Since this changes the ordering, can we devm this ioremap?
Jason
Re: [PATCH v1 10/12] tpm: TPM 2.0 FIFO Interface
Quoted 11 lines · Jason Gunthorpe
drivers/char/tpm/tpm_tis.c static int tpm_tis_init(struct device *dev, resource_size_t start, · line 548
Quoted 4 lines · Jarkko Sakkinen
drivers/char/tpm/tpm_tis.c +2
-1-if (!(chip =tpm_register_hardware (dev, &tpm_tis))) + chip =tpm_chip_alloc (dev, &tpm_tis); +if (!chip)return -ENODEV ;Please put this in a separate patch, don't co-mingle it with TPM2 support. If drivers are going to be converted, then I want to see the new API used properly and the driver itself to be a *correct* example of using the new API.
Agreed.
Quoted 6 lines
So you have to purge the
tis_chips, fix the missing removal functions, call unregister, fix the force probe path, etc.Quoted 1 line
chip->vendor.iobase=ioremap(start, len);Since this changes the ordering, can we devm this ioremap?
Hmm... I was going to do that but forgot it. I'll add this to my backlog.
Quoted 1 line
Jason
/Jarkko
PATCH 11/12 tpm: Driver for TPM 2.0 CRB Interface
In reply to Jarkko Sakkinentpm_crb is a driver for TPM 2.0 CRB Interface as defined in
- http://www.trustedcomputinggroup.org/resources/tpm_20_mobile_command_response_buffer_interface_specification
- http://www.trustedcomputinggroup.org/resources/server_acpi_specification
Tested with TPM2 PTT included in 4th generation Intel processors.
Notes:
- PTT reports using only ACPI start as start method but seems to require CRB with ACPI start.
- cmdReady does not seem to work with PTT.
- Does not have yet interrupt based send/receive because I don't have hardware for that.
--- drivers/char/tpm/Kconfig | 9 ++ drivers/char/tpm/Makefile | 1 + drivers/char/tpm/tpm_crb.c | 332 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 342 insertions(+) create mode 100644 drivers/char/tpm/tpm_crb.c
drivers/char/tpm/Kconfig +9 -0
@@ -122,4 +122,13 @@ config TCG_XEN To compile this driver as a module, choose M here; the module will be called xen-tpmfront. +config TCG_CRB + tristate "TPM 2.0 CRB Interface" + depends on X86 && ACPI + ---help--- + If you have a TPM security chip that is compliant with the + TCG CRB 2.0 TPM specification say Yes and it will be accessible + from within Linux. To compile this driver as a module, choose + M here; the module will be called tpm_crb. + endif # TCG_TPM
drivers/char/tpm/Makefile +1 -0
@@ -22,3 +22,4 @@ obj-$(CONFIG_TCG_INFINEON) += tpm_infineon.o obj-$(CONFIG_TCG_IBMVTPM) += tpm_ibmvtpm.o obj-$(CONFIG_TCG_ST33_I2C) += tpm_i2c_stm_st33.o obj-$(CONFIG_TCG_XEN) += xen-tpmfront.o +obj-$(CONFIG_TCG_CRB) += tpm_crb.o
drivers/char/tpm/tpm_crb.c new file +332 -0
332 lines not on this page · raw message
Signature · 1 line
2.1.0
Re: [PATCH v1 11/12] tpm: Driver for TPM 2.0 CRB Interface
drivers/char/tpm/tpm_crb.c line 136
Quoted 4 lines · Jarkko Sakkinen
drivers/char/tpm/tpm_crb.c new file +4
-0+ offset = cca->rsp_pa - priv->cca_pa; + resp = (u8 *) ((unsigned long ) cca + offset); +memcpy (buf, resp,6 ); + expected =be32_to_cpu (*(__be32 *) (buf +2 ));
be32_to_cpup?
drivers/char/tpm/tpm_crb.c line 226
Quoted 5 lines
drivers/char/tpm/tpm_crb.c new file +5
-0+static void crb_release (void *data) +{ +struct tpm_chip *chip = (struct tpm_chip *) data; +tpm_remove_hardware (chip->dev); +}
Please use a proper remove function on the device driver, not a devm function like this. 'tpm_remove_hardware' is the wrong name for a new API, it must be 'tpm_chip_unregister' (ie the undo of 'tpm_chip_register')
drivers/char/tpm/tpm_crb.c line 240
Quoted 13 lines
drivers/char/tpm/tpm_crb.c new file +13
-0+static int crb_acpi_add (struct acpi_device *device) +{ +struct tpm_chip *chip; +struct acpi_tpm2 *buf; +struct crb_priv *priv; +struct device *dev = &device->dev; +acpi_status status; +u32 sm; +int rc; + + chip =tpm_chip_alloc (dev, &tpm_crb); +if (!chip) +return -ENODEV ;
Lets use ERRPTR here
drivers/char/tpm/tpm_crb.c line 244
Quoted 3 lines
drivers/char/tpm/tpm_crb.c new file +3
-0+ chip->tpm2 = true; + + rc =tpm_chip_register (chip);
This is in the wrong place, it needs to be the last call in the probe function - the driver must be fully operational when register is called, that is one of the bugs the new interface must be fixing.
drivers/char/tpm/tpm_crb.c line 299
Quoted 5 lines
drivers/char/tpm/tpm_crb.c new file +5
-0+ rc =tpm_do_selftest (chip); +if (rc) { + rc = -ENODEV ; + goto out_err; + }
The common TPM command startup sequence should be in tpm_chip_register(), so move this into there.
drivers/char/tpm/tpm_crb.c line 311
Quoted 11 lines
drivers/char/tpm/tpm_crb.c new file +11
-0+ rc =devm_add_action (dev, crb_release, chip); +if (rc) + goto out_err; + +return 0 ; +out_err: +tpm_remove_hardware (chip->dev); +return rc; +} + +static struct acpi_device_id crb_device_ids[] = {
const? Not sure
Jason
Re: [PATCH v1 11/12] tpm: Driver for TPM 2.0 CRB Interface
Thanks for reviewing this. I'll fix these issues, not much to add. Thank you.
/Jarkko
Quoted 67 lines · Jason Gunthorpe
drivers/char/tpm/tpm_crb.c line 136
Quoted 4 lines · Jarkko Sakkinen
drivers/char/tpm/tpm_crb.c new file +4
-0+ offset = cca->rsp_pa - priv->cca_pa; + resp = (u8 *) ((unsigned long ) cca + offset); +memcpy (buf, resp,6 ); + expected =be32_to_cpu (*(__be32 *) (buf +2 ));
be32_to_cpup?drivers/char/tpm/tpm_crb.c line 226
Quoted 5 lines
drivers/char/tpm/tpm_crb.c new file +5
-0+static void crb_release (void *data) +{ +struct tpm_chip *chip = (struct tpm_chip *) data; +tpm_remove_hardware (chip->dev); +}Please use a proper remove function on the device driver, not a devm function like this. '
tpm_remove_hardware' is the wrong name for a new API, it must be 'tpm_chip_unregister' (ie the undo of 'tpm_chip_register')drivers/char/tpm/tpm_crb.c line 240
Quoted 13 lines
drivers/char/tpm/tpm_crb.c new file +13
-0+static int crb_acpi_add (struct acpi_device *device) +{ +struct tpm_chip *chip; +struct acpi_tpm2 *buf; +struct crb_priv *priv; +struct device *dev = &device->dev; +acpi_status status; +u32 sm; +int rc; + + chip =tpm_chip_alloc (dev, &tpm_crb); +if (!chip) +return -ENODEV ;Lets use ERRPTR here
drivers/char/tpm/tpm_crb.c line 244
Quoted 3 lines
drivers/char/tpm/tpm_crb.c new file +3
-0+ chip->tpm2 = true; + + rc =tpm_chip_register (chip);This is in the wrong place, it needs to be the last call in the probe function - the driver must be fully operational when register is called, that is one of the bugs the new interface must be fixing.
drivers/char/tpm/tpm_crb.c line 299
Quoted 5 lines
drivers/char/tpm/tpm_crb.c new file +5
-0+ rc =tpm_do_selftest (chip); +if (rc) { + rc = -ENODEV ; + goto out_err; + }The common TPM command startup sequence should be in
tpm_chip_register(), so move this into there.drivers/char/tpm/tpm_crb.c line 311
Quoted 11 lines
drivers/char/tpm/tpm_crb.c new file +11
-0+ rc =devm_add_action (dev, crb_release, chip); +if (rc) + goto out_err; + +return 0 ; +out_err: +tpm_remove_hardware (chip->dev); +return rc; +} + +static struct acpi_device_id crb_device_ids[] = {const? Not sure
Jason
Re: [PATCH v1 11/12] tpm: Driver for TPM 2.0 CRB Interface
In reply to Jason GunthorpeQuoted 52 lines · Jason Gunthorpe
drivers/char/tpm/tpm_crb.c line 136
Quoted 4 lines · Jarkko Sakkinen
drivers/char/tpm/tpm_crb.c new file +4
-0+ offset = cca->rsp_pa - priv->cca_pa; + resp = (u8 *) ((unsigned long ) cca + offset); +memcpy (buf, resp,6 ); + expected =be32_to_cpu (*(__be32 *) (buf +2 ));
be32_to_cpup?drivers/char/tpm/tpm_crb.c line 226
Quoted 5 lines
drivers/char/tpm/tpm_crb.c new file +5
-0+static void crb_release (void *data) +{ +struct tpm_chip *chip = (struct tpm_chip *) data; +tpm_remove_hardware (chip->dev); +}Please use a proper remove function on the device driver, not a devm function like this. '
tpm_remove_hardware' is the wrong name for a new API, it must be 'tpm_chip_unregister' (ie the undo of 'tpm_chip_register')drivers/char/tpm/tpm_crb.c line 240
Quoted 13 lines
drivers/char/tpm/tpm_crb.c new file +13
-0+static int crb_acpi_add (struct acpi_device *device) +{ +struct tpm_chip *chip; +struct acpi_tpm2 *buf; +struct crb_priv *priv; +struct device *dev = &device->dev; +acpi_status status; +u32 sm; +int rc; + + chip =tpm_chip_alloc (dev, &tpm_crb); +if (!chip) +return -ENODEV ;Lets use ERRPTR here
drivers/char/tpm/tpm_crb.c line 244
Quoted 3 lines
drivers/char/tpm/tpm_crb.c new file +3
-0+ chip->tpm2 = true; + + rc =tpm_chip_register (chip);This is in the wrong place, it needs to be the last call in the probe function - the driver must be fully operational when register is called, that is one of the bugs the new interface must be fixing.
drivers/char/tpm/tpm_crb.c line 299
Quoted 5 lines
drivers/char/tpm/tpm_crb.c new file +5
-0+ rc =tpm_do_selftest (chip); +if (rc) { + rc = -ENODEV ; + goto out_err; + }The common TPM command startup sequence should be in
tpm_chip_register(), so move this into there.
Quoted 13 lines
drivers/char/tpm/tpm_crb.c line 311
Quoted 11 lines
drivers/char/tpm/tpm_crb.c new file +11
-0+ rc =devm_add_action (dev, crb_release, chip); +if (rc) + goto out_err; + +return 0 ; +out_err: +tpm_remove_hardware (chip->dev); +return rc; +} + +static struct acpi_device_id crb_device_ids[] = {const? Not sure
Cannot be because acpi_bus_register_driver() does not take a const pointer.
Quoted 1 line
Jason
/Jarkko
PATCH 12/12 tpm: TPM2 sysfs attributes
In reply to Jarkko SakkinenAdded tpm2-sysfs.c that implements sysfs attributes for a TPM2 device.
--- drivers/char/tpm/Makefile | 2 +- drivers/char/tpm/tpm-chip.c | 10 +- drivers/char/tpm/tpm-interface.c | 1 + drivers/char/tpm/tpm2-commands.c | 2 +- drivers/char/tpm/tpm2-sysfs.c | 242 +++++++++++++++++++++++++++++++++++++++ drivers/char/tpm/tpm2.h | 31 +++++ 6 files changed, 284 insertions(+), 4 deletions(-) create mode 100644 drivers/char/tpm/tpm2-sysfs.c
drivers/char/tpm/Makefile +1 -1
@@ -2,7 +2,7 @@ # Makefile for the kernel tpm device drivers. # obj-$(CONFIG_TCG_TPM) += tpm.o -tpm-y := tpm-interface.o tpm-dev.o tpm-sysfs.o tpm-chip.o tpm2-commands.o +tpm-y := tpm-interface.o tpm-dev.o tpm-sysfs.o tpm-chip.o tpm2-commands.o tpm2-sysfs.o tpm-$(CONFIG_ACPI) += tpm_ppi.o ifdef CONFIG_ACPI
drivers/char/tpm/tpm-chip.c +8 -2
@@ -127,7 +127,10 @@ int tpm_chip_register(struct tpm_chip *chip)if (rc)return rc; - rc =tpm_sysfs_add_device (chip); +if (chip->tpm2) + rc =tpm2_sysfs_add_device (chip); +else + rc =tpm_sysfs_add_device (chip);if (rc) goto del_misc;
@@ -160,7 +163,10 @@ void tpm_chip_unregister(struct tpm_chip *chip)synchronize_rcu ();tpm_dev_del_device (chip); -tpm_sysfs_del_device (chip); +if (chip->tpm2) +tpm2_sysfs_del_device (chip); +else +tpm_sysfs_del_device (chip);tpm_remove_ppi (&chip->dev->kobj);if (!chip->tpm2)
drivers/char/tpm/tpm-interface.c +1 -0
@@ -899,6 +899,7 @@ void tpm_remove_hardware(struct device *dev)tpm_chip_unregister (chip); +/* write it this way to be explicit (chip->dev == dev) */ put_device (chip->dev); }
drivers/char/tpm/tpm2-commands.c +1 -1
@@ -195,7 +195,7 @@ ssize_t tpm2_get_tpm_pt(struct device *dev, u32 property_id, u32* value, cmd.header.in = tpm2_get_tpm_pt_header; cmd.params.tpm2_get_tpm_pt_in.cap_id =cpu_to_be32 (TPM2_CAP_TPM_PROPERTIES ); - cmd.params.tpm2_get_tpm_pt_in.property_id = property_id; + cmd.params.tpm2_get_tpm_pt_in.property_id =cpu_to_be32 (property_id); cmd.params.tpm2_get_tpm_pt_in.property_cnt =cpu_to_be32 (1 ); rc =tpm_transmit_cmd (chip, &cmd,sizeof (cmd), desc);
drivers/char/tpm/tpm2-sysfs.c new file +242 -0
242 lines not on this page · raw message
drivers/char/tpm/tpm2.h +31 -0
@@ -59,6 +59,34 @@ enum tpm2_capabilities { TPM2_CAP_TPM_PROPERTIES = 6, }; +enum tpm2_tpm_properties { +TPM2_PT_MANUFACTURER =0x00000105 , +TPM2_PT_FIRMWARE_VERSION_1 =0x00000111 , +TPM2_PT_FIRMWARE_VERSION_2 =0x00000111 , +TPM2_PT_PERMANENT =0x00000200 , +TPM2_PT_STARTUP_CLEAR =0x00000201 , +}; + +struct tpm2_permanent { +unsigned int owner_auth_set :1 ; +unsigned int endorsement_auth_set :1 ; +unsigned int lockout_auth_set :1 ; +unsigned int reserved1 :5 ; +unsigned int disable_clear :1 ; +unsigned int in_lockout :1 ; +unsigned int tpm_generated_eps :1 ; +unsigned int reserved2 :21 ; +}; + +struct tpm2_startup_clear { +unsigned int ph_enable :1 ; +unsigned int sh_enable :1 ; +unsigned int eh_enable :1 ; +unsigned int ph_enable_nv :1 ; +unsigned int reserved :27 ; +unsigned int orderly :1 ; +}; +struct tpm_chip ;#define TPM2_CC_FIRST 0x11F
@@ -74,4 +102,7 @@ int tpm2_do_selftest(struct tpm_chip *chip);int tpm2_get_random (struct tpm_chip *chip,u8 *out,size_t max);void tpm2_gen_interrupt (struct tpm_chip *chip); +int tpm2_sysfs_add_device (struct tpm_chip *chip); +void tpm2_sysfs_del_device (struct tpm_chip *chip); +#endif /* __DRIVERS_CHAR_TPM2_H__ */
Signature · 1 line
2.1.0
Re: [PATCH v1 12/12] tpm: TPM2 sysfs attributes
Quoted 2 lines · Jarkko Sakkinen
Added
tpm2-sysfs.cthat implements sysfs attributes for a TPM2 device.
You need to document in Documentation every new sysfs that is added.
The existing ones are not documented :(
drivers/char/tpm/tpm-interface.c void tpm_remove_hardware(struct device *dev) · line 905
Quoted 9 lines
+++
b/drivers/char/tpm/tpm-interface.cdrivers/char/tpm/tpm-interface.c +1
-0@@ -899,6 +899,7 @@ void tpm_remove_hardware(struct device *dev)tpm_chip_unregister (chip); +/* write it this way to be explicit (chip->dev == dev) */ put_device (chip->dev); }
Hunk does not belong in this patch
drivers/char/tpm/tpm2-commands.c ssize_t tpm2_get_tpm_pt(struct device *dev, u32 property_id, u32* value, · line 199
Quoted 10 lines
drivers/char/tpm/tpm2-commands.c +2
-1+++ b/drivers/char/tpm/tpm2-commands.c@@ -195,7 +195,7 @@ ssize_t tpm2_get_tpm_pt(struct device *dev, u32 property_id, u32* value, cmd.header.in = tpm2_get_tpm_pt_header; cmd.params.tpm2_get_tpm_pt_in.cap_id =cpu_to_be32 (TPM2_CAP_TPM_PROPERTIES ); - cmd.params.tpm2_get_tpm_pt_in.property_id = property_id; + cmd.params.tpm2_get_tpm_pt_in.property_id =cpu_to_be32 (property_id); cmd.params.tpm2_get_tpm_pt_in.property_cnt =cpu_to_be32 (1 );
Hunk does not belong in this patch
drivers/char/tpm/tpm2-commands.c ssize_t tpm2_get_tpm_pt(struct device *dev, u32 property_id, u32* value,
Quoted 3 lines
drivers/char/tpm/tpm2-commands.c +3
-0+static ssize_t pcrs_show (struct device *dev,struct device_attribute *attr, +char *buf) +{
The pcrs file never conformed to the sysfs rules, if TPM2 is getting a whole new file set, I wouldn't mind seeing it not include the non-conformant ones. What do you think?
drivers/char/tpm/tpm2-commands.c
Quoted 3 lines
drivers/char/tpm/tpm2-commands.c +3
-0+static ssize_t caps_show (struct device *dev,struct device_attribute *attr, +char *buf) +{
Ditto.. The manfacturer number should probably be its own file
Quoted 6 lines
drivers/char/tpm/tpm2-commands.c +6
-0+static ssize_t durations_show (struct device *dev,struct device_attribute *attr, +char *buf) +{ +struct tpm_chip *chip =dev_get_drvdata (dev); + +if (chip->vendor.duration[TPM_LONG ] ==0 )
drivers/char/tpm/tpm2-commands.c
Quoted 10 lines
drivers/char/tpm/tpm2-commands.c +10
-0+return 0 ; + +return sprintf (buf,"%d %d %d [%s]\n" , +jiffies_to_usecs (chip->vendor.duration[TPM_SHORT ]), +jiffies_to_usecs (chip->vendor.duration[TPM_MEDIUM ]), +jiffies_to_usecs (chip->vendor.duration[TPM_LONG ]), + chip->vendor.duration_adjusted + ?"adjusted" :"original" ); +} +static DEVICE_ATTR_RO (durations);
Seem useless since the durations are constant, drop it?
Quoted 4 lines
drivers/char/tpm/tpm2-commands.c +4
-0+static ssize_t timeouts_show (struct device *dev,struct device_attribute *attr, +char *buf) +{ +struct tpm_chip *chip =dev_get_drvdata (dev);
drivers/char/tpm/tpm2-commands.c
Quoted 10 lines
drivers/char/tpm/tpm2-commands.c +10
-0+ +return sprintf (buf,"%d %d %d %d [%s]\n" , +jiffies_to_usecs (chip->vendor.timeout_a), +jiffies_to_usecs (chip->vendor.timeout_b), +jiffies_to_usecs (chip->vendor.timeout_c), +jiffies_to_usecs (chip->vendor.timeout_d), + chip->vendor.timeout_adjusted + ?"adjusted" :"original" ); +} +static DEVICE_ATTR_RO (timeouts);
Ditto
Quoted 11 lines
drivers/char/tpm/tpm2-commands.c +11
-0+static ssize_t version_show (struct device *dev,struct device_attribute *attr, +char *buf) +{ +char *str = buf; + + str +=sprintf (str,"2.0\n" ); + +return str - buf; +} + +static DEVICE_ATTR_RO (version);
drivers/char/tpm/tpm2-commands.c
Quoted 10 lines
drivers/char/tpm/tpm2-commands.c +10
-0+ + +static ssize_t tpm2_show (struct device *dev,struct device_attribute *attr, +char *buf) +{ +struct tpm_chip *chip =dev_get_drvdata (dev); + +return sprintf (buf,"%d\n" , chip->tpm2); +} +static DEVICE_ATTR_RO (tpm2);
Two things for the same report? Drop one?
Also, I think some thought is needed for the char interface - some kind of ioctl to enter TPM2 mode and EINVAL access until that is done?
Finally, this is in the wrong place in sysfs, I suspect it should be attached to the char device node, not the platform device node? We should at least investigate this...
Quoted 9 lines
drivers/char/tpm/tpm2-commands.c +9
-0+struct tpm2_permanent { +unsigned int owner_auth_set :1 ; +unsigned int endorsement_auth_set :1 ; +unsigned int lockout_auth_set :1 ; +unsigned int reserved1 :5 ; +unsigned int disable_clear :1 ; +unsigned int in_lockout :1 ; +unsigned int tpm_generated_eps :1 ; +unsigned int reserved2 :21 ;
drivers/char/tpm/tpm2-commands.c
Quoted 10 lines
drivers/char/tpm/tpm2-commands.c +10
-0+}; + +struct tpm2_startup_clear { +unsigned int ph_enable :1 ; +unsigned int sh_enable :1 ; +unsigned int eh_enable :1 ; +unsigned int ph_enable_nv :1 ; +unsigned int reserved :27 ; +unsigned int orderly :1 ; +};
This idea is not portable, you cannot use bitfields to index bits in a word like this. Please use constants defined with BIT(xx)
Next posting can you include a github link? Thanks
Jason
Re: [tpmdd-devel] [PATCH v1 12/12] tpm: TPM2 sysfs attributes
Quoted 10 lines · Jason Gunthorpe
Quoted 9 lines · Jarkko Sakkinen
drivers/char/tpm/tpm2-sysfs.c new file +9
-0+static ssize_t durations_show (struct device *dev,struct device_attribute *attr, +char *buf) +{ +struct tpm_chip *chip =dev_get_drvdata (dev); + +if (chip->vendor.duration[TPM_LONG ] ==0 ) +return 0 ; + + return sprintf(buf, "%d %d %d [%s]\n",
Quoted 8 lines
drivers/char/tpm/tpm2-sysfs.c line 169
Quoted 7 lines
drivers/char/tpm/tpm2-sysfs.c new file +7
-0+jiffies_to_usecs (chip->vendor.duration[TPM_SHORT ]), +jiffies_to_usecs (chip->vendor.duration[TPM_MEDIUM ]), +jiffies_to_usecs (chip->vendor.duration[TPM_LONG ]), + chip->vendor.duration_adjusted + ? "adjusted" : "original"); +} +static DEVICE_ATTR_RO (durations);Seem useless since the durations are constant, drop it?
We show them for TPM 1.2 as well, so I'd keep them fo TPM2.
Quoted 15 lines
Quoted 5 lines
drivers/char/tpm/tpm2-sysfs.c new file +4
-0+static ssize_t timeouts_show (struct device *dev,struct device_attribute *attr, +char *buf) +{ +struct tpm_chip *chip =dev_get_drvdata (dev);drivers/char/tpm/tpm2-sysfs.c line 184
Quoted 10 lines
drivers/char/tpm/tpm2-sysfs.c new file +10
-0+ +return sprintf (buf,"%d %d %d %d [%s]\n" , +jiffies_to_usecs (chip->vendor.timeout_a), +jiffies_to_usecs (chip->vendor.timeout_b), +jiffies_to_usecs (chip->vendor.timeout_c), +jiffies_to_usecs (chip->vendor.timeout_d), + chip->vendor.timeout_adjusted + ?"adjusted" :"original" ); +} +static DEVICE_ATTR_RO (timeouts);
With all the problems we had with TPM 1.2 TPM's wrong timeouts and showing them in sysfs, why not show them for TPM2 as well?
Re: [tpmdd-devel] [PATCH v1 12/12] tpm: TPM2 sysfs attributes
Quoted 20 lines · Stefan Berger
Quoted 10 lines · Jason Gunthorpe
Quoted 9 lines · Jarkko Sakkinen
drivers/char/tpm/tpm2-sysfs.c new file +9
-0+static ssize_t durations_show (struct device *dev,struct device_attribute *attr, +char *buf) +{ +struct tpm_chip *chip =dev_get_drvdata (dev); + +if (chip->vendor.duration[TPM_LONG ] ==0 ) +return 0 ; + + return sprintf(buf, "%d %d %d [%s]\n",Quoted 8 lines
drivers/char/tpm/tpm2-sysfs.c line 169
Quoted 7 lines
drivers/char/tpm/tpm2-sysfs.c new file +7
-0+jiffies_to_usecs (chip->vendor.duration[TPM_SHORT ]), +jiffies_to_usecs (chip->vendor.duration[TPM_MEDIUM ]), +jiffies_to_usecs (chip->vendor.duration[TPM_LONG ]), + chip->vendor.duration_adjusted + ? "adjusted" : "original"); +} +static DEVICE_ATTR_RO (durations);Seem useless since the durations are constant, drop it?
Quoted 1 line
We show them for TPM 1.2 as well, so I'd keep them fo TPM2.
The durations are constant and hardwired in the driver for TPM2, and the sysfs file format does not follow the one-value-per-file rule.
So it doesn't display anything useful. In TPM2 mode all the timeouts are constant and known, so I'd rather see it go away.
Quoted 2 lines
With all the problems we had with TPM 1.2 TPM's wrong timeouts and showing them in sysfs, why not show them for TPM2 as well?
We had problems with devices reporting the wrong timeout from their cap queries - that isn't possible in TPM2.
Both of these values should live in debugfs anyhow.
It would be nice to start with a fresh set of correct sysfs files for TPM2, since essentially everything is different about the userspace interface we can safely make a breaking change here.
Jason
Re: [tpmdd-devel] [PATCH v1 12/12] tpm: TPM2 sysfs attributes
Quoted 33 lines · Jason Gunthorpe
Quoted 20 lines · Stefan Berger
Quoted 10 lines · Jason Gunthorpe
Quoted 9 lines · Jarkko Sakkinen
drivers/char/tpm/tpm2-sysfs.c new file +9
-0+static ssize_t durations_show (struct device *dev,struct device_attribute *attr, +char *buf) +{ +struct tpm_chip *chip =dev_get_drvdata (dev); + +if (chip->vendor.duration[TPM_LONG ] ==0 ) +return 0 ; + + return sprintf(buf, "%d %d %d [%s]\n",Quoted 8 lines
drivers/char/tpm/tpm2-sysfs.c line 169
Quoted 7 lines
drivers/char/tpm/tpm2-sysfs.c new file +7
-0+jiffies_to_usecs (chip->vendor.duration[TPM_SHORT ]), +jiffies_to_usecs (chip->vendor.duration[TPM_MEDIUM ]), +jiffies_to_usecs (chip->vendor.duration[TPM_LONG ]), + chip->vendor.duration_adjusted + ? "adjusted" : "original"); +} +static DEVICE_ATTR_RO (durations);Seem useless since the durations are constant, drop it?
Quoted 1 line
We show them for TPM 1.2 as well, so I'd keep them fo TPM2.
The durations are constant and hardwired in the driver for TPM2, and the sysfs file format does not follow the one-value-per-file rule.
So it doesn't display anything useful. In TPM2 mode all the timeouts are constant and known, so I'd rather see it go away.
Quoted 2 lines
With all the problems we had with TPM 1.2 TPM's wrong timeouts and showing them in sysfs, why not show them for TPM2 as well?
Quoted 8 lines
We had problems with devices reporting the wrong timeout from their cap queries - that isn't possible in TPM2.
Both of these values should live in debugfs anyhow.
It would be nice to start with a fresh set of correct sysfs files for TPM2, since essentially everything is different about the userspace interface we can safely make a breaking change here.
I'll drop timeouts and durations. It's easy to add them later if they are needed.
Quoted 1 line
Jason
/Jarkko
Peter Hüwe
maintainerRe: [tpmdd-devel] [PATCH v1 12/12] tpm: TPM2 sysfs attributes
In reply to Jason GunthorpeAm Mittwoch, 24. September 2014, 19:59:40 schrieb Jason Gunthorpe:
Quoted 22 lines · Stefan Berger
Quoted 21 lines · Jason Gunthorpe
Quoted 19 lines · Jarkko Sakkinen
Quoted 6 lines
+static
ssize_tdurations_show(struct device *dev, structdevice_attribute*attr, + char *buf)drivers/char/tpm/tpm2-sysfs.c new file +4
-0+{ +struct tpm_chip *chip =dev_get_drvdata (dev); + +if (chip->vendor.duration[TPM_LONG ] ==0 )drivers/char/tpm/tpm2-sysfs.c line 169
Quoted 10 lines
drivers/char/tpm/tpm2-sysfs.c new file +10
-0+return 0 ; + +return sprintf (buf,"%d %d %d [%s]\n" , +jiffies_to_usecs (chip->vendor.duration[TPM_SHORT ]), +jiffies_to_usecs (chip->vendor.duration[TPM_MEDIUM ]), +jiffies_to_usecs (chip->vendor.duration[TPM_LONG ]), + chip->vendor.duration_adjusted + ?"adjusted" :"original" ); +} +static DEVICE_ATTR_RO (durations);Seem useless since the durations are constant, drop it?
Quoted 8 lines
Quoted 1 line
We show them for TPM 1.2 as well, so I'd keep them fo TPM2.
The durations are constant and hardwired in the driver for TPM2, and the sysfs file format does not follow the one-value-per-file rule.
So it doesn't display anything useful. In TPM2 mode all the timeouts are constant and known, so I'd rather see it go away.
If it is more or less a no-op since we have set chip-
Quoted 1 line
vendor.duration[TPM_SHORT] for other code to work, we can show the values for
TPM2.0.
However I think we don't need any extra code to show or hide the sysfs files for TPM2.0.
Peter
Re: [tpmdd-devel] [PATCH v1 12/12] tpm: TPM2 sysfs attributes
Quoted 3 lines · Peter Hüwe
If it is more or less a no-op since we have set chip->vendor.duration[TPM_SHORT] for other code to work, we can show the values for TPM2.0.
It is not a no-op, Jarkko created a whole new file for the tpm2 sysfs interface, so the two timeout prints are duplicated code from the tpm1 sysfs interface.
Mind you, not sure if we need separate sysfs files ...
Jason
Peter Hüwe
maintainerRe: [PATCH v1 12/12] tpm: TPM2 sysfs attributes
In reply to Jason GunthorpeAm Mittwoch, 24. September 2014, 19:13:38 schrieb Jason Gunthorpe:
Quoted 7 lines · Jarkko Sakkinen
Quoted 2 lines
Added
tpm2-sysfs.cthat implements sysfs attributes for a TPM2 device.You need to document in Documentation every new sysfs that is added.
The existing ones are not documented :(
For 1.2 - they are.Documentation/ABI/stable/sysfs-class-tpm
So we also now what our stable sysfs abi is :)
Peter
Re: [PATCH v1 12/12] tpm: TPM2 sysfs attributes
In reply to Jason GunthorpeQuoted 7 lines · Jason Gunthorpe
Quoted 2 lines · Jarkko Sakkinen
Added
tpm2-sysfs.cthat implements sysfs attributes for a TPM2 device.You need to document in Documentation every new sysfs that is added.
The existing ones are not documented :(
This came up in Peters reply (you probably saw that).
https://www.kernel.org/doc/Documentation/ABI/stable/sysfs-class-tpm
Quoted 11 lines
drivers/char/tpm/tpm-interface.c void tpm_remove_hardware(struct device *dev) · line 905
Quoted 9 lines
+++
b/drivers/char/tpm/tpm-interface.cdrivers/char/tpm/tpm-interface.c +1
-0@@ -899,6 +899,7 @@ void tpm_remove_hardware(struct device *dev)tpm_chip_unregister (chip); +/* write it this way to be explicit (chip->dev == dev) */ put_device (chip->dev); }Hunk does not belong in this patch
Ack (thanks).
Quoted 4 lines
Quoted 4 lines
drivers/char/tpm/tpm2-commands.c +1
-0+++ b/drivers/char/tpm/tpm2-commands.c@@ -195,7 +195,7 @@ ssize_t tpm2_get_tpm_pt(struct device *dev, u32 property_id, u32* value,
Quoted 8 lines
drivers/char/tpm/tpm2-commands.c ssize_t tpm2_get_tpm_pt(struct device *dev, u32 property_id, u32* value, · line 199
Quoted 6 lines
drivers/char/tpm/tpm2-commands.c +1
-1cmd.header.in = tpm2_get_tpm_pt_header; cmd.params.tpm2_get_tpm_pt_in.cap_id =cpu_to_be32 (TPM2_CAP_TPM_PROPERTIES ); - cmd.params.tpm2_get_tpm_pt_in.property_id = property_id; + cmd.params.tpm2_get_tpm_pt_in.property_id =cpu_to_be32 (property_id); cmd.params.tpm2_get_tpm_pt_in.property_cnt =cpu_to_be32 (1 );Hunk does not belong in this patch
Ack (thanks).
Quoted 7 lines
drivers/char/tpm/tpm2-commands.c ssize_t tpm2_get_tpm_pt(struct device *dev, u32 property_id, u32* value,
Quoted 3 lines
drivers/char/tpm/tpm2-commands.c +3
-0+static ssize_t pcrs_show (struct device *dev,struct device_attribute *attr, +char *buf) +{The pcrs file never conformed to the sysfs rules, if TPM2 is getting a whole new file set, I wouldn't mind seeing it not include the non-conformant ones. What do you think?
I think that it's better to put extra focus on these sysfs attributes in first patch set because it's user space visible. What's wrong in the current pcrs file?
Quoted 5 lines
drivers/char/tpm/tpm2-commands.c
Quoted 3 lines
drivers/char/tpm/tpm2-commands.c +3
-0+static ssize_t caps_show (struct device *dev,struct device_attribute *attr, +char *buf) +{Ditto.. The manfacturer number should probably be its own file
Maybe here would make sense to have three files:
- manufacturer
- firmware_1
- firmware_2
More or less following the name of the TPM properties in the specification.
Quoted 60 lines
Quoted 6 lines
drivers/char/tpm/tpm2-commands.c +6
-0+static ssize_t durations_show (struct device *dev,struct device_attribute *attr, +char *buf) +{ +struct tpm_chip *chip =dev_get_drvdata (dev); + +if (chip->vendor.duration[TPM_LONG ] ==0 )drivers/char/tpm/tpm2-commands.c
Quoted 10 lines
drivers/char/tpm/tpm2-commands.c +10
-0+return 0 ; + +return sprintf (buf,"%d %d %d [%s]\n" , +jiffies_to_usecs (chip->vendor.duration[TPM_SHORT ]), +jiffies_to_usecs (chip->vendor.duration[TPM_MEDIUM ]), +jiffies_to_usecs (chip->vendor.duration[TPM_LONG ]), + chip->vendor.duration_adjusted + ?"adjusted" :"original" ); +} +static DEVICE_ATTR_RO (durations);Seem useless since the durations are constant, drop it?
Quoted 4 lines
drivers/char/tpm/tpm2-commands.c +4
-0+static ssize_t timeouts_show (struct device *dev,struct device_attribute *attr, +char *buf) +{ +struct tpm_chip *chip =dev_get_drvdata (dev);drivers/char/tpm/tpm2-commands.c
Quoted 10 lines
drivers/char/tpm/tpm2-commands.c +10
-0+ +return sprintf (buf,"%d %d %d %d [%s]\n" , +jiffies_to_usecs (chip->vendor.timeout_a), +jiffies_to_usecs (chip->vendor.timeout_b), +jiffies_to_usecs (chip->vendor.timeout_c), +jiffies_to_usecs (chip->vendor.timeout_d), + chip->vendor.timeout_adjusted + ?"adjusted" :"original" ); +} +static DEVICE_ATTR_RO (timeouts);Ditto
Quoted 11 lines
drivers/char/tpm/tpm2-commands.c +11
-0+static ssize_t version_show (struct device *dev,struct device_attribute *attr, +char *buf) +{ +char *str = buf; + + str +=sprintf (str,"2.0\n" ); + +return str - buf; +} + +static DEVICE_ATTR_RO (version);drivers/char/tpm/tpm2-commands.c
Quoted 10 lines
drivers/char/tpm/tpm2-commands.c +10
-0+ + +static ssize_t tpm2_show (struct device *dev,struct device_attribute *attr, +char *buf) +{ +struct tpm_chip *chip =dev_get_drvdata (dev); + +return sprintf (buf,"%d\n" , chip->tpm2); +} +static DEVICE_ATTR_RO (tpm2);Two things for the same report? Drop one?
Quoted 6 lines
Also, I think some thought is needed for the char interface - some kind of ioctl to enter TPM2 mode and EINVAL access until that is done?
Finally, this is in the wrong place in sysfs, I suspect it should be attached to the char device node, not the platform device node? We should at least investigate this...
This was forgotten. Should not be here at all. Instead we have the variable 'version' to state specification family and level.
I did not fully understand the comment about tpm2 flag. Why driver cannot set it when it initializes the device like with this based on value of the STS3?
Quoted 14 lines
Quoted 14 lines
drivers/char/tpm/tpm2-commands.c +14
-0+struct tpm2_permanent { +unsigned int owner_auth_set :1 ; +unsigned int endorsement_auth_set :1 ; +unsigned int lockout_auth_set :1 ; +unsigned int reserved1 :5 ; +unsigned int disable_clear :1 ; +unsigned int in_lockout :1 ; +unsigned int tpm_generated_eps :1 ; +unsigned int reserved2 :21 ; +}; + +struct tpm2_startup_clear { +unsigned int ph_enable :1 ; +unsigned int sh_enable :1 ;
Quoted 8 lines
drivers/char/tpm/tpm2-commands.c
Quoted 5 lines
drivers/char/tpm/tpm2-commands.c +5
-0+ unsigned int eh_enable : 1; + unsigned int ph_enable_nv : 1; + unsigned int reserved : 27; + unsigned int orderly : 1; +};This idea is not portable, you cannot use bitfields to index bits in a word like this. Please use constants defined with BIT(xx)
Thanks, I'll change this.
Quoted 1 line
Next posting can you include a github link? Thanks
Yup sure. I do everything for v2 in tpm2-v1 by adding fixes on top of these patches. When things look good there I'll create a new branch tpm2-v2 and prepare the next patch set.
Quoted 1 line
Jason
/Jarkko
Re: [PATCH v1 12/12] tpm: TPM2 sysfs attributes
Quoted 7 lines · Jarkko Sakkinen
Quoted 3 lines
The pcrs file never conformed to the sysfs rules, if TPM2 is getting a whole new file set, I wouldn't mind seeing it not include the non-conformant ones. What do you think?
I think that it's better to put extra focus on these sysfs attributes in first patch set because it's user space visible. What's wrong in the current pcrs file?
Each PCR should be a distinct sysfs file, probably with a directory. One Value Per File is the rule.
Quoted 6 lines
Quoted 5 lines
drivers/char/tpm/tpm2-sysfs.c line 112
Quoted 3 lines
drivers/char/tpm/tpm2-sysfs.c new file +3
-0+static ssize_t caps_show (struct device *dev,struct device_attribute *attr, +char *buf) +{Ditto.. The manfacturer number should probably be its own file
Quoted 8 lines
Maybe here would make sense to have three files:
- manufacturer
-firmware_1
-firmware_2More or less following the name of the TPM properties in the specification.
Probably, maybe firmware_1/2 could be combined if they are the same logical value? (I've always expressed it as firmware_1.firwmare_2?)
Quoted 3 lines
I did not fully understand the comment about tpm2 flag. Why driver cannot set it when it initializes the device like with this based on value of the STS3?
I was talking about the /dev/ char device - a random application today will open it and send TPM1 formed messages. Those should be refused with EINVAL for a TPM2 chip unless the application declares via IOCTL that it will be sending TPM2 messages.
Otherwise the API contract for the /dev/ device (write TPM1 formed messages) is broken..
Jason
Peter Hüwe
maintainerRe: [PATCH v1 12/12] tpm: TPM2 sysfs attributes
Am Mittwoch, 24. September 2014, 22:19:38 schrieb Jason Gunthorpe:
Quoted 11 lines · Jarkko Sakkinen
Quoted 7 lines
Quoted 3 lines
The pcrs file never conformed to the sysfs rules, if TPM2 is getting a whole new file set, I wouldn't mind seeing it not include the non-conformant ones. What do you think?
I think that it's better to put extra focus on these sysfs attributes in first patch set because it's user space visible. What's wrong in the current pcrs file?
Each PCR should be a distinct sysfs file, probably with a directory. One Value Per File is the rule.
That would be 24*2 files only for pcrs...Documentation/filesystems/sysfs.txt says:
"
Attributes should be ASCII text files, preferably with only one value per file. It is noted that it may not be efficient to contain only one value per file, so it is socially acceptable to express an array of values of the same type. "
So it would be more or less o.k. to have it in one file like we had.
Then however:
"Mixing types, expressing multiple lines of data, and doing fancy formatting of data is heavily frowned upon. Doing these things may get you publicly humiliated and your code rewritten without notice."
Do we really need the PCRs as sysfs files?
I know they are handy as a dev, but does any application actually use this directly?
Thanks,
Peter
Re: [PATCH v1 12/12] tpm: TPM2 sysfs attributes
Quoted 6 lines · Peter Hüwe
Am Mittwoch, 24. September 2014, 22:19:38 schrieb Jason Gunthorpe:
Quoted 5 lines · Jarkko Sakkinen
Quoted 4 lines
Quoted 3 lines
The pcrs file never conformed to the sysfs rules, if TPM2 is getting a whole new file set, I wouldn't mind seeing it not include the non-conformant ones. What do you think?
Quoted 8 lines
Quoted 6 lines
Quoted 3 lines
I think that it's better to put extra focus on these sysfs attributes in first patch set because it's user space visible. What's wrong in the current pcrs file?
Each PCR should be a distinct sysfs file, probably with a directory. One Value Per File is the rule.
That would be 24*2 files only for pcrs...
Some subsystems do just that..
$ ls /sys/class/infiniband/qib0/ports/1/sl2vl/ 0 1 10 11 12 13 14 15 2 3 4 5 6 7 8 9
Quoted 8 lines
Documentation/filesystems/sysfs.txtsays:"
Attributes should be ASCII text files, preferably with only one value per file. It is noted that it may not be efficient to contain only one value per file, so it is socially acceptable to express an array of values of the same type. "
Quoted 6 lines
So it would be more or less o.k. to have it in one file like we had.
Then however:
"Mixing types, expressing multiple lines of data, and doing fancy formatting of data is heavily frowned upon. Doing these things may get you publicly humiliated and your code rewritten without notice."
I think taken together that says an array of 128 bit PCR hex values without new lines or other formatting would be OK. But the breakdown and fancy formatting we do is not OK.
Quoted 2 lines
Do we really need the PCRs as sysfs files? I know they are handy as a dev, but does any application actually use this directly?
No idea, but using tpm2 to find out seems like a reasonable idea, especially if the pcr meaning changes in some way with TPM2 ..
Jason
Re: [PATCH v1 12/12] tpm: TPM2 sysfs attributes
Quoted 6 lines · Jason Gunthorpe
Quoted 1 line
That would be 24*2 files only for pcrs...
Some subsystems do just that..
$ ls /sys/class/infiniband/qib0/ports/1/sl2vl/ 0 1 10 11 12 13 14 15 2 3 4 5 6 7 8 9
They use static structures in drivers/infiniband/hw/qib/qib_sysfs.c and it does not looks a mess. I would prefer to create struct attribute entries dynamically if there's clean and easy way to do that.
/Jarkko
Re: [tpmdd-devel] [PATCH v1 12/12] tpm: TPM2 sysfs attributes
Quoted 11 lines · Jarkko Sakkinen
Quoted 6 lines · Jason Gunthorpe
Quoted 1 line
That would be 24*2 files only for pcrs...
Some subsystems do just that..
$ ls /sys/class/infiniband/qib0/ports/1/sl2vl/ 0 1 10 11 12 13 14 15 2 3 4 5 6 7 8 9They use static structures in
drivers/infiniband/hw/qib/qib_sysfs.cand it does not looks a mess. I would prefer to create struct attribute entries dynamically if there's clean and easy way to do that.
I gave this a shot:
https://github.com/jsakkine/linux-tpm2/commit/dffce68ce34da265a62908dec71b2d85fc16824f
I want to initialize dynamically so that it is easy to support TPM_PT_PCR_COUNT later.
/Jarkko
Re: [tpmdd-devel] [PATCH v1 12/12] tpm: TPM2 sysfs attributes
Quoted 14 lines · Jarkko Sakkinen
Quoted 5 lines · Jarkko Sakkinen
Quoted 4 lines · Jason Gunthorpe
Quoted 1 line
That would be 24*2 files only for pcrs...
Some subsystems do just that..
Quoted 7 lines
Quoted 2 lines
$ ls /sys/class/infiniband/qib0/ports/1/sl2vl/ 0 1 10 11 12 13 14 15 2 3 4 5 6 7 8 9They use static structures in
drivers/infiniband/hw/qib/qib_sysfs.cand it does not looks a mess. I would prefer to create struct attribute entries dynamically if there's clean and easy way to do that.
Quoted 6 lines
I gave this a shot:
https://github.com/jsakkine/linux-tpm2/commit/dffce68ce34da265a62908dec71b2d85fc16824f
I want to initialize dynamically so that it is easy to support
TPM_PT_PCR_COUNTlater.
You can't use a static pcr_dev_attrs, this has to be allocated in the chip structure (because of the NULL). Otherwise looks about right (although there are more problematic core details here, like racing of the tpm dev create with the creation of the sysfs files)
Do you have a reason to have the pcrs in sysfs? I'd be just as happy to see them dropped or moved to debugfs for TPM2 as well.
Jason
Re: [tpmdd-devel] [PATCH v1 12/12] tpm: TPM2 sysfs attributes
Quoted 19 lines · Jason Gunthorpe
Quoted 18 lines · Jarkko Sakkinen
Quoted 5 lines · Jarkko Sakkinen
Quoted 4 lines · Jason Gunthorpe
Quoted 1 line
That would be 24*2 files only for pcrs...
Some subsystems do just that..
Quoted 7 lines
Quoted 2 lines
$ ls /sys/class/infiniband/qib0/ports/1/sl2vl/ 0 1 10 11 12 13 14 15 2 3 4 5 6 7 8 9They use static structures in
drivers/infiniband/hw/qib/qib_sysfs.cand it does not looks a mess. I would prefer to create struct attribute entries dynamically if there's clean and easy way to do that.I gave this a shot:
https://github.com/jsakkine/linux-tpm2/commit/dffce68ce34da265a62908dec71b2d85fc16824f
Quoted 7 lines
Quoted 2 lines
I want to initialize dynamically so that it is easy to support
TPM_PT_PCR_COUNTlater.You can't use a static
pcr_dev_attrs, this has to be allocated in the chip structure (because of the NULL). Otherwise looks about right (although there are more problematic core details here, like racing of the tpm dev create with the creation of the sysfs files)
I improved things and pushed a commit that encapsulates PCR bank into struct pcrs_kobj (internal struct in tpm2-sysfs.c).
This brings me to my question. In TPM2 there is not just PCR bank with SHA-1 hashes but there are multiple PCR banks.
The way I plan to represent this is:
pcrs/<tag for banks hash algorithm>/<PCR index>
My last commit provides most of the code for implementing this although in the initial patch set I would take a short cut and only show SHA-1 PCRs. The important thing is that it is put into pcrs/sha1 directory.
Quoted 2 lines
Do you have a reason to have the pcrs in sysfs? I'd be just as happy to see them dropped or moved to debugfs for TPM2 as well.
Well, I at least find it useful debugging tool sometimes. And now it is more useful because PCR values are machine readable.
I will include this to the v2 patch set. When we have a clean patch set with all the fixes applied into tpm2-v1 branch it will be a better time to evaluate what is mandatory and what can be postponed.
Quoted 1 line
Jason
/Jarkko
Quoted 2 lines · Jarkko Sakkinen
This patch set enables TPM2 protocol and provides drivers for FIFO and CRB interfaces.
Known issues so far:
- le32/le64_to_cpu()'s and one cpu_to_le32 missing from tpm_crb.c assuming that CRB driver would be used in big-endian architecture.
- I still have troubles having FIFO testing environment so it would not be a big surprise if it had broke for some reason (help with testing and/or bug fixes for FIFO would be highly appreciated).
Notes about the implementation:
- Reworked the code base to the direction that Jason Gunthorpe suggested.
- Moved to use devres in tpm_crb as Jason suggested.
- Did some groundwork for implementing Stefan Bergers suggestions to tpm_crb.
I hope that it is now more in right direction than in my preview.
I'll push fixes on top of tpm2-v1 branch [1] and do not rebase it anymore and therefore it is a good testing branch.
When things look good enough I'll create tpm2-v2 branch and prepare and send a new patch set.
[1] https://github.com/jsakkine/linux-tpm2/
/Jarko
Quoted 36 lines
Jarkko Sakkinen (8):
tpm: prepare TPM driver for adding TPM2 support
tpm: TPM2 support fortpm_pcr_read()
tpm: TPM2 support fortpm_do_selftest()
tpm: addedtpm2_get_tpm_pt()
tpm: TPM2 support fortpm_pcr_extend()
tpm: TPM2 support fortpm_get_random().
tpm: Driver for TPM 2.0 CRB Interface
tpm: TPM2 sysfs attributesWill Arthur (4):
tpm: TPM2 support fortpm_calc_ordinal_durations()
tpm: TPM2 support fortpm_startup()
tpm: TPM2 support fortpm_gen_interrupt().
tpm: TPM 2.0 FIFO Interfacedrivers/char/tpm/Kconfig | 9 + drivers/char/tpm/Makefile | 3 +- drivers/char/tpm/tpm-chip.c | 175 ++++++++++++++++ drivers/char/tpm/tpm-interface.c | 160 +++++---------- drivers/char/tpm/tpm.h | 84 ++++++++ drivers/char/tpm/tpm2-commands.c | 422 +++++++++++++++++++++++++++++++++++++++ drivers/char/tpm/tpm2-sysfs.c | 242 ++++++++++++++++++++++ drivers/char/tpm/tpm2.h | 108 ++++++++++ drivers/char/tpm/tpm_crb.c | 332 ++++++++++++++++++++++++++++++ drivers/char/tpm/tpm_tis.c | 53 ++++- 10 files changed, 1463 insertions(+), 125 deletions(-) create mode 100644 drivers/char/tpm/tpm-chip.c create mode 100644 drivers/char/tpm/tpm2-commands.c create mode 100644 drivers/char/tpm/tpm2-sysfs.c create mode 100644 drivers/char/tpm/tpm2.h create mode 100644 drivers/char/tpm/tpm_crb.cSignature · 1 line
2.1.0