qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH 2/3] hw/intc: Add NULL pointer check on LoongArch ipi device


From: Song Gao
Subject: Re: [PATCH 2/3] hw/intc: Add NULL pointer check on LoongArch ipi device
Date: Wed, 26 Apr 2023 09:37:55 +0800
User-agent: Mozilla/5.0 (X11; Linux loongarch64; rv:68.0) Gecko/20100101 Thunderbird/68.7.0

ping ~

在 2023/4/6 下午6:00, Song Gao 写道:
When ipi mailbox is used, cpu index is decoded from iocsr register.
cpu maybe does not exist. This patch adss NULL pointer check on
ipi device.

Signed-off-by: Song Gao <gaosong@loongson.cn>
---
  hw/intc/loongarch_ipi.c | 31 +++++++++++++++++++------------
  1 file changed, 19 insertions(+), 12 deletions(-)

diff --git a/hw/intc/loongarch_ipi.c b/hw/intc/loongarch_ipi.c
index 0563d83a35..39e899df46 100644
--- a/hw/intc/loongarch_ipi.c
+++ b/hw/intc/loongarch_ipi.c
@@ -86,11 +86,12 @@ static void ipi_send(uint64_t val)
      /* IPI status vector */
      data = 1 << (val & 0x1f);
      cs = qemu_get_cpu(cpuid);
-    cpu = LOONGARCH_CPU(cs);
-    env = &cpu->env;
-    address_space_stl(&env->address_space_iocsr, 0x1008,
-                      data, MEMTXATTRS_UNSPECIFIED, NULL);
-
+    if (cs) {
+        cpu = LOONGARCH_CPU(cs);
+        env = &cpu->env;
+        address_space_stl(&env->address_space_iocsr, 0x1008,
+                          data, MEMTXATTRS_UNSPECIFIED, NULL);
+    }
  }
static void mail_send(uint64_t val)
@@ -104,9 +105,11 @@ static void mail_send(uint64_t val)
      cpuid = (val >> 16) & 0x3ff;
      addr = 0x1020 + (val & 0x1c);
      cs = qemu_get_cpu(cpuid);
-    cpu = LOONGARCH_CPU(cs);
-    env = &cpu->env;
-    send_ipi_data(env, val, addr);
+    if (cs) {
+        cpu = LOONGARCH_CPU(cs);
+        env = &cpu->env;
+        send_ipi_data(env, val, addr);
+    }
  }
static void any_send(uint64_t val)
@@ -114,13 +117,17 @@ static void any_send(uint64_t val)
      int cpuid;
      hwaddr addr;
      CPULoongArchState *env;
+    CPUState *cs;
+    LoongArchCPU *cpu;
cpuid = (val >> 16) & 0x3ff;
      addr = val & 0xffff;
-    CPUState *cs = qemu_get_cpu(cpuid);
-    LoongArchCPU *cpu = LOONGARCH_CPU(cs);
-    env = &cpu->env;
-    send_ipi_data(env, val, addr);
+    cs = qemu_get_cpu(cpuid);
+    if (cs) {
+        cpu = LOONGARCH_CPU(cs);
+        env = &cpu->env;
+        send_ipi_data(env, val, addr);
+    }
  }
static void loongarch_ipi_writel(void *opaque, hwaddr addr, uint64_t val,




reply via email to

[Prev in Thread] Current Thread [Next in Thread]