On 22/10/21 21:27, Yang Zhong wrote:
+
+ for (j = 0; j < num; j++) {
+ epc = pcms->sgx_epc.sections[j];
+ hostmem = MEMORY_BACKEND(epc->hostmem);
+ fd = memory_region_get_fd(host_memory_backend_get_memory(hostmem));
+
+ failures = ioctl(fd, SGX_IOC_VEPC_REMOVE_ALL);
+ if (failures < 0) {
+ return failures;
+ } else if (failures > 0) {
+ /* Remove SECS pages */
+ sleep(1);
+ failures_1 = ioctl(fd, SGX_IOC_VEPC_REMOVE_ALL);
+ }
+
+ /*
+ * The host or guest can support 8 EPC sections, use the
+ * corresponding bit to show each section removal status.
+ */
+ if (failures_1) {
+ set_bit(j, &ret);
+ }
+ }
This sleep is not necessary, just do two tries on all the regions. So
something like
int failures;
/*
* The second pass is needed to remove SECS pages that could not
* be removed during the first.
*/
for (i = 0; i < 2; i++) {
failures = 0;
for (j = 0; j < pcms->sgx_epc.nr_sections; j++) {
epc = pcms->sgx_epc.sections[j];
hostmem = MEMORY_BACKEND(epc->hostmem);
fd =
memory_region_get_fd(host_memory_backend_get_memory(hostmem));
r = ioctl(fd, SGX_IOC_VEPC_REMOVE_ALL);
if (r < 0) {
return r;
}
if (r > 0) {
/* SECS pages remain */
failures++;
if (pass == 1) {
error_report("cannot reset vEPC section %d\n", j);
}
}
}
if (!failures) {
return 0;
}
}
return failures;
is enough, without any need to do further retries.
Paolo