Skip to contentSkip to conversation

Fix save/restore for HVM domains with viridian=1

PATCH In review Paul Durrant 1 participant 2 messages Nov 25, 2011

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Fix save/restore for HVM domains with viridian=1

# HG changeset patch
# User Paul Durrant <[email protected]> # Date 1322234894 0
# Node ID b50479d64deea72b11008fd444aa951737b2573d # Parent 0a0c02a616768bfab16c072788cb76be1893c37f Fix save/restore for HVM domains with viridian=1

xc_domain_save/restore currently pay no attention to HVM_PARAM_VIRIDIAN which results in an HVM domain running a recent version on Windows (post-Vista) locking up on a domain restore due to EOIs (done via a viridian MSR write) being silently dropped.
This patch adds an extra save entry for the viridian parameter and also adds code in the viridian kernel module to catch attempted use of viridian functionality when the HVM parameter has not been set.

tools/libxc/xc_domain_restore.c +14 -0
diff -r 0a0c02a61676 -r b50479d64dee tools/libxc/xc_domain_restore.c
@@ -675,6 +675,7 @@ typedef struct {
     uint64_t vm86_tss;
     uint64_t console_pfn;
     uint64_t acpi_ioport_location;
+    uint64_t viridian;
 } pagebuf_t;
 
 static int pagebuf_init(pagebuf_t* buf)
@@ -809,6 +810,16 @@ static int pagebuf_get_one(xc_interface 
         }
         return pagebuf_get_one(xch, ctx, buf, fd, dom);
 
+    case XC_SAVE_ID_HVM_VIRIDIAN:
+        /* Skip padding 4 bytes then read the viridian flag. */
+        if ( RDEXACT(fd, &buf->viridian, sizeof(uint32_t)) ||
+             RDEXACT(fd, &buf->viridian, sizeof(uint64_t)) )
+        {
+            PERROR("error read the viridian flag");
+            return -1;
+        }
+        return pagebuf_get_one(xch, ctx, buf, fd, dom);
+
     default:
         if ( (count > MAX_BATCH_SIZE) || (count < 0) ) {
             ERROR("Max batch size exceeded (%d). Giving up.", count);
@@ -1440,6 +1451,9 @@ int xc_domain_restore(xc_interface *xch,
             fcntl(io_fd, F_SETFL, orig_io_fd_flags | O_NONBLOCK);
     }
 
+    if (pagebuf.viridian != 0)
+        xc_set_hvm_param(xch, dom, HVM_PARAM_VIRIDIAN, 1);
+
     if (pagebuf.acpi_ioport_location == 1) {
         DBGPRINTF("Use new firmware ioport from the checkpoint\n");
         xc_set_hvm_param(xch, dom, HVM_PARAM_ACPI_IOPORTS_LOCATION, 1);
tools/libxc/xc_domain_save.c +12 -0
diff -r 0a0c02a61676 -r b50479d64dee tools/libxc/xc_domain_save.c
@@ -1506,6 +1506,18 @@ int xc_domain_save(xc_interface *xch, in
             PERROR("Error when writing the firmware ioport version");
             goto out;
         }
+
+        chunk.id = XC_SAVE_ID_HVM_VIRIDIAN;
+        chunk.data = 0;
+        xc_get_hvm_param(xch, dom, HVM_PARAM_VIRIDIAN,
+                         (unsigned long *)&chunk.data);
+
+        if ( (chunk.data != 0) &&
+             wrexact(io_fd, &chunk, sizeof(chunk)) )
+        {
+            PERROR("Error when writing the viridian flag");
+            goto out;
+        }
     }
 
     if ( !callbacks->checkpoint )
tools/libxc/xg_save_restore.h +1 -0
diff -r 0a0c02a61676 -r b50479d64dee tools/libxc/xg_save_restore.h
@@ -134,6 +134,7 @@
 #define XC_SAVE_ID_HVM_CONSOLE_PFN    -8 /* (HVM-only) */
 #define XC_SAVE_ID_LAST_CHECKPOINT    -9 /* Commit to restoring after completion of current iteration. */
 #define XC_SAVE_ID_HVM_ACPI_IOPORTS_LOCATION -10
+#define XC_SAVE_ID_HVM_VIRIDIAN       -11
 
 /*
 ** We process save/restore/migrate in batches of pages; the below
#1 lore raw

Sorry, ignore this one. I need to fix the comment.

Paul

Quoted 102 lines

-----Original Message-----
From: Paul Durrant [mailto:[email protected]]
Sent: 25 November 2011 15:29
To: [email protected]
Cc: Paul Durrant
Subject: [PATCH] Fix save/restore for HVM domains with viridian=1

# HG changeset patch
# User Paul Durrant <[email protected]> # Date 1322234894 0 # Node ID b50479d64deea72b11008fd444aa951737b2573d
# Parent 0a0c02a616768bfab16c072788cb76be1893c37f
Fix save/restore for HVM domains with viridian=1

xc_domain_save/restore currently pay no attention to HVM_PARAM_VIRIDIAN which results in an HVM domain running a recent version on Windows (post-Vista) locking up on a domain restore due to EOIs (done via a viridian MSR write) being silently dropped. This patch adds an extra save entry for the viridian parameter and also adds code in the viridian kernel module to catch attempted use of viridian functionality when the HVM parameter has not been set.

diff -r 0a0c02a61676 -r b50479d64dee tools/libxc/xc_domain_restore.c
--- a/tools/libxc/xc_domain_restore.c Mon Nov 21 21:28:34 2011
+0000
+++ b/tools/libxc/xc_domain_restore.c Fri Nov 25 15:28:14 2011
+0000

tools/libxc/xc_domain_restore.c +1 -0
@@ -675,6 +675,7 @@ typedef struct {
     uint64_t vm86_tss;
     uint64_t console_pfn;
     uint64_t acpi_ioport_location;
+    uint64_t viridian;
 } pagebuf_t;
 
 static int pagebuf_init(pagebuf_t* buf) @@ -809,6 +810,16 @@ static

int pagebuf_get_one(xc_interface

         }
         return pagebuf_get_one(xch, ctx, buf, fd, dom);
tools/libxc/xc_domain_restore.c +10 -0
+    case XC_SAVE_ID_HVM_VIRIDIAN:
+        /* Skip padding 4 bytes then read the viridian flag. */
+        if ( RDEXACT(fd, &buf->viridian, sizeof(uint32_t)) ||
+             RDEXACT(fd, &buf->viridian, sizeof(uint64_t)) )
+        {
+            PERROR("error read the viridian flag");
+            return -1;
+        }
+        return pagebuf_get_one(xch, ctx, buf, fd, dom);
+
     default:
         if ( (count > MAX_BATCH_SIZE) || (count < 0) ) {
             ERROR("Max batch size exceeded (%d). Giving up.",

count); @@ -1440,6 +1451,9 @@ int xc_domain_restore(xc_interface *xch,

             fcntl(io_fd, F_SETFL, orig_io_fd_flags | O_NONBLOCK);
     }
tools/libxc/xc_domain_restore.c +3 -0
+    if (pagebuf.viridian != 0)
+        xc_set_hvm_param(xch, dom, HVM_PARAM_VIRIDIAN, 1);
+
     if (pagebuf.acpi_ioport_location == 1) {
         DBGPRINTF("Use new firmware ioport from the checkpoint\n");
         xc_set_hvm_param(xch, dom, HVM_PARAM_ACPI_IOPORTS_LOCATION,

1); diff -r 0a0c02a61676 -r b50479d64dee
tools/libxc/xc_domain_save.c

tools/libxc/xc_domain_save.c +12 -0
@@ -1506,6 +1506,18 @@ int xc_domain_save(xc_interface *xch, in
             PERROR("Error when writing the firmware ioport
 version");
             goto out;
         }
+
+        chunk.id = XC_SAVE_ID_HVM_VIRIDIAN;
+        chunk.data = 0;
+        xc_get_hvm_param(xch, dom, HVM_PARAM_VIRIDIAN,
+                         (unsigned long *)&chunk.data);
+
+        if ( (chunk.data != 0) &&
+             wrexact(io_fd, &chunk, sizeof(chunk)) )
+        {
+            PERROR("Error when writing the viridian flag");
+            goto out;
+        }
     }
 
     if ( !callbacks->checkpoint )

diff -r 0a0c02a61676 -r b50479d64dee tools/libxc/xg_save_restore.h
--- a/tools/libxc/xg_save_restore.h Mon Nov 21 21:28:34 2011
+0000
+++ b/tools/libxc/xg_save_restore.h Fri Nov 25 15:28:14 2011
+0000

tools/libxc/xc_domain_save.c +0 -0
@@ -134,6 +134,7 @@
 #define XC_SAVE_ID_HVM_CONSOLE_PFN    -8 /* (HVM-only) */
 #define XC_SAVE_ID_LAST_CHECKPOINT    -9 /* Commit to restoring

after completion of current iteration. */
#define XC_SAVE_ID_HVM_ACPI_IOPORTS_LOCATION -10
+#define XC_SAVE_ID_HVM_VIRIDIAN -11

/*
** We process save/restore/migrate in batches of pages; the below