summaryrefslogtreecommitdiff
path: root/kvm-all.c
AgeCommit message (Collapse)AuthorFilesLines
2009-12-03kvm: x86: Add support for VCPU event statesJan Kiszka1-0/+11
This patch extends the qemu-kvm state sync logic with support for KVM_GET/SET_VCPU_EVENTS, giving access to yet missing exception, interrupt and NMI states. Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2009-12-03Don't leak file descriptorsKevin Wolf1-1/+1
We're leaking file descriptors to child processes. Set FD_CLOEXEC on file descriptors that don't need to be passed to children to stop this misbehaviour. Signed-off-by: Kevin Wolf <kwolf@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2009-11-17kvm: Add arch reset handlerJan Kiszka1-0/+2
Will be required by succeeding changes. Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2009-11-12kvm: Move KVM mp_state accessors to i386-specific codeHollis Blanchard1-20/+0
Unbreaks PowerPC and S390 KVM builds. Signed-off-by: Hollis Blanchard <hollisb@us.ibm.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2009-10-12unlock iothread mutex before running kvm ioctlGlauber Costa1-0/+2
Without this, kvm will hold the mutex while it issues its run ioctl, and never be able to step out of it, causing a deadlock. Patchworks-ID: 35359 Signed-off-by: Glauber Costa <glommer@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2009-10-05temporary fix for on_vcpuGlauber Costa1-0/+4
Recent changes made on_vcpu hit the abort() path, even with the IO thread disabled. This is because cpu_single_env is no longer set when we call this function. Although the correct fix is a little bit more complicated that that, the recent thread in which I proposed qemu_queue_work (which fixes that, btw), is likely to go on a quite different direction. So for the benefit of those using guest debugging, I'm proposing this simple fix in the interim. Signed-off-by: Glauber Costa <glommer@redhat.com> Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2009-10-05kvm: Fix guest single-steppingJan Kiszka1-1/+7
Hopefully the last regression of 4c0960c0: KVM_SET_GUEST_DEBUG requires properly synchronized guest registers (on x86: eflags) on entry. Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2009-10-01Revert "Get rid of _t suffix"Anthony Liguori1-23/+23
In the very least, a change like this requires discussion on the list. The naming convention is goofy and it causes a massive merge problem. Something like this _must_ be presented on the list first so people can provide input and cope with it. This reverts commit 99a0949b720a0936da2052cb9a46db04ffc6db29. Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2009-10-01Get rid of _t suffixmalc1-23/+23
Some not so obvious bits, slirp and Xen were left alone for the time being. Signed-off-by: malc <av1474@comtv.ru>
2009-09-20ioports: remove unused env parameter and compile only onceBlue Swirl1-9/+9
The CPU state parameter is not used, remove it and adjust callers. Now we can compile ioport.c once for all targets. Signed-off-by: Blue Swirl <blauwirbel@gmail.com>
2009-09-12Fix sys-queue.h conflict for goodBlue Swirl1-6/+6
Problem: Our file sys-queue.h is a copy of the BSD file, but there are some additions and it's not entirely compatible. Because of that, there have been conflicts with system headers on BSD systems. Some hacks have been introduced in the commits 15cc9235840a22c289edbe064a9b3c19c5f49896, f40d753718c72693c5f520f0d9899f6e50395e94, 96555a96d724016e13190b28cffa3bc929ac60dc and 3990d09adf4463eca200ad964cc55643c33feb50 but the fixes were fragile. Solution: Avoid the conflict entirely by renaming the functions and the file. Revert the previous hacks. Signed-off-by: Blue Swirl <blauwirbel@gmail.com>
2009-08-27kvm: Simplify cpu_synchronize_state()Avi Kivity1-0/+14
cpu_synchronize_state() is a little unreadable since the 'modified' argument isn't self-explanatory. Simplify it by making it always synchronize the kernel state into qemu, and automatically flush the registers back to the kernel if they've been synchronized on this exit. Signed-off-by: Avi Kivity <avi@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2009-07-27Revert "Fake dirty loggin when it's not there"Anthony Liguori1-12/+1
This reverts commit bd8367761236cd5c435598aeb2f1b8240c09b059. PPC should just implement dirty logging so we can avoid all the fall-out from this changeset. Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2009-07-27Fix broken buildLuiz Capitulino1-9/+9
The only caller of on_vcpu() is protected by ifdef KVM_CAP_SET_GUEST_DEBUG, so protect on_vcpu() too otherwise QEMU may not to build. Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2009-07-27Use Little Endian for Dirty LogAlexander Graf1-4/+7
We currently use host endian long types to store information in the dirty bitmap. This works reasonably well on Little Endian targets, because the u32 after the first contains the next 32 bits. On Big Endian this breaks completely though, forcing us to be inventive here. So Ben suggested to always use Little Endian, which looks reasonable. We only have dirty bitmap implemented in Little Endian targets so far and since PowerPC would be the first Big Endian platform, we can just as well switch to Little Endian always with little effort without breaking existing targets. This is the userspace part of the patch. It shouldn't change anything for existing targets, but help PowerPC. It replaces my older patch called "Use 64bit pointer for dirty log". Signed-off-by: Alexander Graf <agraf@suse.de> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2009-07-27Use 64bit pointer for dirty logAlexander Graf1-1/+1
Dirty logs currently get written with native "long" size. On little endian it doesn't matter if we use uint64_t instead though, because we'd still end up using the right bytes. On big endian, this does become a bigger problem, so we need to ensure that kernel and userspace talk the same language, which means getting rid of "long" and using a defined size instead. So I decided to use 64 bit types at all times. This doesn't break existing targets but will in conjunction with a patch I'll send to the KVM ML make dirty logs work with 32 bit userspace on 64 kernel with big endian. Signed-off-by: Alexander Graf <agraf@suse.de> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2009-07-22provide tests for pit in kernel and irqchip in kernelGlauber Costa1-0/+13
KVM can have an in-kernel pit or irqchip. While we don't implement it yet, having a way for test for it (that always returns zero) will allow us to reuse code in qemu-kvm that tests for it. Signed-off-by: Glauber Costa <glommer@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2009-07-22introduce on_vcpuGlauber Costa1-6/+29
on_vcpu is a qemu-kvm function that will make sure that a specific piece of code will run on a requested cpu. We don't need that because we're restricted to -smp 1 right now, but those days are likely to end soon. So for the benefit of having qemu-kvm share more code with us, I'm introducing our own version of on_vcpu(). Right now, we either run a function on the current cpu, or abort the execution, because it would mean something is seriously wrong. As an example code, I "ported" kvm_update_guest_debug to use it, with some slight differences from qemu-kvm. This is probably 0.12 material Signed-off-by: Glauber Costa <glommer@redhat.com> CC: Jan Kiszka <jan.kiszka@siemens.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2009-07-22Fake dirty loggin when it's not thereAlexander Graf1-1/+12
Some KVM platforms don't support dirty logging yet, like IA64 and PPC, so in order to still have screen updates on those, we need to fake it. This patch just tells the getter function for dirty bitmaps, that all pages within a slot are dirty when the slot has dirty logging enabled. That way we can implement dirty logging on those platforms sometime when it drags down performance, but share the rest of the code with dirty logging capable platforms. Signed-off-by: Alexander Graf <agraf@suse.de> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2009-07-22Fix warning in kvm-all.cAlexander Graf1-1/+1
This fixes a warning I stumbled across while compiling qemu on PPC64. Signed-off-by: Alexander Graf <agraf@suse.de> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2009-06-29Revert "Introduce reset notifier order"Jan Kiszka1-1/+1
This reverts commit 8217606e6edb49591b4a6fd5a0d1229cebe470a9 (and updates later added users of qemu_register_reset), we solved the problem it originally addressed less invasively. Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2009-06-29kvm: Rework VCPU synchronizationJan Kiszka1-23/+13
During startup and after reset we have to synchronize user space to the in-kernel KVM state. Namely, we need to transfer the VCPU registers when they change due to VCPU as well as APIC reset. This patch refactors the required hooks so that kvm_init_vcpu registers its own per-VCPU reset handler and adds a cpu_synchronize_state to the APIC reset. That way we no longer depend on the new reset order (and can drop this disliked interface again) and we can even drop a KVM hook in main(). Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2009-06-16kvm: Fix IRQ injection into full queueJan Kiszka1-2/+1
User space may only inject interrupts during kvm_arch_pre_run if ready_for_interrupt_injection is set in kvm_run. But that field is updated on exit from KVM_RUN, so we must ensure that we enter the kernel after potentially queuing an interrupt, otherwise we risk to loose one - like it happens with the current code against latest kernel modules (since kvm-86) that started to queue only a single interrupt. Fix the problem by reordering kvm_cpu_exec. Credits go to Gleb Natapov for analyzing the issue in details. Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2009-06-07kvm: Improve upgrade notes when facing unsupported kernelsJan Kiszka1-3/+7
Users complained that it is not obvious what to do when kvm refuses to build or run due to an unsupported host kernel, so let's improve the hints. Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
2009-05-22kvm: x86: Save/restore KVM-specific CPU statesJan Kiszka1-0/+20
Save and restore all so far neglected KVM-specific CPU states. Handling the TSC stabilizes migration in KVM mode. The interrupt_bitmap and mp_state are currently unused, but will become relevant for in-kernel irqchip support. By including proper saving/restoring already, we avoid having to increment CPU_SAVE_VERSION later on once again. v2: - initialize mp_state runnable (for the boot CPU) Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2009-05-22kvm: Rework VCPU resetJan Kiszka1-0/+8
Use standard callback with highest order to synchronize VCPU on reset after all device callbacks were execute. This allows to remove the special kvm hook in qemu_system_reset. Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2009-05-22kvm: Rework dirty bitmap synchronizationJan Kiszka1-31/+42
Extend kvm_physical_sync_dirty_bitmap() so that is can sync across multiple slots. Useful for updating the whole dirty log during migration. Moreover, properly pass down errors the whole call chain. Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2009-05-22kvm: Fix dirty log temporary buffer sizeJan Kiszka1-1/+1
The buffer passed to KVM_GET_DIRTY_LOG requires one bit per page. Fix the size calculation in kvm_physical_sync_dirty_bitmap accordingly, avoiding allocation of extremly oversized buffers. Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2009-05-22kvm: Introduce kvm_set_migration_logJan Kiszka1-7/+39
Introduce a global dirty logging flag that enforces logging for all slots. This can be used by the live migration code to enable/disable global logging withouth destroying the per-slot setting. Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2009-05-22kvm: Conditionally apply workaround for KVM slot handling bugJan Kiszka1-1/+11
Only apply the workaround for broken slot joining in KVM when the capability was not found that signals the corresponding fix existence. Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2009-05-20kvm: add error message for when SMP is requestedMark McLoughlin1-1/+3
Right now, if you try e.g. '-smp 2' you just get 'failed to initialize KVM'. Signed-off-by: Mark McLoughlin <markmc@redhat.com>
2009-05-08Introduce kvm_check_extension to check if KVM extensions are supportedAnthony Liguori1-17/+22
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2009-05-01kvm: Avoid COW if KVM MMU is asynchronousJan Kiszka1-0/+18
Avi Kivity wrote: > Suggest wrapping in a function and hiding it deep inside kvm-all.c. > Done in v2: ----------> If the KVM MMU is asynchronous (kernel does not support MMU_NOTIFIER), we have to avoid COW for the guest memory. Otherwise we risk serious breakage when guest pages change there physical locations due to COW after fork. Seen when forking smbd during runtime via -smb. Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2009-05-01kvm: Relax aligment check of kvm_set_phys_memJan Kiszka1-1/+9
There is no need to reject an unaligned memory region registration if the region will be I/O memory and it will not split an existing KVM slot. This fixes KVM support on PPC. Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2009-04-17kvm: improve handling of overlapping slots (Jan Kiszka)aliguori1-52/+114
This reworks the slot management to handle more patterns of cpu_register_physical_memory*, finally allowing to reset KVM guests (so far address remapping on reset broke the slot management). We could actually handle all possible ones without failing, but a KVM kernel bug in older versions would force us to track all previous fragmentations and maintain them (as that bug prevents registering larger slots that overlap also deleted ones). To remain backward compatible but avoid overly complicated workarounds, we apply a simpler workaround that covers all currently used patterns. Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com> git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@7139 c046a42c-6fe2-441c-8c8c-71466251a162
2009-04-17kvm: Add sanity checks to slot management (Jan Kiszka)aliguori1-13/+42
Fail loudly if we run out of memory slot. Make sure that dirty log start/stop works with consistent memory regions by reporting invalid parameters. This reveals several inconsistencies in the vga code, patch to fix them follows later in this series. And, for simplicity reasons, also catch and report unaligned memory regions passed to kvm_set_phys_mem (KVM works on page basis). Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com> git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@7138 c046a42c-6fe2-441c-8c8c-71466251a162
2009-04-17kvm: Cleanup unmap condition in kvm_set_phys_mem (Jan Kiszka)aliguori1-1/+1
Testing for TLB_MMIO on unmap makes no sense as A) that flag belongs to CPUTLBEntry and not to io_memory slots or physical addresses and B) we already use a different condition before mapping. So make this test consistent. Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com> git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@7137 c046a42c-6fe2-441c-8c8c-71466251a162
2009-04-11Remove code phys_ram_base uses.pbrook1-2/+2
Signed-off-by: Paul Brook <paul@codesourcery.com> git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@7085 c046a42c-6fe2-441c-8c8c-71466251a162
2009-03-12Guest debugging support for KVM (Jan Kiszka)aliguori1-0/+173
This is a backport of the guest debugging support for the KVM accelerator that is now part of the KVM tree. It implements the reworked KVM kernel API for guest debugging (KVM_CAP_SET_GUEST_DEBUG) which is not yet part of any mainline kernel but will probably be 2.6.30 stuff. So far supported is x86, but PPC is expected to catch up soon. Core features are: - unlimited soft-breakpoints via code patching - hardware-assisted x86 breakpoints and watchpoints Changes in this version: - use generic hook cpu_synchronize_state to transfer registers between user space and kvm - push kvm_sw_breakpoints into KVMState Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com> git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@6825 c046a42c-6fe2-441c-8c8c-71466251a162
2009-03-06Fix race condition on access to env->interrupt_requestaurel321-3/+3
env->interrupt_request is accessed as the bit level from both main code and signal handler, making a race condition possible even on CISC CPU. This causes freeze of QEMU under high load when running the dyntick clock. The patch below move the bit corresponding to CPU_INTERRUPT_EXIT in a separate variable, declared as volatile sig_atomic_t, so it should be work even on RISC CPU. We may want to move the cpu_interrupt(env, CPU_INTERRUPT_EXIT) case in its own function and get rid of CPU_INTERRUPT_EXIT. That can be done later, I wanted to keep the patch short for easier review. Signed-off-by: Aurelien Jarno <aurelien@aurel32.net> git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@6728 c046a42c-6fe2-441c-8c8c-71466251a162
2009-02-05toplevel: remove error handling from qemu_malloc() callers (Avi Kivity)aliguori1-7/+0
Signed-off-by: Avi Kivity <avi@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com> git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@6531 c046a42c-6fe2-441c-8c8c-71466251a162
2008-12-18KVM: Silence unused s warningaurel321-1/+1
Move s under #ifdef to avoid compiler warning. Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com> Signed-off-by: Aurelien Jarno <aurelien@aurel32.net> git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@6086 c046a42c-6fe2-441c-8c8c-71466251a162
2008-12-15kvm: sync vcpu state during initialization (Hollis Blanchard)aliguori1-0/+15
Currently on x86, qemu initializes CPUState but KVM ignores it and does its own vcpu initialization. However, PowerPC KVM needs to be able to set the initial register state to support the -kernel and -append options. Signed-off-by: Hollis Blanchard <hollisb@us.ibm.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com> git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@6060 c046a42c-6fe2-441c-8c8c-71466251a162
2008-12-09KVM: Coalesced MMIO supportaliguori1-0/+72
MMIO exits are more expensive in KVM or Xen than in QEMU because they involve, at least, privilege transitions. However, MMIO write operations can be effectively batched if those writes do not have side effects. Good examples of this include VGA pixel operations when in a planar mode. As it turns out, we can get a nice boost in other areas too. Laurent mentioned a 9.7% performance boost in iperf with the coalesced MMIO changes for the e1000 when he originally posted this work for KVM. Signed-off-by: Anthony Liguori <aliguori@us.ibm.com> git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@5961 c046a42c-6fe2-441c-8c8c-71466251a162
2008-12-09Disable KVM support if the kernel modules have broken memory slot handlingaliguori1-0/+15
Prior to kvm-80, memory slot deletion was broken in the KVM kernel modules. In kvm-81, a new capability is introduced to signify that this problem has been fixed. Since we rely on being able to delete memory slots, refuse to work with any kernel module that does not have this capability present. Signed-off-by: Anthony Liguori <aliguori@us.ibm.com> git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@5960 c046a42c-6fe2-441c-8c8c-71466251a162
2008-12-04Add virtio-balloon supportaliguori1-0/+12
This adds a VirtIO based balloon driver. It uses madvise() to actually balloon the memory when possible. Until 2.6.27, KVM forced memory pinning so we must disable ballooning unless the kernel actually supports it when using KVM. It's always safe when using TCG. Signed-off-by: Anthony Liguori <aliguori@us.ibm.com> git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@5874 c046a42c-6fe2-441c-8c8c-71466251a162
2008-11-24kvm: Introduce kvm logging interface (Glauber Costa)aliguori1-13/+109
Introduce functions to control logging of memory regions. We select regions based on its start address, a guest_physical_addr (target_phys_addr_t, in qemu nomenclature). The main user of this interface right now is VGA optimization (a way of reducing the number of mmio exits). Signed-off-by: Glauber Costa <glommer@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com> git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@5792 c046a42c-6fe2-441c-8c8c-71466251a162
2008-11-19Make KVMSlot a real structurealiguori1-17/+37
struct kvm_userspace_memory_region does not use QEMU friendly types to define memory slots. This results in lots of ugly casting with warnings on 32-bit platforms. This patch introduces a proper KVMSlot structure that uses QEMU types to describe memory slots. This eliminates many of the casts and isolates the type conversions to one spot. Signed-off-by: Anthony Liguori <aliguori@us.ibm.com> git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@5755 c046a42c-6fe2-441c-8c8c-71466251a162
2008-11-19kvm: de-register mem region for MMIO (Glauber Costa)aliguori1-1/+1
Besides unassigned memory, we also don't care about MMIO. So if we're giving an MMIO area that is already registered, wipe it out. Signed-off-by: Glauber Costa <glommer@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com> git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@5753 c046a42c-6fe2-441c-8c8c-71466251a162
2008-11-18Make KVM slot management more robustaliguori1-2/+40
KVM keeps track of physical memory based on slots in the kernel. The current code that translates QEMU memory mappings to slots work but is not robust in the fact of reregistering partial regions of memory. This patch does the right thing for reregistering partial regions of memory. It also prevents QEMU from using KVM private slots. Signed-off-by: Anthony Liguori <aliguori@us.ibm.com> git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@5734 c046a42c-6fe2-441c-8c8c-71466251a162