[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH v3 1/7] x86: add x86_cpu_unrealizefn() for cpu apic
From: |
Zhu Guihua |
Subject: |
[Qemu-devel] [PATCH v3 1/7] x86: add x86_cpu_unrealizefn() for cpu apic remove |
Date: |
Fri, 13 Feb 2015 18:40:16 +0800 |
From: Chen Fan <address@hidden>
Implement x86_cpu_unrealizefn() for corresponding x86_cpu_realizefn(),
which is mostly used to clean the apic related allocation and vmstates
at here.
Signed-off-by: Chen Fan <address@hidden>
Signed-off-by: Gu Zheng <address@hidden>
Signed-off-by: Zhu Guihua <address@hidden>
---
hw/i386/kvm/apic.c | 5 +++++
hw/intc/apic.c | 9 ++++++++
hw/intc/apic_common.c | 21 ++++++++++++-------
include/hw/i386/apic_internal.h | 1 +
target-i386/cpu.c | 46 +++++++++++++++++++++++++++++++++++++++++
5 files changed, 74 insertions(+), 8 deletions(-)
diff --git a/hw/i386/kvm/apic.c b/hw/i386/kvm/apic.c
index 4b7ce57..45abfe9 100644
--- a/hw/i386/kvm/apic.c
+++ b/hw/i386/kvm/apic.c
@@ -195,11 +195,16 @@ static void kvm_apic_realize(DeviceState *dev, Error
**errp)
}
}
+static void kvm_apic_unrealize(DeviceState *dev, Error **errp)
+{
+}
+
static void kvm_apic_class_init(ObjectClass *klass, void *data)
{
APICCommonClass *k = APIC_COMMON_CLASS(klass);
k->realize = kvm_apic_realize;
+ k->unrealize = kvm_apic_unrealize;
k->reset = kvm_apic_reset;
k->set_base = kvm_apic_set_base;
k->set_tpr = kvm_apic_set_tpr;
diff --git a/hw/intc/apic.c b/hw/intc/apic.c
index e48974f..f260cdf 100644
--- a/hw/intc/apic.c
+++ b/hw/intc/apic.c
@@ -895,11 +895,20 @@ static void apic_realize(DeviceState *dev, Error **errp)
msi_supported = true;
}
+static void apic_unrealize(DeviceState *dev, Error **errp)
+{
+ APICCommonState *s = APIC_COMMON(dev);
+
+ timer_free(s->timer);
+ local_apics[s->idx] = NULL;
+}
+
static void apic_class_init(ObjectClass *klass, void *data)
{
APICCommonClass *k = APIC_COMMON_CLASS(klass);
k->realize = apic_realize;
+ k->unrealize = apic_unrealize;
k->set_base = apic_set_base;
k->set_tpr = apic_set_tpr;
k->get_tpr = apic_get_tpr;
diff --git a/hw/intc/apic_common.c b/hw/intc/apic_common.c
index 52b933d..657ffa0 100644
--- a/hw/intc/apic_common.c
+++ b/hw/intc/apic_common.c
@@ -302,17 +302,9 @@ static void apic_common_realize(DeviceState *dev, Error
**errp)
APICCommonState *s = APIC_COMMON(dev);
APICCommonClass *info;
static DeviceState *vapic;
- static int apic_no;
PCMachineState *pcms = PC_MACHINE(qdev_get_machine());
static bool mmio_registered;
- if (apic_no >= MAX_APICS) {
- error_setg(errp, "%s initialization failed.",
- object_get_typename(OBJECT(dev)));
- return;
- }
- s->idx = apic_no++;
-
info = APIC_COMMON_GET_CLASS(s);
info->realize(dev, errp);
@@ -335,6 +327,18 @@ static void apic_common_realize(DeviceState *dev, Error
**errp)
}
+static void apic_common_unrealize(DeviceState *dev, Error **errp)
+{
+ APICCommonState *s = APIC_COMMON(dev);
+ APICCommonClass *info = APIC_COMMON_GET_CLASS(s);
+
+ info->unrealize(dev, errp);
+
+ if (apic_report_tpr_access && info->enable_tpr_reporting) {
+ info->enable_tpr_reporting(s, false);
+ }
+}
+
static int apic_pre_load(void *opaque)
{
APICCommonState *s = APIC_COMMON(opaque);
@@ -442,6 +446,7 @@ static void apic_common_class_init(ObjectClass *klass, void
*data)
dc->reset = apic_reset_common;
dc->props = apic_properties_common;
dc->realize = apic_common_realize;
+ dc->unrealize = apic_common_unrealize;
/*
* Reason: APIC and CPU need to be wired up by
* x86_cpu_apic_create()
diff --git a/include/hw/i386/apic_internal.h b/include/hw/i386/apic_internal.h
index 578a616..3432a78 100644
--- a/include/hw/i386/apic_internal.h
+++ b/include/hw/i386/apic_internal.h
@@ -81,6 +81,7 @@ typedef struct APICCommonClass
DeviceClass parent_class;
DeviceRealize realize;
+ DeviceUnrealize unrealize;
void (*set_base)(APICCommonState *s, uint64_t val);
void (*set_tpr)(APICCommonState *s, uint8_t val);
uint8_t (*get_tpr)(APICCommonState *s);
diff --git a/target-i386/cpu.c b/target-i386/cpu.c
index fc0e4a6..84c88fe 100644
--- a/target-i386/cpu.c
+++ b/target-i386/cpu.c
@@ -2775,6 +2775,8 @@ static void x86_cpu_apic_create(X86CPU *cpu, Error **errp)
/* TODO: convert to link<> */
apic = APIC_COMMON(cpu->apic_state);
+ g_assert(apic_id < MAX_APICS);
+ apic->idx = apic_id;
apic->cpu = cpu;
}
@@ -2798,10 +2800,32 @@ static void x86_cpu_apic_realize(X86CPU *cpu, Error
**errp)
return;
}
}
+
+static void x86_cpu_apic_unrealize(X86CPU *cpu, Error **errp)
+{
+ Error *local_err = NULL;
+
+ if (cpu->apic_state == NULL) {
+ return;
+ }
+
+ object_property_set_bool(OBJECT(cpu->apic_state),
+ false, "realized", &local_err);
+ if (local_err != NULL) {
+ error_propagate(errp, local_err);
+ return;
+ }
+
+ vmstate_unregister(NULL, &vmstate_apic_common, cpu->apic_state);
+ object_unparent(OBJECT(cpu->apic_state));
+}
#else
static void x86_cpu_apic_realize(X86CPU *cpu, Error **errp)
{
}
+static void x86_cpu_apic_unrealize(X86CPU *cpu, Error **errp)
+{
+}
#endif
@@ -2884,6 +2908,27 @@ out:
}
}
+static void x86_cpu_unrealizefn(DeviceState *dev, Error **errp)
+{
+ X86CPU *cpu = X86_CPU(dev);
+ CPUClass *cc = CPU_GET_CLASS(dev);
+ Error *local_err = NULL;
+
+ if (qdev_get_vmsd(DEVICE(cpu)) == NULL) {
+ vmstate_unregister(NULL, &vmstate_cpu_common, cpu);
+ }
+
+ if (cc->vmsd != NULL) {
+ vmstate_unregister(NULL, cc->vmsd, cpu);
+ }
+
+ x86_cpu_apic_unrealize(cpu, &local_err);
+ if (local_err != NULL) {
+ error_propagate(errp, local_err);
+ return;
+ }
+}
+
/* Enables contiguous-apic-ID mode, for compatibility */
static bool compat_apic_id_mode;
@@ -3059,6 +3104,7 @@ static void x86_cpu_common_class_init(ObjectClass *oc,
void *data)
xcc->parent_realize = dc->realize;
dc->realize = x86_cpu_realizefn;
+ dc->unrealize = x86_cpu_unrealizefn;
dc->props = x86_cpu_properties;
xcc->parent_reset = cc->reset;
--
1.9.3
- [Qemu-devel] [PATCH v3 0/7] cpu: add i386 cpu hot remove support, Zhu Guihua, 2015/02/13
- [Qemu-devel] [PATCH v3 2/7] acpi/cpu: add cpu hot unplug request callback function, Zhu Guihua, 2015/02/13
- [Qemu-devel] [PATCH v3 1/7] x86: add x86_cpu_unrealizefn() for cpu apic remove,
Zhu Guihua <=
- [Qemu-devel] [PATCH v3 3/7] acpi, pc: add cpu hot unplug request callback support, Zhu Guihua, 2015/02/13
- [Qemu-devel] [PATCH v3 4/7] acpi/cpu: add cpu hot unplug callback function, Zhu Guihua, 2015/02/13
- [Qemu-devel] [PATCH v3 5/7] acpi, pc: add cpu hot unplug callback support, Zhu Guihua, 2015/02/13
- [Qemu-devel] [PATCH v3 6/7] cpu hotplug: implement function cpu_status_write() for vcpu ejection, Zhu Guihua, 2015/02/13
- [Qemu-devel] [PATCH v3 7/7] cpus: reclaim allocated vCPU objects, Zhu Guihua, 2015/02/13
- Re: [Qemu-devel] [PATCH v3 0/7] cpu: add i386 cpu hot remove support, Gu Zheng, 2015/02/23