KVM: X86: Don't track dirty for KVM_SET_[TSS_ADDR|IDENTITY_MAP_ADDR]
[linux-2.6-microblaze.git] / arch / x86 / kvm / x86.c
index 773cb52..b4ac726 100644 (file)
@@ -10354,7 +10354,32 @@ void kvm_arch_sync_events(struct kvm *kvm)
        kvm_free_pit(kvm);
 }
 
-int __x86_set_memory_region(struct kvm *kvm, int id, gpa_t gpa, u32 size)
+#define  ERR_PTR_USR(e)  ((void __user *)ERR_PTR(e))
+
+/**
+ * __x86_set_memory_region: Setup KVM internal memory slot
+ *
+ * @kvm: the kvm pointer to the VM.
+ * @id: the slot ID to setup.
+ * @gpa: the GPA to install the slot (unused when @size == 0).
+ * @size: the size of the slot. Set to zero to uninstall a slot.
+ *
+ * This function helps to setup a KVM internal memory slot.  Specify
+ * @size > 0 to install a new slot, while @size == 0 to uninstall a
+ * slot.  The return code can be one of the following:
+ *
+ *   HVA:           on success (uninstall will return a bogus HVA)
+ *   -errno:        on error
+ *
+ * The caller should always use IS_ERR() to check the return value
+ * before use.  Note, the KVM internal memory slots are guaranteed to
+ * remain valid and unchanged until the VM is destroyed, i.e., the
+ * GPA->HVA translation will not change.  However, the HVA is a user
+ * address, i.e. its accessibility is not guaranteed, and must be
+ * accessed via __copy_{to,from}_user().
+ */
+void __user * __x86_set_memory_region(struct kvm *kvm, int id, gpa_t gpa,
+                                     u32 size)
 {
        int i, r;
        unsigned long hva, old_npages;
@@ -10363,12 +10388,12 @@ int __x86_set_memory_region(struct kvm *kvm, int id, gpa_t gpa, u32 size)
 
        /* Called with kvm->slots_lock held.  */
        if (WARN_ON(id >= KVM_MEM_SLOTS_NUM))
-               return -EINVAL;
+               return ERR_PTR_USR(-EINVAL);
 
        slot = id_to_memslot(slots, id);
        if (size) {
                if (slot && slot->npages)
-                       return -EEXIST;
+                       return ERR_PTR_USR(-EEXIST);
 
                /*
                 * MAP_SHARED to prevent internal slot pages from being moved
@@ -10377,7 +10402,7 @@ int __x86_set_memory_region(struct kvm *kvm, int id, gpa_t gpa, u32 size)
                hva = vm_mmap(NULL, 0, size, PROT_READ | PROT_WRITE,
                              MAP_SHARED | MAP_ANONYMOUS, 0);
                if (IS_ERR((void *)hva))
-                       return PTR_ERR((void *)hva);
+                       return (void __user *)hva;
        } else {
                if (!slot || !slot->npages)
                        return 0;
@@ -10396,13 +10421,13 @@ int __x86_set_memory_region(struct kvm *kvm, int id, gpa_t gpa, u32 size)
                m.memory_size = size;
                r = __kvm_set_memory_region(kvm, &m);
                if (r < 0)
-                       return r;
+                       return ERR_PTR_USR(r);
        }
 
        if (!size)
                vm_munmap(hva, old_npages * PAGE_SIZE);
 
-       return 0;
+       return (void __user *)hva;
 }
 EXPORT_SYMBOL_GPL(__x86_set_memory_region);