deliverable/linux.git
14 years agoKVM: Use u64 for frame data types
Joerg Roedel [Thu, 1 Jul 2010 14:00:12 +0000 (16:00 +0200)] 
KVM: Use u64 for frame data types

For 32bit machines where the physical address width is
larger than the virtual address width the frame number types
in KVM may overflow. Fix this by changing them to u64.

[sfr: fix build on 32-bit ppc]

Signed-off-by: Joerg Roedel <joerg.roedel@amd.com>
Signed-off-by: Stephen Rothwell <sfr@canb.auug.org.au>
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
14 years agoKVM: Remove unnecessary divide operations
Joerg Roedel [Thu, 1 Jul 2010 14:00:11 +0000 (16:00 +0200)] 
KVM: Remove unnecessary divide operations

This patch converts unnecessary divide and modulo operations
in the KVM large page related code into logical operations.
This allows to convert gfn_t to u64 while not breaking 32
bit builds.

Signed-off-by: Joerg Roedel <joerg.roedel@amd.com>
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
14 years agoKVM: Fix IOMMU memslot reference warning
Sheng Yang [Thu, 1 Jul 2010 07:00:50 +0000 (15:00 +0800)] 
KVM: Fix IOMMU memslot reference warning

This patch fixes the following warning.

===================================================
[ INFO: suspicious rcu_dereference_check() usage. ]
---------------------------------------------------
include/linux/kvm_host.h:259 invoked rcu_dereference_check() without
protection!

other info that might help us debug this:

rcu_scheduler_active = 1, debug_locks = 0
no locks held by qemu-system-x86/29679.

stack backtrace:
Pid: 29679, comm: qemu-system-x86 Not tainted 2.6.35-rc3+ #200
Call Trace:
 [<ffffffff810a224e>] lockdep_rcu_dereference+0xa8/0xb1
 [<ffffffffa018a06f>] kvm_iommu_unmap_memslots+0xc9/0xde [kvm]
 [<ffffffffa018a0c4>] kvm_iommu_unmap_guest+0x40/0x4e [kvm]
 [<ffffffffa018f772>] kvm_arch_destroy_vm+0x1a/0x186 [kvm]
 [<ffffffffa01800d0>] kvm_put_kvm+0x110/0x167 [kvm]
 [<ffffffffa0180ecc>] kvm_vcpu_release+0x18/0x1c [kvm]
 [<ffffffff81156f5d>] fput+0x22a/0x3a0
 [<ffffffff81152288>] filp_close+0xb4/0xcd
 [<ffffffff8106599f>] put_files_struct+0x1b7/0x36b
 [<ffffffff81065830>] ? put_files_struct+0x48/0x36b
 [<ffffffff8131ee59>] ? do_raw_spin_unlock+0x118/0x160
 [<ffffffff81065bc0>] exit_files+0x6d/0x75
 [<ffffffff81068348>] do_exit+0x47d/0xc60
 [<ffffffff8177e7b5>] ? _raw_spin_unlock_irq+0x30/0x36
 [<ffffffff81068bfa>] do_group_exit+0xcf/0x134
 [<ffffffff81080790>] get_signal_to_deliver+0x732/0x81d
 [<ffffffff81095996>] ? cpu_clock+0x4e/0x60
 [<ffffffff81002082>] do_notify_resume+0x117/0xc43
 [<ffffffff810a2fa3>] ? trace_hardirqs_on+0xd/0xf
 [<ffffffff81080d79>] ? sys_rt_sigtimedwait+0x2b5/0x3bf
 [<ffffffff8177d9f2>] ? trace_hardirqs_off_thunk+0x3a/0x3c
 [<ffffffff81003221>] ? sysret_signal+0x5/0x3d
 [<ffffffff8100343b>] int_signal+0x12/0x17

Signed-off-by: Sheng Yang <sheng@linux.intel.com>
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
14 years agoKVM: PPC: Make use of hash based Shadow MMU
Alexander Graf [Wed, 30 Jun 2010 13:18:46 +0000 (15:18 +0200)] 
KVM: PPC: Make use of hash based Shadow MMU

We just introduced generic functions to handle shadow pages on PPC.
This patch makes the respective backends make use of them, getting
rid of a lot of duplicate code along the way.

Signed-off-by: Alexander Graf <agraf@suse.de>
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
14 years agoKVM: PPC: Add generic hpte management functions
Alexander Graf [Wed, 30 Jun 2010 13:18:45 +0000 (15:18 +0200)] 
KVM: PPC: Add generic hpte management functions

Currently the shadow paging code keeps an array of entries it knows about.
Whenever the guest invalidates an entry, we loop through that entry,
trying to invalidate matching parts.

While this is a really simple implementation, it is probably the most
ineffective one possible. So instead, let's keep an array of lists around
that are indexed by a hash. This way each PTE can be added by 4 list_add,
removed by 4 list_del invocations and the search only needs to loop through
entries that share the same hash.

This patch implements said lookup and exports generic functions that both
the 32-bit and 64-bit backend can use.

Signed-off-by: Alexander Graf <agraf@suse.de>
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
14 years agoKVM: MMU: cleanup FNAME(fetch)() functions
Xiao Guangrong [Wed, 30 Jun 2010 08:05:00 +0000 (16:05 +0800)] 
KVM: MMU: cleanup FNAME(fetch)() functions

Cleanup this function that we are already get the direct sp's access

Signed-off-by: Xiao Guangrong <xiaoguangrong@cn.fujitsu.com>
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
14 years agoKVM: MMU: fix direct sp's access corrupted
Xiao Guangrong [Wed, 30 Jun 2010 08:03:28 +0000 (16:03 +0800)] 
KVM: MMU: fix direct sp's access corrupted

If the mapping is writable but the dirty flag is not set, we will find
the read-only direct sp and setup the mapping, then if the write #PF
occur, we will mark this mapping writable in the read-only direct sp,
now, other real read-only mapping will happily write it without #PF.

It may hurt guest's COW

Fixed by re-install the mapping when write #PF occur.

Signed-off-by: Xiao Guangrong <xiaoguangrong@cn.fujitsu.com>
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
14 years agoKVM: MMU: fix conflict access permissions in direct sp
Xiao Guangrong [Wed, 30 Jun 2010 08:02:45 +0000 (16:02 +0800)] 
KVM: MMU: fix conflict access permissions in direct sp

In no-direct mapping, we mark sp is 'direct' when we mapping the
guest's larger page, but its access is encoded form upper page-struct
entire not include the last mapping, it will cause access conflict.

For example, have this mapping:
        [W]
      / PDE1 -> |---|
  P[W]          |   | LPA
      \ PDE2 -> |---|
        [R]

P have two children, PDE1 and PDE2, both PDE1 and PDE2 mapping the
same lage page(LPA). The P's access is WR, PDE1's access is WR,
PDE2's access is RO(just consider read-write permissions here)

When guest access PDE1, we will create a direct sp for LPA, the sp's
access is from P, is W, then we will mark the ptes is W in this sp.

Then, guest access PDE2, we will find LPA's shadow page, is the same as
PDE's, and mark the ptes is RO.

So, if guest access PDE1, the incorrect #PF is occured.

Fixed by encode the last mapping access into direct shadow page

Signed-off-by: Xiao Guangrong <xiaoguangrong@cn.fujitsu.com>
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
14 years agoKVM: MMU: fix writable sync sp mapping
Xiao Guangrong [Wed, 30 Jun 2010 08:02:02 +0000 (16:02 +0800)] 
KVM: MMU: fix writable sync sp mapping

While we sync many unsync sp at one time(in mmu_sync_children()),
we may mapping the spte writable, it's dangerous, if one unsync
sp's mapping gfn is another unsync page's gfn.

For example:

SP1.pte[0] = P
SP2.gfn's pfn = P
[SP1.pte[0] = SP2.gfn's pfn]

First, we write protected SP1 and SP2, but SP1 and SP2 are still the
unsync sp.

Then, sync SP1 first, it will detect SP1.pte[0].gfn only has one unsync-sp,
that is SP2, so it will mapping it writable, but we plan to sync SP2 soon,
at this point, the SP2->unsync is not reliable since later we sync SP2 but
SP2->gfn is already writable.

So the final result is: SP2 is the sync page but SP2.gfn is writable.

This bug will corrupt guest's page table, fixed by mark read-only mapping
if the mapped gfn has shadow pages.

Signed-off-by: Xiao Guangrong <xiaoguangrong@cn.fujitsu.com>
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
14 years agoKVM: VMX: Execute WBINVD to keep data consistency with assigned devices
Sheng Yang [Wed, 30 Jun 2010 04:25:15 +0000 (12:25 +0800)] 
KVM: VMX: Execute WBINVD to keep data consistency with assigned devices

Some guest device driver may leverage the "Non-Snoop" I/O, and explicitly
WBINVD or CLFLUSH to a RAM space. Since migration may occur before WBINVD or
CLFLUSH, we need to maintain data consistency either by:
1: flushing cache (wbinvd) when the guest is scheduled out if there is no
wbinvd exit, or
2: execute wbinvd on all dirty physical CPUs when guest wbinvd exits.

Signed-off-by: Yaozu (Eddie) Dong <eddie.dong@intel.com>
Signed-off-by: Sheng Yang <sheng@linux.intel.com>
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
14 years agoKVM: Document KVM specific review items
Avi Kivity [Thu, 24 Jun 2010 11:10:09 +0000 (14:10 +0300)] 
KVM: Document KVM specific review items

Signed-off-by: Avi Kivity <avi@redhat.com>
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
14 years agoKVM: Simplify vcpu_enter_guest() mmu reload logic slightly
Avi Kivity [Wed, 23 Jun 2010 11:26:18 +0000 (14:26 +0300)] 
KVM: Simplify vcpu_enter_guest() mmu reload logic slightly

No need to reload the mmu in between two different vcpu->requests checks.

kvm_mmu_reload() may trigger KVM_REQ_TRIPLE_FAULT, but that will be caught
during atomic guest entry later.

Signed-off-by: Avi Kivity <avi@redhat.com>
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
14 years agoKVM: Search the LAPIC's for one that will accept a PIC interrupt
Chris Lalancette [Mon, 21 Jun 2010 15:29:40 +0000 (11:29 -0400)] 
KVM: Search the LAPIC's for one that will accept a PIC interrupt

Older versions of 32-bit linux have a "Checking 'hlt' instruction"
test where they repeatedly call the 'hlt' instruction, and then
expect a timer interrupt to kick the CPU out of halt.  This happens
before any LAPIC or IOAPIC setup happens, which means that all of
the APIC's are in virtual wire mode at this point.  Unfortunately,
the current implementation of virtual wire mode is hardcoded to
only kick the BSP, so if a crash+kexec occurs on a different
vcpu, it will never get kicked.

This patch makes pic_unlock() do the equivalent of
kvm_irq_delivery_to_apic() for the IOAPIC code.  That is, it runs
through all of the vcpus looking for one that is in virtual wire
mode.  In the normal case where LAPICs and IOAPICs are configured,
this won't be used at all.  In the bootstrap phase of a modern
OS, before the LAPICs and IOAPICs are configured, this will have
exactly the same behavior as today; VCPU0 is always looked at
first, so it will always get out of the loop after the first
iteration.  This will only go through the loop more than once
during a kexec/kdump, in which case it will only do it a few times
until the kexec'ed kernel programs the LAPIC and IOAPIC.

Signed-off-by: Chris Lalancette <clalance@redhat.com>
Signed-off-by: Avi Kivity <avi@redhat.com>
14 years agoKVM: ia64: cleanup kvm_ia64_sync_dirty_log()
Takuya Yoshikawa [Wed, 23 Jun 2010 06:00:29 +0000 (15:00 +0900)] 
KVM: ia64: cleanup kvm_ia64_sync_dirty_log()

kvm_ia64_sync_dirty_log() is a helper function for kvm_vm_ioctl_get_dirty_log()
which copies ia64's arch specific dirty bitmap to general one in memslot.
So doing sanity checks in this function is unnatural. We move these checks
outside of this and change the prototype appropriately.

Signed-off-by: Takuya Yoshikawa <yoshikawa.takuya@oss.ntt.co.jp>
Signed-off-by: Avi Kivity <avi@redhat.com>
14 years agoKVM: ia64: fix dirty_log_lock spin_lock section not to include get_dirty_log()
Takuya Yoshikawa [Wed, 23 Jun 2010 05:59:29 +0000 (14:59 +0900)] 
KVM: ia64: fix dirty_log_lock spin_lock section not to include get_dirty_log()

kvm_get_dirty_log() calls copy_to_user(). So we need to narrow the
dirty_log_lock spin_lock section not to include this.

Signed-off-by: Takuya Yoshikawa <yoshikawa.takuya@oss.ntt.co.jp>
Signed-off-by: Avi Kivity <avi@redhat.com>
14 years agoKVM: PPC: Make BAT only guest segments work
Alexander Graf [Mon, 21 Jun 2010 13:24:55 +0000 (15:24 +0200)] 
KVM: PPC: Make BAT only guest segments work

When a guest sets its SR entry to invalid, we may still find a
corresponding entry in a BAT. So we need to make sure we're not
faulting on invalid SR entries, but instead just claim them to be
BAT resolved.

This resolves breakage experienced when using libogc based guests.

Signed-off-by: Alexander Graf <agraf@suse.de>
Signed-off-by: Avi Kivity <avi@redhat.com>
14 years agoKVM: PPC: Use kernel hash function
Alexander Graf [Mon, 21 Jun 2010 13:25:19 +0000 (15:25 +0200)] 
KVM: PPC: Use kernel hash function

The linux kernel already provides a hash function. Let's reuse that
instead of reinventing the wheel!

Signed-off-by: Alexander Graf <agraf@suse.de>
Signed-off-by: Avi Kivity <avi@redhat.com>
14 years agoKVM: PPC: Remove obsolete kvmppc_mmu_find_pte
Alexander Graf [Mon, 21 Jun 2010 13:25:40 +0000 (15:25 +0200)] 
KVM: PPC: Remove obsolete kvmppc_mmu_find_pte

Initially we had to search for pte entries to invalidate them. Since
the logic has improved since then, we can just get rid of the search
function.

Signed-off-by: Alexander Graf <agraf@suse.de>
Signed-off-by: Avi Kivity <avi@redhat.com>
14 years agoKVM: Fix a race condition for usage of is_hwpoison_address()
Huang Ying [Tue, 22 Jun 2010 06:23:11 +0000 (14:23 +0800)] 
KVM: Fix a race condition for usage of is_hwpoison_address()

is_hwpoison_address accesses the page table, so the caller must hold
current->mm->mmap_sem in read mode. So fix its usage in hva_to_pfn of
kvm accordingly.

Comment is_hwpoison_address to remind other users.

Reported-by: Avi Kivity <avi@redhat.com>
Signed-off-by: Huang Ying <ying.huang@intel.com>
Signed-off-by: Avi Kivity <avi@redhat.com>
14 years agoKVM: x86: Enable AVX for guest
Sheng Yang [Tue, 22 Jun 2010 05:49:21 +0000 (13:49 +0800)] 
KVM: x86: Enable AVX for guest

Enable Intel(R) Advanced Vector Extension(AVX) for guest.

The detection of AVX feature includes OSXSAVE bit testing. When OSXSAVE bit is
not set, even if AVX is supported, the AVX instruction would result in UD as
well. So we're safe to expose AVX bits to guest directly.

Signed-off-by: Sheng Yang <sheng@linux.intel.com>
Signed-off-by: Avi Kivity <avi@redhat.com>
14 years agoKVM: Prevent internal slots from being COWed
Avi Kivity [Mon, 21 Jun 2010 07:57:45 +0000 (10:57 +0300)] 
KVM: Prevent internal slots from being COWed

If a process with a memory slot is COWed, the page will change its address
(despite having an elevated reference count).  This breaks internal memory
slots which have their physical addresses loaded into vmcs registers (see
the APIC access memory slot).

Signed-off-by: Avi Kivity <avi@redhat.com>
14 years agoKVM: Keep slot ID in memory slot structure
Avi Kivity [Mon, 21 Jun 2010 07:56:36 +0000 (10:56 +0300)] 
KVM: Keep slot ID in memory slot structure

May be used for distinguishing between internal and user slots, or for sorting
slots in size order.

Signed-off-by: Avi Kivity <avi@redhat.com>
14 years agoKVM: Reduce atomic operations on vcpu->requests
Avi Kivity [Mon, 10 May 2010 10:08:26 +0000 (13:08 +0300)] 
KVM: Reduce atomic operations on vcpu->requests

Usually the vcpu->requests bitmap is sparse, so a test_and_clear_bit() for
each request generates a large number of unneeded atomics if a bit is set.

Replace with a separate test/clear sequence.  This is safe since there is
no clear_bit() outside the vcpu thread.

Signed-off-by: Avi Kivity <avi@redhat.com>
14 years agoKVM: Add mini-API for vcpu->requests
Avi Kivity [Mon, 10 May 2010 09:34:53 +0000 (12:34 +0300)] 
KVM: Add mini-API for vcpu->requests

Makes it a little more readable and hackable.

Signed-off-by: Avi Kivity <avi@redhat.com>
14 years agoKVM: i8259: simplify pic_irq_request() calling sequence
Avi Kivity [Mon, 3 May 2010 14:38:06 +0000 (17:38 +0300)] 
KVM: i8259: simplify pic_irq_request() calling sequence

Signed-off-by: Avi Kivity <avi@redhat.com>
14 years agoKVM: i8259: reduce excessive abstraction for pic_irq_request()
Avi Kivity [Mon, 3 May 2010 14:34:34 +0000 (17:34 +0300)] 
KVM: i8259: reduce excessive abstraction for pic_irq_request()

Part of the i8259 code pretends it isn't part of kvm, but we know better.
Reduce excessive abstraction, eliminating callbacks and void pointers.

Signed-off-by: Avi Kivity <avi@redhat.com>
14 years agoKVM: Remove kernel-allocated memory regions
Avi Kivity [Mon, 21 Jun 2010 08:48:05 +0000 (11:48 +0300)] 
KVM: Remove kernel-allocated memory regions

Equivalent (and better) functionality is provided by user-allocated memory
regions.

Signed-off-by: Avi Kivity <avi@redhat.com>
14 years agoKVM: Remove memory alias support
Avi Kivity [Mon, 21 Jun 2010 08:44:20 +0000 (11:44 +0300)] 
KVM: Remove memory alias support

As advertised in feature-removal-schedule.txt.  Equivalent support is provided
by overlapping memory regions.

Signed-off-by: Avi Kivity <avi@redhat.com>
14 years agoKVM: s390: Don't exit SIE on SIGP sense running
Christian Borntraeger [Thu, 17 Jun 2010 21:16:20 +0000 (23:16 +0200)] 
KVM: s390: Don't exit SIE on SIGP sense running

Newer (guest) kernels use sigp sense running in their spinlock
implementation to check if the other cpu is running before yielding
the processor. This revealed some wrong guest settings, causing
unnecessary exits for every sigp sense running.

Signed-off-by: Christian Borntraeger <borntraeger@de.ibm.com>
Signed-off-by: Avi Kivity <avi@redhat.com>
14 years agoKVM: s390: Fix build failure due to centralized vcpu locking patches
Christian Borntraeger [Sat, 12 Jun 2010 06:54:13 +0000 (08:54 +0200)] 
KVM: s390: Fix build failure due to centralized vcpu locking patches

This patch fixes
ERROR: "__kvm_s390_vcpu_store_status" [arch/s390/kvm/kvm.ko] undefined!

triggered by
commit 3268c56840dcee78c3e928336550f4e1861504c4 (kvm.git)
Author: Avi Kivity <avi@redhat.com>
Date:   Thu May 13 12:21:46 2010 +0300
    KVM: s390: Centrally lock arch specific vcpu ioctls

Reported-by: Sachin Sant <sachinp@in.ibm.com>
Signed-off-by: Christian Borntraeger <borntraeger@de.ibm.com>
Signed-off-by: Avi Kivity <avi@redhat.com>
14 years agoKVM: Consolidate load/save temporary buffer allocation and freeing
Avi Kivity [Sun, 20 Jun 2010 12:54:43 +0000 (15:54 +0300)] 
KVM: Consolidate load/save temporary buffer allocation and freeing

Instead of three temporary variables and three free calls, have one temporary
variable (with four names) and one free call.

Signed-off-by: Avi Kivity <avi@redhat.com>
14 years agoKVM: Fix xsave and xcr save/restore memory leak
Avi Kivity [Sun, 20 Jun 2010 12:47:34 +0000 (15:47 +0300)] 
KVM: Fix xsave and xcr save/restore memory leak

We allocate temporary kernel buffers for these structures, but never free them.

Signed-off-by: Avi Kivity <avi@redhat.com>
14 years agoKVM: x86 emulator: fix group3 instruction decoding
Wei Yongjun [Thu, 17 Jun 2010 09:33:55 +0000 (17:33 +0800)] 
KVM: x86 emulator: fix group3 instruction decoding

Group 3 instruction with ModRM reg field as 001 is
defined as test instruction under AMD arch, and
emulate_grp3() is ready for emulate it, so fix the
decoding.

static inline int emulate_grp3(...)
{
...
switch (c->modrm_reg) {
case 0 ... 1:   /* test */
emulate_2op_SrcV("test", c->src, c->dst, ctxt->eflags);
...
}

Signed-off-by: Wei Yongjun <yjwei@cn.fujitsu.com>
Signed-off-by: Avi Kivity <avi@redhat.com>
14 years agoKVM: PPC: fix uninitialized variable warning in kvm_ppc_core_deliver_interrupts
Asias He [Sat, 19 Jun 2010 08:52:12 +0000 (16:52 +0800)] 
KVM: PPC: fix uninitialized variable warning in kvm_ppc_core_deliver_interrupts

Fixes:
arch/powerpc/kvm/booke.c: In function 'kvmppc_core_deliver_interrupts':
arch/powerpc/kvm/booke.c:147: warning: 'msr_mask' may be used uninitialized in this function

Signed-off-by: Asias He <asias.hejun@gmail.com>
Signed-off-by: Avi Kivity <avi@redhat.com>
14 years agoKVM: Fix typos in Documentation/kvm/mmu.txt
Jason Wang [Thu, 17 Jun 2010 08:49:22 +0000 (16:49 +0800)] 
KVM: Fix typos in Documentation/kvm/mmu.txt

Signed-off-by: Jason Wang <jasowang@redhat.com>
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
14 years agoKVM: x86: In DM_LOWEST, only deliver interrupts to vcpus with enabled LAPIC's
Chris Lalancette [Wed, 16 Jun 2010 21:11:13 +0000 (17:11 -0400)] 
KVM: x86: In DM_LOWEST, only deliver interrupts to vcpus with enabled LAPIC's

Otherwise we might try to deliver a timer interrupt to a cpu that
can't possibly handle it.

Signed-off-by: Chris Lalancette <clalance@redhat.com>
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
14 years agoKVM: x86: Allow any LAPIC to accept PIC interrupts
Chris Lalancette [Wed, 16 Jun 2010 21:11:12 +0000 (17:11 -0400)] 
KVM: x86: Allow any LAPIC to accept PIC interrupts

If the guest wants to accept timer interrupts on a CPU other
than the BSP, we need to remove this gate.

Signed-off-by: Chris Lalancette <clalance@redhat.com>
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
14 years agoKVM: x86: Introduce a workqueue to deliver PIT timer interrupts
Chris Lalancette [Wed, 16 Jun 2010 21:11:11 +0000 (17:11 -0400)] 
KVM: x86: Introduce a workqueue to deliver PIT timer interrupts

We really want to "kvm_set_irq" during the hrtimer callback,
but that is risky because that is during interrupt context.
Instead, offload the work to a workqueue, which is a bit safer
and should provide most of the same functionality.

Signed-off-by: Chris Lalancette <clalance@redhat.com>
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
14 years agoKVM: x86 emulator: fix pusha instruction emulation
Wei Yongjun [Tue, 15 Jun 2010 01:03:33 +0000 (09:03 +0800)] 
KVM: x86 emulator: fix pusha instruction emulation

emulate pusha instruction only writeback the last
EDI register, but the other registers which need
to be writeback is ignored. This patch fixed it.

Signed-off-by: Wei Yongjun <yjwei@cn.fujitsu.com>
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
14 years agoKVM: x86: fix -DDEBUG oops
Zachary Amsden [Mon, 14 Jun 2010 21:42:15 +0000 (11:42 -1000)] 
KVM: x86: fix -DDEBUG oops

Fix a slight error with assertion in local APIC code.

Signed-off-by: Zachary Amsden <zamsden@redhat.com>
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
14 years agoKVM: MMU: don't walk every parent pages while mark unsync
Xiao Guangrong [Fri, 11 Jun 2010 13:35:15 +0000 (21:35 +0800)] 
KVM: MMU: don't walk every parent pages while mark unsync

While we mark the parent's unsync_child_bitmap, if the parent is already
unsynced, it no need walk it's parent, it can reduce some unnecessary
workload

Signed-off-by: Xiao Guangrong <xiaoguangrong@cn.fujitsu.com>
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
14 years agoKVM: MMU: clear unsync_child_bitmap completely
Xiao Guangrong [Fri, 11 Jun 2010 13:34:04 +0000 (21:34 +0800)] 
KVM: MMU: clear unsync_child_bitmap completely

In current code, some page's unsync_child_bitmap is not cleared completely
in mmu_sync_children(), for example, if two PDPEs shard one PDT, one of
PDPE's unsync_child_bitmap is not cleared.

Currently, it not harm anything just little overload, but it's the prepare
work for the later patch

Signed-off-by: Xiao Guangrong <xiaoguangrong@cn.fujitsu.com>
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
14 years agoKVM: MMU: cleanup for __mmu_unsync_walk()
Xiao Guangrong [Fri, 11 Jun 2010 13:32:34 +0000 (21:32 +0800)] 
KVM: MMU: cleanup for __mmu_unsync_walk()

Decrease sp->unsync_children after clear unsync_child_bitmap bit

Signed-off-by: Xiao Guangrong <xiaoguangrong@cn.fujitsu.com>
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
14 years agoKVM: MMU: don't mark pte notrap if it's just sync transient
Xiao Guangrong [Fri, 11 Jun 2010 13:31:38 +0000 (21:31 +0800)] 
KVM: MMU: don't mark pte notrap if it's just sync transient

If the sync-sp just sync transient, don't mark its pte notrap

Signed-off-by: Xiao Guangrong <xiaoguangrong@cn.fujitsu.com>
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
14 years agoKVM: MMU: avoid double write protected in sync page path
Xiao Guangrong [Fri, 11 Jun 2010 13:30:36 +0000 (21:30 +0800)] 
KVM: MMU: avoid double write protected in sync page path

The sync page is already write protected in mmu_sync_children(), don't
write protected it again

Signed-off-by: Xiao Guangrong <xiaoguangrong@cn.fujitsu.com>
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
14 years agoKVM: MMU: cleanup for dirty page judgment
Xiao Guangrong [Fri, 11 Jun 2010 13:29:42 +0000 (21:29 +0800)] 
KVM: MMU: cleanup for dirty page judgment

Using wrap function to cleanup page dirty judgment

Signed-off-by: Xiao Guangrong <xiaoguangrong@cn.fujitsu.com>
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
14 years agoKVM: MMU: rename 'page' and 'shadow_page' to 'sp'
Xiao Guangrong [Fri, 11 Jun 2010 13:28:14 +0000 (21:28 +0800)] 
KVM: MMU: rename 'page' and 'shadow_page' to 'sp'

Rename 'page' and 'shadow_page' to 'sp' to better fit the context

Signed-off-by: Xiao Guangrong <xiaoguangrong@cn.fujitsu.com>
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
14 years agoKVM: x86: XSAVE/XRSTOR live migration support
Sheng Yang [Sun, 13 Jun 2010 09:29:39 +0000 (17:29 +0800)] 
KVM: x86: XSAVE/XRSTOR live migration support

This patch enable save/restore of xsave state.

Signed-off-by: Sheng Yang <sheng@linux.intel.com>
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
14 years agoKVM: PPC: fix build warning in kvm_arch_vcpu_ioctl_run
Denis Kirjanov [Fri, 11 Jun 2010 11:23:26 +0000 (11:23 +0000)] 
KVM: PPC: fix build warning in kvm_arch_vcpu_ioctl_run

Fix compile warning:
  CC [M]  arch/powerpc/kvm/powerpc.o
  arch/powerpc/kvm/powerpc.c: In function 'kvm_arch_vcpu_ioctl_run':
  arch/powerpc/kvm/powerpc.c:290: warning: 'gpr' may be used uninitialized in this function
  arch/powerpc/kvm/powerpc.c:290: note: 'gpr' was declared here

Signed-off-by: Denis Kirjanov <dkirjanov@kernel.org>
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
14 years agoKVM: Fix mov cr3 #GP at wrong instruction
Avi Kivity [Thu, 10 Jun 2010 14:02:16 +0000 (17:02 +0300)] 
KVM: Fix mov cr3 #GP at wrong instruction

On Intel, we call skip_emulated_instruction() even if we injected a #GP,
resulting in the #GP pointing at the wrong address.

Fix by injecting the exception and skipping the instruction at the same place,
so we can do just one or the other.

Signed-off-by: Avi Kivity <avi@redhat.com>
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
14 years agoKVM: Fix mov cr4 #GP at wrong instruction
Avi Kivity [Thu, 10 Jun 2010 14:02:15 +0000 (17:02 +0300)] 
KVM: Fix mov cr4 #GP at wrong instruction

On Intel, we call skip_emulated_instruction() even if we injected a #GP,
resulting in the #GP pointing at the wrong address.

Fix by injecting the exception and skipping the instruction at the same place,
so we can do just one or the other.

Signed-off-by: Avi Kivity <avi@redhat.com>
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
14 years agoKVM: Fix mov cr0 #GP at wrong instruction
Avi Kivity [Thu, 10 Jun 2010 14:02:14 +0000 (17:02 +0300)] 
KVM: Fix mov cr0 #GP at wrong instruction

On Intel, we call skip_emulated_instruction() even if we injected a #GP,
resulting in the #GP pointing at the wrong address.

Fix by injecting the exception and skipping the instruction at the same place,
so we can do just one or the other.

Signed-off-by: Avi Kivity <avi@redhat.com>
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
14 years agoKVM: VMX: Enable XSAVE/XRSTOR for guest
Dexuan Cui [Thu, 10 Jun 2010 03:27:12 +0000 (11:27 +0800)] 
KVM: VMX: Enable XSAVE/XRSTOR for guest

This patch enable guest to use XSAVE/XRSTOR instructions.

We assume that host_xcr0 would use all possible bits that OS supported.

And we loaded xcr0 in the same way we handled fpu - do it as late as we can.

Signed-off-by: Dexuan Cui <dexuan.cui@intel.com>
Signed-off-by: Sheng Yang <sheng@linux.intel.com>
Reviewed-by: Marcelo Tosatti <mtosatti@redhat.com>
Signed-off-by: Avi Kivity <avi@redhat.com>
14 years agoKVM: VMX: Fix incorrect rcu deref in rmode_tss_base()
Avi Kivity [Thu, 10 Jun 2010 14:21:29 +0000 (17:21 +0300)] 
KVM: VMX: Fix incorrect rcu deref in rmode_tss_base()

Signed-off-by: Avi Kivity <avi@redhat.com>
14 years agoKVM: Fix unused but set warnings
Andi Kleen [Thu, 10 Jun 2010 11:10:55 +0000 (13:10 +0200)] 
KVM: Fix unused but set warnings

No real bugs in this one.

Signed-off-by: Andi Kleen <ak@linux.intel.com>
Signed-off-by: Avi Kivity <avi@redhat.com>
14 years agoKVM: Fix KVM_SET_SIGNAL_MASK with arg == NULL
Andi Kleen [Thu, 10 Jun 2010 11:10:47 +0000 (13:10 +0200)] 
KVM: Fix KVM_SET_SIGNAL_MASK with arg == NULL

When the user passed in a NULL mask pass this on from the ioctl
handler.

Found by gcc 4.6's new warnings.

Signed-off-by: Andi Kleen <ak@linux.intel.com>
Signed-off-by: Avi Kivity <avi@redhat.com>
14 years agoKVM: MMU: delay local tlb flush
Xiao Guangrong [Tue, 8 Jun 2010 12:07:01 +0000 (20:07 +0800)] 
KVM: MMU: delay local tlb flush

delay local tlb flush until enter guest moden, it can reduce vpid flush
frequency and reduce remote tlb flush IPI(if KVM_REQ_TLB_FLUSH bit is
already set, IPI is not sent)

Signed-off-by: Xiao Guangrong <xiaoguangrong@cn.fujitsu.com>
Signed-off-by: Avi Kivity <avi@redhat.com>
14 years agoKVM: MMU: use wrapper function to flush local tlb
Xiao Guangrong [Tue, 8 Jun 2010 12:05:57 +0000 (20:05 +0800)] 
KVM: MMU: use wrapper function to flush local tlb

Use kvm_mmu_flush_tlb() function instead of calling
kvm_x86_ops->tlb_flush(vcpu) directly.

Signed-off-by: Xiao Guangrong <xiaoguangrong@cn.fujitsu.com>
Signed-off-by: Avi Kivity <avi@redhat.com>
14 years agoKVM: MMU: remove unnecessary remote tlb flush
Xiao Guangrong [Tue, 8 Jun 2010 12:05:05 +0000 (20:05 +0800)] 
KVM: MMU: remove unnecessary remote tlb flush

This remote tlb flush is no necessary since we have synced while
sp is zapped

Signed-off-by: Xiao Guangrong <xiaoguangrong@cn.fujitsu.com>
Signed-off-by: Avi Kivity <avi@redhat.com>
14 years agoKVM: VMX: fix rcu usage warning in init_rmode()
Xiao Guangrong [Tue, 8 Jun 2010 02:15:51 +0000 (10:15 +0800)] 
KVM: VMX: fix rcu usage warning in init_rmode()

fix:

[ INFO: suspicious rcu_dereference_check() usage. ]
---------------------------------------------------
include/linux/kvm_host.h:258 invoked rcu_dereference_check() without protection!

other info that might help us debug this:

rcu_scheduler_active = 1, debug_locks = 1
1 lock held by qemu-system-x86/3796:
 #0:  (&vcpu->mutex){+.+.+.}, at: [<ffffffffa0217fd8>] vcpu_load+0x1a/0x66 [kvm]

stack backtrace:
Pid: 3796, comm: qemu-system-x86 Not tainted 2.6.34 #25
Call Trace:
 [<ffffffff81070ed1>] lockdep_rcu_dereference+0x9d/0xa5
 [<ffffffffa0214fdf>] gfn_to_memslot_unaliased+0x65/0xa0 [kvm]
 [<ffffffffa0216139>] gfn_to_hva+0x22/0x4c [kvm]
 [<ffffffffa0216217>] kvm_write_guest_page+0x2a/0x7f [kvm]
 [<ffffffffa0216286>] kvm_clear_guest_page+0x1a/0x1c [kvm]
 [<ffffffffa0278239>] init_rmode+0x3b/0x180 [kvm_intel]
 [<ffffffffa02786ce>] vmx_set_cr0+0x350/0x4d3 [kvm_intel]
 [<ffffffffa02274ff>] kvm_arch_vcpu_ioctl_set_sregs+0x122/0x31a [kvm]
 [<ffffffffa021859c>] kvm_vcpu_ioctl+0x578/0xa3d [kvm]
 [<ffffffff8106624c>] ? cpu_clock+0x2d/0x40
 [<ffffffff810f7d86>] ? fget_light+0x244/0x28e
 [<ffffffff810709b9>] ? trace_hardirqs_off_caller+0x1f/0x10e
 [<ffffffff8110501b>] vfs_ioctl+0x32/0xa6
 [<ffffffff81105597>] do_vfs_ioctl+0x47f/0x4b8
 [<ffffffff813ae654>] ? sub_preempt_count+0xa3/0xb7
 [<ffffffff810f7da8>] ? fget_light+0x266/0x28e
 [<ffffffff810f7c53>] ? fget_light+0x111/0x28e
 [<ffffffff81105617>] sys_ioctl+0x47/0x6a
 [<ffffffff81002c1b>] system_call_fastpath+0x16/0x1b

Signed-off-by: Xiao Guangrong <xiaoguangrong@cn.fujitsu.com>
Signed-off-by: Avi Kivity <avi@redhat.com>
14 years agoKVM: VMX: rename vpid_sync_vcpu_all() to vpid_sync_vcpu_single()
Gui Jianfeng [Mon, 7 Jun 2010 02:33:27 +0000 (10:33 +0800)] 
KVM: VMX: rename vpid_sync_vcpu_all() to vpid_sync_vcpu_single()

The name "pid_sync_vcpu_all" isn't appropriate since it just affect
a single vpid, so rename it to vpid_sync_vcpu_single().

Signed-off-by: Gui Jianfeng <guijianfeng@cn.fujitsu.com>
Signed-off-by: Avi Kivity <avi@redhat.com>
14 years agoKVM: VMX: Add all-context INVVPID type support
Gui Jianfeng [Mon, 7 Jun 2010 02:32:29 +0000 (10:32 +0800)] 
KVM: VMX: Add all-context INVVPID type support

Add all-context INVVPID type support.

Signed-off-by: Gui Jianfeng <guijianfeng@cn.fujitsu.com>
Signed-off-by: Avi Kivity <avi@redhat.com>
14 years agoKVM: MMU: reduce remote tlb flush in kvm_mmu_pte_write()
Xiao Guangrong [Fri, 4 Jun 2010 13:56:59 +0000 (21:56 +0800)] 
KVM: MMU: reduce remote tlb flush in kvm_mmu_pte_write()

collect remote tlb flush in kvm_mmu_pte_write() path

Signed-off-by: Xiao Guangrong <xiaoguangrong@cn.fujitsu.com>
Signed-off-by: Avi Kivity <avi@redhat.com>
14 years agoKVM: MMU: traverse sp hlish safely
Xiao Guangrong [Fri, 4 Jun 2010 13:56:11 +0000 (21:56 +0800)] 
KVM: MMU: traverse sp hlish safely

Now, we can safely to traverse sp hlish

Signed-off-by: Xiao Guangrong <xiaoguangrong@cn.fujitsu.com>
Signed-off-by: Avi Kivity <avi@redhat.com>
14 years agoKVM: MMU: gather remote tlb flush which occurs during page zapped
Xiao Guangrong [Fri, 4 Jun 2010 13:55:29 +0000 (21:55 +0800)] 
KVM: MMU: gather remote tlb flush which occurs during page zapped

Using kvm_mmu_prepare_zap_page() and kvm_mmu_zap_page() instead of
kvm_mmu_zap_page() that can reduce remote tlb flush IPI

Signed-off-by: Xiao Guangrong <xiaoguangrong@cn.fujitsu.com>
Signed-off-by: Avi Kivity <avi@redhat.com>
14 years agoKVM: MMU: don't get free page number in the loop
Xiao Guangrong [Fri, 4 Jun 2010 13:54:38 +0000 (21:54 +0800)] 
KVM: MMU: don't get free page number in the loop

In the later patch, we will modify sp's zapping way like below:

kvm_mmu_prepare_zap_page A
kvm_mmu_prepare_zap_page B
kvm_mmu_prepare_zap_page C
....
kvm_mmu_commit_zap_page

[ zaped multiple sps only need to call kvm_mmu_commit_zap_page once ]

In __kvm_mmu_free_some_pages() function, the free page number is
getted form 'vcpu->kvm->arch.n_free_mmu_pages' in loop, it will
hinders us to apply kvm_mmu_prepare_zap_page() and kvm_mmu_commit_zap_page()
since kvm_mmu_prepare_zap_page() not free sp.

Signed-off-by: Xiao Guangrong <xiaoguangrong@cn.fujitsu.com>
Signed-off-by: Avi Kivity <avi@redhat.com>
14 years agoKVM: MMU: split the operations of kvm_mmu_zap_page()
Xiao Guangrong [Fri, 4 Jun 2010 13:53:54 +0000 (21:53 +0800)] 
KVM: MMU: split the operations of kvm_mmu_zap_page()

Using kvm_mmu_prepare_zap_page() and kvm_mmu_commit_zap_page() to
split kvm_mmu_zap_page() function, then we can:

- traverse hlist safely
- easily to gather remote tlb flush which occurs during page zapped

Those feature can be used in the later patches

Signed-off-by: Xiao Guangrong <xiaoguangrong@cn.fujitsu.com>
Signed-off-by: Avi Kivity <avi@redhat.com>
14 years agoKVM: MMU: introduce some macros to cleanup hlist traverseing
Xiao Guangrong [Fri, 4 Jun 2010 13:53:07 +0000 (21:53 +0800)] 
KVM: MMU: introduce some macros to cleanup hlist traverseing

Introduce for_each_gfn_sp() and for_each_gfn_indirect_valid_sp() to
cleanup hlist traverseing

Signed-off-by: Xiao Guangrong <xiaoguangrong@cn.fujitsu.com>
Signed-off-by: Avi Kivity <avi@redhat.com>
14 years agoKVM: MMU: skip invalid sp when unprotect page
Xiao Guangrong [Fri, 4 Jun 2010 13:52:17 +0000 (21:52 +0800)] 
KVM: MMU: skip invalid sp when unprotect page

In kvm_mmu_unprotect_page(), the invalid sp can be skipped

Signed-off-by: Xiao Guangrong <xiaoguangrong@cn.fujitsu.com>
Signed-off-by: Avi Kivity <avi@redhat.com>
14 years agoKVM: VMX: Make sure single type invvpid is supported before issuing invvpid instruction
Gui Jianfeng [Fri, 4 Jun 2010 00:51:39 +0000 (08:51 +0800)] 
KVM: VMX: Make sure single type invvpid is supported before issuing invvpid instruction

According to SDM, we need check whether single-context INVVPID type is supported
before issuing invvpid instruction.

Signed-off-by: Gui Jianfeng <guijianfeng@cn.fujitsu.com>
Reviewed-by: Sheng Yang <sheng@linux.intel.com>
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
14 years agoKVM: x86: use linux/uaccess.h instead of asm/uaccess.h
Lai Jiangshan [Wed, 2 Jun 2010 09:06:03 +0000 (17:06 +0800)] 
KVM: x86: use linux/uaccess.h instead of asm/uaccess.h

Should use linux/uaccess.h instead of asm/uaccess.h

Signed-off-by: Lai Jiangshan <laijs@cn.fujitsu.com>
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
14 years agoKVM: cleanup "*new.rmap" type
Lai Jiangshan [Wed, 2 Jun 2010 09:01:23 +0000 (17:01 +0800)] 
KVM: cleanup "*new.rmap" type

The type of '*new.rmap' is not 'struct page *', fix it

Signed-off-by: Lai Jiangshan <laijs@cn.fujitsu.com>
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
14 years agoKVM: VMX: Enforce EPT pagetable level checking
Sheng Yang [Wed, 2 Jun 2010 06:05:24 +0000 (14:05 +0800)] 
KVM: VMX: Enforce EPT pagetable level checking

We only support 4 levels EPT pagetable now.

Signed-off-by: Sheng Yang <sheng@linux.intel.com>
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
14 years agoKVM: Add Documentation/kvm/msr.txt
Glauber Costa [Tue, 1 Jun 2010 12:22:48 +0000 (08:22 -0400)] 
KVM: Add Documentation/kvm/msr.txt

This patch adds a file that documents the usage of KVM-specific
MSRs.

Signed-off-by: Glauber Costa <glommer@redhat.com>
Reviewed-by: Randy Dunlap <randy.dunlap@oracle.com>
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
14 years agoKVM: PPC: elide struct thread_struct instances from stack
Andreas Schwab [Mon, 31 May 2010 19:59:13 +0000 (21:59 +0200)] 
KVM: PPC: elide struct thread_struct instances from stack

Instead of instantiating a whole thread_struct on the stack use only the
required parts of it.

Signed-off-by: Andreas Schwab <schwab@linux-m68k.org>
Tested-by: Alexander Graf <agraf@suse.de>
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
14 years agoKVM: VMX: Properly return error to userspace on vmentry failure
Mohammed Gamal [Mon, 31 May 2010 19:40:54 +0000 (22:40 +0300)] 
KVM: VMX: Properly return error to userspace on vmentry failure

The vmexit handler returns KVM_EXIT_UNKNOWN since there is no handler
for vmentry failures. This intercepts vmentry failures and returns
KVM_FAIL_ENTRY to userspace instead.

Signed-off-by: Mohammed Gamal <m.gamal005@gmail.com>
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
14 years agoKVM: MMU: Don't calculate quadrant if tdp_enabled
Gui Jianfeng [Mon, 31 May 2010 09:11:39 +0000 (17:11 +0800)] 
KVM: MMU: Don't calculate quadrant if tdp_enabled

There's no need to calculate quadrant if tdp is enabled.

Signed-off-by: Gui Jianfeng <guijianfeng@cn.fujitsu.com>
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
14 years agoKVM: MMU: Document large pages
Avi Kivity [Thu, 27 May 2010 13:44:12 +0000 (16:44 +0300)] 
KVM: MMU: Document large pages

Signed-off-by: Avi Kivity <avi@redhat.com>
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
14 years agoKVM: MMU: Document cr0.wp emulation
Avi Kivity [Thu, 27 May 2010 11:46:04 +0000 (14:46 +0300)] 
KVM: MMU: Document cr0.wp emulation

Signed-off-by: Avi Kivity <avi@redhat.com>
14 years agoKVM: MMU: Allow spte.w=1 for gpte.w=0 and cr0.wp=0 only in shadow mode
Avi Kivity [Thu, 27 May 2010 11:22:51 +0000 (14:22 +0300)] 
KVM: MMU: Allow spte.w=1 for gpte.w=0 and cr0.wp=0 only in shadow mode

When tdp is enabled, the guest's cr0.wp shouldn't have any effect on spte
permissions.

Signed-off-by: Avi Kivity <avi@redhat.com>
14 years agoKVM: x86: Propagate fpu_alloc errors
Jan Kiszka [Tue, 25 May 2010 14:01:50 +0000 (16:01 +0200)] 
KVM: x86: Propagate fpu_alloc errors

Memory allocation may fail. Propagate such errors.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
Reviewed-by: Sheng Yang <sheng@linux.intel.com>
Signed-off-by: Avi Kivity <avi@redhat.com>
14 years agoKVM: SVM: Fix EFER.LME being stripped
Zachary Amsden [Thu, 27 May 2010 01:09:43 +0000 (15:09 -1000)] 
KVM: SVM: Fix EFER.LME being stripped

Must set VCPU register to be the guest notion of EFER even if that
setting is not valid on hardware.  This was masked by the set in
set_efer until 7657fd5ace88e8092f5f3a84117e093d7b893f26 broke that.
Fix is simply to set the VCPU register before stripping bits.

Signed-off-by: Zachary Amsden <zamsden@redhat.com>
Signed-off-by: Avi Kivity <avi@redhat.com>
14 years agoKVM: MMU: don't check PT_WRITABLE_MASK directly
Gui Jianfeng [Thu, 27 May 2010 08:09:48 +0000 (16:09 +0800)] 
KVM: MMU: don't check PT_WRITABLE_MASK directly

Since we have is_writable_pte(), make use of it.

Signed-off-by: Gui Jianfeng <guijianfeng@cn.fujitsu.com>
Signed-off-by: Avi Kivity <avi@redhat.com>
14 years agoKVM: MMU: calculate correct gfn for small host pages backing large guest pages
Lai Jiangshan [Wed, 26 May 2010 08:48:19 +0000 (16:48 +0800)] 
KVM: MMU: calculate correct gfn for small host pages backing large guest pages

In Documentation/kvm/mmu.txt:
  gfn:
    Either the guest page table containing the translations shadowed by this
    page, or the base page frame for linear translations. See role.direct.

But in function FNAME(fetch)(), sp->gfn is incorrect when one of following
situations occurred:

 1) guest is 32bit paging and the guest PDE maps a 4-MByte page
    (backed by 4k host pages), FNAME(fetch)() miss handling the quadrant.

    And if guest use pse-36, "table_gfn = gpte_to_gfn(gw->ptes[level - delta]);"
    is incorrect.

 2) guest is long mode paging and the guest PDPTE maps a 1-GByte page
    (backed by 4k or 2M host pages).

So we fix it to suit to the document and suit to the code which
requires sp->gfn correct when sp->role.direct=1.

We use the goal mapping gfn(gw->gfn) to calculate the base page frame
for linear translations, it is simple and easy to be understood.

Reported-by: Marcelo Tosatti <mtosatti@redhat.com>
Reported-by: Gui Jianfeng <guijianfeng@cn.fujitsu.com>
Signed-off-by: Lai Jiangshan <laijs@cn.fujitsu.com>
Signed-off-by: Avi Kivity <avi@redhat.com>
14 years agoKVM: MMU: Calculate correct base gfn for direct non-DIR level
Lai Jiangshan [Wed, 26 May 2010 08:48:25 +0000 (16:48 +0800)] 
KVM: MMU: Calculate correct base gfn for direct non-DIR level

In Document/kvm/mmu.txt:
  gfn:
    Either the guest page table containing the translations shadowed by this
    page, or the base page frame for linear translations. See role.direct.

But in __direct_map(), the base gfn calculation is incorrect,
it does not calculate correctly when level=3 or 4.

Fix by using PT64_LVL_ADDR_MASK() which accounts for all levels correctly.

Reported-by: Marcelo Tosatti <mtosatti@redhat.com>
Signed-off-by: Lai Jiangshan <laijs@cn.fujitsu.com>
Signed-off-by: Avi Kivity <avi@redhat.com>
14 years agoKVM: MMU: Don't allocate gfns page for direct mmu pages
Lai Jiangshan [Wed, 26 May 2010 08:49:59 +0000 (16:49 +0800)] 
KVM: MMU: Don't allocate gfns page for direct mmu pages

When sp->role.direct is set, sp->gfns does not contain any essential
information, leaf sptes reachable from this sp are for a continuous
guest physical memory range (a linear range).
So sp->gfns[i] (if it was set) equals to sp->gfn + i. (PT_PAGE_TABLE_LEVEL)
Obviously, it is not essential information, we can calculate it when need.

It means we don't need sp->gfns when sp->role.direct=1,
Thus we can save one page usage for every kvm_mmu_page.

Note:
  Access to sp->gfns must be wrapped by kvm_mmu_page_get_gfn()
  or kvm_mmu_page_set_gfn().
  It is only exposed in FNAME(sync_page).

Signed-off-by: Lai Jiangshan <laijs@cn.fujitsu.com>
Signed-off-by: Avi Kivity <avi@redhat.com>
14 years agoKVM: VMX: Add constant for invalid guest state exit reason
Mohammed Gamal [Sun, 23 May 2010 22:01:04 +0000 (01:01 +0300)] 
KVM: VMX: Add constant for invalid guest state exit reason

For the sake of completeness, this patch adds a symbolic
constant for VMX exit reason 0x21 (invalid guest state).

Signed-off-by: Mohammed Gamal <m.gamal005@gmail.com>
Signed-off-by: Avi Kivity <avi@redhat.com>
14 years agoKVM: MMU: allow more page become unsync at getting sp time
Xiao Guangrong [Mon, 24 May 2010 07:41:33 +0000 (15:41 +0800)] 
KVM: MMU: allow more page become unsync at getting sp time

Allow more page become asynchronous at getting sp time, if need create new
shadow page for gfn but it not allow unsync(level > 1), we should unsync all
gfn's unsync page

Signed-off-by: Xiao Guangrong <xiaoguangrong@cn.fujitsu.com>
Signed-off-by: Avi Kivity <avi@redhat.com>
14 years agoKVM: MMU: allow more page become unsync at gfn mapping time
Xiao Guangrong [Mon, 24 May 2010 07:40:07 +0000 (15:40 +0800)] 
KVM: MMU: allow more page become unsync at gfn mapping time

In current code, shadow page can become asynchronous only if one
shadow page for a gfn, this rule is too strict, in fact, we can
let all last mapping page(i.e, it's the pte page) become unsync,
and sync them at invlpg or flush tlb time.

This patch allow more page become asynchronous at gfn mapping time

Signed-off-by: Xiao Guangrong <xiaoguangrong@cn.fujitsu.com>
Signed-off-by: Avi Kivity <avi@redhat.com>
14 years agoKVM: Update Red Hat copyrights
Avi Kivity [Sun, 23 May 2010 15:37:00 +0000 (18:37 +0300)] 
KVM: Update Red Hat copyrights

Signed-off-by: Avi Kivity <avi@redhat.com>
14 years agoKVM: SVM: correctly trace irq injection
Gleb Natapov [Sun, 23 May 2010 11:28:26 +0000 (14:28 +0300)] 
KVM: SVM: correctly trace irq injection

On SVM interrupts are injected by svm_set_irq() not svm_inject_irq().
The later is used only to wait for irq window.

Signed-off-by: Gleb Natapov <gleb@redhat.com>
Signed-off-by: Avi Kivity <avi@redhat.com>
14 years agoKVM: MMU: only update unsync page in invlpg path
Xiao Guangrong [Sat, 15 May 2010 10:53:35 +0000 (18:53 +0800)] 
KVM: MMU: only update unsync page in invlpg path

Only unsync pages need updated at invlpg time since other shadow
pages are write-protected

Signed-off-by: Xiao Guangrong <xiaoguangrong@cn.fujitsu.com>
Signed-off-by: Avi Kivity <avi@redhat.com>
14 years agoKVM: MMU: don't write-protect if have new mapping to unsync page
Xiao Guangrong [Sat, 15 May 2010 10:52:34 +0000 (18:52 +0800)] 
KVM: MMU: don't write-protect if have new mapping to unsync page

Two cases maybe happen in kvm_mmu_get_page() function:

- one case is, the goal sp is already in cache, if the sp is unsync,
  we only need update it to assure this mapping is valid, but not
  mark it sync and not write-protect sp->gfn since it not broke unsync
  rule(one shadow page for a gfn)

- another case is, the goal sp not existed, we need create a new sp
  for gfn, i.e, gfn (may)has another shadow page, to keep unsync rule,
  we should sync(mark sync and write-protect) gfn's unsync shadow page.
  After enabling multiple unsync shadows, we sync those shadow pages
  only when the new sp not allow to become unsync(also for the unsyc
  rule, the new rule is: allow all pte page become unsync)

Signed-off-by: Xiao Guangrong <xiaoguangrong@cn.fujitsu.com>
Signed-off-by: Avi Kivity <avi@redhat.com>
14 years agoKVM: MMU: split kvm_sync_page() function
Xiao Guangrong [Sat, 15 May 2010 10:51:24 +0000 (18:51 +0800)] 
KVM: MMU: split kvm_sync_page() function

Split kvm_sync_page() into kvm_sync_page() and kvm_sync_page_transient()
to clarify the code address Avi's suggestion

kvm_sync_page_transient() function only update shadow page but not mark
it sync and not write protect sp->gfn. it will be used by later patch

Signed-off-by: Xiao Guangrong <xiaoguangrong@cn.fujitsu.com>
Signed-off-by: Avi Kivity <avi@redhat.com>
14 years agoKVM: x86: Use FPU API
Sheng Yang [Mon, 17 May 2010 09:08:28 +0000 (17:08 +0800)] 
KVM: x86: Use FPU API

Convert KVM to use generic FPU API.

Signed-off-by: Sheng Yang <sheng@linux.intel.com>
Signed-off-by: Avi Kivity <avi@redhat.com>
14 years agoKVM: x86: Use unlazy_fpu() for host FPU
Sheng Yang [Mon, 17 May 2010 09:08:27 +0000 (17:08 +0800)] 
KVM: x86: Use unlazy_fpu() for host FPU

We can avoid unnecessary fpu load when userspace process
didn't use FPU frequently.

Derived from Avi's idea.

Signed-off-by: Sheng Yang <sheng@linux.intel.com>
Signed-off-by: Avi Kivity <avi@redhat.com>
14 years agox86: Export FPU API for KVM use
Sheng Yang [Mon, 17 May 2010 09:22:23 +0000 (17:22 +0800)] 
x86: Export FPU API for KVM use

Also add some constants.

Signed-off-by: Sheng Yang <sheng@linux.intel.com>
Signed-off-by: Avi Kivity <avi@redhat.com>
14 years agoKVM: Consolidate arch specific vcpu ioctl locking
Avi Kivity [Thu, 13 May 2010 09:35:17 +0000 (12:35 +0300)] 
KVM: Consolidate arch specific vcpu ioctl locking

Now that all arch specific ioctls have centralized locking, it is easy to
move it to the central dispatcher.

Signed-off-by: Avi Kivity <avi@redhat.com>
14 years agoKVM: PPC: Centralize locking of arch specific vcpu ioctls
Avi Kivity [Thu, 13 May 2010 09:30:43 +0000 (12:30 +0300)] 
KVM: PPC: Centralize locking of arch specific vcpu ioctls

Signed-off-by: Avi Kivity <avi@redhat.com>
14 years agoKVM: s390: Centrally lock arch specific vcpu ioctls
Avi Kivity [Thu, 13 May 2010 09:21:46 +0000 (12:21 +0300)] 
KVM: s390: Centrally lock arch specific vcpu ioctls

Signed-off-by: Avi Kivity <avi@redhat.com>
This page took 0.04539 seconds and 5 git commands to generate.