[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [RFC V2 04/10] x86: add x86_cpu_unrealizefn() for cpu a
From: |
Gu Zheng |
Subject: |
Re: [Qemu-devel] [RFC V2 04/10] x86: add x86_cpu_unrealizefn() for cpu apic remove |
Date: |
Thu, 11 Sep 2014 11:06:56 +0800 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:7.0.1) Gecko/20110930 Thunderbird/7.0.1 |
Hi Igor,
On 09/09/2014 09:58 PM, Igor Mammedov wrote:
> On Thu, 28 Aug 2014 11:36:36 +0800
> Gu Zheng <address@hidden> wrote:
>
>> 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>
>> ---
>> hw/i386/kvm/apic.c | 8 +++++++
>> hw/intc/apic.c | 10 ++++++++
>> hw/intc/apic_common.c | 23 +++++++++++++++++++-
>> include/hw/cpu/icc_bus.h | 1 +
>> include/hw/i386/apic_internal.h | 1 +
>> target-i386/cpu-qom.h | 1 +
>> target-i386/cpu.c | 45
>> +++++++++++++++++++++++++++++++++++++++
>> 7 files changed, 88 insertions(+), 1 deletions(-)
>>
>> diff --git a/hw/i386/kvm/apic.c b/hw/i386/kvm/apic.c
>> index e873b50..c95fb8a 100644
>> --- a/hw/i386/kvm/apic.c
>> +++ b/hw/i386/kvm/apic.c
>> @@ -183,11 +183,19 @@ static void kvm_apic_realize(DeviceState *dev, Error
>> **errp)
>> }
>> }
>>
>> +static void kvm_apic_unrealize(DeviceState *dev, Error **errp)
>> +{
>> + APICCommonState *s = APIC_COMMON(dev);
>> +
>> + object_unparent(OBJECT(&s->io_memory));
>> +}
>> +
> what will disable/destroy in kernel APIC?
As we parked kvm cpu, is this step still seriously needed?
>
>> 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->set_base = kvm_apic_set_base;
>> k->set_tpr = kvm_apic_set_tpr;
>> k->get_tpr = kvm_apic_get_tpr;
>> diff --git a/hw/intc/apic.c b/hw/intc/apic.c
>> index 03ff9e9..6d38965 100644
>> --- a/hw/intc/apic.c
>> +++ b/hw/intc/apic.c
>> @@ -885,11 +885,21 @@ static void apic_realize(DeviceState *dev, Error
>> **errp)
>> msi_supported = true;
>> }
>>
>> +static void apic_unrealize(DeviceState *dev, Error **errp)
>> +{
>> + APICCommonState *s = APIC_COMMON(dev);
>> +
>> + object_unparent(OBJECT(&s->io_memory));
>> + 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 029f67d..8d17be1 100644
>> --- a/hw/intc/apic_common.c
>> +++ b/hw/intc/apic_common.c
>> @@ -289,12 +289,13 @@ static int apic_load_old(QEMUFile *f, void *opaque,
>> int version_id)
>> return 0;
>> }
>>
>> +static int apic_no;
>> +
> some apic code still assumes that index in local_apics[] is APIC ID, so
> apic_no and related stuff won't work with arbitrary CPU hotadd (i.e.
> arbitrary APIC ID)
> to make it work the APICCommonState.idx should be dropped altogether and
> replaced with apic_id.
If so, we absolutely need to change this.
>
> I addition intc/apic.c is designed for APIC ID 8-bit max, we probably should
> add
> some assert there so it wouldn't break silently when APIC ID goes above this
> maximum.
OK.
>
>> static void apic_common_realize(DeviceState *dev, Error **errp)
>> {
>> APICCommonState *s = APIC_COMMON(dev);
>> APICCommonClass *info;
>> static DeviceState *vapic;
>> - static int apic_no;
>> static bool mmio_registered;
>>
>> if (apic_no >= MAX_APICS) {
>> @@ -324,6 +325,25 @@ 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);
>> +
>> + if (apic_no <= 0) {
>> + error_setg(errp, "%s exit failed.",
>> + object_get_typename(OBJECT(dev)));
>> + return;
>> + }
>> + apic_no--;
>> +
>> + info->unrealize(dev, errp);
>> +
>> + if (apic_report_tpr_access && info->enable_tpr_reporting) {
>> + info->enable_tpr_reporting(s, false);
>> + }
> what about unrealizing vapic?
IMO, we should not unrealize the vapic, because all apics share one vapic.
>
>
>> +}
>> +
>> static void apic_dispatch_pre_save(void *opaque)
>> {
>> APICCommonState *s = APIC_COMMON(opaque);
>> @@ -394,6 +414,7 @@ static void apic_common_class_init(ObjectClass *klass,
>> void *data)
>> dc->reset = apic_reset_common;
>> dc->props = apic_properties_common;
>> idc->realize = apic_common_realize;
>> + idc->unrealize = apic_common_unrealize;
>> /*
>> * Reason: APIC and CPU need to be wired up by
>> * x86_cpu_apic_create()
>> diff --git a/include/hw/cpu/icc_bus.h b/include/hw/cpu/icc_bus.h
>> index 98a979f..75ed309 100644
>> --- a/include/hw/cpu/icc_bus.h
>> +++ b/include/hw/cpu/icc_bus.h
>> @@ -67,6 +67,7 @@ typedef struct ICCDeviceClass {
>> /*< public >*/
>>
>> DeviceRealize realize;
>> + DeviceUnrealize unrealize;
>> } ICCDeviceClass;
>>
>> #define TYPE_ICC_DEVICE "icc-device"
>> diff --git a/include/hw/i386/apic_internal.h
>> b/include/hw/i386/apic_internal.h
>> index 2c91609..6c9e390 100644
>> --- a/include/hw/i386/apic_internal.h
>> +++ b/include/hw/i386/apic_internal.h
>> @@ -82,6 +82,7 @@ typedef struct APICCommonClass
>> ICCDeviceClass 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-qom.h b/target-i386/cpu-qom.h
>> index 71a1b97..2239105 100644
>> --- a/target-i386/cpu-qom.h
>> +++ b/target-i386/cpu-qom.h
>> @@ -65,6 +65,7 @@ typedef struct X86CPUClass {
>> bool kvm_required;
>>
>> DeviceRealize parent_realize;
>> + DeviceUnrealize parent_unrealize;
>> void (*parent_reset)(CPUState *cpu);
>> } X86CPUClass;
>>
>> diff --git a/target-i386/cpu.c b/target-i386/cpu.c
>> index 5255ddb..72a94a6 100644
>> --- a/target-i386/cpu.c
>> +++ b/target-i386/cpu.c
>> @@ -2712,10 +2712,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);
> this should be done by device_unrealize when APIC is being unrealized.
Yes, I will fix it.
>
>> + 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
>>
>> static void x86_cpu_realizefn(DeviceState *dev, Error **errp)
>> @@ -2778,6 +2800,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);
>> + }
> I don't recall which variant x86cpu uses but it probably should be
> one of above
> or even better, make device_set_realized()->vmstate_[un]register*() work
> wit x86cpu if possible.
I'll try this way, thanks.
Regards,
Gu
>
>> +
>> + 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;
>>
>> @@ -2957,7 +3000,9 @@ static void x86_cpu_common_class_init(ObjectClass *oc,
>> void *data)
>> DeviceClass *dc = DEVICE_CLASS(oc);
>>
>> xcc->parent_realize = dc->realize;
>> + xcc->parent_unrealize = dc->unrealize;
>> dc->realize = x86_cpu_realizefn;
>> + dc->unrealize = x86_cpu_unrealizefn;
>> dc->bus_type = TYPE_ICC_BUS;
>> dc->props = x86_cpu_properties;
>>
>
> .
>