summaryrefslogtreecommitdiffstats
path: root/arch/x86/kvm/emulate.c
Commit message (Collapse)AuthorAgeFilesLines
* KVM: fix emulator_task_switch() return value.Gleb Natapov2010-05-171-1/+1
| | | | | | | | emulator_task_switch() should return -1 for failure and 0 for success to the caller, just like x86_emulate_insn() does. Signed-off-by: Gleb Natapov <gleb@redhat.com> Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
* KVM: x86: Push potential exception error code on task switchesJan Kiszka2010-05-171-4/+18
| | | | | | | | When a fault triggers a task switch, the error code, if existent, has to be pushed on the new task's stack. Implement the missing bits. Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com> Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
* KVM: x86: Terminate early if task_switch_16/32 failedJan Kiszka2010-05-171-0/+2
| | | | | | | | | Stop the switch immediately if task_switch_16/32 returned an error. Only if that step succeeded, the switch should actually take place and update any register states. Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com> Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
* KVM: x86 emulator: Don't overwrite decode cacheAvi Kivity2010-05-171-9/+10
| | | | | | | | | | | Currently if we an instruction spans a page boundary, when we fetch the second half we overwrite the first half. This prevents us from tracing the full instruction opcodes. Fix by appending the second half to the first. Signed-off-by: Avi Kivity <avi@redhat.com> Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
* KVM: x86 emulator: fix unlocked CMPXCHG8B emulationGleb Natapov2010-05-171-1/+0
| | | | | | | | When CMPXCHG8B is executed without LOCK prefix it is racy. Preserve this behaviour in emulator too. Signed-off-by: Gleb Natapov <gleb@redhat.com> Signed-off-by: Avi Kivity <avi@redhat.com>
* KVM: x86 emulator: add decoding of CMPXCHG8B dst operandGleb Natapov2010-05-171-14/+10
| | | | | | | | | | Decode CMPXCHG8B destination operand in decoding stage. Fixes regression introduced by "If LOCK prefix is used dest arg should be memory" commit. This commit relies on dst operand be decoded at the beginning of an instruction emulation. Signed-off-by: Gleb Natapov <gleb@redhat.com> Signed-off-by: Avi Kivity <avi@redhat.com>
* KVM: x86 emulator: commit rflags as part of registers commitGleb Natapov2010-05-171-0/+1
| | | | | | | | Make sure that rflags is committed only after successful instruction emulation. Signed-off-by: Gleb Natapov <gleb@redhat.com> Signed-off-by: Avi Kivity <avi@redhat.com>
* KVM: x86 emulator: introduce pio in string read ahead.Gleb Natapov2010-05-171-5/+41
| | | | | | | | To optimize "rep ins" instruction do IO in big chunks ahead of time instead of doing it only when required during instruction emulation. Signed-off-by: Gleb Natapov <gleb@redhat.com> Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
* KVM: x86 emulator: restart string instruction without going back to a guest.Gleb Natapov2010-05-171-11/+23
| | | | | | | | | | | | Currently when string instruction is only partially complete we go back to a guest mode, guest tries to reexecute instruction and exits again and at this point emulation continues. Avoid all of this by restarting instruction without going back to a guest mode, but return to a guest mode each 1024 iterations to allow interrupt injection. Pending exception causes immediate guest entry too. Signed-off-by: Gleb Natapov <gleb@redhat.com> Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
* KVM: x86 emulator: remove saved_eipGleb Natapov2010-05-171-8/+1
| | | | | | | | c->eip is never written back in case of emulation failure, so no need to set it to old value. Signed-off-by: Gleb Natapov <gleb@redhat.com> Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
* KVM: x86 emulator: Move string pio emulation into emulator.cGleb Natapov2010-05-171-33/+15
| | | | | | | | | | | | Currently emulation is done outside of emulator so things like doing ins/outs to/from mmio are broken it also makes it hard (if not impossible) to implement single stepping in the future. The implementation in this patch is not efficient since it exits to userspace for each IO while previous implementation did 'ins' in batches. Further patch that implements pio in string read ahead address this problem. Signed-off-by: Gleb Natapov <gleb@redhat.com> Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
* KVM: x86 emulator: fix in/out emulation.Gleb Natapov2010-05-171-26/+24
| | | | | | | | | | | | | in/out emulation is broken now. The breakage is different depending on where IO device resides. If it is in userspace emulator reports emulation failure since it incorrectly interprets kvm_emulate_pio() return value. If IO device is in the kernel emulation of 'in' will do nothing since kvm_emulate_pio() stores result directly into vcpu registers, so emulator will overwrite result of emulation during commit of shadowed register. Signed-off-by: Gleb Natapov <gleb@redhat.com> Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
* KVM: x86 emulator: during rep emulation decrement ECX only if emulation ↵Gleb Natapov2010-05-171-7/+8
| | | | | | | succeeded Signed-off-by: Gleb Natapov <gleb@redhat.com> Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
* KVM: x86 emulator: add decoding of X,Y parameters from Intel SDMGleb Natapov2010-05-171-81/+44
| | | | | | | | | Add decoding of X,Y parameters from Intel SDM which are used by string instruction to specify source and destination. Use this new decoding to implement movs, cmps, stos, lods in a generic way. Signed-off-by: Gleb Natapov <gleb@redhat.com> Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
* KVM: x86 emulator: populate OP_MEM operand during decoding.Gleb Natapov2010-05-171-37/+29
| | | | | | | | | All struct operand fields are initialized during decoding for all operand types except OP_MEM, but there is no reason for that. Move OP_MEM operand initialization into decoding stage for consistency. Signed-off-by: Gleb Natapov <gleb@redhat.com> Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
* KVM: Use task switch from emulator.cGleb Natapov2010-05-171-1/+5
| | | | | | | Remove old task switch code from x86.c Signed-off-by: Gleb Natapov <gleb@redhat.com> Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
* KVM: x86 emulator: Use load_segment_descriptor() instead of ↵Gleb Natapov2010-05-171-5/+5
| | | | | | | kvm_load_segment_descriptor() Signed-off-by: Gleb Natapov <gleb@redhat.com> Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
* KVM: x86 emulator: Emulate task switch in emulator.cGleb Natapov2010-05-171-0/+563
| | | | | | | Implement emulation of 16/32 bit task switch in emulator.c Signed-off-by: Gleb Natapov <gleb@redhat.com> Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
* KVM: x86 emulator: cleanup grp3 return valueGleb Natapov2010-05-171-8/+4
| | | | | | | | | When x86_emulate_insn() does not know how to emulate instruction it exits via cannot_emulate label in all cases except when emulating grp3. Fix that. Signed-off-by: Gleb Natapov <gleb@redhat.com> Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
* KVM: x86 emulator: If LOCK prefix is used dest arg should be memory.Gleb Natapov2010-05-171-1/+1
| | | | | | | | If LOCK prefix is used dest arg should be memory, otherwise instruction should generate #UD. Signed-off-by: Gleb Natapov <gleb@redhat.com> Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
* KVM: x86 emulator: do not call writeback if msr access fails.Gleb Natapov2010-05-171-2/+2
| | | | | Signed-off-by: Gleb Natapov <gleb@redhat.com> Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
* KVM: x86 emulator: fix return values of syscall/sysenter/sysexit emulationsGleb Natapov2010-05-171-6/+11
| | | | | | | | Return X86EMUL_PROPAGATE_FAULT is fault was injected. Also inject #UD for those instruction when appropriate. Signed-off-by: Gleb Natapov <gleb@redhat.com> Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
* KVM: x86 emulator: fix mov dr to inject #UD when needed.Gleb Natapov2010-05-171-6/+12
| | | | | | | If CR4.DE=1 access to registers DR4/DR5 cause #UD. Signed-off-by: Gleb Natapov <gleb@redhat.com> Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
* KVM: x86 emulator: inject #UD on access to non-existing CRGleb Natapov2010-05-171-0/+7
| | | | | Signed-off-by: Gleb Natapov <gleb@redhat.com> Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
* KVM: x86 emulator: 0f (20|21|22|23) ignore mod bits.Gleb Natapov2010-05-171-8/+0
| | | | | | | | | Resent spec says that for 0f (20|21|22|23) the 2 bits in the mod field are ignored. Interestingly enough older spec says that 11 is only valid encoding. Signed-off-by: Gleb Natapov <gleb@redhat.com> Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
* KVM: x86 emulator: fix 0f 01 /5 emulationGleb Natapov2010-05-171-0/+3
| | | | | | | It is undefined and should generate #UD. Signed-off-by: Gleb Natapov <gleb@redhat.com> Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
* KVM: x86 emulator: fix mov r/m, sreg emulation.Gleb Natapov2010-05-171-4/+3
| | | | | | | mov r/m, sreg generates #UD ins sreg is incorrect. Signed-off-by: Gleb Natapov <gleb@redhat.com> Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
* KVM: Provide current eip as part of emulator context.Gleb Natapov2010-05-171-6/+6
| | | | | | | Eliminate the need to call back into KVM to get it from emulator. Signed-off-by: Gleb Natapov <gleb@redhat.com> Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
* KVM: Provide x86_emulate_ctxt callback to get current cplGleb Natapov2010-05-171-7/+8
| | | | | Signed-off-by: Gleb Natapov <gleb@redhat.com> Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
* KVM: remove realmode_lmsw function.Gleb Natapov2010-05-171-2/+2
| | | | | | | Use (get|set)_cr callback to emulate lmsw inside emulator. Signed-off-by: Gleb Natapov <gleb@redhat.com> Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
* KVM: Provide callback to get/set control registers in emulator ops.Gleb Natapov2010-05-171-4/+3
| | | | | | | | | Use this callback instead of directly call kvm function. Also rename realmode_(set|get)_cr to emulator_(set|get)_cr since function has nothing to do with real mode. Signed-off-by: Gleb Natapov <gleb@redhat.com> Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
* KVM: Remove pointer to rflags from realmode_set_cr parameters.Gleb Natapov2010-05-171-2/+1
| | | | | | | | Mov reg, cr instruction doesn't change flags in any meaningful way, so no need to update rflags after instruction execution. Signed-off-by: Gleb Natapov <gleb@redhat.com> Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
* KVM: x86 emulator: check return value against correct defineGleb Natapov2010-05-171-1/+1
| | | | | | | | Check return value against correct define instead of open code the value. Signed-off-by: Gleb Natapov <gleb@redhat.com> Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
* KVM: x86 emulator: fix RCX access during rep emulationGleb Natapov2010-05-171-2/+2
| | | | | | | | During rep emulation access length to RCX depends on current address mode. Signed-off-by: Gleb Natapov <gleb@redhat.com> Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
* KVM: x86 emulator: Fix DstAcc decoding.Gleb Natapov2010-05-171-2/+5
| | | | | | | Set correct operation length. Add RAX (64bit) handling. Signed-off-by: Gleb Natapov <gleb@redhat.com> Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
* KVM: x86 emulator mark VMMCALL and LMSW as privilegedGleb Natapov2010-05-171-2/+2
| | | | | | | | LMSW is present in both group tables. It was marked privileged only in one of them. Intel analog of VMMCALL is already marked privileged. Signed-off-by: Gleb Natapov <gleb@redhat.com> Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
* KVM: x86 emulator: Implement jmp far opcode ff/5Gleb Natapov2010-04-251-2/+9
| | | | | | | Implement jmp far opcode ff/5. It is used by multiboot loader. Signed-off-by: Gleb Natapov <gleb@redhat.com> Signed-off-by: Avi Kivity <avi@redhat.com>
* KVM: x86 emulator: Add decoding of 16bit second in memory argumentGleb Natapov2010-04-251-0/+18
| | | | | | | Add decoding of Ep type of argument used by callf/jmpf. Signed-off-by: Gleb Natapov <gleb@redhat.com> Signed-off-by: Avi Kivity <avi@redhat.com>
* KVM: x86: Save&restore interrupt shadow maskJan Kiszka2010-04-251-2/+2
| | | | | | | | | | | | | The interrupt shadow created by STI or MOV-SS-like operations is part of the VCPU state and must be preserved across migration. Transfer it in the spare padding field of kvm_vcpu_events.interrupt. As a side effect we now have to make vmx_set_interrupt_shadow robust against both shadow types being set. Give MOV SS a higher priority and skip STI in that case to avoid that VMX throws a fault on next entry. Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com> Signed-off-by: Avi Kivity <avi@redhat.com>
* KVM: x86 emulator: Fix x86_emulate_insn() not to use the variable rc for ↵Takuya Yoshikawa2010-04-251-9/+6
| | | | | | | | | | | | | non-X86EMUL values This patch makes non-X86EMUL_* family functions not to use the variable rc. Be sure that this changes nothing but makes the purpose of the variable rc clearer. Signed-off-by: Takuya Yoshikawa <yoshikawa.takuya@oss.ntt.co.jp> Signed-off-by: Avi Kivity <avi@redhat.com>
* KVM: x86 emulator: X86EMUL macro replacements: x86_emulate_insn() and its ↵Takuya Yoshikawa2010-04-251-33/+29
| | | | | | | | | | | | | | helpers This patch just replaces integer values used inside x86_emulate_insn() and its helper functions to X86EMUL_*. The purpose of this is to make it clear what will happen when the variable rc is compared to X86EMUL_* at the end of x86_emulate_insn(). Signed-off-by: Takuya Yoshikawa <yoshikawa.takuya@oss.ntt.co.jp> Signed-off-by: Avi Kivity <avi@redhat.com>
* KVM: x86 emulator: X86EMUL macro replacements: from do_fetch_insn_byte() to ↵Takuya Yoshikawa2010-04-251-9/+9
| | | | | | | | | | | | | x86_decode_insn() This patch just replaces the integer values used inside x86's decode functions to X86EMUL_*. By this patch, it becomes clearer that we are using X86EMUL_* value propagated from ops->read_std() in do_fetch_insn_byte(). Signed-off-by: Takuya Yoshikawa <yoshikawa.takuya@oss.ntt.co.jp> Signed-off-by: Avi Kivity <avi@redhat.com>
* KVM: inject #UD in 64bit mode from instruction that are not valid thereGleb Natapov2010-04-251-5/+5
| | | | | | | Some instruction are obsolete in a long mode. Inject #UD. Signed-off-by: Gleb Natapov <gleb@redhat.com> Signed-off-by: Avi Kivity <avi@redhat.com>
* KVM: Fix emulate_sys[call, enter, exit]()'s fault handlingTakuya Yoshikawa2010-03-011-17/+20
| | | | | | | | | | | | | | | | | | This patch fixes emulate_syscall(), emulate_sysenter() and emulate_sysexit() to handle injected faults properly. Even though original code injects faults in these functions, we cannot handle these unless we use the different return value from the UNHANDLEABLE case. So this patch use X86EMUL_* codes instead of -1 and 0 and makes x86_emulate_insn() to handle these propagated faults. Be sure that, in x86_emulate_insn(), goto cannot_emulate and goto done with rc equals X86EMUL_UNHANDLEABLE have same effect. Signed-off-by: Takuya Yoshikawa <yoshikawa.takuya@oss.ntt.co.jp> Signed-off-by: Gleb Natapov <gleb@redhat.com> Signed-off-by: Avi Kivity <avi@redhat.com>
* KVM: Fix segment descriptor loadingGleb Natapov2010-03-011-22/+8
| | | | | | | | | | | Add proper error and permission checking. This patch also change task switching code to load segment selectors before segment descriptors, like SDM requires, otherwise permission checking during segment descriptor loading will be incorrect. Cc: stable@kernel.org (2.6.33, 2.6.32) Signed-off-by: Gleb Natapov <gleb@redhat.com> Signed-off-by: Avi Kivity <avi@redhat.com>
* KVM: x86 emulator: Forbid modifying CS segment register by mov instructionGleb Natapov2010-03-011-0/+6
| | | | | | | | | Inject #UD if guest attempts to do so. This is in accordance to Intel SDM. Cc: stable@kernel.org (2.6.33, 2.6.32) Signed-off-by: Gleb Natapov <gleb@redhat.com> Signed-off-by: Avi Kivity <avi@redhat.com>
* KVM: x86 emulator: disallow opcode 82 in 64-bit modeGleb Natapov2010-03-011-8/+8
| | | | | | | Instructions with opcode 82 are not valid in 64 bit mode. Signed-off-by: Gleb Natapov <gleb@redhat.com> Signed-off-by: Avi Kivity <avi@redhat.com>
* KVM: x86 emulator: code style cleanupWei Yongjun2010-03-011-1/+1
| | | | | | | Just remove redundant semicolon. Signed-off-by: Wei Yongjun <yjwei@cn.fujitsu.com> Signed-off-by: Avi Kivity <avi@redhat.com>
* KVM: x86 emulator: Add LOCK prefix validity checkingGleb Natapov2010-03-011-41/+56
| | | | | | | | | | Instructions which are not allowed to have LOCK prefix should generate #UD if one is used. [avi: fold opcode 82 fix from another patch] Signed-off-by: Gleb Natapov <gleb@redhat.com> Signed-off-by: Avi Kivity <avi@redhat.com>
* KVM: x86 emulator: Check CPL level during privilege instruction emulationGleb Natapov2010-03-011-15/+20
| | | | | | | | | Add CPL checking in case emulator is tricked into emulating privilege instruction from userspace. Signed-off-by: Gleb Natapov <gleb@redhat.com> Cc: stable@kernel.org Signed-off-by: Avi Kivity <avi@redhat.com>
OpenPOWER on IntegriCloud