summaryrefslogtreecommitdiffstats
Commit message (Collapse)AuthorAgeFilesLines
* KVM: Flush remote tlbs when reducing shadow pte permissionsAvi Kivity2007-07-165-15/+84
| | | | | | | | | | | When a vcpu causes a shadow tlb entry to have reduced permissions, it must also clear the tlb on remote vcpus. We do that by: - setting a bit on the vcpu that requests a tlb flush before the next entry - if the vcpu is currently executing, we send an ipi to make sure it exits before we continue Signed-off-by: Avi Kivity <avi@qumranet.com>
* KVM: Keep an upper bound of initialized vcpusAvi Kivity2007-07-162-0/+6
| | | | | | | That way, we don't need to loop for KVM_MAX_VCPUS for a single vcpu vm. Signed-off-by: Avi Kivity <avi@qumranet.com>
* KVM: Emulate hlt on real mode for IntelAvi Kivity2007-07-163-2/+12
| | | | | | | This has two use cases: the bios can't boot from disk, and guest smp bootstrap. Signed-off-by: Avi Kivity <avi@qumranet.com>
* KVM: Move duplicate halt handling code into kvm_main.cAvi Kivity2007-07-164-12/+14
| | | | | | Will soon have a thid user. Signed-off-by: Avi Kivity <avi@qumranet.com>
* KVM: Enable guest smpAvi Kivity2007-07-161-1/+1
| | | | | | | As we don't support guest tlb shootdown yet, this is only reliable for real-mode guests. Signed-off-by: Avi Kivity <avi@qumranet.com>
* KVM: Fix adding an smp virtual machine to the vm listAvi Kivity2007-07-161-3/+3
| | | | | | | If we add the vm once per vcpu, we corrupt the list if the guest has multiple vcpus. Signed-off-by: Avi Kivity <avi@qumranet.com>
* KVM: Fix vcpu freeing for guest smpAvi Kivity2007-07-162-2/+17
| | | | | | | | A vcpu can pin up to four mmu shadow pages, which means the freeing loop will never terminate. Fix by first unpinning shadow pages on all vcpus, then freeing shadow pages. Signed-off-by: Avi Kivity <avi@qumranet.com>
* KVM: Remove unnecessary initialization and checks in mark_page_dirty()Nguyen Anh Quynh2007-07-161-2/+2
| | | | Signed-off-by: Avi Kivity <avi@qumranet.com>
* KVM: Replace C code with call to ARRAY_SIZE() macro.Robert P. J. Day2007-07-161-1/+1
| | | | | Signed-off-by: Robert P. J. Day <rpjday@mindspring.com> Signed-off-by: Avi Kivity <avi@qumranet.com>
* KVM: Lazy guest cr3 switchingAvi Kivity2007-07-164-21/+40
| | | | | | | | | Switch guest paging context may require us to allocate memory, which might fail. Instead of wiring up error paths everywhere, make context switching lazy and actually do the switch before the next guest entry, where we can return an error if allocation fails. Signed-off-by: Avi Kivity <avi@qumranet.com>
* KVM: MMU: Remove unused large page markerAvi Kivity2007-07-162-3/+0
| | | | | | | This has not been used for some time, as the same information is available in the page header. Signed-off-by: Avi Kivity <avi@qumranet.com>
* KVM: MMU: Don't cache guest access bits in the shadow page tableAvi Kivity2007-07-162-9/+0
| | | | | | | | | This was once used to avoid accessing the guest pte when upgrading the shadow pte from read-only to read-write. But usually we need to set the guest pte dirty or accessed bits anyway, so this wasn't really exploited. Signed-off-by: Avi Kivity <avi@qumranet.com>
* KVM: MMU: Simpify accessed/dirty/present/nx bit handlingAvi Kivity2007-07-162-10/+2
| | | | | | | | Always set the accessed and dirty bit (since having them cleared causes a read-modify-write cycle), always set the present bit, and copy the nx bit from the guest. Signed-off-by: Avi Kivity <avi@qumranet.com>
* KVM: MMU: Remove cr0.wp tricksAvi Kivity2007-07-161-11/+0
| | | | | | No longer needed as we do everything in one place. Signed-off-by: Avi Kivity <avi@qumranet.com>
* KVM: MMU: Make setting shadow ptes atomic on i386Avi Kivity2007-07-163-4/+15
| | | | Signed-off-by: Avi Kivity <avi@qumranet.com>
* KVM: Make shadow pte updates atomicAvi Kivity2007-07-161-17/+20
| | | | | | | | | | | With guest smp, a second vcpu might see partial updates when the first vcpu services a page fault. So delay all updates until we have figured out what the pte should look like. Note that on i386, this is still not completely atomic as a 64-bit write will be split into two on a 32-bit machine. Signed-off-by: Avi Kivity <avi@qumranet.com>
* KVM: Move shadow pte modifications from set_pte/set_pde to set_pde_common()Avi Kivity2007-07-161-2/+1
| | | | | | We want all shadow pte modifications in one place. Signed-off-by: Avi Kivity <avi@qumranet.com>
* KVM: MMU: Fold fix_write_pf() into set_pte_common()Avi Kivity2007-07-162-111/+68
| | | | | | | This prevents some work from being performed twice, and, more importantly, reduces the number of places where we modify shadow ptes. Signed-off-by: Avi Kivity <avi@qumranet.com>
* KVM: MMU: Fold fix_read_pf() into set_pte_common()Avi Kivity2007-07-162-28/+23
| | | | Signed-off-by: Avi Kivity <avi@qumranet.com>
* KVM: MMU: Pass the guest pde to set_pte_commonAvi Kivity2007-07-161-14/+15
| | | | | | | We will need the accessed bit (in addition to the dirty bit) and also write access (for setting the dirty bit) in a future patch. Signed-off-by: Avi Kivity <avi@qumranet.com>
* KVM: MMU: Move set_pte_common() to pte width dependent codeAvi Kivity2007-07-162-52/+52
| | | | | | In preparation of some modifications. Signed-off-by: Avi Kivity <avi@qumranet.com>
* KVM: MMU: Simplify fetch() a little bitAvi Kivity2007-07-161-17/+17
| | | | Signed-off-by: Avi Kivity <avi@qumranet.com>
* KVM: MMU: Use slab caches for shadow pages and their headersAvi Kivity2007-07-163-28/+41
| | | | | | Use slab caches instead of a simple custom list. Signed-off-by: Avi Kivity <avi@qumranet.com>
* KVM: Use symbolic constants instead of magic numbersEddie Dong2007-07-161-1/+1
| | | | Signed-off-by: Avi Kivity <avi@qumranet.com>
* KVM: Fix includesMarkus Rechberger2007-07-161-0/+2
| | | | | | | KVM compilation fails for some .configs. This fixes it. Signed-off-by: Markus Rechberger <markus.rechberger@amd.com> Signed-off-by: Avi Kivity <avi@qumranet.com>
* KVM: x86 emulator: implement wbinvdAvi Kivity2007-07-161-1/+3
| | | | | | Vista seems to trigger it. Signed-off-by: Avi Kivity <avi@qumranet.com>
* Use menuconfig objects II - KVM/VirtJan Engelhardt2007-07-161-2/+6
| | | | | | | | | | Make a "menuconfig" out of the Kconfig objects "menu, ..., endmenu", so that the user can disable all the options in that menu at once instead of having to disable each option separately. Signed-off-by: Jan Engelhardt <jengelh@gmx.de> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Avi Kivity <avi@qumranet.com>
* KVM: VMX: Avoid saving and restoring msr_efer on lightweight vmexitEddie Dong2007-07-163-21/+71
| | | | | | | | | | | | | | | | | | | MSR_EFER.LME/LMA bits are automatically save/restored by VMX hardware, KVM only needs to save NX/SCE bits at time of heavy weight VM Exit. But clearing NX bits in host envirnment may cause system hang if the host page table is using EXB bits, thus we leave NX bits as it is. If Host NX=1 and guest NX=0, we can do guest page table EXB bits check before inserting a shadow pte (though no guest is expecting to see this kind of gp fault). If host NX=0, we present guest no Execute-Disable feature to guest, thus no host NX=0, guest NX=1 combination. This patch reduces raw vmexit time by ~27%. Me: fix compile warnings on i386. Signed-off-by: Yaozu (Eddie) Dong <eddie.dong@intel.com> Signed-off-by: Avi Kivity <avi@qumranet.com>
* KVM: VMX: Cleanup redundant code in MSR setEddie Dong2007-07-161-2/+0
| | | | | Signed-off-by: Yaozu (Eddie) Dong <eddie.dong@intel.com> Signed-off-by: Avi Kivity <avi@qumranet.com>
* KVM: VMX: Avoid saving and restoring msrs on lightweight vmexitEddie Dong2007-07-162-56/+76
| | | | | | | | | | | | In a lightweight exit (where we exit and reenter the guest without scheduling or exiting to userspace in between), we don't need various msrs on the host, and avoiding shuffling them around reduces raw exit time by 8%. i386 compile fix by Daniel Hecken <dh@bahntechnik.de>. Signed-off-by: Yaozu (Eddie) Dong <eddie.dong@intel.com> Signed-off-by: Avi Kivity <avi@qumranet.com>
* KVM: VMX: Handle #SS faults from real modeNitin A Kamble2007-07-161-1/+5
| | | | | | | | | Instructions with address size override prefix opcode 0x67 Cause the #SS fault with 0 error code in VM86 mode. Forward them to the emulator. Signed-Off-By: Nitin A Kamble <nitin.a.kamble@intel.com> Signed-off-by: Avi Kivity <avi@qumranet.com>
* KVM: VMX: Use local labels in inline assemblyAvi Kivity2007-07-161-8/+7
| | | | | | This makes oprofile dumps and disassebly easier to read. Signed-off-by: Avi Kivity <avi@qumranet.com>
* KVM: Fix vmx I/O bitmap initialization on highmem systemsAvi Kivity2007-07-161-2/+2
| | | | | | | | | kunmap() expects a struct page, not a virtual address. Fixes an oops loading kvm-intel.ko on i386 with CONFIG_HIGHMEM. Thanks to Michael Ivanov <deruhu@peterstar.ru> for reporting. Signed-off-by: Avi Kivity <avi@qumranet.com>
* KVM: Avoid corrupting tr in real modeAvi Kivity2007-07-161-14/+31
| | | | | | | | | | | | The real mode tr needs to be set to a specific tss so that I/O instructions can function. Divert the new tr values to the real mode save area from where they will be restored on transition to protected mode. This fixes some crashes on reboot when the bios accesses an I/O instruction. Signed-off-by: Avi Kivity <avi@qumranet.com>
* KVM: VMX: Only reload guest msrs if they are already loadedAvi Kivity2007-07-161-1/+2
| | | | | | | | | | If we set an msr via an ioctl() instead of by handling a guest exit, we have the host state loaded, so reloading the msrs would clobber host state instead of guest state. This fixes a host oops (and loss of a cpu) on a guest reboot. Signed-off-by: Avi Kivity <avi@qumranet.com>
* KVM: MMU: Store shadow page tables as kernel virtual addresses, not physicalAvi Kivity2007-07-163-19/+17
| | | | | | Simpifies things a bit. Signed-off-by: Avi Kivity <avi@qumranet.com>
* KVM: MMU: Simplify kvm_mmu_free_page() a tiny bitAvi Kivity2007-07-161-6/+4
| | | | Signed-off-by: Avi Kivity <avi@qumranet.com>
* KVM: Implement IA32_EBL_CR_POWERON msrMatthew Gregan2007-07-161-0/+1
| | | | | | | | | | | | | | Attempting to boot the default 'bsd' kernel of OpenBSD 4.1 i386 in a guest fails early in the kernel init inside p3_get_bus_clock while trying to read the IA32_EBL_CR_POWERON MSR. KVM logs an 'unhandled MSR' message and the guest kernel faults. This patch is sufficient to allow OpenBSD to boot, after which it seems to run fine. I'm not sure if this is the correct solution for dealing with this particular MSR, but it works for me. Signed-off-by: Matthew Gregan <kinetik@flim.org> Signed-off-by: Avi Kivity <avi@qumranet.com>
* KVM: Set cr0.mp for guestsAvi Kivity2007-07-161-1/+3
| | | | | | | This allows fwait instructions to be trapped when the guest fpu is not loaded. Signed-off-by: Avi Kivity <avi@qumranet.com>
* KVM: Consolidate guest fpu activation and deactivationAvi Kivity2007-07-162-20/+32
| | | | | | Easier to keep track of where the fpu is this way. Signed-off-by: Avi Kivity <avi@qumranet.com>
* KVM: Rationalize exception bitmap usageAvi Kivity2007-07-161-21/+21
| | | | | | | | Everyone owns a piece of the exception bitmap, but they happily write to the entire thing like there's no tomorrow. Centralize handling in update_exception_bitmap() and have everyone call that. Signed-off-by: Avi Kivity <avi@qumranet.com>
* KVM: Move some more msr mangling into vmx_save_host_state()Avi Kivity2007-07-161-7/+7
| | | | Signed-off-by: Avi Kivity <avi@qumranet.com>
* KVM: Fix potential guest state leak into hostAvi Kivity2007-07-162-71/+94
| | | | | | | | | | | The lightweight vmexit path avoids saving and reloading certain host state. However in certain cases lightweight vmexit handling can schedule() which requires reloading the host state. So we store the host state in the vcpu structure, and reloaded it if we relinquish the vcpu. Signed-off-by: Avi Kivity <avi@qumranet.com>
* KVM: Increase mmu shadow cache to 1024 pagesAvi Kivity2007-07-161-1/+1
| | | | | | | This improves kbuild times by about 10%, bringing it within a respectable 25% of native. Signed-off-by: Avi Kivity <avi@qumranet.com>
* KVM: Update shadow pte on write to guest pteAvi Kivity2007-07-162-0/+30
| | | | | | | | | | | | | | | | | | | | A typical demand page/copy on write pattern is: - page fault on vaddr - kvm propagates fault to guest - guest handles fault, updates pte - kvm traps write, clears shadow pte, resumes guest - guest returns to userspace, re-faults on same vaddr - kvm installs shadow pte, resumes guest - guest continues So, three vmexits for a single guest page fault. But if instead of clearing the page table entry, we update to correspond to the value that the guest has just written, we eliminate the third vmexit. This patch does exactly that, reducing kbuild time by about 10%. Signed-off-by: Avi Kivity <avi@qumranet.com>
* KVM: MMU: Respect nonpae pagetable quadrant when zapping ptesAvi Kivity2007-07-161-0/+4
| | | | | | | | | | | | | | | | | | | When a guest writes to a page that has an mmu shadow, we have to clear the shadow pte corresponding to the memory location touched by the guest. Now, in nonpae mode, a single guest page may have two or four shadow pages (because a nonpae page maps 4MB or 4GB, whereas the pae shadow maps 2MB or 1GB), so we when we look up the page we find up to three additional aliases for the page. Since we _clear_ the shadow pte, it doesn't matter except for a slight performance penalty, but if we want to _update_ the shadow pte instead of clearing it, it is vital that we don't modify the aliases. Fortunately, exactly which page is needed (the "quadrant") is easily computed, and is accessible in the shadow page header. All we need is to ignore shadow pages from the wrong quadrants. Signed-off-by: Avi Kivity <avi@qumranet.com>
* KVM: Unify kvm_mmu_pre_write() and kvm_mmu_post_write()Avi Kivity2007-07-163-11/+8
| | | | | | | Instead of calling two functions and repeating expensive checks, call one function and provide it with before/after information. Signed-off-by: Avi Kivity <avi@qumranet.com>
* KVM: Be more careful restoring fs on lightweight vmexitAvi Kivity2007-07-161-11/+11
| | | | | | | | i386 wants fs for accessing the pda even on a lightweight exit, so ensure we can always restore it. This fixes a regression on i386 introduced by the lightweight vmexit patch. Signed-off-by: Avi Kivity <avi@qumranet.com>
* KVM: Reduce misfirings of the fork detectorAvi Kivity2007-07-161-0/+4
| | | | | | | | | | | | | | The kvm mmu tries to detects forks by looking for repeated writes to a page table. If it sees a fork, it unshadows the page table so the page table copying can proceed at native speed instead of being emulated. However, the detector also triggered on simple demand paging access patterns: a linear walk of memory would of course cause repeated writes to the same pagetable page, causing it to unshadow prematurely. Fix by resetting the fork detector if we detect a demand fault. Signed-off-by: Avi Kivity <avi@qumranet.com>
* KVM: Unindent some codeAvi Kivity2007-07-161-29/+29
| | | | Signed-off-by: Avi Kivity <avi@qumranet.com>