Skip to content

Commit 80ce163

Browse files
wildea01bonzini
authored andcommitted
KVM: VFIO: register kvm_device_ops dynamically
Now that we have a dynamic means to register kvm_device_ops, use that for the VFIO kvm device, instead of relying on the static table. This is achieved by a module_init call to register the ops with KVM. Cc: Gleb Natapov <gleb@kernel.org> Cc: Paolo Bonzini <pbonzini@redhat.com> Acked-by: Alex Williamson <Alex.Williamson@redhat.com> Signed-off-by: Will Deacon <will.deacon@arm.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
1 parent 84877d9 commit 80ce163

File tree

3 files changed

+15
-12
lines changed

3 files changed

+15
-12
lines changed

include/linux/kvm_host.h

-1
Original file line numberDiff line numberDiff line change
@@ -1068,7 +1068,6 @@ int kvm_register_device_ops(struct kvm_device_ops *ops, u32 type);
10681068

10691069
extern struct kvm_device_ops kvm_mpic_ops;
10701070
extern struct kvm_device_ops kvm_xics_ops;
1071-
extern struct kvm_device_ops kvm_vfio_ops;
10721071

10731072
#ifdef CONFIG_HAVE_KVM_CPU_RELAX_INTERCEPT
10741073

virt/kvm/kvm_main.c

-4
Original file line numberDiff line numberDiff line change
@@ -2281,10 +2281,6 @@ static struct kvm_device_ops *kvm_device_ops_table[KVM_DEV_TYPE_MAX] = {
22812281
#ifdef CONFIG_KVM_XICS
22822282
[KVM_DEV_TYPE_XICS] = &kvm_xics_ops,
22832283
#endif
2284-
2285-
#ifdef CONFIG_KVM_VFIO
2286-
[KVM_DEV_TYPE_VFIO] = &kvm_vfio_ops,
2287-
#endif
22882284
};
22892285

22902286
int kvm_register_device_ops(struct kvm_device_ops *ops, u32 type)

virt/kvm/vfio.c

+15-7
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,16 @@ static void kvm_vfio_destroy(struct kvm_device *dev)
246246
kfree(dev); /* alloc by kvm_ioctl_create_device, free by .destroy */
247247
}
248248

249+
static int kvm_vfio_create(struct kvm_device *dev, u32 type);
250+
251+
static struct kvm_device_ops kvm_vfio_ops = {
252+
.name = "kvm-vfio",
253+
.create = kvm_vfio_create,
254+
.destroy = kvm_vfio_destroy,
255+
.set_attr = kvm_vfio_set_attr,
256+
.has_attr = kvm_vfio_has_attr,
257+
};
258+
249259
static int kvm_vfio_create(struct kvm_device *dev, u32 type)
250260
{
251261
struct kvm_device *tmp;
@@ -268,10 +278,8 @@ static int kvm_vfio_create(struct kvm_device *dev, u32 type)
268278
return 0;
269279
}
270280

271-
struct kvm_device_ops kvm_vfio_ops = {
272-
.name = "kvm-vfio",
273-
.create = kvm_vfio_create,
274-
.destroy = kvm_vfio_destroy,
275-
.set_attr = kvm_vfio_set_attr,
276-
.has_attr = kvm_vfio_has_attr,
277-
};
281+
static int __init kvm_vfio_ops_init(void)
282+
{
283+
return kvm_register_device_ops(&kvm_vfio_ops, KVM_DEV_TYPE_VFIO);
284+
}
285+
module_init(kvm_vfio_ops_init);

0 commit comments

Comments
 (0)