Commit 26fb751c authored by Atish Patra's avatar Atish Patra Committed by Palmer Dabbelt

RISC-V: Do not use cpumask data structure for hartid bitmap

Currently, SBI APIs accept a hartmask that is generated from struct
cpumask. Cpumask data structure can hold upto NR_CPUs value. Thus, it
is not the correct data structure for hartids as it can be higher
than NR_CPUs for platforms with sparse or discontguous hartids.

Remove all association between hartid mask and struct cpumask.

Reviewed-by: Anup Patel <anup@brainfault.org> (For Linux RISC-V changes)
Acked-by: Anup Patel <anup@brainfault.org> (For KVM RISC-V changes)
Signed-off-by: default avatarAtish Patra <atishp@rivosinc.com>
Signed-off-by: default avatarPalmer Dabbelt <palmer@rivosinc.com>
parent 2ffc48fc
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#define _ASM_RISCV_SBI_H #define _ASM_RISCV_SBI_H
#include <linux/types.h> #include <linux/types.h>
#include <linux/cpumask.h>
#ifdef CONFIG_RISCV_SBI #ifdef CONFIG_RISCV_SBI
enum sbi_ext_id { enum sbi_ext_id {
...@@ -128,27 +129,27 @@ long sbi_get_mimpid(void); ...@@ -128,27 +129,27 @@ long sbi_get_mimpid(void);
void sbi_set_timer(uint64_t stime_value); void sbi_set_timer(uint64_t stime_value);
void sbi_shutdown(void); void sbi_shutdown(void);
void sbi_clear_ipi(void); void sbi_clear_ipi(void);
int sbi_send_ipi(const unsigned long *hart_mask); int sbi_send_ipi(const struct cpumask *cpu_mask);
int sbi_remote_fence_i(const unsigned long *hart_mask); int sbi_remote_fence_i(const struct cpumask *cpu_mask);
int sbi_remote_sfence_vma(const unsigned long *hart_mask, int sbi_remote_sfence_vma(const struct cpumask *cpu_mask,
unsigned long start, unsigned long start,
unsigned long size); unsigned long size);
int sbi_remote_sfence_vma_asid(const unsigned long *hart_mask, int sbi_remote_sfence_vma_asid(const struct cpumask *cpu_mask,
unsigned long start, unsigned long start,
unsigned long size, unsigned long size,
unsigned long asid); unsigned long asid);
int sbi_remote_hfence_gvma(const unsigned long *hart_mask, int sbi_remote_hfence_gvma(const struct cpumask *cpu_mask,
unsigned long start, unsigned long start,
unsigned long size); unsigned long size);
int sbi_remote_hfence_gvma_vmid(const unsigned long *hart_mask, int sbi_remote_hfence_gvma_vmid(const struct cpumask *cpu_mask,
unsigned long start, unsigned long start,
unsigned long size, unsigned long size,
unsigned long vmid); unsigned long vmid);
int sbi_remote_hfence_vvma(const unsigned long *hart_mask, int sbi_remote_hfence_vvma(const struct cpumask *cpu_mask,
unsigned long start, unsigned long start,
unsigned long size); unsigned long size);
int sbi_remote_hfence_vvma_asid(const unsigned long *hart_mask, int sbi_remote_hfence_vvma_asid(const struct cpumask *cpu_mask,
unsigned long start, unsigned long start,
unsigned long size, unsigned long size,
unsigned long asid); unsigned long asid);
...@@ -183,7 +184,7 @@ static inline unsigned long sbi_mk_version(unsigned long major, ...@@ -183,7 +184,7 @@ static inline unsigned long sbi_mk_version(unsigned long major,
int sbi_err_map_linux_errno(int err); int sbi_err_map_linux_errno(int err);
#else /* CONFIG_RISCV_SBI */ #else /* CONFIG_RISCV_SBI */
static inline int sbi_remote_fence_i(const unsigned long *hart_mask) { return -1; } static inline int sbi_remote_fence_i(const struct cpumask *cpu_mask) { return -1; }
static inline void sbi_init(void) {} static inline void sbi_init(void) {}
#endif /* CONFIG_RISCV_SBI */ #endif /* CONFIG_RISCV_SBI */
#endif /* _ASM_RISCV_SBI_H */ #endif /* _ASM_RISCV_SBI_H */
...@@ -92,8 +92,6 @@ static inline void riscv_clear_ipi(void) ...@@ -92,8 +92,6 @@ static inline void riscv_clear_ipi(void)
#endif /* CONFIG_SMP */ #endif /* CONFIG_SMP */
void riscv_cpuid_to_hartid_mask(const struct cpumask *in, struct cpumask *out);
#if defined(CONFIG_HOTPLUG_CPU) && (CONFIG_SMP) #if defined(CONFIG_HOTPLUG_CPU) && (CONFIG_SMP)
bool cpu_has_hotplug(unsigned int cpu); bool cpu_has_hotplug(unsigned int cpu);
#else #else
......
This diff is collapsed.
...@@ -59,16 +59,6 @@ atomic_t hart_lottery __section(".sdata") ...@@ -59,16 +59,6 @@ atomic_t hart_lottery __section(".sdata")
unsigned long boot_cpu_hartid; unsigned long boot_cpu_hartid;
static DEFINE_PER_CPU(struct cpu, cpu_devices); static DEFINE_PER_CPU(struct cpu, cpu_devices);
void riscv_cpuid_to_hartid_mask(const struct cpumask *in, struct cpumask *out)
{
int cpu;
cpumask_clear(out);
for_each_cpu(cpu, in)
cpumask_set_cpu(cpuid_to_hartid_map(cpu), out);
}
EXPORT_SYMBOL_GPL(riscv_cpuid_to_hartid_mask);
/* /*
* Place kernel memory regions on the resource tree so that * Place kernel memory regions on the resource tree so that
* kexec-tools can retrieve them from /proc/iomem. While there * kexec-tools can retrieve them from /proc/iomem. While there
......
...@@ -96,7 +96,7 @@ void __init setup_smp(void) ...@@ -96,7 +96,7 @@ void __init setup_smp(void)
if (cpuid >= NR_CPUS) { if (cpuid >= NR_CPUS) {
pr_warn("Invalid cpuid [%d] for hartid [%d]\n", pr_warn("Invalid cpuid [%d] for hartid [%d]\n",
cpuid, hart); cpuid, hart);
break; continue;
} }
cpuid_to_hartid_map(cpuid) = hart; cpuid_to_hartid_map(cpuid) = hart;
......
...@@ -114,7 +114,6 @@ static bool stage2_get_leaf_entry(struct kvm *kvm, gpa_t addr, ...@@ -114,7 +114,6 @@ static bool stage2_get_leaf_entry(struct kvm *kvm, gpa_t addr,
static void stage2_remote_tlb_flush(struct kvm *kvm, u32 level, gpa_t addr) static void stage2_remote_tlb_flush(struct kvm *kvm, u32 level, gpa_t addr)
{ {
struct cpumask hmask;
unsigned long size = PAGE_SIZE; unsigned long size = PAGE_SIZE;
struct kvm_vmid *vmid = &kvm->arch.vmid; struct kvm_vmid *vmid = &kvm->arch.vmid;
...@@ -127,8 +126,7 @@ static void stage2_remote_tlb_flush(struct kvm *kvm, u32 level, gpa_t addr) ...@@ -127,8 +126,7 @@ static void stage2_remote_tlb_flush(struct kvm *kvm, u32 level, gpa_t addr)
* where the Guest/VM is running. * where the Guest/VM is running.
*/ */
preempt_disable(); preempt_disable();
riscv_cpuid_to_hartid_mask(cpu_online_mask, &hmask); sbi_remote_hfence_gvma_vmid(cpu_online_mask, addr, size,
sbi_remote_hfence_gvma_vmid(cpumask_bits(&hmask), addr, size,
READ_ONCE(vmid->vmid)); READ_ONCE(vmid->vmid));
preempt_enable(); preempt_enable();
} }
......
...@@ -82,7 +82,7 @@ static int kvm_sbi_ext_rfence_handler(struct kvm_vcpu *vcpu, struct kvm_run *run ...@@ -82,7 +82,7 @@ static int kvm_sbi_ext_rfence_handler(struct kvm_vcpu *vcpu, struct kvm_run *run
{ {
int ret = 0; int ret = 0;
unsigned long i; unsigned long i;
struct cpumask cm, hm; struct cpumask cm;
struct kvm_vcpu *tmp; struct kvm_vcpu *tmp;
struct kvm_cpu_context *cp = &vcpu->arch.guest_context; struct kvm_cpu_context *cp = &vcpu->arch.guest_context;
unsigned long hmask = cp->a0; unsigned long hmask = cp->a0;
...@@ -90,7 +90,6 @@ static int kvm_sbi_ext_rfence_handler(struct kvm_vcpu *vcpu, struct kvm_run *run ...@@ -90,7 +90,6 @@ static int kvm_sbi_ext_rfence_handler(struct kvm_vcpu *vcpu, struct kvm_run *run
unsigned long funcid = cp->a6; unsigned long funcid = cp->a6;
cpumask_clear(&cm); cpumask_clear(&cm);
cpumask_clear(&hm);
kvm_for_each_vcpu(i, tmp, vcpu->kvm) { kvm_for_each_vcpu(i, tmp, vcpu->kvm) {
if (hbase != -1UL) { if (hbase != -1UL) {
if (tmp->vcpu_id < hbase) if (tmp->vcpu_id < hbase)
...@@ -103,17 +102,15 @@ static int kvm_sbi_ext_rfence_handler(struct kvm_vcpu *vcpu, struct kvm_run *run ...@@ -103,17 +102,15 @@ static int kvm_sbi_ext_rfence_handler(struct kvm_vcpu *vcpu, struct kvm_run *run
cpumask_set_cpu(tmp->cpu, &cm); cpumask_set_cpu(tmp->cpu, &cm);
} }
riscv_cpuid_to_hartid_mask(&cm, &hm);
switch (funcid) { switch (funcid) {
case SBI_EXT_RFENCE_REMOTE_FENCE_I: case SBI_EXT_RFENCE_REMOTE_FENCE_I:
ret = sbi_remote_fence_i(cpumask_bits(&hm)); ret = sbi_remote_fence_i(&cm);
break; break;
case SBI_EXT_RFENCE_REMOTE_SFENCE_VMA: case SBI_EXT_RFENCE_REMOTE_SFENCE_VMA:
ret = sbi_remote_hfence_vvma(cpumask_bits(&hm), cp->a2, cp->a3); ret = sbi_remote_hfence_vvma(&cm, cp->a2, cp->a3);
break; break;
case SBI_EXT_RFENCE_REMOTE_SFENCE_VMA_ASID: case SBI_EXT_RFENCE_REMOTE_SFENCE_VMA_ASID:
ret = sbi_remote_hfence_vvma_asid(cpumask_bits(&hm), cp->a2, ret = sbi_remote_hfence_vvma_asid(&cm, cp->a2,
cp->a3, cp->a4); cp->a3, cp->a4);
break; break;
case SBI_EXT_RFENCE_REMOTE_HFENCE_GVMA: case SBI_EXT_RFENCE_REMOTE_HFENCE_GVMA:
......
...@@ -38,7 +38,7 @@ static int kvm_sbi_ext_v01_handler(struct kvm_vcpu *vcpu, struct kvm_run *run, ...@@ -38,7 +38,7 @@ static int kvm_sbi_ext_v01_handler(struct kvm_vcpu *vcpu, struct kvm_run *run,
int i, ret = 0; int i, ret = 0;
u64 next_cycle; u64 next_cycle;
struct kvm_vcpu *rvcpu; struct kvm_vcpu *rvcpu;
struct cpumask cm, hm; struct cpumask cm;
struct kvm *kvm = vcpu->kvm; struct kvm *kvm = vcpu->kvm;
struct kvm_cpu_context *cp = &vcpu->arch.guest_context; struct kvm_cpu_context *cp = &vcpu->arch.guest_context;
...@@ -101,15 +101,12 @@ static int kvm_sbi_ext_v01_handler(struct kvm_vcpu *vcpu, struct kvm_run *run, ...@@ -101,15 +101,12 @@ static int kvm_sbi_ext_v01_handler(struct kvm_vcpu *vcpu, struct kvm_run *run,
continue; continue;
cpumask_set_cpu(rvcpu->cpu, &cm); cpumask_set_cpu(rvcpu->cpu, &cm);
} }
riscv_cpuid_to_hartid_mask(&cm, &hm);
if (cp->a7 == SBI_EXT_0_1_REMOTE_FENCE_I) if (cp->a7 == SBI_EXT_0_1_REMOTE_FENCE_I)
ret = sbi_remote_fence_i(cpumask_bits(&hm)); ret = sbi_remote_fence_i(&cm);
else if (cp->a7 == SBI_EXT_0_1_REMOTE_SFENCE_VMA) else if (cp->a7 == SBI_EXT_0_1_REMOTE_SFENCE_VMA)
ret = sbi_remote_hfence_vvma(cpumask_bits(&hm), ret = sbi_remote_hfence_vvma(&cm, cp->a1, cp->a2);
cp->a1, cp->a2);
else else
ret = sbi_remote_hfence_vvma_asid(cpumask_bits(&hm), ret = sbi_remote_hfence_vvma_asid(&cm, cp->a1, cp->a2, cp->a3);
cp->a1, cp->a2, cp->a3);
break; break;
default: default:
ret = -EINVAL; ret = -EINVAL;
......
...@@ -67,7 +67,6 @@ void kvm_riscv_stage2_vmid_update(struct kvm_vcpu *vcpu) ...@@ -67,7 +67,6 @@ void kvm_riscv_stage2_vmid_update(struct kvm_vcpu *vcpu)
{ {
unsigned long i; unsigned long i;
struct kvm_vcpu *v; struct kvm_vcpu *v;
struct cpumask hmask;
struct kvm_vmid *vmid = &vcpu->kvm->arch.vmid; struct kvm_vmid *vmid = &vcpu->kvm->arch.vmid;
if (!kvm_riscv_stage2_vmid_ver_changed(vmid)) if (!kvm_riscv_stage2_vmid_ver_changed(vmid))
...@@ -102,8 +101,7 @@ void kvm_riscv_stage2_vmid_update(struct kvm_vcpu *vcpu) ...@@ -102,8 +101,7 @@ void kvm_riscv_stage2_vmid_update(struct kvm_vcpu *vcpu)
* running, we force VM exits on all host CPUs using IPI and * running, we force VM exits on all host CPUs using IPI and
* flush all Guest TLBs. * flush all Guest TLBs.
*/ */
riscv_cpuid_to_hartid_mask(cpu_online_mask, &hmask); sbi_remote_hfence_gvma(cpu_online_mask, 0, 0);
sbi_remote_hfence_gvma(cpumask_bits(&hmask), 0, 0);
} }
vmid->vmid = vmid_next; vmid->vmid = vmid_next;
......
...@@ -67,10 +67,7 @@ void flush_icache_mm(struct mm_struct *mm, bool local) ...@@ -67,10 +67,7 @@ void flush_icache_mm(struct mm_struct *mm, bool local)
*/ */
smp_mb(); smp_mb();
} else if (IS_ENABLED(CONFIG_RISCV_SBI)) { } else if (IS_ENABLED(CONFIG_RISCV_SBI)) {
cpumask_t hartid_mask; sbi_remote_fence_i(&others);
riscv_cpuid_to_hartid_mask(&others, &hartid_mask);
sbi_remote_fence_i(cpumask_bits(&hartid_mask));
} else { } else {
on_each_cpu_mask(&others, ipi_remote_fence_i, NULL, 1); on_each_cpu_mask(&others, ipi_remote_fence_i, NULL, 1);
} }
......
...@@ -32,7 +32,6 @@ static void __sbi_tlb_flush_range(struct mm_struct *mm, unsigned long start, ...@@ -32,7 +32,6 @@ static void __sbi_tlb_flush_range(struct mm_struct *mm, unsigned long start,
unsigned long size, unsigned long stride) unsigned long size, unsigned long stride)
{ {
struct cpumask *cmask = mm_cpumask(mm); struct cpumask *cmask = mm_cpumask(mm);
struct cpumask hmask;
unsigned int cpuid; unsigned int cpuid;
bool broadcast; bool broadcast;
...@@ -46,9 +45,7 @@ static void __sbi_tlb_flush_range(struct mm_struct *mm, unsigned long start, ...@@ -46,9 +45,7 @@ static void __sbi_tlb_flush_range(struct mm_struct *mm, unsigned long start,
unsigned long asid = atomic_long_read(&mm->context.id); unsigned long asid = atomic_long_read(&mm->context.id);
if (broadcast) { if (broadcast) {
riscv_cpuid_to_hartid_mask(cmask, &hmask); sbi_remote_sfence_vma_asid(cmask, start, size, asid);
sbi_remote_sfence_vma_asid(cpumask_bits(&hmask),
start, size, asid);
} else if (size <= stride) { } else if (size <= stride) {
local_flush_tlb_page_asid(start, asid); local_flush_tlb_page_asid(start, asid);
} else { } else {
...@@ -56,9 +53,7 @@ static void __sbi_tlb_flush_range(struct mm_struct *mm, unsigned long start, ...@@ -56,9 +53,7 @@ static void __sbi_tlb_flush_range(struct mm_struct *mm, unsigned long start,
} }
} else { } else {
if (broadcast) { if (broadcast) {
riscv_cpuid_to_hartid_mask(cmask, &hmask); sbi_remote_sfence_vma(cmask, start, size);
sbi_remote_sfence_vma(cpumask_bits(&hmask),
start, size);
} else if (size <= stride) { } else if (size <= stride) {
local_flush_tlb_page(start); local_flush_tlb_page(start);
} else { } else {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment