[Qemu-devel] [PATCH] hw/timer/mc146818rtc: Fix introspection problem

Thomas Huth posted 1 patch 5 years, 9 months ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/1532010203-21331-1-git-send-email-thuth@redhat.com
Test checkpatch passed
Test docker-mingw@fedora passed
Test docker-quick@centos7 passed
hw/timer/mc146818rtc.c | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
[Qemu-devel] [PATCH] hw/timer/mc146818rtc: Fix introspection problem
Posted by Thomas Huth 5 years, 9 months ago
There is currently a funny problem with the "mc146818rtc" device:
1) Start QEMU like this:
   qemu-system-ppc64 -M pseries -S
2) At the HMP monitor, enter "info qom-tree". Note that there is an
   entry for "/rtc (spapr-rtc)".
3) Introspect the mc146818rtc device like this:
   device_add mc146818rtc,help
4) Run "info qom-tree" again. The "/rtc" entry is gone now!

The rtc_finalize() function of the mc146818rtc device has two bugs: First,
it tries to remove a "rtc" property, while the rtc_realizefn() added a
"rtc-time" property instead. And second, it should be done in an unrealize
function, not in a finalize function, to avoid that this causes problems
during introspection.

Fixes: 654a36d857ff949e0d1989904b76f53fded9dc83
Signed-off-by: Thomas Huth <thuth@redhat.com>
---
 hw/timer/mc146818rtc.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/hw/timer/mc146818rtc.c b/hw/timer/mc146818rtc.c
index 6f1f723..c0c6a72 100644
--- a/hw/timer/mc146818rtc.c
+++ b/hw/timer/mc146818rtc.c
@@ -1001,6 +1001,11 @@ static void rtc_realizefn(DeviceState *dev, Error **errp)
     qdev_init_gpio_out(dev, &s->irq, 1);
 }
 
+static void rtc_unrealize(DeviceState *dev, Error **errp)
+{
+    object_property_del(qdev_get_machine(), "rtc-time", errp);
+}
+
 ISADevice *mc146818_rtc_init(ISABus *bus, int base_year, qemu_irq intercept_irq)
 {
     DeviceState *dev;
@@ -1045,6 +1050,7 @@ static void rtc_class_initfn(ObjectClass *klass, void *data)
     DeviceClass *dc = DEVICE_CLASS(klass);
 
     dc->realize = rtc_realizefn;
+    dc->unrealize = rtc_unrealize;
     dc->reset = rtc_resetdev;
     dc->vmsd = &vmstate_rtc;
     dc->props = mc146818rtc_properties;
@@ -1052,17 +1058,11 @@ static void rtc_class_initfn(ObjectClass *klass, void *data)
     dc->user_creatable = false;
 }
 
-static void rtc_finalize(Object *obj)
-{
-    object_property_del(qdev_get_machine(), "rtc", NULL);
-}
-
 static const TypeInfo mc146818rtc_info = {
     .name          = TYPE_MC146818_RTC,
     .parent        = TYPE_ISA_DEVICE,
     .instance_size = sizeof(RTCState),
     .class_init    = rtc_class_initfn,
-    .instance_finalize = rtc_finalize,
 };
 
 static void mc146818rtc_register_types(void)
-- 
1.8.3.1


Re: [Qemu-devel] [PATCH] hw/timer/mc146818rtc: Fix introspection problem
Posted by Peter Maydell 5 years, 9 months ago
On 19 July 2018 at 15:23, Thomas Huth <thuth@redhat.com> wrote:
> There is currently a funny problem with the "mc146818rtc" device:
> 1) Start QEMU like this:
>    qemu-system-ppc64 -M pseries -S
> 2) At the HMP monitor, enter "info qom-tree". Note that there is an
>    entry for "/rtc (spapr-rtc)".
> 3) Introspect the mc146818rtc device like this:
>    device_add mc146818rtc,help
> 4) Run "info qom-tree" again. The "/rtc" entry is gone now!
>
> The rtc_finalize() function of the mc146818rtc device has two bugs: First,
> it tries to remove a "rtc" property, while the rtc_realizefn() added a
> "rtc-time" property instead. And second, it should be done in an unrealize
> function, not in a finalize function, to avoid that this causes problems
> during introspection.

A device that adds a property to a machine is pretty weird...

thanks
-- PMM

Re: [Qemu-devel] [PATCH] hw/timer/mc146818rtc: Fix introspection problem
Posted by Paolo Bonzini 5 years, 9 months ago
On 19/07/2018 16:46, Peter Maydell wrote:
> On 19 July 2018 at 15:23, Thomas Huth <thuth@redhat.com> wrote:
>> There is currently a funny problem with the "mc146818rtc" device:
>> 1) Start QEMU like this:
>>    qemu-system-ppc64 -M pseries -S
>> 2) At the HMP monitor, enter "info qom-tree". Note that there is an
>>    entry for "/rtc (spapr-rtc)".
>> 3) Introspect the mc146818rtc device like this:
>>    device_add mc146818rtc,help
>> 4) Run "info qom-tree" again. The "/rtc" entry is gone now!
>>
>> The rtc_finalize() function of the mc146818rtc device has two bugs: First,
>> it tries to remove a "rtc" property, while the rtc_realizefn() added a
>> "rtc-time" property instead. And second, it should be done in an unrealize
>> function, not in a finalize function, to avoid that this causes problems
>> during introspection.
> 
> A device that adds a property to a machine is pretty weird...

Well, "there can be only one" RTC, since it subtractively decodes I/O
ports 70h and 71h.  But it's true that nowadays the RTC should present
the property, and the machine should add an alias to the RTC's property.
 In my defence, at the time we didn't have alias properties.

Paolo