Skip to content

Commit c10bc26

Browse files
AlexGhitipalmer-dabbelt
authored andcommitted
riscv: Introduce set_kernel_memory helper
This helper should be used for setting permissions to the kernel mapping as it takes pointers as arguments and then avoids explicit cast to unsigned long needed for the set_memory_* API. Suggested-by: Christoph Hellwig <[email protected]> Signed-off-by: Alexandre Ghiti <[email protected]> Reviewed-by: Anup Patel <[email protected]> Reviewed-by: Atish Patra <[email protected]> Reviewed-by: Jisheng Zhang <[email protected]> Signed-off-by: Palmer Dabbelt <[email protected]>
1 parent 7094e6a commit c10bc26

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

arch/riscv/include/asm/set_memory.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,29 @@ 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+
static __always_inline int set_kernel_memory(char *startp, char *endp,
21+
int (*set_memory)(unsigned long start,
22+
int num_pages))
23+
{
24+
unsigned long start = (unsigned long)startp;
25+
unsigned long end = (unsigned long)endp;
26+
int num_pages = PAGE_ALIGN(end - start) >> PAGE_SHIFT;
27+
28+
return set_memory(start, num_pages);
29+
}
2030
#else
2131
static inline int set_memory_ro(unsigned long addr, int numpages) { return 0; }
2232
static inline int set_memory_rw(unsigned long addr, int numpages) { return 0; }
2333
static inline int set_memory_x(unsigned long addr, int numpages) { return 0; }
2434
static inline int set_memory_nx(unsigned long addr, int numpages) { return 0; }
2535
static inline void protect_kernel_text_data(void) {}
2636
static inline int set_memory_rw_nx(unsigned long addr, int numpages) { return 0; }
37+
static inline int set_kernel_memory(char *startp, char *endp,
38+
int (*set_memory)(unsigned long start,
39+
int num_pages))
40+
{
41+
return 0;
42+
}
2743
#endif
2844

2945
#if defined(CONFIG_64BIT) && defined(CONFIG_STRICT_KERNEL_RWX)

0 commit comments

Comments
 (0)