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