linux-sgx.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Haitao Huang" <haitao.huang@linux.intel.com>
To: "jarkko@kernel.org" <jarkko@kernel.org>,
	"Huang, Kai" <kai.huang@intel.com>
Cc: "linux-sgx@vger.kernel.org" <linux-sgx@vger.kernel.org>,
	"Chatre, Reinette" <reinette.chatre@intel.com>,
	"Dhanraj, Vijay" <vijay.dhanraj@intel.com>,
	"dave.hansen@linux.intel.com" <dave.hansen@linux.intel.com>
Subject: Re: [RFC PATCH v4 2/4] x86/sgx: Implement support for MADV_WILLNEED
Date: Wed, 07 Jun 2023 11:59:32 -0500	[thread overview]
Message-ID: <op.156hhiivwjvjmi@hhuan26-mobl.amr.corp.intel.com> (raw)
In-Reply-To: <5930de9d076d148ae572aa081c7dee8a5b696b61.camel@intel.com>

On Mon, 05 Jun 2023 23:11:59 -0500, Huang, Kai <kai.huang@intel.com> wrote:

> On Fri, 2023-05-26 at 19:32 -0500, Haitao Huang wrote:
>> Hi Kai, Jarkko and Dave
>>
>> On Thu, 09 Mar 2023 05:31:29 -0600, Huang, Kai <kai.huang@intel.com>  
>> wrote:
>> >
>> > So I am still a little bit confused about where does "SGX driver uses
>> > MAP_ANONYMOUS semantics for fd-based mmap()" come from.
>> >
>> > Anyway, we certainly don't want to break userspace.  However, IIUC,  
>> even
>> > from
>> > now on we change the driver to depend on userspace to pass the correct
>> > pgoff in
>> > mmap(), this won't break userspace, because old userspace which  
>> doesn't
>> > use
>> > fadvice() and pgoff actually doesn't matter.  For new userspace which
>> > uses
>> > fadvice(), it needs to pass the correct pgoff.
>> >
>> > I am not saying we should do this, but it doesn't seem we can break
>> > userspace?
>> >
>>
>> Sorry for delayed update but I thought about this more and likely to
>> propose a new EAUG ioctl for this and for enabling SGX-CET shadow stack
>> pages. But regardless, I'd like to wrap up this discussion to just  
>> clarify
>> this anonymous semantics design in documentation so people won't get
>> confused in future.
>>
>> I think we all agree to keep this semantics so no user space would need
>> specify 'offset' for mmap with enclave fd. And here is my proposed
>> documentation changes.
>>
>> --- a/Documentation/x86/sgx.rst
>> +++ b/Documentation/x86/sgx.rst
>> @@ -100,6 +100,23 @@ pages and establish enclave page permissions.
>>                  sgx_ioc_enclave_init
>>                  sgx_ioc_enclave_provision
>>
>> +Enclave memory mapping
>> +----------------------
>> +
>> +A file descriptor created from opening **/dev/sgx_enclave** represents  
>> an
>> +enclave object. The mmap() syscall with enclave file descriptors does  
>> not
>> +support non-zero value for the 'offset' parameter.
>
> I think we all need to understand better why SGX driver requires  
> anonymous
> semantics mmap() against /dev/sgx_enclave, and as a result of that,  
> requires
> mmap() to pass  0 as pgoff (which looks wasn't even discussed when  
> upstreaming
> the driver).
>
> I'll do some investigation and try to summerize and report back.  Thanks.
>
> [...]
>
>> This is
>> +unlike regular file mapping in that no content offset can be defined  
>> that
>> is
>> +independent from the virtual address it is loaded to.
>> +
>>
>
> Don't quite understand this.  The virtual address of a regular file  
> mapping can
> be linked to file's offest from VMA's pgoff.
>

For file mapping, the offset is the 'content offset' relative to the  
beginning of the file content. The file 'content' is independent from the  
memory it is mapped to.

mmap(..., encl_fd, ...) just creates VMAs as windows/views into the  
enclave memory whose range is already defined by [encl->base,  
encl->base+encl->size) when ECREATE is done. The 'content' of enclave and  
the memory to which the 'content' is mapped are the same. Hence, no  
independent  'content offset' can be defined from user point of view.

 From implementation point of view:

In regular file mapping, vma->vm_pgoff has nothing to do with  
vma->vm_start (or 'addr' passed by mmap). It is used to load bytes at  
pg_offset in the 'content' referenced by vma->vm_file, which is backed up  
by a real file or object that contains the bytes.

In enclave mapping, vma->vm_file is the '/dev/sgx_enclave' device node,  
and it does not refer to any content. It does not make sense to have  
'offset' into '/dev/sgx_enclave'. vma->pg_offset is meaningless for  
enclave mapping.

Thanks
Haitao

  reply	other threads:[~2023-06-07 17:01 UTC|newest]

Thread overview: 60+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-28  4:55 [RFC PATCH v4 0/4] x86/sgx: implement support for MADV_WILLNEED Haitao Huang
2023-01-28  4:55 ` [RFC PATCH v4 1/4] x86/sgx: Export sgx_encl_eaug_page Haitao Huang
2023-01-28  4:55   ` [RFC PATCH v4 2/4] x86/sgx: Implement support for MADV_WILLNEED Haitao Huang
2023-01-28  4:55     ` [RFC PATCH v4 3/4] selftests/sgx: add len field for EACCEPT op Haitao Huang
2023-01-28  4:55       ` [RFC PATCH v4 4/4] selftests/sgx: Add test for madvise(..., WILLNEED) Haitao Huang
2023-02-07 23:30         ` Jarkko Sakkinen
2023-02-15  2:38         ` Huang, Kai
2023-02-15  4:42           ` Haitao Huang
2023-02-15  8:46             ` Huang, Kai
2023-02-17 22:29               ` jarkko
2023-02-07 23:29       ` [RFC PATCH v4 3/4] selftests/sgx: add len field for EACCEPT op Jarkko Sakkinen
2023-02-07 23:28     ` [RFC PATCH v4 2/4] x86/sgx: Implement support for MADV_WILLNEED Jarkko Sakkinen
2023-02-14  9:47     ` Huang, Kai
2023-02-14 19:18       ` Haitao Huang
2023-02-14 20:54         ` Huang, Kai
2023-02-14 21:42           ` Haitao Huang
2023-02-14 22:36             ` Huang, Kai
2023-02-15  3:59               ` Haitao Huang
2023-02-15  8:51                 ` Huang, Kai
2023-02-15 15:42                   ` Haitao Huang
2023-02-16  7:53                     ` Huang, Kai
2023-02-16 17:12                       ` Haitao Huang
2023-02-17 22:32                     ` jarkko
2023-02-17 23:03                       ` Haitao Huang
2023-02-21 22:10                         ` jarkko
2023-02-22  1:37                           ` Haitao Huang
2023-03-07 23:32                             ` Huang, Kai
2023-03-09  0:50                               ` Haitao Huang
2023-03-09 11:31                                 ` Huang, Kai
2023-03-14 14:54                                   ` Haitao Huang
2023-03-19 13:26                                     ` jarkko
2023-03-20  9:36                                       ` Huang, Kai
2023-03-20 14:04                                         ` jarkko
2023-05-27  0:32                                   ` Haitao Huang
2023-06-06  4:11                                     ` Huang, Kai
2023-06-07 16:59                                       ` Haitao Huang [this message]
2023-06-16  3:49                                       ` Huang, Kai
2023-06-16 22:05                                         ` Sean Christopherson
2023-06-19 11:17                                           ` Huang, Kai
2023-06-22 22:01                                             ` Sean Christopherson
2023-06-22 23:21                                               ` Huang, Kai
2023-06-26 22:28                                                 ` Sean Christopherson
2023-06-27 11:43                                                   ` Huang, Kai
2023-06-27 14:50                                                     ` Sean Christopherson
2023-06-28  9:37                                                       ` Huang, Kai
2023-06-28 14:57                                                         ` Sean Christopherson
2023-06-29  3:10                                                           ` Huang, Kai
2023-06-29 14:23                                                             ` Sean Christopherson
2023-06-29 23:29                                                               ` Huang, Kai
2023-06-30  0:14                                                                 ` Sean Christopherson
2023-06-30  0:56                                                                   ` Huang, Kai
2023-06-30  1:54                                                                 ` Jarkko Sakkinen
2023-06-30  1:57                                                                   ` Jarkko Sakkinen
2023-06-30  4:26                                                                     ` Huang, Kai
2023-06-30  9:35                                                                       ` Jarkko Sakkinen
2023-03-12  1:25                               ` jarkko
2023-03-12 22:25                                 ` Huang, Kai
2023-02-17 22:07           ` jarkko
2023-02-17 21:50       ` jarkko
2023-02-07 23:26   ` [RFC PATCH v4 1/4] x86/sgx: Export sgx_encl_eaug_page Jarkko Sakkinen

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=op.156hhiivwjvjmi@hhuan26-mobl.amr.corp.intel.com \
    --to=haitao.huang@linux.intel.com \
    --cc=dave.hansen@linux.intel.com \
    --cc=jarkko@kernel.org \
    --cc=kai.huang@intel.com \
    --cc=linux-sgx@vger.kernel.org \
    --cc=reinette.chatre@intel.com \
    --cc=vijay.dhanraj@intel.com \
    /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).