qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH v2 5/5] sgx: Reset the vEPC regions during VM reboot


From: Paolo Bonzini
Subject: Re: [PATCH v2 5/5] sgx: Reset the vEPC regions during VM reboot
Date: Fri, 22 Oct 2021 23:46:30 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.1.0

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




reply via email to

[Prev in Thread] Current Thread [Next in Thread]