ia64/xen-unstable
changeset 8947:2401f414d1ad
tpm: Fixes and cleanup
Fix a recently found problem in tpm.c, move the vtpm sysfs
entry to /sys/device/platform/tpm_vtpm and add locking in
the vtpm hotplug script.
Signed-off-by: Stefan Berger <stefanb@us.ibm.com>
Fix a recently found problem in tpm.c, move the vtpm sysfs
entry to /sys/device/platform/tpm_vtpm and add locking in
the vtpm hotplug script.
Signed-off-by: Stefan Berger <stefanb@us.ibm.com>
author | cl349@firebug.cl.cam.ac.uk |
---|---|
date | Tue Feb 21 17:13:30 2006 +0000 (2006-02-21) |
parents | 8005fbd31d8b |
children | 991c4d62d392 |
files | linux-2.6-xen-sparse/drivers/char/tpm/tpm.c linux-2.6-xen-sparse/drivers/char/tpm/tpm.h linux-2.6-xen-sparse/drivers/char/tpm/tpm_xen.c linux-2.6-xen-sparse/drivers/xen/tpmback/interface.c linux-2.6-xen-sparse/drivers/xen/tpmback/tpmback.c tools/examples/vtpm tools/examples/vtpm-common.sh |
line diff
1.1 --- a/linux-2.6-xen-sparse/drivers/char/tpm/tpm.c Tue Feb 21 16:25:56 2006 +0000 1.2 +++ b/linux-2.6-xen-sparse/drivers/char/tpm/tpm.c Tue Feb 21 17:13:30 2006 +0000 1.3 @@ -53,7 +53,7 @@ static void timeout_work(void * ptr) 1.4 1.5 down(&chip->buffer_mutex); 1.6 atomic_set(&chip->data_pending, 0); 1.7 - memset(chip->data_buffer, 0, chip->vendor->buffersize); 1.8 + memset(chip->data_buffer, 0, get_chip_buffersize(chip)); 1.9 up(&chip->buffer_mutex); 1.10 } 1.11 1.12 @@ -352,7 +352,7 @@ int tpm_open(struct inode *inode, struct 1.13 1.14 spin_unlock(&driver_lock); 1.15 1.16 - chip->data_buffer = kmalloc(chip->vendor->buffersize * sizeof(u8), GFP_KERNEL); 1.17 + chip->data_buffer = kmalloc(get_chip_buffersize(chip) * sizeof(u8), GFP_KERNEL); 1.18 if (chip->data_buffer == NULL) { 1.19 chip->num_opens--; 1.20 put_device(chip->dev); 1.21 @@ -400,8 +400,8 @@ ssize_t tpm_write(struct file *file, con 1.22 1.23 down(&chip->buffer_mutex); 1.24 1.25 - if (in_size > chip->vendor->buffersize) 1.26 - in_size = chip->vendor->buffersize; 1.27 + if (in_size > get_chip_buffersize(chip)) 1.28 + in_size = get_chip_buffersize(chip); 1.29 1.30 if (copy_from_user 1.31 (chip->data_buffer, (void __user *) buf, in_size)) { 1.32 @@ -411,7 +411,7 @@ ssize_t tpm_write(struct file *file, con 1.33 1.34 /* atomic tpm command send and result receive */ 1.35 out_size = tpm_transmit(chip, chip->data_buffer, 1.36 - chip->vendor->buffersize); 1.37 + get_chip_buffersize(chip)); 1.38 1.39 atomic_set(&chip->data_pending, out_size); 1.40 atomic_set(&chip->data_position, 0); 1.41 @@ -432,8 +432,6 @@ ssize_t tpm_read(struct file * file, cha 1.42 int ret_size; 1.43 int pos, pending = 0; 1.44 1.45 - del_singleshot_timer_sync(&chip->user_read_timer); 1.46 - flush_scheduled_work(); 1.47 ret_size = atomic_read(&chip->data_pending); 1.48 if (ret_size > 0) { /* relay data */ 1.49 if (size < ret_size) 1.50 @@ -457,6 +455,7 @@ ssize_t tpm_read(struct file * file, cha 1.51 if ( ret_size <= 0 || pending == 0 ) { 1.52 atomic_set( &chip->data_pending, 0 ); 1.53 del_singleshot_timer_sync(&chip->user_read_timer); 1.54 + flush_scheduled_work(); 1.55 } 1.56 1.57 return ret_size;
2.1 --- a/linux-2.6-xen-sparse/drivers/char/tpm/tpm.h Tue Feb 21 16:25:56 2006 +0000 2.2 +++ b/linux-2.6-xen-sparse/drivers/char/tpm/tpm.h Tue Feb 21 17:13:30 2006 +0000 2.3 @@ -101,6 +101,11 @@ static inline void tpm_write_index(int b 2.4 outb(value & 0xFF, base+1); 2.5 } 2.6 2.7 +static inline u32 get_chip_buffersize(struct tpm_chip *chip) 2.8 +{ 2.9 + return chip->vendor->buffersize; 2.10 +} 2.11 + 2.12 extern int tpm_register_hardware(struct device *, 2.13 struct tpm_vendor_specific *); 2.14 extern int tpm_open(struct inode *, struct file *);
3.1 --- a/linux-2.6-xen-sparse/drivers/char/tpm/tpm_xen.c Tue Feb 21 16:25:56 2006 +0000 3.2 +++ b/linux-2.6-xen-sparse/drivers/char/tpm/tpm_xen.c Tue Feb 21 17:13:30 2006 +0000 3.3 @@ -25,6 +25,7 @@ 3.4 #include <xen/tpmfe.h> 3.5 #include <linux/device.h> 3.6 #include <linux/interrupt.h> 3.7 +#include <linux/platform_device.h> 3.8 #include "tpm.h" 3.9 3.10 /* read status bits */ 3.11 @@ -455,9 +456,7 @@ static struct tpm_vendor_specific tpm_xe 3.12 .buffersize = 64 * 1024, 3.13 }; 3.14 3.15 -static struct device tpm_device = { 3.16 - .bus_id = "vtpm", 3.17 -}; 3.18 +static struct platform_device *pdev; 3.19 3.20 static struct tpmfe_device tpmfe = { 3.21 .receive = tpm_recv, 3.22 @@ -477,23 +476,22 @@ static int __init init_xen(void) 3.23 * driver 3.24 */ 3.25 if ((rc = tpm_fe_register_receiver(&tpmfe)) < 0) { 3.26 - return rc; 3.27 + goto err_exit; 3.28 } 3.29 3.30 /* 3.31 * Register our device with the system. 3.32 */ 3.33 - if ((rc = device_register(&tpm_device)) < 0) { 3.34 - tpm_fe_unregister_receiver(); 3.35 - return rc; 3.36 + pdev = platform_device_register_simple("tpm_vtpm", -1, NULL, 0); 3.37 + if (IS_ERR(pdev)) { 3.38 + rc = PTR_ERR(pdev); 3.39 + goto err_unreg_fe; 3.40 } 3.41 3.42 tpm_xen.buffersize = tpmfe.max_tx_size; 3.43 3.44 - if ((rc = tpm_register_hardware(&tpm_device, &tpm_xen)) < 0) { 3.45 - device_unregister(&tpm_device); 3.46 - tpm_fe_unregister_receiver(); 3.47 - return rc; 3.48 + if ((rc = tpm_register_hardware(&pdev->dev, &tpm_xen)) < 0) { 3.49 + goto err_unreg_pdev; 3.50 } 3.51 3.52 dataex.current_request = NULL; 3.53 @@ -508,13 +506,25 @@ static int __init init_xen(void) 3.54 disconnect_time = jiffies; 3.55 3.56 return 0; 3.57 + 3.58 + 3.59 +err_unreg_pdev: 3.60 + platform_device_unregister(pdev); 3.61 +err_unreg_fe: 3.62 + tpm_fe_unregister_receiver(); 3.63 + 3.64 +err_exit: 3.65 + return rc; 3.66 } 3.67 3.68 static void __exit cleanup_xen(void) 3.69 { 3.70 - tpm_remove_hardware(&tpm_device); 3.71 - device_unregister(&tpm_device); 3.72 - tpm_fe_unregister_receiver(); 3.73 + struct tpm_chip *chip = dev_get_drvdata(&pdev->dev); 3.74 + if (chip) { 3.75 + tpm_remove_hardware(chip->dev); 3.76 + platform_device_unregister(pdev); 3.77 + tpm_fe_unregister_receiver(); 3.78 + } 3.79 } 3.80 3.81 module_init(init_xen);
4.1 --- a/linux-2.6-xen-sparse/drivers/xen/tpmback/interface.c Tue Feb 21 16:25:56 2006 +0000 4.2 +++ b/linux-2.6-xen-sparse/drivers/xen/tpmback/interface.c Tue Feb 21 17:13:30 2006 +0000 4.3 @@ -14,9 +14,6 @@ 4.4 #include "common.h" 4.5 #include <xen/balloon.h> 4.6 4.7 -#define TPMIF_HASHSZ (2 << 5) 4.8 -#define TPMIF_HASH(_d,_h) (((int)(_d)^(int)(_h))&(TPMIF_HASHSZ-1)) 4.9 - 4.10 static kmem_cache_t *tpmif_cachep; 4.11 int num_frontends = 0; 4.12
5.1 --- a/linux-2.6-xen-sparse/drivers/xen/tpmback/tpmback.c Tue Feb 21 16:25:56 2006 +0000 5.2 +++ b/linux-2.6-xen-sparse/drivers/xen/tpmback/tpmback.c Tue Feb 21 17:13:30 2006 +0000 5.3 @@ -66,8 +66,6 @@ static int packet_read_shmem(struct pac 5.4 u32 left); 5.5 5.6 5.7 -#define MAX_PENDING_REQS TPMIF_TX_RING_SIZE 5.8 - 5.9 #define MIN(x,y) (x) < (y) ? (x) : (y) 5.10 5.11 5.12 @@ -973,8 +971,6 @@ static void processing_timeout(unsigned 5.13 static void tpm_tx_action(unsigned long unused); 5.14 static DECLARE_TASKLET(tpm_tx_tasklet, tpm_tx_action, 0); 5.15 5.16 -#define MAX_PENDING_REQS TPMIF_TX_RING_SIZE 5.17 - 5.18 static struct list_head tpm_schedule_list; 5.19 static spinlock_t tpm_schedule_list_lock; 5.20
6.1 --- a/tools/examples/vtpm Tue Feb 21 16:25:56 2006 +0000 6.2 +++ b/tools/examples/vtpm Tue Feb 21 17:13:30 2006 +0000 6.3 @@ -3,6 +3,7 @@ 6.4 dir=$(dirname "$0") 6.5 . "$dir/vtpm-common.sh" 6.6 6.7 +vtpm_fatal_error=0 6.8 6.9 case "$command" in 6.10 add) 6.11 @@ -19,5 +20,8 @@ case "$command" in 6.12 ;; 6.13 esac 6.14 6.15 -log debug "Successful vTPM operation '$command'." 6.16 -success 6.17 +if [ $vtpm_fatal_error -eq 0 ]; then 6.18 + log debug "Successful vTPM operation '$command'." 6.19 + success 6.20 +fi 6.21 +
7.1 --- a/tools/examples/vtpm-common.sh Tue Feb 21 16:25:56 2006 +0000 7.2 +++ b/tools/examples/vtpm-common.sh Tue Feb 21 17:13:30 2006 +0000 7.3 @@ -173,6 +173,7 @@ function validate_entry () { 7.4 local vmname=$1 7.5 local inst=$2 7.6 local res 7.7 + 7.8 res=`cat $VTPMDB | \ 7.9 gawk -vvmname=$vmname \ 7.10 -vinst=$inst \ 7.11 @@ -238,6 +239,9 @@ function vtpm_create_instance () { 7.12 local res 7.13 set +e 7.14 get_create_reason 7.15 + 7.16 + claim_lock vtpmdb 7.17 + 7.18 find_instance $domname 7.19 res=$? 7.20 if [ $res -eq 0 ]; then 7.21 @@ -262,6 +266,9 @@ function vtpm_create_instance () { 7.22 vtpm_create $instance 7.23 fi 7.24 fi 7.25 + 7.26 + release_lock vtpmdb 7.27 + 7.28 if [ "$REASON" == "create" ]; then 7.29 vtpm_reset $instance 7.30 elif [ "$REASON" == "resume" ]; then 7.31 @@ -292,3 +299,5 @@ function vtpm_remove_instance () { 7.32 fi 7.33 set -e 7.34 } 7.35 + 7.36 +