[PATCH 2 of 3] Move vm_stat and apic_access_page to kvm_x86

Hollis Blanchard
2007-11-20T16:57:14Z

Signed-off-by: Hollis Blanchard <hollisb-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>

---
5 files changed, 18 insertions(+), 13 deletions(-)
drivers/kvm/kvm.h | 2 --
drivers/kvm/mmu.c | 14 ++++++++------
drivers/kvm/vmx.c | 11 +++++++----
drivers/kvm/x86.c | 2 +-
drivers/kvm/x86.h | 2 ++

diff --git a/drivers/kvm/kvm.h b/drivers/kvm/kvm.h
--- a/drivers/kvm/kvm.h
+++ b/drivers/kvm/kvm.h
@@ -315,8 +315,6 @@ struct kvm {
struct kvm_io_bus mmio_bus;
struct kvm_io_bus pio_bus;
int round_robin_prev_vcpu;
- struct page *apic_access_page;
- struct kvm_vm_stat stat;
};

struct descriptor_table {
diff --git a/drivers/kvm/mmu.c b/drivers/kvm/mmu.c
--- a/drivers/kvm/mmu.c
+++ b/drivers/kvm/mmu.c
@@ -761,7 +761,7 @@ static void kvm_mmu_zap_page(struct kvm
u64 *parent_pte;
struct kvm_x86 *kvm_x86 = to_kvm_x86(kvm);

- ++kvm->stat.mmu_shadow_zapped;
+ ++kvm_x86->stat.mmu_shadow_zapped;
while (page->multimapped || page->parent_pte) {
if (!page->multimapped)
parent_pte = page->parent_pte;
@@ -1236,12 +1236,14 @@ static void mmu_pte_write_new_pte(struct
const void *new, int bytes,
int offset_in_pte)
{
+ struct kvm_x86 *kvm_x86 = to_kvm_x86(vcpu->kvm);
+
if (page->role.level != PT_PAGE_TABLE_LEVEL) {
- ++vcpu->kvm->stat.mmu_pde_zapped;
+ ++kvm_x86->stat.mmu_pde_zapped;
return;
}

- ++vcpu->kvm->stat.mmu_pte_updated;
+ ++kvm_x86->stat.mmu_pte_updated;
if (page->role.glevels == PT32_ROOT_LEVEL)
paging32_update_pte(vcpu, page, spte, new, bytes,
offset_in_pte);
@@ -1277,7 +1279,7 @@ void kvm_mmu_pte_write(struct kvm_vcpu *
int npte;

pgprintk("%s: gpa %llx bytes %d\n", __FUNCTION__, gpa, bytes);
- ++vcpu->kvm->stat.mmu_pte_write;
+ ++kvm_x86->stat.mmu_pte_write;
kvm_mmu_audit(vcpu, "pre pte write");
if (gfn == vcpu->last_pt_write_gfn
&& !last_updated_pte_accessed(vcpu)) {
@@ -1311,7 +1313,7 @@ void kvm_mmu_pte_write(struct kvm_vcpu *
pgprintk("misaligned: gpa %llx bytes %d role %x\n",
gpa, bytes, page->role.word);
kvm_mmu_zap_page(vcpu->kvm, page);
- ++vcpu->kvm->stat.mmu_flooded;
+ ++kvm_x86->stat.mmu_flooded;
continue;
}
page_offset = offset;
@@ -1362,7 +1364,7 @@ void __kvm_mmu_free_some_pages(struct kv
page = container_of(kvm_x86->active_mmu_pages.prev,
struct kvm_mmu_page, link);
kvm_mmu_zap_page(vcpu->kvm, page);
- ++vcpu->kvm->stat.mmu_recycled;
+ ++kvm_x86->stat.mmu_recycled;
}
}

diff --git a/drivers/kvm/vmx.c b/drivers/kvm/vmx.c
--- a/drivers/kvm/vmx.c
+++ b/drivers/kvm/vmx.c
@@ -1468,11 +1468,12 @@ static void seg_setup(int seg)

static int alloc_apic_access_page(struct kvm *kvm)
{
+ struct kvm_x86 *kvm_x86 = to_kvm_x86(kvm);
struct kvm_userspace_memory_region kvm_userspace_mem;
int r = 0;

mutex_lock(&kvm->lock);
- if (kvm->apic_access_page)
+ if (kvm_x86->apic_access_page)
goto out;
kvm_userspace_mem.slot = APIC_ACCESS_PAGE_PRIVATE_MEMSLOT;
kvm_userspace_mem.flags = 0;
@@ -1481,7 +1482,7 @@ static int alloc_apic_access_page(struct
r = __kvm_set_memory_region(kvm, &kvm_userspace_mem, 0);
if (r)
goto out;
- kvm->apic_access_page = gfn_to_page(kvm, 0xfee00);
+ kvm_x86->apic_access_page = gfn_to_page(kvm, 0xfee00);
out:
mutex_unlock(&kvm->lock);
return r;
@@ -1694,9 +1695,11 @@ static int vmx_vcpu_reset(struct kvm_vcp
vmcs_write32(TPR_THRESHOLD, 0);
}

- if (vm_need_virtualize_apic_accesses(vmx->vcpu.kvm))
+ if (vm_need_virtualize_apic_accesses(vmx->vcpu.kvm)) {
+ struct kvm_x86 *kvm_x86 = to_kvm_x86(vmx->vcpu.kvm);
vmcs_write64(APIC_ACCESS_ADDR,
- page_to_phys(vmx->vcpu.kvm->apic_access_page));
+ page_to_phys(kvm_x86->apic_access_page));
+ }

vmx->vcpu.cr0 = 0x60000010;
vmx_set_cr0(&vmx->vcpu, vmx->vcpu.cr0); /* enter rmode */
diff --git a/drivers/kvm/x86.c b/drivers/kvm/x86.c
--- a/drivers/kvm/x86.c
+++ b/drivers/kvm/x86.c
@@ -42,7 +42,7 @@
#define CR8_RESERVED_BITS (~(unsigned long)X86_CR8_TPR)
#define EFER_RESERVED_BITS 0xfffffffffffff2fe

-#define VM_STAT(x) offsetof(struct kvm, stat.x), KVM_STAT_VM
+#define VM_STAT(x) offsetof(struct kvm_x86, stat.x), KVM_STAT_VM
#define VCPU_STAT(x) offsetof(struct kvm_vcpu, stat.x), KVM_STAT_VCPU

struct kvm_x86_ops *kvm_x86_ops;
diff --git a/drivers/kvm/x86.h b/drivers/kvm/x86.h
--- a/drivers/kvm/x86.h
+++ b/drivers/kvm/x86.h
@@ -169,6 +169,8 @@ struct kvm_x86 {
struct kvm_pic *vpic;
struct kvm_ioapic *vioapic;
unsigned int tss_addr;
+ struct page *apic_access_page;
+ struct kvm_vm_stat stat;
};

static struct kvm_x86 *to_kvm_x86(struct kvm *kvm)

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.