On Tue, 12 Jan 2021 13:45:24 -0800 Sean Christopherson wrote: > On Tue, Jan 12, 2021, Kai Huang wrote: > > On Tue, 12 Jan 2021 00:38:40 +0200 Jarkko Sakkinen wrote: > > > On Wed, 2021-01-06 at 14:55 +1300, Kai Huang wrote: > > > > From: Sean Christopherson <sean.j.christopherson@xxxxxxxxx> > > > > > > > > SGX virtualization requires to allocate "raw" EPC and use it as virtual > > > > EPC for SGX guest. Unlike EPC used by SGX driver, virtual EPC doesn't > > > > track how EPC pages are used in VM, e.g. (de)construction of enclaves, > > > > so it cannot guarantee EREMOVE success, e.g. it doesn't have a priori > > > > knowledge of which pages are SECS with non-zero child counts. > > > > > > > > Split sgx_free_page() into two parts so that the "add to free list" > > > > part can be used by virtual EPC without having to modify the EREMOVE > > > > logic in sgx_free_page(). > > > > > > > > Signed-off-by: Sean Christopherson <sean.j.christopherson@xxxxxxxxx> > > > > Signed-off-by: Kai Huang <kai.huang@xxxxxxxxx> > > > > > > I have a better idea with the same outcome for KVM. > > > > > > https://lore.kernel.org/linux-sgx/20210111223610.62261-1-jarkko@xxxxxxxxxx/T/#t > > > > I agree with your patch this one can be replaced. I'll include your patch in > > next version, and once it is upstreamed, it can be removed in my series. > > > > Sean, please let me know if you have objection. > > 6 of one, half dozen of the other. I liked not having to modify the existing > call sites, but it's your code. > > Though on that topic, this snippet is wrong: > > @@ -431,7 +443,8 @@ void sgx_encl_release(struct kref *ref) > va_page = list_first_entry(&encl->va_pages, struct sgx_va_page, > list); > list_del(&va_page->list); > - sgx_free_epc_page(va_page->epc_page); > + sgx_reset_epc_page(entry->epc_page); > + sgx_free_epc_page(entry->epc_page); > > s/entry/va_page in the new code. > > P.S. I apparently hadn't been subscribed linux-sgx and so didn't see those > patches. I'm now subscribed and can chime-in as needed. Thanks. I also have replied to Jarkko's v2 patch, and I think you can see it now. I think if Jarkko's patch is eventually merged to upstream, we can drop this patch. So please help to comment if Jarkko's patch is reasonable, since I don't have history with SGX driver and cannot immediately tell if it is reasonable.