Re: [RFC PATCH v4 2/4] x86/sgx: Implement support for MADV_WILLNEED

Huang, Kai
2023-03-20T09:36:55Z

On Sun, 2023-03-19 at 15:26 +0200, jarkko@kernel.org wrote:
> On Tue, Mar 14, 2023 at 09:54:30AM -0500, Haitao Huang wrote:
> > On Thu, 09 Mar 2023 05:31:29 -0600, Huang, Kai <kai.huang@intel.com> wrote:
> > > >
> > > > Then in v29, PROT_NONE mapping was disallowed for encl_fd before pages
> > > > EADDed so user space has to mmap anonymously to reserve the range.The
> > > > intent was still not to allow mmap before pages EADDed (the !page check
> > > > was still there up to v38)
> > >
> > > Do you know the reason of disallowing PROT_NONE mapping against encl_fd?
> > >
> >
> > I think it was to allow user space to do anonymous mapping to reserve
> > address space for enclave.
> > Before this point, you have to use PROT_NONE to reserve with encl_fd. There
> > might be an issue with how #PF and EPC swapping was handled or the elegance
> > of those flows that motivated the move but I can't remember. ABI was not
> > fixed at that time so it was OK to change.
>
> Yes, this was done because enclave naturally aligned base address.
>
>

Sorry for being ignorant, but you can also get the aligned base address via
mmap() against encl_fd, correct? What is the fundamental difference between
mmap(MAP_ANONYMOUS) vs mmap(encl_fd)?