Skip to content

Commit 869c706

Browse files
sean-jcpalmer-dabbelt
authored andcommitted
RISC-V: Use common riscv_cpuid_to_hartid_mask() for both SMP=y and SMP=n
Use what is currently the SMP=y version of riscv_cpuid_to_hartid_mask() for both SMP=y and SMP=n to fix a build failure with KVM=m and SMP=n due to boot_cpu_hartid not being exported. This also fixes a second bug where the SMP=n version assumes the sole CPU in the system is in the incoming mask, which may not hold true in kvm_riscv_vcpu_sbi_ecall() if the KVM guest VM has multiple vCPUs (on a SMP=n system). Fixes: 1ef46c2 ("RISC-V: Implement new SBI v0.2 extensions") Reported-by: Adam Borowski <kilobyte@angband.pl> Reviewed-by: Anup Patel <anup.patel@wdc.com> Signed-off-by: Sean Christopherson <seanjc@google.com> Cc: stable@vger.kernel.org Signed-off-by: Palmer Dabbelt <palmer@rivosinc.com>
1 parent 51f23e5 commit 869c706

File tree

3 files changed

+12
-18
lines changed

3 files changed

+12
-18
lines changed

arch/riscv/include/asm/smp.h

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ void arch_send_call_function_ipi_mask(struct cpumask *mask);
4343
void arch_send_call_function_single_ipi(int cpu);
4444

4545
int riscv_hartid_to_cpuid(int hartid);
46-
void riscv_cpuid_to_hartid_mask(const struct cpumask *in, struct cpumask *out);
4746

4847
/* Set custom IPI operations */
4948
void riscv_set_ipi_ops(const struct riscv_ipi_ops *ops);
@@ -83,13 +82,6 @@ static inline unsigned long cpuid_to_hartid_map(int cpu)
8382
return boot_cpu_hartid;
8483
}
8584

86-
static inline void riscv_cpuid_to_hartid_mask(const struct cpumask *in,
87-
struct cpumask *out)
88-
{
89-
cpumask_clear(out);
90-
cpumask_set_cpu(boot_cpu_hartid, out);
91-
}
92-
9385
static inline void riscv_set_ipi_ops(const struct riscv_ipi_ops *ops)
9486
{
9587
}
@@ -100,6 +92,8 @@ static inline void riscv_clear_ipi(void)
10092

10193
#endif /* CONFIG_SMP */
10294

95+
void riscv_cpuid_to_hartid_mask(const struct cpumask *in, struct cpumask *out);
96+
10397
#if defined(CONFIG_HOTPLUG_CPU) && (CONFIG_SMP)
10498
bool cpu_has_hotplug(unsigned int cpu);
10599
#else

arch/riscv/kernel/setup.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,16 @@ atomic_t hart_lottery __section(".sdata")
5959
unsigned long boot_cpu_hartid;
6060
static DEFINE_PER_CPU(struct cpu, cpu_devices);
6161

62+
void riscv_cpuid_to_hartid_mask(const struct cpumask *in, struct cpumask *out)
63+
{
64+
int cpu;
65+
66+
cpumask_clear(out);
67+
for_each_cpu(cpu, in)
68+
cpumask_set_cpu(cpuid_to_hartid_map(cpu), out);
69+
}
70+
EXPORT_SYMBOL_GPL(riscv_cpuid_to_hartid_mask);
71+
6272
/*
6373
* Place kernel memory regions on the resource tree so that
6474
* kexec-tools can retrieve them from /proc/iomem. While there

arch/riscv/kernel/smp.c

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -59,16 +59,6 @@ int riscv_hartid_to_cpuid(int hartid)
5959
return -ENOENT;
6060
}
6161

62-
void riscv_cpuid_to_hartid_mask(const struct cpumask *in, struct cpumask *out)
63-
{
64-
int cpu;
65-
66-
cpumask_clear(out);
67-
for_each_cpu(cpu, in)
68-
cpumask_set_cpu(cpuid_to_hartid_map(cpu), out);
69-
}
70-
EXPORT_SYMBOL_GPL(riscv_cpuid_to_hartid_mask);
71-
7262
bool arch_match_cpu_phys_id(int cpu, u64 phys_id)
7363
{
7464
return phys_id == cpuid_to_hartid_map(cpu);

0 commit comments

Comments
 (0)