diff --git a/arch/loongarch/include/asm/smp.h b/arch/loongarch/include/asm/smp.h index cc232901e4dd2373f97eb38b3955936919526d2f..630e5ebec21cb3700dc1d22b003111ef69906daa 100644 --- a/arch/loongarch/include/asm/smp.h +++ b/arch/loongarch/include/asm/smp.h @@ -102,7 +102,4 @@ static inline void __cpu_die(unsigned int cpu) } #endif -int topo_add_cpu(int physid); -int topo_get_cpu(int physid); - #endif /* __ASM_SMP_H */ diff --git a/arch/loongarch/kernel/acpi.c b/arch/loongarch/kernel/acpi.c index 17dc28821a9ddb4cd8116c165100f74d4e025e35..58819b017ba83e545dfc7983430f5e39f41f2fb9 100644 --- a/arch/loongarch/kernel/acpi.c +++ b/arch/loongarch/kernel/acpi.c @@ -71,10 +71,10 @@ int set_processor_mask(u32 id, u32 flags) return -ENODEV; } - - cpu = topo_add_cpu(cpuid); - if (cpu < 0) - return -EEXIST; + if (cpuid == loongson_sysconf.boot_cpu_id) + cpu = 0; + else + cpu = cpumask_next_zero(-1, cpu_present_mask); if (flags & ACPI_MADT_ENABLED) { num_processors++; @@ -197,6 +197,8 @@ void __init acpi_boot_table_init(void) goto fdt_earlycon; } + loongson_sysconf.boot_cpu_id = read_csr_cpuid(); + /* * Process the Multiple APIC Description Table (MADT), if present */ @@ -246,7 +248,7 @@ void __init numa_set_distance(int from, int to, int distance) void __init acpi_numa_processor_affinity_init(struct acpi_srat_cpu_affinity *pa) { - int pxm, node, cpu; + int pxm, node; if (srat_disabled()) return; @@ -275,11 +277,6 @@ acpi_numa_processor_affinity_init(struct acpi_srat_cpu_affinity *pa) return; } - cpu = topo_get_cpu(pa->apic_id); - /* Check whether apic_id exists in MADT table */ - if (cpu < 0) - return; - early_numa_add_cpu(pa->apic_id, node); set_cpuid_to_node(pa->apic_id, node); @@ -318,17 +315,12 @@ int acpi_map_cpu(acpi_handle handle, phys_cpuid_t physid, u32 acpi_id, int *pcpu { int cpu; - cpu = topo_get_cpu(physid); - /* Check whether apic_id exists in MADT table */ + cpu = set_processor_mask(physid, ACPI_MADT_ENABLED); if (cpu < 0) { pr_info(PREFIX "Unable to map lapic to logical cpu number\n"); return cpu; } - num_processors++; - set_cpu_present(cpu, true); - __cpu_number_map[physid] = cpu; - __cpu_logical_map[cpu] = physid; acpi_map_cpu2node(handle, cpu, physid); *pcpu = cpu; diff --git a/arch/loongarch/kernel/setup.c b/arch/loongarch/kernel/setup.c index 352d362c901b574b0f45ae52cb3343b98a9fa941..f53889dd618290e31cfc1532adbeef195dad945f 100644 --- a/arch/loongarch/kernel/setup.c +++ b/arch/loongarch/kernel/setup.c @@ -72,8 +72,6 @@ EXPORT_SYMBOL(cpu_data); struct loongson_board_info b_info; static const char dmi_empty_string[] = " "; -static int possible_cpus; -static bool bsp_added; /* * Setup information @@ -378,50 +376,6 @@ static void __init bootcmdline_init(char **cmdline_p) *cmdline_p = boot_command_line; } -int topo_get_cpu(int physid) -{ - int i; - - for (i = 0; i < possible_cpus; i++) - if (cpu_logical_map(i) == physid) - break; - - if (i == possible_cpus) - return -ENOENT; - - return i; -} - -int topo_add_cpu(int physid) -{ - int cpu; - - if (!bsp_added && (physid == loongson_sysconf.boot_cpu_id)) { - bsp_added = true; - return 0; - } - - cpu = topo_get_cpu(physid); - if (cpu >= 0) { - pr_warn("Adding duplicated physical cpuid 0x%x\n", physid); - return -EEXIST; - } - - if (possible_cpus >= nr_cpu_ids) - return -ERANGE; - - __cpu_logical_map[possible_cpus] = physid; - cpu = possible_cpus++; - return cpu; -} - -static void __init topo_init(void) -{ - loongson_sysconf.boot_cpu_id = read_csr_cpuid(); - __cpu_logical_map[0] = loongson_sysconf.boot_cpu_id; - possible_cpus++; -} - static void __init writecombine_detect(void) { u64 cpuname; @@ -446,7 +400,6 @@ void __init platform_init(void) { arch_reserve_vmcore(); arch_parse_crashkernel(); - topo_init(); #ifdef CONFIG_ACPI_TABLE_UPGRADE acpi_table_upgrade(); diff --git a/arch/loongarch/kernel/smp.c b/arch/loongarch/kernel/smp.c index 5d02bf5126b7177c9f79a4d38bfe74f01e6a3bff..7f693a24687d1a364dc7eeae85dc02bad637a88a 100644 --- a/arch/loongarch/kernel/smp.c +++ b/arch/loongarch/kernel/smp.c @@ -291,9 +291,10 @@ static void __init fdt_smp_setup(void) if (cpuid >= nr_cpu_ids) continue; - cpu = topo_add_cpu(cpuid); - if (cpu < 0) - continue; + if (cpuid == loongson_sysconf.boot_cpu_id) + cpu = 0; + else + cpu = cpumask_next_zero(-1, cpu_present_mask); num_processors++; set_cpu_possible(cpu, true); @@ -301,7 +302,7 @@ static void __init fdt_smp_setup(void) __cpu_number_map[cpuid] = cpu; __cpu_logical_map[cpu] = cpuid; - early_numa_add_cpu(cpuid, 0); + early_numa_add_cpu(cpu, 0); set_cpuid_to_node(cpuid, 0); } diff --git a/arch/loongarch/kvm/intc/extioi.c b/arch/loongarch/kvm/intc/extioi.c index 6dd90145a5114ca02a9950fdcd170ed099f8f4c9..801ac861c876d1893208d39d313dc2bcaecad176 100644 --- a/arch/loongarch/kvm/intc/extioi.c +++ b/arch/loongarch/kvm/intc/extioi.c @@ -938,7 +938,7 @@ int kvm_loongarch_reset_extioi(struct kvm *kvm) { struct loongarch_extioi *extioi = kvm->arch.extioi; unsigned long flags; - u8 offset, size; + unsigned long offset, size; u8 *pstart; if (!extioi) diff --git a/arch/loongarch/kvm/intc/ipi.c b/arch/loongarch/kvm/intc/ipi.c index 2638f58bcf81ce12e5a2829fdf21d12145d4503c..4459ec42eb40e4eb528cd85257f1b969eb2380b5 100644 --- a/arch/loongarch/kvm/intc/ipi.c +++ b/arch/loongarch/kvm/intc/ipi.c @@ -540,7 +540,7 @@ int kvm_loongarch_register_ipi_device(void) int kvm_loongarch_reset_ipi(struct kvm_vcpu *vcpu) { struct ipi_state *s = &vcpu->arch.ipi_state; - u8 offset, size; + unsigned long offset, size; u8 *pstart; if (!s) diff --git a/arch/loongarch/kvm/intc/pch_pic.c b/arch/loongarch/kvm/intc/pch_pic.c index 6726f718e16ba1ee2332f19d0d1304773526d07d..9f287b41991015c2f98fd9971f02d9ba1b73ad23 100644 --- a/arch/loongarch/kvm/intc/pch_pic.c +++ b/arch/loongarch/kvm/intc/pch_pic.c @@ -542,7 +542,7 @@ int kvm_loongarch_register_pch_pic_device(void) int kvm_loongarch_reset_pch(struct kvm *kvm) { struct loongarch_pch_pic *s = kvm->arch.pch_pic; - u8 offset, size; + unsigned long offset, size; u8 *pstart; if (!s) diff --git a/arch/loongarch/kvm/main.c b/arch/loongarch/kvm/main.c index 5f0ddf239352154163d954d6d87d9e6ad53dfdf0..ef2bad612c00309a59937a1b59e63cb9d802ca81 100644 --- a/arch/loongarch/kvm/main.c +++ b/arch/loongarch/kvm/main.c @@ -314,6 +314,12 @@ int kvm_arch_hardware_enable(void) kvm_debug("GCFG:%lx GSTAT:%lx GINTC:%lx GTLBC:%lx", read_csr_gcfg(), read_csr_gstat(), read_csr_gintc(), read_csr_gtlbc()); + /* + * HW Guest CSR registers are lost after CPU suspend and resume. + * Clear last_vcpu so that Guest CSR registers forced to reload + * from vCPU SW state + */ + this_cpu_ptr(vmcs)->last_vcpu = NULL; return 0; } diff --git a/arch/loongarch/kvm/vcpu.c b/arch/loongarch/kvm/vcpu.c index 8d386a6c707b0d4b0670a07111691a7b9c157c70..532138bd049fa257540b8f4c9356ceaf0cf9098d 100644 --- a/arch/loongarch/kvm/vcpu.c +++ b/arch/loongarch/kvm/vcpu.c @@ -309,7 +309,7 @@ static int kvm_handle_exit(struct kvm_run *run, struct kvm_vcpu *vcpu) { int ret = RESUME_GUEST; unsigned long estat = vcpu->arch.host_estat; - u32 intr = estat & 0x1fff; /* Ignore NMI */ + u32 intr = estat & CSR_ESTAT_IS; u32 ecode = (estat & CSR_ESTAT_EXC) >> CSR_ESTAT_EXC_SHIFT; vcpu->mode = OUTSIDE_GUEST_MODE; @@ -874,7 +874,14 @@ static int kvm_set_one_reg(struct kvm_vcpu *vcpu, kvm_loongarch_reset_extioi(vcpu->kvm); kvm_loongarch_reset_pch(vcpu->kvm); } + kvm_loongarch_reset_ipi(vcpu); + /* + * When the vcpu resets, clear the ESTAT and GINTC registers, + * and clear other CSR registers through the _kvm_set_csr register. + */ + kvm_write_sw_gcsr(vcpu->arch.csr, LOONGARCH_CSR_GINTC, 0); + kvm_write_sw_gcsr(vcpu->arch.csr, LOONGARCH_CSR_ESTAT, 0); memset(&vcpu->arch.irq_pending, 0, sizeof(vcpu->arch.irq_pending)); memset(&vcpu->arch.irq_clear, 0, sizeof(vcpu->arch.irq_clear)); break;