Skip to content

Commit

Permalink
x86/sgx/virt: extract sgx_vepc_remove_page
Browse files Browse the repository at this point in the history
For bare-metal SGX on real hardware, the hardware provides guarantees
SGX state at reboot.  For instance, all pages start out uninitialized.
The vepc driver provides a similar guarantee today for freshly-opened
vepc instances, but guests such as Windows expect all pages to be in
uninitialized state on startup, including after every guest reboot.

One way to do this is to simply close and reopen the /dev/sgx_vepc file
descriptor and re-mmap the virtual EPC.  However, this is problematic
because it prevents sandboxing the userspace (for example forbidding
open() after the guest starts; this is doable with heavy use of SCM_RIGHTS
file descriptor passing).

In order to implement this, we will need a ioctl that performs
EREMOVE on all pages mapped by a /dev/sgx_vepc file descriptor:
other possibilities, such as closing and reopening the device,
are racy.

Start the implementation by creating a separate function with just
the __eremove wrapper.

Reviewed-by: Jarkko Sakkinen <jarkko@kernel.org>
Reviewed-by: Dave Hansen <dave.hansen@linux.intel.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Dave Hansen <dave.hansen@linux.intel.com>
Link: https://lkml.kernel.org/r/20211021201155.1523989-2-pbonzini@redhat.com
  • Loading branch information
Paolo Bonzini authored and Dave Hansen committed Oct 22, 2021
1 parent 519d819 commit fd5128e
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions arch/x86/kernel/cpu/sgx/virt.c
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,8 @@ static int sgx_vepc_mmap(struct file *file, struct vm_area_struct *vma)
return 0;
}

static int sgx_vepc_free_page(struct sgx_epc_page *epc_page)
static int sgx_vepc_remove_page(struct sgx_epc_page *epc_page)
{
int ret;

/*
* Take a previously guest-owned EPC page and return it to the
* general EPC page pool.
Expand All @@ -124,7 +122,12 @@ static int sgx_vepc_free_page(struct sgx_epc_page *epc_page)
* case that a guest properly EREMOVE'd this page, a superfluous
* EREMOVE is harmless.
*/
ret = __eremove(sgx_get_epc_virt_addr(epc_page));
return __eremove(sgx_get_epc_virt_addr(epc_page));
}

static int sgx_vepc_free_page(struct sgx_epc_page *epc_page)
{
int ret = sgx_vepc_remove_page(epc_page);
if (ret) {
/*
* Only SGX_CHILD_PRESENT is expected, which is because of
Expand All @@ -144,7 +147,6 @@ static int sgx_vepc_free_page(struct sgx_epc_page *epc_page)
}

sgx_free_epc_page(epc_page);

return 0;
}

Expand Down

0 comments on commit fd5128e

Please sign in to comment.