[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-changelog] [xen master] vTPM/TPM2: Support 'tpm2' extra command line.



commit 71a7c55ad06485217cdc5dca9419e2ae411a7fc6
Author:     Quan Xu <quan.xu@xxxxxxxxx>
AuthorDate: Thu Jan 15 04:21:48 2015 -0500
Commit:     Ian Campbell <ian.campbell@xxxxxxxxxx>
CommitDate: Wed Jan 28 12:54:50 2015 +0000

    vTPM/TPM2: Support 'tpm2' extra command line.
    
    Make vtpm-stubdom domain compatible to launch on TPM 1.x / TPM 2.0.
    Add:
    ..
         extra="tpm2=1"
    ..
    to launch vtpm-stubdom domain on TPM 2.0, ignore it on TPM 1.x. for
    example,
    vtpm-stubdom domain configuration on TPM 2.0:
    
      kernel="/usr/lib/xen/boot/vtpmmgr-stubdom.gz"
      memory=16
      disk=["file:/var/scale/vdisk/vmgr,hda,w"]
      name="vtpmmgr"
      iomem=["fed40,5"]
      extra="tpm2=1"
    
    vtpm-stubdom domain configuration on TPM 1.x:
    
      kernel="/usr/lib/xen/boot/vtpmmgr-stubdom.gz"
      memory=16
      disk=["file:/var/scale/vdisk/vmgr,hda,w"]
      name="vtpmmgr"
      iomem=["fed40,5"]
    
    Signed-off-by: Quan Xu <quan.xu@xxxxxxxxx>
    Acked-by: Daniel De Graaf <dgdegra@xxxxxxxxxxxxx>
---
 stubdom/vtpmmgr/vtpmmgr.c |   46 +++++++++++++++++++++++++++++++++++++++-----
 stubdom/vtpmmgr/vtpmmgr.h |   14 +++++++++++++
 2 files changed, 54 insertions(+), 6 deletions(-)

diff --git a/stubdom/vtpmmgr/vtpmmgr.c b/stubdom/vtpmmgr/vtpmmgr.c
index 270ca8a..9fddaa2 100644
--- a/stubdom/vtpmmgr/vtpmmgr.c
+++ b/stubdom/vtpmmgr/vtpmmgr.c
@@ -45,6 +45,27 @@
 #include "vtpmmgr.h"
 #include "tcg.h"
 
+struct tpm_hardware_version hardware_version = {
+    .hw_version = TPM1_HARDWARE,
+};
+
+int parse_cmdline_hw(int argc, char** argv)
+{
+    int i;
+
+    for (i = 1; i < argc; ++i) {
+        if (!strcmp(argv[i], TPM2_EXTRA_OPT)) {
+            hardware_version.hw_version = TPM2_HARDWARE;
+            break;
+        }
+    }
+    return 0;
+}
+
+int hw_is_tpm2(void)
+{
+    return (hardware_version.hw_version == TPM2_HARDWARE) ? 1 : 0;
+}
 
 void main_loop(void) {
    tpmcmd_t* tpmcmd;
@@ -74,12 +95,25 @@ int main(int argc, char** argv)
    sleep(2);
    vtpmloginfo(VTPM_LOG_VTPM, "Starting vTPM manager domain\n");
 
-   /* Initialize the vtpm manager */
-   if(vtpmmgr_init(argc, argv) != TPM_SUCCESS) {
-      vtpmlogerror(VTPM_LOG_VTPM, "Unable to initialize vtpmmgr domain!\n");
-      rc = -1;
-      goto exit;
-   }
+    /*Parse TPM hardware in extra command line*/
+    parse_cmdline_hw(argc, argv);
+
+    /* Initialize the vtpm manager */
+    if (hw_is_tpm2()) {
+        vtpmloginfo(VTPM_LOG_VTPM, "Hardware : --- TPM 2.0 ---\n");
+        if (vtpmmgr2_init(argc, argv) != TPM_SUCCESS) {
+            vtpmlogerror(VTPM_LOG_VTPM, "Unable to initialize vtpmmgr 
domain!\n");
+            rc = -1;
+            goto exit;
+        }
+    }else{
+        vtpmloginfo(VTPM_LOG_VTPM, "Hardware : --- TPM 1.x ---\n");
+        if (vtpmmgr_init(argc, argv) != TPM_SUCCESS) {
+            vtpmlogerror(VTPM_LOG_VTPM, "Unable to initialize vtpmmgr 
domain!\n");
+            rc = -1;
+            goto exit;
+        }
+    }
 
    main_loop();
 
diff --git a/stubdom/vtpmmgr/vtpmmgr.h b/stubdom/vtpmmgr/vtpmmgr.h
index c479443..c8cd073 100644
--- a/stubdom/vtpmmgr/vtpmmgr.h
+++ b/stubdom/vtpmmgr/vtpmmgr.h
@@ -46,9 +46,21 @@
 #include "vtpm_manager.h"
 #include "tpm2_types.h"
 
+#define TPM2_EXTRA_OPT "tpm2=1"
 #define RSA_KEY_SIZE 0x0800
 #define RSA_CIPHER_SIZE (RSA_KEY_SIZE / 8)
 
+enum {
+    TPM1_HARDWARE = 1,
+    TPM2_HARDWARE,
+} tpm_version;
+
+struct tpm_hardware_version {
+    int hw_version;
+};
+
+extern struct tpm_hardware_version hardware_version;
+
 struct vtpm_globals {
    int tpm_fd;
    TPM_AUTH_SESSION    oiap;                // OIAP session for storageKey
@@ -97,5 +109,7 @@ inline TPM_RESULT vtpmmgr_rand(unsigned char* bytes, size_t 
num_bytes) {
 TPM_RC tpm2_take_ownership(void);
 TPM_RESULT vtpmmgr2_create(void);
 TPM_RESULT vtpmmgr2_init(int argc, char** argv);
+int parse_cmdline_hw(int argc, char** argv);
+int hw_is_tpm2(void);
 
 #endif
--
generated by git-patchbot for /home/xen/git/xen.git#master

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


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.