qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/2] hw/intc/loongson_ipi: Fixes for qemu-stable
@ 2024-07-23 11:14 Philippe Mathieu-Daudé
  2024-07-23 11:14 ` [PATCH 1/2] hw/intc/loongson_ipi: Access memory in little endian Philippe Mathieu-Daudé
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Philippe Mathieu-Daudé @ 2024-07-23 11:14 UTC (permalink / raw)
  To: qemu-devel
  Cc: Huacai Chen, Song Gao, Jiaxun Yang,
	Philippe =?unknown-8bit?q?Mathieu-Daud=C3=A9?=

- 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(-)

-- 
2.41.0



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

* [PATCH 1/2] hw/intc/loongson_ipi: Access memory in little endian
  2024-07-23 11:14 [PATCH 0/2] hw/intc/loongson_ipi: Fixes for qemu-stable Philippe Mathieu-Daudé
@ 2024-07-23 11:14 ` Philippe Mathieu-Daudé
  2024-07-23 11:14 ` [PATCH 2/2] hw/intc/loongson_ipi: Fix resource leak Philippe Mathieu-Daudé
  2024-07-23 16:10 ` [PATCH 0/2] hw/intc/loongson_ipi: Fixes for qemu-stable Philippe Mathieu-Daudé
  2 siblings, 0 replies; 5+ messages in thread
From: Philippe Mathieu-Daudé @ 2024-07-23 11:14 UTC (permalink / raw)
  To: qemu-devel
  Cc: Huacai Chen, Song Gao, Jiaxun Yang, Bibo Mao, qemu-stable,
	Philippe Mathieu-Daudé, Richard Henderson

From: Bibo Mao <maobibo@loongson.cn>

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).

Cc: qemu-stable@nongnu.org
Signed-off-by: Bibo Mao <maobibo@loongson.cn>
Fixes: f6783e3438 ("hw/loongarch: Add LoongArch ipi interrupt support")
[PMD: Extracted from bigger commit, added commit description]
Co-Developed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Reviewed-by: Bibo Mao <maobibo@loongson.cn>
Tested-by: Bibo Mao <maobibo@loongson.cn>
Acked-by: Song Gao <gaosong@loongson.cn>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Reviewed-by: Jiaxun Yang <jiaxun.yang@flygoat.com>
Tested-by: Jiaxun Yang <jiaxun.yang@flygoat.com>
---
 hw/intc/loongson_ipi.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/hw/intc/loongson_ipi.c b/hw/intc/loongson_ipi.c
index e6a7142480c..e7979dbdd8b 100644
--- a/hw/intc/loongson_ipi.c
+++ b/hw/intc/loongson_ipi.c
@@ -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;
 }
-- 
2.41.0



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

* [PATCH 2/2] hw/intc/loongson_ipi: Fix resource leak
  2024-07-23 11:14 [PATCH 0/2] hw/intc/loongson_ipi: Fixes for qemu-stable Philippe Mathieu-Daudé
  2024-07-23 11:14 ` [PATCH 1/2] hw/intc/loongson_ipi: Access memory in little endian Philippe Mathieu-Daudé
@ 2024-07-23 11:14 ` Philippe Mathieu-Daudé
  2024-07-23 12:00   ` gaosong
  2024-07-23 16:10 ` [PATCH 0/2] hw/intc/loongson_ipi: Fixes for qemu-stable Philippe Mathieu-Daudé
  2 siblings, 1 reply; 5+ messages in thread
From: Philippe Mathieu-Daudé @ 2024-07-23 11:14 UTC (permalink / raw)
  To: qemu-devel
  Cc: Huacai Chen, Song Gao, Jiaxun Yang, Philippe Mathieu-Daudé,
	qemu-stable

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().

Cc: qemu-stable@nongnu.org
Fixes: 5e90b8db382 ("hw/loongarch: Set iocsr address space per-board rather than percpu")
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
 hw/intc/loongson_ipi.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/hw/intc/loongson_ipi.c b/hw/intc/loongson_ipi.c
index e7979dbdd8b..4013f81745e 100644
--- a/hw/intc/loongson_ipi.c
+++ b/hw/intc/loongson_ipi.c
@@ -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)
-- 
2.41.0



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

* Re: [PATCH 2/2] hw/intc/loongson_ipi: Fix resource leak
  2024-07-23 11:14 ` [PATCH 2/2] hw/intc/loongson_ipi: Fix resource leak Philippe Mathieu-Daudé
@ 2024-07-23 12:00   ` gaosong
  0 siblings, 0 replies; 5+ messages in thread
From: gaosong @ 2024-07-23 12:00 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé, qemu-devel
  Cc: Huacai Chen, Jiaxun Yang, qemu-stable

在 2024/7/23 下午7:14, 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().
>
> Cc: qemu-stable@nongnu.org
> Fixes: 5e90b8db382 ("hw/loongarch: Set iocsr address space per-board rather than percpu")
> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
> ---
Reviewed-by: Song Gao <gaosong@loongson.cn>

Thanks.
Song Gao
>   hw/intc/loongson_ipi.c | 16 ++++++++--------
>   1 file changed, 8 insertions(+), 8 deletions(-)
>
> diff --git a/hw/intc/loongson_ipi.c b/hw/intc/loongson_ipi.c
> index e7979dbdd8b..4013f81745e 100644
> --- a/hw/intc/loongson_ipi.c
> +++ b/hw/intc/loongson_ipi.c
> @@ -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)



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

* Re: [PATCH 0/2] hw/intc/loongson_ipi: Fixes for qemu-stable
  2024-07-23 11:14 [PATCH 0/2] hw/intc/loongson_ipi: Fixes for qemu-stable Philippe Mathieu-Daudé
  2024-07-23 11:14 ` [PATCH 1/2] hw/intc/loongson_ipi: Access memory in little endian Philippe Mathieu-Daudé
  2024-07-23 11:14 ` [PATCH 2/2] hw/intc/loongson_ipi: Fix resource leak Philippe Mathieu-Daudé
@ 2024-07-23 16:10 ` Philippe Mathieu-Daudé
  2 siblings, 0 replies; 5+ messages in thread
From: Philippe Mathieu-Daudé @ 2024-07-23 16:10 UTC (permalink / raw)
  To: qemu-devel; +Cc: Huacai Chen, Song Gao, Jiaxun Yang

On 23/7/24 13:14, Philippe Mathieu-Daudé wrote:
> - 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.



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

end of thread, other threads:[~2024-07-23 16:11 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-07-23 11:14 [PATCH 0/2] hw/intc/loongson_ipi: Fixes for qemu-stable Philippe Mathieu-Daudé
2024-07-23 11:14 ` [PATCH 1/2] hw/intc/loongson_ipi: Access memory in little endian Philippe Mathieu-Daudé
2024-07-23 11:14 ` [PATCH 2/2] hw/intc/loongson_ipi: Fix resource leak Philippe Mathieu-Daudé
2024-07-23 12:00   ` gaosong
2024-07-23 16:10 ` [PATCH 0/2] hw/intc/loongson_ipi: Fixes for qemu-stable Philippe Mathieu-Daudé

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).