linux-sg2042/arch/riscv/kernel
Emil Renner Berthing 0966d38583
riscv: Fix auipc+jalr relocation range checks
RISC-V can do PC-relative jumps with a 32bit range using the following
two instructions:

	auipc	t0, imm20	; t0 = PC + imm20 * 2^12
	jalr	ra, t0, imm12	; ra = PC + 4, PC = t0 + imm12

Crucially both the 20bit immediate imm20 and the 12bit immediate imm12
are treated as two's-complement signed values. For this reason the
immediates are usually calculated like this:

	imm20 = (offset + 0x800) >> 12
	imm12 = offset & 0xfff

..where offset is the signed offset from the auipc instruction. When
the 11th bit of offset is 0 the addition of 0x800 doesn't change the top
20 bits and imm12 considered positive. When the 11th bit is 1 the carry
of the addition by 0x800 means imm20 is one higher, but since imm12 is
then considered negative the two's complement representation means it
all cancels out nicely.

However, this addition by 0x800 (2^11) means an offset greater than or
equal to 2^31 - 2^11 would overflow so imm20 is considered negative and
result in a backwards jump. Similarly the lower range of offset is also
moved down by 2^11 and hence the true 32bit range is

	[-2^31 - 2^11, 2^31 - 2^11)

Signed-off-by: Emil Renner Berthing <kernel@esmil.dk>
Fixes: e2c0cdfba7 ("RISC-V: User-facing API")
Cc: stable@vger.kernel.org
Signed-off-by: Palmer Dabbelt <palmer@rivosinc.com>
2022-03-10 20:37:44 -08:00
..
probes ftrace: disable preemption when recursion locked 2021-10-27 11:21:49 -04:00
vdso riscv/vdso: Add support for time namespaces 2021-10-04 14:16:43 -07:00
.gitignore .gitignore: add SPDX License Identifier 2020-03-25 11:50:48 +01:00
Makefile riscv: fix oops caused by irqsoff latency tracer 2022-02-24 20:30:30 -08:00
asm-offsets.c RISC-V: Avoid using per cpu array for ordered booting 2022-01-20 09:26:59 -08:00
cacheinfo.c drivers: base: cacheinfo: Get rid of DEFINE_SMP_CALL_CACHE_FUNCTION() 2021-09-01 10:29:10 +02:00
cpu-hotplug.c riscv: cpu-hotplug: clear cpu from numa map when teardown 2022-02-10 09:16:50 -08:00
cpu.c riscv: Use pgtable_l4_enabled to output mmu_type in cpuinfo 2022-01-19 17:54:10 -08:00
cpu_ops.c RISC-V: Move spinwait booting method to its own config 2022-01-20 09:27:16 -08:00
cpu_ops_sbi.c RISC-V: Avoid using per cpu array for ordered booting 2022-01-20 09:26:59 -08:00
cpu_ops_spinwait.c RISC-V: Use __cpu_up_stack/task_pointer only for spinwait method 2022-01-20 09:27:08 -08:00
cpufeature.c riscv: Add __init section marker to some functions again 2021-05-29 13:39:27 -07:00
crash_dump.c RISC-V: Add crash kernel support 2021-04-26 08:25:24 -07:00
crash_save_regs.S RISC-V: Add kdump support 2021-04-26 08:25:23 -07:00
efi-header.S RISC-V: Add PE/COFF header for EFI stub 2020-10-02 14:31:16 -07:00
efi.c RISC-V: Add EFI runtime services 2020-10-02 14:31:28 -07:00
entry.S riscv: fix oops caused by irqsoff latency tracer 2022-02-24 20:30:30 -08:00
fpu.S riscv: abstract out CSR names for supervisor vs machine mode 2019-11-05 09:20:42 -08:00
ftrace.c ftrace: Cleanup ftrace_dyn_arch_init() 2021-10-08 19:41:39 -04:00
head.S riscv: Fix XIP_FIXUP_FLASH_OFFSET 2022-02-04 11:11:07 -08:00
head.h RISC-V: Move spinwait booting method to its own config 2022-01-20 09:27:16 -08:00
image-vars.h arch/riscv:fix typo in a comment in arch/riscv/kernel/image-vars.h 2021-02-18 23:18:00 -08:00
irq.c RISC-V: Remove do_IRQ() function 2020-06-09 19:11:24 -07:00
jump_label.c riscv: Add jump-label implementation 2020-07-30 11:37:43 -07:00
kexec_relocate.S riscv: Don't use va_pa_offset on kdump 2022-01-09 10:38:06 -08:00
kgdb.c riscv: Fix "no previous prototype" compile warning in kgdb.c file 2020-07-09 20:09:30 -07:00
machine_kexec.c riscv: use hart id instead of cpu id on machine_kexec 2022-01-09 10:40:00 -08:00
mcount-dyn.S riscv: Using PATCHABLE_FUNCTION_ENTRY instead of MCOUNT 2021-01-14 15:09:05 -08:00
mcount.S riscv: Workaround mcount name prior to clang-13 2021-04-26 08:25:01 -07:00
module-sections.c riscv: add missing header file includes 2019-10-28 00:46:01 -07:00
module.c riscv: Fix auipc+jalr relocation range checks 2022-03-10 20:37:44 -08:00
patch.c riscv: Fixup compile error BUILD_BUG_ON failed 2021-01-14 15:09:01 -08:00
perf_callchain.c perf: Drop dead and useless guest "support" from arm, csky, nds32 and riscv 2021-11-17 14:49:07 +01:00
perf_event.c riscv: perf_event: Make some funciton static 2020-05-11 13:48:19 -07:00
perf_regs.c perf/arch: Remove perf_sample_data::regs_user_copy 2020-11-09 18:12:34 +01:00
process.c riscv: Turn has_fpu into a static key if FPU=y 2021-05-25 22:56:57 -07:00
ptrace.c RISC-V: Remove redundant err variable 2022-01-20 10:24:12 -08:00
reset.c riscv: set default pm_power_off to NULL 2021-10-04 14:16:57 -07:00
riscv_ksyms.c riscv: provide memmove implementation 2020-12-10 17:27:54 -08:00
sbi.c RISC-V: Fix IPI/RFENCE hmask on non-monotonic hartid ordering 2022-02-14 12:27:45 -08:00
setup.c RISC-V: Do not use cpumask data structure for hartid bitmap 2022-01-20 09:27:22 -08:00
signal.c riscv: Turn has_fpu into a static key if FPU=y 2021-05-25 22:56:57 -07:00
smp.c RISC-V: Use common riscv_cpuid_to_hartid_mask() for both SMP=y and SMP=n 2022-01-09 12:13:31 -08:00
smpboot.c RISC-V: Do not use cpumask data structure for hartid bitmap 2022-01-20 09:27:22 -08:00
soc.c riscv: Fix builtin DTB handling 2021-01-07 19:00:50 -08:00
stacktrace.c riscv: eliminate unreliable __builtin_frame_address(1) 2022-02-04 10:12:32 -08:00
sys_riscv.c RISC-V: Don't allow write+exec only page mapping request in mmap 2020-06-18 17:28:53 -07:00
syscall_table.c riscv/vdso: Refactor asm/vdso.h 2021-10-02 13:42:23 -07:00
time.c RISC-V Patches for the 5.13 Merge Window, Part 1 2021-05-06 09:24:18 -07:00
trace_irq.c riscv: fix oops caused by irqsoff latency tracer 2022-02-24 20:30:30 -08:00
trace_irq.h riscv: fix oops caused by irqsoff latency tracer 2022-02-24 20:30:30 -08:00
traps.c exit: Add and use make_task_dead. 2021-12-13 12:04:45 -06:00
traps_misaligned.c riscv: Unaligned load/store handling for M_MODE 2020-04-03 10:45:33 -07:00
vdso.c riscv/vdso: Add support for time namespaces 2021-10-04 14:16:43 -07:00
vmlinux-xip.lds.S riscv: vmlinux.lds.S|vmlinux-xip.lds.S: remove `.fixup` section 2022-01-05 17:53:37 -08:00
vmlinux.lds.S riscv: vmlinux.lds.S|vmlinux-xip.lds.S: remove `.fixup` section 2022-01-05 17:53:37 -08:00