[kvm-devel] [patch] KVM: simplify mmu_alloc_roots()

2007-01-04 Thread Ingo Molnar
Subject: [patch] KVM: simplify mmu_alloc_roots() From: Ingo Molnar <[EMAIL PROTECTED]> small optimization/cleanup: page == page_header(page->page_hpa) Signed-off-by: Ingo Molnar <[EMAIL PROTECTED]> --- drivers/kvm/mmu.c | 12 ++-- 1 file changed, 6 insertions(+), 6 deletions(-) Index

Re: [kvm-devel] [patch] kvm: make cr3 loading more robust

2007-01-04 Thread Avi Kivity
Ingo Molnar wrote: > * Ingo Molnar <[EMAIL PROTECTED]> wrote: > > >> ok. How about the patch below then? This only addresses the OOM >> scenario, not the !memslot case. >> > > the !memslot case is covered by the patch below. Injecting a #GPF is the > easiest one to do here, although we co

Re: [kvm-devel] [patch] kvm: make cr3 loading more robust

2007-01-04 Thread Avi Kivity
Ingo Molnar wrote: > another small detail is that currently KVM_SET_MEMORY_REGION appears to > be an add-only interface - it is not possible to 'unregister' RAM from a > VM. > Well, the _interface_ supports removing, the implementation does not :) Everything was written in mind to allow memo

Re: [kvm-devel] [patch] kvm: make cr3 loading more robust

2007-01-04 Thread Ingo Molnar
* Avi Kivity <[EMAIL PROTECTED]> wrote: > The guest needs to cooperate, but it can do so using the native memory > hotlpug mechanisms (whatever they are). [...] as far a Linux guest goes, there's no such thing at the moment, at least in the mainline kernel. Most of the difficulties with RAM-un

Re: [kvm-devel] [patch] KVM: simplify mmu_alloc_roots()

2007-01-04 Thread Avi Kivity
Ingo Molnar wrote: > Subject: [patch] KVM: simplify mmu_alloc_roots() > From: Ingo Molnar <[EMAIL PROTECTED]> > > small optimization/cleanup: > > page == page_header(page->page_hpa) > > Applied, thanks. -- error compiling committee.c: too many arguments to function -

Re: [kvm-devel] Solaris 10 U2 installation failure

2007-01-04 Thread Avi Kivity
Parag Warudkar wrote: > Avi Kivity <[EMAIL PROTECTED]> writes: > > > >> 32-bin kvm userspace can run a 64-bit guest, if you're using a 64-bit os >> kernel, hence the 64-bit registers. Just ignore the 64-bit parts. >> >> > > Didn't understand. Allow me to clarify a bit - > > I am running a

[kvm-devel] Compile error with openSuse 10.2

2007-01-04 Thread Peter Smith
When compiling KVM I get the following error:- In file included from /home/peter/applications-home/kvm-9/qemu/usb-linux.c:29: /usr/include/linux/usbdevice_fs.h:49: error: variable or field `__user' declared void /usr/include/linux/usbdevice_fs.h:49: error: syntax error before '*' token My enviro

[kvm-devel] [PATCH] KVM: Prevent stale bits in cr0 and cr4

2007-01-04 Thread Avi Kivity
Hardware virtualization implementations allow the guests to freely change some of the bits in cr0 and cr4, but trap when changing the other bits. This is useful to avoid excessive exits due to changing, for example, the ts flag. It also means the kvm's copy of cr0 and cr4 may be stale with respec

[kvm-devel] [PATCH 0/33] KVM: MMU: Cache shadow page tables

2007-01-04 Thread Avi Kivity
The current kvm shadow page table implementation does not cache shadow page tables (except for global translations, used for kernel addresses) across context switches. This means that after a context switch, every memory access will trap into the host. After a while, the shadow page tables wi

[kvm-devel] [PATCH 1/33] KVM: MMU: Implement simple reverse mapping

2007-01-04 Thread Avi Kivity
Keep in each host page frame's page->private a pointer to the shadow pte which maps it. If there are multiple shadow ptes mapping the page, set bit 0 of page->private, and use the rest as a pointer to a linked list of all such mappings. Reverse mappings are needed because we when we cache shadow

[kvm-devel] [PATCH 2/33] KVM: MMU: Teach the page table walker to track guest page table gfns

2007-01-04 Thread Avi Kivity
Saving the table gfns removes the need to walk the guest and host page tables in lockstep. Signed-off-by: Avi Kivity <[EMAIL PROTECTED]> Index: linux-2.6/drivers/kvm/paging_tmpl.h === --- linux-2.6.orig/drivers/kvm/paging_tmpl.h +++

[kvm-devel] [PATCH 3/33] KVM: MMU: Load the pae pdptrs on cr3 change like the processor does

2007-01-04 Thread Avi Kivity
In pae mode, a load of cr3 loads the four third-level page table entries in addition to cr3 itself. Signed-off-by: Avi Kivity <[EMAIL PROTECTED]> Index: linux-2.6/drivers/kvm/kvm_main.c === --- linux-2.6.orig/drivers/kvm/kvm_main.c +

[kvm-devel] [PATCH 4/33] KVM: MMU: Fold fetch_guest() into init_walker()

2007-01-04 Thread Avi Kivity
It is never necessary to fetch a guest entry from an intermediate page table level (except for large pages), so avoid some confusion by always descending into the lowest possible level. Rename init_walker() to walk_addr() as it is no longer restricted to initialization. Signed-off-by: Avi Kivity

[kvm-devel] [PATCH 5/33] KVM: MU: Special treatment for shadow pae root pages

2007-01-04 Thread Avi Kivity
Since we're not going to cache the pae-mode shadow root pages, allocate a single pae shadow that will hold the four lower-level pages, which will act as roots. Signed-off-by: Avi Kivity <[EMAIL PROTECTED]> Index: linux-2.6/drivers/kvm/mmu.c

[kvm-devel] [PATCH 6/33] KVM: MMU: Use the guest pdptrs instead of mapping cr3 in pae mode

2007-01-04 Thread Avi Kivity
This lets us not write protect a partial page, and is anyway what a real processor does. Signed-off-by: Avi Kivity <[EMAIL PROTECTED]> Index: linux-2.6/drivers/kvm/paging_tmpl.h === --- linux-2.6.orig/drivers/kvm/paging_tmpl.h +++ li

[kvm-devel] [PATCH 7/33] KVM: MMU: Make the shadow page tables also special-case pae

2007-01-04 Thread Avi Kivity
Signed-off-by: Avi Kivity <[EMAIL PROTECTED]> Index: linux-2.6/drivers/kvm/paging_tmpl.h === --- linux-2.6.orig/drivers/kvm/paging_tmpl.h +++ linux-2.6/drivers/kvm/paging_tmpl.h @@ -170,6 +170,11 @@ static u64 *FNAME(fetch)(struct kvm

[kvm-devel] [PATCH 8/33] KVM: MMU: Make kvm_mmu_alloc_page() return a kvm_mmu_page pointer

2007-01-04 Thread Avi Kivity
This allows further manipulation on the shadow page table. Signed-off-by: Avi Kivity <[EMAIL PROTECTED]> Index: linux-2.6/drivers/kvm/mmu.c === --- linux-2.6.orig/drivers/kvm/mmu.c +++ linux-2.6/drivers/kvm/mmu.c @@ -292,12 +292,13 @

[kvm-devel] [PATCH 9/33] KVM: MMU: Shadow page table caching

2007-01-04 Thread Avi Kivity
Define a hashtable for caching shadow page tables. Look up the cache on context switch (cr3 change) or during page faults. The key to the cache is a combination of - the guest page table frame number - the number of paging levels in the guest * we can cache real mode, 32-bit mode, pae, and long

[kvm-devel] [PATCH 10/33] KVM: MMU: Write protect guest pages when a shadow is created for them

2007-01-04 Thread Avi Kivity
When we cache a guest page table into a shadow page table, we need to prevent further access to that page by the guest, as that would render the cache incoherent. Signed-off-by: Avi Kivity <[EMAIL PROTECTED]> Index: linux-2.6/drivers/kvm/mmu.c =

[kvm-devel] [PATCH 11/33] KVM: MMU: Let the walker extract the target page gfn from the pte

2007-01-04 Thread Avi Kivity
This fixes a problem where set_pte_common() looked for shadowed pages based on the page directory gfn (a huge page) instead of the actual gfn being mapped. Signed-off-by: Avi Kivity <[EMAIL PROTECTED]> Index: linux-2.6/drivers/kvm/mmu.c

[kvm-devel] [PATCH 12/33] KVM: MMU: Support emulated writes into RAM

2007-01-04 Thread Avi Kivity
As the mmu write protects guest page table, we emulate those writes. Since they are not mmio, there is no need to go to userspace to perform them. So, perform the writes in the kernel if possible, and notify the mmu about them so it can take the approriate action. Signed-off-by: Avi Kivity <[EMA

[kvm-devel] [PATCH 13/33] KVM: MMU: Zap shadow page table entries on writes to guest page tables

2007-01-04 Thread Avi Kivity
Iterate over all shadow pages which correspond to a the given guest page table and remove the mappings. A subsequent page fault will reestablish the new mapping. Signed-off-by: Avi Kivity <[EMAIL PROTECTED]> Index: linux-2.6/drivers/kvm/mmu.c =

[kvm-devel] [PATCH 14/33] KVM: MMU: If emulating an instruction fails, try unprotecting the page

2007-01-04 Thread Avi Kivity
A page table may have been recycled into a regular page, and so any instruction can be executed on it. Unprotect the page and let the cpu do its thing. Signed-off-by: Avi Kivity <[EMAIL PROTECTED]> Index: linux-2.6/drivers/kvm/mmu.c ===

[kvm-devel] [PATCH 15/33] KVM: MMU: Implement child shadow unlinking

2007-01-04 Thread Avi Kivity
When removing a page table, we must maintain the parent_pte field all child shadow page tables. Signed-off-by: Avi Kivity <[EMAIL PROTECTED]> Index: linux-2.6/drivers/kvm/mmu.c === --- linux-2.6.orig/drivers/kvm/mmu.c +++ linux-2.6/d

[kvm-devel] [PATCH 16/33] KVM: MMU: kvm_mmu_put_page() only removes one link to the page

2007-01-04 Thread Avi Kivity
... and so must not free it unconditionally. Move the freeing to kvm_mmu_zap_page(). Signed-off-by: Avi Kivity <[EMAIL PROTECTED]> Index: linux-2.6/drivers/kvm/mmu.c === --- linux-2.6.orig/drivers/kvm/mmu.c +++ linux-2.6/drivers/kvm

[kvm-devel] [PATCH 17/33] KVM: MMU: oom handling

2007-01-04 Thread Avi Kivity
When beginning to process a page fault, make sure we have enough shadow pages available to service the fault. If not, free some pages. Signed-off-by: Avi Kivity <[EMAIL PROTECTED]> Index: linux-2.6/drivers/kvm/mmu.c === --- linux-2.

[kvm-devel] [PATCH 18/33] KVM: MMU: Remove invlpg interception

2007-01-04 Thread Avi Kivity
Since we write protect shadowed guest page tables, there is no need to trap page invalidations (the guest will always change the mapping before issuing the invlpg instruction). Signed-off-by: Avi Kivity <[EMAIL PROTECTED]> Index: linux-2.6/drivers/kvm/mmu.c ===

[kvm-devel] [PATCH 19/33] KVM: MMU: Remove release_pt_page_64()

2007-01-04 Thread Avi Kivity
Unused. Signed-off-by: Avi Kivity <[EMAIL PROTECTED]> Index: linux-2.6/drivers/kvm/mmu.c === --- linux-2.6.orig/drivers/kvm/mmu.c +++ linux-2.6/drivers/kvm/mmu.c @@ -609,35 +609,6 @@ hpa_t gva_to_hpa(struct kvm_vcpu *vcpu, r

[kvm-devel] [PATCH 20/33] KVM: MMU: Handle misaligned accesses to write protected guest page tables

2007-01-04 Thread Avi Kivity
A misaligned access affects two shadow ptes instead of just one. Since a misaligned access is unlikely to occur on a real page table, just zap the page out of existence, avoiding further trouble. Signed-off-by: Avi Kivity <[EMAIL PROTECTED]> Index: linux-2.6/drivers/kvm/mmu.c ===

[kvm-devel] [PATCH 21/33] KVM: MMU:

2007-01-04 Thread Avi Kivity
Signed-off-by: Avi Kivity <[EMAIL PROTECTED]> Index: linux-2.6/drivers/kvm/mmu.c === --- linux-2.6.orig/drivers/kvm/mmu.c +++ linux-2.6/drivers/kvm/mmu.c @@ -303,16 +303,6 @@ static void rmap_write_protect(struct kv } } -st

[kvm-devel] [PATCH 22/33] KVM: MMU: Ensure freed shadow pages are clean

2007-01-04 Thread Avi Kivity
Signed-off-by: Avi Kivity <[EMAIL PROTECTED]> Index: linux-2.6/drivers/kvm/mmu.c === --- linux-2.6.orig/drivers/kvm/mmu.c +++ linux-2.6/drivers/kvm/mmu.c @@ -318,6 +318,7 @@ static void kvm_mmu_free_page(struct kvm { struct k

[kvm-devel] [PATCH 23/33] KVM: MMU: If an empty shadow page is not empty, report more info

2007-01-04 Thread Avi Kivity
Signed-off-by: Avi Kivity <[EMAIL PROTECTED]> Index: linux-2.6/drivers/kvm/mmu.c === --- linux-2.6.orig/drivers/kvm/mmu.c +++ linux-2.6/drivers/kvm/mmu.c @@ -305,12 +305,16 @@ static void rmap_write_protect(struct kv static int is_

[kvm-devel] [PATCH 24/33] KVM: MMU: Page table write flood protection

2007-01-04 Thread Avi Kivity
In fork() (or when we protect a page that is no longer a page table), we can experience floods of writes to a page, which have to be emulated. This is expensive. So, if we detect such a flood, zap the page so subsequent writes can proceed natively. Signed-off-by: Avi Kivity <[EMAIL PROTECTED]>

[kvm-devel] [PATCH 25/33] KVM: MMU: Never free a shadow page actively serving as a root

2007-01-04 Thread Avi Kivity
We always need cr3 to point to something valid, so if we detect that we're freeing a root page, simply push it back to the top of the active list. Signed-off-by: Avi Kivity <[EMAIL PROTECTED]> Index: linux-2.6/drivers/kvm/mmu.c === -

[kvm-devel] [PATCH 26/33] KVM: MMU: Fix cmpxchg8b emulation

2007-01-04 Thread Avi Kivity
cmpxchg8b uses edx:eax as the compare operand, not edi:eax. cmpxchg8b is used by 32-bit pae guests to set page table entries atomically, and this is emulated touching shadowed guest page tables. Also, implement it for 32-bit hosts. Signed-off-by: Avi Kivity <[EMAIL PROTECTED]> Index: linux-2.6/

[kvm-devel] [PATCH 27/33] KVM: MMU: Treat user-mode faults as a hint that a page is no longer a page table

2007-01-04 Thread Avi Kivity
Signed-off-by: Avi Kivity <[EMAIL PROTECTED]> Index: linux-2.6/drivers/kvm/paging_tmpl.h === --- linux-2.6.orig/drivers/kvm/paging_tmpl.h +++ linux-2.6/drivers/kvm/paging_tmpl.h @@ -271,6 +271,7 @@ static int FNAME(fix_write_pf)(struc

[kvm-devel] [PATCH 28/33] KVM: MMU: Free pages on kvm destruction

2007-01-04 Thread Avi Kivity
Because mmu pages have attached rmap and parent pte chain structures, we need to zap them before freeing so the attached structures are freed. Signed-off-by: Avi Kivity <[EMAIL PROTECTED]> Index: linux-2.6/drivers/kvm/mmu.c === --- l

[kvm-devel] [PATCH 29/33] KVM: MMU: Replace atomic allocations by preallocated objects

2007-01-04 Thread Avi Kivity
The mmu sometimes needs memory for reverse mapping and parent pte chains. however, we can't allocate from within the mmu because of the atomic context. So, move the allocations to a central place that can be executed before the main mmu machinery, where we can bail out on failure before any damage

[kvm-devel] [PATCH 30/33] KVM: MMU: Detect oom conditions and propagate error to userspace

2007-01-04 Thread Avi Kivity
Signed-off-by: Avi Kivity <[EMAIL PROTECTED]> Index: linux-2.6/drivers/kvm/mmu.c === --- linux-2.6.orig/drivers/kvm/mmu.c +++ linux-2.6/drivers/kvm/mmu.c @@ -166,19 +166,20 @@ static int is_rmap_pte(u64 pte) == (PT_WRI

[kvm-devel] [PATCH 31/33] KVM: MMU: Flush guest tlb when reducing permissions on a pte

2007-01-04 Thread Avi Kivity
If we reduce permissions on a pte, we must flush the cached copy of the pte from the guest's tlb. This is implemented at the moment by flushing the entire guest tlb, and can be improved by flushing just the relevant virtual address, if it is known. Signed-off-by: Avi Kivity <[EMAIL PROTECTED]> I

[kvm-devel] [PATCH 32/33] KVM: MMU: Destroy mmu while we still have a vcpu left

2007-01-04 Thread Avi Kivity
mmu_destroy flushes the guest tlb (indirectly), which needs a valid vcpu. Signed-off-by: Avi Kivity <[EMAIL PROTECTED]> Index: linux-2.6/drivers/kvm/kvm_main.c === --- linux-2.6.orig/drivers/kvm/kvm_main.c +++ linux-2.6/drivers/kvm/k

[kvm-devel] [PATCH 33/33] KVM: MMU: add audit code to check mappings, etc are correct

2007-01-04 Thread Avi Kivity
Signed-off-by: Avi Kivity <[EMAIL PROTECTED]> Index: linux-2.6/drivers/kvm/mmu.c === --- linux-2.6.orig/drivers/kvm/mmu.c +++ linux-2.6/drivers/kvm/mmu.c @@ -26,8 +26,31 @@ #include "vmx.h" #include "kvm.h" -#define pgprintk(x...)

Re: [kvm-devel] Compile error with openSuse 10.2

2007-01-04 Thread ( अमेय पाळंदे ) Ameya Palande
> Message: 9 > Date: Thu, 4 Jan 2007 17:00:32 +0200 > From: Peter Smith <[EMAIL PROTECTED]> > Subject: [kvm-devel] Compile error with openSuse 10.2 > To: kvm-devel@lists.sourceforge.net > Message-ID: <[EMAIL PROTECTED]> > Content-Type: text/plain; charset="us-ascii" > > When compiling KVM I get th

Re: [kvm-devel] [PATCH 0/33] KVM: MMU: Cache shadow page tables

2007-01-04 Thread Andrew Morton
On Thu, 04 Jan 2007 17:48:45 +0200 Avi Kivity <[EMAIL PROTECTED]> wrote: > The current kvm shadow page table implementation does not cache shadow > page tables (except for global translations, used for kernel addresses) > across context switches. This means that after a context switch, every >

Re: [kvm-devel] [PATCH 0/33] KVM: MMU: Cache shadow page tables

2007-01-04 Thread Avi Kivity
Andrew Morton wrote: > Is this intended for 2.6.20, or would you prefer that we release what we > have now and hold this off for 2.6.21? > Even though these patches are potentially destabilazing, I'd like them (and a few other patches) to go into 2.6.20: - kvm did not exist in 2.6.19, hence w

Re: [kvm-devel] [PATCH 0/33] KVM: MMU: Cache shadow page tables

2007-01-04 Thread Ingo Molnar
* Avi Kivity <[EMAIL PROTECTED]> wrote: > Andrew Morton wrote: > >Is this intended for 2.6.20, or would you prefer that we release what we > >have now and hold this off for 2.6.21? > > > > Even though these patches are potentially destabilazing, I'd like them > (and a few other patches) to go

[kvm-devel] [PATCH 0/9] KVM: Flush out my patch queue

2007-01-04 Thread Avi Kivity
This patchset is mostly fallout from the mmu stuff that I've neglected to integrate with the main patchset sent yesterday. It includes a fashionable missing dirty bit fix, and other fixes and cleanups. -- Do not meddle in the internals of kernels, for they are subtle and quick to panic. ---

[kvm-devel] [PATCH 1/9] KVM: Improve reporting of vmwrite errors

2007-01-04 Thread Avi Kivity
This will allow us to see the root cause when a vmwrite error happens. Signed-off-by: Avi Kivity <[EMAIL PROTECTED]> Index: linux-2.6/drivers/kvm/vmx.c === --- linux-2.6.orig/drivers/kvm/vmx.c +++ linux-2.6/drivers/kvm/vmx.c @@ -152,

[kvm-devel] [PATCH 2/9] KVM: Initialize vcpu->kvm a little earlier

2007-01-04 Thread Avi Kivity
Fixes oops on early close of /dev/kvm. Signed-off-by: Avi Kivity <[EMAIL PROTECTED]> Index: linux-2.6/drivers/kvm/kvm_main.c === --- linux-2.6.orig/drivers/kvm/kvm_main.c +++ linux-2.6/drivers/kvm/kvm_main.c @@ -230,6 +230,7 @@ stati

[kvm-devel] [PATCH 3/9] KVM: Avoid oom on cr3 switch

2007-01-04 Thread Avi Kivity
From: Ingo Molnar <[EMAIL PROTECTED]> Signed-off-by: Ingo Molnar <[EMAIL PROTECTED]> Signed-off-by: Avi Kivity <[EMAIL PROTECTED]> Index: linux-2.6/drivers/kvm/mmu.c === --- linux-2.6.orig/drivers/kvm/mmu.c +++ linux-2.6/drivers/kvm/

[kvm-devel] [PATCH 4/9] KVM: Add missing 'break'

2007-01-04 Thread Avi Kivity
Signed-off-by: Avi Kivity <[EMAIL PROTECTED]> Index: linux-2.6/drivers/kvm/kvm_main.c === --- linux-2.6.orig/drivers/kvm/kvm_main.c +++ linux-2.6/drivers/kvm/kvm_main.c @@ -1922,6 +1922,7 @@ static long kvm_dev_ioctl(struct file *f

[kvm-devel] [PATCH 5/9] KVM: Don't set guest cr3 from vmx_vcpu_setup()

2007-01-04 Thread Avi Kivity
It overwrites the right cr3 set from mmu setup. Happens only with the test harness. Signed-off-by: Avi Kivity <[EMAIL PROTECTED]> Index: linux-2.6/drivers/kvm/vmx.c === --- linux-2.6.orig/drivers/kvm/vmx.c +++ linux-2.6/drivers/kvm

[kvm-devel] [PATCH 6/9] KVM: MMU: Add missing dirty bit

2007-01-04 Thread Avi Kivity
If we emulate a write, we fail to set the dirty bit on the guest pte, leading the guest to believe the page is clean, and thus lose data. Bad. Fix by setting the guest pte dirty bit under such conditions. Signed-off-by: Avi Kivity <[EMAIL PROTECTED]> Index: linux-2.6/drivers/kvm/paging_tmpl.h =

[kvm-devel] [PATCH 7/9] KVM: Make loading cr3 more robust

2007-01-04 Thread Avi Kivity
From: Ingo Molnar <[EMAIL PROTECTED]> Prevent the guest's loading of a corrupt cr3 (pointing at no guest phsyical page) from crashing the host. Signed-off-by: Ingo Molnar <[EMAIL PROTECTED]> Signed-off-by: Avi Kivity <[EMAIL PROTECTED]> Index: linux-2.6/drivers/kvm/kvm_main.c ===

[kvm-devel] [PATCH 8/9] KVM: Simplify mmu_alloc_roots()

2007-01-04 Thread Avi Kivity
From: Ingo Molnar <[EMAIL PROTECTED]> Small optimization/cleanup: page == page_header(page->page_hpa) Signed-off-by: Ingo Molnar <[EMAIL PROTECTED]> Signed-off-by: Avi Kivity <[EMAIL PROTECTED]> Index: linux-2.6/drivers/kvm/mmu.c =

[kvm-devel] [PATCH 9/9] KVM: Simplify test for interrupt window

2007-01-04 Thread Avi Kivity
No need to test for rflags.if as both VT and SVM specs assure us that on exit caused from interrupt window opening, 'if' is set. Signed-off-by: Dor Laor <[EMAIL PROTECTED]> Signed-off-by: Avi Kivity <[EMAIL PROTECTED]> Index: linux-2.6/drivers/kvm/svm.c ==