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

[Xen-changelog] [xen master] mini-os/tpm{back, front}: Allow device repoens



commit e66cb3294f3aa815ae6741b7030dfeb2ea801284
Author:     Daniel De Graaf <dgdegra@xxxxxxxxxxxxx>
AuthorDate: Thu Mar 21 16:11:19 2013 -0400
Commit:     Ian Campbell <ian.campbell@xxxxxxxxxx>
CommitDate: Fri Apr 12 14:28:17 2013 +0100

    mini-os/tpm{back, front}: Allow device repoens
    
    Allow the vtpm device to be disconnected and reconnected so that a
    bootloader (like pv-grub) can submit measurements and return the vtpm
    device to its initial state before booting the target kernel.
    
    Signed-off-by: Daniel De Graaf <dgdegra@xxxxxxxxxxxxx>
---
 extras/mini-os/tpmback.c  |   23 ++++++++++++++++++++++-
 extras/mini-os/tpmfront.c |   14 ++++++++++++--
 2 files changed, 34 insertions(+), 3 deletions(-)

diff --git a/extras/mini-os/tpmback.c b/extras/mini-os/tpmback.c
index d68ad2b..9917765 100644
--- a/extras/mini-os/tpmback.c
+++ b/extras/mini-os/tpmback.c
@@ -645,6 +645,24 @@ error_post_map:
    return -1;
 }
 
+static void disconnect_fe(tpmif_t* tpmif)
+{
+   if (tpmif->status == CONNECTED) {
+      tpmif->status = DISCONNECTING;
+      mask_evtchn(tpmif->evtchn);
+
+      if(gntmap_munmap(&gtpmdev.map, (unsigned long)tpmif->page, 1)) {
+        TPMBACK_ERR("%u/%u Error occured while trying to unmap shared page\n", 
(unsigned int) tpmif->domid, tpmif->handle);
+      }
+
+      unbind_evtchn(tpmif->evtchn);
+   }
+   tpmif->status = DISCONNECTED;
+   tpmif_change_state(tpmif, XenbusStateInitWait);
+
+   TPMBACK_LOG("Frontend %u/%u disconnected\n", (unsigned int) tpmif->domid, 
tpmif->handle);
+}
+
 static int frontend_changed(tpmif_t* tpmif)
 {
    int state = xenbus_read_integer(tpmif->fe_state_path);
@@ -671,8 +689,11 @@ static int frontend_changed(tpmif_t* tpmif)
         tpmif_change_state(tpmif, XenbusStateClosing);
         break;
 
-      case XenbusStateUnknown: /* keep it here */
       case XenbusStateClosed:
+         disconnect_fe(tpmif);
+        break;
+
+      case XenbusStateUnknown: /* keep it here */
         free_tpmif(tpmif);
         break;
 
diff --git a/extras/mini-os/tpmfront.c b/extras/mini-os/tpmfront.c
index 9f930b5..95d86f6 100644
--- a/extras/mini-os/tpmfront.c
+++ b/extras/mini-os/tpmfront.c
@@ -156,6 +156,9 @@ static int wait_for_backend_closed(xenbus_event_queue* 
events, char* path)
         case XenbusStateClosed:
            TPMFRONT_LOG("Backend Closed\n");
            return 0;
+        case XenbusStateInitWait:
+           TPMFRONT_LOG("Backend Closed (waiting for reconnect)\n");
+           return 0;
         default:
            xenbus_wait_for_watch(events);
       }
@@ -339,10 +342,10 @@ void shutdown_tpmfront(struct tpmfront_dev* dev)
    TPMFRONT_LOG("Shutting down tpmfront\n");
    /* disconnect */
    if(dev->state == XenbusStateConnected) {
-      dev->state = XenbusStateClosing;
-      //FIXME: Transaction for this?
       /* Tell backend we are closing */
+      dev->state = XenbusStateClosing;
       if((err = xenbus_printf(XBT_NIL, dev->nodename, "state", "%u", (unsigned 
int) dev->state))) {
+        TPMFRONT_ERR("Unable to write to %s, error was %s", dev->nodename, 
err);
         free(err);
       }
 
@@ -366,6 +369,13 @@ void shutdown_tpmfront(struct tpmfront_dev* dev)
       /* Wait for the backend to close and unmap shared pages, ignore any 
errors */
       wait_for_backend_state_changed(dev, XenbusStateClosed);
 
+      /* Prepare for a later reopen (possibly by a kexec'd kernel) */
+      dev->state = XenbusStateInitialising;
+      if((err = xenbus_printf(XBT_NIL, dev->nodename, "state", "%u", (unsigned 
int) dev->state))) {
+        TPMFRONT_ERR("Unable to write to %s, error was %s", dev->nodename, 
err);
+        free(err);
+      }
+
       /* Close event channel and unmap shared page */
       mask_evtchn(dev->evtchn);
       unbind_evtchn(dev->evtchn);
--
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®.