Skip to content

Commit fd5128e

Browse files
bonzinihansendc
authored andcommitted
x86/sgx/virt: extract sgx_vepc_remove_page
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 <[email protected]> Reviewed-by: Dave Hansen <[email protected]> Signed-off-by: Paolo Bonzini <[email protected]> Signed-off-by: Dave Hansen <[email protected]> Link: https://lkml.kernel.org/r/[email protected]
1 parent 519d819 commit fd5128e

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

arch/x86/kernel/cpu/sgx/virt.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -111,10 +111,8 @@ static int sgx_vepc_mmap(struct file *file, struct vm_area_struct *vma)
111111
return 0;
112112
}
113113

114-
static int sgx_vepc_free_page(struct sgx_epc_page *epc_page)
114+
static int sgx_vepc_remove_page(struct sgx_epc_page *epc_page)
115115
{
116-
int ret;
117-
118116
/*
119117
* Take a previously guest-owned EPC page and return it to the
120118
* general EPC page pool.
@@ -124,7 +122,12 @@ static int sgx_vepc_free_page(struct sgx_epc_page *epc_page)
124122
* case that a guest properly EREMOVE'd this page, a superfluous
125123
* EREMOVE is harmless.
126124
*/
127-
ret = __eremove(sgx_get_epc_virt_addr(epc_page));
125+
return __eremove(sgx_get_epc_virt_addr(epc_page));
126+
}
127+
128+
static int sgx_vepc_free_page(struct sgx_epc_page *epc_page)
129+
{
130+
int ret = sgx_vepc_remove_page(epc_page);
128131
if (ret) {
129132
/*
130133
* Only SGX_CHILD_PRESENT is expected, which is because of
@@ -144,7 +147,6 @@ static int sgx_vepc_free_page(struct sgx_epc_page *epc_page)
144147
}
145148

146149
sgx_free_epc_page(epc_page);
147-
148150
return 0;
149151
}
150152

0 commit comments

Comments
 (0)