Skip to content

Commit bc38f61

Browse files
clementlegerpalmer-dabbelt
authored andcommitted
riscv: add support for sysctl unaligned_enabled control
This sysctl tuning option allows the user to disable misaligned access handling globally on the system. This will also be used by misaligned detection code to temporarily disable misaligned access handling. Signed-off-by: Clément Léger <cleger@rivosinc.com> Reviewed-by: Björn Töpel <bjorn@rivosinc.com> Link: https://lore.kernel.org/r/20231004151405.521596-6-cleger@rivosinc.com Signed-off-by: Palmer Dabbelt <palmer@rivosinc.com>
1 parent 7c586a5 commit bc38f61

2 files changed

Lines changed: 10 additions & 0 deletions

File tree

arch/riscv/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -638,6 +638,7 @@ config THREAD_SIZE_ORDER
638638

639639
config RISCV_MISALIGNED
640640
bool "Support misaligned load/store traps for kernel and userspace"
641+
select SYSCTL_ARCH_UNALIGN_ALLOW
641642
default y
642643
help
643644
Say Y here if you want the kernel to embed support for misaligned

arch/riscv/kernel/traps_misaligned.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,9 @@ union reg_data {
396396
u64 data_u64;
397397
};
398398

399+
/* sysctl hooks */
400+
int unaligned_enabled __read_mostly = 1; /* Enabled by default */
401+
399402
int handle_misaligned_load(struct pt_regs *regs)
400403
{
401404
union reg_data val;
@@ -406,6 +409,9 @@ int handle_misaligned_load(struct pt_regs *regs)
406409

407410
perf_sw_event(PERF_COUNT_SW_ALIGNMENT_FAULTS, 1, regs, addr);
408411

412+
if (!unaligned_enabled)
413+
return -1;
414+
409415
if (get_insn(regs, epc, &insn))
410416
return -1;
411417

@@ -502,6 +508,9 @@ int handle_misaligned_store(struct pt_regs *regs)
502508

503509
perf_sw_event(PERF_COUNT_SW_ALIGNMENT_FAULTS, 1, regs, addr);
504510

511+
if (!unaligned_enabled)
512+
return -1;
513+
505514
if (get_insn(regs, epc, &insn))
506515
return -1;
507516

0 commit comments

Comments
 (0)