lkml.org 
[lkml]   [2018]   [Mar]   [5]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[RFC, PATCH 21/22] x86/mm: Introduce page_keyid() and page_encrypted()
Date
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.shutemov@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
\
 
 \ /
  Last update: 2018-03-05 17:27    [W:0.372 / U:0.396 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site