prepare for TPM 2.0
Subsystems (4)
v2 cover prepare for TPM 2.0
This patch set fixes two race conditions in the TPM subsystem:
* Two-phase initialization for struct tpm_chip so that device can initialize fully initialize before exposing itself to the user space. Also, in future TPM2 devices must be flagged before they can be registered.
* Machines where there are two TPM devices exposed by ACPI have a racy lookup for the PPI interface. This patch set fixes this issues
In addition, transmit_cmd() is renamed as tpm_transmit_cmd() and made opaque so that separate command structure can be introduced for TPM2.
Comments about v1:
* I think this could be pulled to 3.18 because this clearly fixes bugs in the current implementation.
Changes since v1:
* Removed dev_dbgs from tpm-chip.c
* Use driver_lock for dev_mask (the problem was existing also in tpm-interface.c when the code was moved).
* Check for bios_dir nullity when removed (the problem was existing also in tpm-interface.c when the code was moved).
* Cleaned up the control flow in tpm_i2c_stm_st33.c and tpm_atmel.c.
* Cleaned up the control flow in tpm_ppi.c.
Comments about v2:
* Thanks to Jason Gunthorpe for reviewing v1.
* I'm at T2 infosec conference right now so I wasn't able to test the force paths in tpm_atmel.c and tpm_tis.c.
Jarkko Sakkinen (3):
tpm: merge duplicate transmit_cmd() functions
tpm: two-phase chip management functions
tpm: fix multiple race conditions in tpm_ppi.c
drivers/char/tpm/Makefile | 2 +- drivers/char/tpm/tpm-chip.c | 196 +++++++++++++++++++++++++++++++++++ drivers/char/tpm/tpm-dev.c | 4 +- drivers/char/tpm/tpm-interface.c | 201 ++++++------------------------------ drivers/char/tpm/tpm-sysfs.c | 23 +---- drivers/char/tpm/tpm.h | 32 +++--- drivers/char/tpm/tpm_atmel.c | 12 ++- drivers/char/tpm/tpm_i2c_atmel.c | 33 ++---- drivers/char/tpm/tpm_i2c_infineon.c | 37 ++----- drivers/char/tpm/tpm_i2c_nuvoton.c | 44 +++----- drivers/char/tpm/tpm_i2c_stm_st33.c | 38 +++---- drivers/char/tpm/tpm_ibmvtpm.c | 17 ++- drivers/char/tpm/tpm_infineon.c | 29 +++--- drivers/char/tpm/tpm_nsc.c | 14 ++- drivers/char/tpm/tpm_ppi.c | 136 ++++++++++++++---------- drivers/char/tpm/tpm_tis.c | 94 ++++++++--------- drivers/char/tpm/xen-tpmfront.c | 14 +-- 17 files changed, 471 insertions(+), 455 deletions(-) create mode 100644 drivers/char/tpm/tpm-chip.c
Signature · 1 line
2.1.0
PATCH v2 1/3 tpm: merge duplicate transmit_cmd() functions
Merged transmit_cmd() functions in tpm-interface.c and tpm-sysfs.c. Added "tpm_" prefix for consistency sake. Changed cmd parameter as opaque. This enables to use separate command structures for TPM1 and TPM2 commands in future. Loose coupling works fine here.
--- drivers/char/tpm/tpm-dev.c | 4 +-- drivers/char/tpm/tpm-interface.c | 53 +++++++++++++++++++++------------------- drivers/char/tpm/tpm-sysfs.c | 23 ++--------------- drivers/char/tpm/tpm.h | 5 ++-- 4 files changed, 34 insertions(+), 51 deletions(-)
drivers/char/tpm/tpm-dev.c +2 -2
@@ -140,8 +140,8 @@ static ssize_t tpm_write(struct file *file, const char __user *buf, }/* atomic tpm command send and result receive */ - out_size =tpm_transmit (priv->chip, priv->data_buffer, -sizeof (priv->data_buffer)); + out_size =tpm_transmit_cmd (priv->chip, priv->data_buffer, +sizeof (priv->data_buffer),NULL );if (out_size <0 ) {mutex_unlock (&priv->buffer_mutex);return out_size;
drivers/char/tpm/tpm-interface.c +28 -25
149 lines not on this page · raw message
drivers/char/tpm/tpm-sysfs.c +2 -21
@@ -20,25 +20,6 @@#include <linux/device.h> #include "tpm.h" -/* XXX for now this helper is duplicated in tpm-interface.c */ -static ssize_t transmit_cmd (struct tpm_chip *chip,struct tpm_cmd_t *cmd, -int len,const char *desc) -{ -int err; - - len =tpm_transmit (chip, (u8 *) cmd, len); -if (len <0 ) -return len; -else if (len <TPM_HEADER_SIZE ) -return -EFAULT ; - - err =be32_to_cpu (cmd->header.out.return_code); -if (err !=0 && desc) -dev_err (chip->dev,"A TPM error (%d) occurred %s\n" , err, desc); - -return err; -} -#define READ_PUBEK_RESULT_SIZE 314#define TPM_ORD_READPUBEK cpu_to_be32(124)static struct tpm_input_header tpm_readpubek_header = {
@@ -58,8 +39,8 @@ static ssize_t pubek_show(struct device *dev, struct device_attribute *attr,struct tpm_chip *chip =dev_get_drvdata (dev); tpm_cmd.header.in = tpm_readpubek_header; - err =transmit_cmd (chip, &tpm_cmd,READ_PUBEK_RESULT_SIZE , -"attempting to read the PUBEK" ); + err =tpm_transmit_cmd (chip, &tpm_cmd,READ_PUBEK_RESULT_SIZE , +"attempting to read the PUBEK" );if (err) goto out;
drivers/char/tpm/tpm.h +2 -3
@@ -314,9 +314,8 @@ struct tpm_cmd_t { } __packed;ssize_t tpm_getcap (struct device *,__be32 ,cap_t *,const char *); - -ssize_t tpm_transmit (struct tpm_chip *chip,const char *buf, -size_t bufsiz); +ssize_t tpm_transmit_cmd (struct tpm_chip *chip,void *cmd,int len, +const char *desc);extern int tpm_get_timeouts (struct tpm_chip *);extern void tpm_gen_interrupt (struct tpm_chip *);extern int tpm_do_selftest (struct tpm_chip *);
Signature · 1 line
2.1.0
PATCH v2 2/3 tpm: two-phase chip management functions
In reply to Jarkko Sakkinentpm_register_hardware() and tpm_remove_hardware() are called often before initializing the device. This is wrong order since it could be that main TPM driver needs a fully initialized chip to be able to do its job. For example, now it is impossible to move common startup functions such as tpm_do_selftest() to tpm_register_hardware().
Added tpmm_chip_alloc() and tpm_chip_register() where tpm_chip_alloc() reserves memory resources and tpm_chip_register() initializes the device driver. This way it is possible to alter struct tpm_chip attributes and initialize the device driver before passing it to tpm_chip_register().
The framework takes care of freeing struct tpm_chip by using devres API. The broken release callback has been wiped. For example, ACPI drivers do not ever get this callback.
This is a interm step to get proper life-cycle for TPM device drivers. The next steps are adding proper ref counting and locking to tpm_chip that is used in every place in the TPM driver.
Big thank you to Jason Gunthorpe for carefully reviewing this part of the code. Without his contribution reaching the best quality would not have been possible.
--- drivers/char/tpm/Makefile | 2 +- drivers/char/tpm/tpm-chip.c | 196 ++++++++++++++++++++++++++++++++++++ drivers/char/tpm/tpm-interface.c | 148 +-------------------------- drivers/char/tpm/tpm.h | 11 +- drivers/char/tpm/tpm_atmel.c | 12 ++- drivers/char/tpm/tpm_i2c_atmel.c | 33 ++---- drivers/char/tpm/tpm_i2c_infineon.c | 37 ++----- drivers/char/tpm/tpm_i2c_nuvoton.c | 44 +++----- drivers/char/tpm/tpm_i2c_stm_st33.c | 38 +++---- drivers/char/tpm/tpm_ibmvtpm.c | 17 ++-- drivers/char/tpm/tpm_infineon.c | 29 +++--- drivers/char/tpm/tpm_nsc.c | 14 ++- drivers/char/tpm/tpm_tis.c | 79 ++++++--------- drivers/char/tpm/xen-tpmfront.c | 14 +-- 14 files changed, 331 insertions(+), 343 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 +196 -0
196 lines not on this page · raw message
drivers/char/tpm/tpm-interface.c +1 -147
177 lines not on this page · raw message
drivers/char/tpm/tpm.h +6 -5
@@ -110,7 +110,6 @@ struct tpm_chip {struct dentry **bios_dir;struct list_head list; -void (*release) (struct device *); };#define to_tpm_chip (n) container_of(n, struct tpm_chip, vendor)
@@ -320,15 +319,17 @@ extern int tpm_get_timeouts(struct tpm_chip *);extern void tpm_gen_interrupt (struct tpm_chip *);extern int tpm_do_selftest (struct tpm_chip *);extern unsigned long tpm_calc_ordinal_duration (struct tpm_chip *,u32 ); -extern struct tpm_chip *tpm_register_hardware (struct device *, -const struct tpm_class_ops *ops); -extern void tpm_dev_vendor_release (struct tpm_chip *); -extern void tpm_remove_hardware (struct device *);extern int tpm_pm_suspend (struct device *);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 struct tpm_chip *tpmm_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);
drivers/char/tpm/tpm_atmel.c +9 -3
@@ -138,11 +138,12 @@ static void atml_plat_remove(void)struct tpm_chip *chip =dev_get_drvdata (&pdev->dev);if (chip) { +/* FIXME might be broken when using force */ +tpm_chip_unregister (chip);if (chip->vendor.have_region)atmel_release_region (chip->vendor.base, chip->vendor.region_size);atmel_put_base_addr (chip->vendor.iobase); -tpm_remove_hardware (chip->dev);platform_device_unregister (pdev); } }
@@ -184,8 +185,9 @@ static int __init init_atmel(void) goto err_rel_reg; } -if (!(chip =tpm_register_hardware (&pdev->dev, &tpm_atmel))) { - rc = -ENODEV ; + chip =tpmm_chip_alloc (&pdev->dev, &tpm_atmel); +if (IS_ERR (chip)) { + rc =PTR_ERR (chip); goto err_unreg_dev; }
@@ -194,6 +196,10 @@ static int __init init_atmel(void) chip->vendor.have_region = have_region; chip->vendor.region_size = region_size; + rc =tpm_chip_register (chip); +if (rc) + goto err_unreg_dev; +return 0 ; err_unreg_dev:
drivers/char/tpm/tpm_i2c_atmel.c +11 -22
@@ -160,11 +160,9 @@ static int i2c_atmel_probe(struct i2c_client *client,if (!i2c_check_functionality (client->adapter,I2C_FUNC_I2C ))return -ENODEV ; - chip =tpm_register_hardware (dev, &i2c_atmel); -if (!chip) { -dev_err (dev,"%s() error in tpm_register_hardware\n" , __func__); -return -ENODEV ; - } + chip =tpmm_chip_alloc (dev, &i2c_atmel); +if (IS_ERR (chip)) +return PTR_ERR (chip); chip->vendor.priv =devm_kzalloc (dev,sizeof (struct priv_data ),GFP_KERNEL );
@@ -179,21 +177,16 @@ static int i2c_atmel_probe(struct i2c_client *client,/* There is no known way to probe for this device, and all version * information seems to be read via TPM commands. Thus we rely on the * TPM startup process in the common code to detect the device. */ -if (tpm_get_timeouts (chip)) { - rc = -ENODEV ; - goto out_err; - } +if (tpm_get_timeouts (chip)) +return -ENODEV ; -if (tpm_do_selftest (chip)) { - rc = -ENODEV ; - goto out_err; - } +if (tpm_do_selftest (chip)) +return -ENODEV ; -return 0 ; + rc =tpm_chip_register (chip); +if (rc) +return rc; -out_err: -tpm_dev_vendor_release (chip); -tpm_remove_hardware (chip->dev);return rc; }
@@ -201,11 +194,7 @@ static int i2c_atmel_remove(struct i2c_client *client) {struct device *dev = &(client->dev);struct tpm_chip *chip =dev_get_drvdata (dev); - -if (chip) -tpm_dev_vendor_release (chip); -tpm_remove_hardware (dev); -kfree (chip); +tpm_chip_unregister (chip);return 0 ; }
drivers/char/tpm/tpm_i2c_infineon.c +7 -30
@@ -581,12 +581,9 @@ static int tpm_tis_i2c_init(struct device *dev)int rc =0 ;struct tpm_chip *chip; - chip =tpm_register_hardware (dev, &tpm_tis_i2c); -if (!chip) { -dev_err (dev,"could not register hardware\n" ); - rc = -ENODEV ; - goto out_err; - } + chip =tpmm_chip_alloc (dev, &tpm_tis_i2c); +if (IS_ERR (chip)) +return PTR_ERR (chip);/* Disable interrupts */ chip->vendor.irq =0 ;
@@ -600,7 +597,7 @@ static int tpm_tis_i2c_init(struct device *dev)if (request_locality (chip,0 ) !=0 ) {dev_err (dev,"could not request locality\n" ); rc = -ENODEV ; - goto out_vendor; + goto out_err; }/* read four bytes from DID_VID register */
@@ -628,21 +625,9 @@ static int tpm_tis_i2c_init(struct device *dev)tpm_get_timeouts (chip);tpm_do_selftest (chip); -return 0 ; - +return tpm_chip_register (chip); out_release:release_locality (chip, chip->vendor.locality,1 ); - -out_vendor: -/* close file handles */ -tpm_dev_vendor_release (chip); - -/* remove hardware */ -tpm_remove_hardware (chip->dev); - -/* reset these pointers, otherwise we oops */ - chip->dev->release =NULL ; - chip->release =NULL ; tpm_dev.client =NULL ; out_err:return rc;
@@ -712,17 +697,9 @@ static int tpm_tis_i2c_probe(struct i2c_client *client,static int tpm_tis_i2c_remove (struct i2c_client *client) {struct tpm_chip *chip = tpm_dev.chip; -release_locality (chip, chip->vendor.locality,1 ); -/* close file handles */ -tpm_dev_vendor_release (chip); - -/* remove hardware */ -tpm_remove_hardware (chip->dev); - -/* reset these pointers, otherwise we oops */ - chip->dev->release =NULL ; - chip->release =NULL ; +tpm_chip_unregister (chip); +release_locality (chip, chip->vendor.locality,1 ); tpm_dev.client =NULL ;return 0 ;
drivers/char/tpm/tpm_i2c_nuvoton.c +15 -29
78 lines not on this page · raw message
drivers/char/tpm/tpm_i2c_stm_st33.c +14 -24
@@ -609,37 +609,29 @@ tpm_st33_i2c_probe(struct i2c_client *client, const struct i2c_device_id *id)if (client ==NULL ) {pr_info ("%s: i2c client is NULL. Device not accessible.\n" , __func__); - err = -ENODEV ; - goto end; +return -ENODEV ; }if (!i2c_check_functionality (client->adapter,I2C_FUNC_I2C )) {dev_info (&client->dev,"client not i2c capable\n" ); - err = -ENODEV ; - goto end; +return -ENODEV ; } - chip =tpm_register_hardware (&client->dev, &st_i2c_tpm); -if (!chip) { -dev_info (&client->dev,"fail chip\n" ); - err = -ENODEV ; - goto end; - } + chip =tpmm_chip_alloc (&client->dev, &st_i2c_tpm); +if (IS_ERR (chip)) +return PTR_ERR (chip); platform_data = client->dev.platform_data;if (!platform_data) {dev_info (&client->dev,"chip not available\n" ); - err = -ENODEV ; - goto _tpm_clean_answer; +return -ENODEV ; } platform_data->tpm_i2c_buffer[0 ] =kmalloc (TPM_BUFSIZE *sizeof (u8),GFP_KERNEL ); -if (platform_data->tpm_i2c_buffer[0 ] ==NULL ) { - err = -ENOMEM ; - goto _tpm_clean_answer; - } +if (platform_data->tpm_i2c_buffer[0 ] ==NULL ) +return -ENOMEM ; platform_data->tpm_i2c_buffer[1 ] =kmalloc (TPM_BUFSIZE *sizeof (u8),GFP_KERNEL );if (platform_data->tpm_i2c_buffer[1 ] ==NULL ) {
@@ -716,8 +708,10 @@ tpm_st33_i2c_probe(struct i2c_client *client, const struct i2c_device_id *id)tpm_get_timeouts (chip);tpm_do_selftest (chip); -dev_info (chip->dev,"TPM I2C Initialized\n" ); -return 0 ; + err =tpm_chip_register (chip); +if (!err) +return 0 ; + _irq_set:free_irq (gpio_to_irq (platform_data->io_serirq), (void *)chip); _gpio_init2:
@@ -732,10 +726,6 @@ _tpm_clean_response2: _tpm_clean_response1:kzfree (platform_data->tpm_i2c_buffer[0 ]); platform_data->tpm_i2c_buffer[0 ] =NULL ; -_tpm_clean_answer: -tpm_remove_hardware (chip->dev); -end: -pr_info ("TPM I2C initialisation fail\n" );return err; }
@@ -752,13 +742,13 @@ static int tpm_st33_i2c_remove(struct i2c_client *client) ((struct i2c_client *)TPM_VPRIV (chip))->dev.platform_data;if (pin_infos !=NULL ) { +tpm_chip_unregister (chip); +free_irq (pin_infos->io_serirq, chip);gpio_free (pin_infos->io_serirq);gpio_free (pin_infos->io_lpcpd); -tpm_remove_hardware (chip->dev); -if (pin_infos->tpm_i2c_buffer[1 ] !=NULL ) {kzfree (pin_infos->tpm_i2c_buffer[1 ]); pin_infos->tpm_i2c_buffer[1 ] =NULL ;
drivers/char/tpm/tpm_ibmvtpm.c +7 -10
@@ -270,8 +270,11 @@ static int ibmvtpm_crq_send_init(struct ibmvtpm_dev *ibmvtpm)static int tpm_ibmvtpm_remove (struct vio_dev *vdev) {struct ibmvtpm_dev *ibmvtpm =ibmvtpm_get_data (&vdev->dev); +struct tpm_chip *chip =dev_get_drvdata (ibmvtpm->dev);int rc =0 ; +tpm_chip_unregister (chip); +free_irq (vdev->irq, ibmvtpm); do {
@@ -290,8 +293,6 @@ static int tpm_ibmvtpm_remove(struct vio_dev *vdev)kfree (ibmvtpm->rtce_buf); } -tpm_remove_hardware (ibmvtpm->dev); -kfree (ibmvtpm);return 0 ;
@@ -555,11 +556,9 @@ static int tpm_ibmvtpm_probe(struct vio_dev *vio_dev,struct tpm_chip *chip;int rc = -ENOMEM , rc1; - chip =tpm_register_hardware (dev, &tpm_ibmvtpm); -if (!chip) { -dev_err (dev,"tpm_register_hardware failed\n" ); -return -ENODEV ; - } + chip =tpmm_chip_alloc (dev, &tpm_ibmvtpm); +if (IS_ERR (chip)) +return PTR_ERR (chip); ibmvtpm =kzalloc (sizeof (struct ibmvtpm_dev ),GFP_KERNEL );if (!ibmvtpm) {
@@ -629,7 +628,7 @@ static int tpm_ibmvtpm_probe(struct vio_dev *vio_dev,if (rc) goto init_irq_cleanup; -return rc; +return tpm_chip_register (chip); init_irq_cleanup: do { rc1 = plpar_hcall_norets(H_FREE_CRQ, vio_dev->unit_address);
@@ -644,8 +643,6 @@ cleanup:kfree (ibmvtpm); } -tpm_remove_hardware (dev); -return rc; }
drivers/char/tpm/tpm_infineon.c +17 -12
@@ -546,7 +546,14 @@ static int tpm_inf_pnp_probe(struct pnp_dev *dev, vendorid[0 ], vendorid[1 ], productid[0], productid[1], chipname); -if (!(chip =tpm_register_hardware (&dev->dev, &tpm_inf))) + chip =tpmm_chip_alloc (&dev->dev, &tpm_inf); +if (IS_ERR (chip)) { + rc =PTR_ERR (chip); + goto err_release_region; + } + + rc =tpm_chip_register (chip); +if (rc) goto err_release_region;return 0 ;
@@ -572,17 +579,15 @@ static void tpm_inf_pnp_remove(struct pnp_dev *dev) {struct tpm_chip *chip =pnp_get_drvdata (dev); -if (chip) { -if (tpm_dev.iotype ==TPM_INF_IO_PORT ) { -release_region (tpm_dev.data_regs, tpm_dev.data_size); -release_region (tpm_dev.config_port, - tpm_dev.config_size); - }else { -iounmap (tpm_dev.mem_base); -release_mem_region (tpm_dev.map_base, tpm_dev.map_size); - } -tpm_dev_vendor_release (chip); -tpm_remove_hardware (chip->dev); +tpm_chip_unregister (chip); + +if (tpm_dev.iotype ==TPM_INF_IO_PORT ) { +release_region (tpm_dev.data_regs, tpm_dev.data_size); +release_region (tpm_dev.config_port, + tpm_dev.config_size); + }else { +iounmap (tpm_dev.mem_base); +release_mem_region (tpm_dev.map_base, tpm_dev.map_size); } }
drivers/char/tpm/tpm_nsc.c +9 -5
@@ -247,10 +247,9 @@ static struct platform_device *pdev = NULL;static void tpm_nsc_remove (struct device *dev) {struct tpm_chip *chip =dev_get_drvdata (dev); -if ( chip ) { -release_region (chip->vendor.base,2 ); -tpm_remove_hardware (chip->dev); - } + +tpm_chip_unregister (chip); +release_region (chip->vendor.base,2 ); } static SIMPLE_DEV_PM_OPS(tpm_nsc_pm, tpm_pm_suspend, tpm_pm_resume);
@@ -308,11 +307,16 @@ static int __init init_nsc(void) goto err_del_dev; } -if (!(chip =tpm_register_hardware (&pdev->dev, &tpm_nsc))) { + chip =tpmm_chip_alloc (&pdev->dev, &tpm_nsc); +if (IS_ERR (chip)) { rc = -ENODEV ; goto err_rel_reg; } + rc =tpm_chip_register (chip); +if (rc) + goto err_rel_reg; +dev_dbg (&pdev->dev,"NSC TPM detected\n" ); dev_dbg(&pdev->dev, "NSC LDN 0x%x, SID 0x%x, SRID 0x%x\n",
drivers/char/tpm/tpm_tis.c +30 -49
150 lines not on this page · raw message
drivers/char/tpm/xen-tpmfront.c +8 -6
@@ -175,9 +175,9 @@ static int setup_chip(struct device *dev, struct tpm_private *priv) {struct tpm_chip *chip; - chip =tpm_register_hardware (dev, &tpm_vtpm); -if (!chip) -return -ENODEV ; + chip =tpmm_chip_alloc (dev, &tpm_vtpm); +if (IS_ERR (chip)) +return PTR_ERR (chip);init_waitqueue_head (&chip->vendor.read_queue);
@@ -286,6 +286,7 @@ static int tpmfront_probe(struct xenbus_device *dev, const struct xenbus_device_id *id) {struct tpm_private *priv; +struct tpm_chip *chip;int rv; priv =kzalloc (sizeof (*priv),GFP_KERNEL );
@@ -302,21 +303,22 @@ static int tpmfront_probe(struct xenbus_device *dev, rv =setup_ring (dev, priv);if (rv) { -tpm_remove_hardware (&dev->dev); + chip =dev_get_drvdata (&dev->dev); +tpm_chip_unregister (chip);ring_free (priv);return rv; }tpm_get_timeouts (priv->chip); -return rv; +return tpm_chip_register (priv->chip); }static int tpmfront_remove (struct xenbus_device *dev) {struct tpm_chip *chip =dev_get_drvdata (&dev->dev);struct tpm_private *priv =TPM_VPRIV (chip); -tpm_remove_hardware (&dev->dev); +tpm_chip_unregister (chip);ring_free (priv);TPM_VPRIV (chip) =NULL ;return 0 ;
Signature · 1 line
2.1.0
PATCH v2 3/3 tpm: fix multiple race conditions in tpm_ppi.c
In reply to Jarkko SakkinenTraversal of the ACPI device tree was not done right. It should lookup PPI only under the ACPI device that it is associated. Otherwise, it could match to a wrong PPI interface if there are two TPM devices in the device tree.
Removed global ACPI handle and version string from tpm_ppi.c as this is racy. Instead they should be associated with the chip.
Additionally, added the missing copyright platter to tpm_ppi.c.
--- drivers/char/tpm/tpm-chip.c | 4 +- drivers/char/tpm/tpm.h | 16 ++++-- drivers/char/tpm/tpm_ppi.c | 136 +++++++++++++++++++++++++++----------------- drivers/char/tpm/tpm_tis.c | 15 +++-- 4 files changed, 108 insertions(+), 63 deletions(-)
drivers/char/tpm/tpm-chip.c +2 -2
@@ -148,7 +148,7 @@ int tpm_chip_register(struct tpm_chip *chip)if (rc) goto del_misc; - rc =tpm_add_ppi (&chip->dev->kobj); + rc =tpm_add_ppi (chip);if (rc) goto del_sysfs;
@@ -186,7 +186,7 @@ void tpm_chip_unregister(struct tpm_chip *chip)synchronize_rcu ();tpm_sysfs_del_device (chip); -tpm_remove_ppi (&chip->dev->kobj); +tpm_remove_ppi (chip);if (chip->bios_dir)tpm_bios_log_teardown (chip->bios_dir);
drivers/char/tpm/tpm.h +12 -4
@@ -27,6 +27,7 @@#include <linux/platform_device.h> #include <linux/io.h> #include <linux/tpm.h> +#include <linux/acpi.h> enum tpm_const {TPM_MINOR =224 ,/* officially assigned */
@@ -94,6 +95,8 @@ struct tpm_vendor_specific {#define TPM_VID_WINBOND 0x1050#define TPM_VID_STM 0x104A +#define TPM_PPI_VERSION_LEN 3 +struct tpm_chip {struct device *dev;/* Device stuff */ const struct tpm_class_ops *ops;
@@ -109,6 +112,11 @@ struct tpm_chip {struct dentry **bios_dir; +#ifdef CONFIG_ACPI +acpi_handle acpi_dev_handle; +char ppi_version[TPM_PPI_VERSION_LEN +1 ]; +#endif /* CONFIG_ACPI */ +struct list_head list; };
@@ -338,15 +346,15 @@ void tpm_sysfs_del_device(struct tpm_chip *chip);int tpm_pcr_read_dev (struct tpm_chip *chip,int pcr_idx,u8 *res_buf);#ifdef CONFIG_ACPI -extern int tpm_add_ppi (struct kobject *); -extern void tpm_remove_ppi (struct kobject *); +extern int tpm_add_ppi (struct tpm_chip *chip); +extern void tpm_remove_ppi (struct tpm_chip *chip);#else -static inline int tpm_add_ppi (struct kobject *parent) +static inline int tpm_add_ppi (struct tpm_chip *chip) {return 0 ; } -static inline void tpm_remove_ppi (struct kobject *parent) +static inline void tpm_remove_ppi (struct tpm_chip *chip) { }#endif
drivers/char/tpm/tpm_ppi.c +83 -53
241 lines not on this page · raw message
drivers/char/tpm/tpm_tis.c +11 -4
@@ -536,8 +536,9 @@ static void tpm_tis_remove(struct tpm_chip *chip)release_locality (chip, chip->vendor.locality,1 ); } -static int tpm_tis_init (struct device *dev,resource_size_t start, -resource_size_t len,unsigned int irq) +static int tpm_tis_init (struct device *dev,acpi_handle acpi_dev_handle, +resource_size_t start,resource_size_t len, +unsigned int irq) {u32 vendor, intfcaps, intmask;int rc, i, irq_s, irq_e, probe;
@@ -547,6 +548,8 @@ static int tpm_tis_init(struct device *dev, resource_size_t start,if (IS_ERR (chip))return PTR_ERR (chip); + chip->acpi_dev_handle = acpi_dev_handle; + chip->vendor.iobase =devm_ioremap (dev, start, len);if (!chip->vendor.iobase)return -EIO ;
@@ -777,6 +780,7 @@ static int tpm_tis_pnp_init(struct pnp_dev *pnp_dev, {resource_size_t start, len;unsigned int irq =0 ; +acpi_handle acpi_dev_handle =NULL ; start =pnp_mem_start (pnp_dev,0 ); len =pnp_mem_len (pnp_dev,0 );
@@ -789,7 +793,10 @@ static int tpm_tis_pnp_init(struct pnp_dev *pnp_dev,if (is_itpm (pnp_dev)) itpm = true; -return tpm_tis_init (&pnp_dev->dev, start, len, irq); +if (pnp_acpi_device (pnp_dev)) + acpi_dev_handle =pnp_acpi_device (pnp_dev)->handle; + +return tpm_tis_init (&pnp_dev->dev, acpi_dev_handle, start, len, irq); }static struct pnp_device_id tpm_pnp_tbl[] = {
@@ -858,7 +865,7 @@ static int __init init_tis(void) rc =PTR_ERR (pdev); goto err_dev; } - rc =tpm_tis_init (&pdev->dev,TIS_MEM_BASE ,TIS_MEM_LEN ,0 ); + rc =tpm_tis_init (&pdev->dev,NULL ,TIS_MEM_BASE ,TIS_MEM_LEN ,0 );if (rc) goto err_init;return 0 ;
Signature · 1 line
2.1.0