]> www.infradead.org Git - users/dwmw2/linux.git/commitdiff
KVM: x86 emulator: Handle wraparound in (cs_base + offset) when fetching insns
authorNelson Elhage <nelhage@ksplice.com>
Wed, 13 Apr 2011 15:44:13 +0000 (11:44 -0400)
committerAvi Kivity <avi@redhat.com>
Sun, 17 Apr 2011 09:44:06 +0000 (12:44 +0300)
Currently, setting a large (i.e. negative) base address for %cs does not work on
a 64-bit host. The "JOS" teaching operating system, used by MIT and other
universities, relies on such segments while bootstrapping its way to full
virtual memory management.

Signed-off-by: Nelson Elhage <nelhage@ksplice.com>
Signed-off-by: Avi Kivity <avi@redhat.com>
arch/x86/kvm/emulate.c

index ef70af9d04b591e288074cb2d74df3e3ff4d0abb..51c21d4f9f5bfae6090540aa64f1b14b17969417 100644 (file)
@@ -637,9 +637,12 @@ static int do_fetch_insn_byte(struct x86_emulate_ctxt *ctxt,
        int size, cur_size;
 
        if (eip == fc->end) {
+               unsigned long linear = eip + ctxt->cs_base;
+               if (ctxt->mode != X86EMUL_MODE_PROT64)
+                       linear &= (u32)-1;
                cur_size = fc->end - fc->start;
                size = min(15UL - cur_size, PAGE_SIZE - offset_in_page(eip));
-               rc = ops->fetch(ctxt->cs_base + eip, fc->data + cur_size,
+               rc = ops->fetch(linear, fc->data + cur_size,
                                size, ctxt->vcpu, &ctxt->exception);
                if (rc != X86EMUL_CONTINUE)
                        return rc;