Commit 6e5ce7f2 authored by Charlie Jenkins's avatar Charlie Jenkins Committed by Palmer Dabbelt

riscv: Decouple emulated unaligned accesses from access speed

Detecting if a system traps into the kernel on an unaligned access
can be performed separately from checking the speed of unaligned
accesses. This decoupling will make it possible to selectively enable
or disable each of these checks.
Signed-off-by: default avatarCharlie Jenkins <charlie@rivosinc.com>
Reviewed-by: default avatarConor Dooley <conor.dooley@microchip.com>
Tested-by: default avatarSamuel Holland <samuel.holland@sifive.com>
Link: https://lore.kernel.org/r/20240308-disable_misaligned_probe_config-v9-3-a388770ba0ce@rivosinc.comSigned-off-by: default avatarPalmer Dabbelt <palmer@rivosinc.com>
parent 313130c6
...@@ -37,7 +37,7 @@ void riscv_user_isa_enable(void); ...@@ -37,7 +37,7 @@ void riscv_user_isa_enable(void);
#ifdef CONFIG_RISCV_MISALIGNED #ifdef CONFIG_RISCV_MISALIGNED
bool unaligned_ctl_available(void); bool unaligned_ctl_available(void);
bool check_unaligned_access_emulated(int cpu); bool check_unaligned_access_emulated_all_cpus(void);
void unaligned_emulation_finish(void); void unaligned_emulation_finish(void);
#else #else
static inline bool unaligned_ctl_available(void) static inline bool unaligned_ctl_available(void)
......
...@@ -719,7 +719,8 @@ static int check_unaligned_access(void *param) ...@@ -719,7 +719,8 @@ static int check_unaligned_access(void *param)
void *src; void *src;
long speed = RISCV_HWPROBE_MISALIGNED_SLOW; long speed = RISCV_HWPROBE_MISALIGNED_SLOW;
if (check_unaligned_access_emulated(cpu)) if (IS_ENABLED(CONFIG_RISCV_MISALIGNED) &&
per_cpu(misaligned_access_speed, cpu) != RISCV_HWPROBE_MISALIGNED_UNKNOWN)
return 0; return 0;
/* Make an unaligned destination buffer. */ /* Make an unaligned destination buffer. */
...@@ -896,8 +897,8 @@ static int riscv_offline_cpu(unsigned int cpu) ...@@ -896,8 +897,8 @@ static int riscv_offline_cpu(unsigned int cpu)
return 0; return 0;
} }
/* Measure unaligned access on all CPUs present at boot in parallel. */ /* Measure unaligned access speed on all CPUs present at boot in parallel. */
static int check_unaligned_access_all_cpus(void) static int check_unaligned_access_speed_all_cpus(void)
{ {
unsigned int cpu; unsigned int cpu;
unsigned int cpu_count = num_possible_cpus(); unsigned int cpu_count = num_possible_cpus();
...@@ -935,7 +936,6 @@ static int check_unaligned_access_all_cpus(void) ...@@ -935,7 +936,6 @@ static int check_unaligned_access_all_cpus(void)
riscv_online_cpu, riscv_offline_cpu); riscv_online_cpu, riscv_offline_cpu);
out: out:
unaligned_emulation_finish();
for_each_cpu(cpu, cpu_online_mask) { for_each_cpu(cpu, cpu_online_mask) {
if (bufs[cpu]) if (bufs[cpu])
__free_pages(bufs[cpu], MISALIGNED_BUFFER_ORDER); __free_pages(bufs[cpu], MISALIGNED_BUFFER_ORDER);
...@@ -945,6 +945,23 @@ static int check_unaligned_access_all_cpus(void) ...@@ -945,6 +945,23 @@ static int check_unaligned_access_all_cpus(void)
return 0; return 0;
} }
#ifdef CONFIG_RISCV_MISALIGNED
static int check_unaligned_access_all_cpus(void)
{
bool all_cpus_emulated = check_unaligned_access_emulated_all_cpus();
if (!all_cpus_emulated)
return check_unaligned_access_speed_all_cpus();
return 0;
}
#else
static int check_unaligned_access_all_cpus(void)
{
return check_unaligned_access_speed_all_cpus();
}
#endif
arch_initcall(check_unaligned_access_all_cpus); arch_initcall(check_unaligned_access_all_cpus);
void riscv_user_isa_enable(void) void riscv_user_isa_enable(void)
......
...@@ -596,7 +596,7 @@ int handle_misaligned_store(struct pt_regs *regs) ...@@ -596,7 +596,7 @@ int handle_misaligned_store(struct pt_regs *regs)
return 0; return 0;
} }
bool check_unaligned_access_emulated(int cpu) static bool check_unaligned_access_emulated(int cpu)
{ {
long *mas_ptr = per_cpu_ptr(&misaligned_access_speed, cpu); long *mas_ptr = per_cpu_ptr(&misaligned_access_speed, cpu);
unsigned long tmp_var, tmp_val; unsigned long tmp_var, tmp_val;
...@@ -623,7 +623,7 @@ bool check_unaligned_access_emulated(int cpu) ...@@ -623,7 +623,7 @@ bool check_unaligned_access_emulated(int cpu)
return misaligned_emu_detected; return misaligned_emu_detected;
} }
void unaligned_emulation_finish(void) bool check_unaligned_access_emulated_all_cpus(void)
{ {
int cpu; int cpu;
...@@ -632,13 +632,12 @@ void unaligned_emulation_finish(void) ...@@ -632,13 +632,12 @@ void unaligned_emulation_finish(void)
* accesses emulated since tasks requesting such control can run on any * accesses emulated since tasks requesting such control can run on any
* CPU. * CPU.
*/ */
for_each_online_cpu(cpu) { for_each_online_cpu(cpu)
if (per_cpu(misaligned_access_speed, cpu) != if (!check_unaligned_access_emulated(cpu))
RISCV_HWPROBE_MISALIGNED_EMULATED) { return false;
return;
}
}
unaligned_ctl = true; unaligned_ctl = true;
return true;
} }
bool unaligned_ctl_available(void) bool unaligned_ctl_available(void)
......
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