diff options
author | Nadav Amit <namit@cs.technion.ac.il> | 2015-01-26 02:32:26 -0500 |
---|---|---|
committer | Paolo Bonzini <pbonzini@redhat.com> | 2015-01-26 06:15:18 -0500 |
commit | bac155310be35e0fa64b066d47625d2a12a75122 (patch) | |
tree | 14dd9f7eae1b56432132c6d89c30eeb4b9f846b6 | |
parent | 2b42fce6954d1730edaf479d02378703e7b821cb (diff) |
KVM: x86: 32-bit wraparound read/write not emulated correctly
If we got a wraparound of 32-bit operand, and the limit is 0xffffffff, read and
writes should be successful. It just needs to be done in two segments.
Signed-off-by: Nadav Amit <namit@cs.technion.ac.il>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
-rw-r--r-- | arch/x86/kvm/emulate.c | 10 | ||||
-rw-r--r-- | arch/x86/kvm/x86.c | 2 |
2 files changed, 9 insertions, 3 deletions
diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c index 997c9ebb70ef..c3b07574942f 100644 --- a/arch/x86/kvm/emulate.c +++ b/arch/x86/kvm/emulate.c | |||
@@ -684,9 +684,13 @@ static __always_inline int __linearize(struct x86_emulate_ctxt *ctxt, | |||
684 | } | 684 | } |
685 | if (addr.ea > lim) | 685 | if (addr.ea > lim) |
686 | goto bad; | 686 | goto bad; |
687 | *max_size = min_t(u64, ~0u, (u64)lim + 1 - addr.ea); | 687 | if (lim == 0xffffffff) |
688 | if (size > *max_size) | 688 | *max_size = ~0u; |
689 | goto bad; | 689 | else { |
690 | *max_size = (u64)lim + 1 - addr.ea; | ||
691 | if (size > *max_size) | ||
692 | goto bad; | ||
693 | } | ||
690 | la &= (u32)-1; | 694 | la &= (u32)-1; |
691 | break; | 695 | break; |
692 | } | 696 | } |
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index cdd6606e4c54..1e10e3f7f516 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c | |||
@@ -4495,6 +4495,8 @@ int emulator_read_write(struct x86_emulate_ctxt *ctxt, unsigned long addr, | |||
4495 | if (rc != X86EMUL_CONTINUE) | 4495 | if (rc != X86EMUL_CONTINUE) |
4496 | return rc; | 4496 | return rc; |
4497 | addr += now; | 4497 | addr += now; |
4498 | if (ctxt->mode != X86EMUL_MODE_PROT64) | ||
4499 | addr = (u32)addr; | ||
4498 | val += now; | 4500 | val += now; |
4499 | bytes -= now; | 4501 | bytes -= now; |
4500 | } | 4502 | } |