From: Gu Zheng <guz.fnst@cn.fujitsu.com>
To: Igor Mammedov <imammedo@redhat.com>
Cc: Eduardo <ehabkost@redhat.com>,
qemu-devel@nongnu.org, tangchen@cn.fujitsu.com,
isimatu.yasuaki@jp.fujitsu.com, chen.fan.fnst@cn.fujitsu.com,
anshul.makkar@profitbricks.com, afaerber@suse.de
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 [thread overview]
Message-ID: <541111D0.5030603@cn.fujitsu.com> (raw)
In-Reply-To: <20140909155854.0a002044@nial.usersys.redhat.com>
Hi Igor,
On 09/09/2014 09:58 PM, Igor Mammedov wrote:
> On Thu, 28 Aug 2014 11:36:36 +0800
> Gu Zheng <guz.fnst@cn.fujitsu.com> wrote:
>
>> From: Chen Fan <chen.fan.fnst@cn.fujitsu.com>
>>
>> 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 <chen.fan.fnst@cn.fujitsu.com>
>> Signed-off-by: Gu Zheng <guz.fnst@cn.fujitsu.com>
>> ---
>> 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;
>>
>
> .
>
next prev parent reply other threads:[~2014-09-11 3:20 UTC|newest]
Thread overview: 52+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-08-28 3:36 [Qemu-devel] [RFC V2 00/10] cpu: add device_add foo-x86_64-cpu and i386 cpu hot remove support Gu Zheng
2014-08-28 3:36 ` [Qemu-devel] [RFC V2 01/10] cpu: introduce CpuTopoInfo structure for argument simplification Gu Zheng
2014-08-28 3:36 ` [Qemu-devel] [RFC V2 02/10] qom/cpu: move register_vmstate to common CPUClass.realizefn Gu Zheng
2014-09-09 12:17 ` Igor Mammedov
2014-09-10 2:38 ` Gu Zheng
2014-08-28 3:36 ` [Qemu-devel] [RFC V2 03/10] cpu: add device_add foo-x86_64-cpu support Gu Zheng
2014-09-09 12:44 ` Igor Mammedov
2014-09-10 3:37 ` Gu Zheng
2014-08-28 3:36 ` [Qemu-devel] [RFC V2 04/10] x86: add x86_cpu_unrealizefn() for cpu apic remove Gu Zheng
2014-09-09 13:58 ` Igor Mammedov
2014-09-11 3:06 ` Gu Zheng [this message]
2014-08-28 3:36 ` [Qemu-devel] [RFC V2 05/10] i386: add cpu device_del support Gu Zheng
2014-09-09 14:11 ` Igor Mammedov
2014-08-28 3:36 ` [Qemu-devel] [RFC V2 06/10] qom cpu: rename variable 'cpu_added_notifier' to 'cpu_hotplug_notifier' Gu Zheng
2014-08-28 3:36 ` [Qemu-devel] [RFC V2 07/10] qom cpu: add UNPLUG cpu notify support Gu Zheng
2014-08-28 3:36 ` [Qemu-devel] [RFC V2 08/10] i386: implement pc interface cpu_common_unrealizefn() in qom/cpu.c Gu Zheng
2014-08-28 3:36 ` [Qemu-devel] [RFC V2 09/10] cpu hotplug: implement function cpu_status_write() for vcpu ejection Gu Zheng
2014-09-09 14:28 ` Igor Mammedov
2014-08-28 3:36 ` [Qemu-devel] [RFC V2 10/10] cpus: reclaim allocated vCPU objects Gu Zheng
2014-09-09 14:40 ` Igor Mammedov
2014-09-10 3:54 ` Gu Zheng
2014-09-11 9:35 ` Bharata B Rao
2014-09-11 9:49 ` Gu Zheng
2014-09-11 9:53 ` Gu Zheng
2014-09-11 12:37 ` Bharata B Rao
2014-09-12 1:24 ` Gu Zheng
2014-09-12 8:09 ` Bharata B Rao
2014-09-12 9:53 ` Gu Zheng
2014-09-12 10:30 ` Bharata B Rao
2014-09-12 10:53 ` Anshul Makkar
2014-09-12 13:52 ` Bharata B Rao
2014-09-12 15:34 ` Anshul Makkar
2014-09-15 6:39 ` Gu Zheng
2014-09-15 10:09 ` Bharata B Rao
2014-09-15 10:33 ` Anshul Makkar
2014-09-15 13:53 ` Bharata B Rao
2014-09-15 14:29 ` Anshul Makkar
2014-09-11 10:03 ` Anshul Makkar
2014-09-12 14:15 ` Igor Mammedov
2014-09-15 5:03 ` Gu Zheng
2014-12-08 9:16 ` Bharata B Rao
2014-12-08 9:26 ` Peter Maydell
2014-12-08 10:28 ` Gu Zheng
2014-12-08 10:50 ` Peter Maydell
2014-12-08 15:38 ` Igor Mammedov
2014-12-08 16:38 ` Peter Maydell
2014-12-09 0:58 ` Gu Zheng
2014-12-09 0:58 ` Gu Zheng
2014-12-08 10:12 ` Gu Zheng
2014-11-12 1:46 ` [Qemu-devel] [RFC V2 00/10] cpu: add device_add foo-x86_64-cpu and i386 cpu hot remove support Gu Zheng
2014-11-12 1:46 ` Gu Zheng
2014-11-12 7:57 ` Igor Mammedov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=541111D0.5030603@cn.fujitsu.com \
--to=guz.fnst@cn.fujitsu.com \
--cc=afaerber@suse.de \
--cc=anshul.makkar@profitbricks.com \
--cc=chen.fan.fnst@cn.fujitsu.com \
--cc=ehabkost@redhat.com \
--cc=imammedo@redhat.com \
--cc=isimatu.yasuaki@jp.fujitsu.com \
--cc=qemu-devel@nongnu.org \
--cc=tangchen@cn.fujitsu.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.