RISC-V: Fix IPI/RFENCE hmask on non-monotonic hartid ordering
authorGeert Uytterhoeven <geert@linux-m68k.org>
Mon, 31 Jan 2022 13:26:22 +0000 (14:26 +0100)
committerPalmer Dabbelt <palmer@rivosinc.com>
Mon, 14 Feb 2022 20:27:45 +0000 (12:27 -0800)
commit5feef64f4c67068c49f5409d43c67cabf2327f66
tree9ab6716e6c0be760c787c49717cf8aa00a4c7d53
parent2b35d5b7d13062b805aa82dc53812a5f56249287
RISC-V: Fix IPI/RFENCE hmask on non-monotonic hartid ordering

If the boot CPU does not have the lowest hartid, "hartid - hbase" can
become negative, leading to an incorrect hmask, causing userspace to
crash with SEGV.  This is observed on e.g. Starlight Beta, where cpuid 1
maps to hartid 0, and cpuid 0 maps to hartid 1.

Fix this by detecting this case, and shifting the accumulated mask and
updating hbase, if possible.

Fixes: 26fb751ca37846c9 ("RISC-V: Do not use cpumask data structure for hartid bitmap")
Signed-off-by: Geert Uytterhoeven <geert@linux-m68k.org>
Reviewed-by: Atish Patra <atishp@rivosinc.com>
Tested-by: Atish Patra <atishp@rivosinc.com>
Signed-off-by: Palmer Dabbelt <palmer@rivosinc.com>
arch/riscv/kernel/sbi.c