Skip to contentSkip to conversation

hw/intc/loongson_ipi: Fixes for qemu-stable

PATCH In review Philippe Mathieu-Daudé 2 participants 5 messages Jul 23, 2024

lore
Share & tools
lore
#0 lore raw

cover hw/intc/loongson_ipi: Fixes for qemu-stable

- Fix endianness
- Fix resource leak

Bibo Mao (1):
hw/intc/loongson_ipi: Access memory in little endian

Philippe Mathieu-Daudé (1):
hw/intc/loongson_ipi: Fix resource leak

 hw/intc/loongson_ipi.c | 21 +++++++++++----------
 1 file changed, 11 insertions(+), 10 deletions(-)
Signature · 1 line
2.41.0
#1 lore raw

PATCH 1/2 hw/intc/loongson_ipi: Access memory in little endian

From: Bibo Mao <[email protected]>

Loongson IPI is only available in little-endian,
so use that to access the guest memory (in case
we run on a big-endian host).

Fixes f6783e3438 ("hw/loongarch: Add LoongArch ipi interrupt support")
[PMD: Extracted from bigger commit, added commit description]
---
 hw/intc/loongson_ipi.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
hw/intc/loongson_ipi.c +3 -2
index e6a7142480c..e7979dbdd8b 100644
@@ -14,6 +14,7 @@
 #include "qapi/error.h"
 #include "qemu/log.h"
 #include "exec/address-spaces.h"
+#include "exec/memory.h"
 #include "migration/vmstate.h"
 #ifdef TARGET_LOONGARCH64
 #include "target/loongarch/cpu.h"
@@ -102,7 +103,7 @@ static MemTxResult send_ipi_data(CPUState *cpu, uint64_t val, hwaddr addr,
      * if the mask is 0, we need not to do anything.
      */
     if ((val >> 27) & 0xf) {
-        data = address_space_ldl(iocsr_as, addr, attrs, NULL);
+        data = address_space_ldl_le(iocsr_as, addr, attrs, NULL);
         for (i = 0; i < 4; i++) {
             /* get mask for byte writing */
             if (val & (0x1 << (27 + i))) {
@@ -113,7 +114,7 @@ static MemTxResult send_ipi_data(CPUState *cpu, uint64_t val, hwaddr addr,
 
     data &= mask;
     data |= (val >> 32) & ~mask;
-    address_space_stl(iocsr_as, addr, data, attrs, NULL);
+    address_space_stl_le(iocsr_as, addr, data, attrs, NULL);
 
     return MEMTX_OK;
 }
Signature · 1 line
2.41.0
#2 lore raw

PATCH 2/2 hw/intc/loongson_ipi: Fix resource leak

In reply to Philippe Mathieu-Daudé

Once initialised, QOM objects can be realized and unrealized multiple times before being finalized. Resources allocated in REALIZE must be deallocated in an equivalent UNREALIZE handler.

Free the CPU array in loongson_ipi_unrealize()
instead of loongson_ipi_finalize().

Fixes 5e90b8db382 ("hw/loongarch: Set iocsr address space per-board rather than percpu")
---
 hw/intc/loongson_ipi.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)
hw/intc/loongson_ipi.c +8 -8
index e7979dbdd8b..4013f81745e 100644
@@ -318,6 +318,13 @@ static void loongson_ipi_realize(DeviceState *dev, Error **errp)
     }
 }
 
+static void loongson_ipi_unrealize(DeviceState *dev)
+{
+    LoongsonIPI *s = LOONGSON_IPI(dev);
+
+    g_free(s->cpu);
+}
+
 static const VMStateDescription vmstate_ipi_core = {
     .name = "ipi-single",
     .version_id = 2,
@@ -353,23 +360,16 @@ static void loongson_ipi_class_init(ObjectClass *klass, void *data)
     DeviceClass *dc = DEVICE_CLASS(klass);
 
     dc->realize = loongson_ipi_realize;
+    dc->unrealize = loongson_ipi_unrealize;
     device_class_set_props(dc, ipi_properties);
     dc->vmsd = &vmstate_loongson_ipi;
 }
 
-static void loongson_ipi_finalize(Object *obj)
-{
-    LoongsonIPI *s = LOONGSON_IPI(obj);
-
-    g_free(s->cpu);
-}
-
 static const TypeInfo loongson_ipi_info = {
     .name          = TYPE_LOONGSON_IPI,
     .parent        = TYPE_SYS_BUS_DEVICE,
     .instance_size = sizeof(LoongsonIPI),
     .class_init    = loongson_ipi_class_init,
-    .instance_finalize = loongson_ipi_finalize,
 };
 
 static void loongson_ipi_register_types(void)
Signature · 1 line
2.41.0
Reviewed-by on v1 2/2
#3 lore raw

Re: [PATCH 2/2] hw/intc/loongson_ipi: Fix resource leak

Quoted 5 lines · Philippe Mathieu-Daudé

Once initialised, QOM objects can be realized and unrealized multiple times before being finalized. Resources allocated in REALIZE must be deallocated in an equivalent UNREALIZE handler.

Quoted 7 lines

Free the CPU array in loongson_ipi_unrealize()
instead of loongson_ipi_finalize().

Fixes 5e90b8db382 ("hw/loongarch: Set iocsr address space per-board rather than percpu")

---

Thanks.
Song Gao

Quoted 46 lines
  hw/intc/loongson_ipi.c | 16 ++++++++--------
  1 file changed, 8 insertions(+), 8 deletions(-)
hw/intc/loongson_ipi.c +8 -8
index e7979dbdd8b..4013f81745e 100644
@@ -318,6 +318,13 @@ static void loongson_ipi_realize(DeviceState *dev, Error **errp)
      }
  }
 
+static void loongson_ipi_unrealize(DeviceState *dev)
+{
+    LoongsonIPI *s = LOONGSON_IPI(dev);
+
+    g_free(s->cpu);
+}
+
  static const VMStateDescription vmstate_ipi_core = {
      .name = "ipi-single",
      .version_id = 2,
@@ -353,23 +360,16 @@ static void loongson_ipi_class_init(ObjectClass *klass, void *data)
      DeviceClass *dc = DEVICE_CLASS(klass);
 
      dc->realize = loongson_ipi_realize;
+    dc->unrealize = loongson_ipi_unrealize;
      device_class_set_props(dc, ipi_properties);
      dc->vmsd = &vmstate_loongson_ipi;
  }
 
-static void loongson_ipi_finalize(Object *obj)
-{
-    LoongsonIPI *s = LOONGSON_IPI(obj);
-
-    g_free(s->cpu);
-}
-
  static const TypeInfo loongson_ipi_info = {
      .name          = TYPE_LOONGSON_IPI,
      .parent        = TYPE_SYS_BUS_DEVICE,
      .instance_size = sizeof(LoongsonIPI),
      .class_init    = loongson_ipi_class_init,
-    .instance_finalize = loongson_ipi_finalize,
  };
 
  static void loongson_ipi_register_types(void)
#4 lore raw
In reply to Philippe Mathieu-Daudé
Quoted 8 lines · Philippe Mathieu-Daudé

- Fix endianness
- Fix resource leak

Bibo Mao (1):
hw/intc/loongson_ipi: Access memory in little endian

Philippe Mathieu-Daudé (1):
hw/intc/loongson_ipi: Fix resource leak

Series queued, thanks.