The new helpers checks if page is encrypted and with which keyid. They use anon_vma get the information.
Signed-off-by: Kirill A. Shutemov <kirill.shute...@linux.intel.com> --- arch/x86/include/asm/mktme.h | 14 ++++++++++++++ arch/x86/mm/mktme.c | 17 +++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/arch/x86/include/asm/mktme.h b/arch/x86/include/asm/mktme.h index 56c7e9b14ab6..dd81fe167e25 100644 --- a/arch/x86/include/asm/mktme.h +++ b/arch/x86/include/asm/mktme.h @@ -33,10 +33,24 @@ bool anon_vma_encrypted(struct anon_vma *anon_vma); #define anon_vma_keyid anon_vma_keyid int anon_vma_keyid(struct anon_vma *anon_vma); + +int page_keyid(struct page *page); #else + #define mktme_keyid_mask ((phys_addr_t)0) #define mktme_nr_keyids 0 #define mktme_keyid_shift 0 + +static inline int page_keyid(struct page *page) +{ + return 0; +} #endif +static inline bool page_encrypted(struct page *page) +{ + /* All pages with non-zero KeyID are encrypted */ + return page_keyid(page) != 0; +} + #endif diff --git a/arch/x86/mm/mktme.c b/arch/x86/mm/mktme.c index 69172aabc07c..0ab795dfb1a4 100644 --- a/arch/x86/mm/mktme.c +++ b/arch/x86/mm/mktme.c @@ -39,6 +39,23 @@ int anon_vma_keyid(struct anon_vma *anon_vma) return anon_vma->arch_anon_vma.keyid; } +int page_keyid(struct page *page) +{ + struct anon_vma *anon_vma; + int keyid = 0; + + if (!PageAnon(page)) + return 0; + + anon_vma = page_get_anon_vma(page); + if (anon_vma) { + keyid = anon_vma_keyid(anon_vma); + put_anon_vma(anon_vma); + } + + return keyid; +} + void prep_encrypt_page(struct page *page, gfp_t gfp, unsigned int order) { void *v = page_to_virt(page); -- 2.16.1