qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Yang Zhong <yang.zhong@intel.com>
To: Paolo Bonzini <pbonzini@redhat.com>
Cc: yang.zhong@intel.com, philmd@redhat.com, jarkko@kernel.org,
	eblake@redhat.com, qemu-devel@nongnu.org
Subject: Re: [PATCH v2 5/5] sgx: Reset the vEPC regions during VM reboot
Date: Tue, 26 Oct 2021 16:15:06 +0800	[thread overview]
Message-ID: <20211026081506.GA11341@yangzhon-Virtual> (raw)
In-Reply-To: <6e04392e-e52b-2011-0d62-4a6c24628e7b@redhat.com>

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	other threads:[~2021-10-26  8:36 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-22 19:27 [PATCH v2 0/5] SGX NUMA support plus vepc reset Yang Zhong
2021-10-22 19:27 ` [PATCH v2 1/5] numa: Enable numa for SGX EPC sections Yang Zhong
2021-10-22 19:27 ` [PATCH v2 2/5] monitor: Support 'info numa' command Yang Zhong
2021-10-22 19:27 ` [PATCH v2 3/5] numa: Support SGX numa in the monitor and Libvirt interfaces Yang Zhong
2021-10-22 19:27 ` [PATCH v2 4/5] doc: Add the SGX numa description Yang Zhong
2021-10-22 19:27 ` [PATCH v2 5/5] sgx: Reset the vEPC regions during VM reboot Yang Zhong
2021-10-22 21:46   ` Paolo Bonzini
2021-10-26  8:15     ` Yang Zhong [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20211026081506.GA11341@yangzhon-Virtual \
    --to=yang.zhong@intel.com \
    --cc=eblake@redhat.com \
    --cc=jarkko@kernel.org \
    --cc=pbonzini@redhat.com \
    --cc=philmd@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).