Skip to contentSkip to conversation

watchdog: 6300esb: add exit function

PATCH In review Li Qiang 3 participants 8 messages Nov 29, 2016

lore
Share & tools
lore

Li Qiang

author
#0 lore raw

PATCH 1/1 watchdog: 6300esb: add exit function

From: Li Qiang <[email protected]>

When the Intel 6300ESB watchdog is hot unplug. The timer allocated in realize isn't freed thus leaking memory leak. This patch avoid this through adding the exit function.

---
 hw/watchdog/wdt_i6300esb.c | 9 +++++++++
 1 file changed, 9 insertions(+)
hw/watchdog/wdt_i6300esb.c +9 -0
index a83d951..49b3cd1 100644
@@ -428,6 +428,14 @@ static void i6300esb_realize(PCIDevice *dev, Error **errp)
     /* qemu_register_coalesced_mmio (addr, 0x10); ? */
 }
 
+static void i6300esb_exit(PCIDevice *dev)
+{
+    I6300State *d = WATCHDOG_I6300ESB_DEVICE(dev);
+
+    timer_del(d->timer);
+    timer_free(d->timer);
+}
+
 static WatchdogTimerModel model = {
     .wdt_name = "i6300esb",
     .wdt_description = "Intel 6300ESB",
@@ -441,6 +449,7 @@ static void i6300esb_class_init(ObjectClass *klass, void *data)
     k->config_read = i6300esb_config_read;
     k->config_write = i6300esb_config_write;
     k->realize = i6300esb_realize;
+    k->exit = i6300esb_exit;
     k->vendor_id = PCI_VENDOR_ID_INTEL;
     k->device_id = PCI_DEVICE_ID_INTEL_ESB_9;
     k->class_id = PCI_CLASS_SYSTEM_OTHER;
Signature · 1 line
1.8.3.1
#1 lore raw
Quoted 5 lines · Li Qiang

From: Li Qiang <[email protected]>

When the Intel 6300ESB watchdog is hot unplug. The timer allocated in realize isn't freed thus leaking memory leak. This patch avoid this through adding the exit function.

I will just note that the real hardware is not hot-pluggable. However we don't need to stick to the real hardware capabilities, so that's OK.

Quoted 25 lines
---
 hw/watchdog/wdt_i6300esb.c | 9 +++++++++
 1 file changed, 9 insertions(+)
hw/watchdog/wdt_i6300esb.c +8 -0
index a83d951..49b3cd1 100644
@@ -428,6 +428,14 @@ static void i6300esb_realize(PCIDevice *dev, Error **errp)
     /* qemu_register_coalesced_mmio (addr, 0x10); ? */
 }
 
+static void i6300esb_exit(PCIDevice *dev)
+{
+    I6300State *d = WATCHDOG_I6300ESB_DEVICE(dev);
+
+    timer_del(d->timer);
+    timer_free(d->timer);
+}
+
 static WatchdogTimerModel model = {
     .wdt_name = "i6300esb",
     .wdt_description = "Intel 6300ESB",

hw/watchdog/wdt_i6300esb.c static void i6300esb_class_init(ObjectClass *klass, void *data) · line 452

Quoted 4 lines
hw/watchdog/wdt_i6300esb.c +1 -0
@@ -441,6 +449,7 @@ static void i6300esb_class_init(ObjectClass *klass, void *data)
     k->config_read = i6300esb_config_read;
     k->config_write = i6300esb_config_write;
     k->realize = i6300esb_realize;
+    k->exit = i6300esb_exit;

The wdt_diag288.c file seems to use k->unrealize for this purpose. I don't know which is correct however.

Rich.

Quoted 5 lines
hw/watchdog/wdt_i6300esb.c +0 -0
     k->vendor_id = PCI_VENDOR_ID_INTEL;
     k->device_id = PCI_DEVICE_ID_INTEL_ESB_9;
     k->class_id = PCI_CLASS_SYSTEM_OTHER;
Signature · 1 line
1.8.3.1
Signature · 5 lines
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
Read my programming and virtualization blog: http://rwmj.wordpress.com
virt-p2v converts physical machines to virtual machines.  Boot with a
live CD or over the network (PXE) and turn machines into KVM guests.
http://libguestfs.org/virt-v2v
author
#2 lore raw

Hi

2016-11-29 16:39 GMT+08:00 Richard W.M. Jones <[email protected]>:

Quoted 11 lines · Li Qiang
Quoted 5 lines

From: Li Qiang <[email protected]>

When the Intel 6300ESB watchdog is hot unplug. The timer allocated in realize isn't freed thus leaking memory leak. This patch avoid this through adding the exit function.

I will just note that the real hardware is not hot-pluggable. However we don't need to stick to the real hardware capabilities, so that's OK.

If the hardware is not hot-pluggable, we can set dc->hotpluggable = false.

Quoted 27 lines

hw/watchdog/wdt_i6300esb.c static void i6300esb_realize(PCIDevice *dev, Error

Quoted 9 lines
---
 hw/watchdog/wdt_i6300esb.c | 9 +++++++++
 1 file changed, 9 insertions(+)
hw/watchdog/wdt_i6300esb.c +0 -0
index a83d951..49b3cd1 100644
@@ -428,6 +428,14 @@ static void i6300esb_realize(PCIDevice *dev, Error

**errp)

hw/watchdog/wdt_i6300esb.c static void i6300esb_class_init(ObjectClass *klass,

Quoted 15 lines
hw/watchdog/wdt_i6300esb.c +8 -0
     /* qemu_register_coalesced_mmio (addr, 0x10); ? */
 }
 
+static void i6300esb_exit(PCIDevice *dev)
+{
+    I6300State *d = WATCHDOG_I6300ESB_DEVICE(dev);
+
+    timer_del(d->timer);
+    timer_free(d->timer);
+}
+
 static WatchdogTimerModel model = {
     .wdt_name = "i6300esb",
     .wdt_description = "Intel 6300ESB",
@@ -441,6 +449,7 @@ static void i6300esb_class_init(ObjectClass *klass,

void *data)

Quoted 10 lines

hw/watchdog/wdt_i6300esb.c static void i6300esb_class_init(ObjectClass *klass, void *data) · line 452

Quoted 4 lines
hw/watchdog/wdt_i6300esb.c +1 -0
     k->config_read = i6300esb_config_read;
     k->config_write = i6300esb_config_write;
     k->realize = i6300esb_realize;
+    k->exit = i6300esb_exit;

The wdt_diag288.c file seems to use k->unrealize for this purpose. I don't know which is correct however.

wdt_diag288.c uses dc->unrealize for DeviceClass, while k->exit if for PCIDeviceClass.
I have tested this patch, it's ok.

So we should make it not hotpluggable or just remain this?

Thanks

Li Qiang

Quoted 15 lines
Quoted 6 lines
hw/watchdog/wdt_i6300esb.c +0 -1
     k->vendor_id = PCI_VENDOR_ID_INTEL;
     k->device_id = PCI_DEVICE_ID_INTEL_ESB_9;
     k->class_id = PCI_CLASS_SYSTEM_OTHER;
--

1.8.3.1

--
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~
rjones
Read my programming and virtualization blog: http://rwmj.wordpress.com
virt-p2v converts physical machines to virtual machines. Boot with a live CD or over the network (PXE) and turn machines into KVM guests.
http://libguestfs.org/virt-v2v

#3 lore raw
Quoted 11 lines · Li Qiang

Hi

2016-11-29 16:39 GMT+08:00 Richard W.M. Jones <[email protected]>:

Quoted 7 lines · Li Qiang
Quoted 5 lines

From: Li Qiang <[email protected]>

When the Intel 6300ESB watchdog is hot unplug. The timer allocated in realize isn't freed thus leaking memory leak. This patch avoid this through adding the exit function.

Quoted 6 lines
Quoted 4 lines

I will just note that the real hardware is not hot-pluggable. However we don't need to stick to the real hardware capabilities, so that's OK.

If the hardware is not hot-pluggable, we can set dc->hotpluggable = false.

No no no! The hardware hasn't been made for a decade or two, we don't need to stick with what the real hardware did.

Rich.

Signature · 4 lines
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
Read my programming and virtualization blog: http://rwmj.wordpress.com
libguestfs lets you edit virtual machines.  Supports shell scripting,
bindings from many languages.  http://libguestfs.org
author
#4 lore raw

2016-11-29 17:00 GMT+08:00 Richard W.M. Jones <[email protected]>:

Quoted 17 lines · Li Qiang
Quoted 16 lines

Hi

2016-11-29 16:39 GMT+08:00 Richard W.M. Jones <[email protected]>:

Quoted 11 lines · Li Qiang
Quoted 5 lines

From: Li Qiang <[email protected]>

When the Intel 6300ESB watchdog is hot unplug. The timer allocated in realize isn't freed thus leaking memory leak. This patch avoid this through adding the exit function.

I will just note that the real hardware is not hot-pluggable. However we don't need to stick to the real hardware capabilities, so that's OK.

Quoted 7 lines
Quoted 1 line

If the hardware is not hot-pluggable, we can set dc->hotpluggable =

false.

No no no! The hardware hasn't been made for a decade or two, we don't need to stick with what the real hardware did.

OK, then I think this patch is OK.

Quoted 9 lines

Rich.

--
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~
rjones
Read my programming and virtualization blog: http://rwmj.wordpress.com
libguestfs lets you edit virtual machines. Supports shell scripting, bindings from many languages. http://libguestfs.org

#5 lore raw
In reply to Li Qiang
Quoted 51 lines · Li Qiang

Hi

2016-11-29 16:39 GMT+08:00 Richard W.M. Jones <[email protected]>:

Quoted 11 lines · Li Qiang
Quoted 5 lines

From: Li Qiang <[email protected]>

When the Intel 6300ESB watchdog is hot unplug. The timer allocated in realize isn't freed thus leaking memory leak. This patch avoid this through adding the exit function.

I will just note that the real hardware is not hot-pluggable. However we don't need to stick to the real hardware capabilities, so that's OK.

If the hardware is not hot-pluggable, we can set dc->hotpluggable = false.

Quoted 32 lines

hw/watchdog/wdt_i6300esb.c static void i6300esb_realize(PCIDevice *dev, Error

Quoted 9 lines
---
 hw/watchdog/wdt_i6300esb.c | 9 +++++++++
 1 file changed, 9 insertions(+)
hw/watchdog/wdt_i6300esb.c +0 -0
index a83d951..49b3cd1 100644
@@ -428,6 +428,14 @@ static void i6300esb_realize(PCIDevice *dev, Error

**errp)

hw/watchdog/wdt_i6300esb.c static void i6300esb_class_init(ObjectClass *klass,

Quoted 15 lines
hw/watchdog/wdt_i6300esb.c +8 -0
     /* qemu_register_coalesced_mmio (addr, 0x10); ? */
 }
 
+static void i6300esb_exit(PCIDevice *dev)
+{
+    I6300State *d = WATCHDOG_I6300ESB_DEVICE(dev);
+
+    timer_del(d->timer);
+    timer_free(d->timer);
+}
+
 static WatchdogTimerModel model = {
     .wdt_name = "i6300esb",
     .wdt_description = "Intel 6300ESB",
@@ -441,6 +449,7 @@ static void i6300esb_class_init(ObjectClass *klass,

void *data)

Quoted 4 lines
hw/watchdog/wdt_i6300esb.c +1 -0
     k->config_read = i6300esb_config_read;
     k->config_write = i6300esb_config_write;
     k->realize = i6300esb_realize;
+    k->exit = i6300esb_exit;
Quoted 7 lines
Quoted 5 lines

The wdt_diag288.c file seems to use k->unrealize for this purpose. I don't know which is correct however.

wdt_diag288.c uses dc->unrealize for DeviceClass, while k->exit if for PCIDeviceClass.

Method exit() is deprecated, please use unrealize() in new code.

[...]

author
#6 lore raw

2016-11-29 18:49 GMT+08:00 Markus Armbruster <[email protected]>:

Quoted 61 lines
Quoted 11 lines · Li Qiang

Hi

2016-11-29 16:39 GMT+08:00 Richard W.M. Jones <[email protected]>:

Quoted 7 lines · Li Qiang
Quoted 5 lines

From: Li Qiang <[email protected]>

When the Intel 6300ESB watchdog is hot unplug. The timer allocated in realize isn't freed thus leaking memory leak. This patch avoid this through adding the exit function.

Quoted 6 lines
Quoted 4 lines

I will just note that the real hardware is not hot-pluggable. However we don't need to stick to the real hardware capabilities, so that's OK.

If the hardware is not hot-pluggable, we can set dc->hotpluggable =

false.

Quoted 7 lines
Quoted 7 lines
Quoted 4 lines
---
 hw/watchdog/wdt_i6300esb.c | 9 +++++++++
 1 file changed, 9 insertions(+)
Quoted 5 lines
Quoted 5 lines

hw/watchdog/wdt_i6300esb.c static void i6300esb_realize(PCIDevice *dev,

Quoted 5 lines
hw/watchdog/wdt_i6300esb.c +0 -0
index a83d951..49b3cd1 100644
@@ -428,6 +428,14 @@ static void i6300esb_realize(PCIDevice *dev,

Error

Quoted 4 lines
Quoted 4 lines

**errp)

Quoted 3 lines
hw/watchdog/wdt_i6300esb.c +0 -0
     /* qemu_register_coalesced_mmio (addr, 0x10); ? */
 }
 
Quoted 12 lines
Quoted 4 lines
Quoted 4 lines
hw/watchdog/wdt_i6300esb.c +4 -0
+static void i6300esb_exit(PCIDevice *dev)
+{
+    I6300State *d = WATCHDOG_I6300ESB_DEVICE(dev);
+
Quoted 8 lines

hw/watchdog/wdt_i6300esb.c static void i6300esb_class_init(ObjectClass

Quoted 8 lines
hw/watchdog/wdt_i6300esb.c +4 -0
+    timer_del(d->timer);
+    timer_free(d->timer);
+}
+
 static WatchdogTimerModel model = {
     .wdt_name = "i6300esb",
     .wdt_description = "Intel 6300ESB",
@@ -441,6 +449,7 @@ static void i6300esb_class_init(ObjectClass

*klass,

Quoted 11 lines
Quoted 11 lines

void *data)

hw/watchdog/wdt_i6300esb.c static void i6300esb_class_init(ObjectClass *klass, void *data) · line 452

Quoted 4 lines
hw/watchdog/wdt_i6300esb.c +1 -0
     k->config_read = i6300esb_config_read;
     k->config_write = i6300esb_config_write;
     k->realize = i6300esb_realize;
+    k->exit = i6300esb_exit;

The wdt_diag288.c file seems to use k->unrealize for this purpose. I don't know which is correct however.

Quoted 7 lines
Quoted 2 lines

wdt_diag288.c uses dc->unrealize for DeviceClass, while k->exit if for PCIDeviceClass.

Method exit() is deprecated, please use unrealize() in new code.

[...]

Hello,

IIUC in the PCIDeviceClass definition, there is just an exit member not a unrealize.
The DeviceClass has an unrealize member.

Thanks.

#7 lore raw
Quoted 1 line · Li Qiang

2016-11-29 18:49 GMT+08:00 Markus Armbruster <[email protected]>:

[...]

Quoted 10 lines
Quoted 4 lines

Method exit() is deprecated, please use unrealize() in new code.

[...]

Hello,

IIUC in the PCIDeviceClass definition, there is just an exit member not a unrealize.
The DeviceClass has an unrealize member.

You're right.

A less confusing PCIDeviceClass would be nice.