aboutsummaryrefslogtreecommitdiffstats
path: root/arch/x86/kvm/emulate.c
Commit message (Collapse)AuthorAge
* KVM: x86 emulator: fix %rip-relative addressing with immediate source operandAvi Kivity2011-06-29
| | | | | | | | | | | %rip-relative addressing is relative to the first byte of the next instruction, so we need to add %rip only after we've fetched any immediate bytes. Based on original patch by Li Xin <xin.li@intel.com>. Signed-off-by: Avi Kivity <avi@redhat.com> Acked-by: Li Xin <xin.li@intel.com> Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
* KVM: x86: use proper port value when checking io instruction permissionMarcelo Tosatti2011-06-06
| | | | | | | | | | | | Commit f6511935f42 moved the permission check for io instructions to the ->check_perm callback. It failed to copy the port value from RDX register for string and "in,out ax,dx" instructions. Fix it by reading RDX register at decode stage when appropriate. Fixes FC8.32 installation. Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
* KVM: x86 emulator: Make jmp far emulation into a separate functionTakuya Yoshikawa2011-05-22
| | | | | | | | | | We introduce em_jmp_far(). We also call this from em_grp45() to stop treating modrm_reg == 5 case separately in the group 5 emulation. Signed-off-by: Takuya Yoshikawa <yoshikawa.takuya@oss.ntt.co.jp> Signed-off-by: Avi Kivity <avi@redhat.com>
* KVM: x86 emulator: Rename emulate_grpX() to em_grpX()Takuya Yoshikawa2011-05-22
| | | | | | | | | The prototypes are changed appropriately. We also replaces "goto grp45;" with simple em_grp45() call. Signed-off-by: Takuya Yoshikawa <yoshikawa.takuya@oss.ntt.co.jp> Signed-off-by: Avi Kivity <avi@redhat.com>
* KVM: x86 emulator: Remove unused arg from emulate_pop()Takuya Yoshikawa2011-05-22
| | | | | | | The opt of emulate_grp1a() is also removed. Signed-off-by: Takuya Yoshikawa <yoshikawa.takuya@oss.ntt.co.jp> Signed-off-by: Avi Kivity <avi@redhat.com>
* KVM: x86 emulator: Remove unused arg from writeback()Takuya Yoshikawa2011-05-22
| | | | | | | Remove inline at this chance. Signed-off-by: Takuya Yoshikawa <yoshikawa.takuya@oss.ntt.co.jp> Signed-off-by: Avi Kivity <avi@redhat.com>
* KVM: x86 emulator: Remove unused arg from read_descriptor()Takuya Yoshikawa2011-05-22
| | | | | Signed-off-by: Takuya Yoshikawa <yoshikawa.takuya@oss.ntt.co.jp> Signed-off-by: Avi Kivity <avi@redhat.com>
* KVM: x86 emulator: Remove unused arg from seg_override()Takuya Yoshikawa2011-05-22
| | | | | | | | In addition, one comma at the end of a statement is replaced with a semicolon. Signed-off-by: Takuya Yoshikawa <yoshikawa.takuya@oss.ntt.co.jp> Signed-off-by: Avi Kivity <avi@redhat.com>
* KVM: x86 emulator: consolidate segment accessorsAvi Kivity2011-05-22
| | | | | | | Instead of separate accessors for the segment selector and cached descriptor, use one accessor for both. This simplifies the code somewhat. Signed-off-by: Avi Kivity <avi@redhat.com>
* KVM: emulator: Propagate fault in far jump emulationGleb Natapov2011-05-22
| | | | | Signed-off-by: Gleb Natapov <gleb@redhat.com> Signed-off-by: Avi Kivity <avi@redhat.com>
* KVM: x86 emulator: consolidate group handlingAvi Kivity2011-05-22
| | | | | | | Move all groups into a single field and handle them in a single place. This saves bits when we add more group types (3 bits -> 7 groups types). Signed-off-by: Avi Kivity <avi@redhat.com>
* KVM: x86 emulator: Use opcode::execute for PUSHF/POPF (9C/9D)Takuya Yoshikawa2011-05-22
| | | | | | | For this, em_pushf/popf() are introduced. Signed-off-by: Takuya Yoshikawa <yoshikawa.takuya@oss.ntt.co.jp> Signed-off-by: Avi Kivity <avi@redhat.com>
* KVM: x86 emulator: Use opcode::execute for PUSHA/POPA (60/61)Takuya Yoshikawa2011-05-22
| | | | | | | For this, emulate_pusha/popa() are converted to em_pusha/popa(). Signed-off-by: Takuya Yoshikawa <yoshikawa.takuya@oss.ntt.co.jp> Signed-off-by: Avi Kivity <avi@redhat.com>
* KVM: x86 emulator: Use opcode::execute for POP reg (58-5F)Takuya Yoshikawa2011-05-22
| | | | | | | | In addition, the RET emulation is changed to call em_pop() to remove the pop_instruction label. Signed-off-by: Takuya Yoshikawa <yoshikawa.takuya@oss.ntt.co.jp> Signed-off-by: Avi Kivity <avi@redhat.com>
* KVM: x86 emulator: Use opcode::execute for Group 1, CMPS and SCASTakuya Yoshikawa2011-05-22
| | | | | | | | | | | | | | | The following instructions are changed to use opcode::execute. Group 1 (80-83) ADD (00-05), OR (08-0D), ADC (10-15), SBB (18-1D), AND (20-25), SUB (28-2D), XOR (30-35), CMP (38-3D) CMPS (A6-A7), SCAS (AE-AF) The last two do the same as CMP in the emulator, so em_cmp() is used. Signed-off-by: Takuya Yoshikawa <yoshikawa.takuya@oss.ntt.co.jp> Signed-off-by: Avi Kivity <avi@redhat.com>
* KVM: x86 emulator: Use opcode::execute for 0F 01 opcodeAvi Kivity2011-05-22
| | | | Signed-off-by: Avi Kivity <avi@redhat.com>
* KVM: x86 emulator: Don't force #UD for 0F 01 /5Avi Kivity2011-05-22
| | | | | | | While it isn't defined, no need to force a #UD. If it becomes defined in the future this can cause wierd problems for the guest. Signed-off-by: Avi Kivity <avi@redhat.com>
* KVM: x86 emulator: move 0F 01 sub-opcodes into their own functionsAvi Kivity2011-05-22
| | | | Signed-off-by: Avi Kivity <avi@redhat.com>
* KVM: x86 emulator: fix const value warning on i386 in svm insn RAX checkRandy Dunlap2011-05-22
| | | | | | | arch/x86/kvm/emulate.c:2598: warning: integer constant is too large for 'long' type Signed-off-by: Randy Dunlap <randy.dunlap@oracle.com> Signed-off-by: Avi Kivity <avi@redhat.com>
* KVM: x86 emulator: avoid calling wbinvd() macroClemens Noss2011-05-22
| | | | | | | | | | | | | | | | | Commit 0b56652e33c72092956c651ab6ceb9f0ad081153 fails to build: CC [M] arch/x86/kvm/emulate.o arch/x86/kvm/emulate.c: In function 'x86_emulate_insn': arch/x86/kvm/emulate.c:4095:25: error: macro "wbinvd" passed 1 arguments, but takes just 0 arch/x86/kvm/emulate.c:4095:3: warning: statement with no effect make[2]: *** [arch/x86/kvm/emulate.o] Error 1 make[1]: *** [arch/x86/kvm] Error 2 make: *** [arch/x86] Error 2 Work around this for now. Signed-off-by: Clemens Noss <cnoss@gmx.de> Signed-off-by: Avi Kivity <avi@redhat.com>
* KVM: x86 emulator: add new ->wbinvd() callbackAvi Kivity2011-05-22
| | | | | | Instead of calling kvm_emulate_wbinvd() directly. Signed-off-by: Avi Kivity <avi@redhat.com>
* KVM: x86 emulator: add ->fix_hypercall() callbackAvi Kivity2011-05-22
| | | | | | Artificial, but needed to remove direct calls to KVM. Signed-off-by: Avi Kivity <avi@redhat.com>
* KVM: x86 emulator: add new ->halt() callbackAvi Kivity2011-05-22
| | | | | | Instead of reaching into vcpu internals. Signed-off-by: Avi Kivity <avi@redhat.com>
* KVM: x86 emulator: make emulate_invlpg() an emulator callbackAvi Kivity2011-05-22
| | | | | | Removing direct calls to KVM. Signed-off-by: Avi Kivity <avi@redhat.com>
* KVM: x86 emulator: emulate CLTS internallyAvi Kivity2011-05-22
| | | | | | | | | Avoid using ctxt->vcpu; we can do everything with ->get_cr() and ->set_cr(). A side effect is that we no longer activate the fpu on emulated CLTS; but that should be very rare. Signed-off-by: Avi Kivity <avi@redhat.com>
* KVM: x86 emulator: Replace calls to is_pae() and is_paging with ->get_cr()Avi Kivity2011-05-22
| | | | | | Avoid use of ctxt->vcpu. Signed-off-by: Avi Kivity <avi@redhat.com>
* KVM: x86 emulator: drop use of is_long_mode()Avi Kivity2011-05-22
| | | | | | | Requires ctxt->vcpu, which is to be abolished. Replace with open calls to get_msr(). Signed-off-by: Avi Kivity <avi@redhat.com>
* KVM: x86 emulator: add and use new callbacks set_idt(), set_gdt()Avi Kivity2011-05-22
| | | | | | Replacing direct calls to realmode_lgdt(), realmode_lidt(). Signed-off-by: Avi Kivity <avi@redhat.com>
* KVM: x86 emulator: avoid using ctxt->vcpu in check_perm() callbacksAvi Kivity2011-05-22
| | | | | | Unneeded for register access. Signed-off-by: Avi Kivity <avi@redhat.com>
* KVM: x86 emulator: drop vcpu argument from intercept callbackAvi Kivity2011-05-22
| | | | | | Making the emulator caller agnostic. Signed-off-by: Avi Kivity <avi@redhat.com>
* KVM: x86 emulator: drop vcpu argument from cr/dr/cpl/msr callbacksAvi Kivity2011-05-22
| | | | | | Making the emulator caller agnostic. Signed-off-by: Avi Kivity <avi@redhat.com>
* KVM: x86 emulator: drop vcpu argument from segment/gdt/idt callbacksAvi Kivity2011-05-22
| | | | | | | | | Making the emulator caller agnostic. [Takuya Yoshikawa: fix typo leading to LDT failures] Signed-off-by: Takuya Yoshikawa <yoshikawa.takuya@oss.ntt.co.jp> Signed-off-by: Avi Kivity <avi@redhat.com>
* KVM: x86 emulator: drop vcpu argument from pio callbacksAvi Kivity2011-05-11
| | | | | | Making the emulator caller agnostic. Signed-off-by: Avi Kivity <avi@redhat.com>
* KVM: x86 emulator: drop vcpu argument from memory read/write callbacksAvi Kivity2011-05-11
| | | | | | Making the emulator caller agnostic. Signed-off-by: Avi Kivity <avi@redhat.com>
* KVM: x86 emulator: whitespace cleanupsAvi Kivity2011-05-11
| | | | | | Clean up lines longer than 80 columns. No code changes. Signed-off-by: Avi Kivity <avi@redhat.com>
* KVM: emulator: Use linearize() when fetching instructionsNelson Elhage2011-05-11
| | | | | | | | | | Since segments need to be handled slightly differently when fetching instructions, we add a __linearize helper that accepts a new 'fetch' boolean. [avi: fix oops caused by wrong segmented_address initialization order] Signed-off-by: Nelson Elhage <nelhage@ksplice.com> Signed-off-by: Avi Kivity <avi@redhat.com>
* KVM: x86 emulator: Handle wraparound in (cs_base + offset) when fetching insnsNelson Elhage2011-05-11
| | | | | | | | | | 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>
* KVM: x86 emulator: Use em_push() instead of emulate_push()Takuya Yoshikawa2011-05-11
| | | | | | | | | | | em_push() is a simple wrapper of emulate_push(). So this patch replaces emulate_push() with em_push() and removes the unnecessary former. In addition, the unused ops arguments are removed from emulate_pusha() and emulate_grp45(). Signed-off-by: Takuya Yoshikawa <yoshikawa.takuya@oss.ntt.co.jp> Signed-off-by: Avi Kivity <avi@redhat.com>
* KVM: x86 emulator: Make emulate_push() store the value directlyTakuya Yoshikawa2011-05-11
| | | | | | | | | | | | | | PUSH emulation stores the value by calling writeback() after setting the dst operand appropriately in emulate_push(). This writeback() using dst is not needed at all because we know the target is the stack. So this patch makes emulate_push() call, newly introduced, segmented_write() directly. By this, many inlined writeback()'s are removed. Signed-off-by: Takuya Yoshikawa <yoshikawa.takuya@oss.ntt.co.jp> Signed-off-by: Avi Kivity <avi@redhat.com>
* KVM: x86 emulator: Disable writeback for CMP emulationTakuya Yoshikawa2011-05-11
| | | | | | | | | | This stops "CMP r/m, reg" to write back the data into memory. Pointed out by Avi. The writeback suppression now covers CMP, CMPS, SCAS. Signed-off-by: Takuya Yoshikawa <yoshikawa.takuya@oss.ntt.co.jp> Signed-off-by: Avi Kivity <avi@redhat.com>
* KVM: x86 emulator: implement segment permission checksAvi Kivity2011-05-11
| | | | Signed-off-by: Avi Kivity <avi@redhat.com>
* KVM: x86 emulator: move desc_limit_scaled()Avi Kivity2011-05-11
| | | | | | For reuse later. Signed-off-by: Avi Kivity <avi@redhat.com>
* KVM: x86 emulator: move linearize() downwardsAvi Kivity2011-05-11
| | | | | | So it can call emulate_gp() without forward declarations. Signed-off-by: Avi Kivity <avi@redhat.com>
* KVM: x86 emulator: pass access size and read/write intent to linearize()Avi Kivity2011-05-11
| | | | | | Needed for segment read/write checks. Signed-off-by: Avi Kivity <avi@redhat.com>
* KVM: x86 emulator: change address linearization to return an error codeAvi Kivity2011-05-11
| | | | | | Preparing to add segment checks. Signed-off-by: Avi Kivity <avi@redhat.com>
* KVM: x86 emulator: move invlpg emulation into a functionAvi Kivity2011-05-11
| | | | | | It's going to get more complicated soon. Signed-off-by: Avi Kivity <avi@redhat.com>
* KVM: x86 emulator: Add helpers for memory access using segmented addressesAvi Kivity2011-05-11
| | | | | | Will help later adding proper segment checks. Signed-off-by: Avi Kivity <avi@redhat.com>
* KVM: x86 emulator: Drop EFER.SVME requirement from VMMCALLAvi Kivity2011-05-11
| | | | | | | VMMCALL requires EFER.SVME to be enabled in the host, not in the guest, which is what check_svme() checks. Signed-off-by: Avi Kivity <avi@redhat.com>
* KVM: x86 emulator: Re-add VendorSpecific tag to VMMCALL insnAvi Kivity2011-05-11
| | | | | | | | VMMCALL needs the VendorSpecific tag so that #UD emulation (called if a guest running on AMD was migrated to an Intel host) is allowed to process the instruction. Signed-off-by: Avi Kivity <avi@redhat.com>
* KVM: x86 emulator: do not open code return values from the emulatorGleb Natapov2011-05-11
| | | | | Signed-off-by: Gleb Natapov <gleb@redhat.com> Signed-off-by: Avi Kivity <avi@redhat.com>