aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/kvm/kvm_main.c
diff options
context:
space:
mode:
authorIzik Eidus <izike@qumranet.com>2007-10-02 12:52:55 -0400
committerAvi Kivity <avi@qumranet.com>2008-01-30 10:52:50 -0500
commit82ce2c96831f049a37118733ced5c8f7c8848102 (patch)
tree609fed010ebbb1ced6f0f24698148e69a72da5fd /drivers/kvm/kvm_main.c
parent195aefde9cc2cee38dd54ef92a866721fba4413e (diff)
KVM: Allow dynamic allocation of the mmu shadow cache size
The user is now able to set how many mmu pages will be allocated to the guest. Signed-off-by: Izik Eidus <izike@qumranet.com> Signed-off-by: Avi Kivity <avi@qumranet.com>
Diffstat (limited to 'drivers/kvm/kvm_main.c')
-rw-r--r--drivers/kvm/kvm_main.c47
1 files changed, 47 insertions, 0 deletions
diff --git a/drivers/kvm/kvm_main.c b/drivers/kvm/kvm_main.c
index cac328b8421c..2bb1f2f66efa 100644
--- a/drivers/kvm/kvm_main.c
+++ b/drivers/kvm/kvm_main.c
@@ -743,6 +743,24 @@ static int kvm_vm_ioctl_set_memory_region(struct kvm *kvm,
743 if (mem->slot >= kvm->nmemslots) 743 if (mem->slot >= kvm->nmemslots)
744 kvm->nmemslots = mem->slot + 1; 744 kvm->nmemslots = mem->slot + 1;
745 745
746 if (!kvm->n_requested_mmu_pages) {
747 unsigned int n_pages;
748
749 if (npages) {
750 n_pages = npages * KVM_PERMILLE_MMU_PAGES / 1000;
751 kvm_mmu_change_mmu_pages(kvm, kvm->n_alloc_mmu_pages +
752 n_pages);
753 } else {
754 unsigned int nr_mmu_pages;
755
756 n_pages = old.npages * KVM_PERMILLE_MMU_PAGES / 1000;
757 nr_mmu_pages = kvm->n_alloc_mmu_pages - n_pages;
758 nr_mmu_pages = max(nr_mmu_pages,
759 (unsigned int) KVM_MIN_ALLOC_MMU_PAGES);
760 kvm_mmu_change_mmu_pages(kvm, nr_mmu_pages);
761 }
762 }
763
746 *memslot = new; 764 *memslot = new;
747 765
748 kvm_mmu_slot_remove_write_access(kvm, mem->slot); 766 kvm_mmu_slot_remove_write_access(kvm, mem->slot);
@@ -760,6 +778,26 @@ out:
760 return r; 778 return r;
761} 779}
762 780
781static int kvm_vm_ioctl_set_nr_mmu_pages(struct kvm *kvm,
782 u32 kvm_nr_mmu_pages)
783{
784 if (kvm_nr_mmu_pages < KVM_MIN_ALLOC_MMU_PAGES)
785 return -EINVAL;
786
787 mutex_lock(&kvm->lock);
788
789 kvm_mmu_change_mmu_pages(kvm, kvm_nr_mmu_pages);
790 kvm->n_requested_mmu_pages = kvm_nr_mmu_pages;
791
792 mutex_unlock(&kvm->lock);
793 return 0;
794}
795
796static int kvm_vm_ioctl_get_nr_mmu_pages(struct kvm *kvm)
797{
798 return kvm->n_alloc_mmu_pages;
799}
800
763/* 801/*
764 * Get (and clear) the dirty memory log for a memory slot. 802 * Get (and clear) the dirty memory log for a memory slot.
765 */ 803 */
@@ -3071,6 +3109,14 @@ static long kvm_vm_ioctl(struct file *filp,
3071 goto out; 3109 goto out;
3072 break; 3110 break;
3073 } 3111 }
3112 case KVM_SET_NR_MMU_PAGES:
3113 r = kvm_vm_ioctl_set_nr_mmu_pages(kvm, arg);
3114 if (r)
3115 goto out;
3116 break;
3117 case KVM_GET_NR_MMU_PAGES:
3118 r = kvm_vm_ioctl_get_nr_mmu_pages(kvm);
3119 break;
3074 case KVM_GET_DIRTY_LOG: { 3120 case KVM_GET_DIRTY_LOG: {
3075 struct kvm_dirty_log log; 3121 struct kvm_dirty_log log;
3076 3122
@@ -3278,6 +3324,7 @@ static long kvm_dev_ioctl(struct file *filp,
3278 switch (ext) { 3324 switch (ext) {
3279 case KVM_CAP_IRQCHIP: 3325 case KVM_CAP_IRQCHIP:
3280 case KVM_CAP_HLT: 3326 case KVM_CAP_HLT:
3327 case KVM_CAP_MMU_SHADOW_CACHE_CONTROL:
3281 r = 1; 3328 r = 1;
3282 break; 3329 break;
3283 default: 3330 default: