diff mbox

[v2,3/5] KVM: move kvm_{get|put}_kvm to kvm_host.h

Message ID 1477771515-18015-4-git-send-email-jike.song@intel.com (mailing list archive)
State New, archived
Headers show

Commit Message

Jike Song Oct. 29, 2016, 8:05 p.m. UTC
So that external users like vfio can call them without introducing
symbol-level dependency. A destroy() method is introduced to the kvm
structure so that we don't have to also expose kvm_destroy_vm.

Signed-off-by: Jike Song <jike.song@intel.com>
---
 include/linux/kvm_host.h | 13 +++++++++++--
 virt/kvm/kvm_main.c      | 16 ++--------------
 2 files changed, 13 insertions(+), 16 deletions(-)

Comments

Paolo Bonzini Oct. 30, 2016, 8:53 a.m. UTC | #1
On 29/10/2016 22:05, Jike Song wrote:
> So that external users like vfio can call them without introducing
> symbol-level dependency. A destroy() method is introduced to the kvm
> structure so that we don't have to also expose kvm_destroy_vm.

VFIO does not need kvm_put_kvm, so kvm_destroy_vm need not be exported
(or kvm_put_kvm can remain non-inline).

Paolo
--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Jike Song Oct. 31, 2016, 1:40 a.m. UTC | #2
On 10/30/2016 04:53 PM, Paolo Bonzini wrote:
> On 29/10/2016 22:05, Jike Song wrote:
>> So that external users like vfio can call them without introducing
>> symbol-level dependency. A destroy() method is introduced to the kvm
>> structure so that we don't have to also expose kvm_destroy_vm.
> 
> VFIO does not need kvm_put_kvm, so kvm_destroy_vm need not be exported
> (or kvm_put_kvm can remain non-inline).

Yes, good point. Will keep kvm_put_kvm.

--
Thanks,
Jike

--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
index 01c0b9c..583e9e2 100644
--- a/include/linux/kvm_host.h
+++ b/include/linux/kvm_host.h
@@ -405,6 +405,7 @@  struct kvm {
 	struct kvm_vm_stat stat;
 	struct kvm_arch arch;
 	atomic_t users_count;
+	void (*destroy)(struct kvm *kvm);
 #ifdef KVM_COALESCED_MMIO_PAGE_OFFSET
 	struct kvm_coalesced_mmio_ring *coalesced_mmio_ring;
 	spinlock_t ring_lock;
@@ -526,8 +527,16 @@  int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
 		  struct module *module);
 void kvm_exit(void);
 
-void kvm_get_kvm(struct kvm *kvm);
-void kvm_put_kvm(struct kvm *kvm);
+static inline void kvm_get_kvm(struct kvm *kvm)
+{
+	atomic_inc(&kvm->users_count);
+}
+
+static inline void kvm_put_kvm(struct kvm *kvm)
+{
+	if (atomic_dec_and_test(&kvm->users_count))
+		kvm->destroy(kvm);
+}
 
 static inline struct kvm_memslots *__kvm_memslots(struct kvm *kvm, int as_id)
 {
diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
index 81dfc73..996a88d 100644
--- a/virt/kvm/kvm_main.c
+++ b/virt/kvm/kvm_main.c
@@ -106,6 +106,7 @@ 
 static int kvm_debugfs_num_entries;
 static const struct file_operations *stat_fops_per_vm[];
 
+static void kvm_destroy_vm(struct kvm *kvm);
 static long kvm_vcpu_ioctl(struct file *file, unsigned int ioctl,
 			   unsigned long arg);
 #ifdef CONFIG_KVM_COMPAT
@@ -620,6 +621,7 @@  static struct kvm *kvm_create_vm(unsigned long type)
 	mutex_init(&kvm->irq_lock);
 	mutex_init(&kvm->slots_lock);
 	atomic_set(&kvm->users_count, 1);
+	kvm->destroy = kvm_destroy_vm;
 	INIT_LIST_HEAD(&kvm->devices);
 
 	r = kvm_arch_init_vm(kvm, type);
@@ -740,20 +742,6 @@  static void kvm_destroy_vm(struct kvm *kvm)
 	mmdrop(mm);
 }
 
-void kvm_get_kvm(struct kvm *kvm)
-{
-	atomic_inc(&kvm->users_count);
-}
-EXPORT_SYMBOL_GPL(kvm_get_kvm);
-
-void kvm_put_kvm(struct kvm *kvm)
-{
-	if (atomic_dec_and_test(&kvm->users_count))
-		kvm_destroy_vm(kvm);
-}
-EXPORT_SYMBOL_GPL(kvm_put_kvm);
-
-
 static int kvm_vm_release(struct inode *inode, struct file *filp)
 {
 	struct kvm *kvm = filp->private_data;