Right now, the kvm module is kept alive by VFS via fops_get/fops_put, but there
may be cases in which a kvm_get_kvm's matching kvm_put_kvm happens after
the file descriptor is closed. One case that will be introduced soon is
when work is delegated to the system work queue; the worker might be
a bit late and the file descriptor can be closed in the meantime. Ensure
that the module has not gone away by tying a module reference explicitly
to the lifetime of the struct kvm.
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
preempt_notifier_inc();
kvm_init_pm_notifier(kvm);
+ /* This is safe, since we have a reference from open(). */
+ __module_get(THIS_MODULE);
+
return kvm;
out_err:
preempt_notifier_dec();
hardware_disable_all();
mmdrop(mm);
+ module_put(THIS_MODULE);
}
void kvm_get_kvm(struct kvm *kvm)