kfence.h 865 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * PA-RISC KFENCE support.
  4. *
  5. * Copyright (C) 2021, Helge Deller <[email protected]>
  6. */
  7. #ifndef _ASM_PARISC_KFENCE_H
  8. #define _ASM_PARISC_KFENCE_H
  9. #include <linux/kfence.h>
  10. #include <asm/pgtable.h>
  11. #include <asm/tlbflush.h>
  12. static inline bool arch_kfence_init_pool(void)
  13. {
  14. return true;
  15. }
  16. /* Protect the given page and flush TLB. */
  17. static inline bool kfence_protect_page(unsigned long addr, bool protect)
  18. {
  19. pte_t *pte = virt_to_kpte(addr);
  20. if (WARN_ON(!pte))
  21. return false;
  22. /*
  23. * We need to avoid IPIs, as we may get KFENCE allocations or faults
  24. * with interrupts disabled.
  25. */
  26. if (protect)
  27. set_pte(pte, __pte(pte_val(*pte) & ~_PAGE_PRESENT));
  28. else
  29. set_pte(pte, __pte(pte_val(*pte) | _PAGE_PRESENT));
  30. flush_tlb_kernel_range(addr, addr + PAGE_SIZE);
  31. return true;
  32. }
  33. #endif /* _ASM_PARISC_KFENCE_H */