Skip to content

Commit 395a21f

Browse files
zongboxpalmer-dabbelt
authored andcommitted
riscv: add ARCH_HAS_SET_DIRECT_MAP support
Add set_direct_map_*() functions for setting the direct map alias for the page to its default permissions and to an invalid state that cannot be cached in a TLB. (See d253ca0 ("x86/mm/cpa: Add set_direct_map_*() functions")) Add a similar implementation for RISC-V. Signed-off-by: Zong Li <[email protected]> Signed-off-by: Palmer Dabbelt <[email protected]>
1 parent d3ab332 commit 395a21f

File tree

3 files changed

+28
-0
lines changed

3 files changed

+28
-0
lines changed

arch/riscv/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ config RISCV
5959
select HAVE_EBPF_JIT if 64BIT
6060
select EDAC_SUPPORT
6161
select ARCH_HAS_GIGANTIC_PAGE
62+
select ARCH_HAS_SET_DIRECT_MAP
6263
select ARCH_HAS_SET_MEMORY
6364
select ARCH_WANT_HUGE_PMD_SHARE if 64BIT
6465
select SPARSEMEM_STATIC if 32BIT

arch/riscv/include/asm/set_memory.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,7 @@ static inline int set_memory_x(unsigned long addr, int numpages) { return 0; }
2121
static inline int set_memory_nx(unsigned long addr, int numpages) { return 0; }
2222
#endif
2323

24+
int set_direct_map_invalid_noflush(struct page *page);
25+
int set_direct_map_default_noflush(struct page *page);
26+
2427
#endif /* _ASM_RISCV_SET_MEMORY_H */

arch/riscv/mm/pageattr.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,3 +148,27 @@ int set_memory_nx(unsigned long addr, int numpages)
148148
{
149149
return __set_memory(addr, numpages, __pgprot(0), __pgprot(_PAGE_EXEC));
150150
}
151+
152+
int set_direct_map_invalid_noflush(struct page *page)
153+
{
154+
unsigned long start = (unsigned long)page_address(page);
155+
unsigned long end = start + PAGE_SIZE;
156+
struct pageattr_masks masks = {
157+
.set_mask = __pgprot(0),
158+
.clear_mask = __pgprot(_PAGE_PRESENT)
159+
};
160+
161+
return walk_page_range(&init_mm, start, end, &pageattr_ops, &masks);
162+
}
163+
164+
int set_direct_map_default_noflush(struct page *page)
165+
{
166+
unsigned long start = (unsigned long)page_address(page);
167+
unsigned long end = start + PAGE_SIZE;
168+
struct pageattr_masks masks = {
169+
.set_mask = PAGE_KERNEL,
170+
.clear_mask = __pgprot(0)
171+
};
172+
173+
return walk_page_range(&init_mm, start, end, &pageattr_ops, &masks);
174+
}

0 commit comments

Comments
 (0)