All of lore.kernel.org
 help / color / mirror / Atom feed
From: Wei Huang <wei.huang2@amd.com>
To: xen-devel@lists.xensource.com
Cc: james.harper@bendigoit.com.au
Subject: [PATCH][SVM] Fix 32bit Windows guest VMs save/restore
Date: Mon, 31 Jan 2011 11:33:43 -0600	[thread overview]
Message-ID: <1296495223.2013.8.camel@weilaptop> (raw)

[-- Attachment #1: Type: text/plain, Size: 581 bytes --]

The attached patch fixes the save/restore issue seen with 32bit Windows
guest VMs. The root cause is that current Xen doesn't intercept
SYSENTER-related MSRs for 32bit guest VMs. As a result, the
guest_sysenter_xxx fields contain incorrect values and shouldn't be used
for save/restore. This patch checks the LMA bit of EFER register in the
save/restore code path.

Please apply it to both Xen-4.0 and Xen-unstable trees.

Reported-by: James Harper <james.harper@bendigoit.com.au>
Signed-off-by: Wei Huang <wei.huang2@amd.com>
Acked-by: Christoph Egger <christoph.egger@amd.com>



[-- Attachment #2: amd_fix_sysenter_msr.txt --]
[-- Type: text/plain, Size: 2466 bytes --]

diff -r 5ce41defa1fa xen/arch/x86/hvm/svm/svm.c
--- a/xen/arch/x86/hvm/svm/svm.c	Wed Jan 26 16:11:41 2011 +0000
+++ b/xen/arch/x86/hvm/svm/svm.c	Sun Jan 30 23:38:00 2011 -0600
@@ -157,6 +157,7 @@
 
 static int svm_vmcb_save(struct vcpu *v, struct hvm_hw_cpu *c)
 {
+    bool_t lma = !!(v->arch.hvm_vcpu.guest_efer & EFER_LMA);
     struct vmcb_struct *vmcb = v->arch.hvm_svm.vmcb;
 
     c->cr0 = v->arch.hvm_vcpu.guest_cr[0];
@@ -164,9 +165,20 @@
     c->cr3 = v->arch.hvm_vcpu.guest_cr[3];
     c->cr4 = v->arch.hvm_vcpu.guest_cr[4];
 
-    c->sysenter_cs = v->arch.hvm_svm.guest_sysenter_cs;
-    c->sysenter_esp = v->arch.hvm_svm.guest_sysenter_esp;
-    c->sysenter_eip = v->arch.hvm_svm.guest_sysenter_eip;
+    /* SYSENTER MSRs aren't intercepted under 32bit mode. So the data should 
+     * be copied from VMCB save area under 32bit mode. */
+    if ( lma ) 
+    {
+        c->sysenter_cs = v->arch.hvm_svm.guest_sysenter_cs;
+        c->sysenter_esp = v->arch.hvm_svm.guest_sysenter_esp;
+        c->sysenter_eip = v->arch.hvm_svm.guest_sysenter_eip;
+    } 
+    else
+    {
+        c->sysenter_cs = vmcb->sysenter_cs;
+        c->sysenter_esp = vmcb->sysenter_esp;
+        c->sysenter_eip = vmcb->sysenter_eip;
+    }
 
     c->pending_event = 0;
     c->error_code = 0;
@@ -185,8 +197,12 @@
 {
     unsigned long mfn = 0;
     p2m_type_t p2mt;
+    bool_t lma;
     struct vmcb_struct *vmcb = v->arch.hvm_svm.vmcb;
     struct p2m_domain *p2m = p2m_get_hostp2m(v->domain);
+    
+    /* Note: Please make sure guest_efer been restored at this point. */
+    lma = !!(v->arch.hvm_vcpu.guest_efer & EFER_LMA);
 
     if ( c->pending_valid &&
          ((c->pending_type == 1) || (c->pending_type > 6) ||
@@ -224,9 +240,19 @@
     hvm_update_guest_cr(v, 2);
     hvm_update_guest_cr(v, 4);
 
-    v->arch.hvm_svm.guest_sysenter_cs = c->sysenter_cs;
-    v->arch.hvm_svm.guest_sysenter_esp = c->sysenter_esp;
-    v->arch.hvm_svm.guest_sysenter_eip = c->sysenter_eip;
+    /* Copy data into VMCB save area under 32bit mode */
+    if ( lma )
+    {
+        v->arch.hvm_svm.guest_sysenter_cs = c->sysenter_cs;
+        v->arch.hvm_svm.guest_sysenter_esp = c->sysenter_esp;
+        v->arch.hvm_svm.guest_sysenter_eip = c->sysenter_eip;
+    }
+    else
+    {
+        vmcb->sysenter_cs = c->sysenter_cs;
+        vmcb->sysenter_esp = c->sysenter_esp;
+        vmcb->sysenter_eip = c->sysenter_eip;
+    }
 
     if ( paging_mode_hap(v->domain) )
     {

[-- Attachment #3: Type: text/plain, Size: 138 bytes --]

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

             reply	other threads:[~2011-01-31 17:33 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-01-31 17:33 Wei Huang [this message]
2011-01-31 21:13 ` [PATCH][SVM] Fix 32bit Windows guest VMs save/restore Keir Fraser
2011-01-31 21:17   ` Keir Fraser
2011-01-31 21:43     ` Wei Huang
2011-01-31 21:38   ` Wei Huang
2011-02-01  6:14     ` Keir Fraser
2011-02-01  6:25       ` Wei Huang
2011-02-01  8:14         ` Keir Fraser
2011-02-01 21:06           ` Wei Huang
2011-02-01 22:35             ` Keir Fraser

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1296495223.2013.8.camel@weilaptop \
    --to=wei.huang2@amd.com \
    --cc=james.harper@bendigoit.com.au \
    --cc=xen-devel@lists.xensource.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.