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: Yang Zhong
Subject: Re: [PATCH v2 5/5] sgx: Reset the vEPC regions during VM reboot
Date: Tue, 26 Oct 2021 16:15:06 +0800
User-agent: Mutt/1.5.21 (2010-09-15)

On Fri, Oct 22, 2021 at 11:46:30PM +0200, Paolo Bonzini wrote:
> 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.
>

  Thanks Paolo, i will update it in the next version. Please also
  help review other patches, thanks! 

  Yang

> Paolo



reply via email to

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