All of lore.kernel.org
 help / color / mirror / Atom feed
From: David Lively <dlively@virtualiron.com>
To: Keir Fraser <Keir.Fraser@cl.cam.ac.uk>
Cc: xen-devel@lists.xensource.com
Subject: Re: [PATCH] fix for Failed VMEntry on VMX
Date: Tue, 02 May 2006 12:58:55 -0400	[thread overview]
Message-ID: <44578FCF.3030301@virtualiron.com> (raw)
In-Reply-To: <a28b83e64b0c7cfbaa0d72d32877600f@cl.cam.ac.uk>

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

Okay - revised patch attached.

Thanks,
Dave

Keir Fraser wrote:

>
> On 2 May 2006, at 15:58, David Lively wrote:
>
>> I've been getting a "Failed VMEntry" when trying to boot a second
>> VMX guest (while the first one is still running, but is no longer in
>> real mode).  This patch fixes it.
>
>
> Please `or' the vmread/vmwrite error returns together into an error 
> variable and BUG_ON(error) just once at the bottom of the function. 
> Also extend the comment a little to explicitly explain that this is 
> working around a VMENTRY validation check.
>
> Apart from that it looks good.
>
>  -- Keir
>


[-- Attachment #2: failed-vmentry-fix.patch --]
[-- Type: text/x-patch, Size: 2663 bytes --]

Ensure segment bases are consistent with their
selectors for VMX guests in VM86 mode.

Signed-off-by: David Lively <dlively@virtualiron.com>

diff -r 880433ba7487 xen/arch/x86/hvm/vmx/vmx.c
--- a/xen/arch/x86/hvm/vmx/vmx.c	Mon May  1 17:08:02 2006 -0400
+++ b/xen/arch/x86/hvm/vmx/vmx.c	Tue May  2 12:43:47 2006 -0400
@@ -487,6 +487,44 @@ static void vmx_store_cpu_guest_regs(
         __vmptrld(virt_to_maddr(current->arch.hvm_vmx.vmcs));
 }
 
+/* The VMX spec (section 4.3.1.2, Checks on Guest Segment
+ * Registers) says that virtual-8086 mode guests' segment
+ * base-address fields in the VMCS must be equal to their
+ * corresponding segment selector field shifted right by
+ * four bits upon vmentry.
+ *
+ * This function (called only for VM86-mode guests) fixes
+ * the bases to be consistent with the selectors in regs
+ * if they're not already.  Without this, we can fail the
+ * vmentry check mentioned above.
+ */
+static void fixup_vm86_seg_bases(struct cpu_user_regs *regs)
+{
+    int err = 0;
+    unsigned long base;
+
+    err |= __vmread(GUEST_ES_BASE, &base);
+    if (regs->es << 4 != base)
+        err |= __vmwrite(GUEST_ES_BASE, regs->es << 4);
+    err |= __vmread(GUEST_CS_BASE, &base);
+    if (regs->cs << 4 != base)
+        err |= __vmwrite(GUEST_CS_BASE, regs->cs << 4);
+    err |= __vmread(GUEST_SS_BASE, &base);
+    if (regs->ss << 4 != base)
+        err |= __vmwrite(GUEST_SS_BASE, regs->ss << 4);
+    err |= __vmread(GUEST_DS_BASE, &base);
+    if (regs->ds << 4 != base)
+        err |= __vmwrite(GUEST_DS_BASE, regs->ds << 4);
+    err |= __vmread(GUEST_FS_BASE, &base);
+    if (regs->fs << 4 != base)
+        err |= __vmwrite(GUEST_FS_BASE, regs->fs << 4);
+    err |= __vmread(GUEST_GS_BASE, &base);
+    if (regs->gs << 4 != base)
+        err |= __vmwrite(GUEST_GS_BASE, regs->gs << 4);
+
+    BUG_ON(err);
+}
+
 void vmx_load_cpu_guest_regs(struct vcpu *v, struct cpu_user_regs *regs)
 {
     if ( v != current )
@@ -523,6 +561,8 @@ void vmx_load_cpu_guest_regs(struct vcpu
         __vm_set_bit(EXCEPTION_BITMAP, EXCEPTION_BITMAP_DB);
     else
         __vm_clear_bit(EXCEPTION_BITMAP, EXCEPTION_BITMAP_DB);
+    if (regs->rflags & EF_VM)
+        fixup_vm86_seg_bases(regs);
 
     __vmwrite(GUEST_CS_SELECTOR, regs->cs);
     __vmwrite(GUEST_RIP, regs->rip);
@@ -540,6 +580,8 @@ void vmx_load_cpu_guest_regs(struct vcpu
         __vm_set_bit(EXCEPTION_BITMAP, EXCEPTION_BITMAP_DB);
     else
         __vm_clear_bit(EXCEPTION_BITMAP, EXCEPTION_BITMAP_DB);
+    if (regs->eflags & EF_VM)
+        fixup_vm86_seg_bases(regs);
 
     __vmwrite(GUEST_CS_SELECTOR, regs->cs);
     __vmwrite(GUEST_RIP, regs->eip);

[-- 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:[~2006-05-02 16:58 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-05-02 14:58 [PATCH] fix for Failed VMEntry on VMX David Lively
2006-05-02 16:19 ` Keir Fraser
2006-05-02 16:58   ` David Lively [this message]
  -- strict thread matches above, loose matches on Subject: below --
2006-05-02 15:30 Petersson, Mats
2006-05-02 16:04 ` Dave Lively
2006-05-02 16:34 Petersson, Mats

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=44578FCF.3030301@virtualiron.com \
    --to=dlively@virtualiron.com \
    --cc=Keir.Fraser@cl.cam.ac.uk \
    --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.