[intel-sgx-kernel-dev,v2] intel_sgx: store va_offset in upper bits of page flags
diff mbox

Message ID 1492710084-19371-1-git-send-email-sean.j.christopherson@intel.com
State New
Headers show

Commit Message

Sean Christopherson April 20, 2017, 5:41 p.m. UTC
Signed-off-by: Sean Christopherson <sean.j.christopherson@intel.com>
---
 drivers/platform/x86/intel_sgx/sgx.h            | 17 ++++++++++++++++-
 drivers/platform/x86/intel_sgx/sgx_ioctl.c      |  4 ++--
 drivers/platform/x86/intel_sgx/sgx_page_cache.c |  2 +-
 drivers/platform/x86/intel_sgx/sgx_util.c       |  2 +-
 4 files changed, 20 insertions(+), 5 deletions(-)

Patch
diff mbox

diff --git a/drivers/platform/x86/intel_sgx/sgx.h b/drivers/platform/x86/intel_sgx/sgx.h
index e59ff01..430b5f2 100644
--- a/drivers/platform/x86/intel_sgx/sgx.h
+++ b/drivers/platform/x86/intel_sgx/sgx.h
@@ -101,6 +101,9 @@  static inline void sgx_free_va_slot(struct sgx_va_page *page,
 enum sgx_encl_page_flags {
 	SGX_ENCL_PAGE_TCS	= BIT(0),
 	SGX_ENCL_PAGE_RESERVED	= BIT(1),
+
+	SGX_ENCL_PAGE_VA_OFFSET_SHIFT	= 20,
+	SGX_ENCL_PAGE_VA_OFFSET_MASK	= GENMASK(31, 20),
 };
 
 struct sgx_encl_page {
@@ -109,9 +112,21 @@  struct sgx_encl_page {
 	struct sgx_epc_page *epc_page;
 	struct list_head load_list;
 	struct sgx_va_page *va_page;
-	unsigned int va_offset;
 };
 
+static inline unsigned int sgx_va_offset(struct sgx_encl_page *page)
+{
+	unsigned int shifted = (page->flags & SGX_ENCL_PAGE_VA_OFFSET_MASK);
+	return (shifted >> SGX_ENCL_PAGE_VA_OFFSET_SHIFT);
+}
+
+static inline void sgx_set_va_offset(struct sgx_encl_page *page,
+				     unsigned int va_offset)
+{
+	page->flags = (page->flags & ~SGX_ENCL_PAGE_VA_OFFSET_MASK) |
+		      (va_offset << SGX_ENCL_PAGE_VA_OFFSET_SHIFT);
+}
+
 struct sgx_tgid_ctx {
 	struct pid *tgid;
 	struct kref refcount;
diff --git a/drivers/platform/x86/intel_sgx/sgx_ioctl.c b/drivers/platform/x86/intel_sgx/sgx_ioctl.c
index ba7c0d2..bca33f5 100644
--- a/drivers/platform/x86/intel_sgx/sgx_ioctl.c
+++ b/drivers/platform/x86/intel_sgx/sgx_ioctl.c
@@ -439,7 +439,7 @@  static int sgx_init_page(struct sgx_encl *encl,
 	}
 
 	entry->va_page = va_page;
-	entry->va_offset = va_offset;
+	sgx_set_va_offset(entry, va_offset);
 	entry->addr = addr;
 
 	return 0;
@@ -753,7 +753,7 @@  static int __encl_add_page(struct sgx_encl *encl,
 	if (ret) {
 		kfree(req);
 		sgx_free_va_slot(encl_page->va_page,
-				 encl_page->va_offset);
+				 sgx_va_offset(encl_page));
 	}
 
 	mutex_unlock(&encl->lock);
diff --git a/drivers/platform/x86/intel_sgx/sgx_page_cache.c b/drivers/platform/x86/intel_sgx/sgx_page_cache.c
index 59a67cb..47a6221 100644
--- a/drivers/platform/x86/intel_sgx/sgx_page_cache.c
+++ b/drivers/platform/x86/intel_sgx/sgx_page_cache.c
@@ -290,7 +290,7 @@  static int __sgx_ewb(struct sgx_encl *encl,
 	pginfo.linaddr = 0;
 	pginfo.secs = 0;
 	ret = __ewb(&pginfo, epc,
-		    (void *)((unsigned long)va + encl_page->va_offset));
+		    (void *)((unsigned long)va + sgx_va_offset(encl_page)));
 	kunmap_atomic((void *)(unsigned long)(pginfo.pcmd - pcmd_offset));
 	kunmap_atomic((void *)(unsigned long)pginfo.srcpge);
 
diff --git a/drivers/platform/x86/intel_sgx/sgx_util.c b/drivers/platform/x86/intel_sgx/sgx_util.c
index 1e9fa18..9cb7dd9 100644
--- a/drivers/platform/x86/intel_sgx/sgx_util.c
+++ b/drivers/platform/x86/intel_sgx/sgx_util.c
@@ -226,7 +226,7 @@  static int sgx_eldu(struct sgx_encl *encl,
 	ret = __eldu((unsigned long)&pginfo,
 		     (unsigned long)epc_ptr,
 		     (unsigned long)va_ptr +
-		     encl_page->va_offset);
+		     sgx_va_offset(encl_page));
 	if (ret) {
 		sgx_err(encl, "ELDU returned %d\n", ret);
 		ret = -EFAULT;