diff mbox series

[v2] hw/intc/loongarch_ipi: Add safer check about cpu

Message ID 20241028125747.2094026-1-maobibo@loongson.cn (mailing list archive)
State New
Headers show
Series [v2] hw/intc/loongarch_ipi: Add safer check about cpu | expand

Commit Message

Bibo Mao Oct. 28, 2024, 12:57 p.m. UTC
If cpu hotplug is enabled, all possible_cpus is initialized with
arch_id set. For ipi interrupt controller, cpu is searched from
possible_cpus with specified arch_id. However it is possible that
cpu object is not created for offlined cpu.

Here safer check is added. If cpu object is not created, archid->cpu
will be NULL.

Signed-off-by: Bibo Mao <maobibo@loongson.cn>
---
v1 ... v2:
  1. since physical cpuid is the same with cpu_index when cpu_index
     is set again as index of possible_cpus. Remove phy_id set about
     CSR_CPUID in function loongarch_cpu_reset_hold()
---
 hw/intc/loongarch_ipi.c           | 3 ++-
 target/loongarch/tcg/csr_helper.c | 4 ----
 2 files changed, 2 insertions(+), 5 deletions(-)


base-commit: cea8ac78545a83e1f01c94d89d6f5a3f6b5c05d2

Comments

gaosong Nov. 7, 2024, 12:30 p.m. UTC | #1
在 2024/10/28 下午8:57, Bibo Mao 写道:
> If cpu hotplug is enabled, all possible_cpus is initialized with
> arch_id set. For ipi interrupt controller, cpu is searched from
> possible_cpus with specified arch_id. However it is possible that
> cpu object is not created for offlined cpu.
>
> Here safer check is added. If cpu object is not created, archid->cpu
> will be NULL.
>
> Signed-off-by: Bibo Mao <maobibo@loongson.cn>
> ---
> v1 ... v2:
>    1. since physical cpuid is the same with cpu_index when cpu_index
>       is set again as index of possible_cpus. Remove phy_id set about
>       CSR_CPUID in function loongarch_cpu_reset_hold()
> ---
>   hw/intc/loongarch_ipi.c           | 3 ++-
>   target/loongarch/tcg/csr_helper.c | 4 ----
>   2 files changed, 2 insertions(+), 5 deletions(-)
Acked-by: Song Gao <gaosong@loongson.cn>

Thanks.
Song Gao
> diff --git a/hw/intc/loongarch_ipi.c b/hw/intc/loongarch_ipi.c
> index 2ae1a42c46..78b6fce81b 100644
> --- a/hw/intc/loongarch_ipi.c
> +++ b/hw/intc/loongarch_ipi.c
> @@ -42,7 +42,8 @@ static CPUState *loongarch_cpu_by_arch_id(int64_t arch_id)
>       CPUArchId *archid;
>   
>       archid = find_cpu_by_archid(machine, arch_id);
> -    if (archid) {
> +    /* For offlined cpus, archid->cpu may be NULL */
> +    if (archid && archid->cpu) {
>           return CPU(archid->cpu);
>       }
>   
> diff --git a/target/loongarch/tcg/csr_helper.c b/target/loongarch/tcg/csr_helper.c
> index 15f94caefa..2aeca2343d 100644
> --- a/target/loongarch/tcg/csr_helper.c
> +++ b/target/loongarch/tcg/csr_helper.c
> @@ -37,10 +37,6 @@ target_ulong helper_csrrd_pgd(CPULoongArchState *env)
>   
>   target_ulong helper_csrrd_cpuid(CPULoongArchState *env)
>   {
> -    LoongArchCPU *lac = env_archcpu(env);
> -
> -    env->CSR_CPUID = CPU(lac)->cpu_index;
> -
>       return env->CSR_CPUID;
>   }
>   
>
> base-commit: cea8ac78545a83e1f01c94d89d6f5a3f6b5c05d2
diff mbox series

Patch

diff --git a/hw/intc/loongarch_ipi.c b/hw/intc/loongarch_ipi.c
index 2ae1a42c46..78b6fce81b 100644
--- a/hw/intc/loongarch_ipi.c
+++ b/hw/intc/loongarch_ipi.c
@@ -42,7 +42,8 @@  static CPUState *loongarch_cpu_by_arch_id(int64_t arch_id)
     CPUArchId *archid;
 
     archid = find_cpu_by_archid(machine, arch_id);
-    if (archid) {
+    /* For offlined cpus, archid->cpu may be NULL */
+    if (archid && archid->cpu) {
         return CPU(archid->cpu);
     }
 
diff --git a/target/loongarch/tcg/csr_helper.c b/target/loongarch/tcg/csr_helper.c
index 15f94caefa..2aeca2343d 100644
--- a/target/loongarch/tcg/csr_helper.c
+++ b/target/loongarch/tcg/csr_helper.c
@@ -37,10 +37,6 @@  target_ulong helper_csrrd_pgd(CPULoongArchState *env)
 
 target_ulong helper_csrrd_cpuid(CPULoongArchState *env)
 {
-    LoongArchCPU *lac = env_archcpu(env);
-
-    env->CSR_CPUID = CPU(lac)->cpu_index;
-
     return env->CSR_CPUID;
 }