aboutsummaryrefslogtreecommitdiffstats
Commit message (Collapse)AuthorAge
* KVM: MMU: fix regression from rework mmu_shrink() codeXiaotian Feng2010-10-24
| | | | | | | | | | | | | | | | | Latest kvm mmu_shrink code rework makes kernel changes kvm->arch.n_used_mmu_pages/ kvm->arch.n_max_mmu_pages at kvm_mmu_free_page/kvm_mmu_alloc_page, which is called by kvm_mmu_commit_zap_page. So the kvm->arch.n_used_mmu_pages or kvm_mmu_available_pages(vcpu->kvm) is unchanged after kvm_mmu_prepare_zap_page(), This caused kvm_mmu_change_mmu_pages/__kvm_mmu_free_some_pages loops forever. Moving kvm_mmu_commit_zap_page would make the while loop performs as normal. Reported-by: Avi Kivity <avi@redhat.com> Signed-off-by: Xiaotian Feng <dfeng@redhat.com> Tested-by: Avi Kivity <avi@redhat.com> Cc: Marcelo Tosatti <mtosatti@redhat.com> Cc: Dave Hansen <dave@linux.vnet.ibm.com> Cc: Tim Pepper <lnxninja@linux.vnet.ibm.com> Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
* KVM: x86 emulator: add JrCXZ instruction emulationWei Yongjun2010-10-24
| | | | | | | | Add JrCXZ instruction emulation (opcode 0xe3) Used by FreeBSD boot loader. Signed-off-by: Wei Yongjun <yjwei@cn.fujitsu.com> Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
* KVM: x86 emulator: add LDS/LES/LFS/LGS/LSS instruction emulationWei Yongjun2010-10-24
| | | | | | | | Add LDS/LES/LFS/LGS/LSS instruction emulation. (opcode 0xc4, 0xc5, 0x0f 0xb2, 0x0f 0xb4~0xb5) Signed-off-by: Wei Yongjun <yjwei@cn.fujitsu.com> Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
* KVM: create aggregate kvm_total_used_mmu_pages valueDave Hansen2010-10-24
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Of slab shrinkers, the VM code says: * Note that 'shrink' will be passed nr_to_scan == 0 when the VM is * querying the cache size, so a fastpath for that case is appropriate. and it *means* it. Look at how it calls the shrinkers: nr_before = (*shrinker->shrink)(0, gfp_mask); shrink_ret = (*shrinker->shrink)(this_scan, gfp_mask); So, if you do anything stupid in your shrinker, the VM will doubly punish you. The mmu_shrink() function takes the global kvm_lock, then acquires every VM's kvm->mmu_lock in sequence. If we have 100 VMs, then we're going to take 101 locks. We do it twice, so each call takes 202 locks. If we're under memory pressure, we can have each cpu trying to do this. It can get really hairy, and we've seen lock spinning in mmu_shrink() be the dominant entry in profiles. This is guaranteed to optimize at least half of those lock aquisitions away. It removes the need to take any of the locks when simply trying to count objects. A 'percpu_counter' can be a large object, but we only have one of these for the entire system. There are not any better alternatives at the moment, especially ones that handle CPU hotplug. Signed-off-by: Dave Hansen <dave@linux.vnet.ibm.com> Signed-off-by: Tim Pepper <lnxninja@linux.vnet.ibm.com> Signed-off-by: Avi Kivity <avi@redhat.com>
* KVM: replace x86 kvm n_free_mmu_pages with n_used_mmu_pagesDave Hansen2010-10-24
| | | | | | | | | | | | | | | | | | | | | | Doing this makes the code much more readable. That's borne out by the fact that this patch removes code. "used" also happens to be the number that we need to return back to the slab code when our shrinker gets called. Keeping this value as opposed to free makes the next patch simpler. So, 'struct kvm' is kzalloc()'d. 'struct kvm_arch' is a structure member (and not a pointer) of 'struct kvm'. That means they start out zeroed. I _think_ they get initialized properly by kvm_mmu_change_mmu_pages(). But, that only happens via kvm ioctls. Another benefit of storing 'used' intead of 'free' is that the values are consistent from the moment the structure is allocated: no negative "used" value. Signed-off-by: Dave Hansen <dave@linux.vnet.ibm.com> Signed-off-by: Tim Pepper <lnxninja@linux.vnet.ibm.com> Signed-off-by: Avi Kivity <avi@redhat.com>
* KVM: rename x86 kvm->arch.n_alloc_mmu_pagesDave Hansen2010-10-24
| | | | | | | | | | | | | | | arch.n_alloc_mmu_pages is a poor choice of name. This value truly means, "the number of pages which _may_ be allocated". But, reading the name, "n_alloc_mmu_pages" implies "the number of allocated mmu pages", which is dead wrong. It's really the high watermark, so let's give it a name to match: nr_max_mmu_pages. This change will make the next few patches much more obvious and easy to read. Signed-off-by: Dave Hansen <dave@linux.vnet.ibm.com> Signed-off-by: Tim Pepper <lnxninja@linux.vnet.ibm.com> Signed-off-by: Avi Kivity <avi@redhat.com>
* KVM: abstract kvm x86 mmu->n_free_mmu_pagesDave Hansen2010-10-24
| | | | | | | | | | | | | | | | | | | | "free" is a poor name for this value. In this context, it means, "the number of mmu pages which this kvm instance should be able to allocate." But "free" implies much more that the objects are there and ready for use. "available" is a much better description, especially when you see how it is calculated. In this patch, we abstract its use into a function. We'll soon replace the function's contents by calculating the value in a different way. All of the reads of n_free_mmu_pages are taken care of in this patch. The modification sites will be handled in a patch later in the series. Signed-off-by: Dave Hansen <dave@linux.vnet.ibm.com> Signed-off-by: Tim Pepper <lnxninja@linux.vnet.ibm.com> Signed-off-by: Avi Kivity <avi@redhat.com>
* KVM: x86 emulator: implement CWD (opcode 99)Avi Kivity2010-10-24
| | | | Signed-off-by: Avi Kivity <avi@redhat.com>
* KVM: x86 emulator: implement IMUL REG, R/M, IMM (opcode 69)Avi Kivity2010-10-24
| | | | Signed-off-by: Avi Kivity <avi@redhat.com>
* KVM: x86 emulator: add Src2Imm decodingAvi Kivity2010-10-24
| | | | | | Needed for 3-operand IMUL. Signed-off-by: Avi Kivity <avi@redhat.com>
* KVM: x86 emulator: consolidate immediate decode into a functionAvi Kivity2010-10-24
| | | | Signed-off-by: Avi Kivity <avi@redhat.com>
* KVM: x86 emulator: implement RDTSC (opcode 0F 31)Avi Kivity2010-10-24
| | | | Signed-off-by: Avi Kivity <avi@redhat.com>
* KVM: x86 emulator: remove SrcImplicitAvi Kivity2010-10-24
| | | | | | Useless. Signed-off-by: Avi Kivity <avi@redhat.com>
* KVM: x86 emulator: implement IMUL REG, R/M (opcode 0F AF)Avi Kivity2010-10-24
| | | | Signed-off-by: Avi Kivity <avi@redhat.com>
* KVM: x86 emulator: implement IMUL REG, R/M, imm8 (opcode 6B)Avi Kivity2010-10-24
| | | | Signed-off-by: Avi Kivity <avi@redhat.com>
* KVM: x86 emulator: implement RET imm16 (opcode C2)Avi Kivity2010-10-24
| | | | Signed-off-by: Avi Kivity <avi@redhat.com>
* KVM: x86 emulator: add SrcImmU16 operand typeAvi Kivity2010-10-24
| | | | | | Used for RET NEAR instructions. Signed-off-by: Avi Kivity <avi@redhat.com>
* KVM: x86 emulator: implement CALL FAR (FF /3)Avi Kivity2010-10-24
| | | | Signed-off-by: Avi Kivity <avi@redhat.com>
* KVM: x86 emulator: implement DAS (opcode 2F)Avi Kivity2010-10-24
| | | | Signed-off-by: Avi Kivity <avi@redhat.com>
* KVM: x86 emulator: Use a register for ____emulate_2op() destinationAvi Kivity2010-10-24
| | | | | | | | | Most x86 two operand instructions allow the destination to be a memory operand, but IMUL (for example) requires that the destination be a register. Change ____emulate_2op() to take a register for both source and destination so we can invoke IMUL. Signed-off-by: Avi Kivity <avi@redhat.com>
* KVM: x86 emulator: pass destination type to ____emulate_2op()Avi Kivity2010-10-24
| | | | | | We'll need it later so we can use a register for the destination. Signed-off-by: Avi Kivity <avi@redhat.com>
* KVM: x86 emulator: add LOOP/LOOPcc instruction emulationWei Yongjun2010-10-24
| | | | | | | Add LOOP/LOOPcc instruction emulation (opcode 0xe0~0xe2). Signed-off-by: Wei Yongjun <yjwei@cn.fujitsu.com> Signed-off-by: Avi Kivity <avi@redhat.com>
* KVM: x86 emulator: add CBW/CWDE/CDQE instruction emulationWei Yongjun2010-10-24
| | | | | | | | Add CBW/CWDE/CDQE instruction emulation.(opcode 0x98) Used by FreeBSD's boot loader. Signed-off-by: Wei Yongjun <yjwei@cn.fujitsu.com> Signed-off-by: Avi Kivity <avi@redhat.com>
* KVM: x86 emulator: fix REPZ/REPNZ termination conditionAvi Kivity2010-10-24
| | | | | | EFLAGS.ZF needs to be checked after each iteration, not before. Signed-off-by: Avi Kivity <avi@redhat.com>
* KVM: x86 emulator: implement SCAS (opcodes AE, AF)Avi Kivity2010-10-24
| | | | Signed-off-by: Avi Kivity <avi@redhat.com>
* KVM: x86 emulator: fix INTn emulation not pushing EFLAGS and CSAvi Kivity2010-10-24
| | | | | | | emulate_push() only schedules a push; it doesn't actually push anything. Call writeback() to flush out the write. Signed-off-by: Avi Kivity <avi@redhat.com>
* KVM: x86 emulator: remove dup code of in/out instructionWei Yongjun2010-10-24
| | | | | Signed-off-by: Wei Yongjun <yjwei@cn.fujitsu.com> Signed-off-by: Avi Kivity <avi@redhat.com>
* KVM: x86 emulator: change OUT instruction to use dst instead of srcWei Yongjun2010-10-24
| | | | | | | | Change OUT instruction to use dst instead of src, so we can reuse those code for all out instructions. Signed-off-by: Wei Yongjun <yjwei@cn.fujitsu.com> Signed-off-by: Avi Kivity <avi@redhat.com>
* KVM: x86 emulator: introduce DstImmUByte for dst operand decodeWei Yongjun2010-10-24
| | | | | | | | Introduce DstImmUByte for dst operand decode, which will be used for out instruction. Signed-off-by: Wei Yongjun <yjwei@cn.fujitsu.com> Signed-off-by: Avi Kivity <avi@redhat.com>
* KVM: x86 emulator: remove useless label from x86_emulate_insn()Wei Yongjun2010-10-24
| | | | | Signed-off-by: Wei Yongjun <yjwei@cn.fujitsu.com> Signed-off-by: Avi Kivity <avi@redhat.com>
* KVM: x86 emulator: add setcc instruction emulationWei Yongjun2010-10-24
| | | | | | | Add setcc instruction emulation (opcode 0x0f 0x90~0x9f) Signed-off-by: Wei Yongjun <yjwei@cn.fujitsu.com> Signed-off-by: Avi Kivity <avi@redhat.com>
* KVM: x86: explain 'no-kvmclock' kernel parameterJiri Kosina2010-10-24
| | | | | | | | no-kvmclock kernel parameter is missing its explanation in Documentation/kernel-parameters.txt. Add it. Signed-off-by: Jiri Kosina <jkosina@suse.cz> Signed-off-by: Avi Kivity <avi@redhat.com>
* KVM: x86 emulator: add XADD instruction emulationWei Yongjun2010-10-24
| | | | | | | Add XADD instruction emulation (opcode 0x0f 0xc0~0xc1) Signed-off-by: Wei Yongjun <yjwei@cn.fujitsu.com> Signed-off-by: Avi Kivity <avi@redhat.com>
* KVM: x86 emulator: put register operand write back to a functionWei Yongjun2010-10-24
| | | | | | | | Introduce function write_register_operand() to write back the register operand. Signed-off-by: Wei Yongjun <yjwei@cn.fujitsu.com> Signed-off-by: Avi Kivity <avi@redhat.com>
* KVM: PPC: fix leakage of error page in kvmppc_patch_dcbz()Wei Yongjun2010-10-24
| | | | | | | | Add kvm_release_page_clean() after is_error_page() to avoid leakage of error page. Signed-off-by: Wei Yongjun <yjwei@cn.fujitsu.com> Signed-off-by: Avi Kivity <avi@redhat.com>
* KVM: Separate emulation context initialization in a separate functionMohammed Gamal2010-10-24
| | | | | | | | | The code for initializing the emulation context is duplicated at two locations (emulate_instruction() and kvm_task_switch()). Separate it in a separate function and call it from there. Signed-off-by: Mohammed Gamal <m.gamal005@gmail.com> Signed-off-by: Avi Kivity <avi@redhat.com>
* KVM: x86 emulator: add bsf/bsr instruction emulationWei Yongjun2010-10-24
| | | | | | | Add bsf/bsr instruction emulation (opcode 0x0f 0xbc~0xbd) Signed-off-by: Wei Yongjun <yjwei@cn.fujitsu.com> Signed-off-by: Avi Kivity <avi@redhat.com>
* KVM: x86 emulator: Fix emulate_grp3 return valuesMohammed Gamal2010-10-24
| | | | | | | | This patch lets emulate_grp3() return X86EMUL_* return codes instead of hardcoded ones. Signed-off-by: Mohammed Gamal <m.gamal005@gmail.com> Signed-off-by: Avi Kivity <avi@redhat.com>
* KVM: x86 emulator: Add unary mul, imul, div, and idiv instructionsMohammed Gamal2010-10-24
| | | | | | | This adds unary mul, imul, div, and idiv instructions (group 3 r/m 4-7). Signed-off-by: Mohammed Gamal <m.gamal005@gmail.com> Signed-off-by: Avi Kivity <avi@redhat.com>
* KVM: x86 emulator: mask group 8 instruction as BitOpWei Yongjun2010-10-24
| | | | | | | | | Mask group 8 instruction as BitOp, so we can share the code for adjust the source operand. Signed-off-by: Wei Yongjun <yjwei@cn.fujitsu.com> Reviewed-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Avi Kivity <avi@redhat.com>
* KVM: x86 emulator: do not adjust the address for immediate sourceWei Yongjun2010-10-24
| | | | | | | | | adjust the dst address for a register source but not adjust the address for an immediate source. Signed-off-by: Wei Yongjun <yjwei@cn.fujitsu.com> Reviewed-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Avi Kivity <avi@redhat.com>
* KVM: x86 emulator: fix negative bit offset BitOp instruction emulationWei Yongjun2010-10-24
| | | | | | | | | If bit offset operands is a negative number, BitOp instruction will return wrong value. This patch fix it. Signed-off-by: Wei Yongjun <yjwei@cn.fujitsu.com> Reviewed-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Avi Kivity <avi@redhat.com>
* KVM: x86 emulator: Add stc instruction (opcode 0xf9)Mohammed Gamal2010-10-24
| | | | | Signed-off-by: Mohammed Gamal <m.gamal005@gmail.com> Signed-off-by: Avi Kivity <avi@redhat.com>
* KVM: x86 emulator: using SrcOne for instruction d0/d1 decodingWei Yongjun2010-10-24
| | | | | | | Using SrcOne for instruction d0/d1 decoding. Signed-off-by: Wei Yongjun <yjwei@cn.fujitsu.com> Signed-off-by: Avi Kivity <avi@redhat.com>
* KVM: x86 emulator: disable writeback when decode dest operandWei Yongjun2010-10-24
| | | | | | | | This patch change to disable writeback when decode dest operand if the dest type is ImplicitOps or not specified. Signed-off-by: Wei Yongjun <yjwei@cn.fujitsu.com> Signed-off-by: Avi Kivity <avi@redhat.com>
* KVM: x86 emulator: use SrcAcc to simplify stos decodingWei Yongjun2010-10-24
| | | | | | | Use SrcAcc to simplify stos decoding. Signed-off-by: Wei Yongjun <yjwei@cn.fujitsu.com> Signed-off-by: Avi Kivity <avi@redhat.com>
* KVM: x86 emulator: Add into, int, and int3 instructions (opcodes 0xcc-0xce)Mohammed Gamal2010-10-24
| | | | | | | This adds support for int instructions to the emulator. Signed-off-by: Mohammed Gamal <m.gamal005@gmail.com> Signed-off-by: Avi Kivity <avi@redhat.com>
* KVM: x86 emulator: Allow accessing IDT via emulator opsMohammed Gamal2010-10-24
| | | | | | | | | | | The patch adds a new member get_idt() to x86_emulate_ops. It also adds a function to get the idt in order to be used by the emulator. This is needed for real mode interrupt injection and the emulation of int instructions. Signed-off-by: Mohammed Gamal <m.gamal005@gmail.com> Signed-off-by: Avi Kivity <avi@redhat.com>
* KVM: x86 emulator: simplify two-byte opcode checkWei Yongjun2010-10-24
| | | | | | | | Two-byte opcode always start with 0x0F and the decode flags of opcode 0xF0 is always 0, so remove dup check. Signed-off-by: Wei Yongjun <yjwei@cn.fujitsu.com> Signed-off-by: Avi Kivity <avi@redhat.com>
* KVM: PPC: Move KVM trampolines before __end_interruptsAlexander Graf2010-10-24
| | | | | | | | | | | | When using a relocatable kernel we need to make sure that the trampline code and the interrupt handlers are both copied to low memory. The only way to do this reliably is to put them in the copied section. This patch should make relocated kernels work with KVM. KVM-Stable-Tag Signed-off-by: Alexander Graf <agraf@suse.de> Signed-off-by: Avi Kivity <avi@redhat.com>