Skip to content

Commit 8d91b09

Browse files
geertupalmer-dabbelt
authored andcommitted
riscv: Consistify protect_kernel_linear_mapping_text_rodata() use
The various uses of protect_kernel_linear_mapping_text_rodata() are not consistent: - Its definition depends on "64BIT && !XIP_KERNEL", - Its forward declaration depends on MMU, - Its single caller depends on "STRICT_KERNEL_RWX && 64BIT && MMU && !XIP_KERNEL". Fix this by settling on the dependencies of the caller, which can be simplified as STRICT_KERNEL_RWX depends on "MMU && !XIP_KERNEL". Provide a dummy definition, as the caller is protected by "IS_ENABLED(CONFIG_STRICT_KERNEL_RWX)" instead of "#ifdef CONFIG_STRICT_KERNEL_RWX". Signed-off-by: Geert Uytterhoeven <[email protected]> Tested-by: Alexandre Ghiti <[email protected]> Signed-off-by: Palmer Dabbelt <[email protected]>
1 parent 0e0d499 commit 8d91b09

File tree

3 files changed

+7
-4
lines changed

3 files changed

+7
-4
lines changed

arch/riscv/include/asm/set_memory.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ int set_memory_x(unsigned long addr, int numpages);
1717
int set_memory_nx(unsigned long addr, int numpages);
1818
int set_memory_rw_nx(unsigned long addr, int numpages);
1919
void protect_kernel_text_data(void);
20-
void protect_kernel_linear_mapping_text_rodata(void);
2120
#else
2221
static inline int set_memory_ro(unsigned long addr, int numpages) { return 0; }
2322
static inline int set_memory_rw(unsigned long addr, int numpages) { return 0; }
@@ -27,6 +26,12 @@ static inline void protect_kernel_text_data(void) {}
2726
static inline int set_memory_rw_nx(unsigned long addr, int numpages) { return 0; }
2827
#endif
2928

29+
#if defined(CONFIG_64BIT) && defined(CONFIG_STRICT_KERNEL_RWX)
30+
void protect_kernel_linear_mapping_text_rodata(void);
31+
#else
32+
static inline void protect_kernel_linear_mapping_text_rodata(void) {}
33+
#endif
34+
3035
int set_direct_map_invalid_noflush(struct page *page);
3136
int set_direct_map_default_noflush(struct page *page);
3237
bool kernel_page_present(struct page *page);

arch/riscv/kernel/setup.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -293,9 +293,7 @@ void __init setup_arch(char **cmdline_p)
293293

294294
if (IS_ENABLED(CONFIG_STRICT_KERNEL_RWX)) {
295295
protect_kernel_text_data();
296-
#if defined(CONFIG_64BIT) && defined(CONFIG_MMU) && !defined(CONFIG_XIP_KERNEL)
297296
protect_kernel_linear_mapping_text_rodata();
298-
#endif
299297
}
300298

301299
#ifdef CONFIG_SWIOTLB

arch/riscv/mm/init.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -645,7 +645,7 @@ asmlinkage void __init setup_vm(uintptr_t dtb_pa)
645645
#endif
646646
}
647647

648-
#if defined(CONFIG_64BIT) && !defined(CONFIG_XIP_KERNEL)
648+
#if defined(CONFIG_64BIT) && defined(CONFIG_STRICT_KERNEL_RWX)
649649
void protect_kernel_linear_mapping_text_rodata(void)
650650
{
651651
unsigned long text_start = (unsigned long)lm_alias(_start);

0 commit comments

Comments
 (0)