]> git.karo-electronics.de Git - karo-tx-linux.git/blobdiff - virt/kvm/kvm_main.c
Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tiwai/sound-2.6
[karo-tx-linux.git] / virt / kvm / kvm_main.c
index 659bc12ad16ac1a9a06235bdd5a12bc238ae416f..5a0cd194dce00ee75b40b73d146ee478db1e4d38 100644 (file)
@@ -22,7 +22,6 @@
 #include <linux/module.h>
 #include <linux/errno.h>
 #include <linux/percpu.h>
-#include <linux/gfp.h>
 #include <linux/mm.h>
 #include <linux/miscdevice.h>
 #include <linux/vmalloc.h>
@@ -45,6 +44,8 @@
 #include <linux/spinlock.h>
 #include <linux/compat.h>
 #include <linux/srcu.h>
+#include <linux/hugetlb.h>
+#include <linux/slab.h>
 
 #include <asm/processor.h>
 #include <asm/io.h>
@@ -137,7 +138,7 @@ static bool make_all_cpus_request(struct kvm *kvm, unsigned int req)
 
        zalloc_cpumask_var(&cpus, GFP_ATOMIC);
 
-       spin_lock(&kvm->requests_lock);
+       raw_spin_lock(&kvm->requests_lock);
        me = smp_processor_id();
        kvm_for_each_vcpu(i, vcpu, kvm) {
                if (test_and_set_bit(req, &vcpu->requests))
@@ -152,7 +153,7 @@ static bool make_all_cpus_request(struct kvm *kvm, unsigned int req)
                smp_call_function_many(cpus, ack_flush, NULL, 1);
        else
                called = false;
-       spin_unlock(&kvm->requests_lock);
+       raw_spin_unlock(&kvm->requests_lock);
        free_cpumask_var(cpus);
        return called;
 }
@@ -371,9 +372,6 @@ static struct kvm *kvm_create_vm(void)
 {
        int r = 0, i;
        struct kvm *kvm = kvm_arch_create_vm();
-#ifdef KVM_COALESCED_MMIO_PAGE_OFFSET
-       struct page *page;
-#endif
 
        if (IS_ERR(kvm))
                goto out;
@@ -402,34 +400,20 @@ static struct kvm *kvm_create_vm(void)
                }
        }
 
-#ifdef KVM_COALESCED_MMIO_PAGE_OFFSET
-       page = alloc_page(GFP_KERNEL | __GFP_ZERO);
-       if (!page) {
-               cleanup_srcu_struct(&kvm->srcu);
-               goto out_err;
-       }
-
-       kvm->coalesced_mmio_ring =
-                       (struct kvm_coalesced_mmio_ring *)page_address(page);
-#endif
-
        r = kvm_init_mmu_notifier(kvm);
        if (r) {
                cleanup_srcu_struct(&kvm->srcu);
-#ifdef KVM_COALESCED_MMIO_PAGE_OFFSET
-               put_page(page);
-#endif
                goto out_err;
        }
 
        kvm->mm = current->mm;
        atomic_inc(&kvm->mm->mm_count);
        spin_lock_init(&kvm->mmu_lock);
-       spin_lock_init(&kvm->requests_lock);
+       raw_spin_lock_init(&kvm->requests_lock);
        kvm_eventfd_init(kvm);
        mutex_init(&kvm->lock);
        mutex_init(&kvm->irq_lock);
-       init_rwsem(&kvm->slots_lock);
+       mutex_init(&kvm->slots_lock);
        atomic_set(&kvm->users_count, 1);
        spin_lock(&kvm_lock);
        list_add(&kvm->vm_list, &vm_list);
@@ -506,7 +490,6 @@ static void kvm_destroy_vm(struct kvm *kvm)
 #else
        kvm_arch_flush_shadow(kvm);
 #endif
-       cleanup_srcu_struct(&kvm->srcu);
        kvm_arch_destroy_vm(kvm);
        hardware_disable_all();
        mmdrop(mm);
@@ -763,9 +746,9 @@ int kvm_set_memory_region(struct kvm *kvm,
 {
        int r;
 
-       down_write(&kvm->slots_lock);
+       mutex_lock(&kvm->slots_lock);
        r = __kvm_set_memory_region(kvm, mem, user_alloc);
-       up_write(&kvm->slots_lock);
+       mutex_unlock(&kvm->slots_lock);
        return r;
 }
 EXPORT_SYMBOL_GPL(kvm_set_memory_region);
@@ -885,6 +868,30 @@ int kvm_is_visible_gfn(struct kvm *kvm, gfn_t gfn)
 }
 EXPORT_SYMBOL_GPL(kvm_is_visible_gfn);
 
+unsigned long kvm_host_page_size(struct kvm *kvm, gfn_t gfn)
+{
+       struct vm_area_struct *vma;
+       unsigned long addr, size;
+
+       size = PAGE_SIZE;
+
+       addr = gfn_to_hva(kvm, gfn);
+       if (kvm_is_error_hva(addr))
+               return PAGE_SIZE;
+
+       down_read(&current->mm->mmap_sem);
+       vma = find_vma(current->mm, addr);
+       if (!vma)
+               goto out;
+
+       size = vma_kernel_pagesize(vma);
+
+out:
+       up_read(&current->mm->mmap_sem);
+
+       return size;
+}
+
 int memslot_id(struct kvm *kvm, gfn_t gfn)
 {
        int i;
@@ -1997,7 +2004,7 @@ int kvm_io_bus_read(struct kvm *kvm, enum kvm_bus bus_idx, gpa_t addr,
        return -EOPNOTSUPP;
 }
 
-/* Caller must have write lock on slots_lock. */
+/* Caller must hold slots_lock. */
 int kvm_io_bus_register_dev(struct kvm *kvm, enum kvm_bus bus_idx,
                            struct kvm_io_device *dev)
 {
@@ -2019,7 +2026,7 @@ int kvm_io_bus_register_dev(struct kvm *kvm, enum kvm_bus bus_idx,
        return 0;
 }
 
-/* Caller must have write lock on slots_lock. */
+/* Caller must hold slots_lock. */
 int kvm_io_bus_unregister_dev(struct kvm *kvm, enum kvm_bus bus_idx,
                              struct kvm_io_device *dev)
 {