KVM: x86: allow setting identity map addr with no vcpus only
authorDavid Hildenbrand <david@redhat.com>
Thu, 24 Aug 2017 18:51:36 +0000 (20:51 +0200)
committerPaolo Bonzini <pbonzini@redhat.com>
Thu, 12 Oct 2017 12:01:53 +0000 (14:01 +0200)
Changing it afterwards doesn't make too much sense and will only result
in inconsistencies.

Reviewed-by: Radim Krčmář <rkrcmar@redhat.com>
Signed-off-by: David Hildenbrand <david@redhat.com>
Signed-off-by: Radim Krčmář <rkrcmar@redhat.com>
Documentation/virtual/kvm/api.txt
arch/x86/kvm/x86.c

index 22bc5a052a5d69995dbfb84c571a7b5b7a58284a..dd2dd96927b8ee3c8ee0cf0931b8cc2db58eb023 100644 (file)
@@ -1131,6 +1131,7 @@ This ioctl is required on Intel-based hosts.  This is needed on Intel hardware
 because of a quirk in the virtualization implementation (see the internals
 documentation when it pops into existence).
 
+Fails if any VCPU has already been created.
 
 4.41 KVM_SET_BOOT_CPU_ID
 
index 632561b2a3f66e85902e0eaeec8eb2da51f5cfc8..b0d291518e886cf8630d84837916456ae94d1288 100644 (file)
@@ -4034,10 +4034,16 @@ long kvm_arch_vm_ioctl(struct file *filp,
        case KVM_SET_IDENTITY_MAP_ADDR: {
                u64 ident_addr;
 
+               mutex_lock(&kvm->lock);
+               r = -EINVAL;
+               if (kvm->created_vcpus)
+                       goto set_identity_unlock;
                r = -EFAULT;
                if (copy_from_user(&ident_addr, argp, sizeof ident_addr))
-                       goto out;
+                       goto set_identity_unlock;
                r = kvm_vm_ioctl_set_identity_map_addr(kvm, ident_addr);
+set_identity_unlock:
+               mutex_unlock(&kvm->lock);
                break;
        }
        case KVM_SET_NR_MMU_PAGES: