Skip to content

Commit c2b8239

Browse files
sean-jcbonzini
authored andcommitted
KVM: Move coalesced MMIO initialization (back) into kvm_create_vm()
Invoke kvm_coalesced_mmio_init() from kvm_create_vm() now that allocating and initializing coalesced MMIO objects is separate from registering any associated devices. Moving coalesced MMIO cleans up the last oddity where KVM does VM creation/initialization after kvm_create_vm(), and more importantly after kvm_arch_post_init_vm() is called and the VM is added to the global vm_list, i.e. after the VM is fully created as far as KVM is concerned. Originally, kvm_coalesced_mmio_init() was called by kvm_create_vm(), but the original implementation was completely devoid of error handling. Commit 6ce5a09 ("KVM: coalesced_mmio: fix kvm_coalesced_mmio_init()'s error handling" fixed the various bugs, and in doing so rightly moved the call to after kvm_create_vm() because kvm_coalesced_mmio_init() also registered the coalesced MMIO device. Commit 2b3c246 ("KVM: Make coalesced mmio use a device per zone") cleaned up that mess by having each zone register a separate device, i.e. moved device registration to its logical home in kvm_vm_ioctl_register_coalesced_mmio(). As a result, kvm_coalesced_mmio_init() is now a "pure" initialization helper and can be safely called from kvm_create_vm(). Opportunstically drop the #ifdef, KVM provides stubs for kvm_coalesced_mmio_{init,free}() when CONFIG_KVM_MMIO=n (s390). Signed-off-by: Sean Christopherson <[email protected]> Message-Id: <[email protected]> Signed-off-by: Paolo Bonzini <[email protected]>
1 parent 405294f commit c2b8239

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

virt/kvm/kvm_main.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1214,6 +1214,10 @@ static struct kvm *kvm_create_vm(unsigned long type, const char *fdname)
12141214
if (r)
12151215
goto out_err_no_mmu_notifier;
12161216

1217+
r = kvm_coalesced_mmio_init(kvm);
1218+
if (r < 0)
1219+
goto out_no_coalesced_mmio;
1220+
12171221
r = kvm_create_vm_debugfs(kvm, fdname);
12181222
if (r)
12191223
goto out_err_no_debugfs;
@@ -1234,6 +1238,8 @@ static struct kvm *kvm_create_vm(unsigned long type, const char *fdname)
12341238
out_err:
12351239
kvm_destroy_vm_debugfs(kvm);
12361240
out_err_no_debugfs:
1241+
kvm_coalesced_mmio_free(kvm);
1242+
out_no_coalesced_mmio:
12371243
#if defined(CONFIG_MMU_NOTIFIER) && defined(KVM_ARCH_WANT_MMU_NOTIFIER)
12381244
if (kvm->mmu_notifier.ops)
12391245
mmu_notifier_unregister(&kvm->mmu_notifier, current->mm);
@@ -4907,11 +4913,6 @@ static int kvm_dev_ioctl_create_vm(unsigned long type)
49074913
goto put_fd;
49084914
}
49094915

4910-
#ifdef CONFIG_KVM_MMIO
4911-
r = kvm_coalesced_mmio_init(kvm);
4912-
if (r < 0)
4913-
goto put_kvm;
4914-
#endif
49154916
file = anon_inode_getfile("kvm-vm", &kvm_vm_fops, kvm, O_RDWR);
49164917
if (IS_ERR(file)) {
49174918
r = PTR_ERR(file);

0 commit comments

Comments
 (0)