qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] hw/timer/mc146818rtc: Fix introspection problem
@ 2018-07-19 14:23 Thomas Huth
  2018-07-19 14:46 ` Peter Maydell
  0 siblings, 1 reply; 3+ messages in thread
From: Thomas Huth @ 2018-07-19 14:23 UTC (permalink / raw)
  To: qemu-devel, Paolo Bonzini; +Cc: Michael S. Tsirkin, qemu-ppc

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

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [Qemu-devel] [PATCH] hw/timer/mc146818rtc: Fix introspection problem
  2018-07-19 14:23 [Qemu-devel] [PATCH] hw/timer/mc146818rtc: Fix introspection problem Thomas Huth
@ 2018-07-19 14:46 ` Peter Maydell
  2018-07-19 16:28   ` Paolo Bonzini
  0 siblings, 1 reply; 3+ messages in thread
From: Peter Maydell @ 2018-07-19 14:46 UTC (permalink / raw)
  To: Thomas Huth; +Cc: QEMU Developers, Paolo Bonzini, qemu-ppc, Michael S. Tsirkin

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

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [Qemu-devel] [PATCH] hw/timer/mc146818rtc: Fix introspection problem
  2018-07-19 14:46 ` Peter Maydell
@ 2018-07-19 16:28   ` Paolo Bonzini
  0 siblings, 0 replies; 3+ messages in thread
From: Paolo Bonzini @ 2018-07-19 16:28 UTC (permalink / raw)
  To: Peter Maydell, Thomas Huth; +Cc: QEMU Developers, qemu-ppc, Michael S. Tsirkin

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

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2018-07-19 16:28 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-07-19 14:23 [Qemu-devel] [PATCH] hw/timer/mc146818rtc: Fix introspection problem Thomas Huth
2018-07-19 14:46 ` Peter Maydell
2018-07-19 16:28   ` Paolo Bonzini

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).