WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-changelog

[Xen-changelog] tpm: Fixes and cleanup

# HG changeset patch
# User cl349@xxxxxxxxxxxxxxxxxxxx
# Node ID 2401f414d1ad5109e8ac5cf7636ec986b1f94fea
# Parent  8005fbd31d8b96d7dc38576fd9c518cf73706208
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@xxxxxxxxxx>

diff -r 8005fbd31d8b -r 2401f414d1ad linux-2.6-xen-sparse/drivers/char/tpm/tpm.c
--- a/linux-2.6-xen-sparse/drivers/char/tpm/tpm.c       Tue Feb 21 16:25:56 2006
+++ b/linux-2.6-xen-sparse/drivers/char/tpm/tpm.c       Tue Feb 21 17:13:30 2006
@@ -53,7 +53,7 @@
 
        down(&chip->buffer_mutex);
        atomic_set(&chip->data_pending, 0);
-       memset(chip->data_buffer, 0, chip->vendor->buffersize);
+       memset(chip->data_buffer, 0, get_chip_buffersize(chip));
        up(&chip->buffer_mutex);
 }
 
@@ -352,7 +352,7 @@
 
        spin_unlock(&driver_lock);
 
-       chip->data_buffer = kmalloc(chip->vendor->buffersize * sizeof(u8), 
GFP_KERNEL);
+       chip->data_buffer = kmalloc(get_chip_buffersize(chip) * sizeof(u8), 
GFP_KERNEL);
        if (chip->data_buffer == NULL) {
                chip->num_opens--;
                put_device(chip->dev);
@@ -400,8 +400,8 @@
 
        down(&chip->buffer_mutex);
 
-       if (in_size > chip->vendor->buffersize)
-               in_size = chip->vendor->buffersize;
+       if (in_size > get_chip_buffersize(chip))
+               in_size = get_chip_buffersize(chip);
 
        if (copy_from_user
            (chip->data_buffer, (void __user *) buf, in_size)) {
@@ -411,7 +411,7 @@
 
        /* atomic tpm command send and result receive */
        out_size = tpm_transmit(chip, chip->data_buffer, 
-                               chip->vendor->buffersize);
+                               get_chip_buffersize(chip));
 
        atomic_set(&chip->data_pending, out_size);
        atomic_set(&chip->data_position, 0);
@@ -432,8 +432,6 @@
        int ret_size;
        int pos, pending = 0;
 
-       del_singleshot_timer_sync(&chip->user_read_timer);
-       flush_scheduled_work();
        ret_size = atomic_read(&chip->data_pending);
        if (ret_size > 0) {     /* relay data */
                if (size < ret_size)
@@ -457,6 +455,7 @@
        if ( ret_size <= 0 || pending == 0 ) {
                atomic_set( &chip->data_pending, 0 );
                del_singleshot_timer_sync(&chip->user_read_timer);
+               flush_scheduled_work();
        }
 
        return ret_size;
diff -r 8005fbd31d8b -r 2401f414d1ad linux-2.6-xen-sparse/drivers/char/tpm/tpm.h
--- a/linux-2.6-xen-sparse/drivers/char/tpm/tpm.h       Tue Feb 21 16:25:56 2006
+++ b/linux-2.6-xen-sparse/drivers/char/tpm/tpm.h       Tue Feb 21 17:13:30 2006
@@ -101,6 +101,11 @@
        outb(value & 0xFF, base+1);
 }
 
+static inline u32 get_chip_buffersize(struct tpm_chip *chip)
+{
+       return chip->vendor->buffersize;
+}
+
 extern int tpm_register_hardware(struct device *,
                                 struct tpm_vendor_specific *);
 extern int tpm_open(struct inode *, struct file *);
diff -r 8005fbd31d8b -r 2401f414d1ad 
linux-2.6-xen-sparse/drivers/char/tpm/tpm_xen.c
--- a/linux-2.6-xen-sparse/drivers/char/tpm/tpm_xen.c   Tue Feb 21 16:25:56 2006
+++ b/linux-2.6-xen-sparse/drivers/char/tpm/tpm_xen.c   Tue Feb 21 17:13:30 2006
@@ -25,6 +25,7 @@
 #include <xen/tpmfe.h>
 #include <linux/device.h>
 #include <linux/interrupt.h>
+#include <linux/platform_device.h>
 #include "tpm.h"
 
 /* read status bits */
@@ -455,9 +456,7 @@
        .buffersize = 64 * 1024,
 };
 
-static struct device tpm_device = {
-       .bus_id = "vtpm",
-};
+static struct platform_device *pdev;
 
 static struct tpmfe_device tpmfe = {
        .receive = tpm_recv,
@@ -477,23 +476,22 @@
         * driver
         */
        if ((rc = tpm_fe_register_receiver(&tpmfe)) < 0) {
-               return rc;
+               goto err_exit;
        }
 
        /*
         * Register our device with the system.
         */
-       if ((rc = device_register(&tpm_device)) < 0) {
-               tpm_fe_unregister_receiver();
-               return rc;
+       pdev = platform_device_register_simple("tpm_vtpm", -1, NULL, 0);
+       if (IS_ERR(pdev)) {
+               rc = PTR_ERR(pdev);
+               goto err_unreg_fe;
        }
 
        tpm_xen.buffersize = tpmfe.max_tx_size;
 
-       if ((rc = tpm_register_hardware(&tpm_device, &tpm_xen)) < 0) {
-               device_unregister(&tpm_device);
-               tpm_fe_unregister_receiver();
-               return rc;
+       if ((rc = tpm_register_hardware(&pdev->dev, &tpm_xen)) < 0) {
+               goto err_unreg_pdev;
        }
 
        dataex.current_request = NULL;
@@ -508,13 +506,25 @@
        disconnect_time = jiffies;
 
        return 0;
+
+
+err_unreg_pdev:
+       platform_device_unregister(pdev);
+err_unreg_fe:
+       tpm_fe_unregister_receiver();
+
+err_exit:
+       return rc;
 }
 
 static void __exit cleanup_xen(void)
 {
-       tpm_remove_hardware(&tpm_device);
-       device_unregister(&tpm_device);
-       tpm_fe_unregister_receiver();
+       struct tpm_chip *chip = dev_get_drvdata(&pdev->dev);
+       if (chip) {
+               tpm_remove_hardware(chip->dev);
+               platform_device_unregister(pdev);
+               tpm_fe_unregister_receiver();
+       }
 }
 
 module_init(init_xen);
diff -r 8005fbd31d8b -r 2401f414d1ad 
linux-2.6-xen-sparse/drivers/xen/tpmback/interface.c
--- a/linux-2.6-xen-sparse/drivers/xen/tpmback/interface.c      Tue Feb 21 
16:25:56 2006
+++ b/linux-2.6-xen-sparse/drivers/xen/tpmback/interface.c      Tue Feb 21 
17:13:30 2006
@@ -13,9 +13,6 @@
 
 #include "common.h"
 #include <xen/balloon.h>
-
-#define TPMIF_HASHSZ (2 << 5)
-#define TPMIF_HASH(_d,_h) (((int)(_d)^(int)(_h))&(TPMIF_HASHSZ-1))
 
 static kmem_cache_t *tpmif_cachep;
 int num_frontends = 0;
diff -r 8005fbd31d8b -r 2401f414d1ad 
linux-2.6-xen-sparse/drivers/xen/tpmback/tpmback.c
--- a/linux-2.6-xen-sparse/drivers/xen/tpmback/tpmback.c        Tue Feb 21 
16:25:56 2006
+++ b/linux-2.6-xen-sparse/drivers/xen/tpmback/tpmback.c        Tue Feb 21 
17:13:30 2006
@@ -65,8 +65,6 @@
                               int isuserbuffer,
                               u32 left);
 
-
-#define MAX_PENDING_REQS TPMIF_TX_RING_SIZE
 
 #define MIN(x,y)  (x) < (y) ? (x) : (y)
 
@@ -973,8 +971,6 @@
 static void tpm_tx_action(unsigned long unused);
 static DECLARE_TASKLET(tpm_tx_tasklet, tpm_tx_action, 0);
 
-#define MAX_PENDING_REQS TPMIF_TX_RING_SIZE
-
 static struct list_head tpm_schedule_list;
 static spinlock_t tpm_schedule_list_lock;
 
diff -r 8005fbd31d8b -r 2401f414d1ad tools/examples/vtpm
--- a/tools/examples/vtpm       Tue Feb 21 16:25:56 2006
+++ b/tools/examples/vtpm       Tue Feb 21 17:13:30 2006
@@ -3,6 +3,7 @@
 dir=$(dirname "$0")
 . "$dir/vtpm-common.sh"
 
+vtpm_fatal_error=0
 
 case "$command" in
   add)
@@ -19,5 +20,8 @@
   ;;
 esac
 
-log debug "Successful vTPM operation '$command'."
-success
+if [ $vtpm_fatal_error -eq 0 ]; then
+       log debug "Successful vTPM operation '$command'."
+       success
+fi
+
diff -r 8005fbd31d8b -r 2401f414d1ad tools/examples/vtpm-common.sh
--- a/tools/examples/vtpm-common.sh     Tue Feb 21 16:25:56 2006
+++ b/tools/examples/vtpm-common.sh     Tue Feb 21 17:13:30 2006
@@ -173,6 +173,7 @@
        local vmname=$1
        local inst=$2
        local res
+
        res=`cat $VTPMDB |             \
             gawk -vvmname=$vmname     \
                  -vinst=$inst         \
@@ -238,6 +239,9 @@
        local res
        set +e
        get_create_reason
+
+       claim_lock vtpmdb
+
        find_instance $domname
        res=$?
        if [ $res -eq 0 ]; then
@@ -262,6 +266,9 @@
                        vtpm_create $instance
                fi
        fi
+
+       release_lock vtpmdb
+
        if [ "$REASON" == "create" ]; then
                vtpm_reset $instance
        elif [ "$REASON" == "resume" ]; then
@@ -292,3 +299,5 @@
        fi
        set -e
 }
+
+

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog

<Prev in Thread] Current Thread [Next in Thread>
  • [Xen-changelog] tpm: Fixes and cleanup, Xen patchbot -unstable <=