firefly-linux-kernel-4.4.55.git
13 years agoKVM: Replace reads of vcpu->arch.cr3 by an accessor
Avi Kivity [Sun, 5 Dec 2010 15:30:00 +0000 (17:30 +0200)]
KVM: Replace reads of vcpu->arch.cr3 by an accessor

This allows us to keep cr3 in the VMCS, later on.

Signed-off-by: Avi Kivity <avi@redhat.com>
13 years agoKVM: MMU: only write protect mappings at pagetable level
Marcelo Tosatti [Wed, 22 Dec 2010 11:01:57 +0000 (09:01 -0200)]
KVM: MMU: only write protect mappings at pagetable level

If a pagetable contains a writeable large spte, all of its sptes will be
write protected, including non-leaf ones, leading to endless pagefaults.

Do not write protect pages above PT_PAGE_TABLE_LEVEL, as the spte fault
paths assume non-leaf sptes are writable.

Tested-by: Alex Williamson <alex.williamson@redhat.com>
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
13 years agoKVM: VMX: Correct asm constraint in vmcs_load()/vmcs_clear()
Avi Kivity [Tue, 21 Dec 2010 14:51:50 +0000 (16:51 +0200)]
KVM: VMX: Correct asm constraint in vmcs_load()/vmcs_clear()

'error' is byte sized, so use a byte register constraint.

Acked-by: Randy Dunlap <randy.dunlap@oracle.com>
Signed-off-by: Avi Kivity <avi@redhat.com>
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
13 years agoKVM: MMU: Initialize base_role for tdp mmus
Avi Kivity [Tue, 21 Dec 2010 14:26:01 +0000 (16:26 +0200)]
KVM: MMU: Initialize base_role for tdp mmus

Signed-off-by: Avi Kivity <avi@redhat.com>
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
13 years agoKVM: VMX: Optimize atomic EFER load
Avi Kivity [Tue, 21 Dec 2010 10:54:20 +0000 (12:54 +0200)]
KVM: VMX: Optimize atomic EFER load

When NX is enabled on the host but not on the guest, we use the entry/exit
msr load facility, which is slow.  Optimize it to use entry/exit efer load,
which is ~1200 cycles faster.

Signed-off-by: Avi Kivity <avi@redhat.com>
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
13 years agoKVM: VMX: Add definitions for more vm entry/exit control bits
Avi Kivity [Tue, 21 Dec 2010 10:54:19 +0000 (12:54 +0200)]
KVM: VMX: Add definitions for more vm entry/exit control bits

Signed-off-by: Avi Kivity <avi@redhat.com>
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
13 years agoKVM: SVM: copy instruction bytes from VMCB
Andre Przywara [Tue, 21 Dec 2010 10:12:07 +0000 (11:12 +0100)]
KVM: SVM: copy instruction bytes from VMCB

In case of a nested page fault or an intercepted #PF newer SVM
implementations provide a copy of the faulting instruction bytes
in the VMCB.
Use these bytes to feed the instruction emulator and avoid the costly
guest instruction fetch in this case.

Signed-off-by: Andre Przywara <andre.przywara@amd.com>
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
13 years agoKVM: SVM: implement enhanced INVLPG intercept
Andre Przywara [Tue, 21 Dec 2010 10:12:06 +0000 (11:12 +0100)]
KVM: SVM: implement enhanced INVLPG intercept

When the DecodeAssist feature is available, the linear address
is provided in the VMCB on INVLPG intercepts. Use it directly to
avoid any decoding and emulation.
This is only useful for shadow paging, though.

Signed-off-by: Andre Przywara <andre.przywara@amd.com>
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
13 years agoKVM: SVM: enhance mov DR intercept handler
Andre Przywara [Tue, 21 Dec 2010 10:12:05 +0000 (11:12 +0100)]
KVM: SVM: enhance mov DR intercept handler

Newer SVM implementations provide the GPR number in the VMCB, so
that the emulation path is no longer necesarry to handle debug
register access intercepts. Implement the handling in svm.c and
use it when the info is provided.

Signed-off-by: Andre Przywara <andre.przywara@amd.com>
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
13 years agoKVM: SVM: enhance MOV CR intercept handler
Andre Przywara [Tue, 21 Dec 2010 10:12:04 +0000 (11:12 +0100)]
KVM: SVM: enhance MOV CR intercept handler

Newer SVM implementations provide the GPR number in the VMCB, so
that the emulation path is no longer necesarry to handle CR
register access intercepts. Implement the handling in svm.c and
use it when the info is provided.

Signed-off-by: Andre Przywara <andre.przywara@amd.com>
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
13 years agoKVM: SVM: add new SVM feature bit names
Andre Przywara [Tue, 21 Dec 2010 10:12:03 +0000 (11:12 +0100)]
KVM: SVM: add new SVM feature bit names

the recent APM Vol.2 and the recent AMD CPUID specification describe
new CPUID features bits for SVM. Name them here for later usage.

Signed-off-by: Andre Przywara <andre.przywara@amd.com>
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
13 years agoKVM: cleanup emulate_instruction
Andre Przywara [Tue, 21 Dec 2010 10:12:02 +0000 (11:12 +0100)]
KVM: cleanup emulate_instruction

emulate_instruction had many callers, but only one used all
parameters. One parameter was unused, another one is now
hidden by a wrapper function (required for a future addition
anyway), so most callers use now a shorter parameter list.

Signed-off-by: Andre Przywara <andre.przywara@amd.com>
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
13 years agoKVM: move complete_insn_gp() into x86.c
Andre Przywara [Tue, 21 Dec 2010 10:12:01 +0000 (11:12 +0100)]
KVM: move complete_insn_gp() into x86.c

move the complete_insn_gp() helper function out of the VMX part
into the generic x86 part to make it usable by SVM.

Signed-off-by: Andre Przywara <andre.przywara@amd.com>
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
13 years agoKVM: x86: fix CR8 handling
Andre Przywara [Tue, 21 Dec 2010 10:12:00 +0000 (11:12 +0100)]
KVM: x86: fix CR8 handling

The handling of CR8 writes in KVM is currently somewhat cumbersome.
This patch makes it look like the other CR register handlers
and fixes a possible issue in VMX, where the RIP would be incremented
despite an injected #GP.

Signed-off-by: Andre Przywara <andre.przywara@amd.com>
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
13 years agoKVM guest: Fix kvm clock initialization when it's configured out
Avi Kivity [Thu, 16 Dec 2010 09:27:23 +0000 (11:27 +0200)]
KVM guest: Fix kvm clock initialization when it's configured out

Signed-off-by: Avi Kivity <avi@redhat.com>
13 years agoKVM: Take missing slots_lock for kvm_io_bus_unregister_dev()
Takuya Yoshikawa [Wed, 15 Dec 2010 16:41:37 +0000 (01:41 +0900)]
KVM: Take missing slots_lock for kvm_io_bus_unregister_dev()

In KVM_CREATE_IRQCHIP, kvm_io_bus_unregister_dev() is called without taking
slots_lock in the error handling path.

Signed-off-by: Takuya Yoshikawa <yoshikawa.takuya@oss.ntt.co.jp>
Signed-off-by: Avi Kivity <avi@redhat.com>
13 years agoKVM: return true when user space query KVM_CAP_USER_NMI extension
Lai Jiangshan [Tue, 14 Dec 2010 09:57:47 +0000 (17:57 +0800)]
KVM: return true when user space query KVM_CAP_USER_NMI extension

userspace may check this extension in runtime.

Signed-off-by: Lai Jiangshan <laijs@cn.fujitsu.com>
Signed-off-by: Avi Kivity <avi@redhat.com>
13 years agoKVM: Correct kvm_pio tracepoint count field
Avi Kivity [Mon, 13 Dec 2010 15:24:53 +0000 (17:24 +0200)]
KVM: Correct kvm_pio tracepoint count field

Currently, we record '1' for count regardless of the real count.  Fix.

Signed-off-by: Avi Kivity <avi@redhat.com>
13 years agoKVM: MMU: Fix incorrect direct page write protection due to ro host page
Avi Kivity [Sun, 12 Dec 2010 17:30:55 +0000 (19:30 +0200)]
KVM: MMU: Fix incorrect direct page write protection due to ro host page

If KVM sees a read-only host page, it will map it as read-only to prevent
breaking a COW.  However, if the page was part of a large guest page, KVM
incorrectly extends the write protection to the entire large page frame
instead of limiting it to the normal host page.

This results in the instantiation of a new shadow page with read-only access.

If this happens for a MOVS instruction that moves memory between two normal
pages, within a single large page frame, and mapped within the guest as a
large page, and if, in addition, the source operand is not writeable in the
host (perhaps due to KSM), then KVM will instantiate a read-only direct
shadow page, instantiate an spte for the source operand, then instantiate
a new read/write direct shadow page and instantiate an spte for the
destination operand.  Since these two sptes are in different shadow pages,
MOVS will never see them at the same time and the guest will not make
progress.

Fix by mapping the direct shadow page read/write, and only marking the
host page read-only.

Signed-off-by: Avi Kivity <avi@redhat.com>
13 years agoKVM: Fix build error on s390 due to missing tlbs_dirty
Avi Kivity [Wed, 8 Dec 2010 16:04:51 +0000 (18:04 +0200)]
KVM: Fix build error on s390 due to missing tlbs_dirty

Make it available for all archs.

Signed-off-by: Avi Kivity <avi@redhat.com>
13 years agoKVM: SVM: Add xsetbv intercept
Joerg Roedel [Tue, 7 Dec 2010 16:15:06 +0000 (17:15 +0100)]
KVM: SVM: Add xsetbv intercept

This patch implements the xsetbv intercept to the AMD part
of KVM. This makes AVX usable in a save way for the guest on
AVX capable AMD hardware.

The patch is tested by using AVX in the guest and host in
parallel and checking for data corruption. I also used the
KVM xsave unit-tests and they all pass.

Signed-off-by: Joerg Roedel <joerg.roedel@amd.com>
Signed-off-by: Avi Kivity <avi@redhat.com>
13 years agoKVM: MMU: Make the way of accessing lpage_info more generic
Takuya Yoshikawa [Tue, 7 Dec 2010 03:59:07 +0000 (12:59 +0900)]
KVM: MMU: Make the way of accessing lpage_info more generic

Large page information has two elements but one of them, write_count, alone
is accessed by a helper function.

This patch replaces this helper function with more generic one which returns
newly named kvm_lpage_info structure and use it to access the other element
rmap_pde.

Signed-off-by: Takuya Yoshikawa <yoshikawa.takuya@oss.ntt.co.jp>
Signed-off-by: Avi Kivity <avi@redhat.com>
13 years agoKVM: VMX: add module parameter to avoid trapping HLT instructions (v5)
Anthony Liguori [Mon, 6 Dec 2010 16:53:38 +0000 (10:53 -0600)]
KVM: VMX: add module parameter to avoid trapping HLT instructions (v5)

In certain use-cases, we want to allocate guests fixed time slices where idle
guest cycles leave the machine idling.  There are many approaches to achieve
this but the most direct is to simply avoid trapping the HLT instruction which
lets the guest directly execute the instruction putting the processor to sleep.

Introduce this as a module-level option for kvm-vmx.ko since if you do this
for one guest, you probably want to do it for all.

Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
Signed-off-by: Avi Kivity <avi@redhat.com>
13 years agoKVM: SVM: Implement Flush-By-Asid feature
Joerg Roedel [Fri, 3 Dec 2010 14:25:16 +0000 (15:25 +0100)]
KVM: SVM: Implement Flush-By-Asid feature

This patch adds the new flush-by-asid of upcoming AMD
processors to the KVM-AMD module.

Signed-off-by: Joerg Roedel <joerg.roedel@amd.com>
Signed-off-by: Avi Kivity <avi@redhat.com>
13 years agoKVM: SVM: Use svm_flush_tlb instead of force_new_asid
Joerg Roedel [Fri, 3 Dec 2010 14:25:15 +0000 (15:25 +0100)]
KVM: SVM: Use svm_flush_tlb instead of force_new_asid

This patch replaces all calls to force_new_asid which are
intended to flush the guest-tlb by the more appropriate
function svm_flush_tlb. As a side-effect the force_new_asid
function is removed.

Signed-off-by: Joerg Roedel <joerg.roedel@amd.com>
Signed-off-by: Avi Kivity <avi@redhat.com>
13 years agoKVM: SVM: Remove flush_guest_tlb function
Joerg Roedel [Fri, 3 Dec 2010 14:25:14 +0000 (15:25 +0100)]
KVM: SVM: Remove flush_guest_tlb function

This function is unused and there is svm_flush_tlb which
does the same. So this function can be removed.

Signed-off-by: Joerg Roedel <joerg.roedel@amd.com>
Signed-off-by: Avi Kivity <avi@redhat.com>
13 years agoKVM: MMU: retry #PF for softmmu
Xiao Guangrong [Tue, 7 Dec 2010 02:35:25 +0000 (10:35 +0800)]
KVM: MMU: retry #PF for softmmu

Retry #PF for softmmu only when the current vcpu has the same cr3 as the time
when #PF occurs

Signed-off-by: Xiao Guangrong <xiaoguangrong@cn.fujitsu.com>
Signed-off-by: Avi Kivity <avi@redhat.com>
13 years agoKVM: MMU: fix accessed bit set on prefault path
Xiao Guangrong [Tue, 7 Dec 2010 02:34:42 +0000 (10:34 +0800)]
KVM: MMU: fix accessed bit set on prefault path

Retry #PF is the speculative path, so don't set the accessed bit

Signed-off-by: Xiao Guangrong <xiaoguangrong@cn.fujitsu.com>
Signed-off-by: Avi Kivity <avi@redhat.com>
13 years agoKVM: MMU: rename 'no_apf' to 'prefault'
Xiao Guangrong [Tue, 7 Dec 2010 02:48:06 +0000 (10:48 +0800)]
KVM: MMU: rename 'no_apf' to 'prefault'

It's the speculative path if 'no_apf = 1' and we will specially handle this
speculative path in the later patch, so 'prefault' is better to fit the sense.

Signed-off-by: Xiao Guangrong <xiaoguangrong@cn.fujitsu.com>
Signed-off-by: Avi Kivity <avi@redhat.com>
13 years agoKVM: SVM: Add clean-bit for LBR state
Joerg Roedel [Fri, 3 Dec 2010 10:45:59 +0000 (11:45 +0100)]
KVM: SVM: Add clean-bit for LBR state

This patch implements the clean-bit for all LBR related
state. This includes the debugctl, br_from, br_to,
last_excp_from, and last_excp_to msrs.

Signed-off-by: Joerg Roedel <joerg.roedel@amd.com>
Signed-off-by: Avi Kivity <avi@redhat.com>
13 years agoKVM: SVM: Add clean-bit for CR2 register
Joerg Roedel [Fri, 3 Dec 2010 10:45:58 +0000 (11:45 +0100)]
KVM: SVM: Add clean-bit for CR2 register

This patch implements the clean-bit for the cr2 register in
the vmcb.

Signed-off-by: Joerg Roedel <joerg.roedel@amd.com>
Signed-off-by: Avi Kivity <avi@redhat.com>
13 years agoKVM: SVM: Add clean-bit for Segements and CPL
Joerg Roedel [Fri, 3 Dec 2010 10:45:57 +0000 (11:45 +0100)]
KVM: SVM: Add clean-bit for Segements and CPL

This patch implements the clean-bit defined for the cs, ds,
ss, an es segemnts and the current cpl saved in the vmcb.

Signed-off-by: Joerg Roedel <joerg.roedel@amd.com>
Signed-off-by: Avi Kivity <avi@redhat.com>
13 years agoKVM: SVM: Add clean-bit for GDT and IDT
Joerg Roedel [Fri, 3 Dec 2010 10:45:56 +0000 (11:45 +0100)]
KVM: SVM: Add clean-bit for GDT and IDT

This patch implements the clean-bit for the base and limit
of the gdt and idt in the vmcb.

Signed-off-by: Joerg Roedel <joerg.roedel@amd.com>
Signed-off-by: Avi Kivity <avi@redhat.com>
13 years agoKVM: SVM: Add clean-bit for DR6 and DR7
Joerg Roedel [Fri, 3 Dec 2010 10:45:55 +0000 (11:45 +0100)]
KVM: SVM: Add clean-bit for DR6 and DR7

This patch implements the clean-bit for the dr6 and dr7
debug registers in the vmcb.

Signed-off-by: Joerg Roedel <joerg.roedel@amd.com>
Signed-off-by: Avi Kivity <avi@redhat.com>
13 years agoKVM: SVM: Add clean-bit for control registers
Joerg Roedel [Fri, 3 Dec 2010 10:45:54 +0000 (11:45 +0100)]
KVM: SVM: Add clean-bit for control registers

This patch implements the CRx clean-bit for the vmcb. This
bit covers cr0, cr3, cr4, and efer.

Signed-off-by: Joerg Roedel <joerg.roedel@amd.com>
Signed-off-by: Avi Kivity <avi@redhat.com>
13 years agoKVM: SVM: Add clean-bit for NPT state
Joerg Roedel [Fri, 3 Dec 2010 10:45:53 +0000 (11:45 +0100)]
KVM: SVM: Add clean-bit for NPT state

This patch implements the clean-bit for all nested paging
related state in the vmcb.

Signed-off-by: Joerg Roedel <joerg.roedel@amd.com>
Signed-off-by: Avi Kivity <avi@redhat.com>
13 years agoKVM: SVM: Add clean-bit for interrupt state
Joerg Roedel [Fri, 3 Dec 2010 10:45:52 +0000 (11:45 +0100)]
KVM: SVM: Add clean-bit for interrupt state

This patch implements the clean-bit for all interrupt
related state in the vmcb. This corresponds to vmcb offset
0x60-0x67.

Signed-off-by: Joerg Roedel <joerg.roedel@amd.com>
Signed-off-by: Avi Kivity <avi@redhat.com>
13 years agoKVM: SVM: Add clean-bit for the ASID
Joerg Roedel [Fri, 3 Dec 2010 10:45:51 +0000 (11:45 +0100)]
KVM: SVM: Add clean-bit for the ASID

This patch implements the clean-bit for the asid in the
vmcb.

Signed-off-by: Joerg Roedel <joerg.roedel@amd.com>
Signed-off-by: Avi Kivity <avi@redhat.com>
13 years agoKVM: SVM: Add clean-bit for IOPM_BASE and MSRPM_BASE
Joerg Roedel [Fri, 3 Dec 2010 10:45:50 +0000 (11:45 +0100)]
KVM: SVM: Add clean-bit for IOPM_BASE and MSRPM_BASE

This patch adds the clean bit for the physical addresses of
the MSRPM and the IOPM. It does not need to be set in the
code because the only place where these values are changed
is the nested-svm vmrun and vmexit path. These functions
already mark the complete VMCB as dirty.

Signed-off-by: Joerg Roedel <joerg.roedel@amd.com>
Signed-off-by: Avi Kivity <avi@redhat.com>
13 years agoKVM: SVM: Add clean-bit for intercetps, tsc-offset and pause filter count
Joerg Roedel [Fri, 3 Dec 2010 10:45:49 +0000 (11:45 +0100)]
KVM: SVM: Add clean-bit for intercetps, tsc-offset and pause filter count

This patch adds the clean-bit for intercepts-vectors, the
TSC offset and the pause-filter count to the appropriate
places. The IO and MSR permission bitmaps are not subject to
this bit.

Signed-off-by: Joerg Roedel <joerg.roedel@amd.com>
Signed-off-by: Avi Kivity <avi@redhat.com>
13 years agoKVM: SVM: Add clean-bits infrastructure code
Roedel, Joerg [Fri, 3 Dec 2010 12:15:21 +0000 (13:15 +0100)]
KVM: SVM: Add clean-bits infrastructure code

This patch adds the infrastructure for the implementation of
the individual clean-bits.

Signed-off-by: Joerg Roedel <joerg.roedel@amd.com>
Signed-off-by: Avi Kivity <avi@redhat.com>
13 years agoKVM: MMU: Avoid dropping accessed bit while removing write access
Takuya Yoshikawa [Sun, 5 Dec 2010 16:11:33 +0000 (01:11 +0900)]
KVM: MMU: Avoid dropping accessed bit while removing write access

One more "KVM: MMU: Don't drop accessed bit while updating an spte."

Sptes are accessed by both kvm and hardware.
This patch uses update_spte() to fix the way of removing write access.

Signed-off-by: Takuya Yoshikawa <yoshikawa.takuya@oss.ntt.co.jp>
Signed-off-by: Avi Kivity <avi@redhat.com>
13 years agoKVM: VMX: Return 0 from a failed VMREAD
Avi Kivity [Thu, 2 Dec 2010 15:55:23 +0000 (17:55 +0200)]
KVM: VMX: Return 0 from a failed VMREAD

If we execute VMREAD during reboot we'll just skip over it.  Instead of
returning garbage, return 0, which has a much smaller chance of confusing
the code.  Otherwise we risk a flood of debug printk()s which block the
reboot process if a serial console or netconsole is enabled.

Signed-off-by: Avi Kivity <avi@redhat.com>
13 years agoKVM: Don't spin on virt instruction faults during reboot
Avi Kivity [Thu, 2 Dec 2010 15:52:50 +0000 (17:52 +0200)]
KVM: Don't spin on virt instruction faults during reboot

Since vmx blocks INIT signals, we disable virtualization extensions during
reboot.  This leads to virtualization instructions faulting; we trap these
faults and spin while the reboot continues.

Unfortunately spinning on a non-preemptible kernel may block a task that
reboot depends on; this causes the reboot to hang.

Fix by skipping over the instruction and hoping for the best.

Signed-off-by: Avi Kivity <avi@redhat.com>
13 years agoKVM: SVM: Use get_host_vmcb function in svm_get_msr for TSC
Joerg Roedel [Tue, 30 Nov 2010 17:04:01 +0000 (18:04 +0100)]
KVM: SVM: Use get_host_vmcb function in svm_get_msr for TSC

This patch replaces the open-coded vmcb-selection for the
TSC calculation with the new get_host_vmcb helper function
introduced in this patchset.

Signed-off-by: Joerg Roedel <joerg.roedel@amd.com>
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
13 years agoKVM: SVM: Add manipulation functions for misc intercepts
Joerg Roedel [Tue, 30 Nov 2010 17:04:00 +0000 (18:04 +0100)]
KVM: SVM: Add manipulation functions for misc intercepts

This patch wraps changes to the misc intercepts of SVM
into seperate functions to abstract nested-svm better and
prepare the implementation of the vmcb-clean-bits feature.

Signed-off-by: Joerg Roedel <joerg.roedel@amd.com>
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
13 years agoKVM: SVM: Add manipulation functions for exception intercepts
Joerg Roedel [Tue, 30 Nov 2010 17:03:59 +0000 (18:03 +0100)]
KVM: SVM: Add manipulation functions for exception intercepts

This patch wraps changes to the exception intercepts of SVM
into seperate functions to abstract nested-svm better and
prepare the implementation of the vmcb-clean-bits feature.

Signed-off-by: Joerg Roedel <joerg.roedel@amd.com>
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
13 years agoKVM: SVM: Add manipulation functions for DRx intercepts
Joerg Roedel [Tue, 30 Nov 2010 17:03:58 +0000 (18:03 +0100)]
KVM: SVM: Add manipulation functions for DRx intercepts

This patch wraps changes to the DRx intercepts of SVM into
seperate functions to abstract nested-svm better and prepare
the implementation of the vmcb-clean-bits feature.

Signed-off-by: Joerg Roedel <joerg.roedel@amd.com>
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
13 years agoKVM: SVM: Add manipulation functions for CRx intercepts
Roedel, Joerg [Fri, 3 Dec 2010 09:50:51 +0000 (10:50 +0100)]
KVM: SVM: Add manipulation functions for CRx intercepts

This patch wraps changes to the CRx intercepts of SVM into
seperate functions to abstract nested-svm better and prepare
the implementation of the vmcb-clean-bits feature.

Signed-off-by: Joerg Roedel <joerg.roedel@amd.com>
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
13 years agoKVM: SVM: Add function to recalculate intercept masks
Joerg Roedel [Tue, 30 Nov 2010 17:03:56 +0000 (18:03 +0100)]
KVM: SVM: Add function to recalculate intercept masks

This patch adds a function to recalculate the effective
intercepts masks when the vcpu is in guest-mode and either
the host or the guest intercept masks change.

Signed-off-by: Joerg Roedel <joerg.roedel@amd.com>
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
13 years agoKVM: X86: Don't report L2 emulation failures to user-space
Joerg Roedel [Mon, 29 Nov 2010 16:51:49 +0000 (17:51 +0100)]
KVM: X86: Don't report L2 emulation failures to user-space

This patch prevents that emulation failures which result
from emulating an instruction for an L2-Guest results in
being reported to userspace.
Without this patch a malicious L2-Guest would be able to
kill the L1 by triggering a race-condition between an vmexit
and the instruction emulator.
With this patch the L2 will most likely only kill itself in
this situation.

Signed-off-by: Joerg Roedel <joerg.roedel@amd.com>
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
13 years agoKVM: SVM: Make Use of the generic guest-mode functions
Joerg Roedel [Mon, 29 Nov 2010 16:51:48 +0000 (17:51 +0100)]
KVM: SVM: Make Use of the generic guest-mode functions

This patch replaces the is_nested logic in the SVM module
with the generic notion of guest-mode.

Signed-off-by: Joerg Roedel <joerg.roedel@amd.com>
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
13 years agoKVM: X86: Introduce generic guest-mode representation
Joerg Roedel [Mon, 29 Nov 2010 16:51:47 +0000 (17:51 +0100)]
KVM: X86: Introduce generic guest-mode representation

This patch introduces a generic representation of guest-mode
fpr a vcpu. This currently only exists in the SVM code.
Having this representation generic will help making the
non-svm code aware of nesting when this is necessary.

Signed-off-by: Joerg Roedel <joerg.roedel@amd.com>
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
13 years agoKVM: Pull extra page fault information into struct x86_exception
Avi Kivity [Mon, 29 Nov 2010 14:12:30 +0000 (16:12 +0200)]
KVM: Pull extra page fault information into struct x86_exception

Currently page fault cr2 and nesting infomation are carried outside
the fault data structure.  Instead they are placed in the vcpu struct,
which results in confusion as global variables are manipulated instead
of passing parameters.

Fix this issue by adding address and nested fields to struct x86_exception,
so this struct can carry all information associated with a fault.

Signed-off-by: Avi Kivity <avi@redhat.com>
Tested-by: Joerg Roedel <joerg.roedel@amd.com>
Tested-by: Gleb Natapov <gleb@redhat.com>
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
13 years agoKVM: Push struct x86_exception into walk_addr()
Avi Kivity [Mon, 22 Nov 2010 15:53:27 +0000 (17:53 +0200)]
KVM: Push struct x86_exception into walk_addr()

Signed-off-by: Avi Kivity <avi@redhat.com>
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
13 years agoKVM: Push struct x86_exception info the various gva_to_gpa variants
Avi Kivity [Mon, 22 Nov 2010 15:53:26 +0000 (17:53 +0200)]
KVM: Push struct x86_exception info the various gva_to_gpa variants

Signed-off-by: Avi Kivity <avi@redhat.com>
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
13 years agoKVM: x86 emulator: simplify exception generation
Avi Kivity [Mon, 22 Nov 2010 15:53:25 +0000 (17:53 +0200)]
KVM: x86 emulator: simplify exception generation

Immediately after we generate an exception, we want a X86EMUL_PROPAGATE_FAULT
constant, so return it from the generation functions.

Signed-off-by: Avi Kivity <avi@redhat.com>
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
13 years agoKVM: x86 emulator: tighen up ->read_std() and ->write_std() error checks
Avi Kivity [Mon, 22 Nov 2010 15:53:24 +0000 (17:53 +0200)]
KVM: x86 emulator: tighen up ->read_std() and ->write_std() error checks

Instead of checking for X86EMUL_PROPAGATE_FAULT, check for any error,
making the callers more reliable.

Signed-off-by: Avi Kivity <avi@redhat.com>
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
13 years agoKVM: x86 emulator: drop dead pf injection in emulate_popf()
Avi Kivity [Mon, 22 Nov 2010 15:53:23 +0000 (17:53 +0200)]
KVM: x86 emulator: drop dead pf injection in emulate_popf()

If rc == X86EMUL_PROPAGATE_FAULT, we would have returned earlier.

Signed-off-by: Avi Kivity <avi@redhat.com>
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
13 years agoKVM: x86 emulator: make emulator memory callbacks return full exception
Avi Kivity [Mon, 22 Nov 2010 15:53:22 +0000 (17:53 +0200)]
KVM: x86 emulator: make emulator memory callbacks return full exception

This way, they can return #GP, not just #PF.

Signed-off-by: Avi Kivity <avi@redhat.com>
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
13 years agoKVM: x86 emulator: introduce struct x86_exception to communicate faults
Avi Kivity [Mon, 22 Nov 2010 15:53:21 +0000 (17:53 +0200)]
KVM: x86 emulator: introduce struct x86_exception to communicate faults

Introduce a structure that can contain an exception to be passed back
to main kvm code.

Signed-off-by: Avi Kivity <avi@redhat.com>
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
13 years agoKVM: MMU: delay flush all tlbs on sync_page path
Xiao Guangrong [Tue, 23 Nov 2010 03:13:00 +0000 (11:13 +0800)]
KVM: MMU: delay flush all tlbs on sync_page path

Quote from Avi:
| I don't think we need to flush immediately; set a "tlb dirty" bit somewhere
| that is cleareded when we flush the tlb.  kvm_mmu_notifier_invalidate_page()
| can consult the bit and force a flush if set.

Signed-off-by: Xiao Guangrong <xiaoguangrong@cn.fujitsu.com>
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
13 years agoKVM: MMU: abstract invalid guest pte mapping
Xiao Guangrong [Tue, 23 Nov 2010 03:08:42 +0000 (11:08 +0800)]
KVM: MMU: abstract invalid guest pte mapping

Introduce a common function to map invalid gpte

Signed-off-by: Xiao Guangrong <xiaoguangrong@cn.fujitsu.com>
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
13 years agoKVM: MMU: remove 'clear_unsync' parameter
Xiao Guangrong [Fri, 19 Nov 2010 09:04:03 +0000 (17:04 +0800)]
KVM: MMU: remove 'clear_unsync' parameter

Remove it since we can judge it by using sp->unsync

Signed-off-by: Xiao Guangrong <xiaoguangrong@cn.fujitsu.com>
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
13 years agoKVM: MMU: rename 'reset_host_protection' to 'host_writable'
Lai Jiangshan [Fri, 19 Nov 2010 09:03:22 +0000 (17:03 +0800)]
KVM: MMU: rename 'reset_host_protection' to 'host_writable'

Rename it to fit its sense better

Signed-off-by: Lai Jiangshan <laijs@cn.fujitsu.com>
Signed-off-by: Xiao Guangrong <xiaoguangrong@cn.fujitsu.com>
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
13 years agoKVM: MMU: don't drop spte if overwrite it from W to RO
Xiao Guangrong [Fri, 19 Nov 2010 09:02:35 +0000 (17:02 +0800)]
KVM: MMU: don't drop spte if overwrite it from W to RO

We just need flush tlb if overwrite a writable spte with a read-only one.

And we should move this operation to set_spte() for sync_page path

Signed-off-by: Xiao Guangrong <xiaoguangrong@cn.fujitsu.com>
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
13 years agoKVM: MMU: fix forgot flush tlbs on sync_page path
Xiao Guangrong [Fri, 19 Nov 2010 09:01:40 +0000 (17:01 +0800)]
KVM: MMU: fix forgot flush tlbs on sync_page path

We should flush all tlbs after drop spte on sync_page path since

Quote from Avi:
| sync_page
| drop_spte
| kvm_mmu_notifier_invalidate_page
| kvm_unmap_rmapp
| spte doesn't exist -> no flush
| page is freed
| guest can write into freed page?

KVM-Stable-Tag.
Signed-off-by: Xiao Guangrong <xiaoguangrong@cn.fujitsu.com>
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
13 years agoKVM: PPC: Fix compile warning
Alexander Graf [Thu, 25 Nov 2010 09:25:44 +0000 (10:25 +0100)]
KVM: PPC: Fix compile warning

KVM compilation fails with the following warning:

include/linux/kvm_host.h: In function 'kvm_irq_routing_update':
include/linux/kvm_host.h:679:2: error: 'struct kvm' has no member named 'irq_routing'

That function is only used and reasonable to have on systems that implement
an in-kernel interrupt chip. PPC doesn't.

Fix by #ifdef'ing it out when no irqchip is available.

Signed-off-by: Alexander Graf <agraf@suse.de>
Signed-off-by: Avi Kivity <avi@redhat.com>
13 years agoKVM: Add instruction-set-specific exit qualifications to kvm_exit trace
Avi Kivity [Thu, 18 Nov 2010 11:09:54 +0000 (13:09 +0200)]
KVM: Add instruction-set-specific exit qualifications to kvm_exit trace

The exit reason alone is insufficient to understand exactly why an exit
occured; add ISA-specific trace parameters for additional information.

Because fetching these parameters is expensive on vmx, and because these
parameters are fetched even if tracing is disabled, we fetch the
parameters via a callback instead of as traditional trace arguments.

Signed-off-by: Avi Kivity <avi@redhat.com>
13 years agoKVM: Record instruction set in kvm_exit tracepoint
Avi Kivity [Wed, 17 Nov 2010 16:44:19 +0000 (18:44 +0200)]
KVM: Record instruction set in kvm_exit tracepoint

exit_reason's meaning depend on the instruction set; record it so a trace
taken on one machine can be interpreted on another.

Signed-off-by: Avi Kivity <avi@redhat.com>
13 years agoKVM: fast-path msi injection with irqfd
Michael S. Tsirkin [Thu, 18 Nov 2010 17:09:08 +0000 (19:09 +0200)]
KVM: fast-path msi injection with irqfd

Store irq routing table pointer in the irqfd object,
and use that to inject MSI directly without bouncing out to
a kernel thread.

While we touch this structure, rearrange irqfd fields to make fastpath
better packed for better cache utilization.

This also adds some comments about locking rules and rcu usage in code.

Some notes on the design:
- Use pointer into the rt instead of copying an entry,
  to make it possible to use rcu, thus side-stepping
  locking complexities.  We also save some memory this way.
- Old workqueue code is still used for level irqs.
  I don't think we DTRT with level anyway, however,
  it seems easier to keep the code around as
  it has been thought through and debugged, and fix level later than
  rip out and re-instate it later.

Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Acked-by: Marcelo Tosatti <mtosatti@redhat.com>
Acked-by: Gregory Haskins <ghaskins@novell.com>
Signed-off-by: Avi Kivity <avi@redhat.com>
13 years agoKVM: VMX: Fold __vmx_vcpu_run() into vmx_vcpu_run()
Avi Kivity [Thu, 18 Nov 2010 11:12:52 +0000 (13:12 +0200)]
KVM: VMX: Fold __vmx_vcpu_run() into vmx_vcpu_run()

cea15c2 ("KVM: Move KVM context switch into own function") split vmx_vcpu_run()
to prevent multiple copies of the context switch from being generated (causing
problems due to a label).  This patch folds them back together again and adds
the __noclone attribute to prevent the label from being duplicated.

Signed-off-by: Avi Kivity <avi@redhat.com>
13 years agoKVM: x86 emulator: do not perform address calculations on linear addresses
Avi Kivity [Wed, 17 Nov 2010 13:28:22 +0000 (15:28 +0200)]
KVM: x86 emulator: do not perform address calculations on linear addresses

Linear addresses are supposed to already have segment checks performed on them;
if we play with these addresses the checks become invalid.

Signed-off-by: Avi Kivity <avi@redhat.com>
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
13 years agoKVM: x86 emulator: preserve an operand's segment identity
Avi Kivity [Wed, 17 Nov 2010 13:28:21 +0000 (15:28 +0200)]
KVM: x86 emulator: preserve an operand's segment identity

Currently the x86 emulator converts the segment register associated with
an operand into a segment base which is added into the operand address.
This loss of information results in us not doing segment limit checks properly.

Replace struct operand's addr.mem field by a segmented_address structure
which holds both the effetive address and segment.  This will allow us to
do the limit check at the point of access.

Signed-off-by: Avi Kivity <avi@redhat.com>
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
13 years agoKVM: x86 emulator: drop DPRINTF()
Avi Kivity [Wed, 17 Nov 2010 11:40:51 +0000 (13:40 +0200)]
KVM: x86 emulator: drop DPRINTF()

Failed emulation is reported via a tracepoint; the cmps printk is pointless.

Signed-off-by: Avi Kivity <avi@redhat.com>
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
13 years agoKVM: x86 emulator: drop unused #ifndef __KERNEL__
Avi Kivity [Wed, 17 Nov 2010 11:40:50 +0000 (13:40 +0200)]
KVM: x86 emulator: drop unused #ifndef __KERNEL__

Signed-off-by: Avi Kivity <avi@redhat.com>
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
13 years agoKVM: VMX: Inform user about INTEL_TXT dependency
Shane Wang [Wed, 17 Nov 2010 03:40:17 +0000 (11:40 +0800)]
KVM: VMX: Inform user about INTEL_TXT dependency

Inform user to either disable TXT in the BIOS or do TXT launch
with tboot before enabling KVM since some BIOSes do not set
FEATURE_CONTROL_VMXON_ENABLED_OUTSIDE_SMX bit when TXT is enabled.

Signed-off-by: Shane Wang <shane.wang@intel.com>
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
13 years agoKVM: rename hardware_[dis|en]able() to *_nolock() and add locking wrappers
Takuya Yoshikawa [Tue, 16 Nov 2010 08:37:41 +0000 (17:37 +0900)]
KVM: rename hardware_[dis|en]able() to *_nolock() and add locking wrappers

The naming convension of hardware_[dis|en]able family is little bit confusing
because only hardware_[dis|en]able_all are using _nolock suffix.

Renaming current hardware_[dis|en]able() to *_nolock() and using
hardware_[dis|en]able() as wrapper functions which take kvm_lock for them
reduces extra confusion.

Signed-off-by: Takuya Yoshikawa <yoshikawa.takuya@oss.ntt.co.jp>
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
13 years agoKVM: take kvm_lock for hardware_disable() during cpu hotplug
Takuya Yoshikawa [Tue, 16 Nov 2010 08:35:02 +0000 (17:35 +0900)]
KVM: take kvm_lock for hardware_disable() during cpu hotplug

In kvm_cpu_hotplug(), only CPU_STARTING case is protected by kvm_lock.
This patch adds missing protection for CPU_DYING case.

Signed-off-by: Takuya Yoshikawa <yoshikawa.takuya@oss.ntt.co.jp>
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
13 years agoKVM: MMU: don't mark spte notrap if reserved bit set
Xiao Guangrong [Wed, 17 Nov 2010 04:11:41 +0000 (12:11 +0800)]
KVM: MMU: don't mark spte notrap if reserved bit set

If reserved bit is set, we need inject the #PF with PFEC.RSVD=1,
but shadow_notrap_nonpresent_pte injects #PF with PFEC.RSVD=0 only

Signed-off-by: Xiao Guangrong <xiaoguangrong@cn.fujitsu.com>
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
13 years agoKVM: Document device assigment API
Jan Kiszka [Tue, 16 Nov 2010 21:30:07 +0000 (22:30 +0100)]
KVM: Document device assigment API

Adds API documentation for KVM_[DE]ASSIGN_PCI_DEVICE,
KVM_[DE]ASSIGN_DEV_IRQ, KVM_SET_GSI_ROUTING, KVM_ASSIGN_SET_MSIX_NR, and
KVM_ASSIGN_SET_MSIX_ENTRY.

Acked-by: Alex Williamson <alex.williamson@redhat.com>
Acked-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
13 years agoKVM: Clean up kvm_vm_ioctl_assigned_device
Jan Kiszka [Tue, 16 Nov 2010 21:30:06 +0000 (22:30 +0100)]
KVM: Clean up kvm_vm_ioctl_assigned_device

Any arch not supporting device assigment will also not build
assigned-dev.c. So testing for KVM_CAP_DEVICE_DEASSIGNMENT is pointless.
KVM_CAP_ASSIGN_DEV_IRQ is unconditinally set. Moreover, add a default
case for dispatching the ioctl.

Acked-by: Alex Williamson <alex.williamson@redhat.com>
Acked-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
13 years agoKVM: Save/restore state of assigned PCI device
Jan Kiszka [Tue, 16 Nov 2010 21:30:05 +0000 (22:30 +0100)]
KVM: Save/restore state of assigned PCI device

The guest may change states that pci_reset_function does not touch. So
we better save/restore the assigned device across guest usage.

Acked-by: Alex Williamson <alex.williamson@redhat.com>
Acked-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
13 years agoKVM: Refactor IRQ names of assigned devices
Jan Kiszka [Tue, 16 Nov 2010 21:30:04 +0000 (22:30 +0100)]
KVM: Refactor IRQ names of assigned devices

Cosmetic change, but it helps to correlate IRQs with PCI devices.

Acked-by: Alex Williamson <alex.williamson@redhat.com>
Acked-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
13 years agoKVM: Switch assigned device IRQ forwarding to threaded handler
Jan Kiszka [Tue, 16 Nov 2010 21:30:03 +0000 (22:30 +0100)]
KVM: Switch assigned device IRQ forwarding to threaded handler

This improves the IRQ forwarding for assigned devices: By using the
kernel's threaded IRQ scheme, we can get rid of the latency-prone work
queue and simplify the code in the same run.

Moreover, we no longer have to hold assigned_dev_lock while raising the
guest IRQ, which can be a lenghty operation as we may have to iterate
over all VCPUs. The lock is now only used for synchronizing masking vs.
unmasking of INTx-type IRQs, thus is renames to intx_lock.

Acked-by: Alex Williamson <alex.williamson@redhat.com>
Acked-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
13 years agoKVM: Clear assigned guest IRQ on release
Jan Kiszka [Tue, 16 Nov 2010 21:30:02 +0000 (22:30 +0100)]
KVM: Clear assigned guest IRQ on release

When we deassign a guest IRQ, clear the potentially asserted guest line.
There might be no chance for the guest to do this, specifically if we
switch from INTx to MSI mode.

Acked-by: Alex Williamson <alex.williamson@redhat.com>
Acked-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
13 years agoKVM: Mask KVM_GET_SUPPORTED_CPUID data with Linux cpuid info
Avi Kivity [Tue, 9 Nov 2010 14:15:43 +0000 (16:15 +0200)]
KVM: Mask KVM_GET_SUPPORTED_CPUID data with Linux cpuid info

This allows Linux to mask cpuid bits if, for example, nx is enabled on only
some cpus.

Signed-off-by: Avi Kivity <avi@redhat.com>
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
13 years agoKVM: SVM: Replace svm_has() by standard Linux cpuid accessors
Avi Kivity [Tue, 9 Nov 2010 14:15:42 +0000 (16:15 +0200)]
KVM: SVM: Replace svm_has() by standard Linux cpuid accessors

Instead of querying cpuid directly, use the Linux accessors (boot_cpu_has,
etc.).  This allows the things like the clearcpuid kernel command line to
work (when it's fixed wrt scattered cpuid bits).

Acked-by: Joerg Roedel <joerg.roedel@amd.com>
Signed-off-by: Avi Kivity <avi@redhat.com>
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
13 years agoKVM: MMU: fix apf prefault if nested guest is enabled
Xiao Guangrong [Fri, 12 Nov 2010 06:49:55 +0000 (14:49 +0800)]
KVM: MMU: fix apf prefault if nested guest is enabled

If apf is generated in L2 guest and is completed in L1 guest, it will
prefault this apf in L1 guest's mmu context.

Signed-off-by: Xiao Guangrong <xiaoguangrong@cn.fujitsu.com>
Signed-off-by: Avi Kivity <avi@redhat.com>
13 years agoKVM: MMU: support apf for nonpaing guest
Xiao Guangrong [Fri, 12 Nov 2010 06:49:11 +0000 (14:49 +0800)]
KVM: MMU: support apf for nonpaing guest

Let's support apf for nonpaing guest

Signed-off-by: Xiao Guangrong <xiaoguangrong@cn.fujitsu.com>
Signed-off-by: Avi Kivity <avi@redhat.com>
13 years agoKVM: MMU: clear apfs if page state is changed
Xiao Guangrong [Fri, 12 Nov 2010 06:47:01 +0000 (14:47 +0800)]
KVM: MMU: clear apfs if page state is changed

If CR0.PG is changed, the page fault cann't be avoid when the prefault address
is accessed later

And it also fix a bug: it can retry a page enabled #PF in page disabled context
if mmu is shadow page

This idear is from Gleb Natapov

Signed-off-by: Xiao Guangrong <xiaoguangrong@cn.fujitsu.com>
Signed-off-by: Avi Kivity <avi@redhat.com>
13 years agoKVM: MMU: fix missing post sync audit
Xiao Guangrong [Fri, 12 Nov 2010 06:46:08 +0000 (14:46 +0800)]
KVM: MMU: fix missing post sync audit

Add AUDIT_POST_SYNC audit for long mode shadow page

Signed-off-by: Xiao Guangrong <xiaoguangrong@cn.fujitsu.com>
Signed-off-by: Avi Kivity <avi@redhat.com>
13 years agoKVM: Clean up vm creation and release
Jan Kiszka [Tue, 9 Nov 2010 16:02:49 +0000 (17:02 +0100)]
KVM: Clean up vm creation and release

IA64 support forces us to abstract the allocation of the kvm structure.
But instead of mixing this up with arch-specific initialization and
doing the same on destruction, split both steps. This allows to move
generic destruction calls into generic code.

It also fixes error clean-up on failures of kvm_create_vm for IA64.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
Signed-off-by: Avi Kivity <avi@redhat.com>
13 years agoKVM: x86: Makefile clean up
Tracey Dent [Sat, 6 Nov 2010 18:52:58 +0000 (14:52 -0400)]
KVM: x86: Makefile clean up

Changed makefile to use the ccflags-y option instead of EXTRA_CFLAGS.

Signed-off-by: Tracey Dent <tdent48227@gmail.com>
Signed-off-by: Avi Kivity <avi@redhat.com>
13 years agoKVM: remove unused function declaration
Xiao Guangrong [Thu, 4 Nov 2010 10:29:42 +0000 (18:29 +0800)]
KVM: remove unused function declaration

Remove the declaration of kvm_mmu_set_base_ptes()

Signed-off-by: Xiao Guangrong <xiaoguangrong@cn.fujitsu.com>
Signed-off-by: Avi Kivity <avi@redhat.com>
13 years agoKVM: Refactor srcu struct release on early errors
Jan Kiszka [Tue, 9 Nov 2010 11:42:12 +0000 (12:42 +0100)]
KVM: Refactor srcu struct release on early errors

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
Signed-off-by: Avi Kivity <avi@redhat.com>
13 years agoKVM: VMX: Disallow NMI while blocked by STI
Avi Kivity [Mon, 1 Nov 2010 21:20:48 +0000 (23:20 +0200)]
KVM: VMX: Disallow NMI while blocked by STI

While not mandated by the spec, Linux relies on NMI being blocked by an
IF-enabling STI.  VMX also refuses to enter a guest in this state, at
least on some implementations.

Disallow NMI while blocked by STI by checking for the condition, and
requesting an interrupt window exit if it occurs.

Signed-off-by: Avi Kivity <avi@redhat.com>
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
13 years agoKVM: fix the race while wakeup all pv guest
Xiao Guangrong [Mon, 1 Nov 2010 09:03:44 +0000 (17:03 +0800)]
KVM: fix the race while wakeup all pv guest

In kvm_async_pf_wakeup_all(), we add a dummy apf to vcpu->async_pf.done
without holding vcpu->async_pf.lock, it will break if we are handling apfs
at this time.

Also use 'list_empty_careful()' instead of 'list_empty()'

Signed-off-by: Xiao Guangrong <xiaoguangrong@cn.fujitsu.com>
Acked-by: Gleb Natapov <gleb@redhat.com>
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
13 years agoKVM: handle more completed apfs if possible
Xiao Guangrong [Tue, 2 Nov 2010 09:35:35 +0000 (17:35 +0800)]
KVM: handle more completed apfs if possible

If it's no need to inject async #PF to PV guest we can handle
more completed apfs at one time, so we can retry guest #PF
as early as possible

Signed-off-by: Xiao Guangrong <xiaoguangrong@cn.fujitsu.com>
Acked-by: Gleb Natapov <gleb@redhat.com>
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
13 years agoKVM: avoid unnecessary wait for a async pf
Xiao Guangrong [Mon, 1 Nov 2010 09:01:28 +0000 (17:01 +0800)]
KVM: avoid unnecessary wait for a async pf

In current code, it checks async pf completion out of the wait context,
like this:

if (vcpu->arch.mp_state == KVM_MP_STATE_RUNNABLE &&
    !vcpu->arch.apf.halted)
r = vcpu_enter_guest(vcpu);
else {
......
kvm_vcpu_block(vcpu)
 ^- waiting until 'async_pf.done' is not empty
}

kvm_check_async_pf_completion(vcpu)
 ^- delete list from async_pf.done

So, if we check aysnc pf completion first, it can be blocked at
kvm_vcpu_block

Fixed by mark the vcpu is unhalted in kvm_check_async_pf_completion()
path

Signed-off-by: Xiao Guangrong <xiaoguangrong@cn.fujitsu.com>
Acked-by: Gleb Natapov <gleb@redhat.com>
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>