Add the hook kvm_arch_set_memory region to hold mmu-specific changes

Zhang, Xiantao
2007-11-19T05:35:47Z

[-- Attachment #1: Type: text/plain, Size: 186 bytes --]

Patch [3/3] Add the hook kvm_arch_set_memory_region. In this patch,
introduce a function kvm_caculate_mmu_pages to compute mmu pages in
total, once memory region changes.

Xiantao

[-- Attachment #2: 0003-KVM-Portability-Split-kvm_set_memory_region.patch --]
[-- Type: application/octet-stream, Size: 3272 bytes --]

From 87259f087801b93aa516e76f6a303c54eb8ddb10 Mon Sep 17 00:00:00 2001
From: Zhang Xiantao <xiantao.zhang@intel.com>
Date: Mon, 19 Nov 2007 13:13:44 +0800
Subject: [PATCH] KVM Portability: Split kvm_set_memory_region.
Add arch support for kvm_set_memory_region, and mov mmu-specific code to
kvm_arch_set_memory_region.
Signed-off-by: Zhang Xiantao <xiantao.zhang@intel.com>
---
drivers/kvm/kvm.h | 2 ++
drivers/kvm/kvm_main.c | 22 ++--------------------
drivers/kvm/x86.c | 29 +++++++++++++++++++++++++++++
3 files changed, 33 insertions(+), 20 deletions(-)

diff --git a/drivers/kvm/kvm.h b/drivers/kvm/kvm.h
index c1aa84f..7544e90 100644
--- a/drivers/kvm/kvm.h
+++ b/drivers/kvm/kvm.h
@@ -539,6 +539,8 @@ int kvm_is_error_hva(unsigned long addr);
int kvm_set_memory_region(struct kvm *kvm,
struct kvm_userspace_memory_region *mem,
int user_alloc);
+void kvm_arch_set_memory_region(struct kvm *kvm,
+ struct kvm_userspace_memory_region *mem);
int __kvm_set_memory_region(struct kvm *kvm,
struct kvm_userspace_memory_region *mem,
int user_alloc);
diff --git a/drivers/kvm/kvm_main.c b/drivers/kvm/kvm_main.c
index bda733a..a4a32bd 100644
--- a/drivers/kvm/kvm_main.c
+++ b/drivers/kvm/kvm_main.c
@@ -332,29 +332,9 @@ int __kvm_set_memory_region(struct kvm *kvm,
if (mem->slot >= kvm->nmemslots)
kvm->nmemslots = mem->slot + 1;

- if (!kvm->n_requested_mmu_pages) {
- unsigned int n_pages;
-
- if (npages) {
- n_pages = npages * KVM_PERMILLE_MMU_PAGES / 1000;
- kvm_mmu_change_mmu_pages(kvm, kvm->n_alloc_mmu_pages +
- n_pages);
- } else {
- unsigned int nr_mmu_pages;
-
- n_pages = old.npages * KVM_PERMILLE_MMU_PAGES / 1000;
- nr_mmu_pages = kvm->n_alloc_mmu_pages - n_pages;
- nr_mmu_pages = max(nr_mmu_pages,
- (unsigned int) KVM_MIN_ALLOC_MMU_PAGES);
- kvm_mmu_change_mmu_pages(kvm, nr_mmu_pages);
- }
- }

*memslot = new;

- kvm_mmu_slot_remove_write_access(kvm, mem->slot);
- kvm_flush_remote_tlbs(kvm);
-
kvm_free_physmem_slot(&old, &new);
return 0;

@@ -374,6 +354,8 @@ int kvm_set_memory_region(struct kvm *kvm,

mutex_lock(&kvm->lock);
r = __kvm_set_memory_region(kvm, mem, user_alloc);
+ if (r == 0)
+ kvm_arch_set_memory_region(kvm, mem);
mutex_unlock(&kvm->lock);
return r;
}
diff --git a/drivers/kvm/x86.c b/drivers/kvm/x86.c
index 0ec0eee..89268b5 100644
--- a/drivers/kvm/x86.c
+++ b/drivers/kvm/x86.c
@@ -2646,3 +2646,32 @@ void kvm_arch_destroy_vm(struct kvm *kvm)
kvm_free_physmem(kvm);
kfree(kvm);
}
+
+static unsigned int kvm_calculate_mmu_pages(struct kvm *kvm)
+{
+ int i;
+ unsigned int nr_mmu_pages;
+ unsigned int nr_pages = 0;
+
+ for (i = 0; i < kvm->nmemslots; i++)
+ nr_pages += kvm->memslots[i].npages;
+
+ nr_mmu_pages = nr_pages * KVM_PERMILLE_MMU_PAGES / 1000;
+ nr_mmu_pages = max(nr_mmu_pages,
+ (unsigned int) KVM_MIN_ALLOC_MMU_PAGES);
+
+ return nr_mmu_pages;
+}
+
+void kvm_arch_set_memory_region(struct kvm *kvm,
+ struct kvm_userspace_memory_region *mem)
+{
+ if (!kvm->n_requested_mmu_pages) {
+ int nr_mmu_pages = kvm_calculate_mmu_pages(kvm);
+ kvm_mmu_change_mmu_pages(kvm, nr_mmu_pages);
+ }
+
+ kvm_mmu_slot_remove_write_access(kvm, mem->slot);
+ kvm_flush_remote_tlbs(kvm);
+}
+
--
1.5.1.2

[-- Attachment #3: Type: text/plain, Size: 228 bytes --]

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/

[-- Attachment #4: Type: text/plain, Size: 186 bytes --]

_______________________________________________
kvm-devel mailing list
kvm-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org