secretmem.h 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
  2. #ifndef _LINUX_SECRETMEM_H
  3. #define _LINUX_SECRETMEM_H
  4. #ifdef CONFIG_SECRETMEM
  5. extern const struct address_space_operations secretmem_aops;
  6. static inline bool page_is_secretmem(struct page *page)
  7. {
  8. struct address_space *mapping;
  9. /*
  10. * Using page_mapping() is quite slow because of the actual call
  11. * instruction and repeated compound_head(page) inside the
  12. * page_mapping() function.
  13. * We know that secretmem pages are not compound and LRU so we can
  14. * save a couple of cycles here.
  15. */
  16. if (PageCompound(page) || !PageLRU(page))
  17. return false;
  18. mapping = (struct address_space *)
  19. ((unsigned long)page->mapping & ~PAGE_MAPPING_FLAGS);
  20. if (!mapping || mapping != page->mapping)
  21. return false;
  22. return mapping->a_ops == &secretmem_aops;
  23. }
  24. bool vma_is_secretmem(struct vm_area_struct *vma);
  25. bool secretmem_active(void);
  26. #else
  27. static inline bool vma_is_secretmem(struct vm_area_struct *vma)
  28. {
  29. return false;
  30. }
  31. static inline bool page_is_secretmem(struct page *page)
  32. {
  33. return false;
  34. }
  35. static inline bool secretmem_active(void)
  36. {
  37. return false;
  38. }
  39. #endif /* CONFIG_SECRETMEM */
  40. #endif /* _LINUX_SECRETMEM_H */