Skip to content

Commit bdec22e

Browse files
committed
riscv: add option RISCV_RELAXED_ALLOC_RWX
1 parent d6c0581 commit bdec22e

File tree

5 files changed

+22
-4
lines changed

5 files changed

+22
-4
lines changed

arch/riscv/Kconfig

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ config RISCV
3333
select ARCH_HAS_PTE_SPECIAL
3434
select ARCH_HAS_SET_DIRECT_MAP if MMU
3535
select ARCH_HAS_SET_MEMORY if MMU
36-
select ARCH_HAS_STRICT_KERNEL_RWX if MMU && !XIP_KERNEL
37-
select ARCH_HAS_STRICT_MODULE_RWX if MMU && !XIP_KERNEL
36+
select ARCH_HAS_STRICT_KERNEL_RWX if MMU && !RISCV_RELAXED_RWX
37+
select ARCH_HAS_STRICT_MODULE_RWX if MMU && !RISCV_RELAXED_RWX
3838
select ARCH_HAS_TICK_BROADCAST if GENERIC_CLOCKEVENTS_BROADCAST
3939
select ARCH_HAS_UBSAN_SANITIZE_ALL
4040
select ARCH_OPTIONAL_KERNEL_RWX if ARCH_HAS_STRICT_KERNEL_RWX
@@ -529,13 +529,23 @@ config PHYS_RAM_BASE
529529
explicitly specified to run early relocations of read-write data
530530
from flash to RAM.
531531

532+
config RISCV_RELAXED_RWX
533+
bool
534+
default n
535+
536+
config RISCV_RELAXED_ALLOC_RWX
537+
bool
538+
select RISCV_RELAXED_RWX
539+
default n
540+
532541
config XIP_KERNEL
533542
bool "Kernel Execute-In-Place from ROM"
534543
depends on MMU && SPARSEMEM
535544
# This prevents XIP from being enabled by all{yes,mod}config, which
536545
# fail to build since XIP doesn't support large kernels.
537546
depends on !COMPILE_TEST
538547
select PHYS_RAM_BASE_FIXED
548+
select RISCV_RELAXED_RWX
539549
help
540550
Execute-In-Place allows the kernel to run from non-volatile storage
541551
directly addressable by the CPU, such as NOR flash. This saves RAM

arch/riscv/Kconfig.socs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ config ARCH_SUNXI
8181
select RISCV_SUNXI
8282
select RISCV_XUANTIE
8383
select RISCV_FIXMAP_DTB
84+
select RISCV_RELAXED_ALLOC_RWX
8485
help
8586
This enables support for SUNXI SoC platform hardware.
8687

arch/riscv/include/asm/pgtable.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,11 @@
150150
| _PAGE_EXEC)
151151
#define PAGE_KERNEL_SO __pgprot((_PAGE_KERNEL | _PAGE_SO) & \
152152
~(_PAGE_CACHE | _PAGE_BUF))
153+
#ifdef CONFIG_RISCV_RELAXED_ALLOC_RWX
154+
#define PAGE_KERNEL_MAY_EXEC PAGE_KERNEL_EXEC
155+
#else
156+
#define PAGE_KERNEL_MAY_EXEC PAGE_KERNEL
157+
#endif
153158

154159
#define PAGE_TABLE __pgprot(_PAGE_TABLE)
155160

arch/riscv/kernel/module.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,7 @@ void *module_alloc(unsigned long size)
423423
{
424424
return __vmalloc_node_range(size, 1, MODULES_VADDR,
425425
MODULES_END, GFP_KERNEL,
426-
PAGE_KERNEL, 0, NUMA_NO_NODE,
426+
PAGE_KERNEL_MAY_EXEC, 0, NUMA_NO_NODE,
427427
__builtin_return_address(0));
428428
}
429429
#endif

arch/riscv/net/bpf_jit_core.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,9 @@ struct bpf_prog *bpf_int_jit_compile(struct bpf_prog *prog)
153153
bpf_flush_icache(jit_data->header, ctx->insns + ctx->ninsns);
154154

155155
if (!prog->is_func || extra_pass) {
156+
#ifndef CONFIG_RISCV_RELAXED_ALLOC_RWX
156157
bpf_jit_binary_lock_ro(jit_data->header);
158+
#endif
157159
out_offset:
158160
kfree(ctx->offset);
159161
kfree(jit_data);
@@ -176,7 +178,7 @@ void *bpf_jit_alloc_exec(unsigned long size)
176178
{
177179
return __vmalloc_node_range(size, PAGE_SIZE, BPF_JIT_REGION_START,
178180
BPF_JIT_REGION_END, GFP_KERNEL,
179-
PAGE_KERNEL, 0, NUMA_NO_NODE,
181+
PAGE_KERNEL_MAY_EXEC, 0, NUMA_NO_NODE,
180182
__builtin_return_address(0));
181183
}
182184

0 commit comments

Comments
 (0)