Make kvm_device_ops registration dynamic
v3 cover Make kvm_device_ops registration dynamic
Hi all,
This is version 3 of the patches originally posted here:
v1: http://www.spinics.net/lists/kvm-arm/msg10219.html
v2: http://www.spinics.net/lists/kvm/msg105197.html
Changes since v2 include:
- Rebased onto 3.17-rc* (the vgic code changed a lot!)
- Added relevant acks
The mpic, flic and xics are still not ported over, as I don't want to risk breaking those devices (it's not clear at which point they need to be registered).
Thanks,
Will
--->8
Cornelia Huck (1):
KVM: s390: register flic ops dynamically
Will Deacon (3):
KVM: device: add simple registration mechanism for kvm_device_ops
KVM: ARM: vgic: register kvm_device_ops dynamically
KVM: VFIO: register kvm_device_ops dynamically
arch/s390/kvm/kvm-s390.c | 3 +- arch/s390/kvm/kvm-s390.h | 1 + include/linux/kvm_host.h | 4 +- include/uapi/linux/kvm.h | 22 +++++-- virt/kvm/arm/vgic.c | 157 ++++++++++++++++++++++++----------------------- virt/kvm/kvm_main.c | 57 +++++++++-------- virt/kvm/vfio.c | 22 ++++--- 7 files changed, 142 insertions(+), 124 deletions(-)
Signature · 1 line
2.1.0
PATCH v3 1/4 KVM: device: add simple registration mechanism for kvm_device_ops
kvm_ioctl_create_device currently has knowledge of all the device types and their associated ops. This is fairly inflexible when adding support for new in-kernel device emulations, so move what we currently have out into a table, which can support dynamic registration of ops by new drivers for virtual hardware.
--- include/linux/kvm_host.h | 1 + include/uapi/linux/kvm.h | 22 +++++++++++----- virt/kvm/kvm_main.c | 65 ++++++++++++++++++++++++++++-------------------- 3 files changed, 55 insertions(+), 33 deletions(-)
include/linux/kvm_host.h +1 -0
@@ -1068,6 +1068,7 @@ struct kvm_device_ops {void kvm_device_get (struct kvm_device *dev);void kvm_device_put (struct kvm_device *dev);struct kvm_device *kvm_device_from_filp (struct file *filp); +int kvm_register_device_ops (struct kvm_device_ops *ops,u32 type);extern struct kvm_device_ops kvm_mpic_ops;extern struct kvm_device_ops kvm_xics_ops;
include/uapi/linux/kvm.h +16 -6
@@ -947,15 +947,25 @@ struct kvm_device_attr {__u64 addr;/* userspace address of attr data */ }; -#define KVM_DEV_TYPE_FSL_MPIC_20 1 -#define KVM_DEV_TYPE_FSL_MPIC_42 2 -#define KVM_DEV_TYPE_XICS 3 -#define KVM_DEV_TYPE_VFIO 4#define KVM_DEV_VFIO_GROUP 1#define KVM_DEV_VFIO_GROUP_ADD 1#define KVM_DEV_VFIO_GROUP_DEL 2 -#define KVM_DEV_TYPE_ARM_VGIC_V2 5 -#define KVM_DEV_TYPE_FLIC 6 + +enum kvm_device_type { +KVM_DEV_TYPE_FSL_MPIC_20 =1 , +#define KVM_DEV_TYPE_FSL_MPIC_20 KVM_DEV_TYPE_FSL_MPIC_20 + KVM_DEV_TYPE_FSL_MPIC_42, +#define KVM_DEV_TYPE_FSL_MPIC_42 KVM_DEV_TYPE_FSL_MPIC_42 + KVM_DEV_TYPE_XICS, +#define KVM_DEV_TYPE_XICS KVM_DEV_TYPE_XICS + KVM_DEV_TYPE_VFIO, +#define KVM_DEV_TYPE_VFIO KVM_DEV_TYPE_VFIO + KVM_DEV_TYPE_ARM_VGIC_V2, +#define KVM_DEV_TYPE_ARM_VGIC_V2 KVM_DEV_TYPE_ARM_VGIC_V2 + KVM_DEV_TYPE_FLIC, +#define KVM_DEV_TYPE_FLIC KVM_DEV_TYPE_FLIC + KVM_DEV_TYPE_MAX, +};/* * ioctls for VM fds
virt/kvm/kvm_main.c +38 -27
82 lines not on this page · raw message
Signature · 1 line
2.1.0
PATCH v3 2/4 KVM: ARM: vgic: register kvm_device_ops dynamically
In reply to Will DeaconNow that we have a dynamic means to register kvm_device_ops, use that for the ARM VGIC, instead of relying on the static table.
--- include/linux/kvm_host.h | 1 - virt/kvm/arm/vgic.c | 157 ++++++++++++++++++++++++----------------------- virt/kvm/kvm_main.c | 4 -- 3 files changed, 79 insertions(+), 83 deletions(-)
include/linux/kvm_host.h +0 -1
@@ -1073,7 +1073,6 @@ int kvm_register_device_ops(struct kvm_device_ops *ops, u32 type);extern struct kvm_device_ops kvm_mpic_ops;extern struct kvm_device_ops kvm_xics_ops;extern struct kvm_device_ops kvm_vfio_ops; -extern struct kvm_device_ops kvm_arm_vgic_v2_ops;extern struct kvm_device_ops kvm_flic_ops;#ifdef CONFIG_HAVE_KVM_CPU_RELAX_INTERCEPT
virt/kvm/arm/vgic.c +79 -78
172 lines not on this page · raw message
virt/kvm/kvm_main.c +0 -4
@@ -2273,10 +2273,6 @@ static struct kvm_device_ops *kvm_device_ops_table[KVM_DEV_TYPE_MAX] = { [KVM_DEV_TYPE_VFIO] = &kvm_vfio_ops,#endif -#ifdef CONFIG_KVM_ARM_VGIC - [KVM_DEV_TYPE_ARM_VGIC_V2 ] = &kvm_arm_vgic_v2_ops, -#endif - #ifdef CONFIG_S390 [KVM_DEV_TYPE_FLIC] = &kvm_flic_ops,#endif
Signature · 1 line
2.1.0
PATCH v3 3/4 KVM: s390: register flic ops dynamically
In reply to Will DeaconFrom: Cornelia Huck <[email protected]>
Using the new kvm_register_device_ops() interface makes us get rid of an #ifdef in common code.
--- arch/s390/kvm/kvm-s390.c | 3 ++- arch/s390/kvm/kvm-s390.h | 1 + include/linux/kvm_host.h | 1 - virt/kvm/kvm_main.c | 4 ---- 4 files changed, 3 insertions(+), 6 deletions(-)
arch/s390/kvm/kvm-s390.c +2 -1
@@ -130,7 +130,8 @@ void kvm_arch_check_processor_compat(void *rtn)int kvm_arch_init (void *opaque) { -return 0 ; +/* Register floating interrupt controller interface. */ +return kvm_register_device_ops (&kvm_flic_ops,KVM_DEV_TYPE_FLIC ); }void kvm_arch_exit (void )
arch/s390/kvm/kvm-s390.h +1 -0
@@ -228,6 +228,7 @@ int kvm_cpu_has_interrupt(struct kvm_vcpu *vcpu);int psw_extint_disabled (struct kvm_vcpu *vcpu);void kvm_s390_destroy_adapters (struct kvm *kvm);int kvm_s390_si_ext_call_pending (struct kvm_vcpu *vcpu); +extern struct kvm_device_ops kvm_flic_ops;/* implemented in guestdbg.c */ void kvm_s390_backup_guest_per_regs (struct kvm_vcpu *vcpu);
include/linux/kvm_host.h +0 -1
@@ -1073,7 +1073,6 @@ int kvm_register_device_ops(struct kvm_device_ops *ops, u32 type);extern struct kvm_device_ops kvm_mpic_ops;extern struct kvm_device_ops kvm_xics_ops;extern struct kvm_device_ops kvm_vfio_ops; -extern struct kvm_device_ops kvm_flic_ops;#ifdef CONFIG_HAVE_KVM_CPU_RELAX_INTERCEPT
virt/kvm/kvm_main.c +0 -4
@@ -2272,10 +2272,6 @@ static struct kvm_device_ops *kvm_device_ops_table[KVM_DEV_TYPE_MAX] = { #ifdef CONFIG_KVM_VFIO [KVM_DEV_TYPE_VFIO] = &kvm_vfio_ops,#endif - -#ifdef CONFIG_S390 - [KVM_DEV_TYPE_FLIC] = &kvm_flic_ops, -#endif };int kvm_register_device_ops (struct kvm_device_ops *ops,u32 type)
Signature · 1 line
2.1.0
PATCH v3 4/4 KVM: VFIO: register kvm_device_ops dynamically
In reply to Will DeaconNow 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.
--- include/linux/kvm_host.h | 1 - virt/kvm/kvm_main.c | 4 ---- virt/kvm/vfio.c | 22 +++++++++++++++------- 3 files changed, 15 insertions(+), 12 deletions(-)
include/linux/kvm_host.h +0 -1
@@ -1072,7 +1072,6 @@ int kvm_register_device_ops(struct kvm_device_ops *ops, u32 type);extern struct kvm_device_ops kvm_mpic_ops;extern struct kvm_device_ops kvm_xics_ops; -extern struct kvm_device_ops kvm_vfio_ops;#ifdef CONFIG_HAVE_KVM_CPU_RELAX_INTERCEPT
virt/kvm/kvm_main.c +0 -4
@@ -2268,10 +2268,6 @@ static struct kvm_device_ops *kvm_device_ops_table[KVM_DEV_TYPE_MAX] = { #ifdef CONFIG_KVM_XICS [KVM_DEV_TYPE_XICS] = &kvm_xics_ops,#endif - -#ifdef CONFIG_KVM_VFIO - [KVM_DEV_TYPE_VFIO] = &kvm_vfio_ops, -#endif };int kvm_register_device_ops (struct kvm_device_ops *ops,u32 type)
virt/kvm/vfio.c +15 -7
@@ -246,6 +246,16 @@ static void kvm_vfio_destroy(struct kvm_device *dev)kfree (dev);/* alloc by kvm_ioctl_create_device, free by .destroy */ } +static int kvm_vfio_create (struct kvm_device *dev,u32 type); + +static struct kvm_device_ops kvm_vfio_ops = { + .name ="kvm-vfio" , + .create = kvm_vfio_create, + .destroy = kvm_vfio_destroy, + .set_attr = kvm_vfio_set_attr, + .has_attr = kvm_vfio_has_attr, +}; +static int kvm_vfio_create (struct kvm_device *dev,u32 type) {struct kvm_device *tmp;
@@ -268,10 +278,8 @@ static int kvm_vfio_create(struct kvm_device *dev, u32 type)return 0 ; } -struct kvm_device_ops kvm_vfio_ops = { - .name ="kvm-vfio" , - .create = kvm_vfio_create, - .destroy = kvm_vfio_destroy, - .set_attr = kvm_vfio_set_attr, - .has_attr = kvm_vfio_has_attr, -}; +static int __init kvm_vfio_ops_init (void ) +{ +return kvm_register_device_ops (&kvm_vfio_ops,KVM_DEV_TYPE_VFIO ); +} +module_init (kvm_vfio_ops_init);
Signature · 1 line
2.1.0
Hi Paolo,
Quoted 7 lines · Will Deacon
Hi all,
This is version 3 of the patches originally posted here:
v1: http://www.spinics.net/lists/kvm-arm/msg10219.html
v2: http://www.spinics.net/lists/kvm/msg105197.html
Quoted 8 lines
Changes since v2 include:
- Rebased onto 3.17-rc* (the vgic code changed a lot!)
- Added relevant acksThe mpic, flic and xics are still not ported over, as I don't want to risk breaking those devices (it's not clear at which point they need to be registered).
Any further comments on this lot?
Will
Paolo Bonzini
maintainerIl 02/09/2014 11:27, Will Deacon ha scritto:
Quoted 2 lines
The mpic, flic and xics are still not ported over, as I don't want to risk breaking those devices
Actually FLIC is ported. :)
Quoted 10 lines
arch/s390/kvm/kvm-s390.c | 3 +- arch/s390/kvm/kvm-s390.h | 1 + include/linux/kvm_host.h | 4 +- include/uapi/linux/kvm.h | 22 +++++-- virt/kvm/arm/vgic.c | 157 ++++++++++++++++++++++++----------------------- virt/kvm/kvm_main.c | 57 +++++++++-------- virt/kvm/vfio.c | 22 ++++--- 7 files changed, 142 insertions(+), 124 deletions(-)
Thanks, applying to kvm/queue. Alex (Graf) and Paul, can you look at MPIC and XICS?
Paolo