@@ -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;
@@ -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);
@@ -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);
@@ -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;
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(-)