From 782c3f2939a8faefa4c5a324dfb472a534048510 Mon Sep 17 00:00:00 2001 From: Eduardo Habkost Date: Fri, 26 Sep 2014 17:45:24 -0300 Subject: accel: Move KVM accel registration to kvm-all.c Note that this has an user-visible side-effect: instead of reporting "KVM is not supported for this target", QEMU binaries not supporting KVM will report "kvm accelerator does not exist". As kvm_availble() always return 1 when CONFIG_KVM is enabled, we don't need to set AccelClass.available anymore. kvm_enabled() is not being completely removed yet only because qmp_query_kvm() still uses it. This also allows us to make kvm_init() static. Reviewed-by: Paolo Bonzini Signed-off-by: Eduardo Habkost Signed-off-by: Paolo Bonzini --- kvm-all.c | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) (limited to 'kvm-all.c') diff --git a/kvm-all.c b/kvm-all.c index 4afcd05..18dcd45 100644 --- a/kvm-all.c +++ b/kvm-all.c @@ -25,6 +25,7 @@ #include "qemu/option.h" #include "qemu/config-file.h" #include "sysemu/sysemu.h" +#include "sysemu/accel.h" #include "hw/hw.h" #include "hw/pci/msi.h" #include "hw/s390x/adapter.h" @@ -106,6 +107,8 @@ struct KVMState #endif }; +#define TYPE_KVM_ACCEL ACCEL_CLASS_NAME("kvm") + KVMState *kvm_state; bool kvm_kernel_irqchip; bool kvm_async_interrupts_allowed; @@ -1377,7 +1380,7 @@ static int kvm_max_vcpus(KVMState *s) return (ret) ? ret : kvm_recommended_vcpus(s); } -int kvm_init(MachineClass *mc) +static int kvm_init(MachineClass *mc) { static const char upgrade_note[] = "Please upgrade to at least kernel 2.6.29 or recent kvm-kmod\n" @@ -2225,3 +2228,24 @@ int kvm_get_one_reg(CPUState *cs, uint64_t id, void *target) } return r; } + +static void kvm_accel_class_init(ObjectClass *oc, void *data) +{ + AccelClass *ac = ACCEL_CLASS(oc); + ac->name = "KVM"; + ac->init = kvm_init; + ac->allowed = &kvm_allowed; +} + +static const TypeInfo kvm_accel_type = { + .name = TYPE_KVM_ACCEL, + .parent = TYPE_ACCEL, + .class_init = kvm_accel_class_init, +}; + +static void kvm_type_init(void) +{ + type_register_static(&kvm_accel_type); +} + +type_init(kvm_type_init); -- cgit v1.1 From 0d15da8e6fc3cbcd088476c561dcc88b9aae493a Mon Sep 17 00:00:00 2001 From: Eduardo Habkost Date: Fri, 26 Sep 2014 17:45:29 -0300 Subject: accel: Rename 'init' method to 'init_machine' Today, all accelerator init functions affect some global state: * tcg_init() calls tcg_exec_init() and affects globals such as tcg_tcx, page size globals, and possibly others; * kvm_init() changes the kvm_state global, cpu_interrupt_handler, and possibly others; * xen_init() changes the xen_xc global, and registers a change state handler. With the new accelerator QOM classes, initialization may now be split in two steps: * instance_init() will do basic initialization that doesn't affect any global state and don't need MachineState or MachineClass data. This will allow probing code to safely create multiple accelerator objects on the fly just for reporting host/accelerator capabilities, for example. * accel_init_machine()/init_machine() will save the accelerator object in MachineState, and do initialization steps which still affect global state, machine state, or that need data from MachineClass or MachineState. To clarify the difference between those two steps, rename init() to init_machine(). Signed-off-by: Eduardo Habkost Signed-off-by: Paolo Bonzini --- kvm-all.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'kvm-all.c') diff --git a/kvm-all.c b/kvm-all.c index 18dcd45..ce0e4c7 100644 --- a/kvm-all.c +++ b/kvm-all.c @@ -2233,7 +2233,7 @@ static void kvm_accel_class_init(ObjectClass *oc, void *data) { AccelClass *ac = ACCEL_CLASS(oc); ac->name = "KVM"; - ac->init = kvm_init; + ac->init_machine = kvm_init; ac->allowed = &kvm_allowed; } -- cgit v1.1 From f6a1ef64408a5f7f52601589fef2a850b93d817e Mon Sep 17 00:00:00 2001 From: Eduardo Habkost Date: Fri, 26 Sep 2014 17:45:30 -0300 Subject: accel: Pass MachineState object to accel init functions Most of the machine options and machine state information is in the MachineState object, not on the MachineClass. This will allow init functions to use the MachineState object directly instead of qemu_get_machine_opts() or the current_machine global. Reviewed-by: Paolo Bonzini Signed-off-by: Eduardo Habkost Signed-off-by: Paolo Bonzini --- kvm-all.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'kvm-all.c') diff --git a/kvm-all.c b/kvm-all.c index ce0e4c7..0a9de92 100644 --- a/kvm-all.c +++ b/kvm-all.c @@ -1380,8 +1380,9 @@ static int kvm_max_vcpus(KVMState *s) return (ret) ? ret : kvm_recommended_vcpus(s); } -static int kvm_init(MachineClass *mc) +static int kvm_init(MachineState *ms) { + MachineClass *mc = MACHINE_GET_CLASS(ms); static const char upgrade_note[] = "Please upgrade to at least kernel 2.6.29 or recent kvm-kmod\n" "(see http://sourceforge.net/projects/kvm).\n"; -- cgit v1.1 From fc02086b5ab8de50ce8234cf8f42b254de9e5d91 Mon Sep 17 00:00:00 2001 From: Eduardo Habkost Date: Fri, 26 Sep 2014 17:45:32 -0300 Subject: kvm: Make KVMState be the TYPE_KVM_ACCEL instance struct Now that we create an accel object before calling machine_init, we can simply use the accel object to save all KVMState data, instead of allocationg KVMState manually. Reviewed-by: Paolo Bonzini Signed-off-by: Eduardo Habkost Signed-off-by: Paolo Bonzini --- kvm-all.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'kvm-all.c') diff --git a/kvm-all.c b/kvm-all.c index 0a9de92..e98a7c7 100644 --- a/kvm-all.c +++ b/kvm-all.c @@ -71,8 +71,10 @@ typedef struct KVMSlot typedef struct kvm_dirty_log KVMDirtyLog; -struct KVMState +typedef struct KVMState { + AccelState parent_obj; + KVMSlot *slots; int nr_slots; int fd; @@ -105,10 +107,13 @@ struct KVMState QTAILQ_HEAD(msi_hashtab, KVMMSIRoute) msi_hashtab[KVM_MSI_HASHTAB_SIZE]; bool direct_msi; #endif -}; +} KVMState; #define TYPE_KVM_ACCEL ACCEL_CLASS_NAME("kvm") +#define KVM_STATE(obj) \ + OBJECT_CHECK(KVMState, (obj), TYPE_KVM_ACCEL) + KVMState *kvm_state; bool kvm_kernel_irqchip; bool kvm_async_interrupts_allowed; @@ -1401,7 +1406,7 @@ static int kvm_init(MachineState *ms) int i, type = 0; const char *kvm_type; - s = g_malloc0(sizeof(KVMState)); + s = KVM_STATE(ms->accelerator); /* * On systems where the kernel can support different base page @@ -1590,7 +1595,6 @@ err: close(s->fd); } g_free(s->slots); - g_free(s); return ret; } @@ -2242,6 +2246,7 @@ static const TypeInfo kvm_accel_type = { .name = TYPE_KVM_ACCEL, .parent = TYPE_ACCEL, .class_init = kvm_accel_class_init, + .instance_size = sizeof(KVMState), }; static void kvm_type_init(void) -- cgit v1.1