@@ -544,6 +544,10 @@ int sgx_unmark_page_reclaimable(struct sgx_epc_page *page)
* Finally, wake up ksgxd when the number of pages goes below the watermark
* before returning back to the caller.
*
+ * When an EPC page is assigned to KVM guest, repurpose the 'encl_owner' field
+ * as the virtual address of virtual EPC page, since it is useless in such
+ * scenario, so 'owner' is assigned to 'vepc_vaddr'.
+ *
* Return:
* an EPC page,
* -errno on error
@@ -28,12 +28,18 @@
/* Pages on free list */
#define SGX_EPC_PAGE_IS_FREE BIT(1)
+/* Pages allocated for KVM guest */
+#define SGX_EPC_PAGE_KVM_GUEST BIT(2)
struct sgx_epc_page {
unsigned int section;
u16 flags;
u16 poison;
- struct sgx_encl_page *encl_owner;
+ union {
+ struct sgx_encl_page *encl_owner;
+ /* Use when SGX_EPC_PAGE_KVM_GUEST set in ->flags: */
+ void __user *vepc_vaddr;
+ };
struct list_head list;
};
@@ -46,10 +46,12 @@ static int __sgx_vepc_fault(struct sgx_vepc *vepc,
if (epc_page)
return 0;
- epc_page = sgx_alloc_epc_page(vepc, false);
+ epc_page = sgx_alloc_epc_page((void *)addr, false);
if (IS_ERR(epc_page))
return PTR_ERR(epc_page);
+ epc_page->flags |= SGX_EPC_PAGE_KVM_GUEST;
+
ret = xa_err(xa_store(&vepc->page_array, index, epc_page, GFP_KERNEL));
if (ret)
goto err_free;