summaryrefslogtreecommitdiffstats
path: root/arch/x86/kvm/x86.c
Commit message (Collapse)AuthorAgeFilesLines
* Merge branch 'x86-asm-for-linus' of ↵Linus Torvalds2010-08-061-1/+1
|\ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | git://git.kernel.org/pub/scm/linux/kernel/git/tip/linux-2.6-tip * 'x86-asm-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/linux-2.6-tip: um, x86: Cast to (u64 *) inside set_64bit() x86-32, asm: Directly access per-cpu GDT x86-64, asm: Directly access per-cpu IST x86, asm: Merge cmpxchg_486_u64() and cmpxchg8b_emu() x86, asm: Move cmpxchg emulation code to arch/x86/lib x86, asm: Clean up and simplify <asm/cmpxchg.h> x86, asm: Clean up and simplify set_64bit() x86: Add memory modify constraints to xchg() and cmpxchg() x86-64: Simplify loading initial_gs x86: Use symbolic MSR names x86: Remove redundant K6 MSRs
| * Merge remote branch 'origin/x86/urgent' into x86/asmH. Peter Anvin2010-07-271-2/+2
| |\
| * | x86: Remove redundant K6 MSRsBrian Gerst2010-07-211-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | MSR_K6_EFER is unused, and MSR_K6_STAR is redundant with MSR_STAR. Signed-off-by: Brian Gerst <brgerst@gmail.com> LKML-Reference: <1279371808-24804-1-git-send-email-brgerst@gmail.com> Reviewed-by: Pekka Enberg <penberg@cs.helsinki.fi> Signed-off-by: H. Peter Anvin <hpa@zytor.com>
* | | KVM: x86 emulator: fix xchg instruction emulationWei Yongjun2010-08-021-0/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | If the destination is a memory operand and the memory cannot map to a valid page, the xchg instruction emulation and locked instruction will not work on io regions and stuck in endless loop. We should emulate exchange as write to fix it. Signed-off-by: Wei Yongjun <yjwei@cn.fujitsu.com> Acked-by: Gleb Natapov <gleb@redhat.com> Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
* | | KVM: x86: never re-execute instruction with enabled tdpGleb Natapov2010-08-021-0/+3
| | | | | | | | | | | | | | | | | | | | | | | | With tdp enabled we should get into emulator only when emulating io, so reexecution will always bring us back into emulator. Signed-off-by: Gleb Natapov <gleb@redhat.com> Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
* | | KVM: Expose MCE control MSRs to userspaceAvi Kivity2010-08-021-0/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | Userspace needs to reset and save/restore these MSRs. The MCE banks are not exposed since their number varies from vcpu to vcpu. Signed-off-by: Avi Kivity <avi@redhat.com> Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
* | | KVM: PIT: stop vpit before freeing irq_routingXiao Guangrong2010-08-021-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Fix: general protection fault: 0000 [#1] PREEMPT SMP DEBUG_PAGEALLOC ...... Call Trace: [<ffffffffa0159bd1>] ? kvm_set_irq+0xdd/0x24b [kvm] [<ffffffff8106ea8b>] ? trace_hardirqs_off_caller+0x1f/0x10e [<ffffffff813ad17f>] ? sub_preempt_count+0xe/0xb6 [<ffffffff8106d273>] ? put_lock_stats+0xe/0x27 ... RIP [<ffffffffa0159c72>] kvm_set_irq+0x17e/0x24b [kvm] This bug is triggered when guest is shutdown, is because we freed irq_routing before pit thread stopped Signed-off-by: Xiao Guangrong <xiaoguangrong@cn.fujitsu.com> Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
* | | KVM: Reenter guest after emulation failure if due to access to non-mmio addressGleb Natapov2010-08-021-7/+25
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | When shadow pages are in use sometimes KVM try to emulate an instruction when it accesses a shadowed page. If emulation fails KVM un-shadows the page and reenter guest to allow vcpu to execute the instruction. If page is not in shadow page hash KVM assumes that this was attempt to do MMIO and reports emulation failure to userspace since there is no way to fix the situation. This logic has a race though. If two vcpus tries to write to the same shadowed page simultaneously both will enter emulator, but only one of them will find the page in shadow page hash since the one who founds it also removes it from there, so another cpu will report failure to userspace and will abort the guest. Fix this by checking (in addition to checking shadowed page hash) that page that caused the emulation belongs to valid memory slot. If it is then reenter the guest to allow vcpu to reexecute the instruction. Signed-off-by: Gleb Natapov <gleb@redhat.com> Signed-off-by: Avi Kivity <avi@redhat.com>
* | | KVM: VMX: Execute WBINVD to keep data consistency with assigned devicesSheng Yang2010-08-011-0/+41
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Some guest device driver may leverage the "Non-Snoop" I/O, and explicitly WBINVD or CLFLUSH to a RAM space. Since migration may occur before WBINVD or CLFLUSH, we need to maintain data consistency either by: 1: flushing cache (wbinvd) when the guest is scheduled out if there is no wbinvd exit, or 2: execute wbinvd on all dirty physical CPUs when guest wbinvd exits. Signed-off-by: Yaozu (Eddie) Dong <eddie.dong@intel.com> Signed-off-by: Sheng Yang <sheng@linux.intel.com> Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
* | | KVM: Simplify vcpu_enter_guest() mmu reload logic slightlyAvi Kivity2010-08-011-7/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | No need to reload the mmu in between two different vcpu->requests checks. kvm_mmu_reload() may trigger KVM_REQ_TRIPLE_FAULT, but that will be caught during atomic guest entry later. Signed-off-by: Avi Kivity <avi@redhat.com> Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
* | | KVM: x86: Enable AVX for guestSheng Yang2010-08-011-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Enable Intel(R) Advanced Vector Extension(AVX) for guest. The detection of AVX feature includes OSXSAVE bit testing. When OSXSAVE bit is not set, even if AVX is supported, the AVX instruction would result in UD as well. So we're safe to expose AVX bits to guest directly. Signed-off-by: Sheng Yang <sheng@linux.intel.com> Signed-off-by: Avi Kivity <avi@redhat.com>
* | | KVM: Prevent internal slots from being COWedAvi Kivity2010-08-011-1/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | If a process with a memory slot is COWed, the page will change its address (despite having an elevated reference count). This breaks internal memory slots which have their physical addresses loaded into vmcs registers (see the APIC access memory slot). Signed-off-by: Avi Kivity <avi@redhat.com>
* | | KVM: Add mini-API for vcpu->requestsAvi Kivity2010-08-011-14/+13
| | | | | | | | | | | | | | | | | | Makes it a little more readable and hackable. Signed-off-by: Avi Kivity <avi@redhat.com>
* | | KVM: Remove kernel-allocated memory regionsAvi Kivity2010-08-011-16/+0
| | | | | | | | | | | | | | | | | | | | | Equivalent (and better) functionality is provided by user-allocated memory regions. Signed-off-by: Avi Kivity <avi@redhat.com>
* | | KVM: Remove memory alias supportAvi Kivity2010-08-011-125/+0
| | | | | | | | | | | | | | | | | | | | | As advertised in feature-removal-schedule.txt. Equivalent support is provided by overlapping memory regions. Signed-off-by: Avi Kivity <avi@redhat.com>
* | | KVM: Consolidate load/save temporary buffer allocation and freeingAvi Kivity2010-08-011-30/+32
| | | | | | | | | | | | | | | | | | | | | Instead of three temporary variables and three free calls, have one temporary variable (with four names) and one free call. Signed-off-by: Avi Kivity <avi@redhat.com>
* | | KVM: Fix xsave and xcr save/restore memory leakAvi Kivity2010-08-011-8/+4
| | | | | | | | | | | | | | | | | | We allocate temporary kernel buffers for these structures, but never free them. Signed-off-by: Avi Kivity <avi@redhat.com>
* | | KVM: x86: XSAVE/XRSTOR live migration supportSheng Yang2010-08-011-0/+139
| | | | | | | | | | | | | | | | | | | | | This patch enable save/restore of xsave state. Signed-off-by: Sheng Yang <sheng@linux.intel.com> Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
* | | KVM: Fix mov cr3 #GP at wrong instructionAvi Kivity2010-08-011-8/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | On Intel, we call skip_emulated_instruction() even if we injected a #GP, resulting in the #GP pointing at the wrong address. Fix by injecting the exception and skipping the instruction at the same place, so we can do just one or the other. Signed-off-by: Avi Kivity <avi@redhat.com> Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
* | | KVM: Fix mov cr4 #GP at wrong instructionAvi Kivity2010-08-011-8/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | On Intel, we call skip_emulated_instruction() even if we injected a #GP, resulting in the #GP pointing at the wrong address. Fix by injecting the exception and skipping the instruction at the same place, so we can do just one or the other. Signed-off-by: Avi Kivity <avi@redhat.com> Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
* | | KVM: Fix mov cr0 #GP at wrong instructionAvi Kivity2010-08-011-9/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | On Intel, we call skip_emulated_instruction() even if we injected a #GP, resulting in the #GP pointing at the wrong address. Fix by injecting the exception and skipping the instruction at the same place, so we can do just one or the other. Signed-off-by: Avi Kivity <avi@redhat.com> Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
* | | KVM: VMX: Enable XSAVE/XRSTOR for guestDexuan Cui2010-08-011-7/+123
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This patch enable guest to use XSAVE/XRSTOR instructions. We assume that host_xcr0 would use all possible bits that OS supported. And we loaded xcr0 in the same way we handled fpu - do it as late as we can. Signed-off-by: Dexuan Cui <dexuan.cui@intel.com> Signed-off-by: Sheng Yang <sheng@linux.intel.com> Reviewed-by: Marcelo Tosatti <mtosatti@redhat.com> Signed-off-by: Avi Kivity <avi@redhat.com>
* | | KVM: x86: use linux/uaccess.h instead of asm/uaccess.hLai Jiangshan2010-08-011-1/+1
| | | | | | | | | | | | | | | | | | | | | Should use linux/uaccess.h instead of asm/uaccess.h Signed-off-by: Lai Jiangshan <laijs@cn.fujitsu.com> Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
* | | KVM: x86: Propagate fpu_alloc errorsJan Kiszka2010-08-011-2/+9
| | | | | | | | | | | | | | | | | | | | | | | | Memory allocation may fail. Propagate such errors. Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com> Reviewed-by: Sheng Yang <sheng@linux.intel.com> Signed-off-by: Avi Kivity <avi@redhat.com>
* | | KVM: Update Red Hat copyrightsAvi Kivity2010-08-011-0/+1
| | | | | | | | | | | | Signed-off-by: Avi Kivity <avi@redhat.com>
* | | KVM: x86: Use FPU APISheng Yang2010-08-011-36/+16
| | | | | | | | | | | | | | | | | | | | | Convert KVM to use generic FPU API. Signed-off-by: Sheng Yang <sheng@linux.intel.com> Signed-off-by: Avi Kivity <avi@redhat.com>
* | | KVM: x86: Use unlazy_fpu() for host FPUSheng Yang2010-08-011-16/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | We can avoid unnecessary fpu load when userspace process didn't use FPU frequently. Derived from Avi's idea. Signed-off-by: Sheng Yang <sheng@linux.intel.com> Signed-off-by: Avi Kivity <avi@redhat.com>
* | | KVM: Consolidate arch specific vcpu ioctl lockingAvi Kivity2010-08-011-2/+0
| | | | | | | | | | | | | | | | | | | | | Now that all arch specific ioctls have centralized locking, it is easy to move it to the central dispatcher. Signed-off-by: Avi Kivity <avi@redhat.com>
* | | KVM: x86: Lock arch specific vcpu ioctls centrallyAvi Kivity2010-08-011-39/+2
| | | | | | | | | | | | Signed-off-by: Avi Kivity <avi@redhat.com>
* | | KVM: move vcpu locking to dispatcher for generic vcpu ioctlsAvi Kivity2010-08-011-38/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | All vcpu ioctls need to be locked, so instead of locking each one specifically we lock at the generic dispatcher. This patch only updates generic ioctls and leaves arch specific ioctls alone. Signed-off-by: Avi Kivity <avi@redhat.com>
* | | KVM: x86: cleanup unused local variableXiao Guangrong2010-08-011-2/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | fix: arch/x86/kvm/x86.c: In function ‘handle_emulation_failure’: arch/x86/kvm/x86.c:3844: warning: unused variable ‘ctxt’ Signed-off-by: Xiao Guangrong <xiaoguangrong@cn.fujitsu.com> Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
* | | KVM: VMX: Only reset MMU when necessarySheng Yang2010-08-011-2/+14
| | | | | | | | | | | | | | | | | | | | | | | | | | | Only modifying some bits of CR0/CR4 needs paging mode switch. Modify EFER.NXE bit would result in reserved bit updates. Signed-off-by: Sheng Yang <sheng@linux.intel.com> Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
* | | KVM: x86: Clean up duplicate assignmentSheng Yang2010-08-011-3/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | mmu.free() already set root_hpa to INVALID_PAGE, no need to do it again in the destory_kvm_mmu(). kvm_x86_ops->set_cr4() and set_efer() already assign cr4/efer to vcpu->arch.cr4/efer, no need to do it again later. Signed-off-by: Sheng Yang <sheng@linux.intel.com> Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
* | | KVM: inject #UD if instruction emulation fails and exit to userspaceGleb Natapov2010-08-011-25/+18
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Do not kill VM when instruction emulation fails. Inject #UD and report failure to userspace instead. Userspace may choose to reenter guest if vcpu is in userspace (cpl == 3) in which case guest OS will kill offending process and continue running. Signed-off-by: Gleb Natapov <gleb@redhat.com> Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
* | | KVM: Get rid of KVM_REQ_KICKAvi Kivity2010-08-011-7/+10
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | KVM_REQ_KICK poisons vcpu->requests by having a bit set during normal operation. This causes the fast path check for a clear vcpu->requests to fail all the time, triggering tons of atomic operations. Fix by replacing KVM_REQ_KICK with a vcpu->guest_mode atomic. Signed-off-by: Avi Kivity <avi@redhat.com>
* | | KVM: x86 emulator: do not inject exception directly into vcpuGleb Natapov2010-08-011-3/+17
| | | | | | | | | | | | | | | | | | | | | | | | Return exception as a result of instruction emulation and handle injection in KVM code. Signed-off-by: Gleb Natapov <gleb@redhat.com> Signed-off-by: Avi Kivity <avi@redhat.com>
* | | KVM: x86 emulator: move interruptibility state tracking out of emulatorGleb Natapov2010-08-011-3/+17
| | | | | | | | | | | | | | | | | | | | | Emulator shouldn't access vcpu directly. Signed-off-by: Gleb Natapov <gleb@redhat.com> Signed-off-by: Avi Kivity <avi@redhat.com>
* | | KVM: x86 emulator: handle shadowed registers outside emulatorGleb Natapov2010-08-011-2/+12
| | | | | | | | | | | | | | | | | | | | | Emulator shouldn't access vcpu directly. Signed-off-by: Gleb Natapov <gleb@redhat.com> Signed-off-by: Avi Kivity <avi@redhat.com>
* | | KVM: x86 emulator: set RFLAGS outside x86 emulator codeGleb Natapov2010-08-011-6/+1
| | | | | | | | | | | | | | | | | | | | | Removes the need for set_flags() callback. Signed-off-by: Gleb Natapov <gleb@redhat.com> Signed-off-by: Avi Kivity <avi@redhat.com>
* | | KVM: x86 emulator: advance RIP outside x86 emulator codeGleb Natapov2010-08-011-0/+2
| | | | | | | | | | | | | | | | | | | | | | | | Return new RIP as part of instruction emulation result instead of updating KVM's RIP from x86 emulator code. Signed-off-by: Gleb Natapov <gleb@redhat.com> Signed-off-by: Avi Kivity <avi@redhat.com>
* | | KVM: handle emulation failure case firstGleb Natapov2010-08-011-16/+15
| | | | | | | | | | | | | | | | | | | | | If emulation failed return immediately. Signed-off-by: Gleb Natapov <gleb@redhat.com> Signed-off-by: Avi Kivity <avi@redhat.com>
* | | KVM: do not inject #PF in (read|write)_emulated() callbacksGleb Natapov2010-08-011-14/+14
| | | | | | | | | | | | | | | | | | | | | Return error to x86 emulator instead of injection exception behind its back. Signed-off-by: Gleb Natapov <gleb@redhat.com> Signed-off-by: Avi Kivity <avi@redhat.com>
* | | KVM: remove export of emulator_write_emulated()Gleb Natapov2010-08-011-1/+0
| | | | | | | | | | | | | | | | | | | | | It is not called directly outside of the file it's defined in anymore. Signed-off-by: Gleb Natapov <gleb@redhat.com> Signed-off-by: Avi Kivity <avi@redhat.com>
* | | KVM: x86 emulator: x86_emulate_insn() return -1 only in case of emulation ↵Gleb Natapov2010-08-011-18/+18
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | failure Currently emulator returns -1 when emulation failed or IO is needed. Caller tries to guess whether emulation failed by looking at other variables. Make it easier for caller to recognise error condition by always returning -1 in case of failure. For this new emulator internal return value X86EMUL_IO_NEEDED is introduced. It is used to distinguish between error condition (which returns X86EMUL_UNHANDLEABLE) and condition that requires IO exit to userspace to continue emulation. Signed-off-by: Gleb Natapov <gleb@redhat.com> Signed-off-by: Avi Kivity <avi@redhat.com>
* | | KVM: fill in run->mmio details in (read|write)_emulated functionGleb Natapov2010-08-011-16/+9
| | | | | | | | | | | | | | | | | | | | | | | | | | | Fill in run->mmio details in (read|write)_emulated function just like pio does. There is no point in filling only vcpu fields there just to copy them into vcpu->run a little bit later. Signed-off-by: Gleb Natapov <gleb@redhat.com> Signed-off-by: Avi Kivity <avi@redhat.com>
* | | KVM: x86 emulator: make (get|set)_dr() callback return error if it failsGleb Natapov2010-08-011-26/+37
| | | | | | | | | | | | | | | | | | | | | | | | Make (get|set)_dr() callback return error if it fails instead of injecting exception behind emulator's back. Signed-off-by: Gleb Natapov <gleb@redhat.com> Signed-off-by: Avi Kivity <avi@redhat.com>
* | | KVM: x86 emulator: make set_cr() callback return error if it failsGleb Natapov2010-08-011-73/+75
| | | | | | | | | | | | | | | | | | | | | | | | Make set_cr() callback return error if it fails instead of injecting #GP behind emulator's back. Signed-off-by: Gleb Natapov <gleb@redhat.com> Signed-off-by: Avi Kivity <avi@redhat.com>
* | | KVM: x86 emulator: add get_cached_segment_base() callback to x86_emulate_opsGleb Natapov2010-08-011-0/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | | On VMX it is expensive to call get_cached_descriptor() just to get segment base since multiple vmcs_reads are done instead of only one. Introduce new call back get_cached_segment_base() for efficiency. Signed-off-by: Gleb Natapov <gleb@redhat.com> Signed-off-by: Avi Kivity <avi@redhat.com>
* | | KVM: x86 emulator: add (set|get)_msr callbacks to x86_emulate_opsGleb Natapov2010-08-011-0/+2
| | | | | | | | | | | | | | | | | | | | | | | | Add (set|get)_msr callbacks to x86_emulate_ops instead of calling them directly. Signed-off-by: Gleb Natapov <gleb@redhat.com> Signed-off-by: Avi Kivity <avi@redhat.com>
* | | KVM: x86 emulator: add (set|get)_dr callbacks to x86_emulate_opsGleb Natapov2010-08-011-6/+6
| | | | | | | | | | | | | | | | | | | | | | | | Add (set|get)_dr callbacks to x86_emulate_ops instead of calling them directly. Signed-off-by: Gleb Natapov <gleb@redhat.com> Signed-off-by: Avi Kivity <avi@redhat.com>
OpenPOWER on IntegriCloud