linux/arch/riscv/include/asm
Jisheng Zhang 3a02764c37
riscv: Ensure BPF_JIT_REGION_START aligned with PMD size
Andreas reported commit fc8504765e ("riscv: bpf: Avoid breaking W^X")
breaks booting with one kind of defconfig, I reproduced a kernel panic
with the defconfig:

[    0.138553] Unable to handle kernel paging request at virtual address ffffffff81201220
[    0.139159] Oops [#1]
[    0.139303] Modules linked in:
[    0.139601] CPU: 0 PID: 1 Comm: swapper/0 Not tainted 5.13.0-rc5-default+ #1
[    0.139934] Hardware name: riscv-virtio,qemu (DT)
[    0.140193] epc : __memset+0xc4/0xfc
[    0.140416]  ra : skb_flow_dissector_init+0x1e/0x82
[    0.140609] epc : ffffffff8029806c ra : ffffffff8033be78 sp : ffffffe001647da0
[    0.140878]  gp : ffffffff81134b08 tp : ffffffe001654380 t0 : ffffffff81201158
[    0.141156]  t1 : 0000000000000002 t2 : 0000000000000154 s0 : ffffffe001647dd0
[    0.141424]  s1 : ffffffff80a43250 a0 : ffffffff81201220 a1 : 0000000000000000
[    0.141654]  a2 : 000000000000003c a3 : ffffffff81201258 a4 : 0000000000000064
[    0.141893]  a5 : ffffffff8029806c a6 : 0000000000000040 a7 : ffffffffffffffff
[    0.142126]  s2 : ffffffff81201220 s3 : 0000000000000009 s4 : ffffffff81135088
[    0.142353]  s5 : ffffffff81135038 s6 : ffffffff8080ce80 s7 : ffffffff80800438
[    0.142584]  s8 : ffffffff80bc6578 s9 : 0000000000000008 s10: ffffffff806000ac
[    0.142810]  s11: 0000000000000000 t3 : fffffffffffffffc t4 : 0000000000000000
[    0.143042]  t5 : 0000000000000155 t6 : 00000000000003ff
[    0.143220] status: 0000000000000120 badaddr: ffffffff81201220 cause: 000000000000000f
[    0.143560] [<ffffffff8029806c>] __memset+0xc4/0xfc
[    0.143859] [<ffffffff8061e984>] init_default_flow_dissectors+0x22/0x60
[    0.144092] [<ffffffff800010fc>] do_one_initcall+0x3e/0x168
[    0.144278] [<ffffffff80600df0>] kernel_init_freeable+0x1c8/0x224
[    0.144479] [<ffffffff804868a8>] kernel_init+0x12/0x110
[    0.144658] [<ffffffff800022de>] ret_from_exception+0x0/0xc
[    0.145124] ---[ end trace f1e9643daa46d591 ]---

After some investigation, I think I found the root cause: commit
2bfc6cd81b ("move kernel mapping outside of linear mapping") moves
BPF JIT region after the kernel:

| #define BPF_JIT_REGION_START	PFN_ALIGN((unsigned long)&_end)

The &_end is unlikely aligned with PMD size, so the front bpf jit
region sits with part of kernel .data section in one PMD size mapping.
But kernel is mapped in PMD SIZE, when bpf_jit_binary_lock_ro() is
called to make the first bpf jit prog ROX, we will make part of kernel
.data section RO too, so when we write to, for example memset the
.data section, MMU will trigger a store page fault.

To fix the issue, we need to ensure the BPF JIT region is PMD size
aligned. This patch acchieve this goal by restoring the BPF JIT region
to original position, I.E the 128MB before kernel .text section. The
modification to kasan_init.c is inspired by Alexandre.

Fixes: fc8504765e ("riscv: bpf: Avoid breaking W^X")
Reported-by: Andreas Schwab <schwab@linux-m68k.org>
Signed-off-by: Jisheng Zhang <jszhang@kernel.org>
Signed-off-by: Palmer Dabbelt <palmerdabbelt@google.com>
2021-06-18 21:10:05 -07:00
..
vdso RISC-V: fix barrier() use in <vdso/processor.h> 2020-11-25 09:44:27 -08:00
alternative-macros.h riscv: alternative: fix typo in macro name 2021-06-10 20:35:05 -07:00
alternative.h riscv: sifive: Add SiFive alternative ports 2021-04-26 08:24:56 -07:00
asm-offsets.h
asm-prototypes.h riscv: traps: Fix no prototype warnings 2021-03-09 20:45:51 -08:00
asm.h riscv: Introduce alternative mechanism to apply errata solution 2021-04-26 08:24:55 -07:00
atomic.h locking/atomic: Move ATOMIC_INIT into linux/types.h 2020-07-29 16:14:18 +02:00
barrier.h RISC-V: Upgrade smp_mb__after_spinlock() to iorw,iorw 2020-07-17 09:28:35 -07:00
bitops.h RISC-V patches for v5.2-rc6 2019-06-17 10:34:03 -07:00
bug.h riscv: Add dump stack in show_regs 2021-01-14 15:09:11 -08:00
cache.h riscv: add nommu support 2019-11-17 15:17:39 -08:00
cacheflush.h mm: rename flush_icache_user_range to flush_icache_user_page 2020-06-08 11:05:58 -07:00
cacheinfo.h riscv: Add cache information in AUX vector 2020-09-15 18:46:08 -07:00
clint.h RISC-V: Resurrect the MMIO timer implementation for M-mode systems 2020-09-19 13:21:11 -07:00
clocksource.h riscv: use vDSO common flow to reduce the latency of the time-related functions 2020-06-10 19:47:16 -07:00
cmpxchg.h riscv/atomic: Fix sign extension for RV64I 2020-06-12 12:07:58 -07:00
cpu_ops.h RISC-V: Support cpu hotplug 2020-03-31 11:28:30 -07:00
csr.h riscv: Introduce alternative mechanism to apply errata solution 2021-04-26 08:24:55 -07:00
current.h RISC-V: Stop relying on GCC's register allocator's hueristics 2020-03-03 10:28:13 -08:00
delay.h treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 286 2019-06-05 17:36:37 +02:00
efi.h efi: stub: get rid of efi_get_max_fdt_addr() 2020-12-09 08:37:27 +01:00
elf.h RISC-V: Add kdump support 2021-04-26 08:25:23 -07:00
errata_list.h riscv: sifive: Apply errata "cip-1200" patch 2021-04-26 08:24:58 -07:00
fence.h riscv/spinlock: Strengthen implementations with fences 2018-04-02 19:59:43 -07:00
fixmap.h RISC-V: Add early ioremap support 2020-10-02 14:31:03 -07:00
ftrace.h riscv: Workaround mcount name prior to clang-13 2021-04-26 08:25:01 -07:00
futex.h futex: arch_futex_atomic_op_inuser() calling conventions change 2020-03-27 23:58:51 -04:00
gdb_xml.h riscv: Avoid kgdb.h including gdb_xml.h to solve unused-const-variable warning 2020-07-09 20:12:28 -07:00
hugetlb.h mm/hugetlb: define a generic fallback for arch_clear_hugepage_flags() 2020-06-03 20:09:46 -07:00
hwcap.h RISC-V: Add bitmap reprensenting ISA features common across CPUs 2020-05-04 14:08:59 -07:00
image.h RISC-V: Typo fixes in image header and documentation. 2019-12-19 09:32:45 -07:00
io.h RISC-V: Add early ioremap support 2020-10-02 14:31:03 -07:00
irq_work.h riscv: Support irq_work via self IPIs 2020-07-30 11:37:33 -07:00
irq.h riscv: irq: Fix no prototype warning 2021-03-09 20:46:00 -08:00
irqflags.h riscv: abstract out CSR names for supervisor vs machine mode 2019-11-05 09:20:42 -08:00
jump_label.h riscv: Add jump-label implementation 2020-07-30 11:37:43 -07:00
kasan.h riscv: Improve kasan definitions 2021-02-22 18:44:53 -08:00
Kbuild local64.h: make <asm/local64.h> mandatory 2020-12-29 15:36:49 -08:00
kdebug.h riscv: Add KGDB support 2020-05-18 11:38:10 -07:00
kexec.h riscv: kexec: Fix W=1 build warnings 2021-05-22 22:05:30 -07:00
kgdb.h riscv: Avoid kgdb.h including gdb_xml.h to solve unused-const-variable warning 2020-07-09 20:12:28 -07:00
kprobes.h riscv: Add kprobes supported 2021-01-14 15:09:06 -08:00
linkage.h treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 286 2019-06-05 17:36:37 +02:00
mmio.h riscv: Use generic pgprot_* macros from <linux/pgtable.h> 2020-07-30 11:37:46 -07:00
mmiowb.h riscv: mmiowb: Fix implicit declaration of function 'smp_processor_id' 2020-05-13 17:11:46 -07:00
mmu_context.h RISC-V: Implement ASID allocator 2021-02-18 23:18:06 -08:00
mmu.h RISC-V: Implement ASID allocator 2021-02-18 23:18:06 -08:00
mmzone.h riscv: Add numa support for riscv64 platform 2021-01-14 15:08:58 -08:00
module.h arch: split MODULE_ARCH_VERMAGIC definitions out to <asm/vermagic.h> 2020-04-23 10:50:26 +09:00
module.lds.h kbuild: preprocess module linker script 2020-09-25 00:36:41 +09:00
numa.h riscv: Add numa support for riscv64 platform 2021-01-14 15:08:58 -08:00
page.h riscv: Fix 32b kernel build with CONFIG_DEBUG_VIRTUAL=y 2021-05-01 08:53:31 -07:00
parse_asm.h riscv: Add SW single-step support for KDB 2020-05-18 11:38:12 -07:00
patch.h riscv: Remove the 'riscv_' prefix of function name 2020-05-18 11:38:13 -07:00
pci.h riscv: Add numa support for riscv64 platform 2021-01-14 15:08:58 -08:00
perf_event.h riscv: perf: RISCV_BASE_PMU should be independent 2020-05-12 16:21:46 -07:00
pgalloc.h asm-generic: pgalloc: provide generic pgd_free() 2020-08-07 11:33:26 -07:00
pgtable-32.h arch: pgtable: define MAX_POSSIBLE_PHYSMEM_BITS where needed 2020-11-16 16:57:18 +01:00
pgtable-64.h mm: consolidate pte_index() and pte_offset_*() definitions 2020-06-09 09:39:14 -07:00
pgtable-bits.h treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 286 2019-06-05 17:36:37 +02:00
pgtable.h riscv: Ensure BPF_JIT_REGION_START aligned with PMD size 2021-06-18 21:10:05 -07:00
probes.h riscv: Add kprobes supported 2021-01-14 15:09:06 -08:00
processor.h riscv: process: Fix no prototype for arch_dup_task_struct 2021-03-09 20:46:07 -08:00
ptdump.h riscv: support DEBUG_WX 2020-06-03 20:09:50 -07:00
ptrace.h riscv: ptrace: Fix no prototype warnings 2021-03-09 20:46:02 -08:00
sbi.h RISC-V Patches for the 5.13 Merge Window, Part 1 2021-05-06 09:24:18 -07:00
seccomp.h riscv: Enable seccomp architecture tracking 2020-11-20 11:16:35 -08:00
sections.h riscv: Introduce alternative mechanism to apply errata solution 2021-04-26 08:24:55 -07:00
set_memory.h riscv: Consistify protect_kernel_linear_mapping_text_rodata() use 2021-05-06 09:40:15 -07:00
smp.h riscv: Constify sbi_ipi_ops 2021-04-26 08:25:10 -07:00
soc.h riscv: Fix builtin DTB handling 2021-01-07 19:00:50 -08:00
sparsemem.h riscv: clean up the macro format in each header file 2019-11-12 12:04:52 -08:00
spinlock_types.h riscv: clean up the macro format in each header file 2019-11-12 12:04:52 -08:00
spinlock.h treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 286 2019-06-05 17:36:37 +02:00
stackprotector.h riscv: Enable per-task stack canaries 2021-01-14 15:09:10 -08:00
stacktrace.h riscv: Add dump stack in show_regs 2021-01-14 15:09:11 -08:00
string.h riscv: Add ARCH_HAS_FORTIFY_SOURCE 2021-03-09 18:18:31 -08:00
switch_to.h riscv: abstract out CSR names for supervisor vs machine mode 2019-11-05 09:20:42 -08:00
syscall.h riscv: Constify sys_call_table 2021-04-26 08:25:09 -07:00
thread_info.h riscv: Add uprobes supported 2021-01-14 15:09:08 -08:00
timex.h riscv: time: Fix no prototype for time_init 2021-03-09 20:46:03 -08:00
tlb.h treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 286 2019-06-05 17:36:37 +02:00
tlbflush.h riscv: sifive: Apply errata "cip-1200" patch 2021-04-26 08:24:58 -07:00
uaccess.h Merge branch 'work.misc' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs 2021-05-02 09:14:01 -07:00
unistd.h treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 286 2019-06-05 17:36:37 +02:00
uprobes.h riscv: Add uprobes supported 2021-01-14 15:09:08 -08:00
vdso.h riscv: Fixup CONFIG_GENERIC_TIME_VSYSCALL 2021-01-12 20:34:44 -08:00
vendorid_list.h riscv: Introduce alternative mechanism to apply errata solution 2021-04-26 08:24:55 -07:00
vermagic.h arch: split MODULE_ARCH_VERMAGIC definitions out to <asm/vermagic.h> 2020-04-23 10:50:26 +09:00
vmalloc.h mm/vmalloc: Add empty <asm/vmalloc.h> headers and use them from <linux/vmalloc.h> 2019-12-10 10:12:55 +01:00
word-at-a-time.h treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 286 2019-06-05 17:36:37 +02:00