linux/arch/riscv
Charlie Jenkins 7c1e5b9690
riscv: Disable preemption while handling PR_RISCV_CTX_SW_FENCEI_OFF
The icache will be flushed in switch_to() if force_icache_flush is true,
or in flush_icache_deferred() if icache_stale_mask is set. Between
setting force_icache_flush to false and calculating the new
icache_stale_mask, preemption needs to be disabled. There are two
reasons for this:

1. If CPU migration happens between force_icache_flush = false, and the
   icache_stale_mask is set, an icache flush will not be emitted.
2. smp_processor_id() is used in set_icache_stale_mask() to mark the
   current CPU as not needing another flush since a flush will have
   happened either by userspace or by the kernel when performing the
   migration. smp_processor_id() is currently called twice with preemption
   enabled which causes a race condition. It allows
   icache_stale_mask to be populated with inconsistent CPU ids.

Resolve these two issues by setting the icache_stale_mask before setting
force_icache_flush to false, and using get_cpu()/put_cpu() to obtain the
smp_processor_id().

Signed-off-by: Charlie Jenkins <charlie@rivosinc.com>
Fixes: 6b9391b581 ("riscv: Include riscv_set_icache_flush_ctx prctl")
Link: https://lore.kernel.org/r/20240903-fix_fencei_optimization-v2-1-8025f20171fc@rivosinc.com
Signed-off-by: Palmer Dabbelt <palmer@rivosinc.com>
2024-09-10 20:38:46 -07:00
..
boot RISC-V Patches for the 6.11 Merge Window, Part 2 2024-07-27 10:14:34 -07:00
configs RISC-V: run savedefconfig for defconfig 2024-07-22 10:57:47 -07:00
crypto crypto: riscv - add vector crypto accelerated AES-CBC-CTS 2024-03-20 08:56:11 -07:00
errata riscv: Extend cpufeature.c to detect vendor extensions 2024-07-22 15:36:54 -07:00
include riscv: Fix RISCV_ALTERNATIVE_EARLY 2024-09-03 07:57:55 -07:00
kernel riscv: Fix RISCV_ALTERNATIVE_EARLY 2024-09-03 07:57:55 -07:00
kvm ARM: 2024-07-20 12:41:03 -07:00
lib riscv: Optimize crc32 with Zbc extension 2024-07-10 13:19:50 -07:00
mm riscv: Disable preemption while handling PR_RISCV_CTX_SW_FENCEI_OFF 2024-09-10 20:38:46 -07:00
net RISC-V Patches for the 6.11 Merge Window, Part 1 2024-07-20 09:11:27 -07:00
purgatory riscv/purgatory: align riscv_kernel_entry 2024-08-01 07:14:34 -07:00
tools riscv: Check relocations at compile time 2023-04-19 07:46:32 -07:00
Kbuild RISC-V: hook new crypto subdir into build-system 2024-01-22 17:55:17 -08:00
Kconfig riscv: Fix toolchain vector detection 2024-09-03 07:57:05 -07:00
Kconfig.debug riscv: Add tests for riscv module loading 2023-11-07 14:59:32 -08:00
Kconfig.errata riscv: thead: Rename T-Head PBMT to MAE 2024-04-25 10:22:33 -07:00
Kconfig.socs RISC-V: drop SOC_VIRT for ARCH_VIRT 2024-04-10 11:37:50 +01:00
Kconfig.vendor riscv: Extend cpufeature.c to detect vendor extensions 2024-07-22 15:36:54 -07:00
Makefile Merge patch series "riscv: Apply Zawrs when available" 2024-07-12 08:55:29 -07:00
Makefile.postlink kbuild: remove ARCH_POSTLINK from module builds 2023-10-28 21:10:08 +09:00