diff options
author | Nelson Elhage <nelhage@ksplice.com> | 2011-04-13 11:44:13 -0400 |
---|---|---|
committer | Avi Kivity <avi@redhat.com> | 2011-05-11 07:57:09 -0400 |
commit | 0521e4c0bc73aa86152ee4e4bd03724c8a9e1d6b (patch) | |
tree | 01e60574962d06155ebea802e0dd7832a893f474 /arch/x86/kvm/emulate.c | |
parent | 49704f26586ca87fcab4fe9323fff8db41e78910 (diff) |
KVM: x86 emulator: Handle wraparound in (cs_base + offset) when fetching insns
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>
Diffstat (limited to 'arch/x86/kvm/emulate.c')
-rw-r--r-- | arch/x86/kvm/emulate.c | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c index cb2efa463793..4c5ff22d101a 100644 --- a/arch/x86/kvm/emulate.c +++ b/arch/x86/kvm/emulate.c | |||
@@ -637,9 +637,12 @@ static int do_fetch_insn_byte(struct x86_emulate_ctxt *ctxt, | |||
637 | int size, cur_size; | 637 | int size, cur_size; |
638 | 638 | ||
639 | if (eip == fc->end) { | 639 | if (eip == fc->end) { |
640 | unsigned long linear = eip + ctxt->cs_base; | ||
641 | if (ctxt->mode != X86EMUL_MODE_PROT64) | ||
642 | linear &= (u32)-1; | ||
640 | cur_size = fc->end - fc->start; | 643 | cur_size = fc->end - fc->start; |
641 | size = min(15UL - cur_size, PAGE_SIZE - offset_in_page(eip)); | 644 | size = min(15UL - cur_size, PAGE_SIZE - offset_in_page(eip)); |
642 | rc = ops->fetch(ctxt->cs_base + eip, fc->data + cur_size, | 645 | rc = ops->fetch(linear, fc->data + cur_size, |
643 | size, ctxt->vcpu, &ctxt->exception); | 646 | size, ctxt->vcpu, &ctxt->exception); |
644 | if (rc != X86EMUL_CONTINUE) | 647 | if (rc != X86EMUL_CONTINUE) |
645 | return rc; | 648 | return rc; |