kfence.h 925 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * powerpc KFENCE support.
  4. *
  5. * Copyright (C) 2020 CS GROUP France
  6. */
  7. #ifndef __ASM_POWERPC_KFENCE_H
  8. #define __ASM_POWERPC_KFENCE_H
  9. #include <linux/mm.h>
  10. #include <asm/pgtable.h>
  11. #ifdef CONFIG_PPC64_ELF_ABI_V1
  12. #define ARCH_FUNC_PREFIX "."
  13. #endif
  14. static inline bool arch_kfence_init_pool(void)
  15. {
  16. return true;
  17. }
  18. #ifdef CONFIG_PPC64
  19. static inline bool kfence_protect_page(unsigned long addr, bool protect)
  20. {
  21. struct page *page = virt_to_page(addr);
  22. __kernel_map_pages(page, 1, !protect);
  23. return true;
  24. }
  25. #else
  26. static inline bool kfence_protect_page(unsigned long addr, bool protect)
  27. {
  28. pte_t *kpte = virt_to_kpte(addr);
  29. if (protect) {
  30. pte_update(&init_mm, addr, kpte, _PAGE_PRESENT, 0, 0);
  31. flush_tlb_kernel_range(addr, addr + PAGE_SIZE);
  32. } else {
  33. pte_update(&init_mm, addr, kpte, 0, _PAGE_PRESENT, 0);
  34. }
  35. return true;
  36. }
  37. #endif
  38. #endif /* __ASM_POWERPC_KFENCE_H */