Message ID | 20231003082728.83496-6-philmd@linaro.org |
---|---|
State | New |
Headers | show |
Series | hw/intc/apic: QOM cleanup | expand |
On 10/3/23 10:27, Philippe Mathieu-Daudé wrote: > - /* TODO: convert to link<> */ > - apic = APIC_COMMON(cpu->apic_state); > - apic->cpu = cpu; > - apic->apicbase = APIC_DEFAULT_ADDRESS | MSR_IA32_APICBASE_ENABLE; > + qdev_prop_set_uint32(cpu->apic_state, "base-addr", > + APIC_DEFAULT_ADDRESS | MSR_IA32_APIC For this to use a link, it's missing the corresponding object_unref(apic->cpu) + apic->cpu = NULL assignment somewhere. For example you can add it in apic_common_unrealize (called by device_unparent - which is called in turn by x86_cpu_unrealizefn). Paolo
Hi Paolo, On 6/10/23 01:04, Paolo Bonzini wrote: > On 10/3/23 10:27, Philippe Mathieu-Daudé wrote: >> - /* TODO: convert to link<> */ >> - apic = APIC_COMMON(cpu->apic_state); >> - apic->cpu = cpu; >> - apic->apicbase = APIC_DEFAULT_ADDRESS | MSR_IA32_APICBASE_ENABLE; >> + qdev_prop_set_uint32(cpu->apic_state, "base-addr", >> + APIC_DEFAULT_ADDRESS | MSR_IA32_APIC > > For this to use a link, it's missing the corresponding > object_unref(apic->cpu) + apic->cpu = NULL assignment somewhere. For > example you can add it in apic_common_unrealize (called by > device_unparent - which is called in turn by x86_cpu_unrealizefn). I am a bit confused. DEFINE_PROP_LINK() sets OBJ_PROP_LINK_STRONG: * If the link property was created with * %OBJ_PROP_LINK_STRONG bit, the old target object is * unreferenced, and a reference is added to the new target object. Is this what you are pointing at? If so, I agree this should be unref in apic_common_unrealize().
diff --git a/hw/intc/apic_common.c b/hw/intc/apic_common.c index 8a79eacdb0..be7cf3b332 100644 --- a/hw/intc/apic_common.c +++ b/hw/intc/apic_common.c @@ -398,6 +398,8 @@ static Property apic_properties_common[] = { true), DEFINE_PROP_BOOL("legacy-instance-id", APICCommonState, legacy_instance_id, false), + DEFINE_PROP_LINK("cpu", APICCommonState, cpu, TYPE_X86_CPU, X86CPU *), + DEFINE_PROP_UINT32("base-addr", APICCommonState, apicbase, 0), DEFINE_PROP_END_OF_LIST(), }; diff --git a/target/i386/cpu-sysemu.c b/target/i386/cpu-sysemu.c index 373dc6b1c7..b084706531 100644 --- a/target/i386/cpu-sysemu.c +++ b/target/i386/cpu-sysemu.c @@ -265,7 +265,6 @@ APICCommonClass *apic_get_class(void) void x86_cpu_apic_new(X86CPU *cpu) { - APICCommonState *apic; APICCommonClass *apic_class = apic_get_class(); cpu->apic_state = DEVICE(object_new_with_class(OBJECT_CLASS(apic_class))); @@ -273,11 +272,11 @@ void x86_cpu_apic_new(X86CPU *cpu) OBJECT(cpu->apic_state)); object_unref(OBJECT(cpu->apic_state)); + object_property_set_link(OBJECT(cpu->apic_state), "cpu", + OBJECT(cpu), &error_abort); qdev_prop_set_uint32(cpu->apic_state, "id", cpu->apic_id); - /* TODO: convert to link<> */ - apic = APIC_COMMON(cpu->apic_state); - apic->cpu = cpu; - apic->apicbase = APIC_DEFAULT_ADDRESS | MSR_IA32_APICBASE_ENABLE; + qdev_prop_set_uint32(cpu->apic_state, "base-addr", + APIC_DEFAULT_ADDRESS | MSR_IA32_APICBASE_ENABLE); } void x86_cpu_apic_realize(X86CPU *cpu, Error **errp)