As very well explained in commit 20a004e7b0
("arm64: mm: Use
READ_ONCE/WRITE_ONCE when accessing page tables"), an architecture whose
page table walker can modify the PTE in parallel must use
READ_ONCE()/WRITE_ONCE() macro to avoid any compiler transformation.
So apply that to riscv which is such architecture.
Signed-off-by: Alexandre Ghiti <alexghiti@rivosinc.com>
Acked-by: Anup Patel <anup@brainfault.org>
Link: https://lore.kernel.org/r/20231213203001.179237-5-alexghiti@rivosinc.com
Signed-off-by: Palmer Dabbelt <palmer@rivosinc.com>
30 lines
629 B
C
30 lines
629 B
C
/* SPDX-License-Identifier: GPL-2.0 */
|
|
|
|
#ifndef _ASM_RISCV_KFENCE_H
|
|
#define _ASM_RISCV_KFENCE_H
|
|
|
|
#include <linux/kfence.h>
|
|
#include <linux/pfn.h>
|
|
#include <asm-generic/pgalloc.h>
|
|
#include <asm/pgtable.h>
|
|
|
|
static inline bool arch_kfence_init_pool(void)
|
|
{
|
|
return true;
|
|
}
|
|
|
|
static inline bool kfence_protect_page(unsigned long addr, bool protect)
|
|
{
|
|
pte_t *pte = virt_to_kpte(addr);
|
|
|
|
if (protect)
|
|
set_pte(pte, __pte(pte_val(ptep_get(pte)) & ~_PAGE_PRESENT));
|
|
else
|
|
set_pte(pte, __pte(pte_val(ptep_get(pte)) | _PAGE_PRESENT));
|
|
|
|
flush_tlb_kernel_range(addr, addr + PAGE_SIZE);
|
|
|
|
return true;
|
|
}
|
|
|
|
#endif /* _ASM_RISCV_KFENCE_H */
|